2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2013-10-25 17:19:00 +02: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).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2013-10-25 17:19:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
import android.Manifest;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2020-09-30 15:48:47 +02:00
|
|
|
import android.animation.ObjectAnimator;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.app.Activity;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.app.ActivityManager;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.content.pm.PackageManager;
|
2014-09-25 05:54:35 +02:00
|
|
|
import android.content.res.Configuration;
|
2014-03-04 20:29:32 +01:00
|
|
|
import android.database.Cursor;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.graphics.Bitmap;
|
2020-06-25 17:28:55 +02:00
|
|
|
import android.graphics.Canvas;
|
2014-11-07 11:23:17 +01:00
|
|
|
import android.graphics.Point;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.graphics.Shader;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2020-02-22 21:31:44 +01:00
|
|
|
import android.location.Location;
|
2014-03-04 20:29:32 +01:00
|
|
|
import android.net.Uri;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.os.Build;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.os.Bundle;
|
2014-03-04 20:29:32 +01:00
|
|
|
import android.os.Parcelable;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.os.StatFs;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.os.SystemClock;
|
2014-03-22 23:31:55 +01:00
|
|
|
import android.provider.ContactsContract;
|
2020-11-27 20:32:39 +01:00
|
|
|
import android.se.omapi.Session;
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.text.TextUtils;
|
2020-09-30 15:48:47 +02:00
|
|
|
import android.util.Base64;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.view.ActionMode;
|
2014-10-01 21:55:24 +02:00
|
|
|
import android.view.KeyEvent;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.view.Menu;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.view.ViewAnimationUtils;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.Window;
|
2014-11-17 03:44:57 +01:00
|
|
|
import android.view.WindowManager;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.widget.FrameLayout;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.widget.ImageView;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.widget.LinearLayout;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.widget.RelativeLayout;
|
2014-03-04 20:29:32 +01:00
|
|
|
import android.widget.Toast;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2020-07-27 02:58:40 +02:00
|
|
|
import androidx.core.content.pm.ShortcutInfoCompat;
|
|
|
|
import androidx.core.content.pm.ShortcutManagerCompat;
|
2020-10-09 19:35:17 +02:00
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
2020-06-25 17:28:55 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
2020-10-09 19:35:17 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2020-06-25 17:28:55 +02:00
|
|
|
|
|
|
|
import com.v2ray.ang.V2RayConfig;
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2019-07-18 15:01:39 +02:00
|
|
|
import org.telegram.messenger.AccountInstance;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.BuildVars;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.ChatObject;
|
|
|
|
import org.telegram.messenger.ContactsController;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.messenger.ContactsLoadingObserver;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
2015-10-29 18:10:07 +01:00
|
|
|
import org.telegram.messenger.ImageLoader;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.MediaController;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.messenger.MediaDataController;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.messenger.MessageObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
|
|
|
import org.telegram.messenger.R;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.SendMessagesHelper;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.UserObject;
|
2016-03-06 02:49:31 +01:00
|
|
|
import org.telegram.messenger.Utilities;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.messenger.browser.Browser;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.camera.CameraController;
|
2020-08-14 18:58:22 +02:00
|
|
|
import org.telegram.messenger.voip.VoIPPendingCall;
|
2020-08-15 23:06:36 +02:00
|
|
|
import org.telegram.messenger.voip.VoIPService;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBarLayout;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
|
|
|
import org.telegram.ui.ActionBar.DrawerLayoutContainer;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.Adapters.DrawerLayoutAdapter;
|
|
|
|
import org.telegram.ui.Cells.DrawerActionCheckCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Cells.DrawerAddCell;
|
2020-07-26 10:03:38 +02:00
|
|
|
import org.telegram.ui.Cells.DrawerProfileCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Cells.DrawerUserCell;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.ui.Cells.LanguageCell;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Components.AlertsCreator;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.ui.Components.AudioPlayerAlert;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Components.BlockingUpdateView;
|
2020-03-30 14:00:09 +02:00
|
|
|
import org.telegram.ui.Components.Easings;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.EmbedBottomSheet;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.ui.Components.JoinGroupAlert;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2015-02-26 02:32:51 +01:00
|
|
|
import org.telegram.ui.Components.PasscodeView;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.Components.PhonebookShareAlert;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.ui.Components.PipRoundVideoView;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.ui.Components.RLottieDrawable;
|
|
|
|
import org.telegram.ui.Components.RLottieImageView;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Components.SharingLocationsAlert;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.Components.SideMenultItemAnimator;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.ui.Components.StickersAlert;
|
2020-06-25 17:28:55 +02:00
|
|
|
import org.telegram.ui.Components.Switch;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Components.TermsOfServiceView;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.ThemeEditorView;
|
2020-11-27 20:32:39 +01:00
|
|
|
import org.telegram.ui.Components.UndoView;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.ui.Components.voip.VoIPHelper;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
import java.io.File;
|
2014-03-04 20:29:32 +01:00
|
|
|
import java.util.ArrayList;
|
2016-04-22 15:49:00 +02:00
|
|
|
import java.util.HashMap;
|
2016-03-06 02:49:31 +01:00
|
|
|
import java.util.List;
|
2014-04-05 01:00:38 +02:00
|
|
|
import java.util.Map;
|
2020-01-12 10:34:25 +01:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2020-11-27 20:32:39 +01:00
|
|
|
import kotlin.Unit;
|
2020-09-03 17:37:42 +02:00
|
|
|
import kotlin.text.StringsKt;
|
2020-11-27 20:32:39 +01:00
|
|
|
import tw.nekomimi.nekogram.BottomBuilder;
|
2020-08-10 12:49:33 +02:00
|
|
|
import tw.nekomimi.nekogram.ExternalGcm;
|
2020-06-25 17:28:55 +02:00
|
|
|
import tw.nekomimi.nekogram.NekoConfig;
|
|
|
|
import tw.nekomimi.nekogram.NekoXConfig;
|
2020-05-28 09:29:33 +02:00
|
|
|
import tw.nekomimi.nekogram.settings.NekoSettingsActivity;
|
2020-06-25 17:28:55 +02:00
|
|
|
import tw.nekomimi.nekogram.sub.SubInfo;
|
|
|
|
import tw.nekomimi.nekogram.sub.SubManager;
|
|
|
|
import tw.nekomimi.nekogram.utils.AlertUtil;
|
|
|
|
import tw.nekomimi.nekogram.utils.PrivacyUtil;
|
|
|
|
import tw.nekomimi.nekogram.utils.ProxyUtil;
|
|
|
|
import tw.nekomimi.nekogram.utils.UIUtil;
|
2019-07-29 17:22:59 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
private static final String EXTRA_ACTION_TOKEN = "actions.fulfillment.extra.ACTION_TOKEN";
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
private boolean finished;
|
2020-01-12 10:34:25 +01:00
|
|
|
final private Pattern locationRegex = Pattern.compile("geo: ?(-?\\d+\\.\\d+),(-?\\d+\\.\\d+)(,|\\?z=)(-?\\d+)");
|
|
|
|
private Location sendingLocation;
|
2014-11-17 03:44:57 +01:00
|
|
|
private String videoPath;
|
|
|
|
private String sendingText;
|
2017-12-08 18:35:59 +01:00
|
|
|
private ArrayList<SendMessagesHelper.SendingMediaInfo> photoPathsArray;
|
2014-11-17 03:44:57 +01:00
|
|
|
private ArrayList<String> documentsPathsArray;
|
2014-11-21 01:14:44 +01:00
|
|
|
private ArrayList<Uri> documentsUrisArray;
|
|
|
|
private String documentsMimeType;
|
2014-11-17 03:44:57 +01:00
|
|
|
private ArrayList<String> documentsOriginalPathsArray;
|
|
|
|
private ArrayList<TLRPC.User> contactsToSend;
|
2018-07-30 04:07:02 +02:00
|
|
|
private Uri contactsToSendUri;
|
2013-10-25 17:19:00 +02:00
|
|
|
private int currentConnectionState;
|
2015-01-02 23:15:07 +01:00
|
|
|
private static ArrayList<BaseFragment> mainFragmentsStack = new ArrayList<>();
|
|
|
|
private static ArrayList<BaseFragment> layerFragmentsStack = new ArrayList<>();
|
|
|
|
private static ArrayList<BaseFragment> rightFragmentsStack = new ArrayList<>();
|
2015-11-26 22:04:02 +01:00
|
|
|
private ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener;
|
2014-09-24 04:17:27 +02:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
private ActionMode visibleActionMode;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private ImageView themeSwitchImageView;
|
2020-09-30 15:48:47 +02:00
|
|
|
private View themeSwitchSunView;
|
|
|
|
private RLottieDrawable themeSwitchSunDrawable;
|
2014-11-17 03:44:57 +01:00
|
|
|
private ActionBarLayout actionBarLayout;
|
|
|
|
private ActionBarLayout layersActionBarLayout;
|
|
|
|
private ActionBarLayout rightActionBarLayout;
|
|
|
|
private FrameLayout shadowTablet;
|
|
|
|
private FrameLayout shadowTabletSide;
|
2016-10-11 13:57:01 +02:00
|
|
|
private View backgroundTablet;
|
2020-09-30 15:48:47 +02:00
|
|
|
private FrameLayout frameLayout;
|
2015-05-03 13:48:36 +02:00
|
|
|
protected DrawerLayoutContainer drawerLayoutContainer;
|
2014-11-17 03:44:57 +01:00
|
|
|
private DrawerLayoutAdapter drawerLayoutAdapter;
|
2015-02-26 02:32:51 +01:00
|
|
|
private PasscodeView passcodeView;
|
2018-07-30 04:07:02 +02:00
|
|
|
private TermsOfServiceView termsOfServiceView;
|
|
|
|
private BlockingUpdateView blockingUpdateView;
|
2015-05-03 13:48:36 +02:00
|
|
|
private AlertDialog visibleDialog;
|
2018-07-30 04:07:02 +02:00
|
|
|
private AlertDialog proxyErrorDialog;
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView sideMenu;
|
2020-03-30 14:00:09 +02:00
|
|
|
private SideMenultItemAnimator itemAnimator;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private AlertDialog localeDialog;
|
|
|
|
private boolean loadingLocaleDialog;
|
|
|
|
private HashMap<String, String> systemLocaleStrings;
|
|
|
|
private HashMap<String, String> englishLocaleStrings;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int currentAccount;
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private Intent passcodeSaveIntent;
|
|
|
|
private boolean passcodeSaveIntentIsNew;
|
|
|
|
private boolean passcodeSaveIntentIsRestore;
|
2014-11-07 21:10:12 +01:00
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
private boolean tabletFullSize;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private String loadingThemeFileName;
|
|
|
|
private String loadingThemeWallpaperName;
|
2019-12-31 14:08:08 +01:00
|
|
|
private TLRPC.TL_wallPaper loadingThemeWallpaper;
|
2019-09-10 12:56:11 +02:00
|
|
|
private Theme.ThemeInfo loadingThemeInfo;
|
|
|
|
private TLRPC.TL_theme loadingTheme;
|
2019-12-31 14:08:08 +01:00
|
|
|
private boolean loadingThemeAccent;
|
2019-09-10 12:56:11 +02:00
|
|
|
private AlertDialog loadingThemeProgressDialog;
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private Runnable lockRunnable;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2014-03-22 23:31:55 +01:00
|
|
|
ApplicationLoader.postInitApplication();
|
2016-10-11 13:57:01 +02:00
|
|
|
AndroidUtilities.checkDisplaySize(this, getResources().getConfiguration());
|
2018-07-30 04:07:02 +02:00
|
|
|
currentAccount = UserConfig.selectedAccount;
|
|
|
|
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
|
2014-03-04 20:29:32 +01:00
|
|
|
Intent intent = getIntent();
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean isProxy = false;
|
|
|
|
if (intent != null && intent.getAction() != null) {
|
|
|
|
if (Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
|
Uri uri = intent.getData();
|
|
|
|
if (uri != null) {
|
|
|
|
String url = uri.toString().toLowerCase();
|
2020-06-25 17:28:55 +02:00
|
|
|
isProxy = url.startsWith("tg:proxy") || url.startsWith("tg://proxy") || url.startsWith("tg:socks") || url.startsWith("tg://socks") ||
|
|
|
|
url.startsWith(V2RayConfig.VMESS_PROTOCOL) ||
|
|
|
|
url.startsWith(V2RayConfig.VMESS1_PROTOCOL) ||
|
|
|
|
url.startsWith(V2RayConfig.SS_PROTOCOL) ||
|
2020-10-20 11:15:14 +02:00
|
|
|
url.startsWith(V2RayConfig.SSR_PROTOCOL) ||
|
|
|
|
url.startsWith(V2RayConfig.TROJAN_PROTOCOL);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
2017-07-23 14:56:38 +02:00
|
|
|
long crashed_time = preferences.getLong("intro_crashed_time", 0);
|
|
|
|
boolean fromIntro = intent.getBooleanExtra("fromIntro", false);
|
|
|
|
if (fromIntro) {
|
2020-06-25 17:28:55 +02:00
|
|
|
preferences.edit().putLong("intro_crashed_time", 0).apply();
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!isProxy && Math.abs(crashed_time - System.currentTimeMillis()) >= 60 * 2 * 1000 && intent != null && !fromIntro) {
|
2017-07-23 14:56:38 +02:00
|
|
|
preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo2", MODE_PRIVATE);
|
2014-06-04 01:31:48 +02:00
|
|
|
Map<String, ?> state = preferences.getAll();
|
|
|
|
if (state.isEmpty()) {
|
|
|
|
Intent intent2 = new Intent(this, IntroActivity.class);
|
2017-07-08 18:32:04 +02:00
|
|
|
intent2.setData(intent.getData());
|
2014-06-04 01:31:48 +02:00
|
|
|
startActivity(intent2);
|
2014-09-24 04:17:27 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2014-06-04 01:31:48 +02:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2014-04-05 01:00:38 +02:00
|
|
|
}
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
|
setTheme(R.style.Theme_TMessages);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
try {
|
|
|
|
setTaskDescription(new ActivityManager.TaskDescription(null, null, Theme.getColor(Theme.key_actionBarDefault) | 0xff000000));
|
2019-03-03 21:40:48 +01:00
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
getWindow().setNavigationBarColor(0xff000000);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 00:13:31 +02:00
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
|
2020-06-25 17:28:55 +02:00
|
|
|
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture && !NekoXConfig.disableFlagSecure) {
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
|
AndroidUtilities.isInMultiwindow = isInMultiWindowMode();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.createChatResources(this, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (SharedConfig.passcodeHash.length() != 0 && SharedConfig.appLocked) {
|
2020-01-23 07:15:40 +01:00
|
|
|
SharedConfig.lastPauseTime = (int) (SystemClock.elapsedRealtime() / 1000);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
AndroidUtilities.fillStatusBarHeight(this);
|
|
|
|
actionBarLayout = new ActionBarLayout(this) {
|
|
|
|
@Override
|
|
|
|
public void setThemeAnimationValue(float value) {
|
|
|
|
super.setThemeAnimationValue(value);
|
|
|
|
if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
|
|
|
ArticleViewer.getInstance().updateThemeColors(value);
|
|
|
|
}
|
|
|
|
drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2020-01-03 16:45:22 +01:00
|
|
|
if (PhotoViewer.hasInstance()) {
|
|
|
|
PhotoViewer.getInstance().updateColors();
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
};
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
frameLayout = new FrameLayout(this);
|
2019-12-31 14:08:08 +01:00
|
|
|
setContentView(frameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
themeSwitchImageView = new ImageView(this);
|
|
|
|
themeSwitchImageView.setVisibility(View.GONE);
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
|
|
drawerLayoutContainer = new DrawerLayoutContainer(this);
|
2019-05-14 14:08:05 +02:00
|
|
|
drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2019-12-31 14:08:08 +01:00
|
|
|
frameLayout.addView(drawerLayoutContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
themeSwitchSunView = new View(this) {
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
if (themeSwitchSunDrawable != null) {
|
|
|
|
themeSwitchSunDrawable.draw(canvas);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
frameLayout.addView(themeSwitchSunView, LayoutHelper.createFrame(48, 48));
|
|
|
|
themeSwitchSunView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-11-17 03:44:57 +01:00
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
RelativeLayout launchLayout = new RelativeLayout(this) {
|
|
|
|
|
|
|
|
private boolean inLayout;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (inLayout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
inLayout = true;
|
|
|
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
setMeasuredDimension(width, height);
|
|
|
|
|
|
|
|
if (!AndroidUtilities.isInMultiwindow && (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
|
|
|
|
tabletFullSize = false;
|
|
|
|
int leftWidth = width / 100 * 35;
|
|
|
|
if (leftWidth < AndroidUtilities.dp(320)) {
|
|
|
|
leftWidth = AndroidUtilities.dp(320);
|
|
|
|
}
|
|
|
|
actionBarLayout.measure(MeasureSpec.makeMeasureSpec(leftWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
|
|
|
shadowTabletSide.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
|
|
|
rightActionBarLayout.measure(MeasureSpec.makeMeasureSpec(width - leftWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
|
|
|
} else {
|
|
|
|
tabletFullSize = true;
|
|
|
|
actionBarLayout.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
backgroundTablet.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
|
|
|
shadowTablet.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
2017-03-31 01:58:05 +02:00
|
|
|
layersActionBarLayout.measure(MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(530), width), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(528), height), MeasureSpec.EXACTLY));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
inLayout = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
int width = r - l;
|
|
|
|
int height = b - t;
|
|
|
|
|
|
|
|
if (!AndroidUtilities.isInMultiwindow && (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
|
|
|
|
int leftWidth = width / 100 * 35;
|
|
|
|
if (leftWidth < AndroidUtilities.dp(320)) {
|
|
|
|
leftWidth = AndroidUtilities.dp(320);
|
|
|
|
}
|
|
|
|
shadowTabletSide.layout(leftWidth, 0, leftWidth + shadowTabletSide.getMeasuredWidth(), shadowTabletSide.getMeasuredHeight());
|
|
|
|
actionBarLayout.layout(0, 0, actionBarLayout.getMeasuredWidth(), actionBarLayout.getMeasuredHeight());
|
|
|
|
rightActionBarLayout.layout(leftWidth, 0, leftWidth + rightActionBarLayout.getMeasuredWidth(), rightActionBarLayout.getMeasuredHeight());
|
|
|
|
} else {
|
|
|
|
actionBarLayout.layout(0, 0, actionBarLayout.getMeasuredWidth(), actionBarLayout.getMeasuredHeight());
|
|
|
|
}
|
|
|
|
int x = (width - layersActionBarLayout.getMeasuredWidth()) / 2;
|
2017-03-31 01:58:05 +02:00
|
|
|
int y = (height - layersActionBarLayout.getMeasuredHeight()) / 2;
|
2016-10-11 13:57:01 +02:00
|
|
|
layersActionBarLayout.layout(x, y, x + layersActionBarLayout.getMeasuredWidth(), y + layersActionBarLayout.getMeasuredHeight());
|
|
|
|
backgroundTablet.layout(0, 0, backgroundTablet.getMeasuredWidth(), backgroundTablet.getMeasuredHeight());
|
|
|
|
shadowTablet.layout(0, 0, shadowTablet.getMeasuredWidth(), shadowTablet.getMeasuredHeight());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
drawerLayoutContainer.addView(launchLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
|
|
|
|
backgroundTablet = new View(this);
|
|
|
|
BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(R.drawable.catstile);
|
|
|
|
drawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
|
|
|
|
backgroundTablet.setBackgroundDrawable(drawable);
|
|
|
|
launchLayout.addView(backgroundTablet, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
|
|
launchLayout.addView(actionBarLayout);
|
2014-09-24 04:17:27 +02:00
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
rightActionBarLayout = new ActionBarLayout(this);
|
|
|
|
rightActionBarLayout.init(rightFragmentsStack);
|
|
|
|
rightActionBarLayout.setDelegate(this);
|
2016-10-11 13:57:01 +02:00
|
|
|
launchLayout.addView(rightActionBarLayout);
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
|
|
shadowTabletSide = new FrameLayout(this);
|
|
|
|
shadowTabletSide.setBackgroundColor(0x40295274);
|
|
|
|
launchLayout.addView(shadowTabletSide);
|
|
|
|
|
|
|
|
shadowTablet = new FrameLayout(this);
|
2016-10-11 13:57:01 +02:00
|
|
|
shadowTablet.setVisibility(layerFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
|
2017-03-31 01:58:05 +02:00
|
|
|
shadowTablet.setBackgroundColor(0x7f000000);
|
2014-11-17 03:44:57 +01:00
|
|
|
launchLayout.addView(shadowTablet);
|
2018-08-27 10:33:11 +02:00
|
|
|
shadowTablet.setOnTouchListener((v, event) -> {
|
|
|
|
if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
float x = event.getX();
|
|
|
|
float y = event.getY();
|
2019-06-04 12:14:50 +02:00
|
|
|
int[] location = new int[2];
|
2018-08-27 10:33:11 +02:00
|
|
|
layersActionBarLayout.getLocationOnScreen(location);
|
|
|
|
int viewX = location[0];
|
|
|
|
int viewY = location[1];
|
|
|
|
|
|
|
|
if (layersActionBarLayout.checkTransitionAnimation() || 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--;
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
layersActionBarLayout.closeLastFragment(true);
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
return true;
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
return false;
|
2014-09-28 15:37:26 +02:00
|
|
|
});
|
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
shadowTablet.setOnClickListener(v -> {
|
2014-09-28 15:37:26 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
layersActionBarLayout = new ActionBarLayout(this);
|
2014-11-17 03:44:57 +01:00
|
|
|
layersActionBarLayout.setRemoveActionBarExtraHeight(true);
|
2014-09-24 04:17:27 +02:00
|
|
|
layersActionBarLayout.setBackgroundView(shadowTablet);
|
|
|
|
layersActionBarLayout.setUseAlphaAnimations(true);
|
|
|
|
layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow);
|
|
|
|
layersActionBarLayout.init(layerFragmentsStack);
|
|
|
|
layersActionBarLayout.setDelegate(this);
|
2014-11-17 03:44:57 +01:00
|
|
|
layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
|
2016-10-11 13:57:01 +02:00
|
|
|
layersActionBarLayout.setVisibility(layerFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
|
|
|
|
launchLayout.addView(layersActionBarLayout);
|
2014-11-17 03:44:57 +01:00
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
sideMenu = new RecyclerListView(this) {
|
|
|
|
@Override
|
|
|
|
public boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
|
|
|
int restore = -1;
|
|
|
|
if (itemAnimator != null && itemAnimator.isRunning() && itemAnimator.isAnimatingChild(child)) {
|
|
|
|
restore = canvas.save();
|
|
|
|
canvas.clipRect(0, itemAnimator.getAnimationClipTop(), getMeasuredWidth(), getMeasuredHeight());
|
|
|
|
}
|
|
|
|
boolean result = super.drawChild(canvas, child, drawingTime);
|
|
|
|
if (restore >= 0) {
|
|
|
|
canvas.restoreToCount(restore);
|
|
|
|
invalidate();
|
|
|
|
invalidateViews();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
itemAnimator = new SideMenultItemAnimator(sideMenu);
|
|
|
|
sideMenu.setItemAnimator(itemAnimator);
|
2017-03-31 01:58:05 +02:00
|
|
|
sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
|
|
|
|
sideMenu.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
2019-12-31 14:08:08 +01:00
|
|
|
sideMenu.setAllowItemsInteractionDuringAnimation(false);
|
2020-03-30 14:00:09 +02:00
|
|
|
sideMenu.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this, itemAnimator));
|
2017-03-31 01:58:05 +02:00
|
|
|
drawerLayoutContainer.setDrawerLayout(sideMenu);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) sideMenu.getLayoutParams();
|
2015-10-29 18:10:07 +01:00
|
|
|
Point screenSize = AndroidUtilities.getRealScreenSize();
|
2016-06-24 12:27:15 +02:00
|
|
|
layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(AndroidUtilities.dp(320), Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56));
|
2015-10-29 18:10:07 +01:00
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2017-03-31 01:58:05 +02:00
|
|
|
sideMenu.setLayoutParams(layoutParams);
|
2020-07-26 10:03:38 +02:00
|
|
|
sideMenu.setOnItemClickListener((view, position, x, y) -> {
|
2018-08-27 10:33:11 +02:00
|
|
|
if (position == 0) {
|
2020-07-26 10:03:38 +02:00
|
|
|
DrawerProfileCell profileCell = (DrawerProfileCell) view;
|
|
|
|
if (profileCell.isInAvatar(x, y)) {
|
|
|
|
openSettings(profileCell.hasAvatar());
|
|
|
|
} else {
|
|
|
|
drawerLayoutAdapter.setAccountsShown(!drawerLayoutAdapter.isAccountsShown(), true);
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else if (view instanceof DrawerUserCell) {
|
|
|
|
switchToAccount(((DrawerUserCell) view).getAccountNumber(), true);
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (view instanceof DrawerAddCell) {
|
|
|
|
int freeAccount = -1;
|
|
|
|
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
|
|
|
|
if (!UserConfig.getInstance(a).isClientActivated()) {
|
|
|
|
freeAccount = a;
|
|
|
|
break;
|
2015-02-27 20:57:58 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
if (freeAccount >= 0) {
|
|
|
|
presentFragment(new LoginActivity(freeAccount));
|
|
|
|
}
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
2020-06-25 17:28:55 +02:00
|
|
|
} else if (view instanceof DrawerActionCheckCell) {
|
|
|
|
int id = drawerLayoutAdapter.getId(position);
|
|
|
|
// DrawerLayoutAdapter.CheckItem item = drawerLayoutAdapter.getItem(position);
|
|
|
|
if (id == 12) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("themeconfig", Activity.MODE_PRIVATE);
|
|
|
|
String dayThemeName = preferences.getString("lastDayTheme", "Blue");
|
|
|
|
if (Theme.getTheme(dayThemeName) == null) {
|
|
|
|
dayThemeName = "Blue";
|
|
|
|
}
|
|
|
|
String nightThemeName = preferences.getString("lastDarkTheme", "Night");
|
|
|
|
if (Theme.getTheme(nightThemeName) == null) {
|
|
|
|
nightThemeName = "Night";
|
|
|
|
}
|
|
|
|
Theme.ThemeInfo themeInfo = Theme.getActiveTheme();
|
|
|
|
|
|
|
|
((DrawerActionCheckCell) view).setChecked(!themeInfo.isDark());
|
|
|
|
|
|
|
|
if (dayThemeName.equals(nightThemeName)) {
|
|
|
|
if (themeInfo.isDark()) {
|
|
|
|
dayThemeName = "Blue";
|
|
|
|
} else {
|
|
|
|
nightThemeName = "Night";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dayThemeName.equals(themeInfo.getKey())) {
|
|
|
|
themeInfo = Theme.getTheme(nightThemeName);
|
|
|
|
} else {
|
|
|
|
themeInfo = Theme.getTheme(dayThemeName);
|
|
|
|
}
|
|
|
|
if (Theme.selectedAutoNightType != Theme.AUTO_NIGHT_TYPE_NONE) {
|
|
|
|
AlertUtil.showToast(LocaleController.getString("AutoNightModeOff", R.string.AutoNightModeOff));
|
|
|
|
Theme.selectedAutoNightType = Theme.AUTO_NIGHT_TYPE_NONE;
|
|
|
|
Theme.saveAutoNightThemeConfig();
|
|
|
|
Theme.cancelAutoNightThemeCallbacks();
|
|
|
|
}
|
|
|
|
int[] pos = new int[2];
|
|
|
|
Switch s = ((DrawerActionCheckCell) view).checkBox;
|
|
|
|
s.getLocationInWindow(pos);
|
|
|
|
pos[0] += s.getMeasuredWidth() / 2;
|
|
|
|
pos[1] += s.getMeasuredHeight() / 2;
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needSetDayNightTheme, themeInfo, false, pos, -1);
|
|
|
|
} else if (id == 13) {
|
|
|
|
presentFragment(new ProxyListActivity());
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
2020-07-02 05:28:34 +02:00
|
|
|
} else if (id == 14) {
|
2020-07-27 02:58:40 +02:00
|
|
|
NekoXConfig.toggleKeepOnlineStatus();
|
2020-10-09 19:35:17 +02:00
|
|
|
|
2020-07-02 05:28:34 +02:00
|
|
|
drawerLayoutAdapter.notifyDataSetChanged();
|
2020-06-25 17:28:55 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
int id = drawerLayoutAdapter.getId(position);
|
|
|
|
if (id == 2) {
|
2019-01-23 18:03:33 +01:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
presentFragment(new GroupCreateActivity(args));
|
2018-07-30 04:07:02 +02:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
2018-08-27 10:33:11 +02:00
|
|
|
} else if (id == 3) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlyUsers", true);
|
|
|
|
args.putBoolean("destroyAfterSelect", true);
|
|
|
|
args.putBoolean("createSecretChat", true);
|
|
|
|
args.putBoolean("allowBots", false);
|
2019-12-31 14:08:08 +01:00
|
|
|
args.putBoolean("allowSelf", false);
|
2018-08-27 10:33:11 +02:00
|
|
|
presentFragment(new ContactsActivity(args));
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (id == 4) {
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
if (!BuildVars.DEBUG_VERSION && preferences.getBoolean("channel_intro", false)) {
|
2018-07-30 04:07:02 +02:00
|
|
|
Bundle args = new Bundle();
|
2018-08-27 10:33:11 +02:00
|
|
|
args.putInt("step", 0);
|
|
|
|
presentFragment(new ChannelCreateActivity(args));
|
|
|
|
} else {
|
2019-07-18 15:01:39 +02:00
|
|
|
presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANNEL_CREATE));
|
2020-06-25 17:28:55 +02:00
|
|
|
preferences.edit().putBoolean("channel_intro", true).apply();
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (id == 6) {
|
|
|
|
presentFragment(new ContactsActivity(null));
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (id == 7) {
|
|
|
|
presentFragment(new InviteContactsActivity());
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (id == 8) {
|
2020-07-26 10:03:38 +02:00
|
|
|
openSettings(false);
|
2018-08-27 10:33:11 +02:00
|
|
|
} else if (id == 9) {
|
2020-06-25 17:28:55 +02:00
|
|
|
Browser.openUrl(LaunchActivity.this, NekoXConfig.FAQ_URL);
|
2018-08-27 10:33:11 +02:00
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (id == 10) {
|
|
|
|
presentFragment(new CallLogActivity());
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (id == 11) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", UserConfig.getInstance(currentAccount).getClientUserId());
|
|
|
|
presentFragment(new ChatActivity(args));
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
2014-11-07 21:10:12 +01:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
});
|
2020-09-30 15:48:47 +02:00
|
|
|
final ItemTouchHelper sideMenuTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0) {
|
|
|
|
|
|
|
|
private RecyclerView.ViewHolder selectedViewHolder;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
|
|
|
if (viewHolder.getItemViewType() != target.getItemViewType()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
drawerLayoutAdapter.swapElements(viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLongPressDragEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
|
|
|
|
clearSelectedViewHolder();
|
|
|
|
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
|
|
|
|
selectedViewHolder = viewHolder;
|
|
|
|
final View view = viewHolder.itemView;
|
|
|
|
sideMenu.cancelClickRunnables(false);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
ObjectAnimator.ofFloat(view, "elevation", AndroidUtilities.dp(1)).setDuration(150).start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
|
|
|
clearSelectedViewHolder();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void clearSelectedViewHolder() {
|
|
|
|
if (selectedViewHolder != null) {
|
|
|
|
final View view = selectedViewHolder.itemView;
|
|
|
|
selectedViewHolder = null;
|
|
|
|
view.setTranslationX(0f);
|
|
|
|
view.setTranslationY(0f);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
final ObjectAnimator animator = ObjectAnimator.ofFloat(view, "elevation", 0f);
|
|
|
|
animator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
view.setBackground(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animator.setDuration(150).start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
|
|
|
final View view = viewHolder.itemView;
|
|
|
|
if (drawerLayoutAdapter.isAccountsShown()) {
|
|
|
|
RecyclerView.ViewHolder topViewHolder = recyclerView.findViewHolderForAdapterPosition(drawerLayoutAdapter.getFirstAccountPosition() - 1);
|
|
|
|
RecyclerView.ViewHolder bottomViewHolder = recyclerView.findViewHolderForAdapterPosition(drawerLayoutAdapter.getLastAccountPosition() + 1);
|
|
|
|
if (topViewHolder != null && topViewHolder.itemView != null && topViewHolder.itemView.getBottom() == view.getTop() && dY < 0f) {
|
|
|
|
dY = 0f;
|
|
|
|
} else if (bottomViewHolder != null && bottomViewHolder.itemView != null && bottomViewHolder.itemView.getTop() == view.getBottom() && dY > 0f) {
|
|
|
|
dY = 0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
view.setTranslationX(dX);
|
|
|
|
view.setTranslationY(dY);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sideMenuTouchHelper.attachToRecyclerView(sideMenu);
|
|
|
|
sideMenu.setOnItemLongClickListener((view, position) -> {
|
|
|
|
if (view instanceof DrawerUserCell) {
|
|
|
|
final int accountNumber = ((DrawerUserCell) view).getAccountNumber();
|
|
|
|
if (accountNumber == currentAccount || AndroidUtilities.isTablet()) {
|
|
|
|
sideMenuTouchHelper.startDrag(sideMenu.getChildViewHolder(view));
|
|
|
|
} else {
|
|
|
|
final BaseFragment fragment = new DialogsActivity(null) {
|
|
|
|
@Override
|
|
|
|
protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
|
|
|
|
super.onTransitionAnimationEnd(isOpen, backward);
|
|
|
|
if (!isOpen && backward) { // closed
|
|
|
|
drawerLayoutContainer.setDrawCurrentPreviewFragmentAbove(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPreviewOpenAnimationEnd() {
|
|
|
|
super.onPreviewOpenAnimationEnd();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
drawerLayoutContainer.setDrawCurrentPreviewFragmentAbove(false);
|
|
|
|
switchToAccount(accountNumber, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fragment.setCurrentAccount(accountNumber);
|
|
|
|
actionBarLayout.presentFragmentAsPreview(fragment);
|
|
|
|
drawerLayoutContainer.setDrawCurrentPreviewFragmentAbove(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2014-11-07 21:10:12 +01:00
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
drawerLayoutContainer.setParentActionBarLayout(actionBarLayout);
|
|
|
|
actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayout.init(mainFragmentsStack);
|
|
|
|
actionBarLayout.setDelegate(this);
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.loadWallpaper();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
passcodeView = new PasscodeView(this);
|
2017-03-31 01:58:05 +02:00
|
|
|
drawerLayoutContainer.addView(passcodeView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
checkCurrentAccount();
|
2020-03-30 14:00:09 +02:00
|
|
|
updateCurrentConnectionState(currentAccount);
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this);
|
|
|
|
|
|
|
|
currentConnectionState = ConnectionsManager.getInstance(currentAccount).getConnectionState();
|
|
|
|
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.needShowAlert);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.reloadInterface);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.suggestedLangpack);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewTheme);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.needSetDayNightTheme);
|
2019-12-31 14:08:08 +01:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.needCheckSystemBarColors);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.closeOtherAppActivities);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetPasscode);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.notificationsCountUpdated);
|
2019-12-31 14:08:08 +01:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.screenStateChanged);
|
2020-07-02 05:28:34 +02:00
|
|
|
|
2020-06-25 17:28:55 +02:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(drawerLayoutAdapter, NotificationCenter.proxySettingsChanged);
|
2020-07-02 05:28:34 +02:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(drawerLayoutAdapter, NotificationCenter.updateUserStatus);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayout.addFragmentToStack(new LoginActivity());
|
2015-03-19 00:09:45 +01:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
DialogsActivity dialogsActivity = new DialogsActivity(null);
|
|
|
|
dialogsActivity.setSideMenu(sideMenu);
|
|
|
|
actionBarLayout.addFragmentToStack(dialogsActivity);
|
2015-04-09 20:00:14 +02:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-03-26 21:16:28 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
String fragmentName = savedInstanceState.getString("fragment");
|
|
|
|
if (fragmentName != null) {
|
|
|
|
Bundle args = savedInstanceState.getBundle("args");
|
2015-01-02 23:15:07 +01:00
|
|
|
switch (fragmentName) {
|
|
|
|
case "chat":
|
|
|
|
if (args != null) {
|
|
|
|
ChatActivity chat = new ChatActivity(args);
|
|
|
|
if (actionBarLayout.addFragmentToStack(chat)) {
|
|
|
|
chat.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
break;
|
|
|
|
case "settings": {
|
2020-07-26 10:03:38 +02:00
|
|
|
args.putInt("user_id", UserConfig.getInstance(currentAccount).clientUserId);
|
|
|
|
ProfileActivity settings = new ProfileActivity(args);
|
2015-01-02 23:15:07 +01:00
|
|
|
actionBarLayout.addFragmentToStack(settings);
|
|
|
|
settings.restoreSelfArgs(savedInstanceState);
|
|
|
|
break;
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
case "group":
|
|
|
|
if (args != null) {
|
|
|
|
GroupCreateFinalActivity group = new GroupCreateFinalActivity(args);
|
|
|
|
if (actionBarLayout.addFragmentToStack(group)) {
|
|
|
|
group.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
break;
|
2015-09-24 22:52:02 +02:00
|
|
|
case "channel":
|
|
|
|
if (args != null) {
|
|
|
|
ChannelCreateActivity channel = new ChannelCreateActivity(args);
|
|
|
|
if (actionBarLayout.addFragmentToStack(channel)) {
|
|
|
|
channel.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2015-01-02 23:15:07 +01:00
|
|
|
case "chat_profile":
|
|
|
|
if (args != null) {
|
|
|
|
ProfileActivity profile = new ProfileActivity(args);
|
|
|
|
if (actionBarLayout.addFragmentToStack(profile)) {
|
|
|
|
profile.restoreSelfArgs(savedInstanceState);
|
|
|
|
}
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
break;
|
|
|
|
case "wallpapers": {
|
2019-01-23 18:03:33 +01:00
|
|
|
WallpapersListActivity settings = new WallpapersListActivity(WallpapersListActivity.TYPE_ALL);
|
2015-01-02 23:15:07 +01:00
|
|
|
actionBarLayout.addFragmentToStack(settings);
|
|
|
|
settings.restoreSelfArgs(savedInstanceState);
|
|
|
|
break;
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
2014-11-18 13:37:11 +01:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
BaseFragment fragment = actionBarLayout.fragmentsStack.get(0);
|
|
|
|
if (fragment instanceof DialogsActivity) {
|
|
|
|
((DialogsActivity) fragment).setSideMenu(sideMenu);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
boolean allowOpen = true;
|
2014-11-18 13:37:11 +01:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-12-01 18:56:31 +01:00
|
|
|
allowOpen = actionBarLayout.fragmentsStack.size() <= 1 && layersActionBarLayout.fragmentsStack.isEmpty();
|
2015-05-21 23:27:27 +02:00
|
|
|
if (layersActionBarLayout.fragmentsStack.size() == 1 && layersActionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
|
|
|
|
allowOpen = false;
|
|
|
|
}
|
2014-11-18 13:37:11 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (actionBarLayout.fragmentsStack.size() == 1 && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
|
2014-12-01 18:56:31 +01:00
|
|
|
allowOpen = false;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
checkLayout();
|
2019-12-31 14:08:08 +01:00
|
|
|
checkSystemBarColors();
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
handleIntent(getIntent(), false, savedInstanceState != null, false);
|
2015-11-26 22:04:02 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
try {
|
|
|
|
String os1 = Build.DISPLAY;
|
|
|
|
String os2 = Build.USER;
|
|
|
|
if (os1 != null) {
|
|
|
|
os1 = os1.toLowerCase();
|
|
|
|
} else {
|
|
|
|
os1 = "";
|
|
|
|
}
|
|
|
|
if (os2 != null) {
|
|
|
|
os2 = os1.toLowerCase();
|
|
|
|
} else {
|
|
|
|
os2 = "";
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
2019-07-18 15:01:39 +02:00
|
|
|
FileLog.d("OS name " + os1 + " " + os2);
|
|
|
|
}
|
2020-08-22 01:59:49 +02:00
|
|
|
if ((os1.contains("flyme") || os2.contains("flyme")) && Build.VERSION.SDK_INT <= 24) {
|
2016-10-11 13:57:01 +02:00
|
|
|
AndroidUtilities.incorrectDisplaySizeFix = true;
|
|
|
|
final View view = getWindow().getDecorView().getRootView();
|
2018-08-27 10:33:11 +02:00
|
|
|
view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener = () -> {
|
|
|
|
int height = view.getMeasuredHeight();
|
2019-08-22 01:53:26 +02:00
|
|
|
FileLog.d("height = " + height + " displayHeight = " + AndroidUtilities.displaySize.y);
|
2018-08-27 10:33:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
height -= AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
|
|
|
if (height > AndroidUtilities.dp(100) && height < AndroidUtilities.displaySize.y && height + AndroidUtilities.dp(100) > AndroidUtilities.displaySize.y) {
|
|
|
|
AndroidUtilities.displaySize.y = height;
|
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("fix display size y to " + AndroidUtilities.displaySize.y);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
MediaController.getInstance().setBaseActivity(this, true);
|
2020-08-10 12:49:33 +02:00
|
|
|
ExternalGcm.checkUpdate(this);
|
2020-06-25 17:28:55 +02:00
|
|
|
UIUtil.runOnIoDispatcher(() -> {
|
|
|
|
|
|
|
|
for (SubInfo subInfo : SubManager.getSubList().find()) {
|
|
|
|
|
|
|
|
if (subInfo == null) continue;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
subInfo.proxies = subInfo.reloadProxies();
|
|
|
|
subInfo.lastFetch = System.currentTimeMillis();
|
|
|
|
|
|
|
|
SubManager.getSubList().update(subInfo, true);
|
2020-06-27 07:36:00 +02:00
|
|
|
SharedConfig.reloadProxyList();
|
2020-06-25 17:28:55 +02:00
|
|
|
|
|
|
|
} catch (SubInfo.AllTriesFailed allTriesFailed) {
|
2020-06-27 07:36:00 +02:00
|
|
|
|
|
|
|
FileLog.e(allTriesFailed);
|
|
|
|
|
2020-06-25 17:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
private void openSettings(boolean expanded) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", UserConfig.getInstance(currentAccount).clientUserId);
|
|
|
|
if (expanded) {
|
|
|
|
args.putBoolean("expandPhoto", true);
|
|
|
|
}
|
|
|
|
ProfileActivity fragment = new ProfileActivity(args);
|
|
|
|
presentFragment(fragment);
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void checkSystemBarColors() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
int color = Theme.getColor(Theme.key_actionBarDefault, null, true);
|
2020-02-09 08:43:28 +01:00
|
|
|
AndroidUtilities.setLightStatusBar(getWindow(), AndroidUtilities.computePerceivedBrightness(color) >= 0.721f);
|
2019-12-31 14:08:08 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
final Window window = getWindow();
|
|
|
|
color = Theme.getColor(Theme.key_windowBackgroundGray, null, true);
|
|
|
|
if (window.getNavigationBarColor() != color) {
|
|
|
|
window.setNavigationBarColor(color);
|
|
|
|
final float brightness = AndroidUtilities.computePerceivedBrightness(color);
|
|
|
|
AndroidUtilities.setLightNavigationBar(getWindow(), brightness >= 0.721f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void switchToAccount(int account, boolean removeAll) {
|
2020-06-25 17:28:55 +02:00
|
|
|
switchToAccount(account, removeAll, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void switchToAccount(int account, boolean removeAll, boolean afterLogin) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (account == UserConfig.selectedAccount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionsManager.getInstance(currentAccount).setAppPaused(true, false);
|
|
|
|
UserConfig.selectedAccount = account;
|
|
|
|
UserConfig.getInstance(0).saveConfig(false);
|
|
|
|
|
|
|
|
checkCurrentAccount();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
layersActionBarLayout.removeAllFragments();
|
|
|
|
rightActionBarLayout.removeAllFragments();
|
|
|
|
if (!tabletFullSize) {
|
|
|
|
shadowTabletSide.setVisibility(View.VISIBLE);
|
|
|
|
if (rightActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
rightActionBarLayout.setVisibility(View.GONE);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
layersActionBarLayout.setVisibility(View.GONE);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if (removeAll) {
|
|
|
|
actionBarLayout.removeAllFragments();
|
|
|
|
} else {
|
|
|
|
actionBarLayout.removeFragmentFromStack(0);
|
|
|
|
}
|
|
|
|
DialogsActivity dialogsActivity = new DialogsActivity(null);
|
|
|
|
dialogsActivity.setSideMenu(sideMenu);
|
|
|
|
actionBarLayout.addFragmentToStack(dialogsActivity, 0);
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
layersActionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
}
|
|
|
|
if (!ApplicationLoader.mainInterfacePaused) {
|
|
|
|
ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false);
|
|
|
|
}
|
|
|
|
if (UserConfig.getInstance(account).unacceptedTermsOfService != null) {
|
|
|
|
showTosActivity(account, UserConfig.getInstance(account).unacceptedTermsOfService);
|
|
|
|
}
|
2020-06-25 17:28:55 +02:00
|
|
|
if (afterLogin) {
|
|
|
|
PrivacyUtil.postCheckAll(this, account);
|
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
updateCurrentConnectionState(currentAccount);
|
2020-07-02 05:28:34 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.updateUserStatus, (Object) null);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToAvailableAccountOrLogout() {
|
|
|
|
int account = -1;
|
|
|
|
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
|
|
|
|
if (UserConfig.getInstance(a).isClientActivated()) {
|
|
|
|
account = a;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (termsOfServiceView != null) {
|
|
|
|
termsOfServiceView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (account != -1) {
|
|
|
|
switchToAccount(account, true);
|
|
|
|
} else {
|
|
|
|
if (drawerLayoutAdapter != null) {
|
|
|
|
drawerLayoutAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
for (BaseFragment fragment : actionBarLayout.fragmentsStack) {
|
|
|
|
fragment.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
Intent intent2 = new Intent(this, IntroActivity.class);
|
|
|
|
startActivity(intent2);
|
|
|
|
onFinish();
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMainFragmentsCount() {
|
|
|
|
return mainFragmentsStack.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkCurrentAccount() {
|
|
|
|
if (currentAccount != UserConfig.selectedAccount) {
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.appDidLogout);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.mainUserInfoChanged);
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.didUpdateConnectionState);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.needShowAlert);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.openArticle);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.hasNewContactsToImport);
|
2019-07-18 15:01:39 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.needShowPlayServicesAlert);
|
2019-09-10 12:56:11 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileDidFailToLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
currentAccount = UserConfig.selectedAccount;
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.appDidLogout);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.mainUserInfoChanged);
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.didUpdateConnectionState);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.needShowAlert);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.openArticle);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.hasNewContactsToImport);
|
2019-07-18 15:01:39 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.needShowPlayServicesAlert);
|
2019-09-10 12:56:11 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.fileDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.fileDidFailToLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void checkLayout() {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (!AndroidUtilities.isTablet() || rightActionBarLayout == null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
if (!AndroidUtilities.isInMultiwindow && (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
|
|
|
|
tabletFullSize = false;
|
|
|
|
if (actionBarLayout.fragmentsStack.size() >= 2) {
|
|
|
|
for (int a = 1; a < actionBarLayout.fragmentsStack.size(); a++) {
|
|
|
|
BaseFragment chatFragment = actionBarLayout.fragmentsStack.get(a);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (chatFragment instanceof ChatActivity) {
|
|
|
|
((ChatActivity) chatFragment).setIgnoreAttachOnPause(true);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
chatFragment.onPause();
|
|
|
|
actionBarLayout.fragmentsStack.remove(a);
|
|
|
|
rightActionBarLayout.fragmentsStack.add(chatFragment);
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
if (passcodeView.getVisibility() != View.VISIBLE) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02: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);
|
|
|
|
} else {
|
|
|
|
tabletFullSize = true;
|
|
|
|
if (!rightActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < rightActionBarLayout.fragmentsStack.size(); a++) {
|
|
|
|
BaseFragment chatFragment = rightActionBarLayout.fragmentsStack.get(a);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (chatFragment instanceof ChatActivity) {
|
|
|
|
((ChatActivity) chatFragment).setIgnoreAttachOnPause(true);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
chatFragment.onPause();
|
|
|
|
rightActionBarLayout.fragmentsStack.remove(a);
|
|
|
|
actionBarLayout.fragmentsStack.add(chatFragment);
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
if (passcodeView.getVisibility() != View.VISIBLE) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shadowTabletSide.setVisibility(View.GONE);
|
|
|
|
rightActionBarLayout.setVisibility(View.GONE);
|
|
|
|
backgroundTablet.setVisibility(!actionBarLayout.fragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
private void showUpdateActivity(int account, TLRPC.TL_help_appUpdate update, boolean check) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (blockingUpdateView == null) {
|
|
|
|
blockingUpdateView = new BlockingUpdateView(LaunchActivity.this) {
|
|
|
|
@Override
|
|
|
|
public void setVisibility(int visibility) {
|
|
|
|
super.setVisibility(visibility);
|
|
|
|
if (visibility == View.GONE) {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
drawerLayoutContainer.addView(blockingUpdateView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
blockingUpdateView.show(account, update, check);
|
2018-07-30 04:07:02 +02:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showTosActivity(int account, TLRPC.TL_help_termsOfService tos) {
|
|
|
|
if (termsOfServiceView == null) {
|
|
|
|
termsOfServiceView = new TermsOfServiceView(this);
|
2019-12-31 14:08:08 +01:00
|
|
|
termsOfServiceView.setAlpha(0f);
|
2018-07-30 04:07:02 +02:00
|
|
|
drawerLayoutContainer.addView(termsOfServiceView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
termsOfServiceView.setDelegate(new TermsOfServiceView.TermsOfServiceViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onAcceptTerms(int account) {
|
|
|
|
UserConfig.getInstance(account).unacceptedTermsOfService = null;
|
|
|
|
UserConfig.getInstance(account).saveConfig(false);
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2019-12-31 14:08:08 +01:00
|
|
|
if (mainFragmentsStack.size() > 0) {
|
|
|
|
mainFragmentsStack.get(mainFragmentsStack.size() - 1).onResume();
|
|
|
|
}
|
|
|
|
termsOfServiceView.animate()
|
|
|
|
.alpha(0f)
|
|
|
|
.setDuration(150)
|
|
|
|
.setInterpolator(AndroidUtilities.accelerateInterpolator)
|
|
|
|
.withEndAction(() -> termsOfServiceView.setVisibility(View.GONE))
|
|
|
|
.start();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDeclineTerms(int account) {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
termsOfServiceView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
TLRPC.TL_help_termsOfService currentTos = UserConfig.getInstance(account).unacceptedTermsOfService;
|
|
|
|
if (currentTos != tos && (currentTos == null || !currentTos.id.data.equals(tos.id.data))) {
|
|
|
|
UserConfig.getInstance(account).unacceptedTermsOfService = tos;
|
|
|
|
UserConfig.getInstance(account).saveConfig(false);
|
|
|
|
}
|
|
|
|
termsOfServiceView.show(account, tos);
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
2019-12-31 14:08:08 +01:00
|
|
|
termsOfServiceView.animate().alpha(1f).setDuration(150).setInterpolator(AndroidUtilities.decelerateInterpolator).setListener(null).start();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private void showPasscodeActivity() {
|
|
|
|
if (passcodeView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedConfig.appLocked = true;
|
|
|
|
if (SecretMediaViewer.hasInstance() && SecretMediaViewer.getInstance().isVisible()) {
|
2017-07-23 14:56:38 +02:00
|
|
|
SecretMediaViewer.getInstance().closePhoto(false, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
PhotoViewer.getInstance().closePhoto(false, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
ArticleViewer.getInstance().close(false, true);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
passcodeView.onShow();
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedConfig.isWaitingForPasscodeEnter = true;
|
2015-03-19 00:09:45 +01:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
2018-08-27 10:33:11 +02:00
|
|
|
passcodeView.setDelegate(() -> {
|
|
|
|
SharedConfig.isWaitingForPasscodeEnter = false;
|
|
|
|
if (passcodeSaveIntent != null) {
|
|
|
|
handleIntent(passcodeSaveIntent, passcodeSaveIntentIsNew, passcodeSaveIntentIsRestore, true);
|
|
|
|
passcodeSaveIntent = null;
|
|
|
|
}
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
actionBarLayout.setVisibility(View.VISIBLE);
|
2018-08-27 10:33:11 +02:00
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
layersActionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
2019-05-14 14:08:05 +02:00
|
|
|
if (layersActionBarLayout.getVisibility() == View.INVISIBLE) {
|
|
|
|
layersActionBarLayout.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
rightActionBarLayout.setVisibility(View.VISIBLE);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
});
|
2019-05-14 14:08:05 +02:00
|
|
|
actionBarLayout.setVisibility(View.INVISIBLE);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (layersActionBarLayout.getVisibility() == View.VISIBLE) {
|
|
|
|
layersActionBarLayout.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
rightActionBarLayout.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean handleIntent(Intent intent, boolean isNew, boolean restore, boolean fromPassword) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (AndroidUtilities.handleProxyIntent(this, intent)) {
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
layersActionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
|
|
|
if (intent == null || !Intent.ACTION_MAIN.equals(intent.getAction())) {
|
|
|
|
PhotoViewer.getInstance().closePhoto(false, true);
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
int flags = intent.getFlags();
|
2019-06-04 12:14:50 +02:00
|
|
|
final int[] intentAccount = new int[]{intent.getIntExtra("currentAccount", UserConfig.selectedAccount)};
|
2018-07-30 04:07:02 +02:00
|
|
|
switchToAccount(intentAccount[0], true);
|
2020-08-15 23:06:36 +02:00
|
|
|
boolean isVoipIntent = intent.getAction() != null && intent.getAction().equals("voip");
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!fromPassword && (AndroidUtilities.needShowPasscode(true) || SharedConfig.isWaitingForPasscodeEnter)) {
|
2015-02-26 02:32:51 +01:00
|
|
|
showPasscodeActivity();
|
2018-07-30 04:07:02 +02:00
|
|
|
UserConfig.getInstance(currentAccount).saveConfig(false);
|
2020-08-15 23:06:36 +02:00
|
|
|
if (!isVoipIntent) {
|
|
|
|
passcodeSaveIntent = intent;
|
|
|
|
passcodeSaveIntentIsNew = isNew;
|
|
|
|
passcodeSaveIntentIsRestore = restore;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean pushOpened = false;
|
|
|
|
|
|
|
|
int push_user_id = 0;
|
|
|
|
int push_chat_id = 0;
|
|
|
|
int push_enc_id = 0;
|
|
|
|
int push_msg_id = 0;
|
|
|
|
int open_settings = 0;
|
|
|
|
int open_new_dialog = 0;
|
|
|
|
long dialogId = 0;
|
|
|
|
boolean showDialogsList = false;
|
|
|
|
boolean showPlayer = false;
|
|
|
|
boolean showLocations = false;
|
2020-09-30 15:48:47 +02:00
|
|
|
boolean showCallLog = false;
|
2020-08-15 23:06:36 +02:00
|
|
|
boolean audioCallUser = false;
|
|
|
|
boolean videoCallUser = false;
|
2020-09-30 15:48:47 +02:00
|
|
|
boolean needCallAlert = false;
|
|
|
|
boolean newContact = false;
|
2020-10-05 00:13:31 +02:00
|
|
|
boolean newContactAlert = false;
|
2020-09-30 15:48:47 +02:00
|
|
|
boolean scanQr = false;
|
|
|
|
String searchQuery = null;
|
|
|
|
String callSearchQuery = null;
|
|
|
|
String newContactName = null;
|
|
|
|
String newContactPhone = null;
|
2020-08-15 23:06:36 +02:00
|
|
|
|
|
|
|
photoPathsArray = null;
|
|
|
|
videoPath = null;
|
|
|
|
sendingText = null;
|
2020-08-16 03:13:38 +02:00
|
|
|
sendingLocation = null;
|
2020-08-15 23:06:36 +02:00
|
|
|
documentsPathsArray = null;
|
|
|
|
documentsOriginalPathsArray = null;
|
|
|
|
documentsMimeType = null;
|
|
|
|
documentsUrisArray = null;
|
|
|
|
contactsToSend = null;
|
|
|
|
contactsToSendUri = null;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
if ((flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
|
|
|
|
if (intent != null && intent.getAction() != null && !restore) {
|
|
|
|
if (Intent.ACTION_SEND.equals(intent.getAction())) {
|
|
|
|
if (SharedConfig.directShare && intent != null && intent.getExtras() != null) {
|
|
|
|
dialogId = intent.getExtras().getLong("dialogId", 0);
|
|
|
|
String hash = null;
|
|
|
|
if (dialogId == 0) {
|
|
|
|
try {
|
|
|
|
String id = intent.getExtras().getString(ShortcutManagerCompat.EXTRA_SHORTCUT_ID);
|
|
|
|
if (id != null) {
|
|
|
|
List<ShortcutInfoCompat> list = ShortcutManagerCompat.getDynamicShortcuts(ApplicationLoader.applicationContext);
|
|
|
|
for (int a = 0, N = list.size(); a < N; a++) {
|
|
|
|
ShortcutInfoCompat info = list.get(a);
|
|
|
|
if (id.equals(info.getId())) {
|
|
|
|
Bundle extras = info.getIntent().getExtras();
|
|
|
|
dialogId = extras.getLong("dialogId", 0);
|
|
|
|
hash = extras.getString("hash", null);
|
|
|
|
break;
|
2020-07-26 10:03:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
2020-07-26 10:03:38 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
hash = intent.getExtras().getString("hash", null);
|
2020-07-26 10:03:38 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
if (SharedConfig.directShareHash == null || !SharedConfig.directShareHash.equals(hash)) {
|
|
|
|
dialogId = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
boolean error = false;
|
|
|
|
String type = intent.getType();
|
|
|
|
if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) {
|
|
|
|
try {
|
|
|
|
Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM);
|
|
|
|
if (uri != null) {
|
|
|
|
contactsToSend = AndroidUtilities.loadVCardFromStream(uri, currentAccount, false, null, null);
|
|
|
|
if (contactsToSend.size() > 5) {
|
|
|
|
contactsToSend = null;
|
|
|
|
documentsUrisArray = new ArrayList<>();
|
|
|
|
documentsUrisArray.add(uri);
|
|
|
|
documentsMimeType = type;
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2020-08-15 23:06:36 +02:00
|
|
|
contactsToSendUri = uri;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
error = true;
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
|
|
if (text == null) {
|
|
|
|
CharSequence textSequence = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
|
|
|
|
if (textSequence != null) {
|
|
|
|
text = textSequence.toString();
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
if (!TextUtils.isEmpty(text)) {
|
2020-08-16 03:13:38 +02:00
|
|
|
Matcher m = locationRegex.matcher(text);
|
2020-10-01 11:01:48 +02:00
|
|
|
if (m.find()) {
|
|
|
|
String[] lines = text.split("\\n");
|
|
|
|
String venueTitle = null;
|
|
|
|
String venueAddress = null;
|
|
|
|
if (lines[0].equals("My Position")) {
|
|
|
|
// Use normal GeoPoint message (user position)
|
|
|
|
} else if (!lines[0].contains("geo:")) {
|
|
|
|
venueTitle = lines[0];
|
|
|
|
if (!lines[1].contains("geo:")) {
|
|
|
|
venueAddress = lines[1];
|
2020-01-12 10:34:25 +01:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2020-10-01 11:01:48 +02:00
|
|
|
sendingLocation = new Location("");
|
|
|
|
sendingLocation.setLatitude(Double.parseDouble(m.group(1)));
|
|
|
|
sendingLocation.setLongitude(Double.parseDouble(m.group(2)));
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putCharSequence("venueTitle", venueTitle);
|
|
|
|
bundle.putCharSequence("venueAddress", venueAddress);
|
|
|
|
sendingLocation.setExtras(bundle);
|
|
|
|
} else if ((text.startsWith("http://") || text.startsWith("https://")) && !TextUtils.isEmpty(subject)) {
|
2020-08-15 23:06:36 +02:00
|
|
|
text = subject + "\n" + text;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
sendingText = text;
|
|
|
|
} else if (!TextUtils.isEmpty(subject)) {
|
|
|
|
sendingText = subject;
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
if (parcelable != null) {
|
|
|
|
String path;
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
|
|
|
}
|
|
|
|
Uri uri = (Uri) parcelable;
|
|
|
|
if (!error) {
|
|
|
|
if (uri != null && (type != null && type.startsWith("image/") || uri.toString().toLowerCase().endsWith(".jpg"))) {
|
|
|
|
if (photoPathsArray == null) {
|
|
|
|
photoPathsArray = new ArrayList<>();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
|
|
|
|
info.uri = uri;
|
|
|
|
photoPathsArray.add(info);
|
|
|
|
} else {
|
|
|
|
path = AndroidUtilities.getPath(uri);
|
|
|
|
if (path != null) {
|
|
|
|
if (path.startsWith("file:")) {
|
|
|
|
path = path.replace("file://", "");
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
if (type != null && type.startsWith("video/")) {
|
|
|
|
videoPath = path;
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2020-08-15 23:06:36 +02:00
|
|
|
if (documentsPathsArray == null) {
|
|
|
|
documentsPathsArray = new ArrayList<>();
|
|
|
|
documentsOriginalPathsArray = new ArrayList<>();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
documentsPathsArray.add(path);
|
|
|
|
documentsOriginalPathsArray.add(uri.toString());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (documentsUrisArray == null) {
|
|
|
|
documentsUrisArray = new ArrayList<>();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
documentsUrisArray.add(uri);
|
|
|
|
documentsMimeType = type;
|
2014-05-17 01:05:49 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2020-10-01 11:01:48 +02:00
|
|
|
} else if (sendingText == null && sendingLocation == null) {
|
2020-08-15 23:06:36 +02:00
|
|
|
error = true;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
} else if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
|
|
|
|
boolean error = false;
|
|
|
|
try {
|
|
|
|
ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
|
|
String type = intent.getType();
|
|
|
|
if (uris != null) {
|
|
|
|
for (int a = 0; a < uris.size(); a++) {
|
|
|
|
Parcelable parcelable = uris.get(a);
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
|
|
|
}
|
|
|
|
Uri uri = (Uri) parcelable;
|
|
|
|
if (uri != null) {
|
|
|
|
if (AndroidUtilities.isInternalUri(uri)) {
|
|
|
|
uris.remove(a);
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uris.isEmpty()) {
|
|
|
|
uris = null;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
if (uris != null) {
|
|
|
|
if (type != null && type.startsWith("image/")) {
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < uris.size(); a++) {
|
|
|
|
Parcelable parcelable = uris.get(a);
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
|
|
|
}
|
|
|
|
Uri uri = (Uri) parcelable;
|
2020-08-15 23:06:36 +02:00
|
|
|
if (photoPathsArray == null) {
|
|
|
|
photoPathsArray = new ArrayList<>();
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
|
|
|
|
info.uri = uri;
|
|
|
|
photoPathsArray.add(info);
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
for (int a = 0; a < uris.size(); a++) {
|
|
|
|
Parcelable parcelable = uris.get(a);
|
|
|
|
if (!(parcelable instanceof Uri)) {
|
|
|
|
parcelable = Uri.parse(parcelable.toString());
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
Uri uri = (Uri) parcelable;
|
|
|
|
String path = AndroidUtilities.getPath(uri);
|
|
|
|
String originalPath = parcelable.toString();
|
|
|
|
if (originalPath == null) {
|
|
|
|
originalPath = path;
|
|
|
|
}
|
|
|
|
if (path != null) {
|
|
|
|
if (path.startsWith("file:")) {
|
|
|
|
path = path.replace("file://", "");
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
if (documentsPathsArray == null) {
|
|
|
|
documentsPathsArray = new ArrayList<>();
|
|
|
|
documentsOriginalPathsArray = new ArrayList<>();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
documentsPathsArray.add(path);
|
|
|
|
documentsOriginalPathsArray.add(originalPath);
|
|
|
|
} else {
|
|
|
|
if (documentsUrisArray == null) {
|
|
|
|
documentsUrisArray = new ArrayList<>();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
documentsUrisArray.add(uri);
|
|
|
|
documentsMimeType = type;
|
2014-06-20 02:18:13 +02:00
|
|
|
}
|
2014-04-05 19:11:44 +02:00
|
|
|
}
|
2014-05-17 01:05:49 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
2015-01-02 23:15:07 +01:00
|
|
|
error = true;
|
2014-05-17 01:05:49 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
|
Uri data = intent.getData();
|
|
|
|
if (data != null) {
|
|
|
|
String username = null;
|
|
|
|
String login = null;
|
|
|
|
String group = null;
|
|
|
|
String sticker = null;
|
|
|
|
HashMap<String, String> auth = null;
|
|
|
|
String unsupportedUrl = null;
|
|
|
|
String botUser = null;
|
|
|
|
String botChat = null;
|
|
|
|
String message = null;
|
|
|
|
String phone = null;
|
|
|
|
String game = null;
|
|
|
|
String phoneHash = null;
|
|
|
|
String lang = null;
|
|
|
|
String theme = null;
|
|
|
|
String code = null;
|
|
|
|
TLRPC.TL_wallPaper wallPaper = null;
|
|
|
|
Integer messageId = null;
|
|
|
|
Integer channelId = null;
|
2020-09-30 15:48:47 +02:00
|
|
|
Integer threadId = null;
|
|
|
|
Integer commentId = null;
|
2020-08-15 23:06:36 +02:00
|
|
|
boolean hasUrl = false;
|
2020-10-04 12:14:58 +02:00
|
|
|
final String scheme = data.getScheme();
|
2020-10-01 11:01:48 +02:00
|
|
|
boolean internal = intent.getExtras() != null && intent.getExtras().get("internal") != null && (boolean) intent.getExtras().get("internal");
|
2020-08-15 23:06:36 +02:00
|
|
|
if (scheme != null) {
|
|
|
|
switch (scheme) {
|
|
|
|
case "http":
|
|
|
|
case "https": {
|
|
|
|
String host = data.getHost().toLowerCase();
|
|
|
|
if (host.equals("telegram.me") || host.equals("t.me") || host.equals("telegram.dog")) {
|
|
|
|
String path = data.getPath();
|
|
|
|
if (path != null && path.length() > 1) {
|
|
|
|
path = path.substring(1);
|
|
|
|
if (path.startsWith("bg/")) {
|
|
|
|
wallPaper = new TLRPC.TL_wallPaper();
|
|
|
|
wallPaper.settings = new TLRPC.TL_wallPaperSettings();
|
|
|
|
wallPaper.slug = path.replace("bg/", "");
|
|
|
|
if (wallPaper.slug != null && wallPaper.slug.length() == 6) {
|
|
|
|
try {
|
|
|
|
wallPaper.settings.background_color = Integer.parseInt(wallPaper.slug, 16) | 0xff000000;
|
|
|
|
} catch (Exception ignore) {
|
2019-02-08 03:30:32 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
wallPaper.slug = null;
|
|
|
|
} else if (wallPaper.slug != null && wallPaper.slug.length() == 13 && wallPaper.slug.charAt(6) == '-') {
|
|
|
|
try {
|
|
|
|
wallPaper.settings.background_color = Integer.parseInt(wallPaper.slug.substring(0, 6), 16) | 0xff000000;
|
|
|
|
wallPaper.settings.second_background_color = Integer.parseInt(wallPaper.slug.substring(7), 16) | 0xff000000;
|
|
|
|
wallPaper.settings.rotation = 45;
|
|
|
|
} catch (Exception ignore) {
|
2019-12-31 14:08:08 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
String rotation = data.getQueryParameter("rotation");
|
|
|
|
if (!TextUtils.isEmpty(rotation)) {
|
|
|
|
wallPaper.settings.rotation = Utilities.parseInt(rotation);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception ignore) {
|
2019-12-31 14:08:08 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
wallPaper.slug = null;
|
|
|
|
} else {
|
|
|
|
String mode = data.getQueryParameter("mode");
|
|
|
|
if (mode != null) {
|
|
|
|
mode = mode.toLowerCase();
|
|
|
|
String[] modes = mode.split(" ");
|
|
|
|
if (modes != null && modes.length > 0) {
|
|
|
|
for (int a = 0; a < modes.length; a++) {
|
|
|
|
if ("blur".equals(modes[a])) {
|
|
|
|
wallPaper.settings.blur = true;
|
|
|
|
} else if ("motion".equals(modes[a])) {
|
|
|
|
wallPaper.settings.motion = true;
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
String intensity = data.getQueryParameter("intensity");
|
|
|
|
if (!TextUtils.isEmpty(intensity)) {
|
|
|
|
wallPaper.settings.intensity = Utilities.parseInt(intensity);
|
|
|
|
} else {
|
|
|
|
wallPaper.settings.intensity = 50;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
String bgColor = data.getQueryParameter("bg_color");
|
|
|
|
if (!TextUtils.isEmpty(bgColor)) {
|
|
|
|
wallPaper.settings.background_color = Integer.parseInt(bgColor.substring(0, 6), 16) | 0xff000000;
|
|
|
|
if (bgColor.length() > 6) {
|
|
|
|
wallPaper.settings.second_background_color = Integer.parseInt(bgColor.substring(7), 16) | 0xff000000;
|
|
|
|
wallPaper.settings.rotation = 45;
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
wallPaper.settings.background_color = 0xffffffff;
|
2019-02-08 03:30:32 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception ignore) {
|
2019-02-08 03:30:32 +01:00
|
|
|
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
try {
|
|
|
|
String rotation = data.getQueryParameter("rotation");
|
|
|
|
if (!TextUtils.isEmpty(rotation)) {
|
|
|
|
wallPaper.settings.rotation = Utilities.parseInt(rotation);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
} else if (path.startsWith("login/")) {
|
|
|
|
code = path.replace("login/", "");
|
|
|
|
} else if (path.startsWith("joinchat/")) {
|
|
|
|
group = path.replace("joinchat/", "");
|
|
|
|
} else if (path.startsWith("addstickers/")) {
|
|
|
|
sticker = path.replace("addstickers/", "");
|
|
|
|
} else if (path.startsWith("msg/") || path.startsWith("share/")) {
|
|
|
|
message = data.getQueryParameter("url");
|
|
|
|
if (message == null) {
|
|
|
|
message = "";
|
|
|
|
}
|
|
|
|
if (data.getQueryParameter("text") != null) {
|
|
|
|
if (message.length() > 0) {
|
|
|
|
hasUrl = true;
|
|
|
|
message += "\n";
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
message += data.getQueryParameter("text");
|
|
|
|
}
|
|
|
|
if (message.length() > 4096 * 4) {
|
|
|
|
message = message.substring(0, 4096 * 4);
|
|
|
|
}
|
|
|
|
while (message.endsWith("\n")) {
|
|
|
|
message = message.substring(0, message.length() - 1);
|
|
|
|
}
|
|
|
|
} else if (path.startsWith("confirmphone")) {
|
|
|
|
phone = data.getQueryParameter("phone");
|
|
|
|
phoneHash = data.getQueryParameter("hash");
|
|
|
|
} else if (path.startsWith("setlanguage/")) {
|
|
|
|
lang = path.substring(12);
|
|
|
|
} else if (path.startsWith("addtheme/")) {
|
|
|
|
theme = path.substring(9);
|
|
|
|
} else if (path.startsWith("c/")) {
|
|
|
|
List<String> segments = data.getPathSegments();
|
|
|
|
if (segments.size() == 3) {
|
|
|
|
channelId = Utilities.parseInt(segments.get(1));
|
|
|
|
messageId = Utilities.parseInt(segments.get(2));
|
|
|
|
if (messageId == 0 || channelId == 0) {
|
|
|
|
messageId = null;
|
|
|
|
channelId = null;
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
threadId = Utilities.parseInt(data.getQueryParameter("thread"));
|
|
|
|
if (threadId == 0) {
|
|
|
|
threadId = null;
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
2020-09-03 17:37:42 +02:00
|
|
|
} else if (path.startsWith("@id")) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
int userId = Utilities.parseInt(StringsKt.substringAfter(path, "@id", "0"));
|
|
|
|
if (userId != 0) {
|
|
|
|
push_user_id = userId;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else if (path.length() >= 1) {
|
|
|
|
ArrayList<String> segments = new ArrayList<>(data.getPathSegments());
|
|
|
|
if (segments.size() > 0 && segments.get(0).equals("s")) {
|
|
|
|
segments.remove(0);
|
|
|
|
}
|
|
|
|
if (segments.size() > 0) {
|
|
|
|
username = segments.get(0);
|
|
|
|
if (segments.size() > 1) {
|
|
|
|
messageId = Utilities.parseInt(segments.get(1));
|
|
|
|
if (messageId == 0) {
|
2016-03-06 02:49:31 +01:00
|
|
|
messageId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
botUser = data.getQueryParameter("start");
|
|
|
|
botChat = data.getQueryParameter("startgroup");
|
|
|
|
game = data.getQueryParameter("game");
|
2020-09-30 15:48:47 +02:00
|
|
|
threadId = Utilities.parseInt(data.getQueryParameter("thread"));
|
|
|
|
if (threadId == 0) {
|
|
|
|
threadId = null;
|
|
|
|
}
|
|
|
|
commentId = Utilities.parseInt(data.getQueryParameter("comment"));
|
|
|
|
if (commentId == 0) {
|
|
|
|
commentId = null;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2014-05-17 01:05:49 +02:00
|
|
|
}
|
2014-04-01 03:00:35 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "tg": {
|
|
|
|
String url = data.toString();
|
|
|
|
if (url.startsWith("tg:resolve") || url.startsWith("tg://resolve")) {
|
|
|
|
url = url.replace("tg:resolve", "tg://telegram.org").replace("tg://resolve", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
username = data.getQueryParameter("domain");
|
|
|
|
if ("telegrampassport".equals(username)) {
|
|
|
|
username = null;
|
|
|
|
auth = new HashMap<>();
|
|
|
|
String scope = data.getQueryParameter("scope");
|
|
|
|
if (!TextUtils.isEmpty(scope) && scope.startsWith("{") && scope.endsWith("}")) {
|
|
|
|
auth.put("nonce", data.getQueryParameter("nonce"));
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
2020-08-15 23:06:36 +02:00
|
|
|
auth.put("payload", data.getQueryParameter("payload"));
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
auth.put("bot_id", data.getQueryParameter("bot_id"));
|
|
|
|
auth.put("scope", scope);
|
|
|
|
auth.put("public_key", data.getQueryParameter("public_key"));
|
|
|
|
auth.put("callback_url", data.getQueryParameter("callback_url"));
|
|
|
|
} else {
|
|
|
|
botUser = data.getQueryParameter("start");
|
|
|
|
botChat = data.getQueryParameter("startgroup");
|
|
|
|
game = data.getQueryParameter("game");
|
2018-07-30 04:07:02 +02:00
|
|
|
messageId = Utilities.parseInt(data.getQueryParameter("post"));
|
2020-08-15 23:06:36 +02:00
|
|
|
if (messageId == 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
messageId = null;
|
2019-02-08 03:30:32 +01:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
threadId = Utilities.parseInt(data.getQueryParameter("thread"));
|
|
|
|
if (threadId == 0) {
|
|
|
|
threadId = null;
|
|
|
|
}
|
|
|
|
commentId = Utilities.parseInt(data.getQueryParameter("comment"));
|
|
|
|
if (commentId == 0) {
|
|
|
|
commentId = null;
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
} else if (url.startsWith("tg:privatepost") || url.startsWith("tg://privatepost")) {
|
|
|
|
url = url.replace("tg:privatepost", "tg://telegram.org").replace("tg://privatepost", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
messageId = Utilities.parseInt(data.getQueryParameter("post"));
|
|
|
|
channelId = Utilities.parseInt(data.getQueryParameter("channel"));
|
|
|
|
if (messageId == 0 || channelId == 0) {
|
|
|
|
messageId = null;
|
|
|
|
channelId = null;
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
threadId = Utilities.parseInt(data.getQueryParameter("thread"));
|
|
|
|
if (threadId == 0) {
|
|
|
|
threadId = null;
|
|
|
|
}
|
|
|
|
commentId = Utilities.parseInt(data.getQueryParameter("comment"));
|
|
|
|
if (commentId == 0) {
|
|
|
|
commentId = null;
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else if (url.startsWith("tg:bg") || url.startsWith("tg://bg")) {
|
|
|
|
url = url.replace("tg:bg", "tg://telegram.org").replace("tg://bg", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
wallPaper = new TLRPC.TL_wallPaper();
|
|
|
|
wallPaper.settings = new TLRPC.TL_wallPaperSettings();
|
|
|
|
wallPaper.slug = data.getQueryParameter("slug");
|
|
|
|
if (wallPaper.slug == null) {
|
|
|
|
wallPaper.slug = data.getQueryParameter("color");
|
|
|
|
}
|
|
|
|
if (wallPaper.slug != null && wallPaper.slug.length() == 6) {
|
|
|
|
try {
|
|
|
|
wallPaper.settings.background_color = Integer.parseInt(wallPaper.slug, 16) | 0xff000000;
|
|
|
|
} catch (Exception ignore) {
|
2019-12-31 14:08:08 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
wallPaper.slug = null;
|
|
|
|
} else if (wallPaper.slug != null && wallPaper.slug.length() == 13 && wallPaper.slug.charAt(6) == '-') {
|
|
|
|
try {
|
|
|
|
wallPaper.settings.background_color = Integer.parseInt(wallPaper.slug.substring(0, 6), 16) | 0xff000000;
|
|
|
|
wallPaper.settings.second_background_color = Integer.parseInt(wallPaper.slug.substring(7), 16) | 0xff000000;
|
|
|
|
wallPaper.settings.rotation = 45;
|
|
|
|
} catch (Exception ignore) {
|
2019-12-31 14:08:08 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
String rotation = data.getQueryParameter("rotation");
|
|
|
|
if (!TextUtils.isEmpty(rotation)) {
|
|
|
|
wallPaper.settings.rotation = Utilities.parseInt(rotation);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception ignore) {
|
2019-12-31 14:08:08 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
wallPaper.slug = null;
|
|
|
|
} else {
|
|
|
|
String mode = data.getQueryParameter("mode");
|
|
|
|
if (mode != null) {
|
|
|
|
mode = mode.toLowerCase();
|
|
|
|
String[] modes = mode.split(" ");
|
|
|
|
if (modes != null && modes.length > 0) {
|
|
|
|
for (int a = 0; a < modes.length; a++) {
|
|
|
|
if ("blur".equals(modes[a])) {
|
|
|
|
wallPaper.settings.blur = true;
|
|
|
|
} else if ("motion".equals(modes[a])) {
|
|
|
|
wallPaper.settings.motion = true;
|
2019-02-08 03:30:32 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
wallPaper.settings.intensity = Utilities.parseInt(data.getQueryParameter("intensity"));
|
|
|
|
try {
|
|
|
|
String bgColor = data.getQueryParameter("bg_color");
|
|
|
|
if (!TextUtils.isEmpty(bgColor)) {
|
|
|
|
wallPaper.settings.background_color = Integer.parseInt(bgColor.substring(0, 6), 16) | 0xff000000;
|
|
|
|
if (bgColor.length() > 6) {
|
|
|
|
wallPaper.settings.second_background_color = Integer.parseInt(bgColor.substring(7), 16) | 0xff000000;
|
|
|
|
wallPaper.settings.rotation = 45;
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2019-02-08 03:30:32 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception ignore) {
|
2019-02-08 03:30:32 +01:00
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
try {
|
|
|
|
String rotation = data.getQueryParameter("rotation");
|
|
|
|
if (!TextUtils.isEmpty(rotation)) {
|
|
|
|
wallPaper.settings.rotation = Utilities.parseInt(rotation);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
} else if (url.startsWith("tg:join") || url.startsWith("tg://join")) {
|
|
|
|
url = url.replace("tg:join", "tg://telegram.org").replace("tg://join", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
group = data.getQueryParameter("invite");
|
|
|
|
} else if (url.startsWith("tg:addstickers") || url.startsWith("tg://addstickers")) {
|
|
|
|
url = url.replace("tg:addstickers", "tg://telegram.org").replace("tg://addstickers", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
sticker = data.getQueryParameter("set");
|
|
|
|
} else if (url.startsWith("tg:msg") || url.startsWith("tg://msg") || url.startsWith("tg://share") || url.startsWith("tg:share")) {
|
|
|
|
url = url.replace("tg:msg", "tg://telegram.org").replace("tg://msg", "tg://telegram.org").replace("tg://share", "tg://telegram.org").replace("tg:share", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
message = data.getQueryParameter("url");
|
|
|
|
if (message == null) {
|
|
|
|
message = "";
|
|
|
|
}
|
|
|
|
if (data.getQueryParameter("text") != null) {
|
|
|
|
if (message.length() > 0) {
|
|
|
|
hasUrl = true;
|
|
|
|
message += "\n";
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
message += data.getQueryParameter("text");
|
|
|
|
}
|
|
|
|
if (message.length() > 4096 * 4) {
|
|
|
|
message = message.substring(0, 4096 * 4);
|
|
|
|
}
|
|
|
|
while (message.endsWith("\n")) {
|
|
|
|
message = message.substring(0, message.length() - 1);
|
|
|
|
}
|
|
|
|
} else if (url.startsWith("tg:confirmphone") || url.startsWith("tg://confirmphone")) {
|
|
|
|
url = url.replace("tg:confirmphone", "tg://telegram.org").replace("tg://confirmphone", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
|
|
|
|
phone = data.getQueryParameter("phone");
|
|
|
|
phoneHash = data.getQueryParameter("hash");
|
|
|
|
} else if (url.startsWith("tg:login") || url.startsWith("tg://login")) {
|
|
|
|
url = url.replace("tg:login", "tg://telegram.org").replace("tg://login", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
login = data.getQueryParameter("token");
|
|
|
|
code = data.getQueryParameter("code");
|
|
|
|
} else if (url.startsWith("tg:openmessage") || url.startsWith("tg://openmessage")) {
|
|
|
|
url = url.replace("tg:openmessage", "tg://telegram.org").replace("tg://openmessage", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
|
|
|
|
String userID = data.getQueryParameter("user_id");
|
|
|
|
String chatID = data.getQueryParameter("chat_id");
|
|
|
|
String msgID = data.getQueryParameter("message_id");
|
|
|
|
if (userID != null) {
|
|
|
|
try {
|
|
|
|
push_user_id = Integer.parseInt(userID);
|
|
|
|
} catch (NumberFormatException ignore) {
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else if (chatID != null) {
|
|
|
|
try {
|
|
|
|
push_chat_id = Integer.parseInt(chatID);
|
|
|
|
} catch (NumberFormatException ignore) {
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
if (msgID != null) {
|
|
|
|
try {
|
|
|
|
push_msg_id = Integer.parseInt(msgID);
|
|
|
|
} catch (NumberFormatException ignore) {
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
} else if (url.startsWith("tg:passport") || url.startsWith("tg://passport") || url.startsWith("tg:secureid")) {
|
|
|
|
url = url.replace("tg:passport", "tg://telegram.org").replace("tg://passport", "tg://telegram.org").replace("tg:secureid", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
auth = new HashMap<>();
|
|
|
|
String scope = data.getQueryParameter("scope");
|
|
|
|
if (!TextUtils.isEmpty(scope) && scope.startsWith("{") && scope.endsWith("}")) {
|
|
|
|
auth.put("nonce", data.getQueryParameter("nonce"));
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
2020-08-15 23:06:36 +02:00
|
|
|
auth.put("payload", data.getQueryParameter("payload"));
|
|
|
|
}
|
|
|
|
auth.put("bot_id", data.getQueryParameter("bot_id"));
|
|
|
|
auth.put("scope", scope);
|
|
|
|
auth.put("public_key", data.getQueryParameter("public_key"));
|
|
|
|
auth.put("callback_url", data.getQueryParameter("callback_url"));
|
|
|
|
} else if (url.startsWith("tg:setlanguage") || url.startsWith("tg://setlanguage")) {
|
|
|
|
url = url.replace("tg:setlanguage", "tg://telegram.org").replace("tg://setlanguage", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
lang = data.getQueryParameter("lang");
|
|
|
|
} else if (url.startsWith("tg:addtheme") || url.startsWith("tg://addtheme")) {
|
|
|
|
url = url.replace("tg:addtheme", "tg://telegram.org").replace("tg://addtheme", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
theme = data.getQueryParameter("slug");
|
|
|
|
} else if (url.startsWith("tg:settings") || url.startsWith("tg://settings")) {
|
|
|
|
if (url.contains("themes")) {
|
|
|
|
open_settings = 2;
|
|
|
|
} else if (url.contains("devices")) {
|
|
|
|
open_settings = 3;
|
|
|
|
} else if (url.contains("folders")) {
|
|
|
|
open_settings = 4;
|
|
|
|
} else if (url.contains("change_number")) {
|
|
|
|
open_settings = 5;
|
2020-08-16 03:13:38 +02:00
|
|
|
} else if (url.contains("neko")) {
|
2020-10-01 11:01:48 +02:00
|
|
|
open_settings = 100;
|
2020-09-30 15:48:47 +02:00
|
|
|
} else {
|
|
|
|
open_settings = 1;
|
|
|
|
}
|
2020-09-03 17:37:42 +02:00
|
|
|
} else if (url.startsWith("tg:user") || url.startsWith("tg://user")) {
|
|
|
|
try {
|
|
|
|
url = url.replace("tg:user", "tg://telegram.org").replace("tg://user", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
int userId = Utilities.parseInt(data.getQueryParameter("id"));
|
|
|
|
if (userId != 0) {
|
|
|
|
push_user_id = userId;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2020-10-05 00:13:31 +02:00
|
|
|
} else if ((url.startsWith("tg:search") || url.startsWith("tg://search"))) {
|
2020-09-30 15:48:47 +02:00
|
|
|
url = url.replace("tg:search", "tg://telegram.org").replace("tg://search", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
searchQuery = data.getQueryParameter("query");
|
|
|
|
if (searchQuery != null) {
|
|
|
|
searchQuery = searchQuery.trim();
|
|
|
|
} else {
|
|
|
|
searchQuery = "";
|
|
|
|
}
|
2020-10-05 00:13:31 +02:00
|
|
|
} else if ((url.startsWith("tg:calllog") || url.startsWith("tg://calllog"))) {
|
2020-09-30 15:48:47 +02:00
|
|
|
showCallLog = true;
|
2020-10-05 00:13:31 +02:00
|
|
|
} else if ((url.startsWith("tg:call") || url.startsWith("tg://call"))) {
|
2020-09-30 15:48:47 +02:00
|
|
|
if (UserConfig.getInstance(currentAccount).isClientActivated()) {
|
|
|
|
final String extraForceCall = "extra_force_call";
|
|
|
|
if (ContactsController.getInstance(currentAccount).contactsLoaded || intent.hasExtra(extraForceCall)) {
|
|
|
|
final String callFormat = data.getQueryParameter("format");
|
|
|
|
final String callUserName = data.getQueryParameter("name");
|
|
|
|
final String callPhone = data.getQueryParameter("phone");
|
|
|
|
final List<TLRPC.TL_contact> contacts = findContacts(callUserName, callPhone, false);
|
|
|
|
|
2020-10-05 00:13:31 +02:00
|
|
|
if (contacts.isEmpty() && callPhone != null) {
|
|
|
|
newContactName = callUserName;
|
|
|
|
newContactPhone = callPhone;
|
|
|
|
newContactAlert = true;
|
|
|
|
} else {
|
|
|
|
if (contacts.size() == 1) {
|
|
|
|
push_user_id = contacts.get(0).user_id;
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
|
2020-10-05 00:13:31 +02:00
|
|
|
if (push_user_id == 0) {
|
|
|
|
callSearchQuery = callUserName != null ? callUserName : "";
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
|
2020-10-05 00:13:31 +02:00
|
|
|
if ("video".equalsIgnoreCase(callFormat)) {
|
|
|
|
videoCallUser = true;
|
|
|
|
} else {
|
|
|
|
audioCallUser = true;
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
|
2020-10-05 00:13:31 +02:00
|
|
|
needCallAlert = true;
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
} else {
|
|
|
|
final Intent copyIntent = new Intent(intent);
|
|
|
|
copyIntent.removeExtra(EXTRA_ACTION_TOKEN);
|
|
|
|
copyIntent.putExtra(extraForceCall, true);
|
|
|
|
ContactsLoadingObserver.observe((contactsLoaded) -> handleIntent(copyIntent, true, false, false), 1000);
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
2020-10-05 00:13:31 +02:00
|
|
|
} else if ((url.startsWith("tg:scanqr") || url.startsWith("tg://scanqr"))) {
|
2020-09-30 15:48:47 +02:00
|
|
|
scanQr = true;
|
2020-10-05 00:13:31 +02:00
|
|
|
} else if ((url.startsWith("tg:addcontact") || url.startsWith("tg://addcontact"))) {
|
2020-09-30 15:48:47 +02:00
|
|
|
url = url.replace("tg:addcontact", "tg://telegram.org").replace("tg://addcontact", "tg://telegram.org");
|
|
|
|
data = Uri.parse(url);
|
|
|
|
newContactName = data.getQueryParameter("name");
|
|
|
|
newContactPhone = data.getQueryParameter("phone");
|
|
|
|
newContact = true;
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
unsupportedUrl = url.replace("tg://", "").replace("tg:", "");
|
|
|
|
int index;
|
|
|
|
if ((index = unsupportedUrl.indexOf('?')) >= 0) {
|
|
|
|
unsupportedUrl = unsupportedUrl.substring(0, index);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
break;
|
2014-12-01 18:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
2020-10-04 12:14:58 +02:00
|
|
|
/*if (intent.hasExtra(EXTRA_ACTION_TOKEN)) {
|
2020-09-30 15:48:47 +02:00
|
|
|
final boolean success = UserConfig.getInstance(currentAccount).isClientActivated() && "tg".equals(scheme) && unsupportedUrl == null;
|
|
|
|
final Action action = new AssistActionBuilder()
|
|
|
|
.setActionToken(intent.getStringExtra(EXTRA_ACTION_TOKEN))
|
|
|
|
.setActionStatus(success ? Action.Builder.STATUS_TYPE_COMPLETED : Action.Builder.STATUS_TYPE_FAILED)
|
|
|
|
.build();
|
|
|
|
FirebaseUserActions.getInstance().end(action);
|
|
|
|
intent.removeExtra(EXTRA_ACTION_TOKEN);
|
2020-10-04 12:14:58 +02:00
|
|
|
}*/
|
2020-08-15 23:06:36 +02:00
|
|
|
if (code != null || UserConfig.getInstance(currentAccount).isClientActivated()) {
|
|
|
|
if (phone != null || phoneHash != null) {
|
|
|
|
final Bundle args = new Bundle();
|
|
|
|
args.putString("phone", phone);
|
|
|
|
args.putString("hash", phoneHash);
|
|
|
|
AndroidUtilities.runOnUIThread(() -> presentFragment(new CancelAccountDeletionActivity(args)));
|
|
|
|
} else if (username != null || group != null || sticker != null || message != null || game != null || auth != null || unsupportedUrl != null || lang != null || code != null || wallPaper != null || channelId != null || theme != null || login != null) {
|
|
|
|
if (message != null && message.startsWith("@")) {
|
|
|
|
message = " " + message;
|
|
|
|
}
|
2020-10-01 11:01:48 +02:00
|
|
|
runLinkRequest(intentAccount[0], username, group, sticker, botUser, botChat, message, hasUrl, messageId, channelId, threadId, commentId, game, auth, lang, unsupportedUrl, code, login, wallPaper, theme, internal ? 3 : 0);
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
try (Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null)) {
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
int accountId = Utilities.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME)));
|
|
|
|
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
|
|
|
|
if (UserConfig.getInstance(a).getClientUserId() == accountId) {
|
|
|
|
intentAccount[0] = a;
|
|
|
|
switchToAccount(intentAccount[0], true);
|
|
|
|
break;
|
2020-08-14 18:58:22 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
int userId = cursor.getInt(cursor.getColumnIndex(ContactsContract.Data.DATA4));
|
|
|
|
NotificationCenter.getInstance(intentAccount[0]).postNotificationName(NotificationCenter.closeChats);
|
|
|
|
push_user_id = userId;
|
|
|
|
String mimeType = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE));
|
|
|
|
if (TextUtils.equals(mimeType, "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call")) {
|
|
|
|
audioCallUser = true;
|
|
|
|
} else if (TextUtils.equals(mimeType, "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call.video")) {
|
|
|
|
videoCallUser = true;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2014-12-01 18:56:31 +01:00
|
|
|
}
|
2014-05-17 01:05:49 +02:00
|
|
|
}
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) {
|
|
|
|
open_settings = 1;
|
|
|
|
} else if (intent.getAction().equals("new_dialog")) {
|
|
|
|
open_new_dialog = 1;
|
|
|
|
} else if (intent.getAction().startsWith("com.tmessages.openchat")) {
|
|
|
|
int chatId = intent.getIntExtra("chatId", 0);
|
|
|
|
int userId = intent.getIntExtra("userId", 0);
|
|
|
|
int encId = intent.getIntExtra("encId", 0);
|
|
|
|
if (chatId != 0) {
|
|
|
|
NotificationCenter.getInstance(intentAccount[0]).postNotificationName(NotificationCenter.closeChats);
|
|
|
|
push_chat_id = chatId;
|
|
|
|
} else if (userId != 0) {
|
|
|
|
NotificationCenter.getInstance(intentAccount[0]).postNotificationName(NotificationCenter.closeChats);
|
|
|
|
push_user_id = userId;
|
|
|
|
} else if (encId != 0) {
|
|
|
|
NotificationCenter.getInstance(intentAccount[0]).postNotificationName(NotificationCenter.closeChats);
|
|
|
|
push_enc_id = encId;
|
|
|
|
} else {
|
|
|
|
showDialogsList = true;
|
|
|
|
}
|
|
|
|
} else if (intent.getAction().equals("com.tmessages.openplayer")) {
|
|
|
|
showPlayer = true;
|
|
|
|
} else if (intent.getAction().equals("org.tmessages.openlocations")) {
|
|
|
|
showLocations = true;
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
if (UserConfig.getInstance(currentAccount).isClientActivated()) {
|
2020-09-30 15:48:47 +02:00
|
|
|
if (searchQuery != null) {
|
|
|
|
final BaseFragment lastFragment = actionBarLayout.getLastFragment();
|
|
|
|
if (lastFragment instanceof DialogsActivity) {
|
|
|
|
final DialogsActivity dialogsActivity = (DialogsActivity) lastFragment;
|
|
|
|
if (dialogsActivity.isMainDialogList()) {
|
|
|
|
if (dialogsActivity.getFragmentView() != null) {
|
|
|
|
dialogsActivity.search(searchQuery, true);
|
|
|
|
} else {
|
|
|
|
dialogsActivity.setInitialSearchString(searchQuery);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showDialogsList = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
if (push_user_id != 0) {
|
2020-09-30 15:48:47 +02:00
|
|
|
if (audioCallUser || videoCallUser) {
|
|
|
|
if (needCallAlert) {
|
|
|
|
final BaseFragment lastFragment = actionBarLayout.getLastFragment();
|
|
|
|
if (lastFragment != null) {
|
|
|
|
AlertsCreator.createCallDialogAlert(lastFragment, lastFragment.getMessagesController().getUser(push_user_id), videoCallUser);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VoIPPendingCall.startOrSchedule(this, push_user_id, videoCallUser);
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
Bundle args = new Bundle();
|
2020-08-15 23:06:36 +02:00
|
|
|
args.putInt("user_id", push_user_id);
|
|
|
|
if (push_msg_id != 0) {
|
2019-01-23 18:03:33 +01:00
|
|
|
args.putInt("message_id", push_msg_id);
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount[0]).checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
|
|
|
if (actionBarLayout.presentFragment(fragment, false, true, true, false)) {
|
|
|
|
pushOpened = true;
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
} else if (push_chat_id != 0) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", push_chat_id);
|
|
|
|
if (push_msg_id != 0)
|
|
|
|
args.putInt("message_id", push_msg_id);
|
|
|
|
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount[0]).checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
|
2016-03-16 13:26:32 +01:00
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (actionBarLayout.presentFragment(fragment, false, true, true, false)) {
|
2016-03-16 13:26:32 +01:00
|
|
|
pushOpened = true;
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
} else if (push_enc_id != 0) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("enc_id", push_enc_id);
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
|
|
|
if (actionBarLayout.presentFragment(fragment, false, true, true, false)) {
|
|
|
|
pushOpened = true;
|
|
|
|
}
|
|
|
|
} else if (showDialogsList) {
|
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.removeAllFragments();
|
|
|
|
} else {
|
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
layersActionBarLayout.closeLastFragment(false);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
|
|
|
pushOpened = false;
|
|
|
|
isNew = false;
|
|
|
|
} else if (showPlayer) {
|
|
|
|
if (!actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment fragment = actionBarLayout.fragmentsStack.get(0);
|
|
|
|
fragment.showDialog(new AudioPlayerAlert(this));
|
|
|
|
}
|
|
|
|
pushOpened = false;
|
|
|
|
} else if (showLocations) {
|
|
|
|
if (!actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment fragment = actionBarLayout.fragmentsStack.get(0);
|
|
|
|
fragment.showDialog(new SharingLocationsAlert(this, info -> {
|
|
|
|
intentAccount[0] = info.messageObject.currentAccount;
|
|
|
|
switchToAccount(intentAccount[0], true);
|
|
|
|
|
|
|
|
LocationActivity locationActivity = new LocationActivity(2);
|
|
|
|
locationActivity.setMessageObject(info.messageObject);
|
|
|
|
final long dialog_id = info.messageObject.getDialogId();
|
2020-09-30 15:48:47 +02:00
|
|
|
locationActivity.setDelegate((location, live, notify, scheduleDate) -> SendMessagesHelper.getInstance(intentAccount[0]).sendMessage(location, dialog_id, null, null, null, null, notify, scheduleDate));
|
2020-08-15 23:06:36 +02:00
|
|
|
presentFragment(locationActivity);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
pushOpened = false;
|
2020-08-16 03:13:38 +02:00
|
|
|
} else if (videoPath != null || photoPathsArray != null || sendingText != null || sendingLocation != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
|
2020-08-15 23:06:36 +02:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
NotificationCenter.getInstance(intentAccount[0]).postNotificationName(NotificationCenter.closeChats);
|
|
|
|
}
|
|
|
|
if (dialogId == 0) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
|
|
|
args.putInt("dialogsType", 3);
|
|
|
|
args.putBoolean("allowSwitchAccount", true);
|
|
|
|
if (contactsToSend != null) {
|
|
|
|
if (contactsToSend.size() != 1) {
|
|
|
|
args.putString("selectAlertString", LocaleController.getString("SendContactToText", R.string.SendMessagesToText));
|
|
|
|
args.putString("selectAlertStringGroup", LocaleController.getString("SendContactToGroupText", R.string.SendContactToGroupText));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
} else {
|
2020-08-15 23:06:36 +02:00
|
|
|
args.putString("selectAlertString", LocaleController.getString("SendMessagesToText", R.string.SendMessagesToText));
|
|
|
|
args.putString("selectAlertStringGroup", LocaleController.getString("SendMessagesToGroupText", R.string.SendMessagesToGroupText));
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
|
|
|
fragment.setDelegate(this);
|
|
|
|
boolean removeLast;
|
2015-10-29 18:10:07 +01:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2020-08-15 23:06:36 +02:00
|
|
|
removeLast = layersActionBarLayout.fragmentsStack.size() > 0 && layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
|
2015-10-29 18:10:07 +01:00
|
|
|
} else {
|
2020-08-15 23:06:36 +02:00
|
|
|
removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
actionBarLayout.presentFragment(fragment, removeLast, true, true, false);
|
2015-10-29 18:10:07 +01:00
|
|
|
pushOpened = true;
|
2020-08-15 23:06:36 +02:00
|
|
|
if (SecretMediaViewer.hasInstance() && SecretMediaViewer.getInstance().isVisible()) {
|
|
|
|
SecretMediaViewer.getInstance().closePhoto(false, false);
|
|
|
|
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
|
|
|
PhotoViewer.getInstance().closePhoto(false, true);
|
|
|
|
} else if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
|
|
|
ArticleViewer.getInstance().close(false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
ArrayList<Long> dids = new ArrayList<>();
|
|
|
|
dids.add(dialogId);
|
|
|
|
didSelectDialogs(null, dids, null, false);
|
|
|
|
}
|
|
|
|
} else if (open_settings != 0) {
|
|
|
|
BaseFragment fragment;
|
|
|
|
boolean closePrevious = false;
|
|
|
|
if (open_settings == 1) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", UserConfig.getInstance(currentAccount).clientUserId);
|
|
|
|
fragment = new ProfileActivity(args);
|
|
|
|
} else if (open_settings == 2) {
|
|
|
|
fragment = new ThemeActivity(ThemeActivity.THEME_TYPE_BASIC);
|
|
|
|
} else if (open_settings == 3) {
|
|
|
|
fragment = new SessionsActivity(0);
|
|
|
|
} else if (open_settings == 4) {
|
|
|
|
fragment = new FiltersSetupActivity();
|
|
|
|
} else if (open_settings == 5) {
|
|
|
|
fragment = new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANGE_PHONE_NUMBER);
|
|
|
|
closePrevious = true;
|
2020-08-16 03:13:38 +02:00
|
|
|
} else if (open_settings == 100) {
|
2020-10-01 11:01:48 +02:00
|
|
|
fragment = new NekoSettingsActivity();
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
fragment = null;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
boolean closePreviousFinal = closePrevious;
|
|
|
|
AndroidUtilities.runOnUIThread(() -> presentFragment(fragment, closePreviousFinal, false));
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
pushOpened = true;
|
|
|
|
} else if (open_new_dialog != 0) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("destroyAfterSelect", true);
|
|
|
|
actionBarLayout.presentFragment(new ContactsActivity(args), false, true, true, false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
pushOpened = true;
|
2020-09-30 15:48:47 +02:00
|
|
|
} else if (callSearchQuery != null) {
|
|
|
|
final Bundle args = new Bundle();
|
|
|
|
args.putBoolean("destroyAfterSelect", true);
|
|
|
|
args.putBoolean("returnAsResult", true);
|
|
|
|
args.putBoolean("onlyUsers", true);
|
|
|
|
args.putBoolean("allowSelf", false);
|
|
|
|
final ContactsActivity contactsFragment = new ContactsActivity(args);
|
|
|
|
contactsFragment.setInitialSearchString(callSearchQuery);
|
|
|
|
final boolean videoCall = videoCallUser;
|
|
|
|
contactsFragment.setDelegate((user, param, activity) -> {
|
|
|
|
final TLRPC.UserFull userFull = MessagesController.getInstance(currentAccount).getUserFull(user.id);
|
|
|
|
VoIPHelper.startCall(user, videoCall, userFull != null && userFull.video_calls_available, LaunchActivity.this, userFull);
|
|
|
|
});
|
|
|
|
actionBarLayout.presentFragment(contactsFragment, actionBarLayout.getLastFragment() instanceof ContactsActivity, true, true, false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
pushOpened = true;
|
|
|
|
} else if (scanQr) {
|
|
|
|
ActionIntroActivity fragment = new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_QR_LOGIN);
|
|
|
|
fragment.setQrLoginDelegate(code -> {
|
|
|
|
AlertDialog progressDialog = new AlertDialog(LaunchActivity.this, 3);
|
|
|
|
progressDialog.setCanCacnel(false);
|
|
|
|
progressDialog.show();
|
|
|
|
byte[] token = Base64.decode(code.substring("tg://login?token=".length()), Base64.URL_SAFE);
|
|
|
|
TLRPC.TL_auth_acceptLoginToken req = new TLRPC.TL_auth_acceptLoginToken();
|
|
|
|
req.token = token;
|
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
}
|
|
|
|
if (!(response instanceof TLRPC.TL_authorization)) {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> AlertsCreator.showSimpleAlert(fragment, LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient), LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
actionBarLayout.presentFragment(fragment, false, true, true, false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
pushOpened = true;
|
|
|
|
} else if (newContact) {
|
|
|
|
final NewContactActivity fragment = new NewContactActivity();
|
|
|
|
if (newContactName != null) {
|
|
|
|
final String[] names = newContactName.split(" ", 2);
|
|
|
|
fragment.setInitialName(names[0], names.length > 1 ? names[1] : null);
|
|
|
|
}
|
|
|
|
if (newContactPhone != null) {
|
2020-10-02 23:48:16 +02:00
|
|
|
fragment.setInitialPhoneNumber(PhoneFormat.stripExceptNumbers(newContactPhone, true), false);
|
2020-09-30 15:48:47 +02:00
|
|
|
}
|
|
|
|
actionBarLayout.presentFragment(fragment, false, true, true, false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
pushOpened = true;
|
2020-10-05 00:13:31 +02:00
|
|
|
} else if (newContactAlert) {
|
|
|
|
final BaseFragment lastFragment = actionBarLayout.getLastFragment();
|
|
|
|
if (lastFragment != null && lastFragment.getParentActivity() != null) {
|
|
|
|
final String finalNewContactName = newContactName;
|
2020-10-15 02:39:36 +02:00
|
|
|
final String finalNewContactPhone = NewContactActivity.getPhoneNumber(this, UserConfig.getInstance(currentAccount).getCurrentUser(), newContactPhone, false);
|
2020-10-05 00:13:31 +02:00
|
|
|
final AlertDialog newContactAlertDialog = new AlertDialog.Builder(lastFragment.getParentActivity())
|
|
|
|
.setTitle(LocaleController.getString("NewContactAlertTitle", R.string.NewContactAlertTitle))
|
|
|
|
.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("NewContactAlertMessage", R.string.NewContactAlertMessage, PhoneFormat.getInstance().format(finalNewContactPhone))))
|
|
|
|
.setPositiveButton(LocaleController.getString("NewContactAlertButton", R.string.NewContactAlertButton), (d, i) -> {
|
|
|
|
final NewContactActivity fragment = new NewContactActivity();
|
|
|
|
fragment.setInitialPhoneNumber(finalNewContactPhone, false);
|
|
|
|
if (finalNewContactName != null) {
|
|
|
|
final String[] names = finalNewContactName.split(" ", 2);
|
|
|
|
fragment.setInitialName(names[0], names.length > 1 ? names[1] : null);
|
|
|
|
}
|
|
|
|
lastFragment.presentFragment(fragment);
|
|
|
|
})
|
|
|
|
.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)
|
|
|
|
.create();
|
|
|
|
lastFragment.showDialog(newContactAlertDialog);
|
|
|
|
pushOpened = true;
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
} else if (showCallLog) {
|
|
|
|
actionBarLayout.presentFragment(new CallLogActivity(), false, true, true, false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
pushOpened = true;
|
2014-11-19 02:23:46 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
if (!pushOpened && !isNew) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
|
|
|
|
if (layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
layersActionBarLayout.addFragmentToStack(new LoginActivity());
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
|
|
|
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
2020-08-15 23:06:36 +02:00
|
|
|
DialogsActivity dialogsActivity = new DialogsActivity(null);
|
|
|
|
dialogsActivity.setSideMenu(sideMenu);
|
2020-09-30 15:48:47 +02:00
|
|
|
if (searchQuery != null) {
|
|
|
|
dialogsActivity.setInitialSearchString(searchQuery);
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
actionBarLayout.addFragmentToStack(dialogsActivity);
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
} else {
|
|
|
|
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
|
|
|
|
actionBarLayout.addFragmentToStack(new LoginActivity());
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
DialogsActivity dialogsActivity = new DialogsActivity(null);
|
|
|
|
dialogsActivity.setSideMenu(sideMenu);
|
2020-09-30 15:48:47 +02:00
|
|
|
if (searchQuery != null) {
|
|
|
|
dialogsActivity.setInitialSearchString(searchQuery);
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
actionBarLayout.addFragmentToStack(dialogsActivity);
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
layersActionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
2020-08-14 18:58:22 +02:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
}
|
2020-08-14 18:58:22 +02:00
|
|
|
|
2020-08-15 23:06:36 +02:00
|
|
|
if (isVoipIntent) {
|
2020-10-31 22:13:37 +01:00
|
|
|
VoIPFragment.show(this, intentAccount[0]);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2020-08-15 23:06:36 +02:00
|
|
|
|
|
|
|
intent.setAction(null);
|
|
|
|
return pushOpened;
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
private int runCommentRequest(int intentAccount, AlertDialog progressDialog, Integer messageId, Integer commentId, Integer threadId, TLRPC.Chat chat) {
|
|
|
|
if (chat == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
TLRPC.TL_messages_getDiscussionMessage req = new TLRPC.TL_messages_getDiscussionMessage();
|
|
|
|
req.peer = MessagesController.getInputPeer(chat);
|
|
|
|
req.msg_id = commentId != null ? messageId : threadId;
|
|
|
|
return ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
boolean chatOpened = false;
|
|
|
|
if (response instanceof TLRPC.TL_messages_discussionMessage) {
|
|
|
|
TLRPC.TL_messages_discussionMessage res = (TLRPC.TL_messages_discussionMessage) response;
|
|
|
|
MessagesController.getInstance(intentAccount).putUsers(res.users, false);
|
|
|
|
MessagesController.getInstance(intentAccount).putChats(res.chats, false);
|
|
|
|
ArrayList<MessageObject> arrayList = new ArrayList<>();
|
|
|
|
for (int a = 0, N = res.messages.size(); a < N; a++) {
|
|
|
|
arrayList.add(new MessageObject(UserConfig.selectedAccount, res.messages.get(a), true, true));
|
|
|
|
}
|
|
|
|
if (!arrayList.isEmpty()) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", (int) -arrayList.get(0).getDialogId());
|
|
|
|
args.putInt("message_id", Math.max(1, messageId));
|
|
|
|
ChatActivity chatActivity = new ChatActivity(args);
|
|
|
|
chatActivity.setThreadMessages(arrayList, chat, req.msg_id, res.read_inbox_max_id, res.read_outbox_max_id);
|
|
|
|
if (commentId != null) {
|
|
|
|
chatActivity.setHighlightMessageId(commentId);
|
2020-10-15 02:39:36 +02:00
|
|
|
} else if (threadId != null) {
|
|
|
|
chatActivity.setHighlightMessageId(messageId);
|
2020-09-30 15:48:47 +02:00
|
|
|
}
|
|
|
|
presentFragment(chatActivity);
|
|
|
|
chatOpened = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!chatOpened) {
|
|
|
|
try {
|
|
|
|
Toast.makeText(LaunchActivity.this, LocaleController.getString("ChannelPostDeleted", R.string.ChannelPostDeleted), Toast.LENGTH_SHORT).show();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private void runLinkRequest(final int intentAccount,
|
|
|
|
final String username,
|
|
|
|
final String group,
|
|
|
|
final String sticker,
|
|
|
|
final String botUser,
|
|
|
|
final String botChat,
|
|
|
|
final String message,
|
|
|
|
final boolean hasUrl,
|
|
|
|
final Integer messageId,
|
2019-05-14 14:08:05 +02:00
|
|
|
final Integer channelId,
|
2020-09-30 15:48:47 +02:00
|
|
|
final Integer threadId,
|
|
|
|
final Integer commentId,
|
2019-01-23 18:03:33 +01:00
|
|
|
final String game,
|
|
|
|
final HashMap<String, String> auth,
|
|
|
|
final String lang,
|
|
|
|
final String unsupportedUrl,
|
|
|
|
final String code,
|
2019-12-31 14:08:08 +01:00
|
|
|
final String loginToken,
|
2019-02-08 03:30:32 +01:00
|
|
|
final TLRPC.TL_wallPaper wallPaper,
|
2019-09-10 12:56:11 +02:00
|
|
|
final String theme,
|
2019-01-23 18:03:33 +01:00
|
|
|
final int state) {
|
2019-06-19 14:41:36 +02:00
|
|
|
if (state == 0 && UserConfig.getActivatedAccountsCount() >= 2) {
|
2018-08-27 10:33:11 +02:00
|
|
|
AlertsCreator.createAccountSelectDialog(this, account -> {
|
|
|
|
if (account != intentAccount) {
|
|
|
|
switchToAccount(account, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2020-10-01 11:01:48 +02:00
|
|
|
runLinkRequest(account, username, group, sticker, botUser, botChat, message, hasUrl, messageId, channelId, threadId, commentId, game, auth, lang, unsupportedUrl, code, loginToken, wallPaper, theme, 3);
|
2018-07-30 04:07:02 +02:00
|
|
|
}).show();
|
|
|
|
return;
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (code != null) {
|
|
|
|
if (NotificationCenter.getGlobalInstance().hasObservers(NotificationCenter.didReceiveSmsCode)) {
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, code);
|
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
|
2020-06-25 17:28:55 +02:00
|
|
|
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
|
2019-01-23 18:03:33 +01:00
|
|
|
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("OtherLoginCode", R.string.OtherLoginCode, code)));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
showAlertDialog(builder);
|
|
|
|
}
|
|
|
|
return;
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (loginToken != null) {
|
2020-11-27 20:32:39 +01:00
|
|
|
BottomBuilder builder = new BottomBuilder(this);
|
|
|
|
builder.addTitle(LocaleController.getString("AuthAnotherClientScan", R.string.AuthAnotherClientScan), LocaleController.getString("QRLoginNotice",R.string.QRLoginNotice));
|
|
|
|
builder.addItem(LocaleController.getString("QRLoginConfirm", R.string.QRLoginConfirm), R.drawable.baseline_security_24, true, (c) -> {
|
|
|
|
AlertDialog progressDialog = new AlertDialog(this, 3);
|
|
|
|
progressDialog.setCanCacnel(false);
|
|
|
|
progressDialog.show();
|
|
|
|
byte[] token = Base64.decode(loginToken, Base64.URL_SAFE);
|
|
|
|
TLRPC.TL_auth_acceptLoginToken req = new TLRPC.TL_auth_acceptLoginToken();
|
|
|
|
req.token = token;
|
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
}
|
|
|
|
if (response instanceof TLRPC.TL_authorization) {
|
|
|
|
SessionsActivity fragment = new SessionsActivity(0);
|
|
|
|
fragment.newAuthorizationToOpen = (TLRPC.TL_authorization) response;
|
|
|
|
presentFragment(fragment, false, false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
final String text;
|
|
|
|
if (error.text.equals("AUTH_TOKEN_EXCEPTION")) {
|
|
|
|
text = LocaleController.getString("AccountAlreadyLoggedIn", R.string.AccountAlreadyLoggedIn);
|
|
|
|
} else {
|
|
|
|
text = LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text;
|
|
|
|
}
|
|
|
|
AlertUtil.showSimpleAlert(this, LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient), text);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
});
|
|
|
|
builder.addCancelItem();
|
|
|
|
builder.show();
|
2019-12-31 14:08:08 +01:00
|
|
|
return;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
final AlertDialog progressDialog = new AlertDialog(this, 3);
|
2018-07-30 04:07:02 +02:00
|
|
|
final int[] requestId = new int[]{0};
|
2019-09-10 12:56:11 +02:00
|
|
|
Runnable cancelRunnable = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
if (username != null) {
|
|
|
|
TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
|
|
|
|
req.username = username;
|
2018-08-27 10:33:11 +02:00
|
|
|
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (!LaunchActivity.this.isFinishing()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
boolean hideProgressDialog = true;
|
2018-08-27 10:33:11 +02:00
|
|
|
final TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
|
|
|
|
if (error == null && actionBarLayout != null && (game == null || game != null && !res.users.isEmpty())) {
|
|
|
|
MessagesController.getInstance(intentAccount).putUsers(res.users, false);
|
|
|
|
MessagesController.getInstance(intentAccount).putChats(res.chats, false);
|
|
|
|
MessagesStorage.getInstance(intentAccount).putUsersAndChats(res.users, res.chats, false, true);
|
2020-09-30 15:48:47 +02:00
|
|
|
if (messageId != null && (commentId != null || threadId != null) && !res.chats.isEmpty()) {
|
|
|
|
requestId[0] = runCommentRequest(intentAccount, progressDialog, messageId, commentId, threadId, res.chats.get(0));
|
|
|
|
if (requestId[0] != 0) {
|
|
|
|
hideProgressDialog = false;
|
|
|
|
}
|
|
|
|
} else if (game != null) {
|
2018-08-27 10:33:11 +02:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
|
|
|
args.putBoolean("cantSendToChannels", true);
|
|
|
|
args.putInt("dialogsType", 1);
|
2019-12-31 14:08:08 +01:00
|
|
|
args.putString("selectAlertString", LocaleController.getString("SendGameToText", R.string.SendGameToText));
|
|
|
|
args.putString("selectAlertStringGroup", LocaleController.getString("SendGameToGroupText", R.string.SendGameToGroupText));
|
2018-08-27 10:33:11 +02:00
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
|
|
|
fragment.setDelegate((fragment1, dids, message1, param) -> {
|
|
|
|
long did = dids.get(0);
|
|
|
|
TLRPC.TL_inputMediaGame inputMediaGame = new TLRPC.TL_inputMediaGame();
|
|
|
|
inputMediaGame.id = new TLRPC.TL_inputGameShortName();
|
|
|
|
inputMediaGame.id.short_name = game;
|
|
|
|
inputMediaGame.id.bot_id = MessagesController.getInstance(intentAccount).getInputUser(res.users.get(0));
|
|
|
|
SendMessagesHelper.getInstance(intentAccount).sendGame(MessagesController.getInstance(intentAccount).getInputPeer((int) did), inputMediaGame, 0, 0);
|
|
|
|
|
|
|
|
Bundle args1 = new Bundle();
|
|
|
|
args1.putBoolean("scrollToTopOnResume", true);
|
|
|
|
int lower_part = (int) did;
|
|
|
|
int high_id = (int) (did >> 32);
|
|
|
|
if (lower_part != 0) {
|
2019-09-10 12:56:11 +02:00
|
|
|
if (lower_part > 0) {
|
|
|
|
args1.putInt("user_id", lower_part);
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
args1.putInt("chat_id", -lower_part);
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args1.putInt("enc_id", high_id);
|
|
|
|
}
|
|
|
|
if (MessagesController.getInstance(intentAccount).checkCanOpenChat(args1, fragment1)) {
|
|
|
|
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
|
|
|
|
actionBarLayout.presentFragment(new ChatActivity(args1), true, false, true, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
boolean removeLast;
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
removeLast = layersActionBarLayout.fragmentsStack.size() > 0 && layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
|
|
|
|
} else {
|
|
|
|
removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
|
|
|
|
}
|
|
|
|
actionBarLayout.presentFragment(fragment, removeLast, true, true, false);
|
|
|
|
if (SecretMediaViewer.hasInstance() && SecretMediaViewer.getInstance().isVisible()) {
|
|
|
|
SecretMediaViewer.getInstance().closePhoto(false, false);
|
|
|
|
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
|
|
|
PhotoViewer.getInstance().closePhoto(false, true);
|
|
|
|
} else if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
|
|
|
ArticleViewer.getInstance().close(false, true);
|
|
|
|
}
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayout.showLastFragment();
|
|
|
|
rightActionBarLayout.showLastFragment();
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
|
|
|
} else if (botChat != null) {
|
|
|
|
final TLRPC.User user = !res.users.isEmpty() ? res.users.get(0) : null;
|
|
|
|
if (user == null || user.bot && user.bot_nochats) {
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
2018-08-27 10:33:11 +02:00
|
|
|
Toast.makeText(LaunchActivity.this, LocaleController.getString("BotCantJoinGroups", R.string.BotCantJoinGroups), Toast.LENGTH_SHORT).show();
|
2015-05-03 13:48:36 +02:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
|
|
|
args.putInt("dialogsType", 2);
|
2019-12-31 14:08:08 +01:00
|
|
|
args.putString("addToGroupAlertString", LocaleController.formatString("AddToTheGroupAlertText", R.string.AddToTheGroupAlertText, UserObject.getUserName(user), "%1$s"));
|
2018-08-27 10:33:11 +02:00
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
|
|
|
fragment.setDelegate((fragment12, dids, message1, param) -> {
|
|
|
|
long did = dids.get(0);
|
|
|
|
Bundle args12 = new Bundle();
|
|
|
|
args12.putBoolean("scrollToTopOnResume", true);
|
|
|
|
args12.putInt("chat_id", -(int) did);
|
|
|
|
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount).checkCanOpenChat(args12, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
|
|
|
|
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
|
2019-01-23 18:03:33 +01:00
|
|
|
MessagesController.getInstance(intentAccount).addUserToChat(-(int) did, user, null, 0, botChat, null, null);
|
2018-08-27 10:33:11 +02:00
|
|
|
actionBarLayout.presentFragment(new ChatActivity(args12), true, false, true, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else {
|
|
|
|
long dialog_id;
|
|
|
|
boolean isBot = false;
|
|
|
|
Bundle args = new Bundle();
|
2019-12-31 14:08:08 +01:00
|
|
|
final TLRPC.Chat chat;
|
2018-08-27 10:33:11 +02:00
|
|
|
if (!res.chats.isEmpty()) {
|
|
|
|
args.putInt("chat_id", res.chats.get(0).id);
|
|
|
|
dialog_id = -res.chats.get(0).id;
|
2019-12-31 14:08:08 +01:00
|
|
|
chat = res.chats.get(0);
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
args.putInt("user_id", res.users.get(0).id);
|
|
|
|
dialog_id = res.users.get(0).id;
|
2019-12-31 14:08:08 +01:00
|
|
|
chat = null;
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
if (botUser != null && res.users.size() > 0 && res.users.get(0).bot) {
|
|
|
|
args.putString("botUser", botUser);
|
|
|
|
isBot = true;
|
|
|
|
}
|
|
|
|
if (messageId != null) {
|
|
|
|
args.putInt("message_id", messageId);
|
|
|
|
}
|
|
|
|
BaseFragment lastFragment = !mainFragmentsStack.isEmpty() ? mainFragmentsStack.get(mainFragmentsStack.size() - 1) : null;
|
|
|
|
if (lastFragment == null || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, lastFragment)) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (isBot && lastFragment instanceof ChatActivity && ((ChatActivity) lastFragment).getDialogId() == dialog_id) {
|
2018-08-27 10:33:11 +02:00
|
|
|
((ChatActivity) lastFragment).setBotUser(botUser);
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
MessagesController.getInstance(intentAccount).ensureMessagesLoaded(dialog_id, ChatObject.isChannel(chat), messageId == null ? 0 : messageId, () -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
if (!LaunchActivity.this.isFinishing()) {
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
|
|
|
actionBarLayout.presentFragment(fragment);
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
}, () -> {
|
|
|
|
if (!LaunchActivity.this.isFinishing()) {
|
|
|
|
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
|
|
|
AlertsCreator.showSimpleAlert(fragment, LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
});
|
|
|
|
hideProgressDialog = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Toast.makeText(LaunchActivity.this, LocaleController.getString("NoUsernameFound", R.string.NoUsernameFound), Toast.LENGTH_SHORT).show();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
if (hideProgressDialog) {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}));
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (group != null) {
|
2019-06-19 14:41:36 +02:00
|
|
|
if (state == 0 || state == 3) {
|
2015-05-03 13:48:36 +02:00
|
|
|
final TLRPC.TL_messages_checkChatInvite req = new TLRPC.TL_messages_checkChatInvite();
|
|
|
|
req.hash = group;
|
2018-08-27 10:33:11 +02:00
|
|
|
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (!LaunchActivity.this.isFinishing()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
boolean hideProgressDialog = true;
|
2018-08-27 10:33:11 +02:00
|
|
|
if (error == null && actionBarLayout != null) {
|
|
|
|
TLRPC.ChatInvite invite = (TLRPC.ChatInvite) response;
|
2020-09-30 15:48:47 +02:00
|
|
|
if (invite.chat != null && (!ChatObject.isLeftFromChat(invite.chat) || !invite.chat.kicked && (!TextUtils.isEmpty(invite.chat.username) || invite instanceof TLRPC.TL_chatInvitePeek || invite.chat.has_geo))) {
|
2018-08-27 10:33:11 +02:00
|
|
|
MessagesController.getInstance(intentAccount).putChat(invite.chat, false);
|
|
|
|
ArrayList<TLRPC.Chat> chats = new ArrayList<>();
|
|
|
|
chats.add(invite.chat);
|
|
|
|
MessagesStorage.getInstance(intentAccount).putUsersAndChats(null, chats, false, true);
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", invite.chat.id);
|
|
|
|
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
|
2019-12-31 14:08:08 +01:00
|
|
|
boolean[] canceled = new boolean[1];
|
|
|
|
progressDialog.setOnCancelListener(dialog -> canceled[0] = true);
|
|
|
|
|
|
|
|
MessagesController.getInstance(intentAccount).ensureMessagesLoaded(-invite.chat.id, ChatObject.isChannel(invite.chat), 0, () -> {
|
2020-01-23 07:15:40 +01:00
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (canceled[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
2020-07-26 10:03:38 +02:00
|
|
|
if (invite instanceof TLRPC.TL_chatInvitePeek) {
|
|
|
|
fragment.setChatInvite(invite);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
actionBarLayout.presentFragment(fragment);
|
2020-06-04 18:47:15 +02:00
|
|
|
}, () -> {
|
|
|
|
if (!LaunchActivity.this.isFinishing()) {
|
|
|
|
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
|
|
|
AlertsCreator.showSimpleAlert(fragment, LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
});
|
|
|
|
hideProgressDialog = false;
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
|
|
|
fragment.showDialog(new JoinGroupAlert(LaunchActivity.this, invite, group, fragment));
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
|
2020-06-25 17:28:55 +02:00
|
|
|
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
|
2018-08-27 10:33:11 +02:00
|
|
|
if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
builder.setMessage(LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
|
|
|
|
}
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
showAlertDialog(builder);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (hideProgressDialog) {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}), ConnectionsManager.RequestFlagFailOnServerErrors);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (state == 1) {
|
|
|
|
TLRPC.TL_messages_importChatInvite req = new TLRPC.TL_messages_importChatInvite();
|
|
|
|
req.hash = group;
|
2018-08-27 10:33:11 +02:00
|
|
|
ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
if (error == null) {
|
|
|
|
TLRPC.Updates updates = (TLRPC.Updates) response;
|
|
|
|
MessagesController.getInstance(intentAccount).processUpdates(updates, false);
|
|
|
|
}
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (!LaunchActivity.this.isFinishing()) {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
if (error == null) {
|
|
|
|
if (actionBarLayout != null) {
|
|
|
|
TLRPC.Updates updates = (TLRPC.Updates) response;
|
|
|
|
if (!updates.chats.isEmpty()) {
|
|
|
|
TLRPC.Chat chat = updates.chats.get(0);
|
|
|
|
chat.left = false;
|
|
|
|
chat.kicked = false;
|
|
|
|
MessagesController.getInstance(intentAccount).putUsers(updates.users, false);
|
|
|
|
MessagesController.getInstance(intentAccount).putChats(updates.chats, false);
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", chat.id);
|
|
|
|
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
|
|
|
|
ChatActivity fragment = new ChatActivity(args);
|
|
|
|
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
|
|
|
|
actionBarLayout.presentFragment(fragment, false, true, true, false);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
|
2020-06-25 17:28:55 +02:00
|
|
|
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
|
2018-08-27 10:33:11 +02:00
|
|
|
if (error.text.startsWith("FLOOD_WAIT")) {
|
|
|
|
builder.setMessage(LocaleController.getString("FloodWait", R.string.FloodWait));
|
|
|
|
} else if (error.text.equals("USERS_TOO_MUCH")) {
|
|
|
|
builder.setMessage(LocaleController.getString("JoinToGroupErrorFull", R.string.JoinToGroupErrorFull));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
|
|
|
|
}
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
showAlertDialog(builder);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
});
|
2015-12-09 19:27:52 +01:00
|
|
|
}, ConnectionsManager.RequestFlagFailOnServerErrors);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
} else if (sticker != null) {
|
|
|
|
if (!mainFragmentsStack.isEmpty()) {
|
|
|
|
TLRPC.TL_inputStickerSetShortName stickerset = new TLRPC.TL_inputStickerSetShortName();
|
|
|
|
stickerset.short_name = sticker;
|
2016-10-11 13:57:01 +02:00
|
|
|
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
2020-07-26 10:03:38 +02:00
|
|
|
StickersAlert alert;
|
2019-12-31 14:08:08 +01:00
|
|
|
if (fragment instanceof ChatActivity) {
|
2020-07-26 10:03:38 +02:00
|
|
|
ChatActivity chatActivity = (ChatActivity) fragment;
|
|
|
|
alert = new StickersAlert(LaunchActivity.this, fragment, stickerset, null, chatActivity.getChatActivityEnterView());
|
|
|
|
alert.setCalcMandatoryInsets(chatActivity.isKeyboardVisible());
|
2019-12-31 14:08:08 +01:00
|
|
|
} else {
|
2020-07-26 10:03:38 +02:00
|
|
|
alert = new StickersAlert(LaunchActivity.this, fragment, stickerset, null, null);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
fragment.showDialog(alert);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
return;
|
2015-08-13 11:23:31 +02:00
|
|
|
} else if (message != null) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
2020-03-30 14:00:09 +02:00
|
|
|
args.putInt("dialogsType", 3);
|
2015-08-13 11:23:31 +02:00
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
2018-08-27 10:33:11 +02:00
|
|
|
fragment.setDelegate((fragment13, dids, m, param) -> {
|
|
|
|
long did = dids.get(0);
|
|
|
|
Bundle args13 = new Bundle();
|
|
|
|
args13.putBoolean("scrollToTopOnResume", true);
|
|
|
|
args13.putBoolean("hasUrl", hasUrl);
|
|
|
|
int lower_part = (int) did;
|
|
|
|
int high_id = (int) (did >> 32);
|
|
|
|
if (lower_part != 0) {
|
2019-09-10 12:56:11 +02:00
|
|
|
if (lower_part > 0) {
|
|
|
|
args13.putInt("user_id", lower_part);
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
args13.putInt("chat_id", -lower_part);
|
2016-03-16 13:26:32 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
args13.putInt("enc_id", high_id);
|
|
|
|
}
|
|
|
|
if (MessagesController.getInstance(intentAccount).checkCanOpenChat(args13, fragment13)) {
|
|
|
|
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
|
2020-09-30 15:48:47 +02:00
|
|
|
MediaDataController.getInstance(intentAccount).saveDraft(did, 0, message, null, null, false);
|
2018-08-27 10:33:11 +02:00
|
|
|
actionBarLayout.presentFragment(new ChatActivity(args13), true, false, true, false);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
});
|
2015-10-29 18:10:07 +01:00
|
|
|
presentFragment(fragment, false, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (auth != null) {
|
|
|
|
final int bot_id = Utilities.parseInt(auth.get("bot_id"));
|
|
|
|
if (bot_id == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final String payload = auth.get("payload");
|
2018-08-29 00:59:16 +02:00
|
|
|
final String nonce = auth.get("nonce");
|
2018-07-30 04:07:02 +02:00
|
|
|
final String callbackUrl = auth.get("callback_url");
|
|
|
|
final TLRPC.TL_account_getAuthorizationForm req = new TLRPC.TL_account_getAuthorizationForm();
|
|
|
|
req.bot_id = bot_id;
|
|
|
|
req.scope = auth.get("scope");
|
|
|
|
req.public_key = auth.get("public_key");
|
2018-08-27 10:33:11 +02:00
|
|
|
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
final TLRPC.TL_account_authorizationForm authorizationForm = (TLRPC.TL_account_authorizationForm) response;
|
|
|
|
if (authorizationForm != null) {
|
|
|
|
TLRPC.TL_account_getPassword req2 = new TLRPC.TL_account_getPassword();
|
|
|
|
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req2, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
if (response1 != null) {
|
|
|
|
TLRPC.TL_account_password accountPassword = (TLRPC.TL_account_password) response1;
|
|
|
|
MessagesController.getInstance(intentAccount).putUsers(authorizationForm.users, false);
|
2018-08-29 00:59:16 +02:00
|
|
|
presentFragment(new PassportActivity(PassportActivity.TYPE_PASSWORD, req.bot_id, req.scope, req.public_key, payload, nonce, callbackUrl, authorizationForm, accountPassword));
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
if ("APP_VERSION_OUTDATED".equals(error.text)) {
|
|
|
|
AlertsCreator.showUpdateAppAlert(LaunchActivity.this, LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
|
|
|
|
} else {
|
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
});
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (unsupportedUrl != null) {
|
|
|
|
TLRPC.TL_help_getDeepLinkInfo req = new TLRPC.TL_help_getDeepLinkInfo();
|
|
|
|
req.path = unsupportedUrl;
|
2018-08-27 10:33:11 +02:00
|
|
|
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
if (response instanceof TLRPC.TL_help_deepLinkInfo) {
|
|
|
|
TLRPC.TL_help_deepLinkInfo res = (TLRPC.TL_help_deepLinkInfo) response;
|
|
|
|
AlertsCreator.showUpdateAppAlert(LaunchActivity.this, res.message, res.update_app);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
}));
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (lang != null) {
|
|
|
|
TLRPC.TL_langpack_getLanguage req = new TLRPC.TL_langpack_getLanguage();
|
|
|
|
req.lang_code = lang;
|
|
|
|
req.lang_pack = "android";
|
|
|
|
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
2018-08-27 10:33:11 +02:00
|
|
|
try {
|
2019-01-23 18:03:33 +01:00
|
|
|
progressDialog.dismiss();
|
2018-08-27 10:33:11 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (response instanceof TLRPC.TL_langPackLanguage) {
|
|
|
|
TLRPC.TL_langPackLanguage res = (TLRPC.TL_langPackLanguage) response;
|
2020-06-25 17:28:55 +02:00
|
|
|
AlertsCreator.createLanguageAlert(LaunchActivity.this, res).show();
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (error != null) {
|
|
|
|
if ("LANG_CODE_NOT_SUPPORTED".equals(error.text)) {
|
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("LanguageUnsupportedError", R.string.LanguageUnsupportedError)));
|
|
|
|
} else {
|
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2019-02-08 03:30:32 +01:00
|
|
|
} else if (wallPaper != null) {
|
|
|
|
boolean ok = false;
|
|
|
|
if (TextUtils.isEmpty(wallPaper.slug)) {
|
2019-01-23 18:03:33 +01:00
|
|
|
try {
|
2019-12-31 14:08:08 +01:00
|
|
|
WallpapersListActivity.ColorWallpaper colorWallpaper = new WallpapersListActivity.ColorWallpaper(Theme.COLOR_BACKGROUND_SLUG, wallPaper.settings.background_color, wallPaper.settings.second_background_color, AndroidUtilities.getWallpaperRotation(wallPaper.settings.rotation, false));
|
|
|
|
ThemePreviewActivity wallpaperActivity = new ThemePreviewActivity(colorWallpaper, null);
|
2019-02-08 03:30:32 +01:00
|
|
|
AndroidUtilities.runOnUIThread(() -> presentFragment(wallpaperActivity));
|
|
|
|
ok = true;
|
2019-01-23 18:03:33 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2019-02-08 03:30:32 +01:00
|
|
|
}
|
|
|
|
if (!ok) {
|
|
|
|
TLRPC.TL_account_getWallPaper req = new TLRPC.TL_account_getWallPaper();
|
|
|
|
TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
|
|
|
|
inputWallPaperSlug.slug = wallPaper.slug;
|
|
|
|
req.wallpaper = inputWallPaperSlug;
|
|
|
|
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
if (response instanceof TLRPC.TL_wallPaper) {
|
|
|
|
TLRPC.TL_wallPaper res = (TLRPC.TL_wallPaper) response;
|
|
|
|
Object object;
|
2019-05-14 14:08:05 +02:00
|
|
|
if (res.pattern) {
|
2019-12-31 14:08:08 +01:00
|
|
|
WallpapersListActivity.ColorWallpaper colorWallpaper = new WallpapersListActivity.ColorWallpaper(res.slug, wallPaper.settings.background_color, wallPaper.settings.second_background_color, AndroidUtilities.getWallpaperRotation(wallPaper.settings.rotation, false), wallPaper.settings.intensity / 100.0f, wallPaper.settings.motion, null);
|
2019-02-08 03:30:32 +01:00
|
|
|
colorWallpaper.pattern = res;
|
|
|
|
object = colorWallpaper;
|
|
|
|
} else {
|
|
|
|
object = res;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
ThemePreviewActivity wallpaperActivity = new ThemePreviewActivity(object, null);
|
2019-02-08 03:30:32 +01:00
|
|
|
wallpaperActivity.setInitialModes(wallPaper.settings.blur, wallPaper.settings.motion);
|
|
|
|
presentFragment(wallpaperActivity);
|
|
|
|
} else {
|
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
} else if (theme != null) {
|
|
|
|
cancelRunnable = () -> {
|
|
|
|
loadingThemeFileName = null;
|
|
|
|
loadingThemeWallpaperName = null;
|
2019-12-31 14:08:08 +01:00
|
|
|
loadingThemeWallpaper = null;
|
2019-09-10 12:56:11 +02:00
|
|
|
loadingThemeInfo = null;
|
|
|
|
loadingThemeProgressDialog = null;
|
|
|
|
loadingTheme = null;
|
|
|
|
};
|
|
|
|
TLRPC.TL_account_getTheme req = new TLRPC.TL_account_getTheme();
|
|
|
|
req.format = "android";
|
|
|
|
TLRPC.TL_inputThemeSlug inputThemeSlug = new TLRPC.TL_inputThemeSlug();
|
|
|
|
inputThemeSlug.slug = theme;
|
|
|
|
req.theme = inputThemeSlug;
|
|
|
|
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
int notFound = 2;
|
|
|
|
if (response instanceof TLRPC.TL_theme) {
|
|
|
|
TLRPC.TL_theme t = (TLRPC.TL_theme) response;
|
2019-12-31 14:08:08 +01:00
|
|
|
if (t.settings != null) {
|
|
|
|
String key = Theme.getBaseThemeKey(t.settings);
|
|
|
|
Theme.ThemeInfo info = Theme.getTheme(key);
|
|
|
|
if (info != null) {
|
|
|
|
TLRPC.TL_wallPaper object;
|
|
|
|
if (t.settings.wallpaper instanceof TLRPC.TL_wallPaper) {
|
|
|
|
object = (TLRPC.TL_wallPaper) t.settings.wallpaper;
|
|
|
|
File path = FileLoader.getPathToAttach(object.document, true);
|
|
|
|
if (!path.exists()) {
|
|
|
|
loadingThemeProgressDialog = progressDialog;
|
|
|
|
loadingThemeAccent = true;
|
|
|
|
loadingThemeInfo = info;
|
|
|
|
loadingTheme = t;
|
|
|
|
loadingThemeWallpaper = object;
|
|
|
|
loadingThemeWallpaperName = FileLoader.getAttachFileName(object.document);
|
|
|
|
FileLoader.getInstance(currentAccount).loadFile(object.document, object, 1, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
object = null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
notFound = 0;
|
|
|
|
openThemeAccentPreview(t, object, info);
|
|
|
|
} else {
|
|
|
|
notFound = 1;
|
|
|
|
}
|
|
|
|
} else if (t.document != null) {
|
|
|
|
loadingThemeAccent = false;
|
2019-09-10 12:56:11 +02:00
|
|
|
loadingTheme = t;
|
|
|
|
loadingThemeFileName = FileLoader.getAttachFileName(loadingTheme.document);
|
|
|
|
loadingThemeProgressDialog = progressDialog;
|
|
|
|
FileLoader.getInstance(currentAccount).loadFile(loadingTheme.document, t, 1, 1);
|
|
|
|
notFound = 0;
|
|
|
|
} else {
|
|
|
|
notFound = 1;
|
|
|
|
}
|
|
|
|
} else if (error != null && "THEME_FORMAT_INVALID".equals(error.text)) {
|
|
|
|
notFound = 1;
|
|
|
|
}
|
|
|
|
if (notFound != 0) {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
if (notFound == 1) {
|
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("Theme", R.string.Theme), LocaleController.getString("ThemeNotSupported", R.string.ThemeNotSupported)));
|
|
|
|
} else {
|
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("Theme", R.string.Theme), LocaleController.getString("ThemeNotFound", R.string.ThemeNotFound)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (channelId != null && messageId != null) {
|
2020-09-30 15:48:47 +02:00
|
|
|
if (threadId != null) {
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(intentAccount).getChat(channelId);
|
|
|
|
if (chat != null) {
|
|
|
|
requestId[0] = runCommentRequest(intentAccount, progressDialog, messageId, commentId, threadId, chat);
|
|
|
|
} else {
|
|
|
|
TLRPC.TL_channels_getChannels req = new TLRPC.TL_channels_getChannels();
|
|
|
|
TLRPC.TL_inputChannel inputChannel = new TLRPC.TL_inputChannel();
|
|
|
|
inputChannel.channel_id = channelId;
|
|
|
|
req.id.add(inputChannel);
|
|
|
|
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
boolean notFound = true;
|
|
|
|
if (response instanceof TLRPC.TL_messages_chats) {
|
|
|
|
TLRPC.TL_messages_chats res = (TLRPC.TL_messages_chats) response;
|
|
|
|
if (!res.chats.isEmpty()) {
|
|
|
|
notFound = false;
|
|
|
|
MessagesController.getInstance(currentAccount).putChats(res.chats, false);
|
|
|
|
requestId[0] = runCommentRequest(intentAccount, progressDialog, messageId, commentId, threadId, res.chats.get(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (notFound) {
|
2019-05-14 14:08:05 +02:00
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("LinkNotFound", R.string.LinkNotFound)));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", channelId);
|
|
|
|
args.putInt("message_id", messageId);
|
|
|
|
BaseFragment lastFragment = !mainFragmentsStack.isEmpty() ? mainFragmentsStack.get(mainFragmentsStack.size() - 1) : null;
|
|
|
|
if (lastFragment == null || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, lastFragment)) {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (!actionBarLayout.presentFragment(new ChatActivity(args))) {
|
|
|
|
TLRPC.TL_channels_getChannels req = new TLRPC.TL_channels_getChannels();
|
|
|
|
TLRPC.TL_inputChannel inputChannel = new TLRPC.TL_inputChannel();
|
|
|
|
inputChannel.channel_id = channelId;
|
|
|
|
req.id.add(inputChannel);
|
|
|
|
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
boolean notFound = true;
|
|
|
|
if (response instanceof TLRPC.TL_messages_chats) {
|
|
|
|
TLRPC.TL_messages_chats res = (TLRPC.TL_messages_chats) response;
|
|
|
|
if (!res.chats.isEmpty()) {
|
|
|
|
notFound = false;
|
|
|
|
MessagesController.getInstance(currentAccount).putChats(res.chats, false);
|
|
|
|
TLRPC.Chat chat = res.chats.get(0);
|
|
|
|
if (lastFragment == null || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, lastFragment)) {
|
|
|
|
actionBarLayout.presentFragment(new ChatActivity(args));
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
if (notFound) {
|
|
|
|
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("LinkNotFound", R.string.LinkNotFound)));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (requestId[0] != 0) {
|
2019-09-10 12:56:11 +02:00
|
|
|
final Runnable cancelRunnableFinal = cancelRunnable;
|
|
|
|
progressDialog.setOnCancelListener(dialog -> {
|
|
|
|
ConnectionsManager.getInstance(intentAccount).cancelRequest(requestId[0], true);
|
|
|
|
if (cancelRunnableFinal != null) {
|
|
|
|
cancelRunnableFinal.run();
|
|
|
|
}
|
|
|
|
});
|
2017-12-08 18:35:59 +01:00
|
|
|
try {
|
2020-01-05 12:50:11 +01:00
|
|
|
progressDialog.showDelayed(300);
|
2017-12-08 18:35:59 +01:00
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
private List<TLRPC.TL_contact> findContacts(String userName, String userPhone, boolean allowSelf) {
|
|
|
|
final MessagesController messagesController = MessagesController.getInstance(currentAccount);
|
|
|
|
final ContactsController contactsController = ContactsController.getInstance(currentAccount);
|
|
|
|
final List<TLRPC.TL_contact> contacts = new ArrayList<>(contactsController.contacts);
|
|
|
|
final List<TLRPC.TL_contact> foundContacts = new ArrayList<>();
|
|
|
|
|
|
|
|
if (userPhone != null) {
|
|
|
|
userPhone = PhoneFormat.stripExceptNumbers(userPhone);
|
2020-10-05 00:13:31 +02:00
|
|
|
TLRPC.TL_contact contact = contactsController.contactsByPhone.get(userPhone);
|
|
|
|
if (contact == null) {
|
|
|
|
String shortUserPhone = userPhone.substring(Math.max(0, userPhone.length() - 7));
|
|
|
|
contact = contactsController.contactsByShortPhone.get(shortUserPhone);
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
if (contact != null) {
|
|
|
|
final TLRPC.User user = messagesController.getUser(contact.user_id);
|
|
|
|
if (user != null && (!user.self || allowSelf)) {
|
|
|
|
foundContacts.add(contact);
|
|
|
|
} else {
|
|
|
|
// disable search by name
|
|
|
|
userName = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundContacts.isEmpty() && userName != null) {
|
|
|
|
final String query1 = userName.trim().toLowerCase();
|
|
|
|
if (!TextUtils.isEmpty(query1)) {
|
|
|
|
String query2 = LocaleController.getInstance().getTranslitString(query1);
|
|
|
|
if (query1.equals(query2) || query2.length() == 0) {
|
|
|
|
query2 = null;
|
|
|
|
}
|
|
|
|
final String[] queries = new String[]{query1, query2};
|
|
|
|
for (int i = 0, size = contacts.size(); i < size; i++) {
|
|
|
|
final TLRPC.TL_contact contact = contacts.get(i);
|
|
|
|
if (contact != null) {
|
|
|
|
final TLRPC.User user = messagesController.getUser(contact.user_id);
|
|
|
|
if (user != null) {
|
|
|
|
if (user.self && !allowSelf) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String[] names = new String[3];
|
|
|
|
names[0] = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
|
|
|
|
names[1] = LocaleController.getInstance().getTranslitString(names[0]);
|
|
|
|
if (names[0].equals(names[1])) {
|
|
|
|
names[1] = null;
|
|
|
|
}
|
|
|
|
if (UserObject.isReplyUser(user)) {
|
|
|
|
names[2] = LocaleController.getString("RepliesTitle", R.string.RepliesTitle).toLowerCase();
|
|
|
|
} else if (user.self) {
|
|
|
|
names[2] = LocaleController.getString("SavedMessages", R.string.SavedMessages).toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean found = false;
|
|
|
|
for (String q : queries) {
|
|
|
|
if (q == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int j = 0; j < names.length; j++) {
|
|
|
|
final String name = names[j];
|
|
|
|
if (name != null && (name.startsWith(q) || name.contains(" " + q))) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found && user.username != null && user.username.startsWith(q)) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
foundContacts.add(contact);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundContacts;
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public AlertDialog showAlertDialog(AlertDialog.Builder builder) {
|
|
|
|
try {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
visibleDialog = builder.show();
|
|
|
|
visibleDialog.setCanceledOnTouchOutside(true);
|
2019-12-31 14:08:08 +01:00
|
|
|
visibleDialog.setOnDismissListener(dialog -> {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
if (visibleDialog == localeDialog) {
|
|
|
|
try {
|
|
|
|
String shorname = LocaleController.getInstance().getCurrentLocaleInfo().shortName;
|
|
|
|
Toast.makeText(LaunchActivity.this, getStringForLanguageAlert(shorname.equals("en") ? englishLocaleStrings : systemLocaleStrings, "ChangeLanguageLater", R.string.ChangeLanguageLater), Toast.LENGTH_LONG).show();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
localeDialog = null;
|
|
|
|
} else if (visibleDialog == proxyErrorDialog) {
|
2020-06-25 17:28:55 +02:00
|
|
|
SharedConfig.setProxyEnable(false);
|
2019-12-31 14:08:08 +01:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged);
|
|
|
|
proxyErrorDialog = null;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
visibleDialog = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
});
|
|
|
|
return visibleDialog;
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-03-04 20:29:32 +01:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
2015-02-26 02:32:51 +01:00
|
|
|
handleIntent(intent, true, false, false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-12-08 18:35:59 +01:00
|
|
|
public void didSelectDialogs(DialogsActivity dialogsFragment, ArrayList<Long> dids, CharSequence message, boolean param) {
|
2019-08-22 01:53:26 +02:00
|
|
|
int attachesCount = 0;
|
|
|
|
if (contactsToSend != null) {
|
|
|
|
attachesCount += contactsToSend.size();
|
|
|
|
}
|
|
|
|
if (videoPath != null) {
|
|
|
|
attachesCount++;
|
|
|
|
}
|
|
|
|
if (photoPathsArray != null) {
|
|
|
|
attachesCount += photoPathsArray.size();
|
|
|
|
}
|
|
|
|
if (documentsPathsArray != null) {
|
|
|
|
attachesCount += documentsPathsArray.size();
|
|
|
|
}
|
|
|
|
if (documentsUrisArray != null) {
|
|
|
|
attachesCount += documentsUrisArray.size();
|
|
|
|
}
|
|
|
|
if (videoPath == null && photoPathsArray == null && documentsPathsArray == null && documentsUrisArray == null && sendingText != null) {
|
|
|
|
attachesCount++;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < dids.size(); i++) {
|
|
|
|
final long did = dids.get(i);
|
|
|
|
if (AlertsCreator.checkSlowMode(this, currentAccount, did, attachesCount > 1)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
final int account = dialogsFragment != null ? dialogsFragment.getCurrentAccount() : currentAccount;
|
2019-12-31 14:08:08 +01:00
|
|
|
final ChatActivity fragment;
|
|
|
|
if (dids.size() <= 1) {
|
|
|
|
final long did = dids.get(0);
|
|
|
|
int lower_part = (int) did;
|
|
|
|
int high_id = (int) (did >> 32);
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("scrollToTopOnResume", true);
|
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
NotificationCenter.getInstance(account).postNotificationName(NotificationCenter.closeChats);
|
2016-03-16 13:26:32 +01:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (lower_part != 0) {
|
|
|
|
if (lower_part > 0) {
|
|
|
|
args.putInt("user_id", lower_part);
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
args.putInt("chat_id", -lower_part);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args.putInt("enc_id", high_id);
|
|
|
|
}
|
|
|
|
if (!MessagesController.getInstance(account).checkCanOpenChat(args, dialogsFragment)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fragment = new ChatActivity(args);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
fragment = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
|
2020-01-01 19:32:12 +01:00
|
|
|
if (contactsToSend != null && contactsToSend.size() == 1 && !mainFragmentsStack.isEmpty()) {
|
2020-04-24 11:21:58 +02:00
|
|
|
PhonebookShareAlert alert = new PhonebookShareAlert(mainFragmentsStack.get(mainFragmentsStack.size() - 1), null, null, contactsToSendUri, null, null, null);
|
2019-12-31 14:08:08 +01:00
|
|
|
alert.setDelegate((user, notify, scheduleDate) -> {
|
|
|
|
if (fragment != null) {
|
2018-08-27 10:33:11 +02:00
|
|
|
actionBarLayout.presentFragment(fragment, true, false, true, false);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
for (int i = 0; i < dids.size(); i++) {
|
2020-09-30 15:48:47 +02:00
|
|
|
SendMessagesHelper.getInstance(account).sendMessage(user, dids.get(i), null, null, null, null, notify, scheduleDate);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(alert);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2020-10-02 13:25:02 +02:00
|
|
|
String captionToSend = null;
|
2019-12-31 14:08:08 +01:00
|
|
|
for (int i = 0; i < dids.size(); i++) {
|
|
|
|
final long did = dids.get(i);
|
|
|
|
int lower_part = (int) did;
|
|
|
|
int high_id = (int) (did >> 32);
|
|
|
|
|
|
|
|
AccountInstance accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount);
|
|
|
|
if (fragment != null) {
|
|
|
|
actionBarLayout.presentFragment(fragment, dialogsFragment != null, dialogsFragment == null, true, false);
|
|
|
|
if (videoPath != null) {
|
|
|
|
fragment.openVideoEditor(videoPath, sendingText);
|
|
|
|
sendingText = null;
|
|
|
|
}
|
|
|
|
} else {
|
2020-04-24 11:21:58 +02:00
|
|
|
if (videoPath != null) {
|
|
|
|
if (sendingText != null && sendingText.length() <= 1024) {
|
2020-10-02 13:25:02 +02:00
|
|
|
captionToSend = sendingText;
|
2020-04-24 11:21:58 +02:00
|
|
|
sendingText = null;
|
|
|
|
}
|
|
|
|
ArrayList<String> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(videoPath);
|
2020-10-02 13:25:02 +02:00
|
|
|
SendMessagesHelper.prepareSendingDocuments(accountInstance, arrayList, arrayList, null, captionToSend, null, did, null, null, null, null, true, 0);
|
2020-04-24 11:21:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (photoPathsArray != null) {
|
|
|
|
if (sendingText != null && sendingText.length() <= 1024 && photoPathsArray.size() == 1) {
|
|
|
|
photoPathsArray.get(0).caption = sendingText;
|
|
|
|
sendingText = null;
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
SendMessagesHelper.prepareSendingMedia(accountInstance, photoPathsArray, did, null, null, null, false, false, null, true, 0);
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (documentsPathsArray != null || documentsUrisArray != null) {
|
|
|
|
if (sendingText != null && sendingText.length() <= 1024 && ((documentsPathsArray != null ? documentsPathsArray.size() : 0) + (documentsUrisArray != null ? documentsUrisArray.size() : 0)) == 1) {
|
2020-10-02 13:25:02 +02:00
|
|
|
captionToSend = sendingText;
|
2019-12-31 14:08:08 +01:00
|
|
|
sendingText = null;
|
|
|
|
}
|
2020-10-02 13:25:02 +02:00
|
|
|
SendMessagesHelper.prepareSendingDocuments(accountInstance, documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, captionToSend, documentsMimeType, did, null, null, null, null, true, 0);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-01-12 10:34:25 +01:00
|
|
|
if (sendingLocation != null) {
|
|
|
|
SendMessagesHelper.prepareSendingLocation(accountInstance, sendingLocation, did);
|
|
|
|
sendingText = null;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (sendingText != null) {
|
|
|
|
SendMessagesHelper.prepareSendingText(accountInstance, sendingText, did, true, 0);
|
|
|
|
}
|
|
|
|
if (contactsToSend != null && !contactsToSend.isEmpty()) {
|
|
|
|
for (int a = 0; a < contactsToSend.size(); a++) {
|
|
|
|
TLRPC.User user = contactsToSend.get(a);
|
2020-09-30 15:48:47 +02:00
|
|
|
SendMessagesHelper.getInstance(account).sendMessage(user, did, null, null, null, null, true, 0);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(message)) {
|
|
|
|
SendMessagesHelper.prepareSendingText(accountInstance, message.toString(), did, true, 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (dialogsFragment != null && fragment == null) {
|
|
|
|
dialogsFragment.finishFragment();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
photoPathsArray = null;
|
|
|
|
videoPath = null;
|
|
|
|
sendingText = null;
|
2020-01-12 10:34:25 +01:00
|
|
|
sendingLocation = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
documentsPathsArray = null;
|
|
|
|
documentsOriginalPathsArray = null;
|
|
|
|
contactsToSend = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
contactsToSendUri = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
private void onFinish() {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (lockRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(lockRunnable);
|
|
|
|
lockRunnable = null;
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finished = true;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (currentAccount != -1) {
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.appDidLogout);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.mainUserInfoChanged);
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.didUpdateConnectionState);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.needShowAlert);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.openArticle);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.hasNewContactsToImport);
|
2020-04-24 11:21:58 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.needShowPlayServicesAlert);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileDidFailToLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.needShowAlert);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didSetNewWallpapper);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.suggestedLangpack);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.reloadInterface);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didSetNewTheme);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.needSetDayNightTheme);
|
2019-12-31 14:08:08 +01:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.needCheckSystemBarColors);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.closeOtherAppActivities);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didSetPasscode);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.notificationsCountUpdated);
|
2019-12-31 14:08:08 +01:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.screenStateChanged);
|
2020-06-25 17:28:55 +02:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(drawerLayoutAdapter, NotificationCenter.proxySettingsChanged);
|
2020-07-02 05:28:34 +02:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(drawerLayoutAdapter, NotificationCenter.updateUserStatus);
|
2020-06-25 17:28:55 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void presentFragment(BaseFragment fragment) {
|
|
|
|
actionBarLayout.presentFragment(fragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean presentFragment(final BaseFragment fragment, final boolean removeLast, boolean forceWithoutAnimation) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, true, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public ActionBarLayout getActionBarLayout() {
|
|
|
|
return actionBarLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBarLayout getLayersActionBarLayout() {
|
|
|
|
return layersActionBarLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBarLayout getRightActionBarLayout() {
|
|
|
|
return rightActionBarLayout;
|
|
|
|
}
|
|
|
|
|
2020-07-20 03:44:19 +02:00
|
|
|
@FunctionalInterface
|
|
|
|
public interface Callback {
|
|
|
|
|
|
|
|
void invoke(Intent data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public HashMap<Integer, Callback> callbacks = new HashMap<>();
|
2020-07-19 09:44:11 +02:00
|
|
|
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (SharedConfig.passcodeHash.length() != 0 && SharedConfig.lastPauseTime != 0) {
|
|
|
|
SharedConfig.lastPauseTime = 0;
|
2020-01-23 07:15:40 +01:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("reset lastPauseTime onActivityResult");
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
UserConfig.getInstance(currentAccount).saveConfig(false);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-03-26 21:16:28 +01:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2020-07-19 09:44:11 +02:00
|
|
|
|
|
|
|
if (callbacks.containsKey(requestCode)) {
|
|
|
|
|
2020-07-20 03:44:19 +02:00
|
|
|
callbacks.remove(requestCode).invoke(data);
|
2020-07-19 09:44:11 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-22 21:31:44 +01:00
|
|
|
ThemeEditorView editorView = ThemeEditorView.getInstance();
|
|
|
|
if (editorView != null) {
|
|
|
|
editorView.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
if (actionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (rightActionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = rightActionBarLayout.fragmentsStack.get(rightActionBarLayout.fragmentsStack.size() - 1);
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
|
|
|
}
|
2020-02-22 21:31:44 +01:00
|
|
|
if (layersActionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
2019-12-31 14:08:08 +01:00
|
|
|
if (grantResults == null) {
|
|
|
|
grantResults = new int[0];
|
|
|
|
}
|
|
|
|
if (permissions == null) {
|
|
|
|
permissions = new String[0];
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
|
|
|
|
boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
|
|
|
|
|
|
|
if (requestCode == 4) {
|
|
|
|
if (!granted) {
|
|
|
|
showPermissionErrorAlert(LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
|
|
|
|
} else {
|
|
|
|
ImageLoader.getInstance().checkMediaPaths();
|
|
|
|
}
|
|
|
|
} else if (requestCode == 5) {
|
|
|
|
if (!granted) {
|
|
|
|
showPermissionErrorAlert(LocaleController.getString("PermissionContacts", R.string.PermissionContacts));
|
|
|
|
return;
|
2019-12-31 14:08:08 +01:00
|
|
|
} else {
|
|
|
|
ContactsController.getInstance(currentAccount).forceImportContacts();
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
|
|
|
} else if (requestCode == 3) {
|
|
|
|
boolean audioGranted = true;
|
|
|
|
boolean cameraGranted = true;
|
2019-12-31 14:08:08 +01:00
|
|
|
for (int i = 0, size = Math.min(permissions.length, grantResults.length); i < size; i++) {
|
2019-08-22 01:53:26 +02:00
|
|
|
if (Manifest.permission.RECORD_AUDIO.equals(permissions[i])) {
|
|
|
|
audioGranted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
|
|
|
|
} else if (Manifest.permission.CAMERA.equals(permissions[i])) {
|
|
|
|
cameraGranted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
if (!audioGranted) {
|
|
|
|
showPermissionErrorAlert(LocaleController.getString("PermissionNoAudio", R.string.PermissionNoAudio));
|
|
|
|
} else if (!cameraGranted) {
|
|
|
|
showPermissionErrorAlert(LocaleController.getString("PermissionNoCamera", R.string.PermissionNoCamera));
|
|
|
|
} else {
|
|
|
|
if (SharedConfig.inappCamera) {
|
|
|
|
CameraController.getInstance().initCamera(null);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
} else if (requestCode == 18 || requestCode == 19 || requestCode == 20 || requestCode == 22) {
|
|
|
|
if (!granted) {
|
|
|
|
showPermissionErrorAlert(LocaleController.getString("PermissionNoCamera", R.string.PermissionNoCamera));
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
} else if (requestCode == 2) {
|
2019-08-22 01:53:26 +02:00
|
|
|
if (granted) {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.locationPermissionGranted);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
if (actionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
fragment.onRequestPermissionsResultFragment(requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (rightActionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = rightActionBarLayout.fragmentsStack.get(rightActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
fragment.onRequestPermissionsResultFragment(requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
if (layersActionBarLayout.fragmentsStack.size() != 0) {
|
|
|
|
BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
fragment.onRequestPermissionsResultFragment(requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
}
|
2020-08-14 18:58:22 +02:00
|
|
|
|
|
|
|
VoIPFragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
private void showPermissionErrorAlert(String message) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2020-06-25 17:28:55 +02:00
|
|
|
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
|
2019-08-22 01:53:26 +02:00
|
|
|
builder.setMessage(message);
|
|
|
|
builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), (dialog, which) -> {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
|
|
|
|
startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2019-08-22 01:53:26 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 4096);
|
2015-10-29 18:10:07 +01:00
|
|
|
ApplicationLoader.mainInterfacePaused = true;
|
2020-08-15 23:06:36 +02:00
|
|
|
int account = currentAccount;
|
2018-08-27 10:33:11 +02:00
|
|
|
Utilities.stageQueue.postRunnable(() -> {
|
|
|
|
ApplicationLoader.mainInterfacePausedStageQueue = true;
|
|
|
|
ApplicationLoader.mainInterfacePausedStageQueueTime = 0;
|
2020-08-15 23:06:36 +02:00
|
|
|
if (VoIPService.getSharedInstance() == null) {
|
|
|
|
MessagesController.getInstance(account).ignoreSetOnline = false;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
});
|
2015-02-26 02:32:51 +01:00
|
|
|
onPasscodePause();
|
2020-06-25 17:28:55 +02:00
|
|
|
try {
|
|
|
|
if (actionBarLayout != null) {
|
|
|
|
actionBarLayout.onPause();
|
|
|
|
}
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onPause();
|
|
|
|
layersActionBarLayout.onPause();
|
|
|
|
}
|
|
|
|
if (passcodeView != null) {
|
|
|
|
passcodeView.onPause();
|
|
|
|
}
|
|
|
|
} catch (Exception ignored) {
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
ConnectionsManager.getInstance(currentAccount).setAppPaused(true, false);
|
|
|
|
if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
2016-05-25 23:49:47 +02:00
|
|
|
PhotoViewer.getInstance().onPause();
|
|
|
|
}
|
2020-08-14 18:58:22 +02:00
|
|
|
|
|
|
|
if (VoIPFragment.getInstance() != null) {
|
|
|
|
VoIPFragment.onPause();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
Browser.bindCustomTabsService(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
Browser.unbindCustomTabsService(this);
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (PhotoViewer.getPipInstance() != null) {
|
|
|
|
PhotoViewer.getPipInstance().destroyPhotoViewer();
|
|
|
|
}
|
|
|
|
if (PhotoViewer.hasInstance()) {
|
|
|
|
PhotoViewer.getInstance().destroyPhotoViewer();
|
|
|
|
}
|
|
|
|
if (SecretMediaViewer.hasInstance()) {
|
|
|
|
SecretMediaViewer.getInstance().destroyPhotoViewer();
|
|
|
|
}
|
|
|
|
if (ArticleViewer.hasInstance()) {
|
|
|
|
ArticleViewer.getInstance().destroyArticleViewer();
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (ContentPreviewViewer.hasInstance()) {
|
|
|
|
ContentPreviewViewer.getInstance().destroy();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
PipRoundVideoView pipRoundVideoView = PipRoundVideoView.getInstance();
|
|
|
|
MediaController.getInstance().setBaseActivity(this, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.getInstance().setFeedbackView(actionBarLayout, false);
|
2017-07-08 18:32:04 +02:00
|
|
|
if (pipRoundVideoView != null) {
|
|
|
|
pipRoundVideoView.close(false);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.destroyResources();
|
|
|
|
EmbedBottomSheet embedBottomSheet = EmbedBottomSheet.getInstance();
|
|
|
|
if (embedBottomSheet != null) {
|
|
|
|
embedBottomSheet.destroy();
|
|
|
|
}
|
|
|
|
ThemeEditorView editorView = ThemeEditorView.getInstance();
|
|
|
|
if (editorView != null) {
|
|
|
|
editorView.destroy();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
try {
|
|
|
|
if (onGlobalLayoutListener != null) {
|
|
|
|
final View view = getWindow().getDecorView().getRootView();
|
2017-07-23 14:56:38 +02:00
|
|
|
view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
super.onDestroy();
|
2014-06-04 01:31:48 +02:00
|
|
|
onFinish();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
2019-09-10 12:56:11 +02:00
|
|
|
super.onResume();
|
2019-08-22 01:53:26 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 4096);
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.getInstance().setFeedbackView(actionBarLayout, true);
|
2015-10-29 18:10:07 +01:00
|
|
|
ApplicationLoader.mainInterfacePaused = false;
|
2019-01-23 18:03:33 +01:00
|
|
|
showLanguageAlert(false);
|
2018-08-27 10:33:11 +02:00
|
|
|
Utilities.stageQueue.postRunnable(() -> {
|
|
|
|
ApplicationLoader.mainInterfacePausedStageQueue = false;
|
|
|
|
ApplicationLoader.mainInterfacePausedStageQueueTime = System.currentTimeMillis();
|
2017-03-31 01:58:05 +02:00
|
|
|
});
|
2017-12-08 18:35:59 +01:00
|
|
|
checkFreeDiscSpace();
|
|
|
|
MediaController.checkGallery();
|
2015-02-26 02:32:51 +01:00
|
|
|
onPasscodeResume();
|
|
|
|
if (passcodeView.getVisibility() != View.VISIBLE) {
|
|
|
|
actionBarLayout.onResume();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onResume();
|
|
|
|
layersActionBarLayout.onResume();
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
actionBarLayout.dismissDialogs();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.dismissDialogs();
|
|
|
|
layersActionBarLayout.dismissDialogs();
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
passcodeView.onResume();
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false);
|
|
|
|
updateCurrentConnectionState(currentAccount);
|
2020-06-25 17:28:55 +02:00
|
|
|
if (NekoConfig.disableProxyWhenVpnEnabled && SharedConfig.proxyEnabled && ProxyUtil.isVPNEnabled()) {
|
|
|
|
SharedConfig.setProxyEnable(false);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
2015-05-03 13:48:36 +02:00
|
|
|
PhotoViewer.getInstance().onResume();
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
PipRoundVideoView pipRoundVideoView = PipRoundVideoView.getInstance();
|
|
|
|
if (pipRoundVideoView != null && MediaController.getInstance().isMessagePaused()) {
|
|
|
|
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
|
|
|
|
if (messageObject != null) {
|
|
|
|
MediaController.getInstance().seekToProgress(messageObject, messageObject.audioProgress);
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (UserConfig.getInstance(UserConfig.selectedAccount).unacceptedTermsOfService != null) {
|
|
|
|
showTosActivity(UserConfig.selectedAccount, UserConfig.getInstance(UserConfig.selectedAccount).unacceptedTermsOfService);
|
|
|
|
} else if (UserConfig.getInstance(0).pendingAppUpdate != null) {
|
2019-08-22 01:53:26 +02:00
|
|
|
showUpdateActivity(UserConfig.selectedAccount, UserConfig.getInstance(0).pendingAppUpdate, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2020-08-14 18:58:22 +02:00
|
|
|
|
|
|
|
if (VoIPFragment.getInstance() != null) {
|
2020-08-15 23:06:36 +02:00
|
|
|
VoIPFragment.onResume();
|
2020-08-14 18:58:22 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-11 13:57:01 +02:00
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
AndroidUtilities.checkDisplaySize(this, newConfig);
|
2014-09-24 04:17:27 +02:00
|
|
|
super.onConfigurationChanged(newConfig);
|
2016-10-11 13:57:01 +02:00
|
|
|
checkLayout();
|
2017-07-08 18:32:04 +02:00
|
|
|
PipRoundVideoView pipRoundVideoView = PipRoundVideoView.getInstance();
|
|
|
|
if (pipRoundVideoView != null) {
|
|
|
|
pipRoundVideoView.onConfigurationChanged();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
EmbedBottomSheet embedBottomSheet = EmbedBottomSheet.getInstance();
|
|
|
|
if (embedBottomSheet != null) {
|
|
|
|
embedBottomSheet.onConfigurationChanged(newConfig);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
PhotoViewer photoViewer = PhotoViewer.getPipInstance();
|
|
|
|
if (photoViewer != null) {
|
|
|
|
photoViewer.onConfigurationChanged(newConfig);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
ThemeEditorView editorView = ThemeEditorView.getInstance();
|
|
|
|
if (editorView != null) {
|
|
|
|
editorView.onConfigurationChanged();
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
|
|
|
|
Theme.checkAutoNightThemeConditions();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
|
|
|
|
AndroidUtilities.isInMultiwindow = isInMultiWindowMode;
|
|
|
|
checkLayout();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, final int account, Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.appDidLogout) {
|
2018-07-30 04:07:02 +02:00
|
|
|
switchToAvailableAccountOrLogout();
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.closeOtherAppActivities) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (args[0] != this) {
|
2014-06-04 01:31:48 +02:00
|
|
|
onFinish();
|
2015-02-26 02:32:51 +01:00
|
|
|
finish();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.didUpdateConnectionState) {
|
2018-07-30 04:07:02 +02:00
|
|
|
int state = ConnectionsManager.getInstance(account).getConnectionState();
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentConnectionState != state) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("switch to state " + state);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
currentConnectionState = state;
|
2018-07-30 04:07:02 +02:00
|
|
|
updateCurrentConnectionState(account);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
} else if (id == NotificationCenter.mainUserInfoChanged) {
|
|
|
|
drawerLayoutAdapter.notifyDataSetChanged();
|
2015-12-09 19:27:52 +01:00
|
|
|
} else if (id == NotificationCenter.needShowAlert) {
|
2015-09-24 22:52:02 +02:00
|
|
|
final Integer reason = (Integer) args[0];
|
2018-07-30 04:07:02 +02:00
|
|
|
if (reason == 3 && proxyErrorDialog != null) {
|
|
|
|
return;
|
|
|
|
} else if (reason == 4) {
|
|
|
|
showTosActivity(account, (TLRPC.TL_help_termsOfService) args[1]);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2020-06-25 17:28:55 +02:00
|
|
|
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
|
2018-07-30 04:07:02 +02:00
|
|
|
if (reason != 2 && reason != 3) {
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("MoreInfo", R.string.MoreInfo), (dialogInterface, i) -> {
|
|
|
|
if (!mainFragmentsStack.isEmpty()) {
|
|
|
|
MessagesController.getInstance(account).openByUserName("spambot", mainFragmentsStack.get(mainFragmentsStack.size() - 1), 1);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-12-09 19:27:52 +01:00
|
|
|
});
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (reason == 5) {
|
|
|
|
builder.setMessage(LocaleController.getString("NobodyLikesSpam3", R.string.NobodyLikesSpam3));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
} else if (reason == 0) {
|
2015-09-24 22:52:02 +02:00
|
|
|
builder.setMessage(LocaleController.getString("NobodyLikesSpam1", R.string.NobodyLikesSpam1));
|
2018-07-30 04:07:02 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (reason == 1) {
|
|
|
|
builder.setMessage(LocaleController.getString("NobodyLikesSpam2", R.string.NobodyLikesSpam2));
|
2018-07-30 04:07:02 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2015-12-09 19:27:52 +01:00
|
|
|
} else if (reason == 2) {
|
|
|
|
builder.setMessage((String) args[1]);
|
2018-07-30 04:07:02 +02:00
|
|
|
String type = (String) args[2];
|
|
|
|
if (type.startsWith("AUTH_KEY_DROP_")) {
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("LogOut", R.string.LogOut), (dialog, which) -> MessagesController.getInstance(currentAccount).performLogout(2));
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
}
|
|
|
|
} else if (reason == 3) {
|
2019-12-31 14:08:08 +01:00
|
|
|
builder.setTitle(LocaleController.getString("Proxy", R.string.Proxy));
|
2018-07-30 04:07:02 +02:00
|
|
|
builder.setMessage(LocaleController.getString("UseProxyTelegramError", R.string.UseProxyTelegramError));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
proxyErrorDialog = showAlertDialog(builder);
|
|
|
|
return;
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
if (!mainFragmentsStack.isEmpty()) {
|
|
|
|
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (id == NotificationCenter.wasUnableToFindCurrentLocation) {
|
|
|
|
final HashMap<String, MessageObject> waitingForLocation = (HashMap<String, MessageObject>) args[0];
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2020-06-25 17:28:55 +02:00
|
|
|
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
|
2016-04-22 15:49:00 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("ShareYouLocationUnableManually", R.string.ShareYouLocationUnableManually), (dialogInterface, i) -> {
|
|
|
|
if (mainFragmentsStack.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseFragment lastFragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
|
|
|
if (!AndroidUtilities.isGoogleMapsInstalled(lastFragment)) {
|
|
|
|
return;
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
LocationActivity fragment = new LocationActivity(0);
|
2019-09-10 12:56:11 +02:00
|
|
|
fragment.setDelegate((location, live, notify, scheduleDate) -> {
|
2018-08-27 10:33:11 +02:00
|
|
|
for (HashMap.Entry<String, MessageObject> entry : waitingForLocation.entrySet()) {
|
|
|
|
MessageObject messageObject = entry.getValue();
|
2020-09-30 15:48:47 +02:00
|
|
|
SendMessagesHelper.getInstance(account).sendMessage(location, messageObject.getDialogId(), messageObject, null, null, null, notify, scheduleDate);
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
2016-04-22 15:49:00 +02:00
|
|
|
});
|
|
|
|
builder.setMessage(LocaleController.getString("ShareYouLocationUnable", R.string.ShareYouLocationUnable));
|
|
|
|
if (!mainFragmentsStack.isEmpty()) {
|
|
|
|
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (id == NotificationCenter.didSetNewWallpapper) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (sideMenu != null) {
|
|
|
|
View child = sideMenu.getChildAt(0);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (child != null) {
|
|
|
|
child.invalidate();
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (id == NotificationCenter.didSetPasscode) {
|
2020-06-25 17:28:55 +02:00
|
|
|
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture && !NekoXConfig.disableFlagSecure) {
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (!AndroidUtilities.hasFlagSecureFragment()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (id == NotificationCenter.reloadInterface) {
|
2020-07-26 10:03:38 +02:00
|
|
|
boolean last = mainFragmentsStack.size() > 1 && mainFragmentsStack.get(mainFragmentsStack.size() - 1) instanceof ProfileActivity;
|
|
|
|
if (last) {
|
|
|
|
ProfileActivity profileActivity = (ProfileActivity) mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
|
|
|
if (!profileActivity.isSettings()) {
|
|
|
|
last = false;
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
rebuildAllFragments(last);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (id == NotificationCenter.suggestedLangpack) {
|
|
|
|
showLanguageAlert(false);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (id == NotificationCenter.openArticle) {
|
|
|
|
if (mainFragmentsStack.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ArticleViewer.getInstance().setParentActivity(this, mainFragmentsStack.get(mainFragmentsStack.size() - 1));
|
|
|
|
ArticleViewer.getInstance().open((TLRPC.TL_webPage) args[0], (String) args[1]);
|
|
|
|
} else if (id == NotificationCenter.hasNewContactsToImport) {
|
|
|
|
if (actionBarLayout == null || actionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final int type = (Integer) args[0];
|
|
|
|
final HashMap<String, ContactsController.Contact> contactHashMap = (HashMap<String, ContactsController.Contact>) args[1];
|
|
|
|
final boolean first = (Boolean) args[2];
|
|
|
|
final boolean schedule = (Boolean) args[3];
|
|
|
|
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
|
|
|
|
builder.setTitle(LocaleController.getString("UpdateContactsTitle", R.string.UpdateContactsTitle));
|
|
|
|
builder.setMessage(LocaleController.getString("UpdateContactsMessage", R.string.UpdateContactsMessage));
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, false));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
|
|
|
|
builder.setOnBackButtonListener((dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
|
2017-12-08 18:35:59 +01:00
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
fragment.showDialog(dialog);
|
|
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
|
|
} else if (id == NotificationCenter.didSetNewTheme) {
|
2018-07-30 04:07:02 +02:00
|
|
|
Boolean nightTheme = (Boolean) args[0];
|
|
|
|
if (!nightTheme) {
|
|
|
|
if (sideMenu != null) {
|
|
|
|
sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
|
|
|
|
sideMenu.setGlowColor(Theme.getColor(Theme.key_chats_menuBackground));
|
2019-05-14 14:08:05 +02:00
|
|
|
sideMenu.setListSelectorColor(Theme.getColor(Theme.key_listSelector));
|
2018-07-30 04:07:02 +02:00
|
|
|
sideMenu.getAdapter().notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
try {
|
|
|
|
setTaskDescription(new ActivityManager.TaskDescription(null, null, Theme.getColor(Theme.key_actionBarDefault) | 0xff000000));
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2019-12-31 14:08:08 +01:00
|
|
|
checkSystemBarColors();
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (id == NotificationCenter.needSetDayNightTheme) {
|
2019-12-31 14:08:08 +01:00
|
|
|
boolean instant = false;
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && args[2] != null) {
|
|
|
|
if (themeSwitchImageView.getVisibility() == View.VISIBLE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
int[] pos = (int[]) args[2];
|
2020-09-30 15:48:47 +02:00
|
|
|
boolean toDark = (Boolean) args[4];
|
|
|
|
RLottieImageView darkThemeView = (RLottieImageView) args[5];
|
2019-12-31 14:08:08 +01:00
|
|
|
int w = drawerLayoutContainer.getMeasuredWidth();
|
|
|
|
int h = drawerLayoutContainer.getMeasuredHeight();
|
2020-09-30 15:48:47 +02:00
|
|
|
if (!toDark) {
|
|
|
|
darkThemeView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
Bitmap bitmap = Bitmap.createBitmap(drawerLayoutContainer.getMeasuredWidth(), drawerLayoutContainer.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
drawerLayoutContainer.draw(canvas);
|
2020-09-30 15:48:47 +02:00
|
|
|
frameLayout.removeView(themeSwitchImageView);
|
|
|
|
if (toDark) {
|
|
|
|
frameLayout.addView(themeSwitchImageView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
themeSwitchSunView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
frameLayout.addView(themeSwitchImageView, 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
themeSwitchSunView.setTranslationX(pos[0] - AndroidUtilities.dp(14));
|
|
|
|
themeSwitchSunView.setTranslationY(pos[1] - AndroidUtilities.dp(14));
|
|
|
|
themeSwitchSunView.setVisibility(View.VISIBLE);
|
|
|
|
themeSwitchSunView.invalidate();
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
themeSwitchImageView.setImageBitmap(bitmap);
|
|
|
|
themeSwitchImageView.setVisibility(View.VISIBLE);
|
2020-09-30 15:48:47 +02:00
|
|
|
themeSwitchSunDrawable = darkThemeView.getAnimatedDrawable();
|
2019-12-31 14:08:08 +01:00
|
|
|
float finalRadius = (float) Math.max(Math.sqrt((w - pos[0]) * (w - pos[0]) + (h - pos[1]) * (h - pos[1])), Math.sqrt(pos[0] * pos[0] + (h - pos[1]) * (h - pos[1])));
|
2020-09-30 15:48:47 +02:00
|
|
|
Animator anim = ViewAnimationUtils.createCircularReveal(toDark ? drawerLayoutContainer : themeSwitchImageView, pos[0], pos[1], toDark ? 0 : finalRadius, toDark ? finalRadius : 0);
|
2020-06-25 17:28:55 +02:00
|
|
|
anim.setDuration(100);
|
2020-03-30 14:00:09 +02:00
|
|
|
anim.setInterpolator(Easings.easeInOutQuad);
|
2019-12-31 14:08:08 +01:00
|
|
|
anim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
themeSwitchImageView.setImageDrawable(null);
|
|
|
|
themeSwitchImageView.setVisibility(View.GONE);
|
2020-09-30 15:48:47 +02:00
|
|
|
themeSwitchSunView.setVisibility(View.GONE);
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeAccentListUpdated);
|
|
|
|
if (!toDark) {
|
|
|
|
darkThemeView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2020-10-09 19:35:17 +02:00
|
|
|
drawerLayoutAdapter.notifyDataSetChanged();
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
anim.start();
|
|
|
|
instant = true;
|
2020-09-30 15:48:47 +02:00
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
try {
|
|
|
|
themeSwitchImageView.setImageDrawable(null);
|
|
|
|
frameLayout.removeView(themeSwitchImageView);
|
|
|
|
} catch (Exception e2) {
|
|
|
|
FileLog.e(e2);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
Theme.ThemeInfo theme = (Theme.ThemeInfo) args[0];
|
2019-02-08 03:30:32 +01:00
|
|
|
boolean nigthTheme = (Boolean) args[1];
|
2019-12-31 14:08:08 +01:00
|
|
|
int accentId = (Integer) args[3];
|
|
|
|
actionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
layersActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
|
|
|
|
rightActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.notificationsCountUpdated) {
|
|
|
|
if (sideMenu != null) {
|
|
|
|
Integer accountNum = (Integer) args[0];
|
|
|
|
int count = sideMenu.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = sideMenu.getChildAt(a);
|
|
|
|
if (child instanceof DrawerUserCell) {
|
|
|
|
if (((DrawerUserCell) child).getAccountNumber() == accountNum) {
|
|
|
|
child.invalidate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
} else if (id == NotificationCenter.fileDidLoad) {
|
|
|
|
if (loadingThemeFileName != null) {
|
|
|
|
String path = (String) args[0];
|
|
|
|
if (loadingThemeFileName.equals(path)) {
|
|
|
|
loadingThemeFileName = null;
|
|
|
|
File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
|
|
|
|
Theme.ThemeInfo themeInfo = Theme.fillThemeValues(locFile, loadingTheme.title, loadingTheme);
|
|
|
|
if (themeInfo != null) {
|
|
|
|
if (themeInfo.pathToWallpaper != null) {
|
|
|
|
File file = new File(themeInfo.pathToWallpaper);
|
|
|
|
if (!file.exists()) {
|
|
|
|
TLRPC.TL_account_getWallPaper req = new TLRPC.TL_account_getWallPaper();
|
|
|
|
TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
|
|
|
|
inputWallPaperSlug.slug = themeInfo.slug;
|
|
|
|
req.wallpaper = inputWallPaperSlug;
|
|
|
|
ConnectionsManager.getInstance(themeInfo.account).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (response instanceof TLRPC.TL_wallPaper) {
|
|
|
|
TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) response;
|
|
|
|
loadingThemeInfo = themeInfo;
|
|
|
|
loadingThemeWallpaperName = FileLoader.getAttachFileName(wallPaper.document);
|
2019-12-31 14:08:08 +01:00
|
|
|
loadingThemeWallpaper = wallPaper;
|
2019-09-10 12:56:11 +02:00
|
|
|
FileLoader.getInstance(themeInfo.account).loadFile(wallPaper.document, wallPaper, 1, 1);
|
|
|
|
} else {
|
|
|
|
onThemeLoadFinish();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
|
|
|
|
if (finalThemeInfo != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
onThemeLoadFinish();
|
|
|
|
}
|
|
|
|
} else if (loadingThemeWallpaperName != null) {
|
|
|
|
String path = (String) args[0];
|
|
|
|
if (loadingThemeWallpaperName.equals(path)) {
|
|
|
|
loadingThemeWallpaperName = null;
|
|
|
|
File file = (File) args[1];
|
2019-12-31 14:08:08 +01:00
|
|
|
if (loadingThemeAccent) {
|
|
|
|
openThemeAccentPreview(loadingTheme, loadingThemeWallpaper, loadingThemeInfo);
|
|
|
|
onThemeLoadFinish();
|
|
|
|
} else {
|
2020-01-05 12:50:11 +01:00
|
|
|
Theme.ThemeInfo info = loadingThemeInfo;
|
2019-12-31 14:08:08 +01:00
|
|
|
Utilities.globalQueue.postRunnable(() -> {
|
2020-01-05 12:50:11 +01:00
|
|
|
info.createBackground(file, info.pathToWallpaper);
|
2019-12-31 14:08:08 +01:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
2020-01-05 12:50:11 +01:00
|
|
|
if (loadingTheme == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
|
|
|
|
Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
|
|
|
|
if (finalThemeInfo != null) {
|
|
|
|
presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
|
|
|
|
}
|
|
|
|
onThemeLoadFinish();
|
|
|
|
});
|
2019-09-10 12:56:11 +02:00
|
|
|
});
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.fileDidFailToLoad) {
|
|
|
|
String path = (String) args[0];
|
|
|
|
if (path.equals(loadingThemeFileName) || path.equals(loadingThemeWallpaperName)) {
|
|
|
|
onThemeLoadFinish();
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (id == NotificationCenter.screenStateChanged) {
|
|
|
|
if (ApplicationLoader.mainInterfacePaused) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ApplicationLoader.isScreenOn) {
|
|
|
|
onPasscodeResume();
|
|
|
|
} else {
|
|
|
|
onPasscodePause();
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.needCheckSystemBarColors) {
|
|
|
|
checkSystemBarColors();
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getStringForLanguageAlert(HashMap<String, String> map, String key, int intKey) {
|
|
|
|
String value = map.get(key);
|
|
|
|
if (value == null) {
|
|
|
|
return LocaleController.getString(key, intKey);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void openThemeAccentPreview(TLRPC.TL_theme t, TLRPC.TL_wallPaper wallPaper, Theme.ThemeInfo info) {
|
|
|
|
int lastId = info.lastAccentId;
|
|
|
|
Theme.ThemeAccent accent = info.createNewAccent(t, currentAccount);
|
|
|
|
info.prevAccentId = info.currentAccentId;
|
|
|
|
info.setCurrentAccentId(accent.id);
|
|
|
|
accent.pattern = wallPaper;
|
|
|
|
presentFragment(new ThemePreviewActivity(info, lastId != info.lastAccentId, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private void onThemeLoadFinish() {
|
|
|
|
if (loadingThemeProgressDialog != null) {
|
|
|
|
try {
|
|
|
|
loadingThemeProgressDialog.dismiss();
|
|
|
|
} finally {
|
|
|
|
loadingThemeProgressDialog = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadingThemeWallpaperName = null;
|
2019-12-31 14:08:08 +01:00
|
|
|
loadingThemeWallpaper = null;
|
2019-09-10 12:56:11 +02:00
|
|
|
loadingThemeInfo = null;
|
|
|
|
loadingThemeFileName = null;
|
|
|
|
loadingTheme = null;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void checkFreeDiscSpace() {
|
2019-08-22 01:53:26 +02:00
|
|
|
SharedConfig.checkKeepMedia();
|
2017-12-08 18:35:59 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
Utilities.globalQueue.postRunnable(() -> {
|
|
|
|
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
if (Math.abs(preferences.getLong("last_space_check", 0) - System.currentTimeMillis()) >= 3 * 24 * 3600 * 1000) {
|
|
|
|
File path = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
|
|
|
|
if (path == null) {
|
|
|
|
return;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
long freeSpace;
|
|
|
|
StatFs statFs = new StatFs(path.getAbsolutePath());
|
|
|
|
if (Build.VERSION.SDK_INT < 18) {
|
|
|
|
freeSpace = Math.abs(statFs.getAvailableBlocks() * statFs.getBlockSize());
|
|
|
|
} else {
|
|
|
|
freeSpace = statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
|
|
|
|
}
|
|
|
|
if (freeSpace < 1024 * 1024 * 100) {
|
2020-06-25 17:28:55 +02:00
|
|
|
preferences.edit().putLong("last_space_check", System.currentTimeMillis()).apply();
|
2018-08-27 10:33:11 +02:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
try {
|
|
|
|
AlertsCreator.createFreeSpaceDialog(LaunchActivity.this).show();
|
|
|
|
} catch (Throwable ignore) {
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} catch (Throwable ignore) {
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private void showLanguageAlertInternal(LocaleController.LocaleInfo systemInfo, LocaleController.LocaleInfo englishInfo, String systemLang) {
|
|
|
|
try {
|
|
|
|
loadingLocaleDialog = false;
|
|
|
|
boolean firstSystem = systemInfo.builtIn || LocaleController.getInstance().isCurrentLocalLocale();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
|
|
|
|
builder.setTitle(getStringForLanguageAlert(systemLocaleStrings, "ChooseYourLanguage", R.string.ChooseYourLanguage));
|
|
|
|
builder.setSubtitle(getStringForLanguageAlert(englishLocaleStrings, "ChooseYourLanguage", R.string.ChooseYourLanguage));
|
|
|
|
LinearLayout linearLayout = new LinearLayout(LaunchActivity.this);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
final LanguageCell[] cells = new LanguageCell[2];
|
|
|
|
final LocaleController.LocaleInfo[] selectedLanguage = new LocaleController.LocaleInfo[1];
|
|
|
|
final LocaleController.LocaleInfo[] locales = new LocaleController.LocaleInfo[2];
|
|
|
|
final String englishName = getStringForLanguageAlert(systemLocaleStrings, "English", R.string.English);
|
|
|
|
locales[0] = firstSystem ? systemInfo : englishInfo;
|
|
|
|
locales[1] = firstSystem ? englishInfo : systemInfo;
|
|
|
|
selectedLanguage[0] = firstSystem ? systemInfo : englishInfo;
|
|
|
|
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
cells[a] = new LanguageCell(LaunchActivity.this, true);
|
|
|
|
cells[a].setLanguage(locales[a], locales[a] == englishInfo ? englishName : null, true);
|
|
|
|
cells[a].setTag(a);
|
|
|
|
cells[a].setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_dialogButtonSelector), 2));
|
|
|
|
cells[a].setLanguageSelected(a == 0);
|
2019-01-23 18:03:33 +01:00
|
|
|
linearLayout.addView(cells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
|
2018-08-27 10:33:11 +02:00
|
|
|
cells[a].setOnClickListener(v -> {
|
|
|
|
Integer tag = (Integer) v.getTag();
|
|
|
|
selectedLanguage[0] = ((LanguageCell) v).getCurrentLocale();
|
|
|
|
for (int a1 = 0; a1 < cells.length; a1++) {
|
|
|
|
cells[a1].setLanguageSelected(a1 == tag);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
LanguageCell cell = new LanguageCell(LaunchActivity.this, true);
|
|
|
|
cell.setValue(getStringForLanguageAlert(systemLocaleStrings, "ChooseYourLanguageOther", R.string.ChooseYourLanguageOther), getStringForLanguageAlert(englishLocaleStrings, "ChooseYourLanguageOther", R.string.ChooseYourLanguageOther));
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
localeDialog = null;
|
|
|
|
drawerLayoutContainer.closeDrawer(true);
|
|
|
|
presentFragment(new LanguageSelectActivity());
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
|
2017-07-08 18:32:04 +02:00
|
|
|
builder.setView(linearLayout);
|
2018-08-27 10:33:11 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> {
|
|
|
|
LocaleController.getInstance().applyLanguage(selectedLanguage[0], true, false, currentAccount);
|
|
|
|
rebuildAllFragments(true);
|
2017-07-08 18:32:04 +02:00
|
|
|
});
|
|
|
|
localeDialog = showAlertDialog(builder);
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
2020-06-25 17:28:55 +02:00
|
|
|
preferences.edit().putString("language_showed2", systemLang).apply();
|
2017-07-08 18:32:04 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showLanguageAlert(boolean force) {
|
|
|
|
try {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (loadingLocaleDialog || ApplicationLoader.mainInterfacePaused) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
2017-07-08 18:32:04 +02:00
|
|
|
String showedLang = preferences.getString("language_showed2", "");
|
2019-01-23 18:03:33 +01:00
|
|
|
final String systemLang = MessagesController.getInstance(currentAccount).suggestedLangCode;
|
2017-07-08 18:32:04 +02:00
|
|
|
if (!force && showedLang.equals(systemLang)) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("alert already showed for " + showedLang);
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
final LocaleController.LocaleInfo[] infos = new LocaleController.LocaleInfo[2];
|
2017-07-08 18:32:04 +02:00
|
|
|
String arg = systemLang.contains("-") ? systemLang.split("-")[0] : systemLang;
|
2017-12-08 18:35:59 +01:00
|
|
|
String alias;
|
|
|
|
if ("in".equals(arg)) {
|
|
|
|
alias = "id";
|
|
|
|
} else if ("iw".equals(arg)) {
|
|
|
|
alias = "he";
|
|
|
|
} else if ("jw".equals(arg)) {
|
|
|
|
alias = "jv";
|
|
|
|
} else {
|
|
|
|
alias = null;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
for (int a = 0; a < LocaleController.getInstance().languages.size(); a++) {
|
|
|
|
LocaleController.LocaleInfo info = LocaleController.getInstance().languages.get(a);
|
|
|
|
if (info.shortName.equals("en")) {
|
|
|
|
infos[0] = info;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (info.shortName.replace("_", "-").equals(systemLang) || info.shortName.equals(arg) || info.shortName.equals(alias)) {
|
2017-07-08 18:32:04 +02:00
|
|
|
infos[1] = info;
|
|
|
|
}
|
|
|
|
if (infos[0] != null && infos[1] != null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (infos[0] == null || infos[1] == null || infos[0] == infos[1]) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("show lang alert for " + infos[0].getKey() + " and " + infos[1].getKey());
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
systemLocaleStrings = null;
|
|
|
|
englishLocaleStrings = null;
|
|
|
|
loadingLocaleDialog = true;
|
|
|
|
|
|
|
|
TLRPC.TL_langpack_getStrings req = new TLRPC.TL_langpack_getStrings();
|
2019-01-23 18:03:33 +01:00
|
|
|
req.lang_code = infos[1].getLangCode();
|
2017-07-08 18:32:04 +02:00
|
|
|
req.keys.add("English");
|
|
|
|
req.keys.add("ChooseYourLanguage");
|
|
|
|
req.keys.add("ChooseYourLanguageOther");
|
|
|
|
req.keys.add("ChangeLanguageLater");
|
2018-08-27 10:33:11 +02:00
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
final HashMap<String, String> keys = new HashMap<>();
|
|
|
|
if (response != null) {
|
|
|
|
TLRPC.Vector vector = (TLRPC.Vector) response;
|
|
|
|
for (int a = 0; a < vector.objects.size(); a++) {
|
|
|
|
final TLRPC.LangPackString string = (TLRPC.LangPackString) vector.objects.get(a);
|
|
|
|
keys.put(string.key, string.value);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
systemLocaleStrings = keys;
|
|
|
|
if (englishLocaleStrings != null && systemLocaleStrings != null) {
|
|
|
|
showLanguageAlertInternal(infos[1], infos[0], systemLang);
|
|
|
|
}
|
|
|
|
});
|
2017-07-08 18:32:04 +02:00
|
|
|
}, ConnectionsManager.RequestFlagWithoutLogin);
|
|
|
|
|
|
|
|
req = new TLRPC.TL_langpack_getStrings();
|
2019-01-23 18:03:33 +01:00
|
|
|
req.lang_code = infos[0].getLangCode();
|
2017-07-08 18:32:04 +02:00
|
|
|
req.keys.add("English");
|
|
|
|
req.keys.add("ChooseYourLanguage");
|
|
|
|
req.keys.add("ChooseYourLanguageOther");
|
|
|
|
req.keys.add("ChangeLanguageLater");
|
2018-08-27 10:33:11 +02:00
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
final HashMap<String, String> keys = new HashMap<>();
|
|
|
|
if (response != null) {
|
|
|
|
TLRPC.Vector vector = (TLRPC.Vector) response;
|
|
|
|
for (int a = 0; a < vector.objects.size(); a++) {
|
|
|
|
final TLRPC.LangPackString string = (TLRPC.LangPackString) vector.objects.get(a);
|
|
|
|
keys.put(string.key, string.value);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
englishLocaleStrings = keys;
|
|
|
|
if (englishLocaleStrings != null && systemLocaleStrings != null) {
|
|
|
|
showLanguageAlertInternal(infos[1], infos[0], systemLang);
|
|
|
|
}
|
|
|
|
});
|
2017-07-08 18:32:04 +02:00
|
|
|
}, ConnectionsManager.RequestFlagWithoutLogin);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onPasscodePause() {
|
|
|
|
if (lockRunnable != null) {
|
2020-01-23 07:15:40 +01:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("cancel lockRunnable onPasscodePause");
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
AndroidUtilities.cancelRunOnUIThread(lockRunnable);
|
|
|
|
lockRunnable = null;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (SharedConfig.passcodeHash.length() != 0) {
|
2020-01-23 07:15:40 +01:00
|
|
|
SharedConfig.lastPauseTime = (int) (SystemClock.elapsedRealtime() / 1000);
|
2015-02-26 02:32:51 +01:00
|
|
|
lockRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (lockRunnable == this) {
|
|
|
|
if (AndroidUtilities.needShowPasscode(true)) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("lock app");
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
showPasscodeActivity();
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("didn't pass lock check");
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
lockRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-07-30 04:07:02 +02:00
|
|
|
if (SharedConfig.appLocked) {
|
2015-02-26 02:32:51 +01:00
|
|
|
AndroidUtilities.runOnUIThread(lockRunnable, 1000);
|
2020-01-23 07:15:40 +01:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("schedule app lock in " + 1000);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (SharedConfig.autoLockIn != 0) {
|
2020-01-23 07:15:40 +01:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("schedule app lock in " + (((long) SharedConfig.autoLockIn) * 1000 + 1000));
|
|
|
|
}
|
|
|
|
AndroidUtilities.runOnUIThread(lockRunnable, ((long) SharedConfig.autoLockIn) * 1000 + 1000);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedConfig.lastPauseTime = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedConfig.saveConfig();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onPasscodeResume() {
|
|
|
|
if (lockRunnable != null) {
|
2020-01-23 07:15:40 +01:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("cancel lockRunnable onPasscodeResume");
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
AndroidUtilities.cancelRunOnUIThread(lockRunnable);
|
|
|
|
lockRunnable = null;
|
|
|
|
}
|
|
|
|
if (AndroidUtilities.needShowPasscode(true)) {
|
|
|
|
showPasscodeActivity();
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (SharedConfig.lastPauseTime != 0) {
|
|
|
|
SharedConfig.lastPauseTime = 0;
|
|
|
|
SharedConfig.saveConfig();
|
2020-01-23 07:15:40 +01:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("reset lastPauseTime onPasscodeResume");
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void updateCurrentConnectionState(int account) {
|
|
|
|
if (actionBarLayout == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
String title = null;
|
2019-01-23 18:03:33 +01:00
|
|
|
int titleId = 0;
|
2017-07-08 18:32:04 +02:00
|
|
|
Runnable action = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
currentConnectionState = ConnectionsManager.getInstance(currentAccount).getConnectionState();
|
2015-09-24 22:52:02 +02:00
|
|
|
if (currentConnectionState == ConnectionsManager.ConnectionStateWaitingForNetwork) {
|
2019-01-23 18:03:33 +01:00
|
|
|
title = "WaitingForNetwork";
|
|
|
|
titleId = R.string.WaitingForNetwork;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (currentConnectionState == ConnectionsManager.ConnectionStateUpdating) {
|
2019-01-23 18:03:33 +01:00
|
|
|
title = "Updating";
|
|
|
|
titleId = R.string.Updating;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (currentConnectionState == ConnectionsManager.ConnectionStateConnectingToProxy) {
|
2019-01-23 18:03:33 +01:00
|
|
|
title = "ConnectingToProxy";
|
|
|
|
titleId = R.string.ConnectingToProxy;
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (currentConnectionState == ConnectionsManager.ConnectionStateConnecting) {
|
2019-01-23 18:03:33 +01:00
|
|
|
title = "Connecting";
|
|
|
|
titleId = R.string.Connecting;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if (currentConnectionState == ConnectionsManager.ConnectionStateConnecting || currentConnectionState == ConnectionsManager.ConnectionStateConnectingToProxy) {
|
2018-08-27 10:33:11 +02:00
|
|
|
action = () -> {
|
|
|
|
BaseFragment lastFragment = null;
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (!layerFragmentsStack.isEmpty()) {
|
|
|
|
lastFragment = layerFragmentsStack.get(layerFragmentsStack.size() - 1);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else {
|
|
|
|
if (!mainFragmentsStack.isEmpty()) {
|
|
|
|
lastFragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
if (lastFragment instanceof ProxyListActivity || lastFragment instanceof ProxySettingsActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
presentFragment(new ProxyListActivity());
|
2017-07-08 18:32:04 +02:00
|
|
|
};
|
2014-11-18 06:01:04 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
actionBarLayout.setTitleOverlayText(title, titleId, action);
|
2014-11-18 06:01:04 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void hideVisibleActionMode() {
|
|
|
|
if (visibleActionMode == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
visibleActionMode.finish();
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
try {
|
|
|
|
super.onSaveInstanceState(outState);
|
2014-09-28 15:37:26 +02: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 21:16:28 +01:00
|
|
|
Bundle args = lastFragment.getArguments();
|
|
|
|
if (lastFragment instanceof ChatActivity && args != null) {
|
|
|
|
outState.putBundle("args", args);
|
|
|
|
outState.putString("fragment", "chat");
|
|
|
|
} else if (lastFragment instanceof GroupCreateFinalActivity && args != null) {
|
|
|
|
outState.putBundle("args", args);
|
|
|
|
outState.putString("fragment", "group");
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (lastFragment instanceof WallpapersListActivity) {
|
2014-03-26 21:16:28 +01:00
|
|
|
outState.putString("fragment", "wallpapers");
|
2020-07-26 10:03:38 +02:00
|
|
|
} else if (lastFragment instanceof ProfileActivity) {
|
|
|
|
ProfileActivity profileActivity = (ProfileActivity) lastFragment;
|
|
|
|
if (profileActivity.isSettings()) {
|
|
|
|
outState.putString("fragment", "settings");
|
|
|
|
} else if (profileActivity.isChat() && args != null) {
|
|
|
|
outState.putBundle("args", args);
|
|
|
|
outState.putString("fragment", "chat_profile");
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (lastFragment instanceof ChannelCreateActivity && args != null && args.getInt("step") == 0) {
|
|
|
|
outState.putBundle("args", args);
|
|
|
|
outState.putString("fragment", "channel");
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
|
|
|
lastFragment.saveSelfArgs(outState);
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2020-06-25 17:28:55 +02:00
|
|
|
try {
|
|
|
|
if (passcodeView != null && passcodeView.getVisibility() == View.VISIBLE) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (SecretMediaViewer.hasInstance() && SecretMediaViewer.getInstance().isVisible()) {
|
|
|
|
SecretMediaViewer.getInstance().closePhoto(true, false);
|
|
|
|
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
|
|
|
PhotoViewer.getInstance().closePhoto(true, false);
|
|
|
|
} else if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
|
|
|
ArticleViewer.getInstance().close(true, false);
|
|
|
|
} else if (drawerLayoutContainer.isDrawerOpened()) {
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
} else if (AndroidUtilities.isTablet()) {
|
|
|
|
if (layersActionBarLayout != null && layersActionBarLayout.getVisibility() == View.VISIBLE) {
|
|
|
|
layersActionBarLayout.onBackPressed();
|
|
|
|
} else if (rightActionBarLayout != null) {
|
|
|
|
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-11-07 21:10:12 +01:00
|
|
|
}
|
2020-06-25 17:28:55 +02:00
|
|
|
} else {
|
|
|
|
actionBarLayout.onBackPressed();
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2020-06-25 17:28:55 +02:00
|
|
|
} catch (Exception ignored) {
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory() {
|
|
|
|
super.onLowMemory();
|
2019-12-31 14:08:08 +01:00
|
|
|
if (actionBarLayout != null) {
|
|
|
|
actionBarLayout.onLowMemory();
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onLowMemory();
|
|
|
|
layersActionBarLayout.onLowMemory();
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionModeStarted(ActionMode mode) {
|
|
|
|
super.onActionModeStarted(mode);
|
2019-05-14 14:08:05 +02:00
|
|
|
visibleActionMode = mode;
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
Menu menu = mode.getMenu();
|
|
|
|
if (menu != null) {
|
|
|
|
boolean extended = actionBarLayout.extendActionMode(menu);
|
|
|
|
if (!extended && AndroidUtilities.isTablet()) {
|
|
|
|
extended = rightActionBarLayout.extendActionMode(menu);
|
|
|
|
if (!extended) {
|
|
|
|
layersActionBarLayout.extendActionMode(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= 23 && mode.getType() == ActionMode.TYPE_FLOATING) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayout.onActionModeStarted(mode);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onActionModeStarted(mode);
|
|
|
|
layersActionBarLayout.onActionModeStarted(mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionModeFinished(ActionMode mode) {
|
|
|
|
super.onActionModeFinished(mode);
|
2019-05-14 14:08:05 +02:00
|
|
|
if (visibleActionMode == mode) {
|
|
|
|
visibleActionMode = null;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= 23 && mode.getType() == ActionMode.TYPE_FLOATING) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayout.onActionModeFinished(mode);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
rightActionBarLayout.onActionModeFinished(mode);
|
|
|
|
layersActionBarLayout.onActionModeFinished(mode);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreIme() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (SecretMediaViewer.hasInstance() && SecretMediaViewer.getInstance().isVisible()) {
|
2017-07-23 14:56:38 +02:00
|
|
|
SecretMediaViewer.getInstance().closePhoto(true, false);
|
|
|
|
return true;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
PhotoViewer.getInstance().closePhoto(true, false);
|
2014-06-07 01:35:21 +02:00
|
|
|
return true;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
ArticleViewer.getInstance().close(true, false);
|
|
|
|
return true;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
return false;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
@Override
|
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
|
|
|
int keyCode = event.getKeyCode();
|
|
|
|
if (!mainFragmentsStack.isEmpty() && (!PhotoViewer.hasInstance() || !PhotoViewer.getInstance().isVisible()) && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN && (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP || event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN)) {
|
|
|
|
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
|
|
|
|
if (fragment instanceof ChatActivity) {
|
|
|
|
if (((ChatActivity) fragment).maybePlayVisibleVideo()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (AndroidUtilities.isTablet() && !rightFragmentsStack.isEmpty()) {
|
|
|
|
fragment = rightFragmentsStack.get(rightFragmentsStack.size() - 1);
|
|
|
|
if (fragment instanceof ChatActivity) {
|
|
|
|
if (((ChatActivity) fragment).maybePlayVisibleVideo()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
return super.dispatchKeyEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:55:24 +02:00
|
|
|
@Override
|
2017-07-23 14:56:38 +02:00
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU && !SharedConfig.isWaitingForPasscodeEnter) {
|
|
|
|
if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return super.onKeyUp(keyCode, event);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return super.onKeyUp(keyCode, event);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2014-11-21 01:14:44 +01:00
|
|
|
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);
|
|
|
|
}
|
2014-10-01 21:55:24 +02:00
|
|
|
} else {
|
2014-11-21 01:14:44 +01:00
|
|
|
if (actionBarLayout.fragmentsStack.size() == 1) {
|
|
|
|
if (!drawerLayoutContainer.isDrawerOpened()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (getCurrentFocus() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(getCurrentFocus());
|
|
|
|
}
|
2014-11-21 01:14:44 +01:00
|
|
|
drawerLayoutContainer.openDrawer(false);
|
|
|
|
} else {
|
|
|
|
drawerLayoutContainer.closeDrawer(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionBarLayout.onKeyUp(keyCode, event);
|
|
|
|
}
|
2014-10-01 21:55:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
@Override
|
|
|
|
public boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
ArticleViewer.getInstance().close(false, true);
|
|
|
|
}
|
2020-06-25 17:28:55 +02:00
|
|
|
if (AndroidUtilities.isTablet() && layersActionBarLayout != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity || fragment instanceof CountrySelectActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
|
2015-07-22 20:56:37 +02:00
|
|
|
if (fragment instanceof DialogsActivity) {
|
2017-03-31 01:58:05 +02:00
|
|
|
DialogsActivity dialogsActivity = (DialogsActivity) fragment;
|
2015-07-22 20:56:37 +02:00
|
|
|
if (dialogsActivity.isMainDialogList() && layout != actionBarLayout) {
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayout.removeAllFragments();
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, false, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
layersActionBarLayout.removeAllFragments();
|
|
|
|
layersActionBarLayout.setVisibility(View.GONE);
|
2015-03-19 00:09:45 +01:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2014-09-25 05:54:35 +02:00
|
|
|
if (!tabletFullSize) {
|
|
|
|
shadowTabletSide.setVisibility(View.VISIBLE);
|
2014-09-28 15:37:26 +02:00
|
|
|
if (rightActionBarLayout.fragmentsStack.isEmpty()) {
|
2014-09-25 05:54:35 +02:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
if (fragment instanceof ChatActivity && !((ChatActivity) fragment).isInScheduleMode()) {
|
2014-11-20 15:45:33 +01:00
|
|
|
if (!tabletFullSize && layout == rightActionBarLayout || tabletFullSize && layout == actionBarLayout) {
|
2015-01-23 22:59:15 +01:00
|
|
|
boolean result = !(tabletFullSize && layout == actionBarLayout && actionBarLayout.fragmentsStack.size() == 1);
|
2014-11-20 15:45:33 +01:00
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
layersActionBarLayout.closeLastFragment(!forceWithoutAnimation);
|
|
|
|
}
|
2015-01-23 22:59:15 +01:00
|
|
|
if (!result) {
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBarLayout.presentFragment(fragment, false, forceWithoutAnimation, false, false);
|
2015-01-23 22:59:15 +01:00
|
|
|
}
|
|
|
|
return result;
|
2014-11-20 15:45:33 +01:00
|
|
|
} else if (!tabletFullSize && layout != rightActionBarLayout) {
|
2014-09-24 04:17:27 +02:00
|
|
|
rightActionBarLayout.setVisibility(View.VISIBLE);
|
2014-09-25 05:54:35 +02:00
|
|
|
backgroundTablet.setVisibility(View.GONE);
|
2014-09-24 04:17:27 +02:00
|
|
|
rightActionBarLayout.removeAllFragments();
|
2018-07-30 04:07:02 +02:00
|
|
|
rightActionBarLayout.presentFragment(fragment, removeLast, true, false, false);
|
2014-09-28 15:37:26 +02:00
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
layersActionBarLayout.closeLastFragment(!forceWithoutAnimation);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
return false;
|
2014-09-25 05:54:35 +02:00
|
|
|
} else if (tabletFullSize && layout != actionBarLayout) {
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBarLayout.presentFragment(fragment, actionBarLayout.fragmentsStack.size() > 1, forceWithoutAnimation, false, false);
|
2014-09-28 15:37:26 +02:00
|
|
|
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
|
|
|
|
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
|
|
|
|
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
|
|
|
|
a--;
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
layersActionBarLayout.closeLastFragment(!forceWithoutAnimation);
|
2014-09-25 05:54:35 +02:00
|
|
|
}
|
|
|
|
return false;
|
2014-09-28 15:37:26 +02: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-30 00:48:11 +02:00
|
|
|
layersActionBarLayout.closeLastFragment(!forceWithoutAnimation);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBarLayout.presentFragment(fragment, actionBarLayout.fragmentsStack.size() > 1, forceWithoutAnimation, false, false);
|
2014-11-17 23:04:31 +01:00
|
|
|
return false;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
} else if (layout != layersActionBarLayout) {
|
|
|
|
layersActionBarLayout.setVisibility(View.VISIBLE);
|
2015-03-19 00:09:45 +01:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, true);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (fragment instanceof LoginActivity) {
|
2014-09-25 05:54:35 +02:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
shadowTabletSide.setVisibility(View.GONE);
|
2014-09-24 04:17:27 +02:00
|
|
|
shadowTablet.setBackgroundColor(0x00000000);
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
shadowTablet.setBackgroundColor(0x7f000000);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
layersActionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, false, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean allow = true;
|
|
|
|
if (fragment instanceof LoginActivity) {
|
|
|
|
if (mainFragmentsStack.size() == 0) {
|
|
|
|
allow = false;
|
|
|
|
}
|
|
|
|
} else if (fragment instanceof CountrySelectActivity) {
|
|
|
|
if (mainFragmentsStack.size() == 1) {
|
|
|
|
allow = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(allow, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
return true;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
2015-05-03 13:48:36 +02:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity || fragment instanceof CountrySelectActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
|
2015-07-22 20:56:37 +02:00
|
|
|
if (fragment instanceof DialogsActivity) {
|
2017-03-31 01:58:05 +02:00
|
|
|
DialogsActivity dialogsActivity = (DialogsActivity) fragment;
|
2015-07-22 20:56:37 +02:00
|
|
|
if (dialogsActivity.isMainDialogList() && layout != actionBarLayout) {
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayout.removeAllFragments();
|
|
|
|
actionBarLayout.addFragmentToStack(fragment);
|
|
|
|
layersActionBarLayout.removeAllFragments();
|
|
|
|
layersActionBarLayout.setVisibility(View.GONE);
|
2015-03-19 00:09:45 +01:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2014-09-25 05:54:35 +02:00
|
|
|
if (!tabletFullSize) {
|
|
|
|
shadowTabletSide.setVisibility(View.VISIBLE);
|
2014-09-28 15:37:26 +02:00
|
|
|
if (rightActionBarLayout.fragmentsStack.isEmpty()) {
|
2014-09-25 05:54:35 +02:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
} else if (fragment instanceof ChatActivity && !((ChatActivity) fragment).isInScheduleMode()) {
|
2014-09-25 05:54:35 +02:00
|
|
|
if (!tabletFullSize && layout != rightActionBarLayout) {
|
2014-09-24 04:17:27 +02:00
|
|
|
rightActionBarLayout.setVisibility(View.VISIBLE);
|
2014-09-25 05:54:35 +02:00
|
|
|
backgroundTablet.setVisibility(View.GONE);
|
2014-09-24 04:17:27 +02:00
|
|
|
rightActionBarLayout.removeAllFragments();
|
|
|
|
rightActionBarLayout.addFragmentToStack(fragment);
|
2014-09-28 15:37:26 +02: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 04:17:27 +02:00
|
|
|
return false;
|
2014-09-25 05:54:35 +02:00
|
|
|
} else if (tabletFullSize && layout != actionBarLayout) {
|
|
|
|
actionBarLayout.addFragmentToStack(fragment);
|
2014-09-28 15:37:26 +02: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 05:54:35 +02:00
|
|
|
return false;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
} else if (layout != layersActionBarLayout) {
|
|
|
|
layersActionBarLayout.setVisibility(View.VISIBLE);
|
2015-03-19 00:09:45 +01:00
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(false, true);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (fragment instanceof LoginActivity) {
|
2014-09-25 05:54:35 +02:00
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
shadowTabletSide.setVisibility(View.GONE);
|
2014-09-24 04:17:27 +02:00
|
|
|
shadowTablet.setBackgroundColor(0x00000000);
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
shadowTablet.setBackgroundColor(0x7f000000);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
layersActionBarLayout.addFragmentToStack(fragment);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean allow = true;
|
|
|
|
if (fragment instanceof LoginActivity) {
|
|
|
|
if (mainFragmentsStack.size() == 0) {
|
|
|
|
allow = false;
|
|
|
|
}
|
|
|
|
} else if (fragment instanceof CountrySelectActivity) {
|
|
|
|
if (mainFragmentsStack.size() == 1) {
|
|
|
|
allow = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(allow, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
return true;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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 05:54:35 +02:00
|
|
|
if (!tabletFullSize) {
|
|
|
|
backgroundTablet.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-10-16 22:02:44 +02:00
|
|
|
} else if (layout == layersActionBarLayout && actionBarLayout.fragmentsStack.isEmpty() && layersActionBarLayout.fragmentsStack.size() == 1) {
|
2014-09-28 15:37:26 +02:00
|
|
|
onFinish();
|
|
|
|
finish();
|
|
|
|
return false;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (layout.fragmentsStack.size() <= 1) {
|
|
|
|
onFinish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (layout.fragmentsStack.size() >= 2 && !(layout.fragmentsStack.get(0) instanceof LoginActivity)) {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public void rebuildAllFragments(boolean last) {
|
|
|
|
if (layersActionBarLayout != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
layersActionBarLayout.rebuildAllFragmentViews(last, last);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBarLayout.rebuildAllFragmentViews(last, last);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void onRebuildAllFragments(ActionBarLayout layout, boolean last) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (layout == layersActionBarLayout) {
|
2018-07-30 04:07:02 +02:00
|
|
|
rightActionBarLayout.rebuildAllFragmentViews(last, last);
|
|
|
|
actionBarLayout.rebuildAllFragmentViews(last, last);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 02:23:46 +01:00
|
|
|
drawerLayoutAdapter.notifyDataSetChanged();
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|