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-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-03-04 19:29:32 +00:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
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;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.TextView;
|
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;
|
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;
|
|
|
|
import org.telegram.android.MessagesController;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
|
|
|
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-06-03 23:31:48 +00:00
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarActivity;
|
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
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-03-04 20:04:57 +00:00
|
|
|
public class LaunchActivity extends ActionBarActivity implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate {
|
2013-10-25 15:19:00 +00:00
|
|
|
private boolean finished = false;
|
2013-12-20 19:25:49 +00:00
|
|
|
private String videoPath = null;
|
|
|
|
private String sendingText = null;
|
2014-06-20 00:18:13 +00:00
|
|
|
private ArrayList<Uri> photoPathsArray = null;
|
|
|
|
private ArrayList<String> documentsPathsArray = null;
|
|
|
|
private ArrayList<String> documentsOriginalPathsArray = null;
|
2014-03-22 22:31:55 +00:00
|
|
|
private ArrayList<TLRPC.User> contactsToSend = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
private int currentConnectionState;
|
|
|
|
|
|
|
|
@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-06-03 23:31:48 +00:00
|
|
|
super.onCreateFinish(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);
|
|
|
|
super.onCreateFinish(savedInstanceState);
|
|
|
|
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-06-03 23:31:48 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
|
|
|
if (resourceId > 0) {
|
2014-07-02 22:39:05 +00:00
|
|
|
AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(702, this);
|
2014-07-02 22:39:05 +00:00
|
|
|
currentConnectionState = ConnectionsManager.getInstance().getConnectionState();
|
2014-06-03 23:31:48 +00:00
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, 1234);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, 658);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, 701);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, 702);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, 703);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
if (fragmentsStack.isEmpty()) {
|
2014-06-13 10:42:21 +00:00
|
|
|
if (!UserConfig.isClientActivated()) {
|
2014-06-04 16:00:42 +00:00
|
|
|
addFragmentToStack(new LoginActivity());
|
2014-06-03 23:31:48 +00:00
|
|
|
} else {
|
2014-06-04 16:00:42 +00:00
|
|
|
addFragmentToStack(new MessagesActivity(null));
|
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-06-04 16:00:42 +00:00
|
|
|
if (addFragmentToStack(chat)) {
|
2014-03-26 20:16:28 +00:00
|
|
|
chat.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fragmentName.equals("settings")) {
|
|
|
|
SettingsActivity settings = new SettingsActivity();
|
2014-06-04 16:00:42 +00:00
|
|
|
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-06-04 16:00:42 +00:00
|
|
|
if (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) {
|
|
|
|
ChatProfileActivity profile = new ChatProfileActivity(args);
|
2014-06-04 16:00:42 +00:00
|
|
|
if (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")) {
|
|
|
|
SettingsWallpapersActivity settings = new SettingsWallpapersActivity();
|
2014-06-04 16:00:42 +00:00
|
|
|
addFragmentToStack(settings);
|
2014-03-26 20:16:28 +00:00
|
|
|
settings.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-10 09:27:49 +00:00
|
|
|
handleIntent(getIntent(), false, savedInstanceState != null);
|
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-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"));
|
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
|
|
|
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) {
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().chats.get(chatId);
|
|
|
|
if (chat != null) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
|
|
|
push_chat_id = chatId;
|
|
|
|
}
|
|
|
|
} else if (userId != 0) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(userId);
|
|
|
|
if (user != null) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
|
|
|
push_user_id = userId;
|
|
|
|
}
|
|
|
|
} else if (encId != 0) {
|
|
|
|
TLRPC.EncryptedChat chat = MessagesController.getInstance().encryptedChats.get(encId);
|
|
|
|
if (chat != null) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
|
|
|
push_enc_id = encId;
|
|
|
|
}
|
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);
|
|
|
|
if (presentFragment(fragment, false, 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);
|
|
|
|
if (presentFragment(fragment, false, 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);
|
|
|
|
if (presentFragment(fragment, false, true)) {
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
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-06-03 23:31:48 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.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-06-03 23:31:48 +00:00
|
|
|
MessagesActivity fragment = new MessagesActivity(args);
|
|
|
|
fragment.setDelegate(this);
|
|
|
|
presentFragment(fragment, false, true);
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
if (open_settings != 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new SettingsActivity(), false, 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-06-03 23:31:48 +00:00
|
|
|
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-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("scrollToTopOnResume", true);
|
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (lower_part != 0) {
|
|
|
|
if (lower_part > 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
args.putInt("user_id", lower_part);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (lower_part < 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
args.putInt("chat_id", -lower_part);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
args.putInt("enc_id", (int)(dialog_id >> 32));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
|
|
|
presentFragment(fragment, true);
|
2014-04-01 01:00:35 +00:00
|
|
|
if (videoPath != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
fragment.processSendingVideo(videoPath);
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
|
|
|
if (sendingText != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
fragment.processSendingText(sendingText);
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
if (photoPathsArray != null) {
|
|
|
|
fragment.processSendingPhotos(null, photoPathsArray);
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
if (documentsPathsArray != null) {
|
|
|
|
fragment.processSendingDocuments(documentsPathsArray, documentsOriginalPathsArray);
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
|
|
|
if (contactsToSend != null && !contactsToSend.isEmpty()) {
|
2014-03-22 22:31:55 +00:00
|
|
|
for (TLRPC.User user : contactsToSend) {
|
|
|
|
MessagesController.getInstance().sendMessage(user, dialog_id);
|
|
|
|
}
|
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-03-26 20:16:28 +00:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2014-06-03 23:31:48 +00:00
|
|
|
if (fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2014-03-26 20:16:28 +00:00
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.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();
|
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-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-06-12 15:53:20 +00:00
|
|
|
actionBar.setBackOverlayVisible(currentConnectionState != 0);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
protected void onFinish() {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finished = true;
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, 1234);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, 658);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, 701);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, 702);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, 703);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
2014-07-02 22:39:05 +00:00
|
|
|
AndroidUtilities.checkDisplaySize();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
|
|
|
if (id == 1234) {
|
2014-06-03 23:31:48 +00:00
|
|
|
for (BaseFragment fragment : fragmentsStack) {
|
2013-10-25 15:19:00 +00:00
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
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();
|
|
|
|
} else if (id == 658) {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (PhotoViewer.getInstance().isVisible()) {
|
|
|
|
PhotoViewer.getInstance().closePhoto(false);
|
|
|
|
}
|
|
|
|
Integer push_chat_id = (Integer)args[0];
|
|
|
|
Integer push_user_id = (Integer)args[1];
|
|
|
|
Integer push_enc_id = (Integer)args[2];
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (push_user_id != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
args2.putInt("user_id", push_user_id);
|
|
|
|
presentFragment(new ChatActivity(args2), false, true);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (push_chat_id != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
args2.putInt("chat_id", push_chat_id);
|
|
|
|
presentFragment(new ChatActivity(args2), false, true);
|
|
|
|
} else if (push_enc_id != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
args2.putInt("enc_id", push_enc_id);
|
|
|
|
presentFragment(new ChatActivity(args2), false, true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (id == 702) {
|
|
|
|
if (args[0] != this) {
|
2014-06-03 23:31:48 +00:00
|
|
|
onFinish();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (id == 703) {
|
|
|
|
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-06-12 15:53:20 +00:00
|
|
|
actionBar.setBackOverlayVisible(currentConnectionState != 0);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-12 15:53:20 +00:00
|
|
|
public void onOverlayShow(View view, BaseFragment fragment) {
|
|
|
|
if (view == null || fragment == null || fragmentsStack.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
View backStatusButton = view.findViewById(R.id.back_button);
|
|
|
|
TextView statusText = (TextView)view.findViewById(R.id.status_text);
|
|
|
|
backStatusButton.setVisibility(fragmentsStack.get(0) == fragment ? View.GONE : View.VISIBLE);
|
|
|
|
view.setEnabled(fragmentsStack.get(0) != fragment);
|
|
|
|
if (currentConnectionState == 1) {
|
|
|
|
statusText.setText(LocaleController.getString("WaitingForNetwork", R.string.WaitingForNetwork));
|
|
|
|
} else if (currentConnectionState == 2) {
|
|
|
|
statusText.setText(LocaleController.getString("Connecting", R.string.Connecting));
|
|
|
|
} else if (currentConnectionState == 3) {
|
|
|
|
statusText.setText(LocaleController.getString("Updating", R.string.Updating));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
try {
|
|
|
|
super.onSaveInstanceState(outState);
|
2014-06-03 23:31:48 +00:00
|
|
|
if (!fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
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");
|
|
|
|
} else if (lastFragment instanceof SettingsWallpapersActivity) {
|
|
|
|
outState.putString("fragment", "wallpapers");
|
2014-06-03 23:31:48 +00:00
|
|
|
} else if (lastFragment instanceof ChatProfileActivity && 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-06-06 23:35:21 +00:00
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
return super.onPreIme();
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory() {
|
|
|
|
super.onLowMemory();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|