2013-10-25 15:19:00 +00:00
|
|
|
/*
|
2013-12-20 19:25:49 +00:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 15:19:00 +00:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
import android.app.Activity;
|
2014-03-22 22:31:55 +00:00
|
|
|
import android.content.ContentResolver;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2014-09-25 03:54:35 +00:00
|
|
|
import android.content.res.Configuration;
|
2014-03-04 19:29:32 +00:00
|
|
|
import android.database.Cursor;
|
2014-11-07 10:23:17 +00:00
|
|
|
import android.graphics.Point;
|
2014-03-04 19:29:32 +00:00
|
|
|
import android.net.Uri;
|
2014-09-24 02:17:27 +00:00
|
|
|
import android.os.Build;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.os.Bundle;
|
2014-03-04 19:29:32 +00:00
|
|
|
import android.os.Parcelable;
|
2014-03-22 22:31:55 +00:00
|
|
|
import android.provider.ContactsContract;
|
2014-09-24 02:17:27 +00:00
|
|
|
import android.view.ActionMode;
|
2014-10-01 19:55:24 +00:00
|
|
|
import android.view.KeyEvent;
|
2014-09-24 02:17:27 +00:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.View;
|
2014-09-24 02:17:27 +00:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.Window;
|
2014-11-17 02:44:57 +00:00
|
|
|
import android.view.WindowManager;
|
2014-11-07 20:10:12 +00:00
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.AdapterView;
|
2014-09-24 02:17:27 +00:00
|
|
|
import android.widget.FrameLayout;
|
2014-09-25 03:54:35 +00:00
|
|
|
import android.widget.ImageView;
|
2014-11-07 20:10:12 +00:00
|
|
|
import android.widget.ListView;
|
2014-09-24 02:17:27 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2014-03-04 19:29:32 +00:00
|
|
|
import android.widget.Toast;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2014-03-22 22:31:55 +00:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-11-10 11:05:22 +00:00
|
|
|
import org.telegram.android.ContactsController;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.SendMessagesHelper;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.LocaleController;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.R;
|
2014-03-04 19:29:32 +00:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
import org.telegram.messenger.Utilities;
|
2014-11-07 20:10:12 +00:00
|
|
|
import org.telegram.ui.Adapters.DrawerLayoutAdapter;
|
2014-11-13 20:10:14 +00:00
|
|
|
import org.telegram.ui.ActionBar.ActionBarLayout;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
|
|
|
import org.telegram.ui.ActionBar.DrawerLayoutContainer;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
2014-03-04 19:29:32 +00:00
|
|
|
import java.util.ArrayList;
|
2014-04-04 23:00:38 +00:00
|
|
|
import java.util.Map;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate {
|
2014-11-17 02:44:57 +00:00
|
|
|
private boolean finished;
|
|
|
|
private String videoPath;
|
|
|
|
private String sendingText;
|
|
|
|
private ArrayList<Uri> photoPathsArray;
|
|
|
|
private ArrayList<String> documentsPathsArray;
|
|
|
|
private ArrayList<String> documentsOriginalPathsArray;
|
|
|
|
private ArrayList<TLRPC.User> contactsToSend;
|
2013-10-25 15:19:00 +00:00
|
|
|
private int currentConnectionState;
|
2014-09-24 02:17:27 +00:00
|
|
|
private static ArrayList<BaseFragment> mainFragmentsStack = new ArrayList<BaseFragment>();
|
|
|
|
private static ArrayList<BaseFragment> layerFragmentsStack = new ArrayList<BaseFragment>();
|
|
|
|
private static ArrayList<BaseFragment> rightFragmentsStack = new ArrayList<BaseFragment>();
|
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
private ActionBarLayout actionBarLayout;
|
|
|
|
private ActionBarLayout layersActionBarLayout;
|
|
|
|
private ActionBarLayout rightActionBarLayout;
|
|
|
|
private FrameLayout shadowTablet;
|
|
|
|
private FrameLayout shadowTabletSide;
|
|
|
|
private ImageView backgroundTablet;
|
|
|
|
private DrawerLayoutContainer drawerLayoutContainer;
|
|
|
|
private DrawerLayoutAdapter drawerLayoutAdapter;
|
2014-11-07 20:10:12 +00:00
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
private boolean tabletFullSize;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2014-03-22 22:31:55 +00:00
|
|
|
ApplicationLoader.postInitApplication();
|
|
|
|
|
2014-06-13 10:42:21 +00:00
|
|
|
if (!UserConfig.isClientActivated()) {
|
2014-03-04 19:29:32 +00:00
|
|
|
Intent intent = getIntent();
|
2014-03-24 21:10:35 +00:00
|
|
|
if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) {
|
2014-09-24 02:17:27 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2014-03-04 19:29:32 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
if (intent != null && !intent.getBooleanExtra("fromIntro", false)) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", MODE_PRIVATE);
|
|
|
|
Map<String, ?> state = preferences.getAll();
|
|
|
|
if (state.isEmpty()) {
|
|
|
|
Intent intent2 = new Intent(this, IntroActivity.class);
|
|
|
|
startActivity(intent2);
|
2014-09-24 02:17:27 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2014-06-03 23:31:48 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 23:00:38 +00:00
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
|
setTheme(R.style.Theme_TMessages);
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
|
|
|
if (resourceId > 0) {
|
|
|
|
AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout = new ActionBarLayout(this);
|
2014-11-17 02:44:57 +00:00
|
|
|
|
|
|
|
drawerLayoutContainer = new DrawerLayoutContainer(this);
|
|
|
|
setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-11-17 02:44:57 +00:00
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
|
|
|
RelativeLayout launchLayout = new RelativeLayout(this);
|
|
|
|
drawerLayoutContainer.addView(launchLayout);
|
|
|
|
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) launchLayout.getLayoutParams();
|
|
|
|
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
launchLayout.setLayoutParams(layoutParams1);
|
|
|
|
|
|
|
|
backgroundTablet = new ImageView(this);
|
|
|
|
backgroundTablet.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
|
backgroundTablet.setImageResource(R.drawable.cats);
|
|
|
|
launchLayout.addView(backgroundTablet);
|
|
|
|
RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) backgroundTablet.getLayoutParams();
|
|
|
|
relativeLayoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
backgroundTablet.setLayoutParams(relativeLayoutParams);
|
|
|
|
|
|
|
|
launchLayout.addView(actionBarLayout);
|
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
|
|
|
|
relativeLayoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
actionBarLayout.setLayoutParams(relativeLayoutParams);
|
2014-09-24 02:17:27 +00:00
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
rightActionBarLayout = new ActionBarLayout(this);
|
|
|
|
launchLayout.addView(rightActionBarLayout);
|
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams)rightActionBarLayout.getLayoutParams();
|
|
|
|
relativeLayoutParams.width = AndroidUtilities.dp(320);
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
rightActionBarLayout.setLayoutParams(relativeLayoutParams);
|
|
|
|
rightActionBarLayout.init(rightFragmentsStack);
|
|
|
|
rightActionBarLayout.setDelegate(this);
|
|
|
|
|
|
|
|
shadowTabletSide = new FrameLayout(this);
|
|
|
|
shadowTabletSide.setBackgroundColor(0x40295274);
|
|
|
|
launchLayout.addView(shadowTabletSide);
|
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams();
|
|
|
|
relativeLayoutParams.width = AndroidUtilities.dp(1);
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
shadowTabletSide.setLayoutParams(relativeLayoutParams);
|
|
|
|
|
|
|
|
shadowTablet = new FrameLayout(this);
|
|
|
|
shadowTablet.setVisibility(View.GONE);
|
|
|
|
shadowTablet.setBackgroundColor(0x7F000000);
|
|
|
|
launchLayout.addView(shadowTablet);
|
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTablet.getLayoutParams();
|
|
|
|
relativeLayoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
shadowTablet.setLayoutParams(relativeLayoutParams);
|
2014-09-24 02:17:27 +00:00
|
|
|
shadowTablet.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
2014-09-28 13:37:26 +00:00
|
|
|
if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
float x = event.getX();
|
|
|
|
float y = event.getY();
|
|
|
|
int location[] = new int[2];
|
|
|
|
layersActionBarLayout.getLocationOnScreen(location);
|
|
|
|
int viewX = location[0];
|
|
|
|
int viewY = location[1];
|
|
|
|
|
|
|
|
if (x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
layersActionBarLayout.closeLastFragment(true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
shadowTablet.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
layersActionBarLayout = new ActionBarLayout(this);
|
2014-11-17 02:44:57 +00:00
|
|
|
layersActionBarLayout.setRemoveActionBarExtraHeight(true);
|
2014-09-24 02:17:27 +00:00
|
|
|
layersActionBarLayout.setBackgroundView(shadowTablet);
|
|
|
|
layersActionBarLayout.setUseAlphaAnimations(true);
|
|
|
|
layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow);
|
|
|
|
launchLayout.addView(layersActionBarLayout);
|
2014-11-17 02:44:57 +00:00
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams)layersActionBarLayout.getLayoutParams();
|
2014-09-24 02:17:27 +00:00
|
|
|
relativeLayoutParams.width = AndroidUtilities.dp(498);
|
|
|
|
relativeLayoutParams.height = AndroidUtilities.dp(528);
|
|
|
|
layersActionBarLayout.setLayoutParams(relativeLayoutParams);
|
|
|
|
layersActionBarLayout.init(layerFragmentsStack);
|
|
|
|
layersActionBarLayout.setDelegate(this);
|
2014-11-17 02:44:57 +00:00
|
|
|
layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
|
2014-09-24 02:17:27 +00:00
|
|
|
layersActionBarLayout.setVisibility(View.GONE);
|
2014-11-17 02:44:57 +00:00
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
ListView listView = new ListView(this);
|
|
|
|
listView.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this));
|
|
|
|
drawerLayoutContainer.setDrawerLayout(listView);
|
|
|
|
listView.setBackgroundColor(0xffffffff);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)listView.getLayoutParams();
|
|
|
|
Point screenSize = AndroidUtilities.getRealScreenSize();
|
|
|
|
layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56);
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
listView.setPadding(0, 0, 0, 0);
|
|
|
|
listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
|
|
|
|
listView.setDivider(null);
|
|
|
|
listView.setDividerHeight(0);
|
|
|
|
listView.setLayoutParams(layoutParams);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if (position == 2) {
|
2014-09-24 02:17:27 +00:00
|
|
|
presentFragment(new GroupCreateActivity());
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (position == 3) {
|
2014-09-24 02:17:27 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlyUsers", true);
|
|
|
|
args.putBoolean("destroyAfterSelect", true);
|
|
|
|
args.putBoolean("createSecretChat", true);
|
|
|
|
presentFragment(new ContactsActivity(args));
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (position == 4) {
|
2014-09-24 02:17:27 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("broadcast", true);
|
|
|
|
presentFragment(new GroupCreateActivity(args));
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (position == 6) {
|
2014-09-24 02:17:27 +00:00
|
|
|
presentFragment(new ContactsActivity(null));
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (position == 7) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setType("text/plain");
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText());
|
|
|
|
startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (position == 8) {
|
2014-09-24 02:17:27 +00:00
|
|
|
presentFragment(new SettingsActivity());
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (position == 9) {
|
|
|
|
try {
|
|
|
|
Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)));
|
|
|
|
startActivity(pickIntent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-11-07 20:10:12 +00:00
|
|
|
}
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
2014-11-07 20:10:12 +00:00
|
|
|
}
|
2014-11-17 02:44:57 +00:00
|
|
|
}
|
|
|
|
});
|
2014-11-07 20:10:12 +00:00
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setParentActionBarLayout(actionBarLayout);
|
|
|
|
actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.init(mainFragmentsStack);
|
|
|
|
actionBarLayout.setDelegate(this);
|
|
|
|
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this);
|
2014-07-02 22:39:05 +00:00
|
|
|
currentConnectionState = ConnectionsManager.getInstance().getConnectionState();
|
2014-06-03 23:31:48 +00:00
|
|
|
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
|
2014-11-17 02:44:57 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged);
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
2014-06-13 10:42:21 +00:00
|
|
|
if (!UserConfig.isClientActivated()) {
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.addFragmentToStack(new LoginActivity());
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false);
|
2014-06-03 23:31:48 +00:00
|
|
|
} else {
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true);
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
2014-03-26 20:16:28 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
String fragmentName = savedInstanceState.getString("fragment");
|
|
|
|
if (fragmentName != null) {
|
|
|
|
Bundle args = savedInstanceState.getBundle("args");
|
|
|
|
if (fragmentName.equals("chat")) {
|
|
|
|
if (args != null) {
|
2014-06-03 23:31:48 +00:00
|
|
|
ChatActivity chat = new ChatActivity(args);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (actionBarLayout.addFragmentToStack(chat)) {
|
2014-03-26 20:16:28 +00:00
|
|
|
chat.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fragmentName.equals("settings")) {
|
|
|
|
SettingsActivity settings = new SettingsActivity();
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.addFragmentToStack(settings);
|
2014-03-26 20:16:28 +00:00
|
|
|
settings.restoreSelfArgs(savedInstanceState);
|
|
|
|
} else if (fragmentName.equals("group")) {
|
|
|
|
if (args != null) {
|
2014-06-03 23:31:48 +00:00
|
|
|
GroupCreateFinalActivity group = new GroupCreateFinalActivity(args);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (actionBarLayout.addFragmentToStack(group)) {
|
2014-03-26 20:16:28 +00:00
|
|
|
group.restoreSelfArgs(savedInstanceState);
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fragmentName.equals("chat_profile")) {
|
|
|
|
if (args != null) {
|
2014-11-12 22:16:59 +00:00
|
|
|
ProfileActivity profile = new ProfileActivity(args);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (actionBarLayout.addFragmentToStack(profile)) {
|
2014-06-03 23:31:48 +00:00
|
|
|
profile.restoreSelfArgs(savedInstanceState);
|
2014-03-26 20:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fragmentName.equals("wallpapers")) {
|
2014-11-13 20:10:14 +00:00
|
|
|
WallpapersActivity settings = new WallpapersActivity();
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.addFragmentToStack(settings);
|
2014-03-26 20:16:28 +00:00
|
|
|
settings.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-11-18 12:37:11 +00:00
|
|
|
} else {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(actionBarLayout.fragmentsStack.size() <= 1 && layersActionBarLayout.fragmentsStack.isEmpty());
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(actionBarLayout.fragmentsStack.size() <= 1);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-10 09:27:49 +00:00
|
|
|
handleIntent(getIntent(), false, savedInstanceState != null);
|
2014-09-24 02:17:27 +00:00
|
|
|
needLayout();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-10 09:27:49 +00:00
|
|
|
private void handleIntent(Intent intent, boolean isNew, boolean restore) {
|
2014-03-04 19:29:32 +00:00
|
|
|
boolean pushOpened = false;
|
|
|
|
|
|
|
|
Integer push_user_id = 0;
|
|
|
|
Integer push_chat_id = 0;
|
|
|
|
Integer push_enc_id = 0;
|
|
|
|
Integer open_settings = 0;
|
2014-07-22 23:27:00 +00:00
|
|
|
boolean showDialogsList = false;
|
2014-03-04 19:29:32 +00:00
|
|
|
|
2014-06-20 00:18:13 +00:00
|
|
|
photoPathsArray = null;
|
2014-03-04 19:29:32 +00:00
|
|
|
videoPath = null;
|
|
|
|
sendingText = null;
|
2014-06-20 00:18:13 +00:00
|
|
|
documentsPathsArray = null;
|
|
|
|
documentsOriginalPathsArray = null;
|
|
|
|
contactsToSend = null;
|
2014-03-04 19:29:32 +00:00
|
|
|
|
2014-06-12 15:53:20 +00:00
|
|
|
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
|
2014-05-16 23:05:49 +00:00
|
|
|
if (intent != null && intent.getAction() != null && !restore) {
|
|
|
|
if (Intent.ACTION_SEND.equals(intent.getAction())) {
|
|
|
|
boolean error = false;
|
|
|
|
String type = intent.getType();
|
|
|
|
if (type != null && type.equals("text/plain")) {
|
|
|
|
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
|
|
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
|
|
|
|
|
|
|
if (text != null && text.length() != 0) {
|
|
|
|
if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null && subject.length() != 0) {
|
|
|
|
text = subject + "\n" + text;
|
|
|
|
}
|
|
|
|
sendingText = text;
|
|
|
|
} else {
|
|
|
|
error = true;
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) {
|
|
|
|
try {
|
|
|
|
Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM);
|
|
|
|
if (uri != null) {
|
|
|
|
ContentResolver cr = getContentResolver();
|
|
|
|
InputStream stream = cr.openInputStream(uri);
|
|
|
|
|
|
|
|
String name = null;
|
|
|
|
String nameEncoding = null;
|
|
|
|
String nameCharset = null;
|
|
|
|
ArrayList<String> phones = new ArrayList<String>();
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
|
|
|
|
String line = null;
|
|
|
|
while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
String[] args = line.split(":");
|
|
|
|
if (args.length != 2) {
|
|
|
|
continue;
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
if (args[0].startsWith("FN")) {
|
|
|
|
String[] params = args[0].split(";");
|
|
|
|
for (String param : params) {
|
|
|
|
String[] args2 = param.split("=");
|
|
|
|
if (args2.length != 2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args2[0].equals("CHARSET")) {
|
|
|
|
nameCharset = args2[1];
|
|
|
|
} else if (args2[0].equals("ENCODING")) {
|
|
|
|
nameEncoding = args2[1];
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
name = args[1];
|
|
|
|
if (nameEncoding != null && nameEncoding.equalsIgnoreCase("QUOTED-PRINTABLE")) {
|
|
|
|
while (name.endsWith("=") && nameEncoding != null) {
|
|
|
|
name = name.substring(0, name.length() - 1);
|
|
|
|
line = bufferedReader.readLine();
|
|
|
|
if (line == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
name += line;
|
|
|
|
}
|
|
|
|
byte[] bytes = Utilities.decodeQuotedPrintable(name.getBytes());
|
|
|
|
if (bytes != null && bytes.length != 0) {
|
|
|
|
String decodedName = new String(bytes, nameCharset);
|
|
|
|
if (decodedName != null) {
|
|
|
|
name = decodedName;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else if (args[0].startsWith("TEL")) {
|
|
|
|
String phone = PhoneFormat.stripExceptNumbers(args[1], true);
|
|
|
|
if (phone.length() > 0) {
|
|
|
|
phones.add(phone);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
if (name != null && !phones.isEmpty()) {
|
|
|
|
contactsToSend = new ArrayList<TLRPC.User>();
|
|
|
|
for (String phone : phones) {
|
|
|
|
TLRPC.User user = new TLRPC.TL_userContact();
|
|
|
|
user.phone = phone;
|
|
|
|
user.first_name = name;
|
|
|
|
user.last_name = "";
|
|
|
|
user.id = 0;
|
|
|
|
contactsToSend.add(user);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else {
|
|
|
|
error = true;
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-03-22 22:31:55 +00:00
|
|
|
error = true;
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else {
|
|
|
|
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
if (parcelable == null) {
|
|
|
|
return;
|
2014-04-05 17:11:44 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
String path = null;
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
Uri uri = (Uri) parcelable;
|
|
|
|
if (uri != null && type != null && type.startsWith("image/")) {
|
|
|
|
String tempPath = Utilities.getPath(uri);
|
2014-06-20 00:18:13 +00:00
|
|
|
if (photoPathsArray == null) {
|
|
|
|
photoPathsArray = new ArrayList<Uri>();
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
photoPathsArray.add(uri);
|
2014-03-04 19:29:32 +00:00
|
|
|
} else {
|
2014-05-16 23:05:49 +00:00
|
|
|
path = Utilities.getPath(uri);
|
|
|
|
if (path != null) {
|
|
|
|
if (path.startsWith("file:")) {
|
|
|
|
path = path.replace("file://", "");
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
if (type != null && type.startsWith("video/")) {
|
|
|
|
videoPath = path;
|
|
|
|
} else {
|
2014-06-20 00:18:13 +00:00
|
|
|
if (documentsPathsArray == null) {
|
|
|
|
documentsPathsArray = new ArrayList<String>();
|
|
|
|
documentsOriginalPathsArray = new ArrayList<String>();
|
|
|
|
}
|
|
|
|
documentsPathsArray.add(path);
|
|
|
|
documentsOriginalPathsArray.add(uri.toString());
|
2014-04-05 17:11:44 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
|
|
|
|
boolean error = false;
|
|
|
|
try {
|
|
|
|
ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
|
|
String type = intent.getType();
|
|
|
|
if (uris != null) {
|
|
|
|
if (type != null && type.startsWith("image/")) {
|
|
|
|
for (Parcelable parcelable : uris) {
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
Uri uri = (Uri) parcelable;
|
2014-06-20 00:18:13 +00:00
|
|
|
if (photoPathsArray == null) {
|
|
|
|
photoPathsArray = new ArrayList<Uri>();
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
photoPathsArray.add(uri);
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else {
|
|
|
|
for (Parcelable parcelable : uris) {
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
String path = Utilities.getPath((Uri) parcelable);
|
2014-06-20 00:18:13 +00:00
|
|
|
String originalPath = parcelable.toString();
|
|
|
|
if (originalPath == null) {
|
|
|
|
originalPath = path;
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
if (path != null) {
|
|
|
|
if (path.startsWith("file:")) {
|
|
|
|
path = path.replace("file://", "");
|
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
if (documentsPathsArray == null) {
|
|
|
|
documentsPathsArray = new ArrayList<String>();
|
|
|
|
documentsOriginalPathsArray = new ArrayList<String>();
|
2014-05-16 23:05:49 +00:00
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
documentsPathsArray.add(path);
|
|
|
|
documentsOriginalPathsArray.add(originalPath);
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else {
|
|
|
|
error = true;
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-03-04 19:29:32 +00:00
|
|
|
error = true;
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
if (error) {
|
|
|
|
Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
|
try {
|
|
|
|
Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
int userId = cursor.getInt(cursor.getColumnIndex("DATA4"));
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
2014-05-16 23:05:49 +00:00
|
|
|
push_user_id = userId;
|
|
|
|
}
|
|
|
|
cursor.close();
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
} else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) {
|
|
|
|
open_settings = 1;
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-12 15:53:20 +00:00
|
|
|
if (intent.getAction() != null && intent.getAction().startsWith("com.tmessages.openchat") && !restore) {
|
|
|
|
int chatId = intent.getIntExtra("chatId", 0);
|
|
|
|
int userId = intent.getIntExtra("userId", 0);
|
|
|
|
int encId = intent.getIntExtra("encId", 0);
|
2014-05-16 23:05:49 +00:00
|
|
|
if (chatId != 0) {
|
2014-08-29 21:06:04 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
push_chat_id = chatId;
|
2014-05-16 23:05:49 +00:00
|
|
|
} else if (userId != 0) {
|
2014-08-29 21:06:04 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
push_user_id = userId;
|
2014-05-16 23:05:49 +00:00
|
|
|
} else if (encId != 0) {
|
2014-08-29 21:06:04 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
push_enc_id = encId;
|
2014-07-22 23:27:00 +00:00
|
|
|
} else {
|
|
|
|
showDialogsList = true;
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (push_user_id != 0) {
|
2014-06-13 10:42:21 +00:00
|
|
|
if (push_user_id == UserConfig.getClientUserId()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
open_settings = 1;
|
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", push_user_id);
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (actionBarLayout.presentFragment(fragment, false, true, true)) {
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (push_chat_id != 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", push_chat_id);
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (actionBarLayout.presentFragment(fragment, false, true, true)) {
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
} else if (push_enc_id != 0) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("enc_id", push_enc_id);
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (actionBarLayout.presentFragment(fragment, false, true, true)) {
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-07-22 23:27:00 +00:00
|
|
|
} else if (showDialogsList) {
|
2014-10-05 21:23:57 +00:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.removeAllFragments();
|
2014-07-22 23:27:00 +00:00
|
|
|
}
|
2014-08-30 19:30:42 +00:00
|
|
|
pushOpened = false;
|
|
|
|
isNew = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null) {
|
2014-09-28 13:37:26 +00:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
2014-07-10 21:15:39 +00:00
|
|
|
args.putString("selectAlertString", LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
|
2014-10-04 15:56:09 +00:00
|
|
|
args.putString("selectAlertStringGroup", LocaleController.getString("SendMessagesToGroup", R.string.SendMessagesToGroup));
|
2014-06-03 23:31:48 +00:00
|
|
|
MessagesActivity fragment = new MessagesActivity(args);
|
|
|
|
fragment.setDelegate(this);
|
2014-09-28 13:37:26 +00:00
|
|
|
actionBarLayout.presentFragment(fragment, false, true, true);
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2014-08-29 21:06:04 +00:00
|
|
|
if (PhotoViewer.getInstance().isVisible()) {
|
2014-09-29 22:48:11 +00:00
|
|
|
PhotoViewer.getInstance().closePhoto(false);
|
2014-08-29 21:06:04 +00:00
|
|
|
}
|
2014-10-07 20:14:27 +00:00
|
|
|
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
if (open_settings != 0) {
|
2014-09-28 13:37:26 +00:00
|
|
|
actionBarLayout.presentFragment(new SettingsActivity(), false, true, true);
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
if (!pushOpened && !isNew) {
|
2014-09-28 13:37:26 +00:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (UserConfig.isClientActivated()) {
|
|
|
|
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true);
|
2014-09-28 13:37:26 +00:00
|
|
|
}
|
2014-09-13 23:40:36 +00:00
|
|
|
} else {
|
2014-09-28 13:37:26 +00:00
|
|
|
if (layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
layersActionBarLayout.addFragmentToStack(new LoginActivity());
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false);
|
2014-09-28 13:37:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
if (!UserConfig.isClientActivated()) {
|
|
|
|
actionBarLayout.addFragmentToStack(new LoginActivity());
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false);
|
2014-09-28 13:37:26 +00:00
|
|
|
} else {
|
|
|
|
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true);
|
2014-09-28 13:37:26 +00:00
|
|
|
}
|
2014-09-13 23:40:36 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
layersActionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 15:53:20 +00:00
|
|
|
intent.setAction(null);
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
2014-03-10 09:27:49 +00:00
|
|
|
handleIntent(intent, true, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-10 21:15:39 +00:00
|
|
|
public void didSelectDialog(MessagesActivity messageFragment, long dialog_id, boolean param) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (dialog_id != 0) {
|
|
|
|
int lower_part = (int)dialog_id;
|
2014-07-27 10:53:00 +00:00
|
|
|
int high_id = (int)(dialog_id >> 32);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("scrollToTopOnResume", true);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
if (lower_part != 0) {
|
2014-07-27 10:53:00 +00:00
|
|
|
if (high_id == 1) {
|
|
|
|
args.putInt("chat_id", lower_part);
|
2014-07-26 22:28:33 +00:00
|
|
|
} else {
|
2014-07-27 10:53:00 +00:00
|
|
|
if (lower_part > 0) {
|
|
|
|
args.putInt("user_id", lower_part);
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
args.putInt("chat_id", -lower_part);
|
|
|
|
}
|
2014-07-26 22:28:33 +00:00
|
|
|
}
|
2014-07-27 10:53:00 +00:00
|
|
|
} else {
|
|
|
|
args.putInt("enc_id", high_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
2014-09-29 22:48:11 +00:00
|
|
|
|
2014-04-01 01:00:35 +00:00
|
|
|
if (videoPath != null) {
|
2014-09-29 22:48:11 +00:00
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 16) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.presentFragment(fragment, false, true, true);
|
|
|
|
}
|
|
|
|
|
2014-10-20 11:30:05 +00:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.addFragmentToStack(fragment, actionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fragment.openVideoEditor(videoPath, true)) {
|
2014-10-15 18:43:52 +00:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
2014-10-20 11:30:05 +00:00
|
|
|
messageFragment.finishFragment(true);
|
2014-10-15 18:43:52 +00:00
|
|
|
}
|
2014-09-29 22:48:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionBarLayout.presentFragment(fragment, true);
|
2014-10-16 20:02:44 +00:00
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id);
|
2014-09-29 22:48:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionBarLayout.presentFragment(fragment, true);
|
2014-11-17 22:04:31 +00:00
|
|
|
|
2014-09-29 22:48:11 +00:00
|
|
|
if (sendingText != null) {
|
|
|
|
fragment.processSendingText(sendingText);
|
|
|
|
}
|
|
|
|
if (photoPathsArray != null) {
|
2014-10-16 20:02:44 +00:00
|
|
|
SendMessagesHelper.prepareSendingPhotos(null, photoPathsArray, dialog_id);
|
2014-09-29 22:48:11 +00:00
|
|
|
}
|
|
|
|
if (documentsPathsArray != null) {
|
2014-10-16 20:02:44 +00:00
|
|
|
SendMessagesHelper.prepareSendingDocuments(documentsPathsArray, documentsOriginalPathsArray, dialog_id);
|
2014-09-29 22:48:11 +00:00
|
|
|
}
|
|
|
|
if (contactsToSend != null && !contactsToSend.isEmpty()) {
|
|
|
|
for (TLRPC.User user : contactsToSend) {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage(user, dialog_id);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
|
|
|
|
photoPathsArray = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
videoPath = null;
|
|
|
|
sendingText = null;
|
2014-06-20 00:18:13 +00:00
|
|
|
documentsPathsArray = null;
|
|
|
|
documentsOriginalPathsArray = null;
|
2014-03-22 22:31:55 +00:00
|
|
|
contactsToSend = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
private void onFinish() {
|
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finished = true;
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout);
|
2014-11-17 02:44:57 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mainUserInfoChanged);
|
2014-09-24 02:17:27 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeOtherAppActivities);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didUpdatedConnectionState);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void presentFragment(BaseFragment fragment) {
|
|
|
|
actionBarLayout.presentFragment(fragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean presentFragment(final BaseFragment fragment, final boolean removeLast, boolean forceWithoutAnimation) {
|
2014-09-28 13:37:26 +00:00
|
|
|
return actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, true);
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void needLayout() {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-11-17 02:44:57 +00:00
|
|
|
|
|
|
|
RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams)layersActionBarLayout.getLayoutParams();
|
|
|
|
relativeLayoutParams.leftMargin = (AndroidUtilities.displaySize.x - relativeLayoutParams.width) / 2;
|
|
|
|
int y = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
|
|
|
relativeLayoutParams.topMargin = y + (AndroidUtilities.displaySize.y - relativeLayoutParams.height - y) / 2;
|
|
|
|
layersActionBarLayout.setLayoutParams(relativeLayoutParams);
|
|
|
|
|
2014-09-25 03:54:35 +00:00
|
|
|
if (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
tabletFullSize = false;
|
|
|
|
int leftWidth = AndroidUtilities.displaySize.x / 100 * 35;
|
|
|
|
if (leftWidth < AndroidUtilities.dp(320)) {
|
|
|
|
leftWidth = AndroidUtilities.dp(320);
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
|
2014-09-25 03:54:35 +00:00
|
|
|
relativeLayoutParams.width = leftWidth;
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
actionBarLayout.setLayoutParams(relativeLayoutParams);
|
|
|
|
|
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams();
|
|
|
|
relativeLayoutParams.leftMargin = leftWidth;
|
|
|
|
shadowTabletSide.setLayoutParams(relativeLayoutParams);
|
|
|
|
|
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams) rightActionBarLayout.getLayoutParams();
|
|
|
|
relativeLayoutParams.width = AndroidUtilities.displaySize.x - leftWidth;
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
relativeLayoutParams.leftMargin = leftWidth;
|
|
|
|
rightActionBarLayout.setLayoutParams(relativeLayoutParams);
|
|
|
|
|
2014-09-28 13:37:26 +00:00
|
|
|
if (AndroidUtilities.isSmallTablet() && actionBarLayout.fragmentsStack.size() == 2) {
|
|
|
|
BaseFragment chatFragment = actionBarLayout.fragmentsStack.get(1);
|
2014-10-07 20:14:27 +00:00
|
|
|
chatFragment.onPause();
|
2014-09-28 13:37:26 +00:00
|
|
|
actionBarLayout.fragmentsStack.remove(1);
|
2014-09-25 03:54:35 +00:00
|
|
|
actionBarLayout.showLastFragment();
|
2014-09-28 13:37:26 +00:00
|
|
|
rightActionBarLayout.fragmentsStack.add(chatFragment);
|
2014-09-25 03:54:35 +00:00
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
|
2014-09-28 13:37:26 +00:00
|
|
|
rightActionBarLayout.setVisibility(rightActionBarLayout.fragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
|
|
|
|
backgroundTablet.setVisibility(rightActionBarLayout.fragmentsStack.isEmpty() ? View.VISIBLE : View.GONE);
|
|
|
|
shadowTabletSide.setVisibility(!actionBarLayout.fragmentsStack.isEmpty() ? View.VISIBLE : View.GONE);
|
2014-09-25 03:54:35 +00:00
|
|
|
} else {
|
|
|
|
tabletFullSize = true;
|
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
|
2014-09-25 03:54:35 +00:00
|
|
|
relativeLayoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
actionBarLayout.setLayoutParams(relativeLayoutParams);
|
|
|
|
|
|
|
|
shadowTabletSide.setVisibility(View.GONE);
|
|
|
|
rightActionBarLayout.setVisibility(View.GONE);
|
2014-09-28 13:37:26 +00:00
|
|
|
backgroundTablet.setVisibility(!actionBarLayout.fragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
|
2014-09-25 03:54:35 +00:00
|
|
|
|
2014-09-28 13:37:26 +00:00
|
|
|
if (rightActionBarLayout.fragmentsStack.size() == 1) {
|
|
|
|
BaseFragment chatFragment = rightActionBarLayout.fragmentsStack.get(0);
|
2014-10-07 20:14:27 +00:00
|
|
|
chatFragment.onPause();
|
2014-09-28 13:37:26 +00:00
|
|
|
rightActionBarLayout.fragmentsStack.remove(0);
|
|
|
|
actionBarLayout.presentFragment(chatFragment, false, true, false);
|
2014-09-25 03:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fixLayout() {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-10-23 07:55:32 +00:00
|
|
|
if (actionBarLayout == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-28 15:07:16 +00:00
|
|
|
actionBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
2014-09-24 02:17:27 +00:00
|
|
|
@Override
|
|
|
|
public void onGlobalLayout() {
|
|
|
|
needLayout();
|
2014-09-28 15:07:16 +00:00
|
|
|
if (actionBarLayout != null) {
|
|
|
|
if (Build.VERSION.SDK_INT < 16) {
|
|
|
|
actionBarLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
|
|
|
} else {
|
|
|
|
actionBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-26 20:16:28 +00:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (actionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
2014-03-26 20:16:28 +00:00
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (rightActionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = rightActionBarLayout.fragmentsStack.get(rightActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
if (layersActionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
}
|
2014-03-26 20:16:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.onPause();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onPause();
|
|
|
|
layersActionBarLayout.onPause();
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
ApplicationLoader.mainInterfacePaused = true;
|
|
|
|
ConnectionsManager.getInstance().setAppPaused(true, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2014-07-11 22:14:13 +00:00
|
|
|
PhotoViewer.getInstance().destroyPhotoViewer();
|
2014-10-09 15:55:05 +00:00
|
|
|
SecretPhotoViewer.getInstance().destroyPhotoViewer();
|
2013-10-25 15:19:00 +00:00
|
|
|
super.onDestroy();
|
2014-06-03 23:31:48 +00:00
|
|
|
onFinish();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.onResume();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onResume();
|
|
|
|
layersActionBarLayout.onResume();
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
Utilities.checkForCrashes(this);
|
|
|
|
Utilities.checkForUpdates(this);
|
2014-07-02 22:39:05 +00:00
|
|
|
ApplicationLoader.mainInterfacePaused = false;
|
|
|
|
ConnectionsManager.getInstance().setAppPaused(false, false);
|
2014-11-18 05:01:04 +00:00
|
|
|
updateCurrentConnectionState();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
2014-07-02 22:39:05 +00:00
|
|
|
AndroidUtilities.checkDisplaySize();
|
2014-09-24 02:17:27 +00:00
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
fixLayout();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (id == NotificationCenter.appDidLogout) {
|
2014-09-24 02:17:27 +00:00
|
|
|
for (BaseFragment fragment : actionBarLayout.fragmentsStack) {
|
2013-10-25 15:19:00 +00:00
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
actionBarLayout.fragmentsStack.clear();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
for (BaseFragment fragment : layersActionBarLayout.fragmentsStack) {
|
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
layersActionBarLayout.fragmentsStack.clear();
|
|
|
|
for (BaseFragment fragment : rightActionBarLayout.fragmentsStack) {
|
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
rightActionBarLayout.fragmentsStack.clear();
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
Intent intent2 = new Intent(this, IntroActivity.class);
|
2013-10-25 15:19:00 +00:00
|
|
|
startActivity(intent2);
|
2014-06-03 23:31:48 +00:00
|
|
|
onFinish();
|
2013-10-25 15:19:00 +00:00
|
|
|
finish();
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.closeOtherAppActivities) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (args[0] != this) {
|
2014-06-03 23:31:48 +00:00
|
|
|
onFinish();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.didUpdatedConnectionState) {
|
2013-10-25 15:19:00 +00:00
|
|
|
int state = (Integer)args[0];
|
|
|
|
if (currentConnectionState != state) {
|
2013-12-20 19:25:49 +00:00
|
|
|
FileLog.e("tmessages", "switch to state " + state);
|
2013-10-25 15:19:00 +00:00
|
|
|
currentConnectionState = state;
|
2014-11-18 05:01:04 +00:00
|
|
|
updateCurrentConnectionState();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-17 02:44:57 +00:00
|
|
|
} else if (id == NotificationCenter.mainUserInfoChanged) {
|
|
|
|
drawerLayoutAdapter.notifyDataSetChanged();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 05:01:04 +00:00
|
|
|
private void updateCurrentConnectionState() {
|
|
|
|
String text = null;
|
|
|
|
if (currentConnectionState == 1) {
|
|
|
|
text = LocaleController.getString("WaitingForNetwork", R.string.WaitingForNetwork);
|
|
|
|
} else if (currentConnectionState == 2) {
|
|
|
|
text = LocaleController.getString("Connecting", R.string.Connecting);
|
|
|
|
} else if (currentConnectionState == 3) {
|
|
|
|
text = LocaleController.getString("Updating", R.string.Updating);
|
|
|
|
}
|
|
|
|
actionBarLayout.setTitleOverlayText(text);
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
try {
|
|
|
|
super.onSaveInstanceState(outState);
|
2014-09-28 13:37:26 +00:00
|
|
|
BaseFragment lastFragment = null;
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
lastFragment = layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
} else if (!rightActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
lastFragment = rightActionBarLayout.fragmentsStack.get(rightActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
} else if (!actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
lastFragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
lastFragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastFragment != null) {
|
2014-03-26 20:16:28 +00:00
|
|
|
Bundle args = lastFragment.getArguments();
|
|
|
|
if (lastFragment instanceof ChatActivity && args != null) {
|
|
|
|
outState.putBundle("args", args);
|
|
|
|
outState.putString("fragment", "chat");
|
|
|
|
} else if (lastFragment instanceof SettingsActivity) {
|
|
|
|
outState.putString("fragment", "settings");
|
|
|
|
} else if (lastFragment instanceof GroupCreateFinalActivity && args != null) {
|
|
|
|
outState.putBundle("args", args);
|
|
|
|
outState.putString("fragment", "group");
|
2014-11-13 20:10:14 +00:00
|
|
|
} else if (lastFragment instanceof WallpapersActivity) {
|
2014-03-26 20:16:28 +00:00
|
|
|
outState.putString("fragment", "wallpapers");
|
2014-11-12 22:16:59 +00:00
|
|
|
} else if (lastFragment instanceof ProfileActivity && ((ProfileActivity) lastFragment).isChat() && args != null) {
|
2014-06-12 15:53:20 +00:00
|
|
|
outState.putBundle("args", args);
|
2014-06-03 23:31:48 +00:00
|
|
|
outState.putString("fragment", "chat_profile");
|
2014-03-26 20:16:28 +00:00
|
|
|
}
|
|
|
|
lastFragment.saveSelfArgs(outState);
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (PhotoViewer.getInstance().isVisible()) {
|
2014-06-10 23:05:54 +00:00
|
|
|
PhotoViewer.getInstance().closePhoto(true);
|
2014-11-07 20:10:12 +00:00
|
|
|
} else if (drawerLayoutContainer.isDrawerOpened()) {
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (AndroidUtilities.isTablet()) {
|
|
|
|
if (layersActionBarLayout.getVisibility() == View.VISIBLE) {
|
|
|
|
layersActionBarLayout.onBackPressed();
|
2014-09-24 02:17:27 +00:00
|
|
|
} else {
|
2014-11-07 20:10:12 +00:00
|
|
|
boolean cancel = false;
|
|
|
|
if (rightActionBarLayout.getVisibility() == View.VISIBLE && !rightActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = rightActionBarLayout.fragmentsStack.get(rightActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
cancel = !lastFragment.onBackPressed();
|
|
|
|
}
|
|
|
|
if (!cancel) {
|
|
|
|
actionBarLayout.onBackPressed();
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
2014-11-07 20:10:12 +00:00
|
|
|
} else {
|
|
|
|
actionBarLayout.onBackPressed();
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory() {
|
|
|
|
super.onLowMemory();
|
|
|
|
actionBarLayout.onLowMemory();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onLowMemory();
|
|
|
|
layersActionBarLayout.onLowMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionModeStarted(ActionMode mode) {
|
|
|
|
super.onActionModeStarted(mode);
|
|
|
|
actionBarLayout.onActionModeStarted(mode);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onActionModeStarted(mode);
|
|
|
|
layersActionBarLayout.onActionModeStarted(mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionModeFinished(ActionMode mode) {
|
|
|
|
super.onActionModeFinished(mode);
|
|
|
|
actionBarLayout.onActionModeFinished(mode);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onActionModeFinished(mode);
|
|
|
|
layersActionBarLayout.onActionModeFinished(mode);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreIme() {
|
|
|
|
if (PhotoViewer.getInstance().isVisible()) {
|
2014-06-10 23:05:54 +00:00
|
|
|
PhotoViewer.getInstance().closePhoto(true);
|
2014-06-06 23:35:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
return false;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
|
2014-10-01 19:55:24 +00:00
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (layersActionBarLayout.getVisibility() == View.VISIBLE && !layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
layersActionBarLayout.onKeyUp(keyCode, event);
|
|
|
|
} else if (rightActionBarLayout.getVisibility() == View.VISIBLE && !rightActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
rightActionBarLayout.onKeyUp(keyCode, event);
|
|
|
|
} else {
|
|
|
|
actionBarLayout.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionBarLayout.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
@Override
|
|
|
|
public boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (fragment instanceof MessagesActivity) {
|
|
|
|
MessagesActivity messagesActivity = (MessagesActivity)fragment;
|
|
|
|
if (messagesActivity.getDelegate() == null && layout != actionBarLayout) {
|
|
|
|
actionBarLayout.removeAllFragments();
|
2014-09-28 13:37:26 +00:00
|
|
|
actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, false);
|
2014-09-24 02:17:27 +00:00
|
|
|
layersActionBarLayout.removeAllFragments();
|
|
|
|
layersActionBarLayout.setVisibility(View.GONE);
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true);
|
2014-09-25 03:54:35 +00:00
|
|
|
if (!tabletFullSize) {
|
|
|
|
shadowTabletSide.setVisibility(View.VISIBLE);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (rightActionBarLayout.fragmentsStack.isEmpty()) {
|
2014-09-25 03:54:35 +00:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-28 13:37:26 +00:00
|
|
|
}
|
|
|
|
if (fragment instanceof ChatActivity) {
|
2014-09-25 03:54:35 +00:00
|
|
|
if (!tabletFullSize && layout != rightActionBarLayout) {
|
2014-09-24 02:17:27 +00:00
|
|
|
rightActionBarLayout.setVisibility(View.VISIBLE);
|
2014-09-25 03:54:35 +00:00
|
|
|
backgroundTablet.setVisibility(View.GONE);
|
2014-09-24 02:17:27 +00:00
|
|
|
rightActionBarLayout.removeAllFragments();
|
2014-09-28 13:37:26 +00:00
|
|
|
rightActionBarLayout.presentFragment(fragment, removeLast, true, false);
|
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
2014-09-29 22:48:11 +00:00
|
|
|
layersActionBarLayout.closeLastFragment(!forceWithoutAnimation);
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
return false;
|
2014-09-25 03:54:35 +00:00
|
|
|
} else if (tabletFullSize && layout != actionBarLayout) {
|
2014-09-28 13:37:26 +00:00
|
|
|
actionBarLayout.presentFragment(fragment, actionBarLayout.fragmentsStack.size() > 1, forceWithoutAnimation, false);
|
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
2014-09-29 22:48:11 +00:00
|
|
|
layersActionBarLayout.closeLastFragment(!forceWithoutAnimation);
|
2014-09-25 03:54:35 +00:00
|
|
|
}
|
|
|
|
return false;
|
2014-09-28 13:37:26 +00:00
|
|
|
} else {
|
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
2014-09-29 22:48:11 +00:00
|
|
|
layersActionBarLayout.closeLastFragment(!forceWithoutAnimation);
|
|
|
|
}
|
2014-11-17 22:04:31 +00:00
|
|
|
actionBarLayout.presentFragment(fragment, actionBarLayout.fragmentsStack.size() > 1, forceWithoutAnimation, false);
|
|
|
|
return false;
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
} else if (layout != layersActionBarLayout) {
|
|
|
|
layersActionBarLayout.setVisibility(View.VISIBLE);
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (fragment instanceof LoginActivity) {
|
2014-09-25 03:54:35 +00:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
shadowTabletSide.setVisibility(View.GONE);
|
2014-09-24 02:17:27 +00:00
|
|
|
shadowTablet.setBackgroundColor(0x00000000);
|
|
|
|
} else {
|
|
|
|
shadowTablet.setBackgroundColor(0x7F000000);
|
|
|
|
}
|
2014-09-28 13:37:26 +00:00
|
|
|
layersActionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, false);
|
2014-09-24 02:17:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity));
|
2014-09-24 02:17:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (fragment instanceof MessagesActivity) {
|
|
|
|
MessagesActivity messagesActivity = (MessagesActivity)fragment;
|
|
|
|
if (messagesActivity.getDelegate() == null && layout != actionBarLayout) {
|
|
|
|
actionBarLayout.removeAllFragments();
|
|
|
|
actionBarLayout.addFragmentToStack(fragment);
|
|
|
|
layersActionBarLayout.removeAllFragments();
|
|
|
|
layersActionBarLayout.setVisibility(View.GONE);
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true);
|
2014-09-25 03:54:35 +00:00
|
|
|
if (!tabletFullSize) {
|
|
|
|
shadowTabletSide.setVisibility(View.VISIBLE);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (rightActionBarLayout.fragmentsStack.isEmpty()) {
|
2014-09-25 03:54:35 +00:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (fragment instanceof ChatActivity) {
|
2014-09-25 03:54:35 +00:00
|
|
|
if (!tabletFullSize && layout != rightActionBarLayout) {
|
2014-09-24 02:17:27 +00:00
|
|
|
rightActionBarLayout.setVisibility(View.VISIBLE);
|
2014-09-25 03:54:35 +00:00
|
|
|
backgroundTablet.setVisibility(View.GONE);
|
2014-09-24 02:17:27 +00:00
|
|
|
rightActionBarLayout.removeAllFragments();
|
|
|
|
rightActionBarLayout.addFragmentToStack(fragment);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
layersActionBarLayout.closeLastFragment(true);
|
|
|
|
}
|
2014-09-24 02:17:27 +00:00
|
|
|
return false;
|
2014-09-25 03:54:35 +00:00
|
|
|
} else if (tabletFullSize && layout != actionBarLayout) {
|
|
|
|
actionBarLayout.addFragmentToStack(fragment);
|
2014-09-28 13:37:26 +00:00
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
layersActionBarLayout.closeLastFragment(true);
|
|
|
|
}
|
2014-09-25 03:54:35 +00:00
|
|
|
return false;
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
} else if (layout != layersActionBarLayout) {
|
|
|
|
layersActionBarLayout.setVisibility(View.VISIBLE);
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (fragment instanceof LoginActivity) {
|
2014-09-25 03:54:35 +00:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
shadowTabletSide.setVisibility(View.GONE);
|
2014-09-24 02:17:27 +00:00
|
|
|
shadowTablet.setBackgroundColor(0x00000000);
|
|
|
|
} else {
|
|
|
|
shadowTablet.setBackgroundColor(0x7F000000);
|
|
|
|
}
|
|
|
|
layersActionBarLayout.addFragmentToStack(fragment);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
2014-11-17 02:44:57 +00:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity));
|
2014-09-24 02:17:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean needCloseLastFragment(ActionBarLayout layout) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (layout == actionBarLayout && layout.fragmentsStack.size() <= 1) {
|
|
|
|
onFinish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
} else if (layout == rightActionBarLayout) {
|
2014-09-25 03:54:35 +00:00
|
|
|
if (!tabletFullSize) {
|
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-10-16 20:02:44 +00:00
|
|
|
} else if (layout == layersActionBarLayout && actionBarLayout.fragmentsStack.isEmpty() && layersActionBarLayout.fragmentsStack.size() == 1) {
|
2014-09-28 13:37:26 +00:00
|
|
|
onFinish();
|
|
|
|
finish();
|
|
|
|
return false;
|
2014-09-24 02:17:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (layout.fragmentsStack.size() <= 1) {
|
|
|
|
onFinish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRebuildAllFragments(ActionBarLayout layout) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (layout == layersActionBarLayout) {
|
|
|
|
rightActionBarLayout.rebuildAllFragmentViews(true);
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
actionBarLayout.rebuildAllFragmentViews(true);
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|