Search in sources :

Example 46 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupVoipInviteAlert method fillContacts.

private void fillContacts() {
    if (!showContacts) {
        return;
    }
    contacts.addAll(ContactsController.getInstance(currentAccount).contacts);
    long selfId = UserConfig.getInstance(currentAccount).clientUserId;
    for (int a = 0, N = contacts.size(); a < N; a++) {
        TLObject object = contacts.get(a);
        if (!(object instanceof TLRPC.TL_contact)) {
            continue;
        }
        long userId = ((TLRPC.TL_contact) object).user_id;
        if (userId == selfId || ignoredUsers.indexOfKey(userId) >= 0 || invitedUsers.contains(userId)) {
            contacts.remove(a);
            a--;
            N--;
        }
    }
    int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
    MessagesController messagesController = MessagesController.getInstance(currentAccount);
    Collections.sort(contacts, (o1, o2) -> {
        TLRPC.User user1 = messagesController.getUser(((TLRPC.TL_contact) o2).user_id);
        TLRPC.User user2 = messagesController.getUser(((TLRPC.TL_contact) o1).user_id);
        int status1 = 0;
        int status2 = 0;
        if (user1 != null) {
            if (user1.self) {
                status1 = currentTime + 50000;
            } else if (user1.status != null) {
                status1 = user1.status.expires;
            }
        }
        if (user2 != null) {
            if (user2.self) {
                status2 = currentTime + 50000;
            } else if (user2.status != null) {
                status2 = user2.status.expires;
            }
        }
        if (status1 > 0 && status2 > 0) {
            if (status1 > status2) {
                return 1;
            } else if (status1 < status2) {
                return -1;
            }
            return 0;
        } else if (status1 < 0 && status2 < 0) {
            if (status1 > status2) {
                return 1;
            } else if (status1 < status2) {
                return -1;
            }
            return 0;
        } else if (status1 < 0 && status2 > 0 || status1 == 0 && status2 != 0) {
            return -1;
        } else if (status2 < 0 || status1 != 0) {
            return 1;
        }
        return 0;
    });
}
Also used : TLObject(org.telegram.tgnet.TLObject) MessagesController(org.telegram.messenger.MessagesController) TLRPC(org.telegram.tgnet.TLRPC)

Example 47 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class LaunchActivity method didReceivedNotification.

@Override
@SuppressWarnings("unchecked")
public void didReceivedNotification(int id, final int account, Object... args) {
    if (id == NotificationCenter.appDidLogout) {
        switchToAvailableAccountOrLogout();
    } else if (id == NotificationCenter.closeOtherAppActivities) {
        if (args[0] != this) {
            onFinish();
            finish();
        }
    } else if (id == NotificationCenter.didUpdateConnectionState) {
        int state = ConnectionsManager.getInstance(account).getConnectionState();
        if (currentConnectionState != state) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("switch to state " + state);
            }
            currentConnectionState = state;
            updateCurrentConnectionState(account);
        }
    } else if (id == NotificationCenter.mainUserInfoChanged) {
        drawerLayoutAdapter.notifyDataSetChanged();
    } else if (id == NotificationCenter.needShowAlert) {
        final Integer reason = (Integer) args[0];
        if (reason == 6 || reason == 3 && proxyErrorDialog != null) {
            return;
        } else if (reason == 4) {
            showTosActivity(account, (TLRPC.TL_help_termsOfService) args[1]);
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        if (reason != 2 && reason != 3) {
            builder.setNegativeButton(LocaleController.getString("MoreInfo", R.string.MoreInfo), (dialogInterface, i) -> {
                if (!mainFragmentsStack.isEmpty()) {
                    MessagesController.getInstance(account).openByUserName("spambot", mainFragmentsStack.get(mainFragmentsStack.size() - 1), 1);
                }
            });
        }
        if (reason == 5) {
            builder.setMessage(LocaleController.getString("NobodyLikesSpam3", R.string.NobodyLikesSpam3));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        } else if (reason == 0) {
            builder.setMessage(LocaleController.getString("NobodyLikesSpam1", R.string.NobodyLikesSpam1));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        } else if (reason == 1) {
            builder.setMessage(LocaleController.getString("NobodyLikesSpam2", R.string.NobodyLikesSpam2));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        } else if (reason == 2) {
            builder.setMessage((String) args[1]);
            String type = (String) args[2];
            if (type.startsWith("AUTH_KEY_DROP_")) {
                builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setNegativeButton(LocaleController.getString("LogOut", R.string.LogOut), (dialog, which) -> MessagesController.getInstance(currentAccount).performLogout(2));
            } else {
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
            }
        } else if (reason == 3) {
            builder.setTitle(LocaleController.getString("Proxy", R.string.Proxy));
            builder.setMessage(LocaleController.getString("UseProxyTelegramError", R.string.UseProxyTelegramError));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
            proxyErrorDialog = showAlertDialog(builder);
            return;
        }
        if (!mainFragmentsStack.isEmpty()) {
            mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
        }
    } else if (id == NotificationCenter.wasUnableToFindCurrentLocation) {
        final HashMap<String, MessageObject> waitingForLocation = (HashMap<String, MessageObject>) args[0];
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.setNegativeButton(LocaleController.getString("ShareYouLocationUnableManually", R.string.ShareYouLocationUnableManually), (dialogInterface, i) -> {
            if (mainFragmentsStack.isEmpty()) {
                return;
            }
            BaseFragment lastFragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
            if (!AndroidUtilities.isGoogleMapsInstalled(lastFragment)) {
                return;
            }
            LocationActivity fragment = new LocationActivity(0);
            fragment.setDelegate((location, live, notify, scheduleDate) -> {
                for (HashMap.Entry<String, MessageObject> entry : waitingForLocation.entrySet()) {
                    MessageObject messageObject = entry.getValue();
                    SendMessagesHelper.getInstance(account).sendMessage(location, messageObject.getDialogId(), messageObject, null, null, null, notify, scheduleDate);
                }
            });
            presentFragment(fragment);
        });
        builder.setMessage(LocaleController.getString("ShareYouLocationUnable", R.string.ShareYouLocationUnable));
        if (!mainFragmentsStack.isEmpty()) {
            mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
        }
    } else if (id == NotificationCenter.didSetNewWallpapper) {
        if (sideMenu != null) {
            View child = sideMenu.getChildAt(0);
            if (child != null) {
                child.invalidate();
            }
        }
        if (backgroundTablet != null) {
            backgroundTablet.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
        }
    } else if (id == NotificationCenter.didSetPasscode) {
        if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture) {
            try {
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
            } catch (Exception e) {
                FileLog.e(e);
            }
        } else if (!AndroidUtilities.hasFlagSecureFragment()) {
            try {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    } else if (id == NotificationCenter.reloadInterface) {
        boolean last = mainFragmentsStack.size() > 1 && mainFragmentsStack.get(mainFragmentsStack.size() - 1) instanceof ProfileActivity;
        if (last) {
            ProfileActivity profileActivity = (ProfileActivity) mainFragmentsStack.get(mainFragmentsStack.size() - 1);
            if (!profileActivity.isSettings()) {
                last = false;
            }
        }
        rebuildAllFragments(last);
    } else if (id == NotificationCenter.suggestedLangpack) {
        showLanguageAlert(false);
    } else if (id == NotificationCenter.openArticle) {
        if (mainFragmentsStack.isEmpty()) {
            return;
        }
        ArticleViewer.getInstance().setParentActivity(this, mainFragmentsStack.get(mainFragmentsStack.size() - 1));
        ArticleViewer.getInstance().open((TLRPC.TL_webPage) args[0], (String) args[1]);
    } else if (id == NotificationCenter.hasNewContactsToImport) {
        if (actionBarLayout == null || actionBarLayout.fragmentsStack.isEmpty()) {
            return;
        }
        final int type = (Integer) args[0];
        final HashMap<String, ContactsController.Contact> contactHashMap = (HashMap<String, ContactsController.Contact>) args[1];
        final boolean first = (Boolean) args[2];
        final boolean schedule = (Boolean) args[3];
        BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
        AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
        builder.setTitle(LocaleController.getString("UpdateContactsTitle", R.string.UpdateContactsTitle));
        builder.setMessage(LocaleController.getString("UpdateContactsMessage", R.string.UpdateContactsMessage));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, false));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
        builder.setOnBackButtonListener((dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
        AlertDialog dialog = builder.create();
        fragment.showDialog(dialog);
        dialog.setCanceledOnTouchOutside(false);
    } else if (id == NotificationCenter.didSetNewTheme) {
        Boolean nightTheme = (Boolean) args[0];
        if (!nightTheme) {
            if (sideMenu != null) {
                sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
                sideMenu.setGlowColor(Theme.getColor(Theme.key_chats_menuBackground));
                sideMenu.setListSelectorColor(Theme.getColor(Theme.key_listSelector));
                sideMenu.getAdapter().notifyDataSetChanged();
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                try {
                    setTaskDescription(new ActivityManager.TaskDescription(null, null, Theme.getColor(Theme.key_actionBarDefault) | 0xff000000));
                } catch (Exception ignore) {
                }
            }
        }
        drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        boolean checkNavigationBarColor = true;
        if (args.length > 1) {
            checkNavigationBarColor = (boolean) args[1];
        }
        checkSystemBarColors(true, checkNavigationBarColor);
    } else if (id == NotificationCenter.needSetDayNightTheme) {
        boolean instant = false;
        if (Build.VERSION.SDK_INT >= 21 && args[2] != null) {
            if (themeSwitchImageView.getVisibility() == View.VISIBLE) {
                return;
            }
            try {
                int[] pos = (int[]) args[2];
                boolean toDark = (Boolean) args[4];
                RLottieImageView darkThemeView = (RLottieImageView) args[5];
                int w = drawerLayoutContainer.getMeasuredWidth();
                int h = drawerLayoutContainer.getMeasuredHeight();
                if (!toDark) {
                    darkThemeView.setVisibility(View.INVISIBLE);
                }
                Bitmap bitmap = Bitmap.createBitmap(drawerLayoutContainer.getMeasuredWidth(), drawerLayoutContainer.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                HashMap<View, Integer> viewLayerTypes = new HashMap<>();
                invalidateCachedViews(drawerLayoutContainer);
                drawerLayoutContainer.draw(canvas);
                frameLayout.removeView(themeSwitchImageView);
                if (toDark) {
                    frameLayout.addView(themeSwitchImageView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
                    themeSwitchSunView.setVisibility(View.GONE);
                } else {
                    frameLayout.addView(themeSwitchImageView, 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
                    themeSwitchSunView.setTranslationX(pos[0] - AndroidUtilities.dp(14));
                    themeSwitchSunView.setTranslationY(pos[1] - AndroidUtilities.dp(14));
                    themeSwitchSunView.setVisibility(View.VISIBLE);
                    themeSwitchSunView.invalidate();
                }
                themeSwitchImageView.setImageBitmap(bitmap);
                themeSwitchImageView.setVisibility(View.VISIBLE);
                themeSwitchSunDrawable = darkThemeView.getAnimatedDrawable();
                float finalRadius = (float) Math.max(Math.sqrt((w - pos[0]) * (w - pos[0]) + (h - pos[1]) * (h - pos[1])), Math.sqrt(pos[0] * pos[0] + (h - pos[1]) * (h - pos[1])));
                float finalRadius2 = (float) Math.max(Math.sqrt((w - pos[0]) * (w - pos[0]) + pos[1] * pos[1]), Math.sqrt(pos[0] * pos[0] + pos[1] * pos[1]));
                finalRadius = Math.max(finalRadius, finalRadius2);
                Animator anim = ViewAnimationUtils.createCircularReveal(toDark ? drawerLayoutContainer : themeSwitchImageView, pos[0], pos[1], toDark ? 0 : finalRadius, toDark ? finalRadius : 0);
                anim.setDuration(400);
                anim.setInterpolator(Easings.easeInOutQuad);
                anim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        themeSwitchImageView.setImageDrawable(null);
                        themeSwitchImageView.setVisibility(View.GONE);
                        themeSwitchSunView.setVisibility(View.GONE);
                        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeAccentListUpdated);
                        if (!toDark) {
                            darkThemeView.setVisibility(View.VISIBLE);
                        }
                        DrawerProfileCell.switchingTheme = false;
                    }
                });
                anim.start();
                instant = true;
            } catch (Throwable e) {
                FileLog.e(e);
                try {
                    themeSwitchImageView.setImageDrawable(null);
                    frameLayout.removeView(themeSwitchImageView);
                    DrawerProfileCell.switchingTheme = false;
                } catch (Exception e2) {
                    FileLog.e(e2);
                }
            }
        } else {
            DrawerProfileCell.switchingTheme = false;
        }
        Theme.ThemeInfo theme = (Theme.ThemeInfo) args[0];
        boolean nigthTheme = (Boolean) args[1];
        int accentId = (Integer) args[3];
        actionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
        if (AndroidUtilities.isTablet()) {
            layersActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
            rightActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
        }
    } else if (id == NotificationCenter.notificationsCountUpdated) {
        if (sideMenu != null) {
            Integer accountNum = (Integer) args[0];
            int count = sideMenu.getChildCount();
            for (int a = 0; a < count; a++) {
                View child = sideMenu.getChildAt(a);
                if (child instanceof DrawerUserCell) {
                    if (((DrawerUserCell) child).getAccountNumber() == accountNum) {
                        child.invalidate();
                        break;
                    }
                }
            }
        }
    } else if (id == NotificationCenter.fileLoaded) {
        String path = (String) args[0];
        if (SharedConfig.isAppUpdateAvailable()) {
            String name = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
            if (name.equals(path)) {
                updateAppUpdateViews(true);
            }
        }
        if (loadingThemeFileName != null) {
            if (loadingThemeFileName.equals(path)) {
                loadingThemeFileName = null;
                File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
                Theme.ThemeInfo themeInfo = Theme.fillThemeValues(locFile, loadingTheme.title, loadingTheme);
                if (themeInfo != null) {
                    if (themeInfo.pathToWallpaper != null) {
                        File file = new File(themeInfo.pathToWallpaper);
                        if (!file.exists()) {
                            TLRPC.TL_account_getWallPaper req = new TLRPC.TL_account_getWallPaper();
                            TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
                            inputWallPaperSlug.slug = themeInfo.slug;
                            req.wallpaper = inputWallPaperSlug;
                            ConnectionsManager.getInstance(themeInfo.account).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                                if (response instanceof TLRPC.TL_wallPaper) {
                                    TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) response;
                                    loadingThemeInfo = themeInfo;
                                    loadingThemeWallpaperName = FileLoader.getAttachFileName(wallPaper.document);
                                    loadingThemeWallpaper = wallPaper;
                                    FileLoader.getInstance(themeInfo.account).loadFile(wallPaper.document, wallPaper, 1, 1);
                                } else {
                                    onThemeLoadFinish();
                                }
                            }));
                            return;
                        }
                    }
                    Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
                    if (finalThemeInfo != null) {
                        presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
                    }
                }
                onThemeLoadFinish();
            }
        } else if (loadingThemeWallpaperName != null) {
            if (loadingThemeWallpaperName.equals(path)) {
                loadingThemeWallpaperName = null;
                File file = (File) args[1];
                if (loadingThemeAccent) {
                    openThemeAccentPreview(loadingTheme, loadingThemeWallpaper, loadingThemeInfo);
                    onThemeLoadFinish();
                } else {
                    Theme.ThemeInfo info = loadingThemeInfo;
                    Utilities.globalQueue.postRunnable(() -> {
                        info.createBackground(file, info.pathToWallpaper);
                        AndroidUtilities.runOnUIThread(() -> {
                            if (loadingTheme == null) {
                                return;
                            }
                            File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
                            Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
                            if (finalThemeInfo != null) {
                                presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
                            }
                            onThemeLoadFinish();
                        });
                    });
                }
            }
        }
    } else if (id == NotificationCenter.fileLoadFailed) {
        String path = (String) args[0];
        if (path.equals(loadingThemeFileName) || path.equals(loadingThemeWallpaperName)) {
            onThemeLoadFinish();
        }
        if (SharedConfig.isAppUpdateAvailable()) {
            String name = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
            if (name.equals(path)) {
                updateAppUpdateViews(true);
            }
        }
    } else if (id == NotificationCenter.screenStateChanged) {
        if (ApplicationLoader.mainInterfacePaused) {
            return;
        }
        if (ApplicationLoader.isScreenOn) {
            onPasscodeResume();
        } else {
            onPasscodePause();
        }
    } else if (id == NotificationCenter.needCheckSystemBarColors) {
        checkSystemBarColors();
    } else if (id == NotificationCenter.historyImportProgressChanged) {
        if (args.length > 1 && !mainFragmentsStack.isEmpty()) {
            AlertsCreator.processError(currentAccount, (TLRPC.TL_error) args[2], mainFragmentsStack.get(mainFragmentsStack.size() - 1), (TLObject) args[1]);
        }
    } else if (id == NotificationCenter.stickersImportComplete) {
        MediaDataController.getInstance(account).toggleStickerSet(this, (TLObject) args[0], 2, !mainFragmentsStack.isEmpty() ? mainFragmentsStack.get(mainFragmentsStack.size() - 1) : null, false, true);
    } else if (id == NotificationCenter.newSuggestionsAvailable) {
        sideMenu.invalidateViews();
    } else if (id == NotificationCenter.showBulletin) {
        if (!mainFragmentsStack.isEmpty()) {
            int type = (int) args[0];
            FrameLayout container = null;
            BaseFragment fragment = null;
            if (GroupCallActivity.groupCallUiVisible && GroupCallActivity.groupCallInstance != null) {
                container = GroupCallActivity.groupCallInstance.getContainer();
            }
            if (container == null) {
                fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
            }
            if (type == Bulletin.TYPE_NAME_CHANGED) {
                long peerId = (long) args[1];
                String text = peerId > 0 ? LocaleController.getString("YourNameChanged", R.string.YourNameChanged) : LocaleController.getString("CannelTitleChanged", R.string.ChannelTitleChanged);
                (container != null ? BulletinFactory.of(container, null) : BulletinFactory.of(fragment)).createErrorBulletin(text).show();
            } else if (type == Bulletin.TYPE_BIO_CHANGED) {
                long peerId = (long) args[1];
                String text = peerId > 0 ? LocaleController.getString("YourBioChanged", R.string.YourBioChanged) : LocaleController.getString("CannelDescriptionChanged", R.string.ChannelDescriptionChanged);
                (container != null ? BulletinFactory.of(container, null) : BulletinFactory.of(fragment)).createErrorBulletin(text).show();
            } else if (type == Bulletin.TYPE_STICKER) {
                TLRPC.Document sticker = (TLRPC.Document) args[1];
                StickerSetBulletinLayout layout = new StickerSetBulletinLayout(this, null, (int) args[2], sticker, null);
                if (fragment != null) {
                    Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT).show();
                } else {
                    Bulletin.make(container, layout, Bulletin.DURATION_SHORT).show();
                }
            } else if (type == Bulletin.TYPE_ERROR) {
                if (fragment != null) {
                    BulletinFactory.of(fragment).createErrorBulletin((String) args[1]).show();
                } else {
                    BulletinFactory.of(container, null).createErrorBulletin((String) args[1]).show();
                }
            }
        }
    } else if (id == NotificationCenter.groupCallUpdated) {
        checkWasMutedByAdmin(false);
    } else if (id == NotificationCenter.fileLoadProgressChanged) {
        if (updateTextView != null && SharedConfig.isAppUpdateAvailable()) {
            String location = (String) args[0];
            String fileName = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
            if (fileName != null && fileName.equals(location)) {
                Long loadedSize = (Long) args[1];
                Long totalSize = (Long) args[2];
                float loadProgress = loadedSize / (float) totalSize;
                updateLayoutIcon.setProgress(loadProgress, true);
                updateTextView.setText(LocaleController.formatString("AppUpdateDownloading", R.string.AppUpdateDownloading, (int) (loadProgress * 100)));
            }
        }
    } else if (id == NotificationCenter.appUpdateAvailable) {
        updateAppUpdateViews(mainFragmentsStack.size() == 1);
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) UpdateAppAlertDialog(org.telegram.ui.Components.UpdateAppAlertDialog) 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) HashMap(java.util.HashMap) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) TLRPC(org.telegram.tgnet.TLRPC) Canvas(android.graphics.Canvas) DrawerUserCell(org.telegram.ui.Cells.DrawerUserCell) File(java.io.File) ContactsController(org.telegram.messenger.ContactsController) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StickerSetBulletinLayout(org.telegram.ui.Components.StickerSetBulletinLayout) ActivityManager(android.app.ActivityManager) Bitmap(android.graphics.Bitmap) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ImageView(android.widget.ImageView) UndoView(org.telegram.ui.Components.UndoView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) PasscodeView(org.telegram.ui.Components.PasscodeView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) ThemeEditorView(org.telegram.ui.Components.ThemeEditorView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TermsOfServiceView(org.telegram.ui.Components.TermsOfServiceView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BlockingUpdateView(org.telegram.ui.Components.BlockingUpdateView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) Point(android.graphics.Point) ParseException(java.text.ParseException) SideMenultItemAnimator(org.telegram.ui.Components.SideMenultItemAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TLObject(org.telegram.tgnet.TLObject) FrameLayout(android.widget.FrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) Theme(org.telegram.ui.ActionBar.Theme) MessageObject(org.telegram.messenger.MessageObject)

Example 48 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupCallActivity method processSelectedOption.

private void processSelectedOption(TLRPC.TL_groupCallParticipant participant, long peerId, int option) {
    VoIPService voIPService = VoIPService.getSharedInstance();
    if (voIPService == null) {
        return;
    }
    TLObject object;
    if (peerId > 0) {
        object = accountInstance.getMessagesController().getUser(peerId);
    } else {
        object = accountInstance.getMessagesController().getChat(-peerId);
    }
    if (option == 0 || option == 2 || option == 3) {
        if (option == 0) {
            if (VoIPService.getSharedInstance() == null) {
                return;
            }
            VoIPService.getSharedInstance().editCallMember(object, true, null, null, null, null);
            getUndoView().showWithAction(0, UndoView.ACTION_VOIP_MUTED, object, null, null, null);
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setDialogButtonColorKey(Theme.key_voipgroup_listeningText);
        TextView messageTextView = new TextView(getContext());
        messageTextView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
        messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
        FrameLayout frameLayout = new FrameLayout(getContext());
        builder.setView(frameLayout);
        AvatarDrawable avatarDrawable = new AvatarDrawable();
        avatarDrawable.setTextSize(AndroidUtilities.dp(12));
        BackupImageView imageView = new BackupImageView(getContext());
        imageView.setRoundRadius(AndroidUtilities.dp(20));
        frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
        avatarDrawable.setInfo(object);
        String name;
        if (object instanceof TLRPC.User) {
            TLRPC.User user = (TLRPC.User) object;
            imageView.setForUserOrChat(user, avatarDrawable);
            name = UserObject.getFirstName(user);
        } else {
            TLRPC.Chat chat = (TLRPC.Chat) object;
            imageView.setForUserOrChat(chat, avatarDrawable);
            name = chat.title;
        }
        TextView textView = new TextView(getContext());
        textView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        textView.setLines(1);
        textView.setMaxLines(1);
        textView.setSingleLine(true);
        textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
        textView.setEllipsize(TextUtils.TruncateAt.END);
        if (option == 2) {
            textView.setText(LocaleController.getString("VoipGroupRemoveMemberAlertTitle2", R.string.VoipGroupRemoveMemberAlertTitle2));
            if (ChatObject.isChannelOrGiga(currentChat)) {
                messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipChannelRemoveMemberAlertText2", R.string.VoipChannelRemoveMemberAlertText2, name, currentChat.title)));
            } else {
                messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupRemoveMemberAlertText2", R.string.VoipGroupRemoveMemberAlertText2, name, currentChat.title)));
            }
        } else {
            textView.setText(LocaleController.getString("VoipGroupAddMemberTitle", R.string.VoipGroupAddMemberTitle));
            messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupAddMemberText", R.string.VoipGroupAddMemberText, name, currentChat.title)));
        }
        frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
        frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
        if (option == 2) {
            builder.setPositiveButton(LocaleController.getString("VoipGroupUserRemove", R.string.VoipGroupUserRemove), (dialogInterface, i) -> {
                if (object instanceof TLRPC.User) {
                    TLRPC.User user = (TLRPC.User) object;
                    accountInstance.getMessagesController().deleteParticipantFromChat(currentChat.id, user, null);
                    getUndoView().showWithAction(0, UndoView.ACTION_VOIP_REMOVED, user, null, null, null);
                } else {
                    TLRPC.Chat chat = (TLRPC.Chat) object;
                    accountInstance.getMessagesController().deleteParticipantFromChat(currentChat.id, null, chat, null, false, false);
                    getUndoView().showWithAction(0, UndoView.ACTION_VOIP_REMOVED, chat, null, null, null);
                }
            });
        } else if (object instanceof TLRPC.User) {
            TLRPC.User user = (TLRPC.User) object;
            builder.setPositiveButton(LocaleController.getString("VoipGroupAdd", R.string.VoipGroupAdd), (dialogInterface, i) -> {
                BaseFragment fragment = parentActivity.getActionBarLayout().fragmentsStack.get(parentActivity.getActionBarLayout().fragmentsStack.size() - 1);
                accountInstance.getMessagesController().addUserToChat(currentChat.id, user, 0, null, fragment, () -> inviteUserToCall(peerId, false));
            });
        }
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        AlertDialog dialog = builder.create();
        dialog.setBackgroundColor(Theme.getColor(Theme.key_voipgroup_dialogBackground));
        dialog.show();
        if (option == 2) {
            TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_voipgroup_leaveCallMenu));
            }
        }
    } else if (option == 6) {
        parentActivity.switchToAccount(currentAccount, true);
        Bundle args = new Bundle();
        if (peerId > 0) {
            args.putLong("user_id", peerId);
        } else {
            args.putLong("chat_id", -peerId);
        }
        parentActivity.presentFragment(new ChatActivity(args));
        dismiss();
    } else if (option == 8) {
        parentActivity.switchToAccount(currentAccount, true);
        BaseFragment fragment = parentActivity.getActionBarLayout().fragmentsStack.get(parentActivity.getActionBarLayout().fragmentsStack.size() - 1);
        if (fragment instanceof ChatActivity) {
            if (((ChatActivity) fragment).getDialogId() == peerId) {
                dismiss();
                return;
            }
        }
        Bundle args = new Bundle();
        if (peerId > 0) {
            args.putLong("user_id", peerId);
        } else {
            args.putLong("chat_id", -peerId);
        }
        parentActivity.presentFragment(new ChatActivity(args));
        dismiss();
    } else if (option == 7) {
        voIPService.editCallMember(object, true, null, null, false, null);
        updateMuteButton(MUTE_BUTTON_STATE_MUTED_BY_ADMIN, true);
    } else if (option == 9) {
        if (currentAvatarUpdater != null && currentAvatarUpdater.isUploadingImage()) {
            return;
        }
        currentAvatarUpdater = new ImageUpdater(true);
        currentAvatarUpdater.setOpenWithFrontfaceCamera(true);
        currentAvatarUpdater.setForceDarkTheme(true);
        currentAvatarUpdater.setSearchAvailable(true, true);
        currentAvatarUpdater.setShowingFromDialog(true);
        currentAvatarUpdater.parentFragment = parentActivity.getActionBarLayout().getLastFragment();
        currentAvatarUpdater.setDelegate(avatarUpdaterDelegate = new AvatarUpdaterDelegate(peerId));
        TLRPC.User user = accountInstance.getUserConfig().getCurrentUser();
        currentAvatarUpdater.openMenu(user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty), () -> accountInstance.getMessagesController().deleteUserPhoto(null), dialog -> {
        });
    } else if (option == 10) {
        AlertsCreator.createChangeBioAlert(participant.about, peerId, getContext(), currentAccount);
    } else if (option == 11) {
        AlertsCreator.createChangeNameAlert(peerId, getContext(), currentAccount);
    } else {
        if (option == 5) {
            voIPService.editCallMember(object, true, null, null, null, null);
            getUndoView().showWithAction(0, UndoView.ACTION_VOIP_MUTED_FOR_YOU, object);
            voIPService.setParticipantVolume(participant, 0);
        } else {
            if ((participant.flags & 128) != 0 && participant.volume == 0) {
                participant.volume = 10000;
                participant.volume_by_admin = false;
                voIPService.editCallMember(object, false, null, participant.volume, null, null);
            } else {
                voIPService.editCallMember(object, false, null, null, null, null);
            }
            voIPService.setParticipantVolume(participant, ChatObject.getParticipantVolume(participant));
            getUndoView().showWithAction(0, option == 1 ? UndoView.ACTION_VOIP_UNMUTED : UndoView.ACTION_VOIP_UNMUTED_FOR_YOU, object, null, null, null);
        }
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) MediaProjectionManager(android.media.projection.MediaProjectionManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) GroupCallFullscreenAdapter(org.telegram.ui.Components.GroupCallFullscreenAdapter) GroupVoipInviteAlert(org.telegram.ui.Components.GroupVoipInviteAlert) Drawable(android.graphics.drawable.Drawable) RadialGradient(android.graphics.RadialGradient) Property(android.util.Property) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) RadialProgressView(org.telegram.ui.Components.RadialProgressView) Manifest(android.Manifest) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) ProfileGalleryView(org.telegram.ui.Components.ProfileGalleryView) Shader(android.graphics.Shader) Canvas(android.graphics.Canvas) GroupCallStatusIcon(org.telegram.ui.Components.voip.GroupCallStatusIcon) ListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback) UndoView(org.telegram.ui.Components.UndoView) AnimationProperties(org.telegram.ui.Components.AnimationProperties) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) HapticFeedbackConstants(android.view.HapticFeedbackConstants) Nullable(androidx.annotation.Nullable) AUDIO_SERVICE(android.content.Context.AUDIO_SERVICE) HintView(org.telegram.ui.Components.HintView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) GroupCallTextCell(org.telegram.ui.Cells.GroupCallTextCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) PrivateVideoPreviewDialog(org.telegram.ui.Components.voip.PrivateVideoPreviewDialog) TextWatcher(android.text.TextWatcher) GroupCallMiniTextureView(org.telegram.ui.Components.voip.GroupCallMiniTextureView) FileLoader(org.telegram.messenger.FileLoader) GroupCallPip(org.telegram.ui.Components.GroupCallPip) Path(android.graphics.Path) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) SystemClock(android.os.SystemClock) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) Log(com.google.android.exoplayer2.util.Log) TLRPC(org.telegram.tgnet.TLRPC) GradientDrawable(android.graphics.drawable.GradientDrawable) Settings(android.provider.Settings) CellFlickerDrawable(org.telegram.ui.Components.voip.CellFlickerDrawable) ColorFilter(android.graphics.ColorFilter) LongSparseIntArray(org.telegram.messenger.support.LongSparseIntArray) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) LinearGradient(android.graphics.LinearGradient) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) JoinCallAlert(org.telegram.ui.Components.JoinCallAlert) TextUtils(android.text.TextUtils) File(java.io.File) CheckBoxSquare(org.telegram.ui.Components.CheckBoxSquare) Gravity(android.view.Gravity) SparseBooleanArray(android.util.SparseBooleanArray) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) AudioPlayerAlert(org.telegram.ui.Components.AudioPlayerAlert) ValueAnimator(android.animation.ValueAnimator) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) ImageUpdater(org.telegram.ui.Components.ImageUpdater) PackageManager(android.content.pm.PackageManager) BlobDrawable(org.telegram.ui.Components.BlobDrawable) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) ViewConfiguration(android.view.ViewConfiguration) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) Matrix(android.graphics.Matrix) RectF(android.graphics.RectF) ImageLoader(org.telegram.messenger.ImageLoader) Utilities(org.telegram.messenger.Utilities) GroupCallUserCell(org.telegram.ui.Cells.GroupCallUserCell) DiffUtil(androidx.recyclerview.widget.DiffUtil) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) ImageLocation(org.telegram.messenger.ImageLocation) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Instance(org.telegram.messenger.voip.Instance) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) ShareAlert(org.telegram.ui.Components.ShareAlert) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) SparseArray(android.util.SparseArray) TextView(android.widget.TextView) VoIPToggleButton(org.telegram.ui.Components.voip.VoIPToggleButton) EditorInfo(android.view.inputmethod.EditorInfo) GroupCallInvitedCell(org.telegram.ui.Cells.GroupCallInvitedCell) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) GroupCallRenderersContainer(org.telegram.ui.Components.voip.GroupCallRenderersContainer) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) KeyEvent(android.view.KeyEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) VoIPService(org.telegram.messenger.voip.VoIPService) SparseIntArray(android.util.SparseIntArray) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) PixelFormat(android.graphics.PixelFormat) AudioManager(android.media.AudioManager) WaveDrawable(org.telegram.ui.Components.WaveDrawable) GroupCallGridCell(org.telegram.ui.Components.voip.GroupCallGridCell) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) ActionBar(org.telegram.ui.ActionBar.ActionBar) GroupCallRecordAlert(org.telegram.ui.Components.GroupCallRecordAlert) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) Build(android.os.Build) NumberPicker(org.telegram.ui.Components.NumberPicker) DialogInterface(android.content.DialogInterface) LongSparseArray(androidx.collection.LongSparseArray) DialogObject(org.telegram.messenger.DialogObject) BackupImageView(org.telegram.ui.Components.BackupImageView) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) RecordStatusDrawable(org.telegram.ui.Components.RecordStatusDrawable) Bitmap(android.graphics.Bitmap) OvershootInterpolator(android.view.animation.OvershootInterpolator) ViewTreeObserver(android.view.ViewTreeObserver) FillLastGridLayoutManager(org.telegram.ui.Components.FillLastGridLayoutManager) RecyclerListView(org.telegram.ui.Components.RecyclerListView) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) Bundle(android.os.Bundle) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ImageUpdater(org.telegram.ui.Components.ImageUpdater) TLObject(org.telegram.tgnet.TLObject) BackupImageView(org.telegram.ui.Components.BackupImageView) FrameLayout(android.widget.FrameLayout) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) TextView(android.widget.TextView) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) VoIPService(org.telegram.messenger.voip.VoIPService)

Example 49 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupCallActivity method updateItems.

private void updateItems() {
    if (call == null || call.isScheduled()) {
        pipItem.setVisibility(View.INVISIBLE);
        screenShareItem.setVisibility(View.GONE);
        if (call == null) {
            otherItem.setVisibility(View.GONE);
            return;
        }
    }
    if (changingPermissions) {
        return;
    }
    TLRPC.Chat newChat = accountInstance.getMessagesController().getChat(currentChat.id);
    if (newChat != null) {
        currentChat = newChat;
    }
    if (ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_INVITE) || (!ChatObject.isChannel(currentChat) || currentChat.megagroup) && (!TextUtils.isEmpty(currentChat.username) || ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_INVITE)) || ChatObject.isChannel(currentChat) && !currentChat.megagroup && !TextUtils.isEmpty(currentChat.username)) {
        inviteItem.setVisibility(View.VISIBLE);
    } else {
        inviteItem.setVisibility(View.GONE);
    }
    TLRPC.TL_groupCallParticipant participant = call.participants.get(MessageObject.getPeerId(selfPeer));
    if (call == null || call.isScheduled() || participant != null && !participant.can_self_unmute && participant.muted) {
        noiseItem.setVisibility(View.GONE);
    } else {
        noiseItem.setVisibility(View.VISIBLE);
    }
    noiseItem.setIcon(SharedConfig.noiseSupression ? R.drawable.msg_noise_on : R.drawable.msg_noise_off);
    noiseItem.setSubtext(SharedConfig.noiseSupression ? LocaleController.getString("VoipNoiseCancellationEnabled", R.string.VoipNoiseCancellationEnabled) : LocaleController.getString("VoipNoiseCancellationDisabled", R.string.VoipNoiseCancellationDisabled));
    if (ChatObject.canManageCalls(currentChat)) {
        leaveItem.setVisibility(View.VISIBLE);
        editTitleItem.setVisibility(View.VISIBLE);
        if (call.isScheduled()) {
            recordItem.setVisibility(View.GONE);
            screenItem.setVisibility(View.GONE);
        } else {
            recordItem.setVisibility(View.VISIBLE);
        }
        if (!call.canRecordVideo() || call.isScheduled() || Build.VERSION.SDK_INT < 21) {
            screenItem.setVisibility(View.GONE);
        } else {
            screenItem.setVisibility(View.VISIBLE);
        }
        screenShareItem.setVisibility(View.GONE);
        recordCallDrawable.setRecording(call.recording);
        if (call.recording) {
            if (updateCallRecordRunnable == null) {
                AndroidUtilities.runOnUIThread(updateCallRecordRunnable = () -> {
                    updateRecordCallText();
                    AndroidUtilities.runOnUIThread(updateCallRecordRunnable, 1000);
                }, 1000);
            }
            recordItem.setText(LocaleController.getString("VoipGroupStopRecordCall", R.string.VoipGroupStopRecordCall));
        } else {
            if (updateCallRecordRunnable != null) {
                AndroidUtilities.cancelRunOnUIThread(updateCallRecordRunnable);
                updateCallRecordRunnable = null;
            }
            recordItem.setText(LocaleController.getString("VoipGroupRecordCall", R.string.VoipGroupRecordCall));
        }
        if (VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().getVideoState(true) == Instance.VIDEO_STATE_ACTIVE) {
            screenItem.setTextAndIcon(LocaleController.getString("VoipChatStopScreenCapture", R.string.VoipChatStopScreenCapture), R.drawable.msg_screencast_off);
        } else {
            screenItem.setTextAndIcon(LocaleController.getString("VoipChatStartScreenCapture", R.string.VoipChatStartScreenCapture), R.drawable.msg_screencast);
        }
        updateRecordCallText();
    } else {
        boolean mutedByAdmin = participant != null && !participant.can_self_unmute && participant.muted && !ChatObject.canManageCalls(currentChat);
        boolean sharingScreen = VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().getVideoState(true) == Instance.VIDEO_STATE_ACTIVE;
        if (Build.VERSION.SDK_INT >= 21 && !mutedByAdmin && (call.canRecordVideo() || sharingScreen) && !call.isScheduled()) {
            if (sharingScreen) {
                screenShareItem.setVisibility(View.GONE);
                screenItem.setVisibility(View.VISIBLE);
                screenItem.setTextAndIcon(LocaleController.getString("VoipChatStopScreenCapture", R.string.VoipChatStopScreenCapture), R.drawable.msg_screencast_off);
                screenItem.setContentDescription(LocaleController.getString("VoipChatStopScreenCapture", R.string.VoipChatStopScreenCapture));
            } else {
                screenItem.setTextAndIcon(LocaleController.getString("VoipChatStartScreenCapture", R.string.VoipChatStartScreenCapture), R.drawable.msg_screencast);
                screenItem.setContentDescription(LocaleController.getString("VoipChatStartScreenCapture", R.string.VoipChatStartScreenCapture));
                screenShareItem.setVisibility(View.GONE);
                screenItem.setVisibility(View.VISIBLE);
            }
        } else {
            screenShareItem.setVisibility(View.GONE);
            screenItem.setVisibility(View.GONE);
        }
        leaveItem.setVisibility(View.GONE);
        editTitleItem.setVisibility(View.GONE);
        recordItem.setVisibility(View.GONE);
    }
    if (ChatObject.canManageCalls(currentChat) && call.call.can_change_join_muted) {
        permissionItem.setVisibility(View.VISIBLE);
    } else {
        permissionItem.setVisibility(View.GONE);
    }
    soundItem.setVisibility(View.VISIBLE);
    if (editTitleItem.getVisibility() == View.VISIBLE || permissionItem.getVisibility() == View.VISIBLE || inviteItem.getVisibility() == View.VISIBLE || screenItem.getVisibility() == View.VISIBLE || recordItem.getVisibility() == View.VISIBLE || leaveItem.getVisibility() == View.VISIBLE) {
        soundItemDivider.setVisibility(View.VISIBLE);
    } else {
        soundItemDivider.setVisibility(View.GONE);
    }
    int margin = 48;
    if (VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().hasFewPeers || scheduleHasFewPeers) {
        accountSelectCell.setVisibility(View.VISIBLE);
        accountGap.setVisibility(View.VISIBLE);
        long peerId = MessageObject.getPeerId(selfPeer);
        TLObject object;
        if (DialogObject.isUserDialog(peerId)) {
            object = accountInstance.getMessagesController().getUser(peerId);
        } else {
            object = accountInstance.getMessagesController().getChat(-peerId);
        }
        accountSelectCell.setObject(object);
        margin += 48;
    } else {
        margin += 48;
        accountSelectCell.setVisibility(View.GONE);
        accountGap.setVisibility(View.GONE);
    }
    otherItem.setVisibility(View.VISIBLE);
    FrameLayout.LayoutParams layoutParams = ((FrameLayout.LayoutParams) titleTextView.getLayoutParams());
    if (layoutParams.rightMargin != AndroidUtilities.dp(margin)) {
        layoutParams.rightMargin = AndroidUtilities.dp(margin);
        titleTextView.requestLayout();
    }
    ((FrameLayout.LayoutParams) menuItemsContainer.getLayoutParams()).rightMargin = 0;
    actionBar.setTitleRightMargin(AndroidUtilities.dp(48) * 2);
}
Also used : TLObject(org.telegram.tgnet.TLObject) FrameLayout(android.widget.FrameLayout) TLRPC(org.telegram.tgnet.TLRPC) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 50 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class FilteredSearchView method search.

public void search(long dialogId, long minDate, long maxDate, FiltersView.MediaFilterData currentSearchFilter, boolean includeFolder, String query, boolean clearOldResults) {
    String currentSearchFilterQueryString = String.format(Locale.ENGLISH, "%d%d%d%d%s%s", dialogId, minDate, maxDate, currentSearchFilter == null ? -1 : currentSearchFilter.filterType, query, includeFolder);
    boolean filterAndQueryIsSame = lastSearchFilterQueryString != null && lastSearchFilterQueryString.equals(currentSearchFilterQueryString);
    boolean forceClear = !filterAndQueryIsSame && clearOldResults;
    this.currentSearchFilter = currentSearchFilter;
    this.currentSearchDialogId = dialogId;
    this.currentSearchMinDate = minDate;
    this.currentSearchMaxDate = maxDate;
    this.currentSearchString = query;
    this.currentIncludeFolder = includeFolder;
    if (searchRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(searchRunnable);
    }
    AndroidUtilities.cancelRunOnUIThread(clearCurrentResultsRunnable);
    if (filterAndQueryIsSame && clearOldResults) {
        return;
    }
    if (forceClear || currentSearchFilter == null && dialogId == 0 && minDate == 0 && maxDate == 0) {
        messages.clear();
        sections.clear();
        sectionArrays.clear();
        isLoading = true;
        emptyView.setVisibility(View.VISIBLE);
        if (adapter != null) {
            adapter.notifyDataSetChanged();
        }
        requestIndex++;
        firstLoading = true;
        if (recyclerListView.getPinnedHeader() != null) {
            recyclerListView.getPinnedHeader().setAlpha(0);
        }
        localTipChats.clear();
        localTipDates.clear();
        if (!forceClear) {
            return;
        }
    } else if (clearOldResults && !messages.isEmpty()) {
        return;
    }
    isLoading = true;
    if (adapter != null) {
        adapter.notifyDataSetChanged();
    }
    if (!filterAndQueryIsSame) {
        clearCurrentResultsRunnable.run();
        emptyView.showProgress(true, !clearOldResults);
    }
    if (TextUtils.isEmpty(query)) {
        localTipDates.clear();
        localTipChats.clear();
        if (delegate != null) {
            delegate.updateFiltersView(false, null, null, false);
        }
    }
    requestIndex++;
    final int requestId = requestIndex;
    int currentAccount = UserConfig.selectedAccount;
    AndroidUtilities.runOnUIThread(searchRunnable = () -> {
        TLObject request;
        ArrayList<Object> resultArray = null;
        if (dialogId != 0) {
            final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
            req.q = query;
            req.limit = 20;
            req.filter = currentSearchFilter == null ? new TLRPC.TL_inputMessagesFilterEmpty() : currentSearchFilter.filter;
            req.peer = AccountInstance.getInstance(currentAccount).getMessagesController().getInputPeer(dialogId);
            if (minDate > 0) {
                req.min_date = (int) (minDate / 1000);
            }
            if (maxDate > 0) {
                req.max_date = (int) (maxDate / 1000);
            }
            if (filterAndQueryIsSame && query.equals(lastMessagesSearchString) && !messages.isEmpty()) {
                MessageObject lastMessage = messages.get(messages.size() - 1);
                req.offset_id = lastMessage.getId();
            } else {
                req.offset_id = 0;
            }
            request = req;
        } else {
            if (!TextUtils.isEmpty(query)) {
                resultArray = new ArrayList<>();
                ArrayList<CharSequence> resultArrayNames = new ArrayList<>();
                ArrayList<TLRPC.User> encUsers = new ArrayList<>();
                MessagesStorage.getInstance(currentAccount).localSearch(0, query, resultArray, resultArrayNames, encUsers, includeFolder ? 1 : 0);
            }
            final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal();
            req.limit = 20;
            req.q = query;
            req.filter = currentSearchFilter == null ? new TLRPC.TL_inputMessagesFilterEmpty() : currentSearchFilter.filter;
            if (minDate > 0) {
                req.min_date = (int) (minDate / 1000);
            }
            if (maxDate > 0) {
                req.max_date = (int) (maxDate / 1000);
            }
            if (filterAndQueryIsSame && query.equals(lastMessagesSearchString) && !messages.isEmpty()) {
                MessageObject lastMessage = messages.get(messages.size() - 1);
                req.offset_id = lastMessage.getId();
                req.offset_rate = nextSearchRate;
                long id = MessageObject.getPeerId(lastMessage.messageOwner.peer_id);
                req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id);
            } else {
                req.offset_rate = 0;
                req.offset_id = 0;
                req.offset_peer = new TLRPC.TL_inputPeerEmpty();
            }
            req.flags |= 1;
            req.folder_id = includeFolder ? 1 : 0;
            request = req;
        }
        lastMessagesSearchString = query;
        lastSearchFilterQueryString = currentSearchFilterQueryString;
        ArrayList<Object> finalResultArray = resultArray;
        final ArrayList<FiltersView.DateData> dateData = new ArrayList<>();
        FiltersView.fillTipDates(lastMessagesSearchString, dateData);
        ConnectionsManager.getInstance(currentAccount).sendRequest(request, (response, error) -> {
            ArrayList<MessageObject> messageObjects = new ArrayList<>();
            if (error == null) {
                TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                int n = res.messages.size();
                for (int i = 0; i < n; i++) {
                    MessageObject messageObject = new MessageObject(currentAccount, res.messages.get(i), false, true);
                    messageObject.setQuery(query);
                    messageObjects.add(messageObject);
                }
            }
            AndroidUtilities.runOnUIThread(() -> {
                if (requestId != requestIndex) {
                    return;
                }
                isLoading = false;
                if (error != null) {
                    emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
                    emptyView.subtitle.setVisibility(View.VISIBLE);
                    emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
                    emptyView.showProgress(false, true);
                    return;
                }
                emptyView.showProgress(false);
                TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                nextSearchRate = res.next_rate;
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                if (!filterAndQueryIsSame) {
                    messages.clear();
                    messagesById.clear();
                    sections.clear();
                    sectionArrays.clear();
                }
                totalCount = res.count;
                currentDataQuery = query;
                int n = messageObjects.size();
                for (int i = 0; i < n; i++) {
                    MessageObject messageObject = messageObjects.get(i);
                    ArrayList<MessageObject> messageObjectsByDate = sectionArrays.get(messageObject.monthKey);
                    if (messageObjectsByDate == null) {
                        messageObjectsByDate = new ArrayList<>();
                        sectionArrays.put(messageObject.monthKey, messageObjectsByDate);
                        sections.add(messageObject.monthKey);
                    }
                    messageObjectsByDate.add(messageObject);
                    messages.add(messageObject);
                    messagesById.put(messageObject.getId(), messageObject);
                    if (PhotoViewer.getInstance().isVisible()) {
                        PhotoViewer.getInstance().addPhoto(messageObject, photoViewerClassGuid);
                    }
                }
                if (messages.size() > totalCount) {
                    totalCount = messages.size();
                }
                endReached = messages.size() >= totalCount;
                if (messages.isEmpty()) {
                    if (currentSearchFilter != null) {
                        if (TextUtils.isEmpty(currentDataQuery) && dialogId == 0 && minDate == 0) {
                            emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle", R.string.SearchEmptyViewTitle));
                            String str;
                            if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_FILES) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleFiles", R.string.SearchEmptyViewFilteredSubtitleFiles);
                            } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MEDIA) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleMedia", R.string.SearchEmptyViewFilteredSubtitleMedia);
                            } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_LINKS) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleLinks", R.string.SearchEmptyViewFilteredSubtitleLinks);
                            } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MUSIC) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleMusic", R.string.SearchEmptyViewFilteredSubtitleMusic);
                            } else {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleVoice", R.string.SearchEmptyViewFilteredSubtitleVoice);
                            }
                            emptyView.subtitle.setVisibility(View.VISIBLE);
                            emptyView.subtitle.setText(str);
                        } else {
                            emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
                            emptyView.subtitle.setVisibility(View.VISIBLE);
                            emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
                        }
                    } else {
                        emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
                        emptyView.subtitle.setVisibility(View.GONE);
                    }
                }
                if (currentSearchFilter != null) {
                    switch(currentSearchFilter.filterType) {
                        case FiltersView.FILTER_TYPE_MEDIA:
                            if (TextUtils.isEmpty(currentDataQuery)) {
                                adapter = sharedPhotoVideoAdapter;
                            } else {
                                adapter = dialogsAdapter;
                            }
                            break;
                        case FiltersView.FILTER_TYPE_FILES:
                            adapter = sharedDocumentsAdapter;
                            break;
                        case FiltersView.FILTER_TYPE_LINKS:
                            adapter = sharedLinksAdapter;
                            break;
                        case FiltersView.FILTER_TYPE_MUSIC:
                            adapter = sharedAudioAdapter;
                            break;
                        case FiltersView.FILTER_TYPE_VOICE:
                            adapter = sharedVoiceAdapter;
                            break;
                    }
                } else {
                    adapter = dialogsAdapter;
                }
                if (recyclerListView.getAdapter() != adapter) {
                    recyclerListView.setAdapter(adapter);
                }
                if (!filterAndQueryIsSame) {
                    localTipChats.clear();
                    if (finalResultArray != null) {
                        localTipChats.addAll(finalResultArray);
                    }
                    if (query.length() >= 3 && (LocaleController.getString("SavedMessages", R.string.SavedMessages).toLowerCase().startsWith(query) || "saved messages".startsWith(query))) {
                        boolean found = false;
                        for (int i = 0; i < localTipChats.size(); i++) {
                            if (localTipChats.get(i) instanceof TLRPC.User)
                                if (UserConfig.getInstance(UserConfig.selectedAccount).getCurrentUser().id == ((TLRPC.User) localTipChats.get(i)).id) {
                                    found = true;
                                    break;
                                }
                        }
                        if (!found) {
                            localTipChats.add(0, UserConfig.getInstance(UserConfig.selectedAccount).getCurrentUser());
                        }
                    }
                    localTipDates.clear();
                    localTipDates.addAll(dateData);
                    localTipArchive = false;
                    if (query.length() >= 3 && (LocaleController.getString("ArchiveSearchFilter", R.string.ArchiveSearchFilter).toLowerCase().startsWith(query) || "archive".startsWith(query))) {
                        localTipArchive = true;
                    }
                    if (delegate != null) {
                        delegate.updateFiltersView(TextUtils.isEmpty(currentDataQuery), localTipChats, localTipDates, localTipArchive);
                    }
                }
                firstLoading = false;
                View progressView = null;
                int progressViewPosition = -1;
                for (int i = 0; i < n; i++) {
                    View child = recyclerListView.getChildAt(i);
                    if (child instanceof FlickerLoadingView) {
                        progressView = child;
                        progressViewPosition = recyclerListView.getChildAdapterPosition(child);
                    }
                }
                final View finalProgressView = progressView;
                if (progressView != null) {
                    recyclerListView.removeView(progressView);
                }
                if ((loadingView.getVisibility() == View.VISIBLE && recyclerListView.getChildCount() == 0) || (recyclerListView.getAdapter() != sharedPhotoVideoAdapter && progressView != null)) {
                    int finalProgressViewPosition = progressViewPosition;
                    getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                        @Override
                        public boolean onPreDraw() {
                            getViewTreeObserver().removeOnPreDrawListener(this);
                            int n = recyclerListView.getChildCount();
                            AnimatorSet animatorSet = new AnimatorSet();
                            for (int i = 0; i < n; i++) {
                                View child = recyclerListView.getChildAt(i);
                                if (finalProgressView != null) {
                                    if (recyclerListView.getChildAdapterPosition(child) < finalProgressViewPosition) {
                                        continue;
                                    }
                                }
                                child.setAlpha(0);
                                int s = Math.min(recyclerListView.getMeasuredHeight(), Math.max(0, child.getTop()));
                                int delay = (int) ((s / (float) recyclerListView.getMeasuredHeight()) * 100);
                                ObjectAnimator a = ObjectAnimator.ofFloat(child, View.ALPHA, 0, 1f);
                                a.setStartDelay(delay);
                                a.setDuration(200);
                                animatorSet.playTogether(a);
                            }
                            animatorSet.addListener(new AnimatorListenerAdapter() {

                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
                                }
                            });
                            animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
                            animatorSet.start();
                            if (finalProgressView != null && finalProgressView.getParent() == null) {
                                recyclerListView.addView(finalProgressView);
                                RecyclerView.LayoutManager layoutManager = recyclerListView.getLayoutManager();
                                if (layoutManager != null) {
                                    layoutManager.ignoreView(finalProgressView);
                                    Animator animator = ObjectAnimator.ofFloat(finalProgressView, ALPHA, finalProgressView.getAlpha(), 0);
                                    animator.addListener(new AnimatorListenerAdapter() {

                                        @Override
                                        public void onAnimationEnd(Animator animation) {
                                            finalProgressView.setAlpha(1f);
                                            layoutManager.stopIgnoringView(finalProgressView);
                                            recyclerListView.removeView(finalProgressView);
                                        }
                                    });
                                    animator.start();
                                }
                            }
                            return true;
                        }
                    });
                }
                adapter.notifyDataSetChanged();
            });
        });
    }, (filterAndQueryIsSame && !messages.isEmpty()) ? 0 : 350);
    if (currentSearchFilter == null) {
        loadingView.setViewType(FlickerLoadingView.DIALOG_TYPE);
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MEDIA) {
        if (!TextUtils.isEmpty(currentSearchString)) {
            loadingView.setViewType(FlickerLoadingView.DIALOG_TYPE);
        } else {
            loadingView.setViewType(FlickerLoadingView.PHOTOS_TYPE);
        }
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_FILES) {
        loadingView.setViewType(FlickerLoadingView.FILES_TYPE);
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MUSIC || currentSearchFilter.filterType == FiltersView.FILTER_TYPE_VOICE) {
        loadingView.setViewType(FlickerLoadingView.AUDIO_TYPE);
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_LINKS) {
        loadingView.setViewType(FlickerLoadingView.LINKS_TYPE);
    }
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) FiltersView(org.telegram.ui.Adapters.FiltersView) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) ApplicationLoader(org.telegram.messenger.ApplicationLoader) SharedPhotoVideoCell(org.telegram.ui.Cells.SharedPhotoVideoCell) Locale(java.util.Locale) MediaController(org.telegram.messenger.MediaController) View(android.view.View) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) SharedMediaSectionCell(org.telegram.ui.Cells.SharedMediaSectionCell) ObjectAnimator(android.animation.ObjectAnimator) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ChatActionCell(org.telegram.ui.Cells.ChatActionCell) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) Context(android.content.Context) ColoredImageSpan(org.telegram.ui.Components.ColoredImageSpan) Theme(org.telegram.ui.ActionBar.Theme) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) SharedLinkCell(org.telegram.ui.Cells.SharedLinkCell) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) Build(android.os.Build) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) SearchViewPager(org.telegram.ui.Components.SearchViewPager) Browser(org.telegram.messenger.browser.Browser) EmbedBottomSheet(org.telegram.ui.Components.EmbedBottomSheet) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) BackupImageView(org.telegram.ui.Components.BackupImageView) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) SharedAudioCell(org.telegram.ui.Cells.SharedAudioCell) Gravity(android.view.Gravity) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) ImageReceiver(org.telegram.messenger.ImageReceiver) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LoadingCell(org.telegram.ui.Cells.LoadingCell) ArrayList(java.util.ArrayList) FiltersView(org.telegram.ui.Adapters.FiltersView) AnimatorSet(android.animation.AnimatorSet) TLRPC(org.telegram.tgnet.TLRPC) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) ObjectAnimator(android.animation.ObjectAnimator) FiltersView(org.telegram.ui.Adapters.FiltersView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) BackupImageView(org.telegram.ui.Components.BackupImageView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TLObject(org.telegram.tgnet.TLObject) RecyclerView(androidx.recyclerview.widget.RecyclerView) MessageObject(org.telegram.messenger.MessageObject)

Aggregations

TLObject (org.telegram.tgnet.TLObject)85 TLRPC (org.telegram.tgnet.TLRPC)79 Paint (android.graphics.Paint)36 ArrayList (java.util.ArrayList)36 TextPaint (android.text.TextPaint)25 SuppressLint (android.annotation.SuppressLint)22 ConnectionsManager (org.telegram.tgnet.ConnectionsManager)22 File (java.io.File)21 HashMap (java.util.HashMap)20 Context (android.content.Context)19 Build (android.os.Build)19 TextUtils (android.text.TextUtils)19 MessageObject (org.telegram.messenger.MessageObject)19 Theme (org.telegram.ui.ActionBar.Theme)19 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)18 LongSparseArray (androidx.collection.LongSparseArray)17 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)17 Bundle (android.os.Bundle)16 SpannableStringBuilder (android.text.SpannableStringBuilder)16 ChatObject (org.telegram.messenger.ChatObject)16