Search in sources :

Example 1 with AudioPlayerAlert

use of org.telegram.ui.Components.AudioPlayerAlert in project Telegram-FOSS by Telegram-FOSS-Team.

the class LaunchActivity method handleIntent.

private boolean handleIntent(Intent intent, boolean isNew, boolean restore, boolean fromPassword) {
    if (AndroidUtilities.handleProxyIntent(this, intent)) {
        actionBarLayout.showLastFragment();
        if (AndroidUtilities.isTablet()) {
            layersActionBarLayout.showLastFragment();
            rightActionBarLayout.showLastFragment();
        }
        return true;
    }
    if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
        if (intent == null || !Intent.ACTION_MAIN.equals(intent.getAction())) {
            PhotoViewer.getInstance().closePhoto(false, true);
        }
    }
    int flags = intent.getFlags();
    String action = intent.getAction();
    final int[] intentAccount = new int[] { intent.getIntExtra("currentAccount", UserConfig.selectedAccount) };
    switchToAccount(intentAccount[0], true);
    boolean isVoipIntent = action != null && action.equals("voip");
    if (!fromPassword && (AndroidUtilities.needShowPasscode(true) || SharedConfig.isWaitingForPasscodeEnter)) {
        showPasscodeActivity(true, false, -1, -1, null, null);
        UserConfig.getInstance(currentAccount).saveConfig(false);
        if (!isVoipIntent) {
            passcodeSaveIntent = intent;
            passcodeSaveIntentIsNew = isNew;
            passcodeSaveIntentIsRestore = restore;
            return false;
        }
    }
    boolean pushOpened = false;
    long push_user_id = 0;
    long push_chat_id = 0;
    int push_enc_id = 0;
    int push_msg_id = 0;
    int open_settings = 0;
    int open_widget_edit = -1;
    int open_widget_edit_type = -1;
    int open_new_dialog = 0;
    long dialogId = 0;
    boolean showDialogsList = false;
    boolean showPlayer = false;
    boolean showLocations = false;
    boolean showGroupVoip = false;
    boolean showCallLog = false;
    boolean audioCallUser = false;
    boolean videoCallUser = false;
    boolean needCallAlert = false;
    boolean newContact = false;
    boolean newContactAlert = false;
    boolean scanQr = false;
    String searchQuery = null;
    String callSearchQuery = null;
    String newContactName = null;
    String newContactPhone = null;
    photoPathsArray = null;
    videoPath = null;
    sendingText = null;
    sendingLocation = null;
    documentsPathsArray = null;
    documentsOriginalPathsArray = null;
    documentsMimeType = null;
    documentsUrisArray = null;
    exportingChatUri = null;
    contactsToSend = null;
    contactsToSendUri = null;
    importingStickers = null;
    importingStickersEmoji = null;
    importingStickersSoftware = null;
    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;
                                    }
                                }
                            }
                        } catch (Throwable e) {
                            FileLog.e(e);
                        }
                    } else {
                        hash = intent.getExtras().getString("hash", null);
                    }
                    if (SharedConfig.directShareHash == null || !SharedConfig.directShareHash.equals(hash)) {
                        dialogId = 0;
                    }
                }
                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;
                            } else {
                                contactsToSendUri = uri;
                            }
                        } else {
                            error = true;
                        }
                    } 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();
                        }
                    }
                    String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
                    if (!TextUtils.isEmpty(text)) {
                        Matcher m = locationRegex.matcher(text);
                        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];
                                }
                            }
                            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)) {
                            text = subject + "\n" + text;
                        }
                        sendingText = text;
                    } else if (!TextUtils.isEmpty(subject)) {
                        sendingText = subject;
                    }
                    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 (uri != null) {
                            if (AndroidUtilities.isInternalUri(uri)) {
                                error = true;
                            }
                        }
                        if (!error && uri != null) {
                            if (type != null && type.startsWith("image/") || uri.toString().toLowerCase().endsWith(".jpg")) {
                                if (photoPathsArray == null) {
                                    photoPathsArray = new ArrayList<>();
                                }
                                SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
                                info.uri = uri;
                                photoPathsArray.add(info);
                            } else {
                                String originalPath = uri.toString();
                                if (dialogId == 0 && originalPath != null) {
                                    if (BuildVars.LOGS_ENABLED) {
                                        FileLog.d("export path = " + originalPath);
                                    }
                                    Set<String> exportUris = MessagesController.getInstance(intentAccount[0]).exportUri;
                                    String fileName = FileLoader.fixFileName(MediaController.getFileName(uri));
                                    for (String u : exportUris) {
                                        try {
                                            Pattern pattern = Pattern.compile(u);
                                            if (pattern.matcher(originalPath).find() || pattern.matcher(fileName).find()) {
                                                exportingChatUri = uri;
                                                break;
                                            }
                                        } catch (Exception e) {
                                            FileLog.e(e);
                                        }
                                    }
                                    if (exportingChatUri == null) {
                                        if (originalPath.startsWith("content://com.kakao.talk") && originalPath.endsWith("KakaoTalkChats.txt")) {
                                            exportingChatUri = uri;
                                        }
                                    }
                                }
                                if (exportingChatUri == null) {
                                    path = AndroidUtilities.getPath(uri);
                                    if (!BuildVars.NO_SCOPED_STORAGE) {
                                        path = MediaController.copyFileToCache(uri, "file");
                                    }
                                    if (path != null) {
                                        if (path.startsWith("file:")) {
                                            path = path.replace("file://", "");
                                        }
                                        if (type != null && type.startsWith("video/")) {
                                            videoPath = path;
                                        } else {
                                            if (documentsPathsArray == null) {
                                                documentsPathsArray = new ArrayList<>();
                                                documentsOriginalPathsArray = new ArrayList<>();
                                            }
                                            documentsPathsArray.add(path);
                                            documentsOriginalPathsArray.add(uri.toString());
                                        }
                                    } else {
                                        if (documentsUrisArray == null) {
                                            documentsUrisArray = new ArrayList<>();
                                        }
                                        documentsUrisArray.add(uri);
                                        documentsMimeType = type;
                                    }
                                }
                            }
                        }
                    } else if (sendingText == null && sendingLocation == null) {
                        error = true;
                    }
                }
                if (error) {
                    Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
                }
            } else if ("org.telegram.messenger.CREATE_STICKER_PACK".equals(intent.getAction())) {
                try {
                    importingStickers = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                    importingStickersEmoji = intent.getStringArrayListExtra("STICKER_EMOJIS");
                    importingStickersSoftware = intent.getStringExtra("IMPORTER");
                } catch (Throwable e) {
                    FileLog.e(e);
                    importingStickers = null;
                    importingStickersEmoji = null;
                    importingStickersSoftware = null;
                }
            } 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;
                        }
                    }
                    if (uris != null) {
                        if (type != null && type.startsWith("image/")) {
                            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 (photoPathsArray == null) {
                                    photoPathsArray = new ArrayList<>();
                                }
                                SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
                                info.uri = uri;
                                photoPathsArray.add(info);
                            }
                        } else {
                            Set<String> exportUris = MessagesController.getInstance(intentAccount[0]).exportUri;
                            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;
                                String path = AndroidUtilities.getPath(uri);
                                String originalPath = parcelable.toString();
                                if (originalPath == null) {
                                    originalPath = path;
                                }
                                if (BuildVars.LOGS_ENABLED) {
                                    FileLog.d("export path = " + originalPath);
                                }
                                if (dialogId == 0 && originalPath != null && exportingChatUri == null) {
                                    boolean ok = false;
                                    String fileName = FileLoader.fixFileName(MediaController.getFileName(uri));
                                    for (String u : exportUris) {
                                        try {
                                            Pattern pattern = Pattern.compile(u);
                                            if (pattern.matcher(originalPath).find() || pattern.matcher(fileName).find()) {
                                                exportingChatUri = uri;
                                                ok = true;
                                                break;
                                            }
                                        } catch (Exception e) {
                                            FileLog.e(e);
                                        }
                                    }
                                    if (ok) {
                                        continue;
                                    } else if (originalPath.startsWith("content://com.kakao.talk") && originalPath.endsWith("KakaoTalkChats.txt")) {
                                        exportingChatUri = uri;
                                        continue;
                                    }
                                }
                                if (path != null) {
                                    if (path.startsWith("file:")) {
                                        path = path.replace("file://", "");
                                    }
                                    if (documentsPathsArray == null) {
                                        documentsPathsArray = new ArrayList<>();
                                        documentsOriginalPathsArray = new ArrayList<>();
                                    }
                                    documentsPathsArray.add(path);
                                    documentsOriginalPathsArray.add(originalPath);
                                } else {
                                    if (documentsUrisArray == null) {
                                        documentsUrisArray = new ArrayList<>();
                                    }
                                    documentsUrisArray.add(uri);
                                    documentsMimeType = type;
                                }
                            }
                        }
                    } else {
                        error = true;
                    }
                } 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 voicechat = null;
                    String livestream = null;
                    String phoneHash = null;
                    String lang = null;
                    String theme = null;
                    String code = null;
                    TLRPC.TL_wallPaper wallPaper = null;
                    Integer messageId = null;
                    Long channelId = null;
                    Integer threadId = null;
                    Integer commentId = null;
                    int videoTimestamp = -1;
                    boolean hasUrl = false;
                    final String scheme = data.getScheme();
                    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/", "");
                                                boolean ok = false;
                                                if (wallPaper.slug != null && wallPaper.slug.length() == 6) {
                                                    try {
                                                        wallPaper.settings.background_color = Integer.parseInt(wallPaper.slug, 16) | 0xff000000;
                                                        wallPaper.slug = null;
                                                        ok = true;
                                                    } catch (Exception ignore) {
                                                    }
                                                } else if (wallPaper.slug != null && wallPaper.slug.length() >= 13 && AndroidUtilities.isValidWallChar(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, 13), 16) | 0xff000000;
                                                        if (wallPaper.slug.length() >= 20 && AndroidUtilities.isValidWallChar(wallPaper.slug.charAt(13))) {
                                                            wallPaper.settings.third_background_color = Integer.parseInt(wallPaper.slug.substring(14, 20), 16) | 0xff000000;
                                                        }
                                                        if (wallPaper.slug.length() == 27 && AndroidUtilities.isValidWallChar(wallPaper.slug.charAt(20))) {
                                                            wallPaper.settings.fourth_background_color = Integer.parseInt(wallPaper.slug.substring(21), 16) | 0xff000000;
                                                        }
                                                        try {
                                                            String rotation = data.getQueryParameter("rotation");
                                                            if (!TextUtils.isEmpty(rotation)) {
                                                                wallPaper.settings.rotation = Utilities.parseInt(rotation);
                                                            }
                                                        } catch (Exception ignore) {
                                                        }
                                                        wallPaper.slug = null;
                                                        ok = true;
                                                    } catch (Exception ignore) {
                                                    }
                                                }
                                                if (!ok) {
                                                    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;
                                                                }
                                                            }
                                                        }
                                                    }
                                                    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() >= 13) {
                                                                wallPaper.settings.second_background_color = Integer.parseInt(bgColor.substring(7, 13), 16) | 0xff000000;
                                                                if (bgColor.length() >= 20 && AndroidUtilities.isValidWallChar(bgColor.charAt(13))) {
                                                                    wallPaper.settings.third_background_color = Integer.parseInt(bgColor.substring(14, 20), 16) | 0xff000000;
                                                                }
                                                                if (bgColor.length() == 27 && AndroidUtilities.isValidWallChar(bgColor.charAt(20))) {
                                                                    wallPaper.settings.fourth_background_color = Integer.parseInt(bgColor.substring(21), 16) | 0xff000000;
                                                                }
                                                            }
                                                        } else {
                                                            wallPaper.settings.background_color = 0xffffffff;
                                                        }
                                                    } catch (Exception ignore) {
                                                    }
                                                    try {
                                                        String rotation = data.getQueryParameter("rotation");
                                                        if (!TextUtils.isEmpty(rotation)) {
                                                            wallPaper.settings.rotation = Utilities.parseInt(rotation);
                                                        }
                                                    } catch (Exception ignore) {
                                                    }
                                                }
                                            } else if (path.startsWith("login/")) {
                                                int intCode = Utilities.parseInt(path.replace("login/", ""));
                                                if (intCode != 0) {
                                                    code = "" + intCode;
                                                }
                                            } else if (path.startsWith("joinchat/")) {
                                                group = path.replace("joinchat/", "");
                                            } else if (path.startsWith("+")) {
                                                group = path.replace("+", "");
                                            } 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";
                                                    }
                                                    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.parseLong(segments.get(1));
                                                    messageId = Utilities.parseInt(segments.get(2));
                                                    if (messageId == 0 || channelId == 0) {
                                                        messageId = null;
                                                        channelId = null;
                                                    }
                                                    threadId = Utilities.parseInt(data.getQueryParameter("thread"));
                                                    if (threadId == 0) {
                                                        threadId = null;
                                                    }
                                                }
                                            } 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) {
                                                            messageId = null;
                                                        }
                                                    }
                                                }
                                                if (messageId != null) {
                                                    videoTimestamp = getTimestampFromLink(data);
                                                }
                                                botUser = data.getQueryParameter("start");
                                                botChat = data.getQueryParameter("startgroup");
                                                game = data.getQueryParameter("game");
                                                voicechat = data.getQueryParameter("voicechat");
                                                livestream = data.getQueryParameter("livestream");
                                                threadId = Utilities.parseInt(data.getQueryParameter("thread"));
                                                if (threadId == 0) {
                                                    threadId = null;
                                                }
                                                commentId = Utilities.parseInt(data.getQueryParameter("comment"));
                                                if (commentId == 0) {
                                                    commentId = null;
                                                }
                                            }
                                        }
                                    }
                                    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"));
                                            } else {
                                                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 {
                                            botUser = data.getQueryParameter("start");
                                            botChat = data.getQueryParameter("startgroup");
                                            game = data.getQueryParameter("game");
                                            voicechat = data.getQueryParameter("voicechat");
                                            livestream = data.getQueryParameter("livestream");
                                            messageId = Utilities.parseInt(data.getQueryParameter("post"));
                                            if (messageId == 0) {
                                                messageId = null;
                                            }
                                            threadId = Utilities.parseInt(data.getQueryParameter("thread"));
                                            if (threadId == 0) {
                                                threadId = null;
                                            }
                                            commentId = Utilities.parseInt(data.getQueryParameter("comment"));
                                            if (commentId == 0) {
                                                commentId = null;
                                            }
                                        }
                                    } 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.parseLong(data.getQueryParameter("channel"));
                                        if (messageId == 0 || channelId == 0) {
                                            messageId = null;
                                            channelId = null;
                                        }
                                        threadId = Utilities.parseInt(data.getQueryParameter("thread"));
                                        if (threadId == 0) {
                                            threadId = null;
                                        }
                                        commentId = Utilities.parseInt(data.getQueryParameter("comment"));
                                        if (commentId == 0) {
                                            commentId = null;
                                        }
                                    } 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");
                                        }
                                        boolean ok = false;
                                        if (wallPaper.slug != null && wallPaper.slug.length() == 6) {
                                            try {
                                                wallPaper.settings.background_color = Integer.parseInt(wallPaper.slug, 16) | 0xff000000;
                                                wallPaper.slug = null;
                                                ok = true;
                                            } catch (Exception ignore) {
                                            }
                                        } else if (wallPaper.slug != null && wallPaper.slug.length() >= 13 && AndroidUtilities.isValidWallChar(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, 13), 16) | 0xff000000;
                                                if (wallPaper.slug.length() >= 20 && AndroidUtilities.isValidWallChar(wallPaper.slug.charAt(13))) {
                                                    wallPaper.settings.third_background_color = Integer.parseInt(wallPaper.slug.substring(14, 20), 16) | 0xff000000;
                                                }
                                                if (wallPaper.slug.length() == 27 && AndroidUtilities.isValidWallChar(wallPaper.slug.charAt(20))) {
                                                    wallPaper.settings.fourth_background_color = Integer.parseInt(wallPaper.slug.substring(21), 16) | 0xff000000;
                                                }
                                                try {
                                                    String rotation = data.getQueryParameter("rotation");
                                                    if (!TextUtils.isEmpty(rotation)) {
                                                        wallPaper.settings.rotation = Utilities.parseInt(rotation);
                                                    }
                                                } catch (Exception ignore) {
                                                }
                                                wallPaper.slug = null;
                                                ok = true;
                                            } catch (Exception ignore) {
                                            }
                                        }
                                        if (!ok) {
                                            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;
                                                        }
                                                    }
                                                }
                                            }
                                            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() >= 13) {
                                                        wallPaper.settings.second_background_color = Integer.parseInt(bgColor.substring(8, 13), 16) | 0xff000000;
                                                        if (bgColor.length() >= 20 && AndroidUtilities.isValidWallChar(bgColor.charAt(13))) {
                                                            wallPaper.settings.third_background_color = Integer.parseInt(bgColor.substring(14, 20), 16) | 0xff000000;
                                                        }
                                                        if (bgColor.length() == 27 && AndroidUtilities.isValidWallChar(bgColor.charAt(20))) {
                                                            wallPaper.settings.fourth_background_color = Integer.parseInt(bgColor.substring(21), 16) | 0xff000000;
                                                        }
                                                    }
                                                }
                                            } catch (Exception ignore) {
                                            }
                                            try {
                                                String rotation = data.getQueryParameter("rotation");
                                                if (!TextUtils.isEmpty(rotation)) {
                                                    wallPaper.settings.rotation = Utilities.parseInt(rotation);
                                                }
                                            } catch (Exception ignore) {
                                            }
                                        }
                                    } 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";
                                            }
                                            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");
                                        int intCode = Utilities.parseInt(data.getQueryParameter("code"));
                                        if (intCode != 0) {
                                            code = "" + intCode;
                                        }
                                    } 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 = Long.parseLong(userID);
                                            } catch (NumberFormatException ignore) {
                                            }
                                        } else if (chatID != null) {
                                            try {
                                                push_chat_id = Long.parseLong(chatID);
                                            } catch (NumberFormatException ignore) {
                                            }
                                        }
                                        if (msgID != null) {
                                            try {
                                                push_msg_id = Integer.parseInt(msgID);
                                            } catch (NumberFormatException ignore) {
                                            }
                                        }
                                    } 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"));
                                        } else {
                                            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;
                                        } else {
                                            open_settings = 1;
                                        }
                                    } else if ((url.startsWith("tg:search") || url.startsWith("tg://search"))) {
                                        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 = "";
                                        }
                                    } else if ((url.startsWith("tg:calllog") || url.startsWith("tg://calllog"))) {
                                        showCallLog = true;
                                    } else if ((url.startsWith("tg:call") || url.startsWith("tg://call"))) {
                                        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);
                                                if (contacts.isEmpty() && callPhone != null) {
                                                    newContactName = callUserName;
                                                    newContactPhone = callPhone;
                                                    newContactAlert = true;
                                                } else {
                                                    if (contacts.size() == 1) {
                                                        push_user_id = contacts.get(0).user_id;
                                                    }
                                                    if (push_user_id == 0) {
                                                        callSearchQuery = callUserName != null ? callUserName : "";
                                                    }
                                                    if ("video".equalsIgnoreCase(callFormat)) {
                                                        videoCallUser = true;
                                                    } else {
                                                        audioCallUser = true;
                                                    }
                                                    needCallAlert = true;
                                                }
                                            } 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);
                                            }
                                        }
                                    } else if ((url.startsWith("tg:scanqr") || url.startsWith("tg://scanqr"))) {
                                        scanQr = true;
                                    } else if ((url.startsWith("tg:addcontact") || url.startsWith("tg://addcontact"))) {
                                        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;
                                    } else {
                                        unsupportedUrl = url.replace("tg://", "").replace("tg:", "");
                                        int index;
                                        if ((index = unsupportedUrl.indexOf('?')) >= 0) {
                                            unsupportedUrl = unsupportedUrl.substring(0, index);
                                        }
                                    }
                                    break;
                                }
                        }
                    }
                    if (intent.hasExtra(EXTRA_ACTION_TOKEN)) {
                        final boolean success = UserConfig.getInstance(currentAccount).isClientActivated() && "tg".equals(scheme) && unsupportedUrl == null;
                        intent.removeExtra(EXTRA_ACTION_TOKEN);
                    }
                    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 || voicechat != null || auth != null || unsupportedUrl != null || lang != null || code != null || wallPaper != null || channelId != null || theme != null || login != null) {
                            if (message != null && message.startsWith("@")) {
                                message = " " + message;
                            }
                            runLinkRequest(intentAccount[0], username, group, sticker, botUser, botChat, message, hasUrl, messageId, channelId, threadId, commentId, game, auth, lang, unsupportedUrl, code, login, wallPaper, theme, voicechat, livestream, 0, videoTimestamp);
                        } 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;
                                            }
                                        }
                                        long userId = cursor.getLong(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;
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                FileLog.e(e);
                            }
                        }
                    }
                }
            } 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")) {
                long chatId = intent.getLongExtra("chatId", intent.getIntExtra("chatId", 0));
                long userId = intent.getLongExtra("userId", intent.getIntExtra("userId", 0));
                int encId = intent.getIntExtra("encId", 0);
                int widgetId = intent.getIntExtra("appWidgetId", 0);
                if (widgetId != 0) {
                    open_settings = 6;
                    open_widget_edit = widgetId;
                    open_widget_edit_type = intent.getIntExtra("appWidgetType", 0);
                } else {
                    if (push_msg_id == 0) {
                        push_msg_id = intent.getIntExtra("message_id", 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;
            } else if (action.equals("voip_chat")) {
                showGroupVoip = true;
            }
        }
    }
    if (UserConfig.getInstance(currentAccount).isClientActivated()) {
        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;
            }
        }
        if (push_user_id != 0) {
            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, AccountInstance.getInstance(intentAccount[0]));
                }
            } else {
                Bundle args = new Bundle();
                args.putLong("user_id", push_user_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))) {
                    ChatActivity fragment = new ChatActivity(args);
                    if (actionBarLayout.presentFragment(fragment, false, true, true, false)) {
                        pushOpened = true;
                        drawerLayoutContainer.closeDrawer();
                    }
                }
            }
        } else if (push_chat_id != 0) {
            Bundle args = new Bundle();
            args.putLong("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))) {
                ChatActivity fragment = new ChatActivity(args);
                if (actionBarLayout.presentFragment(fragment, false, true, true, false)) {
                    pushOpened = true;
                    drawerLayoutContainer.closeDrawer();
                }
            }
        } 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;
                drawerLayoutContainer.closeDrawer();
            }
        } 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--;
                    }
                    layersActionBarLayout.closeLastFragment(false);
                }
            }
            pushOpened = false;
            isNew = false;
        } else if (showPlayer) {
            if (!actionBarLayout.fragmentsStack.isEmpty()) {
                BaseFragment fragment = actionBarLayout.fragmentsStack.get(0);
                fragment.showDialog(new AudioPlayerAlert(this, null));
            }
            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();
                    locationActivity.setDelegate((location, live, notify, scheduleDate) -> SendMessagesHelper.getInstance(intentAccount[0]).sendMessage(location, dialog_id, null, null, null, null, notify, scheduleDate));
                    presentFragment(locationActivity);
                }, null));
            }
            pushOpened = false;
        } else if (exportingChatUri != null) {
            runImportRequest(exportingChatUri, documentsUrisArray);
        } else if (importingStickers != null) {
            AndroidUtilities.runOnUIThread(() -> {
                if (!actionBarLayout.fragmentsStack.isEmpty()) {
                    BaseFragment fragment = actionBarLayout.fragmentsStack.get(0);
                    fragment.showDialog(new StickersAlert(this, importingStickersSoftware, importingStickers, importingStickersEmoji, null));
                }
            });
            pushOpened = false;
        } else if (videoPath != null || photoPathsArray != null || sendingText != null || sendingLocation != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
            if (!AndroidUtilities.isTablet()) {
                NotificationCenter.getInstance(intentAccount[0]).postNotificationName(NotificationCenter.closeChats);
            }
            if (dialogId == 0) {
                openDialogsToSend(false);
                pushOpened = true;
            } 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.putLong("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;
            } else if (open_settings == 6) {
                fragment = new EditWidgetActivity(open_widget_edit_type, open_widget_edit);
            } else {
                fragment = null;
            }
            boolean closePreviousFinal = closePrevious;
            if (open_settings == 6) {
                actionBarLayout.presentFragment(fragment, false, true, true, false);
            } else {
                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);
            }
            pushOpened = true;
        } 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, AccountInstance.getInstance(intentAccount[0]));
            });
            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) {
                fragment.setInitialPhoneNumber(PhoneFormat.stripExceptNumbers(newContactPhone, true), false);
            }
            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 (showGroupVoip) {
            GroupCallActivity.create(this, AccountInstance.getInstance(currentAccount), null, null, false, null);
            if (GroupCallActivity.groupCallInstance != null) {
                GroupCallActivity.groupCallUiVisible = true;
            }
        } else if (newContactAlert) {
            final BaseFragment lastFragment = actionBarLayout.getLastFragment();
            if (lastFragment != null && lastFragment.getParentActivity() != null) {
                final String finalNewContactName = newContactName;
                final String finalNewContactPhone = NewContactActivity.getPhoneNumber(this, UserConfig.getInstance(currentAccount).getCurrentUser(), newContactPhone, false);
                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;
            }
        } 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;
        }
    }
    if (!pushOpened && !isNew) {
        if (AndroidUtilities.isTablet()) {
            if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
                if (layersActionBarLayout.fragmentsStack.isEmpty()) {
                    layersActionBarLayout.addFragmentToStack(new LoginActivity());
                    drawerLayoutContainer.setAllowOpenDrawer(false, false);
                }
            } else {
                if (actionBarLayout.fragmentsStack.isEmpty()) {
                    DialogsActivity dialogsActivity = new DialogsActivity(null);
                    dialogsActivity.setSideMenu(sideMenu);
                    if (searchQuery != null) {
                        dialogsActivity.setInitialSearchString(searchQuery);
                    }
                    actionBarLayout.addFragmentToStack(dialogsActivity);
                    drawerLayoutContainer.setAllowOpenDrawer(true, false);
                }
            }
        } 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);
                    if (searchQuery != null) {
                        dialogsActivity.setInitialSearchString(searchQuery);
                    }
                    actionBarLayout.addFragmentToStack(dialogsActivity);
                    drawerLayoutContainer.setAllowOpenDrawer(true, false);
                }
            }
        }
        actionBarLayout.showLastFragment();
        if (AndroidUtilities.isTablet()) {
            layersActionBarLayout.showLastFragment();
            rightActionBarLayout.showLastFragment();
        }
    }
    if (isVoipIntent) {
        VoIPFragment.show(this, intentAccount[0]);
    }
    if (!showGroupVoip && (intent == null || !Intent.ACTION_MAIN.equals(intent.getAction())) && GroupCallActivity.groupCallInstance != null) {
        GroupCallActivity.groupCallInstance.dismiss();
    }
    intent.setAction(null);
    return pushOpened;
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AbstractSerializedData(org.telegram.tgnet.AbstractSerializedData) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) StickersAlert(org.telegram.ui.Components.StickersAlert) LocationController(org.telegram.messenger.LocationController) Bulletin(org.telegram.ui.Components.Bulletin) VoIPPendingCall(org.telegram.messenger.voip.VoIPPendingCall) MediaActionDrawable(org.telegram.ui.Components.MediaActionDrawable) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) Manifest(android.Manifest) Matcher(java.util.regex.Matcher) DrawerProfileCell(org.telegram.ui.Cells.DrawerProfileCell) Map(java.util.Map) Shader(android.graphics.Shader) Canvas(android.graphics.Canvas) Function(androidx.arch.core.util.Function) UndoView(org.telegram.ui.Components.UndoView) ContactsLoadingObserver(org.telegram.messenger.ContactsLoadingObserver) Set(java.util.Set) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) FileLoader(org.telegram.messenger.FileLoader) GroupCallPip(org.telegram.ui.Components.GroupCallPip) ViewParent(android.view.ViewParent) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SimpleDateFormat(java.text.SimpleDateFormat) SystemClock(android.os.SystemClock) AlertsCreator(org.telegram.ui.Components.AlertsCreator) WebRtcAudioTrack(org.webrtc.voiceengine.WebRtcAudioTrack) ArrayList(java.util.ArrayList) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) Menu(android.view.Menu) PasscodeView(org.telegram.ui.Components.PasscodeView) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) Settings(android.provider.Settings) JoinGroupAlert(org.telegram.ui.Components.JoinGroupAlert) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) LinearGradient(android.graphics.LinearGradient) Parcelable(android.os.Parcelable) R(org.telegram.messenger.R) LanguageCell(org.telegram.ui.Cells.LanguageCell) SideMenultItemAnimator(org.telegram.ui.Components.SideMenultItemAnimator) TextUtils(android.text.TextUtils) InputStreamReader(java.io.InputStreamReader) DrawerLayoutContainer(org.telegram.ui.ActionBar.DrawerLayoutContainer) File(java.io.File) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) DrawerAddCell(org.telegram.ui.Cells.DrawerAddCell) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) Configuration(android.content.res.Configuration) Easings(org.telegram.ui.Components.Easings) BufferedReader(java.io.BufferedReader) ChatObject(org.telegram.messenger.ChatObject) CameraController(org.telegram.messenger.camera.CameraController) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) AudioPlayerAlert(org.telegram.ui.Components.AudioPlayerAlert) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) ActionMode(android.view.ActionMode) LinearLayout(android.widget.LinearLayout) RadialProgress2(org.telegram.ui.Components.RadialProgress2) PackageManager(android.content.pm.PackageManager) Date(java.util.Date) DrawerLayoutAdapter(org.telegram.ui.Adapters.DrawerLayoutAdapter) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) VideoCapturerDevice(org.telegram.messenger.voip.VideoCapturerDevice) Animator(android.animation.Animator) ApplicationLoader(org.telegram.messenger.ApplicationLoader) ContactsContract(android.provider.ContactsContract) MediaController(org.telegram.messenger.MediaController) ThemeEditorView(org.telegram.ui.Components.ThemeEditorView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TermsOfServiceView(org.telegram.ui.Components.TermsOfServiceView) Matrix(android.graphics.Matrix) ParseException(java.text.ParseException) DateFormat(java.text.DateFormat) ImageLoader(org.telegram.messenger.ImageLoader) DrawerUserCell(org.telegram.ui.Cells.DrawerUserCell) Utilities(org.telegram.messenger.Utilities) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewAnimationUtils(android.view.ViewAnimationUtils) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) BlockingUpdateView(org.telegram.ui.Components.BlockingUpdateView) ViewGroup(android.view.ViewGroup) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) PhonebookShareAlert(org.telegram.ui.Components.PhonebookShareAlert) RelativeLayout(android.widget.RelativeLayout) Pattern(java.util.regex.Pattern) Location(android.location.Location) LocationManager(android.location.LocationManager) Window(android.view.Window) ActivityManager(android.app.ActivityManager) Context(android.content.Context) KeyEvent(android.view.KeyEvent) VoIPService(org.telegram.messenger.voip.VoIPService) Theme(org.telegram.ui.ActionBar.Theme) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) ActionBarLayout(org.telegram.ui.ActionBar.ActionBarLayout) SharingLocationsAlert(org.telegram.ui.Components.SharingLocationsAlert) AudioManager(android.media.AudioManager) MotionEvent(android.view.MotionEvent) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) Cursor(android.database.Cursor) Browser(org.telegram.messenger.browser.Browser) EmbedBottomSheet(org.telegram.ui.Components.EmbedBottomSheet) DialogObject(org.telegram.messenger.DialogObject) Point(android.graphics.Point) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) StatFs(android.os.StatFs) Bitmap(android.graphics.Bitmap) Base64(android.util.Base64) ViewTreeObserver(android.view.ViewTreeObserver) UpdateAppAlertDialog(org.telegram.ui.Components.UpdateAppAlertDialog) Activity(android.app.Activity) RecyclerListView(org.telegram.ui.Components.RecyclerListView) StickerSetBulletinLayout(org.telegram.ui.Components.StickerSetBulletinLayout) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) InputStream(java.io.InputStream) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) UpdateAppAlertDialog(org.telegram.ui.Components.UpdateAppAlertDialog) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) TLRPC(org.telegram.tgnet.TLRPC) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) SharingLocationsAlert(org.telegram.ui.Components.SharingLocationsAlert) ArrayList(java.util.ArrayList) List(java.util.List) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) Parcelable(android.os.Parcelable) StickersAlert(org.telegram.ui.Components.StickersAlert) Matcher(java.util.regex.Matcher) AudioPlayerAlert(org.telegram.ui.Components.AudioPlayerAlert) Uri(android.net.Uri) Pattern(java.util.regex.Pattern) Bundle(android.os.Bundle) Intent(android.content.Intent) Paint(android.graphics.Paint) Point(android.graphics.Point) ParseException(java.text.ParseException) Location(android.location.Location)

Aggregations

Manifest (android.Manifest)1 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ObjectAnimator (android.animation.ObjectAnimator)1 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Color (android.graphics.Color)1 LinearGradient (android.graphics.LinearGradient)1 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Shader (android.graphics.Shader)1