Search in sources :

Example 6 with RadioColorCell

use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class AlertsCreator method createPopupSelectDialog.

public static Dialog createPopupSelectDialog(Activity parentActivity, final int globalType, final Runnable onSelect) {
    SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
    final int[] selected = new int[1];
    if (globalType == NotificationsController.TYPE_PRIVATE) {
        selected[0] = preferences.getInt("popupAll", 0);
    } else if (globalType == NotificationsController.TYPE_GROUP) {
        selected[0] = preferences.getInt("popupGroup", 0);
    } else {
        selected[0] = preferences.getInt("popupChannel", 0);
    }
    String[] descriptions = new String[] { LocaleController.getString("NoPopup", R.string.NoPopup), LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn), LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff), LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup) };
    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    for (int a = 0; a < descriptions.length; a++) {
        RadioColorCell cell = new RadioColorCell(parentActivity);
        cell.setTag(a);
        cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
        cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
        cell.setTextAndValue(descriptions[a], selected[0] == a);
        linearLayout.addView(cell);
        cell.setOnClickListener(v -> {
            selected[0] = (Integer) v.getTag();
            final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
            SharedPreferences.Editor editor = preferences1.edit();
            if (globalType == NotificationsController.TYPE_PRIVATE) {
                editor.putInt("popupAll", selected[0]);
            } else if (globalType == NotificationsController.TYPE_GROUP) {
                editor.putInt("popupGroup", selected[0]);
            } else {
                editor.putInt("popupChannel", selected[0]);
            }
            editor.commit();
            builder.getDismissRunnable().run();
            if (onSelect != null) {
                onSelect.run();
            }
        });
    }
    builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification));
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder.create();
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SharedPreferences(android.content.SharedPreferences) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 7 with RadioColorCell

use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class DataSettingsActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setTitle(LocaleController.getString("DataSettings", R.string.DataSettings));
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    listView = new RecyclerListView(context);
    listView.setVerticalScrollBarEnabled(false);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position, x, y) -> {
        if (position == mobileRow || position == roamingRow || position == wifiRow) {
            if (LocaleController.isRTL && x <= AndroidUtilities.dp(76) || !LocaleController.isRTL && x >= view.getMeasuredWidth() - AndroidUtilities.dp(76)) {
                boolean wasEnabled = listAdapter.isRowEnabled(resetDownloadRow);
                NotificationsCheckCell cell = (NotificationsCheckCell) view;
                boolean checked = cell.isChecked();
                DownloadController.Preset preset;
                DownloadController.Preset defaultPreset;
                String key;
                String key2;
                int num;
                if (position == mobileRow) {
                    preset = DownloadController.getInstance(currentAccount).mobilePreset;
                    defaultPreset = DownloadController.getInstance(currentAccount).mediumPreset;
                    key = "mobilePreset";
                    key2 = "currentMobilePreset";
                    num = 0;
                } else if (position == wifiRow) {
                    preset = DownloadController.getInstance(currentAccount).wifiPreset;
                    defaultPreset = DownloadController.getInstance(currentAccount).highPreset;
                    key = "wifiPreset";
                    key2 = "currentWifiPreset";
                    num = 1;
                } else {
                    preset = DownloadController.getInstance(currentAccount).roamingPreset;
                    defaultPreset = DownloadController.getInstance(currentAccount).lowPreset;
                    key = "roamingPreset";
                    key2 = "currentRoamingPreset";
                    num = 2;
                }
                if (!checked && preset.enabled) {
                    preset.set(defaultPreset);
                } else {
                    preset.enabled = !preset.enabled;
                }
                SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
                editor.putString(key, preset.toString());
                editor.putInt(key2, 3);
                editor.commit();
                cell.setChecked(!checked);
                RecyclerView.ViewHolder holder = listView.findContainingViewHolder(view);
                if (holder != null) {
                    listAdapter.onBindViewHolder(holder, position);
                }
                DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
                DownloadController.getInstance(currentAccount).savePresetToServer(num);
                if (wasEnabled != listAdapter.isRowEnabled(resetDownloadRow)) {
                    listAdapter.notifyItemChanged(resetDownloadRow);
                }
            } else {
                int type;
                if (position == mobileRow) {
                    type = 0;
                } else if (position == wifiRow) {
                    type = 1;
                } else {
                    type = 2;
                }
                presentFragment(new DataAutoDownloadActivity(type));
            }
        } else if (position == resetDownloadRow) {
            if (getParentActivity() == null || !view.isEnabled()) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("ResetAutomaticMediaDownloadAlertTitle", R.string.ResetAutomaticMediaDownloadAlertTitle));
            builder.setMessage(LocaleController.getString("ResetAutomaticMediaDownloadAlert", R.string.ResetAutomaticMediaDownloadAlert));
            builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
                DownloadController.Preset preset;
                DownloadController.Preset defaultPreset;
                String key;
                SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
                for (int a = 0; a < 3; a++) {
                    if (a == 0) {
                        preset = DownloadController.getInstance(currentAccount).mobilePreset;
                        defaultPreset = DownloadController.getInstance(currentAccount).mediumPreset;
                        key = "mobilePreset";
                    } else if (a == 1) {
                        preset = DownloadController.getInstance(currentAccount).wifiPreset;
                        defaultPreset = DownloadController.getInstance(currentAccount).highPreset;
                        key = "wifiPreset";
                    } else {
                        preset = DownloadController.getInstance(currentAccount).roamingPreset;
                        defaultPreset = DownloadController.getInstance(currentAccount).lowPreset;
                        key = "roamingPreset";
                    }
                    preset.set(defaultPreset);
                    preset.enabled = defaultPreset.isEnabled();
                    editor.putInt("currentMobilePreset", DownloadController.getInstance(currentAccount).currentMobilePreset = 3);
                    editor.putInt("currentWifiPreset", DownloadController.getInstance(currentAccount).currentWifiPreset = 3);
                    editor.putInt("currentRoamingPreset", DownloadController.getInstance(currentAccount).currentRoamingPreset = 3);
                    editor.putString(key, preset.toString());
                }
                editor.commit();
                DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
                for (int a = 0; a < 3; a++) {
                    DownloadController.getInstance(currentAccount).savePresetToServer(a);
                }
                listAdapter.notifyItemRangeChanged(mobileRow, 4);
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog dialog = builder.create();
            showDialog(dialog);
            TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        } else if (position == storageUsageRow) {
            presentFragment(new CacheControlActivity());
        } else if (position == useLessDataForCallsRow) {
            final SharedPreferences preferences = MessagesController.getGlobalMainSettings();
            int selected = 0;
            switch(preferences.getInt("VoipDataSaving", VoIPHelper.getDataSavingDefault())) {
                case Instance.DATA_SAVING_NEVER:
                    selected = 0;
                    break;
                case Instance.DATA_SAVING_ROAMING:
                    selected = 1;
                    break;
                case Instance.DATA_SAVING_MOBILE:
                    selected = 2;
                    break;
                case Instance.DATA_SAVING_ALWAYS:
                    selected = 3;
                    break;
            }
            Dialog dlg = AlertsCreator.createSingleChoiceDialog(getParentActivity(), new String[] { LocaleController.getString("UseLessDataNever", R.string.UseLessDataNever), LocaleController.getString("UseLessDataOnRoaming", R.string.UseLessDataOnRoaming), LocaleController.getString("UseLessDataOnMobile", R.string.UseLessDataOnMobile), LocaleController.getString("UseLessDataAlways", R.string.UseLessDataAlways) }, LocaleController.getString("VoipUseLessData", R.string.VoipUseLessData), selected, (dialog, which) -> {
                int val = -1;
                switch(which) {
                    case 0:
                        val = Instance.DATA_SAVING_NEVER;
                        break;
                    case 1:
                        val = Instance.DATA_SAVING_ROAMING;
                        break;
                    case 2:
                        val = Instance.DATA_SAVING_MOBILE;
                        break;
                    case 3:
                        val = Instance.DATA_SAVING_ALWAYS;
                        break;
                }
                if (val != -1) {
                    preferences.edit().putInt("VoipDataSaving", val).commit();
                }
                if (listAdapter != null) {
                    listAdapter.notifyItemChanged(position);
                }
            });
            setVisibleDialog(dlg);
            dlg.show();
        } else if (position == dataUsageRow) {
            presentFragment(new DataUsageActivity());
        } else if (position == storageNumRow) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("StoragePath", R.string.StoragePath));
            final LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            String dir = storageDirs.get(0).getAbsolutePath();
            if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
                for (int a = 0, N = storageDirs.size(); a < N; a++) {
                    String path = storageDirs.get(a).getAbsolutePath();
                    if (path.startsWith(SharedConfig.storageCacheDir)) {
                        dir = path;
                        break;
                    }
                }
            }
            for (int a = 0, N = storageDirs.size(); a < N; a++) {
                String storageDir = storageDirs.get(a).getAbsolutePath();
                RadioColorCell cell = new RadioColorCell(context);
                cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                cell.setTag(a);
                cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
                cell.setTextAndValue(storageDir, storageDir.startsWith(dir));
                linearLayout.addView(cell);
                cell.setOnClickListener(v -> {
                    SharedConfig.storageCacheDir = storageDir;
                    SharedConfig.saveConfig();
                    ImageLoader.getInstance().checkMediaPaths();
                    builder.getDismissRunnable().run();
                    listAdapter.notifyItemChanged(storageNumRow);
                });
            }
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        } else if (position == proxyRow) {
            presentFragment(new ProxyListActivity());
        } else if (position == enableStreamRow) {
            SharedConfig.toggleStreamMedia();
            TextCheckCell textCheckCell = (TextCheckCell) view;
            textCheckCell.setChecked(SharedConfig.streamMedia);
        } else if (position == enableAllStreamRow) {
            SharedConfig.toggleStreamAllVideo();
            TextCheckCell textCheckCell = (TextCheckCell) view;
            textCheckCell.setChecked(SharedConfig.streamAllVideo);
        } else if (position == enableMkvRow) {
            SharedConfig.toggleStreamMkv();
            TextCheckCell textCheckCell = (TextCheckCell) view;
            textCheckCell.setChecked(SharedConfig.streamMkv);
        } else if (position == enableCacheStreamRow) {
            SharedConfig.toggleSaveStreamMedia();
            TextCheckCell textCheckCell = (TextCheckCell) view;
            textCheckCell.setChecked(SharedConfig.saveStreamMedia);
        } else if (position == quickRepliesRow) {
            presentFragment(new QuickRepliesSettingsActivity());
        } else if (position == autoplayGifsRow) {
            SharedConfig.toggleAutoplayGifs();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.autoplayGifs);
            }
        } else if (position == autoplayVideoRow) {
            SharedConfig.toggleAutoplayVideo();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.autoplayVideo);
            }
        } else if (position == clearDraftsRow) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("AreYouSureClearDraftsTitle", R.string.AreYouSureClearDraftsTitle));
            builder.setMessage(LocaleController.getString("AreYouSureClearDrafts", R.string.AreYouSureClearDrafts));
            builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
                TLRPC.TL_messages_clearAllDrafts req = new TLRPC.TL_messages_clearAllDrafts();
                getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> getMediaDataController().clearAllDrafts(true)));
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        }
    });
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Theme(org.telegram.ui.ActionBar.Theme) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Dialog(android.app.Dialog) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) AlertsCreator(org.telegram.ui.Components.AlertsCreator) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) View(android.view.View) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) RecyclerView(androidx.recyclerview.widget.RecyclerView) Build(android.os.Build) DownloadController(org.telegram.messenger.DownloadController) DialogInterface(android.content.DialogInterface) ImageLoader(org.telegram.messenger.ImageLoader) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) Instance(org.telegram.messenger.voip.Instance) ViewGroup(android.view.ViewGroup) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) Dialog(android.app.Dialog) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) SharedPreferences(android.content.SharedPreferences) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) FrameLayout(android.widget.FrameLayout) DownloadController(org.telegram.messenger.DownloadController) RecyclerView(androidx.recyclerview.widget.RecyclerView) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout)

Example 8 with RadioColorCell

use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class StickersActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setAllowOverlayTitle(true);
    if (currentType == MediaDataController.TYPE_IMAGE) {
        actionBar.setTitle(LocaleController.getString("StickersName", R.string.StickersName));
    } else {
        actionBar.setTitle(LocaleController.getString("Masks", R.string.Masks));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (onBackPressed()) {
                    finishFragment();
                }
            } else if (id == MENU_ARCHIVE || id == MENU_DELETE || id == MENU_SHARE) {
                if (!needReorder) {
                    if (activeReorderingRequests == 0) {
                        listAdapter.processSelectionMenu(id);
                    }
                } else {
                    sendReorder();
                }
            }
        }
    });
    final ActionBarMenu actionMode = actionBar.createActionMode();
    selectedCountTextView = new NumberTextView(actionMode.getContext());
    selectedCountTextView.setTextSize(18);
    selectedCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    selectedCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarActionModeDefaultIcon));
    actionMode.addView(selectedCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 72, 0, 0, 0));
    selectedCountTextView.setOnTouchListener((v, event) -> true);
    shareMenuItem = actionMode.addItemWithWidth(MENU_SHARE, R.drawable.msg_share, AndroidUtilities.dp(54));
    archiveMenuItem = actionMode.addItemWithWidth(MENU_ARCHIVE, R.drawable.msg_archive, AndroidUtilities.dp(54));
    deleteMenuItem = actionMode.addItemWithWidth(MENU_DELETE, R.drawable.msg_delete, AndroidUtilities.dp(54));
    listAdapter = new ListAdapter(context, MediaDataController.getInstance(currentAccount).getStickerSets(currentType));
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    listView.setFocusable(true);
    listView.setTag(7);
    layoutManager = new LinearLayoutManager(context) {

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }

        @Override
        protected void calculateExtraLayoutSpace(@NonNull RecyclerView.State state, @NonNull int[] extraLayoutSpace) {
            extraLayoutSpace[1] = listView.getHeight();
        }
    };
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    listView.setLayoutManager(layoutManager);
    itemTouchHelper = new ItemTouchHelper(new TouchHelperCallback());
    itemTouchHelper.attachToRecyclerView(listView);
    itemAnimator = (DefaultItemAnimator) listView.getItemAnimator();
    itemAnimator.setSupportsChangeAnimations(false);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (position >= stickersStartRow && position < stickersEndRow && getParentActivity() != null) {
            if (!listAdapter.hasSelected()) {
                final TLRPC.TL_messages_stickerSet stickerSet = listAdapter.stickerSets.get(position - stickersStartRow);
                ArrayList<TLRPC.Document> stickers = stickerSet.documents;
                if (stickers == null || stickers.isEmpty()) {
                    return;
                }
                showDialog(new StickersAlert(getParentActivity(), StickersActivity.this, null, stickerSet, null));
            } else {
                listAdapter.toggleSelected(position);
            }
        } else if (position == featuredRow) {
            final TrendingStickersLayout.Delegate trendingDelegate = new TrendingStickersLayout.Delegate() {

                @Override
                public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet, boolean primary) {
                    MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, 2, StickersActivity.this, false, false);
                }

                @Override
                public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
                    MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, 0, StickersActivity.this, false, false);
                }
            };
            trendingStickersAlert = new TrendingStickersAlert(context, this, new TrendingStickersLayout(context, trendingDelegate), null);
            trendingStickersAlert.show();
        } else if (position == archivedRow) {
            presentFragment(new ArchivedStickersActivity(currentType));
        } else if (position == masksRow) {
            presentFragment(new StickersActivity(MediaDataController.TYPE_MASK));
        } else if (position == suggestRow) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("SuggestStickers", R.string.SuggestStickers));
            String[] items = new String[] { LocaleController.getString("SuggestStickersAll", R.string.SuggestStickersAll), LocaleController.getString("SuggestStickersInstalled", R.string.SuggestStickersInstalled), LocaleController.getString("SuggestStickersNone", R.string.SuggestStickersNone) };
            final LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            for (int a = 0; a < items.length; a++) {
                RadioColorCell cell = new RadioColorCell(getParentActivity());
                cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                cell.setTag(a);
                cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
                cell.setTextAndValue(items[a], SharedConfig.suggestStickers == a);
                linearLayout.addView(cell);
                cell.setOnClickListener(v -> {
                    Integer which = (Integer) v.getTag();
                    SharedConfig.setSuggestStickers(which);
                    listAdapter.notifyItemChanged(suggestRow);
                    builder.getDismissRunnable().run();
                });
            }
            showDialog(builder.create());
        } else if (position == loopRow) {
            SharedConfig.toggleLoopStickers();
            listAdapter.notifyItemChanged(loopRow, ListAdapter.UPDATE_LOOP_STICKERS);
        }
    });
    listView.setOnItemLongClickListener((view, position) -> {
        if (!listAdapter.hasSelected() && position >= stickersStartRow && position < stickersEndRow) {
            listAdapter.toggleSelected(position);
            return true;
        } else {
            return false;
        }
    });
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) NumberTextView(org.telegram.ui.Components.NumberTextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) TrendingStickersLayout(org.telegram.ui.Components.TrendingStickersLayout) TrendingStickersAlert(org.telegram.ui.Components.TrendingStickersAlert) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) SuppressLint(android.annotation.SuppressLint) StickersAlert(org.telegram.ui.Components.StickersAlert) TrendingStickersAlert(org.telegram.ui.Components.TrendingStickersAlert) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout)

Example 9 with RadioColorCell

use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class SessionsActivity method createView.

@Override
public View createView(Context context) {
    globalFlickerLoadingView = new FlickerLoadingView(context);
    globalFlickerLoadingView.setIsSingleCell(true);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (currentType == 0) {
        actionBar.setTitle(LocaleController.getString("Devices", R.string.Devices));
    } else {
        actionBar.setTitle(LocaleController.getString("WebSessionsTitle", R.string.WebSessionsTitle));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    emptyLayout = new LinearLayout(context);
    emptyLayout.setOrientation(LinearLayout.VERTICAL);
    emptyLayout.setGravity(Gravity.CENTER);
    emptyLayout.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()));
    imageView = new ImageView(context);
    if (currentType == 0) {
        imageView.setImageResource(R.drawable.devices);
    } else {
        imageView.setImageResource(R.drawable.no_apps);
    }
    imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_sessions_devicesImage), PorterDuff.Mode.MULTIPLY));
    emptyLayout.addView(imageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
    textView1 = new TextView(context);
    textView1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
    textView1.setGravity(Gravity.CENTER);
    textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    textView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    if (currentType == 0) {
        textView1.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions));
    } else {
        textView1.setText(LocaleController.getString("NoOtherWebSessions", R.string.NoOtherWebSessions));
    }
    emptyLayout.addView(textView1, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 16, 0, 0));
    textView2 = new TextView(context);
    textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
    textView2.setGravity(Gravity.CENTER);
    textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    textView2.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
    if (currentType == 0) {
        textView2.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo));
    } else {
        textView2.setText(LocaleController.getString("NoOtherWebSessionsInfo", R.string.NoOtherWebSessionsInfo));
    }
    emptyLayout.addView(textView2, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 14, 0, 0));
    emptyView = new EmptyTextProgressView(context);
    emptyView.showProgress();
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
    listView = new RecyclerListView(context);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setVerticalScrollBarEnabled(false);
    listView.setEmptyView(emptyView);
    listView.setAnimateEmptyView(true, 0);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (position == ttlRow) {
            if (getParentActivity() == null) {
                return;
            }
            int selected;
            if (ttlDays <= 7) {
                selected = 0;
            } else if (ttlDays <= 93) {
                selected = 1;
            } else if (ttlDays <= 183) {
                selected = 2;
            } else {
                selected = 3;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("SessionsSelfDestruct", R.string.SessionsSelfDestruct));
            String[] items = new String[] { LocaleController.formatPluralString("Weeks", 1), LocaleController.formatPluralString("Months", 3), LocaleController.formatPluralString("Months", 6), LocaleController.formatPluralString("Years", 1) };
            final LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            for (int a = 0; a < items.length; a++) {
                RadioColorCell cell = new RadioColorCell(getParentActivity());
                cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                cell.setTag(a);
                cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
                cell.setTextAndValue(items[a], selected == a);
                linearLayout.addView(cell);
                cell.setOnClickListener(v -> {
                    builder.getDismissRunnable().run();
                    Integer which = (Integer) v.getTag();
                    int value = 0;
                    if (which == 0) {
                        value = 7;
                    } else if (which == 1) {
                        value = 90;
                    } else if (which == 2) {
                        value = 183;
                    } else if (which == 3) {
                        value = 365;
                    }
                    final TLRPC.TL_account_setAuthorizationTTL req = new TLRPC.TL_account_setAuthorizationTTL();
                    req.authorization_ttl_days = value;
                    ttlDays = value;
                    if (listAdapter != null) {
                        listAdapter.notifyDataSetChanged();
                    }
                    getConnectionsManager().sendRequest(req, (response, error) -> {
                    });
                });
            }
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        } else if (position == terminateAllSessionsRow) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            String buttonText;
            if (currentType == 0) {
                builder.setMessage(LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions));
                builder.setTitle(LocaleController.getString("AreYouSureSessionsTitle", R.string.AreYouSureSessionsTitle));
                buttonText = LocaleController.getString("Terminate", R.string.Terminate);
            } else {
                builder.setMessage(LocaleController.getString("AreYouSureWebSessions", R.string.AreYouSureWebSessions));
                builder.setTitle(LocaleController.getString("TerminateWebSessionsTitle", R.string.TerminateWebSessionsTitle));
                buttonText = LocaleController.getString("Disconnect", R.string.Disconnect);
            }
            builder.setPositiveButton(buttonText, (dialogInterface, i) -> {
                if (currentType == 0) {
                    TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
                        AndroidUtilities.runOnUIThread(() -> {
                            if (getParentActivity() == null) {
                                return;
                            }
                            if (error == null && response instanceof TLRPC.TL_boolTrue) {
                                Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT);
                                toast.show();
                                finishFragment();
                            }
                        });
                        for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
                            UserConfig userConfig = UserConfig.getInstance(a);
                            if (!userConfig.isClientActivated()) {
                                continue;
                            }
                            userConfig.registeredForPush = false;
                            userConfig.saveConfig(false);
                            MessagesController.getInstance(a).registerForPush(SharedConfig.pushString);
                            ConnectionsManager.getInstance(a).setUserId(userConfig.getClientUserId());
                        }
                    });
                } else {
                    TLRPC.TL_account_resetWebAuthorizations req = new TLRPC.TL_account_resetWebAuthorizations();
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        if (getParentActivity() == null) {
                            return;
                        }
                        if (error == null && response instanceof TLRPC.TL_boolTrue) {
                            Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllWebSessions", R.string.TerminateAllWebSessions), Toast.LENGTH_SHORT);
                            toast.show();
                        } else {
                            Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT);
                            toast.show();
                        }
                        finishFragment();
                    }));
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        } else if (position >= otherSessionsStartRow && position < otherSessionsEndRow || position >= passwordSessionsStartRow && position < passwordSessionsEndRow || position == currentSessionRow) {
            if (getParentActivity() == null) {
                return;
            }
            if (currentType == 0) {
                final TLRPC.TL_authorization authorization;
                boolean isCurrentSession = false;
                if (position == currentSessionRow) {
                    authorization = currentSession;
                    isCurrentSession = true;
                } else if (position >= otherSessionsStartRow && position < otherSessionsEndRow) {
                    authorization = (TLRPC.TL_authorization) sessions.get(position - otherSessionsStartRow);
                } else {
                    authorization = (TLRPC.TL_authorization) passwordSessions.get(position - passwordSessionsStartRow);
                }
                showSessionBottomSheet(authorization, isCurrentSession);
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            final boolean[] param = new boolean[1];
            String buttonText;
            if (currentType == 0) {
                builder.setMessage(LocaleController.getString("TerminateSessionText", R.string.TerminateSessionText));
                builder.setTitle(LocaleController.getString("AreYouSureSessionTitle", R.string.AreYouSureSessionTitle));
                buttonText = LocaleController.getString("Terminate", R.string.Terminate);
            } else {
                final TLRPC.TL_webAuthorization authorization = (TLRPC.TL_webAuthorization) sessions.get(position - otherSessionsStartRow);
                builder.setMessage(LocaleController.formatString("TerminateWebSessionText", R.string.TerminateWebSessionText, authorization.domain));
                builder.setTitle(LocaleController.getString("TerminateWebSessionTitle", R.string.TerminateWebSessionTitle));
                buttonText = LocaleController.getString("Disconnect", R.string.Disconnect);
                FrameLayout frameLayout1 = new FrameLayout(getParentActivity());
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(authorization.bot_id);
                String name;
                if (user != null) {
                    name = UserObject.getFirstName(user);
                } else {
                    name = "";
                }
                CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1);
                cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                cell.setText(LocaleController.formatString("TerminateWebSessionStop", R.string.TerminateWebSessionStop, name), "", false, false);
                cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
                frameLayout1.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
                cell.setOnClickListener(v -> {
                    if (!v.isEnabled()) {
                        return;
                    }
                    CheckBoxCell cell1 = (CheckBoxCell) v;
                    param[0] = !param[0];
                    cell1.setChecked(param[0], true);
                });
                builder.setCustomViewOffset(16);
                builder.setView(frameLayout1);
            }
            builder.setPositiveButton(buttonText, (dialogInterface, option) -> {
                if (getParentActivity() == null) {
                    return;
                }
                final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
                progressDialog.setCanCacnel(false);
                progressDialog.show();
                if (currentType == 0) {
                    final TLRPC.TL_authorization authorization;
                    if (position >= otherSessionsStartRow && position < otherSessionsEndRow) {
                        authorization = (TLRPC.TL_authorization) sessions.get(position - otherSessionsStartRow);
                    } else {
                        authorization = (TLRPC.TL_authorization) passwordSessions.get(position - passwordSessionsStartRow);
                    }
                    TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization();
                    req.hash = authorization.hash;
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        if (error == null) {
                            sessions.remove(authorization);
                            passwordSessions.remove(authorization);
                            updateRows();
                            if (listAdapter != null) {
                                listAdapter.notifyDataSetChanged();
                            }
                        }
                    }));
                } else {
                    final TLRPC.TL_webAuthorization authorization = (TLRPC.TL_webAuthorization) sessions.get(position - otherSessionsStartRow);
                    TLRPC.TL_account_resetWebAuthorization req = new TLRPC.TL_account_resetWebAuthorization();
                    req.hash = authorization.hash;
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        if (error == null) {
                            sessions.remove(authorization);
                            updateRows();
                            if (listAdapter != null) {
                                listAdapter.notifyDataSetChanged();
                            }
                        }
                    }));
                    if (param[0]) {
                        MessagesController.getInstance(currentAccount).blockPeer(authorization.bot_id);
                    }
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        }
    });
    if (currentType == 0) {
        undoView = new UndoView(context) {

            @Override
            public void hide(boolean apply, int animated) {
                if (!apply) {
                    TLRPC.TL_authorization authorization = (TLRPC.TL_authorization) getCurrentInfoObject();
                    TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization();
                    req.hash = authorization.hash;
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        if (error == null) {
                            sessions.remove(authorization);
                            passwordSessions.remove(authorization);
                            updateRows();
                            if (listAdapter != null) {
                                listAdapter.notifyDataSetChanged();
                            }
                            loadSessions(true);
                        }
                    }));
                }
                super.hide(apply, animated);
            }
        };
        frameLayout.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
    }
    itemsEnterAnimator = new RecyclerItemsEnterAnimator(listView, true) {

        @Override
        public View getProgressView() {
            View progressView = null;
            for (int i = 0; i < listView.getChildCount(); i++) {
                View child = listView.getChildAt(i);
                if (listView.getChildAdapterPosition(child) >= 0 && child instanceof SessionCell && ((SessionCell) child).isStub()) {
                    progressView = child;
                }
            }
            return progressView;
        }
    };
    itemsEnterAnimator.animateAlphaProgressView = false;
    updateRows();
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) LinearLayout(android.widget.LinearLayout) SvgHelper(org.telegram.messenger.SvgHelper) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) Manifest(android.Manifest) ApplicationLoader(org.telegram.messenger.ApplicationLoader) SessionCell(org.telegram.ui.Cells.SessionCell) TextCell(org.telegram.ui.Cells.TextCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) DocumentObject(org.telegram.messenger.DocumentObject) SlideChooseView(org.telegram.ui.Components.SlideChooseView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ImageLocation(org.telegram.messenger.ImageLocation) UndoView(org.telegram.ui.Components.UndoView) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) RecyclerItemsEnterAnimator(org.telegram.ui.Components.RecyclerItemsEnterAnimator) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Context(android.content.Context) Spanned(android.text.Spanned) ImageSpan(android.text.style.ImageSpan) ColoredImageSpan(org.telegram.ui.Components.ColoredImageSpan) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) URLSpanNoUnderline(org.telegram.ui.Components.URLSpanNoUnderline) AlertsCreator(org.telegram.ui.Components.AlertsCreator) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) SharedConfig(org.telegram.messenger.SharedConfig) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) DialogInterface(android.content.DialogInterface) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) R(org.telegram.messenger.R) ReplaceableIconDrawable(org.telegram.ui.Components.ReplaceableIconDrawable) BackupImageView(org.telegram.ui.Components.BackupImageView) AbsListView(android.widget.AbsListView) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) Base64(android.util.Base64) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) RecyclerListView(org.telegram.ui.Components.RecyclerListView) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) TextView(android.widget.TextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) AbsListView(android.widget.AbsListView) UserConfig(org.telegram.messenger.UserConfig) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) RecyclerItemsEnterAnimator(org.telegram.ui.Components.RecyclerItemsEnterAnimator) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) UndoView(org.telegram.ui.Components.UndoView) Toast(android.widget.Toast) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SlideChooseView(org.telegram.ui.Components.SlideChooseView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) UndoView(org.telegram.ui.Components.UndoView) TextView(android.widget.TextView) BackupImageView(org.telegram.ui.Components.BackupImageView) AbsListView(android.widget.AbsListView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) SessionCell(org.telegram.ui.Cells.SessionCell) FrameLayout(android.widget.FrameLayout) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout)

Example 10 with RadioColorCell

use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class PrivacySettingsActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("PrivacySettings", R.string.PrivacySettings));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    });
    listView.setVerticalScrollBarEnabled(false);
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (!view.isEnabled()) {
            return;
        }
        if (position == blockedRow) {
            presentFragment(new PrivacyUsersActivity());
        } else if (position == sessionsRow) {
            presentFragment(new SessionsActivity(0));
        } else if (position == webSessionsRow) {
            presentFragment(new SessionsActivity(1));
        } else if (position == deleteAccountRow) {
            if (getParentActivity() == null) {
                return;
            }
            int ttl = getContactsController().getDeleteAccountTTL();
            int selected;
            if (ttl <= 31) {
                selected = 0;
            } else if (ttl <= 93) {
                selected = 1;
            } else if (ttl <= 182) {
                selected = 2;
            } else {
                selected = 3;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("DeleteAccountTitle", R.string.DeleteAccountTitle));
            String[] items = new String[] { LocaleController.formatPluralString("Months", 1), LocaleController.formatPluralString("Months", 3), LocaleController.formatPluralString("Months", 6), LocaleController.formatPluralString("Years", 1) };
            final LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            for (int a = 0; a < items.length; a++) {
                RadioColorCell cell = new RadioColorCell(getParentActivity());
                cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                cell.setTag(a);
                cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
                cell.setTextAndValue(items[a], selected == a);
                linearLayout.addView(cell);
                cell.setOnClickListener(v -> {
                    builder.getDismissRunnable().run();
                    Integer which = (Integer) v.getTag();
                    int value = 0;
                    if (which == 0) {
                        value = 30;
                    } else if (which == 1) {
                        value = 90;
                    } else if (which == 2) {
                        value = 182;
                    } else if (which == 3) {
                        value = 365;
                    }
                    final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
                    progressDialog.setCanCacnel(false);
                    progressDialog.show();
                    final TLRPC.TL_account_setAccountTTL req = new TLRPC.TL_account_setAccountTTL();
                    req.ttl = new TLRPC.TL_accountDaysTTL();
                    req.ttl.days = value;
                    getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        if (response instanceof TLRPC.TL_boolTrue) {
                            getContactsController().setDeleteAccountTTL(req.ttl.days);
                            listAdapter.notifyDataSetChanged();
                        }
                    }));
                });
            }
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        } else if (position == lastSeenRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_LASTSEEN));
        } else if (position == phoneNumberRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_PHONE));
        } else if (position == groupsRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_INVITE));
        } else if (position == callsRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_CALLS));
        } else if (position == profilePhotoRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_PHOTO));
        } else if (position == forwardsRow) {
            presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_FORWARDS));
        } else if (position == passwordRow) {
            if (currentPassword == null) {
                return;
            }
            if (!TwoStepVerificationActivity.canHandleCurrentPassword(currentPassword, false)) {
                AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
            }
            if (currentPassword.has_password) {
                TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
                fragment.setPassword(currentPassword);
                presentFragment(fragment);
            } else {
                int type;
                if (TextUtils.isEmpty(currentPassword.email_unconfirmed_pattern)) {
                    type = TwoStepVerificationSetupActivity.TYPE_INTRO;
                } else {
                    type = TwoStepVerificationSetupActivity.TYPE_EMAIL_CONFIRM;
                }
                presentFragment(new TwoStepVerificationSetupActivity(type, currentPassword));
            }
        } else if (position == passcodeRow) {
            if (SharedConfig.passcodeHash.length() > 0) {
                presentFragment(new PasscodeActivity(2));
            } else {
                presentFragment(new PasscodeActivity(0));
            }
        } else if (position == secretWebpageRow) {
            if (getMessagesController().secretWebpagePreview == 1) {
                getMessagesController().secretWebpagePreview = 0;
            } else {
                getMessagesController().secretWebpagePreview = 1;
            }
            MessagesController.getGlobalMainSettings().edit().putInt("secretWebpage2", getMessagesController().secretWebpagePreview).commit();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(getMessagesController().secretWebpagePreview == 1);
            }
        } else if (position == contactsDeleteRow) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("SyncContactsDeleteTitle", R.string.SyncContactsDeleteTitle));
            builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("SyncContactsDeleteText", R.string.SyncContactsDeleteText)));
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
                AlertDialog.Builder builder12 = new AlertDialog.Builder(getParentActivity(), 3, null);
                progressDialog = builder12.show();
                progressDialog.setCanCacnel(false);
                if (currentSync != newSync) {
                    currentSync = getUserConfig().syncContacts = newSync;
                    getUserConfig().saveConfig(false);
                }
                getContactsController().deleteAllContacts(() -> progressDialog.dismiss());
            });
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        } else if (position == contactsSuggestRow) {
            final TextCheckCell cell = (TextCheckCell) view;
            if (newSuggest) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("SuggestContactsTitle", R.string.SuggestContactsTitle));
                builder.setMessage(LocaleController.getString("SuggestContactsAlert", R.string.SuggestContactsAlert));
                builder.setPositiveButton(LocaleController.getString("MuteDisable", R.string.MuteDisable), (dialogInterface, i) -> {
                    TLRPC.TL_payments_clearSavedInfo req = new TLRPC.TL_payments_clearSavedInfo();
                    req.credentials = clear[1];
                    req.info = clear[0];
                    getUserConfig().tmpPassword = null;
                    getUserConfig().saveConfig(false);
                    getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        newSuggest = !newSuggest;
                        cell.setChecked(newSuggest);
                    }));
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                AlertDialog alertDialog = builder.create();
                showDialog(alertDialog);
                TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
            } else {
                cell.setChecked(newSuggest = true);
            }
        } else if (position == newChatsRow) {
            final TextCheckCell cell = (TextCheckCell) view;
            archiveChats = !archiveChats;
            cell.setChecked(archiveChats);
        } else if (position == contactsSyncRow) {
            newSync = !newSync;
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(newSync);
            }
        } else if (position == secretMapRow) {
            AlertsCreator.showSecretLocationAlert(getParentActivity(), currentAccount, () -> listAdapter.notifyDataSetChanged(), false, null);
        } else if (position == paymentsClearRow) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("PrivacyPaymentsClearAlertTitle", R.string.PrivacyPaymentsClearAlertTitle));
            builder.setMessage(LocaleController.getString("PrivacyPaymentsClearAlertText", R.string.PrivacyPaymentsClearAlertText));
            LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            for (int a = 0; a < 2; a++) {
                String name;
                if (a == 0) {
                    name = LocaleController.getString("PrivacyClearShipping", R.string.PrivacyClearShipping);
                } else {
                    name = LocaleController.getString("PrivacyClearPayment", R.string.PrivacyClearPayment);
                }
                clear[a] = true;
                CheckBoxCell checkBoxCell = new CheckBoxCell(getParentActivity(), 1, 21, null);
                checkBoxCell.setTag(a);
                checkBoxCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                checkBoxCell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                checkBoxCell.setText(name, null, true, false);
                checkBoxCell.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
                checkBoxCell.setOnClickListener(v -> {
                    CheckBoxCell cell = (CheckBoxCell) v;
                    int num = (Integer) cell.getTag();
                    clear[num] = !clear[num];
                    cell.setChecked(clear[num], true);
                });
            }
            builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton), (dialogInterface, i) -> {
                try {
                    if (visibleDialog != null) {
                        visibleDialog.dismiss();
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
                AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity());
                builder1.setTitle(LocaleController.getString("PrivacyPaymentsClearAlertTitle", R.string.PrivacyPaymentsClearAlertTitle));
                builder1.setMessage(LocaleController.getString("PrivacyPaymentsClearAlert", R.string.PrivacyPaymentsClearAlert));
                builder1.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton), (dialogInterface2, i2) -> {
                    TLRPC.TL_payments_clearSavedInfo req = new TLRPC.TL_payments_clearSavedInfo();
                    req.credentials = clear[1];
                    req.info = clear[0];
                    getUserConfig().tmpPassword = null;
                    getUserConfig().saveConfig(false);
                    getConnectionsManager().sendRequest(req, (response, error) -> {
                    });
                    String text;
                    if (clear[0] && clear[1]) {
                        text = LocaleController.getString("PrivacyPaymentsPaymentShippingCleared", R.string.PrivacyPaymentsPaymentShippingCleared);
                    } else if (clear[0]) {
                        text = LocaleController.getString("PrivacyPaymentsShippingInfoCleared", R.string.PrivacyPaymentsShippingInfoCleared);
                    } else if (clear[1]) {
                        text = LocaleController.getString("PrivacyPaymentsPaymentInfoCleared", R.string.PrivacyPaymentsPaymentInfoCleared);
                    } else {
                        return;
                    }
                    BulletinFactory.of(PrivacySettingsActivity.this).createSimpleBulletin(R.raw.chats_infotip, text).show();
                });
                builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder1.create());
                AlertDialog alertDialog = builder1.create();
                showDialog(alertDialog);
                TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        } else if (position == passportRow) {
            presentFragment(new PassportActivity(PassportActivity.TYPE_PASSWORD, 0, "", "", null, null, null, null, null));
        }
    });
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Theme(org.telegram.ui.ActionBar.Theme) FrameLayout(android.widget.FrameLayout) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) BulletinFactory(org.telegram.ui.Components.BulletinFactory) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) AlertsCreator(org.telegram.ui.Components.AlertsCreator) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) ActionBar(org.telegram.ui.ActionBar.ActionBar) View(android.view.View) SharedConfig(org.telegram.messenger.SharedConfig) RecyclerView(androidx.recyclerview.widget.RecyclerView) DialogInterface(android.content.DialogInterface) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) MessagesController(org.telegram.messenger.MessagesController) NotificationCenter(org.telegram.messenger.NotificationCenter) TextView(android.widget.TextView) ContactsController(org.telegram.messenger.ContactsController) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) FrameLayout(android.widget.FrameLayout) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout)

Aggregations

LinearLayout (android.widget.LinearLayout)12 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)12 RadioColorCell (org.telegram.ui.Cells.RadioColorCell)12 SpannableStringBuilder (android.text.SpannableStringBuilder)10 SuppressLint (android.annotation.SuppressLint)9 SpannableString (android.text.SpannableString)7 SharedPreferences (android.content.SharedPreferences)6 View (android.view.View)5 TextView (android.widget.TextView)5 FrameLayout (android.widget.FrameLayout)4 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 ArrayList (java.util.ArrayList)4 TLRPC (org.telegram.tgnet.TLRPC)4 ActionBar (org.telegram.ui.ActionBar.ActionBar)4 RecyclerListView (org.telegram.ui.Components.RecyclerListView)4 Context (android.content.Context)3 DialogInterface (android.content.DialogInterface)3 ViewGroup (android.view.ViewGroup)3 AndroidUtilities (org.telegram.messenger.AndroidUtilities)3