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;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.NotificationManager;
|
2014-03-22 22:31:55 +00:00
|
|
|
import android.content.ContentResolver;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2014-03-04 19:29:32 +00:00
|
|
|
import android.database.Cursor;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.graphics.PixelFormat;
|
2014-03-04 19:29:32 +00:00
|
|
|
import android.net.Uri;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.os.Build;
|
|
|
|
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.support.v4.app.FragmentManager;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
import android.support.v7.app.ActionBarActivity;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
2014-02-04 18:36:55 +00:00
|
|
|
import android.widget.EditText;
|
2013-10-25 15:19:00 +00:00
|
|
|
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-03-22 22:31:55 +00:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-03-22 23:20:13 +00:00
|
|
|
import org.telegram.messenger.BuildVars;
|
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;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
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;
|
|
|
|
import org.telegram.objects.MessageObject;
|
|
|
|
import org.telegram.ui.Views.BaseFragment;
|
|
|
|
import org.telegram.ui.Views.NotificationView;
|
|
|
|
|
|
|
|
import net.hockeyapp.android.CrashManager;
|
|
|
|
import net.hockeyapp.android.UpdateManager;
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
2013-10-25 15:19:00 +00:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Method;
|
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;
|
|
|
|
private NotificationView notificationView;
|
2014-03-04 19:29:32 +00:00
|
|
|
private Uri photoPath = null;
|
2013-12-20 19:25:49 +00:00
|
|
|
private String videoPath = null;
|
|
|
|
private String sendingText = null;
|
2014-02-28 22:28:25 +00:00
|
|
|
private String documentPath = null;
|
2014-04-01 01:00:35 +00:00
|
|
|
private ArrayList<Uri> imagesPathArray = null;
|
|
|
|
private ArrayList<String> documentsPathArray = 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;
|
|
|
|
private View statusView;
|
|
|
|
private View backStatusButton;
|
|
|
|
private View statusBackground;
|
|
|
|
private TextView statusText;
|
2013-12-20 19:25:49 +00:00
|
|
|
private View containerView;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2014-03-22 22:31:55 +00:00
|
|
|
ApplicationLoader.postInitApplication();
|
|
|
|
|
2014-03-04 19:29:32 +00:00
|
|
|
this.setTheme(R.style.Theme_TMessages);
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
|
|
|
|
getWindow().setFormat(PixelFormat.RGB_565);
|
|
|
|
|
|
|
|
if (!UserConfig.clientActivated) {
|
|
|
|
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-03-04 19:29:32 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 23:00:38 +00:00
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
Intent intent2 = new Intent(this, LoginActivity.class);
|
|
|
|
startActivity(intent2);
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
|
|
|
if (resourceId > 0) {
|
|
|
|
Utilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
|
|
|
}
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(702, this);
|
|
|
|
currentConnectionState = ConnectionsManager.getInstance().connectionState;
|
2013-10-25 15:19:00 +00:00
|
|
|
for (BaseFragment fragment : ApplicationLoader.fragmentsStack) {
|
|
|
|
if (fragment.fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup)fragment.fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragment.fragmentView);
|
|
|
|
}
|
|
|
|
fragment.fragmentView = null;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
fragment.parentActivity = this;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
setContentView(R.layout.application_layout);
|
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);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, GalleryImageViewer.needShowAllMedia);
|
2013-10-25 15:19:00 +00:00
|
|
|
getSupportActionBar().setLogo(R.drawable.ab_icon_fixed2);
|
|
|
|
|
|
|
|
statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null);
|
|
|
|
statusBackground = statusView.findViewById(R.id.back_button_background);
|
|
|
|
backStatusButton = statusView.findViewById(R.id.back_button);
|
2013-12-20 19:25:49 +00:00
|
|
|
containerView = findViewById(R.id.container);
|
2013-10-25 15:19:00 +00:00
|
|
|
statusText = (TextView)statusView.findViewById(R.id.status_text);
|
|
|
|
statusBackground.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() > 1) {
|
|
|
|
onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (ApplicationLoader.fragmentsStack.isEmpty()) {
|
|
|
|
MessagesActivity fragment = new MessagesActivity();
|
|
|
|
fragment.onFragmentCreate();
|
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
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) {
|
|
|
|
ChatActivity chat = new ChatActivity();
|
|
|
|
chat.setArguments(args);
|
|
|
|
if (chat.onFragmentCreate()) {
|
|
|
|
ApplicationLoader.fragmentsStack.add(chat);
|
|
|
|
chat.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fragmentName.equals("settings")) {
|
|
|
|
SettingsActivity settings = new SettingsActivity();
|
|
|
|
settings.onFragmentCreate();
|
|
|
|
settings.restoreSelfArgs(savedInstanceState);
|
|
|
|
ApplicationLoader.fragmentsStack.add(settings);
|
|
|
|
} else if (fragmentName.equals("group")) {
|
|
|
|
if (args != null) {
|
|
|
|
GroupCreateFinalActivity group = new GroupCreateFinalActivity();
|
|
|
|
group.setArguments(args);
|
|
|
|
if (group.onFragmentCreate()) {
|
|
|
|
group.restoreSelfArgs(savedInstanceState);
|
|
|
|
ApplicationLoader.fragmentsStack.add(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fragmentName.equals("wallpapers")) {
|
|
|
|
SettingsWallpapersActivity settings = new SettingsWallpapersActivity();
|
|
|
|
settings.onFragmentCreate();
|
|
|
|
settings.restoreSelfArgs(savedInstanceState);
|
|
|
|
ApplicationLoader.fragmentsStack.add(settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void prepareForHideShowActionBar() {
|
|
|
|
try {
|
2013-12-20 19:25:49 +00:00
|
|
|
Class firstClass = getSupportActionBar().getClass();
|
|
|
|
Class aClass = firstClass.getSuperclass();
|
|
|
|
if (aClass == android.support.v7.app.ActionBar.class) {
|
|
|
|
Method method = firstClass.getDeclaredMethod("setShowHideAnimationEnabled", boolean.class);
|
2013-10-25 15:19:00 +00:00
|
|
|
method.invoke(getSupportActionBar(), false);
|
|
|
|
} else {
|
|
|
|
Field field = aClass.getDeclaredField("mActionBar");
|
|
|
|
field.setAccessible(true);
|
|
|
|
Method method = field.get(getSupportActionBar()).getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class);
|
|
|
|
method.invoke(field.get(getSupportActionBar()), false);
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
2014-02-04 18:36:55 +00:00
|
|
|
e.printStackTrace();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showActionBar() {
|
|
|
|
prepareForHideShowActionBar();
|
|
|
|
getSupportActionBar().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideActionBar() {
|
|
|
|
prepareForHideShowActionBar();
|
|
|
|
getSupportActionBar().hide();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
photoPath = null;
|
|
|
|
videoPath = null;
|
|
|
|
sendingText = null;
|
|
|
|
documentPath = null;
|
|
|
|
imagesPathArray = null;
|
|
|
|
documentsPathArray = null;
|
|
|
|
|
2014-03-10 09:27:49 +00:00
|
|
|
if (intent != null && intent.getAction() != null && !restore) {
|
2014-03-04 19:29:32 +00:00
|
|
|
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);
|
2014-03-22 22:31:55 +00:00
|
|
|
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
|
|
|
|
2014-03-04 19:29:32 +00:00
|
|
|
if (text != null && text.length() != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null && subject.length() != 0) {
|
|
|
|
text = subject + "\n" + text;
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
sendingText = text;
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
2014-03-22 22:31:55 +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;
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (args[0].startsWith("TEL")) {
|
|
|
|
String phone = PhoneFormat.stripExceptNumbers(args[1], true);
|
|
|
|
if (phone.length() > 0) {
|
|
|
|
phones.add(phone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
error = true;
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
} else {
|
|
|
|
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
if (parcelable == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String path = null;
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
|
|
|
}
|
|
|
|
if (parcelable != null && type != null && type.startsWith("image/")) {
|
2014-04-03 21:56:42 +00:00
|
|
|
String tempPath = Utilities.getPath((Uri)parcelable);
|
|
|
|
if (type.equals("image/gif") || tempPath != null && tempPath.endsWith(".gif")) {
|
2014-04-01 01:00:35 +00:00
|
|
|
try {
|
|
|
|
documentPath = Utilities.getPath((Uri)parcelable);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (documentPath == null) {
|
|
|
|
photoPath = (Uri) parcelable;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
photoPath = (Uri) parcelable;
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
} else {
|
|
|
|
path = Utilities.getPath((Uri)parcelable);
|
|
|
|
if (path != null) {
|
|
|
|
if (path.startsWith("file:")) {
|
|
|
|
path = path.replace("file://", "");
|
|
|
|
}
|
|
|
|
if (type != null && type.startsWith("video/")) {
|
|
|
|
videoPath = path;
|
|
|
|
} else {
|
|
|
|
documentPath = path;
|
|
|
|
}
|
|
|
|
} 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/")) {
|
2014-04-01 01:00:35 +00:00
|
|
|
for (Parcelable parcelable : uris) {
|
2014-03-04 19:29:32 +00:00
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
|
|
|
}
|
2014-04-03 21:56:42 +00:00
|
|
|
String tempPath = Utilities.getPath((Uri)parcelable);
|
|
|
|
if (type.equals("image/gif") || tempPath != null && tempPath.endsWith(".gif")) {
|
2014-04-01 01:00:35 +00:00
|
|
|
if (documentsPathArray == null) {
|
|
|
|
documentsPathArray = new ArrayList<String>();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
documentsPathArray.add(Utilities.getPath((Uri) parcelable));
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (imagesPathArray == null) {
|
|
|
|
imagesPathArray = new ArrayList<Uri>();
|
|
|
|
}
|
|
|
|
imagesPathArray.add((Uri) parcelable);
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-01 01:00:35 +00:00
|
|
|
for (Parcelable parcelable : uris) {
|
2014-03-04 19:29:32 +00:00
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
|
|
|
}
|
2014-04-01 01:00:35 +00:00
|
|
|
String path = Utilities.getPath((Uri) parcelable);
|
2014-03-04 19:29:32 +00:00
|
|
|
if (path != null) {
|
|
|
|
if (path.startsWith("file:")) {
|
|
|
|
path = path.replace("file://", "");
|
|
|
|
}
|
2014-04-01 01:00:35 +00:00
|
|
|
if (documentsPathArray == null) {
|
|
|
|
documentsPathArray = new ArrayList<String>();
|
|
|
|
}
|
|
|
|
documentsPathArray.add(path);
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
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-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2014-03-04 19:29:32 +00:00
|
|
|
push_user_id = userId;
|
|
|
|
}
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) {
|
|
|
|
open_settings = 1;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
if (getIntent().getAction() != null && getIntent().getAction().startsWith("com.tmessages.openchat") && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0 && !restore) {
|
2014-03-04 19:29:32 +00:00
|
|
|
int chatId = getIntent().getIntExtra("chatId", 0);
|
|
|
|
int userId = getIntent().getIntExtra("userId", 0);
|
|
|
|
int encId = getIntent().getIntExtra("encId", 0);
|
|
|
|
if (chatId != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().chats.get(chatId);
|
2014-03-04 19:29:32 +00:00
|
|
|
if (chat != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2014-03-04 19:29:32 +00:00
|
|
|
push_chat_id = chatId;
|
|
|
|
}
|
|
|
|
} else if (userId != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(userId);
|
2014-03-04 19:29:32 +00:00
|
|
|
if (user != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2014-03-04 19:29:32 +00:00
|
|
|
push_user_id = userId;
|
|
|
|
}
|
|
|
|
} else if (encId != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.EncryptedChat chat = MessagesController.getInstance().encryptedChats.get(encId);
|
2014-03-04 19:29:32 +00:00
|
|
|
if (chat != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2014-03-04 19:29:32 +00:00
|
|
|
push_enc_id = encId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (push_user_id != 0) {
|
|
|
|
if (push_user_id == UserConfig.clientUserId) {
|
|
|
|
open_settings = 1;
|
|
|
|
} else {
|
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("user_id", push_user_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
if (fragment.onFragmentCreate()) {
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
2013-12-20 19:25:49 +00:00
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (push_chat_id != 0) {
|
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("chat_id", push_chat_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
if (fragment.onFragmentCreate()) {
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
2013-12-20 19:25:49 +00:00
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
} else if (push_enc_id != 0) {
|
2013-10-25 15:19:00 +00:00
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("enc_id", push_enc_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
if (fragment.onFragmentCreate()) {
|
2014-03-04 19:29:32 +00:00
|
|
|
pushOpened = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
2013-12-20 19:25:49 +00:00
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
if (videoPath != null || photoPath != null || sendingText != null || documentPath != null || documentsPathArray != null || imagesPathArray != null || contactsToSend != null) {
|
2014-03-04 19:29:32 +00:00
|
|
|
MessagesActivity fragment = new MessagesActivity();
|
|
|
|
fragment.selectAlertString = R.string.ForwardMessagesTo;
|
2014-03-22 22:31:55 +00:00
|
|
|
fragment.selectAlertStringDesc = "ForwardMessagesTo";
|
2014-03-04 19:29:32 +00:00
|
|
|
fragment.animationType = 1;
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
|
|
|
fragment.setArguments(args);
|
|
|
|
fragment.delegate = this;
|
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
|
|
|
fragment.onFragmentCreate();
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()).commitAllowingStateLoss();
|
|
|
|
pushOpened = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
if (open_settings != 0) {
|
|
|
|
SettingsActivity fragment = new SettingsActivity();
|
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
|
|
|
fragment.onFragmentCreate();
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings").commitAllowingStateLoss();
|
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) {
|
|
|
|
BaseFragment fragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()).commitAllowingStateLoss();
|
|
|
|
}
|
|
|
|
|
|
|
|
getIntent().setAction(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
public void didSelectDialog(MessagesActivity messageFragment, long dialog_id) {
|
|
|
|
if (dialog_id != 0) {
|
|
|
|
int lower_part = (int)dialog_id;
|
|
|
|
|
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
if (lower_part != 0) {
|
|
|
|
if (lower_part > 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2013-10-25 15:19:00 +00:00
|
|
|
bundle.putInt("user_id", lower_part);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
fragment.scrollToTopOnResume = true;
|
2013-12-20 19:25:49 +00:00
|
|
|
presentFragment(fragment, "chat" + Math.random(), true, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (lower_part < 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2013-10-25 15:19:00 +00:00
|
|
|
bundle.putInt("chat_id", -lower_part);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
fragment.scrollToTopOnResume = true;
|
2013-12-20 19:25:49 +00:00
|
|
|
presentFragment(fragment, "chat" + Math.random(), true, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2013-10-25 15:19:00 +00:00
|
|
|
int chat_id = (int)(dialog_id >> 32);
|
|
|
|
bundle.putInt("enc_id", chat_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
fragment.scrollToTopOnResume = true;
|
2013-12-20 19:25:49 +00:00
|
|
|
presentFragment(fragment, "chat" + Math.random(), true, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
if (photoPath != null) {
|
2014-03-04 19:29:32 +00:00
|
|
|
fragment.processSendingPhoto(null, photoPath);
|
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
|
|
|
}
|
|
|
|
if (documentPath != null) {
|
2014-02-28 22:28:25 +00:00
|
|
|
fragment.processSendingDocument(documentPath);
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
|
|
|
if (imagesPathArray != null) {
|
2014-03-04 19:29:32 +00:00
|
|
|
for (Uri path : imagesPathArray) {
|
|
|
|
fragment.processSendingPhoto(null, path);
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
|
|
|
if (documentsPathArray != null) {
|
2014-02-28 22:28:25 +00:00
|
|
|
for (String path : documentsPathArray) {
|
|
|
|
fragment.processSendingDocument(path);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
photoPath = null;
|
|
|
|
videoPath = null;
|
|
|
|
sendingText = null;
|
2014-02-28 22:28:25 +00:00
|
|
|
documentPath = null;
|
|
|
|
imagesPathArray = null;
|
|
|
|
documentsPathArray = null;
|
2014-03-22 22:31:55 +00:00
|
|
|
contactsToSend = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkForCrashes() {
|
2014-03-22 23:20:13 +00:00
|
|
|
CrashManager.register(this, BuildVars.HOCKEY_APP_HASH);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkForUpdates() {
|
2014-03-22 23:20:13 +00:00
|
|
|
if (BuildVars.DEBUG_VERSION) {
|
|
|
|
UpdateManager.register(this, BuildVars.HOCKEY_APP_HASH);
|
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);
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
ApplicationLoader.lastPauseTime = System.currentTimeMillis();
|
|
|
|
if (notificationView != null) {
|
|
|
|
notificationView.hide(false);
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
View focusView = getCurrentFocus();
|
|
|
|
if (focusView instanceof EditText) {
|
|
|
|
focusView.clearFocus();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
processOnFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2013-11-04 12:31:01 +00:00
|
|
|
if (notificationView == null && getLayoutInflater() != null) {
|
|
|
|
notificationView = (NotificationView) getLayoutInflater().inflate(R.layout.notification_layout, null);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
fixLayout();
|
|
|
|
checkForCrashes();
|
|
|
|
checkForUpdates();
|
2013-12-20 19:25:49 +00:00
|
|
|
ApplicationLoader.resetLastPauseTime();
|
|
|
|
supportInvalidateOptionsMenu();
|
2013-10-25 15:19:00 +00:00
|
|
|
updateActionBar();
|
|
|
|
try {
|
|
|
|
NotificationManager mNotificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
mNotificationManager.cancel(1);
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().currentPushMessage = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
} catch (Exception e) {
|
2013-12-20 19:25:49 +00:00
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processOnFinish() {
|
|
|
|
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);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, GalleryImageViewer.needShowAllMedia);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (notificationView != null) {
|
|
|
|
notificationView.hide(false);
|
|
|
|
notificationView.destroy();
|
|
|
|
notificationView = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
2014-02-28 22:28:25 +00:00
|
|
|
Utilities.checkDisplaySize();
|
2013-10-25 15:19:00 +00:00
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayout() {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (containerView != null) {
|
|
|
|
ViewTreeObserver obs = containerView.getViewTreeObserver();
|
2013-10-25 15:19:00 +00:00
|
|
|
obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
|
@Override
|
|
|
|
public void onGlobalLayout() {
|
|
|
|
WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
2013-12-20 19:25:49 +00:00
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
int height;
|
|
|
|
int currentActionBarHeight = getSupportActionBar().getHeight();
|
2013-12-26 16:46:13 +00:00
|
|
|
if (currentActionBarHeight != Utilities.dp(48) && currentActionBarHeight != Utilities.dp(40)) {
|
2013-10-25 15:19:00 +00:00
|
|
|
height = currentActionBarHeight;
|
|
|
|
} else {
|
2013-12-26 16:46:13 +00:00
|
|
|
height = Utilities.dp(48);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
2013-12-26 16:46:13 +00:00
|
|
|
height = Utilities.dp(40);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notificationView != null) {
|
2013-12-26 16:46:13 +00:00
|
|
|
notificationView.applyOrientationPaddings(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < 16) {
|
2013-12-20 19:25:49 +00:00
|
|
|
containerView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
containerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
|
|
|
if (id == 1234) {
|
|
|
|
for (BaseFragment fragment : ApplicationLoader.fragmentsStack) {
|
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
ApplicationLoader.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);
|
|
|
|
processOnFinish();
|
|
|
|
finish();
|
|
|
|
} else if (id == GalleryImageViewer.needShowAllMedia) {
|
|
|
|
long dialog_id = (Long)args[0];
|
|
|
|
MediaActivity fragment = new MediaActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
if (dialog_id != 0) {
|
|
|
|
bundle.putLong("dialog_id", dialog_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
presentFragment(fragment, "media_" + dialog_id, false);
|
|
|
|
}
|
|
|
|
} else if (id == 658) {
|
2014-03-22 22:31:55 +00:00
|
|
|
Integer push_user_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_user_id", 0);
|
|
|
|
Integer push_chat_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_chat_id", 0);
|
|
|
|
Integer push_enc_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_enc_id", 0);
|
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);
|
2013-10-25 15:19:00 +00:00
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("user_id", push_user_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
if (fragment.onFragmentCreate()) {
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() > 0) {
|
|
|
|
BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
lastFragment.willBeHidden();
|
|
|
|
}
|
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
2013-12-20 19:25:49 +00:00
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
|
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);
|
2013-10-25 15:19:00 +00:00
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("chat_id", push_chat_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
if (fragment.onFragmentCreate()) {
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() > 0) {
|
|
|
|
BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
lastFragment.willBeHidden();
|
|
|
|
}
|
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
2013-12-20 19:25:49 +00:00
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (push_enc_id != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
2013-10-25 15:19:00 +00:00
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("enc_id", push_enc_id);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
if (fragment.onFragmentCreate()) {
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() > 0) {
|
|
|
|
BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
lastFragment.willBeHidden();
|
|
|
|
}
|
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
2013-12-20 19:25:49 +00:00
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == 701) {
|
|
|
|
if (notificationView != null) {
|
|
|
|
MessageObject message = (MessageObject)args[0];
|
|
|
|
notificationView.show(message);
|
|
|
|
}
|
|
|
|
} else if (id == 702) {
|
|
|
|
if (args[0] != this) {
|
|
|
|
processOnFinish();
|
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
updateActionBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
public void fixBackButton() {
|
|
|
|
if(android.os.Build.VERSION.SDK_INT == 19) {
|
|
|
|
//workaround for back button dissapear
|
|
|
|
try {
|
|
|
|
Class firstClass = getSupportActionBar().getClass();
|
|
|
|
Class aClass = firstClass.getSuperclass();
|
|
|
|
if (aClass == android.support.v7.app.ActionBar.class) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Field field = aClass.getDeclaredField("mActionBar");
|
|
|
|
field.setAccessible(true);
|
|
|
|
android.app.ActionBar bar = (android.app.ActionBar)field.get(getSupportActionBar());
|
|
|
|
|
|
|
|
field = bar.getClass().getDeclaredField("mActionView");
|
|
|
|
field.setAccessible(true);
|
|
|
|
View v = (View)field.get(bar);
|
|
|
|
aClass = v.getClass();
|
|
|
|
|
|
|
|
field = aClass.getDeclaredField("mHomeLayout");
|
|
|
|
field.setAccessible(true);
|
|
|
|
v = (View)field.get(v);
|
|
|
|
v.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
public void updateActionBar() {
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseFragment currentFragment = null;
|
|
|
|
if (!ApplicationLoader.fragmentsStack.isEmpty()) {
|
|
|
|
currentFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
}
|
|
|
|
boolean canApplyLoading = true;
|
|
|
|
if (currentFragment != null && (currentConnectionState == 0 || !currentFragment.canApplyUpdateStatus() || statusView == null)) {
|
|
|
|
currentFragment.applySelfActionBar();
|
|
|
|
canApplyLoading = false;
|
|
|
|
}
|
|
|
|
if (canApplyLoading) {
|
|
|
|
if (statusView != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
statusView.setVisibility(View.VISIBLE);
|
2013-10-25 15:19:00 +00:00
|
|
|
actionBar.setDisplayShowTitleEnabled(false);
|
|
|
|
actionBar.setDisplayShowHomeEnabled(false);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(false);
|
|
|
|
actionBar.setDisplayUseLogoEnabled(false);
|
|
|
|
actionBar.setDisplayShowCustomEnabled(true);
|
|
|
|
actionBar.setSubtitle(null);
|
|
|
|
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() > 1) {
|
|
|
|
backStatusButton.setVisibility(View.VISIBLE);
|
|
|
|
statusBackground.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
backStatusButton.setVisibility(View.GONE);
|
|
|
|
statusBackground.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentConnectionState == 1) {
|
2013-12-20 19:25:49 +00:00
|
|
|
statusText.setText(getString(R.string.WaitingForNetwork));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (currentConnectionState == 2) {
|
2013-12-20 19:25:49 +00:00
|
|
|
statusText.setText(getString(R.string.Connecting));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (currentConnectionState == 3) {
|
2013-12-20 19:25:49 +00:00
|
|
|
statusText.setText(getString(R.string.Updating));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
if (actionBar.getCustomView() != statusView) {
|
|
|
|
actionBar.setCustomView(statusView);
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (statusView.getLayoutParams() instanceof android.support.v7.app.ActionBar.LayoutParams) {
|
|
|
|
android.support.v7.app.ActionBar.LayoutParams statusParams = (android.support.v7.app.ActionBar.LayoutParams)statusView.getLayoutParams();
|
2014-02-04 18:36:55 +00:00
|
|
|
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
|
|
|
|
statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
|
2014-03-22 22:31:55 +00:00
|
|
|
if (statusParams.height == 0) {
|
|
|
|
statusParams.height = actionBar.getHeight();
|
|
|
|
}
|
|
|
|
if (statusParams.width <= 0) {
|
|
|
|
statusParams.width = Utilities.dp(100);
|
|
|
|
}
|
|
|
|
statusParams.topMargin = 0;
|
|
|
|
statusParams.leftMargin = 0;
|
2013-12-20 19:25:49 +00:00
|
|
|
statusView.setLayoutParams(statusParams);
|
|
|
|
} else if (statusView.getLayoutParams() instanceof android.app.ActionBar.LayoutParams) {
|
|
|
|
android.app.ActionBar.LayoutParams statusParams = (android.app.ActionBar.LayoutParams)statusView.getLayoutParams();
|
2014-02-04 18:36:55 +00:00
|
|
|
statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST));
|
|
|
|
statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54));
|
2014-03-22 22:31:55 +00:00
|
|
|
if (statusParams.height == 0) {
|
|
|
|
statusParams.height = actionBar.getHeight();
|
|
|
|
}
|
|
|
|
if (statusParams.width <= 0) {
|
|
|
|
statusParams.width = Utilities.dp(100);
|
|
|
|
}
|
|
|
|
statusParams.topMargin = 0;
|
|
|
|
statusParams.leftMargin = 0;
|
2013-12-20 19:25:49 +00:00
|
|
|
statusView.setLayoutParams(statusParams);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void presentFragment(BaseFragment fragment, String tag, boolean bySwipe) {
|
|
|
|
presentFragment(fragment, tag, false, bySwipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void presentFragment(BaseFragment fragment, String tag, boolean removeLast, boolean bySwipe) {
|
|
|
|
if (getCurrentFocus() != null) {
|
|
|
|
Utilities.hideKeyboard(getCurrentFocus());
|
|
|
|
}
|
|
|
|
if (!fragment.onFragmentCreate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseFragment current = null;
|
|
|
|
if (!ApplicationLoader.fragmentsStack.isEmpty()) {
|
|
|
|
current = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
}
|
|
|
|
if (current != null) {
|
|
|
|
current.willBeHidden();
|
|
|
|
}
|
|
|
|
FragmentManager fm = getSupportFragmentManager();
|
|
|
|
FragmentTransaction fTrans = fm.beginTransaction();
|
|
|
|
if (removeLast && current != null) {
|
|
|
|
ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
current.onFragmentDestroy();
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean animations = preferences.getBoolean("view_animations", true);
|
|
|
|
if (animations) {
|
|
|
|
if (bySwipe) {
|
|
|
|
fTrans.setCustomAnimations(R.anim.slide_left, R.anim.no_anim);
|
|
|
|
} else {
|
|
|
|
fTrans.setCustomAnimations(R.anim.scale_in, R.anim.no_anim);
|
|
|
|
}
|
|
|
|
}
|
2014-03-10 09:27:49 +00:00
|
|
|
try {
|
|
|
|
fTrans.replace(R.id.container, fragment, tag);
|
|
|
|
fTrans.commitAllowingStateLoss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeFromStack(BaseFragment fragment) {
|
|
|
|
ApplicationLoader.fragmentsStack.remove(fragment);
|
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishFragment(boolean bySwipe) {
|
|
|
|
if (getCurrentFocus() != null) {
|
|
|
|
Utilities.hideKeyboard(getCurrentFocus());
|
|
|
|
}
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() < 2) {
|
|
|
|
for (BaseFragment fragment : ApplicationLoader.fragmentsStack) {
|
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
ApplicationLoader.fragmentsStack.clear();
|
|
|
|
MessagesActivity fragment = new MessagesActivity();
|
|
|
|
fragment.onFragmentCreate();
|
|
|
|
ApplicationLoader.fragmentsStack.add(fragment);
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chats").commitAllowingStateLoss();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseFragment fragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
BaseFragment prev = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 2);
|
|
|
|
FragmentManager fm = getSupportFragmentManager();
|
|
|
|
FragmentTransaction fTrans = fm.beginTransaction();
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean animations = preferences.getBoolean("view_animations", true);
|
|
|
|
if (animations) {
|
|
|
|
if (bySwipe) {
|
|
|
|
fTrans.setCustomAnimations(R.anim.no_anim_show, R.anim.slide_right_away);
|
|
|
|
} else {
|
|
|
|
fTrans.setCustomAnimations(R.anim.no_anim_show, R.anim.scale_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fTrans.replace(R.id.container, prev, prev.getTag());
|
|
|
|
fTrans.commitAllowingStateLoss();
|
|
|
|
ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (ApplicationLoader.fragmentsStack.size() == 1) {
|
|
|
|
ApplicationLoader.fragmentsStack.get(0).onFragmentDestroy();
|
|
|
|
ApplicationLoader.fragmentsStack.clear();
|
|
|
|
processOnFinish();
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ApplicationLoader.fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
if (lastFragment.onBackPressed()) {
|
|
|
|
finishFragment(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
try {
|
|
|
|
super.onSaveInstanceState(outState);
|
2014-03-26 20:16:28 +00:00
|
|
|
if (!ApplicationLoader.fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1);
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
lastFragment.saveSelfArgs(outState);
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|