Search in sources :

Example 1 with TextCheckBoxCell

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

the class ProfileNotificationsActivity method createView.

@Override
public View createView(final Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (!addingException && notificationsEnabled && customEnabled) {
                    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                    preferences.edit().putInt("notify2_" + dialogId, 0).commit();
                }
            } else if (id == done_button) {
                SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean("custom_" + dialogId, true);
                TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(dialogId);
                if (notificationsEnabled) {
                    editor.putInt("notify2_" + dialogId, 0);
                    MessagesStorage.getInstance(currentAccount).setDialogFlags(dialogId, 0);
                    if (dialog != null) {
                        dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                    }
                } else {
                    editor.putInt("notify2_" + dialogId, 2);
                    NotificationsController.getInstance(currentAccount).removeNotificationsForDialog(dialogId);
                    MessagesStorage.getInstance(currentAccount).setDialogFlags(dialogId, 1);
                    if (dialog != null) {
                        dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                        dialog.notify_settings.mute_until = Integer.MAX_VALUE;
                    }
                }
                editor.commit();
                NotificationsController.getInstance(currentAccount).updateServerNotificationsSettings(dialogId);
                if (delegate != null) {
                    NotificationsSettingsActivity.NotificationException exception = new NotificationsSettingsActivity.NotificationException();
                    exception.did = dialogId;
                    exception.hasCustom = true;
                    exception.notify = preferences.getInt("notify2_" + dialogId, 0);
                    if (exception.notify != 0) {
                        exception.muteUntil = preferences.getInt("notifyuntil_" + dialogId, 0);
                    }
                    delegate.didCreateNewException(exception);
                }
            }
            finishFragment();
        }
    });
    if (addingException) {
        actionBar.setTitle(LocaleController.getString("NotificationsNewException", R.string.NotificationsNewException));
        actionBar.createMenu().addItem(done_button, LocaleController.getString("Done", R.string.Done).toUpperCase());
    } else {
        actionBar.setTitle(LocaleController.getString("CustomNotifications", R.string.CustomNotifications));
    }
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(adapter = new ListAdapter(context));
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    listView.setLayoutManager(new LinearLayoutManager(context) {

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    });
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            if (position == customRow && view instanceof TextCheckBoxCell) {
                SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                customEnabled = !customEnabled;
                notificationsEnabled = customEnabled;
                preferences.edit().putBoolean("custom_" + dialogId, customEnabled).commit();
                TextCheckBoxCell cell = (TextCheckBoxCell) view;
                cell.setChecked(customEnabled);
                checkRowsEnabled();
            } else if (customEnabled) {
                if (!view.isEnabled()) {
                    return;
                }
                if (position == soundRow) {
                    try {
                        Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                        Uri currentSound = null;
                        String defaultPath = null;
                        Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                        if (defaultUri != null) {
                            defaultPath = defaultUri.getPath();
                        }
                        String path = preferences.getString("sound_path_" + dialogId, defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                        startActivityForResult(tmpIntent, 12);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                } else if (position == ringtoneRow) {
                    try {
                        Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
                        SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                        Uri currentSound = null;
                        String defaultPath = null;
                        Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                        if (defaultUri != null) {
                            defaultPath = defaultUri.getPath();
                        }
                        String path = preferences.getString("ringtone_path_" + dialogId, defaultPath);
                        if (path != null && !path.equals("NoSound")) {
                            if (path.equals(defaultPath)) {
                                currentSound = defaultUri;
                            } else {
                                currentSound = Uri.parse(path);
                            }
                        }
                        tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                        startActivityForResult(tmpIntent, 13);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                } else if (position == vibrateRow) {
                    showDialog(AlertsCreator.createVibrationSelectDialog(getParentActivity(), dialogId, false, false, () -> {
                        if (adapter != null) {
                            adapter.notifyItemChanged(vibrateRow);
                        }
                    }));
                } else if (position == enableRow) {
                    TextCheckCell checkCell = (TextCheckCell) view;
                    notificationsEnabled = !checkCell.isChecked();
                    checkCell.setChecked(notificationsEnabled);
                    checkRowsEnabled();
                } else if (position == previewRow) {
                    TextCheckCell checkCell = (TextCheckCell) view;
                    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                    preferences.edit().putBoolean("content_preview_" + dialogId, !checkCell.isChecked()).commit();
                    checkCell.setChecked(!checkCell.isChecked());
                } else if (position == callsVibrateRow) {
                    showDialog(AlertsCreator.createVibrationSelectDialog(getParentActivity(), dialogId, "calls_vibrate_" + dialogId, () -> {
                        if (adapter != null) {
                            adapter.notifyItemChanged(callsVibrateRow);
                        }
                    }));
                } else if (position == priorityRow) {
                    showDialog(AlertsCreator.createPrioritySelectDialog(getParentActivity(), dialogId, -1, () -> {
                        if (adapter != null) {
                            adapter.notifyItemChanged(priorityRow);
                        }
                    }));
                } else if (position == smartRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    final Context context1 = getParentActivity();
                    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                    int notifyMaxCount = preferences.getInt("smart_max_count_" + dialogId, 2);
                    int notifyDelay = preferences.getInt("smart_delay_" + dialogId, 3 * 60);
                    if (notifyMaxCount == 0) {
                        notifyMaxCount = 2;
                    }
                    final int selected = (notifyDelay / 60 - 1) * 10 + notifyMaxCount - 1;
                    RecyclerListView list = new RecyclerListView(getParentActivity());
                    list.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
                    list.setClipToPadding(true);
                    list.setAdapter(new RecyclerListView.SelectionAdapter() {

                        @Override
                        public int getItemCount() {
                            return 100;
                        }

                        @Override
                        public boolean isEnabled(RecyclerView.ViewHolder holder) {
                            return true;
                        }

                        @Override
                        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                            TextView textView = new TextView(context1) {

                                @Override
                                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                                    super.onMeasure(MeasureSpec.makeMeasureSpec(widthMeasureSpec, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), MeasureSpec.EXACTLY));
                                }
                            };
                            textView.setGravity(Gravity.CENTER);
                            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                            textView.setSingleLine(true);
                            textView.setEllipsize(TextUtils.TruncateAt.END);
                            textView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                            return new RecyclerListView.Holder(textView);
                        }

                        @Override
                        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
                            TextView textView = (TextView) holder.itemView;
                            textView.setTextColor(Theme.getColor(position == selected ? Theme.key_dialogTextGray : Theme.key_dialogTextBlack));
                            int notifyMaxCount = position % 10;
                            int notifyDelay = position / 10;
                            String times = LocaleController.formatPluralString("Times", notifyMaxCount + 1);
                            String minutes = LocaleController.formatPluralString("Minutes", notifyDelay + 1);
                            textView.setText(LocaleController.formatString("SmartNotificationsDetail", R.string.SmartNotificationsDetail, times, minutes));
                        }
                    });
                    list.setPadding(0, AndroidUtilities.dp(12), 0, AndroidUtilities.dp(8));
                    list.setOnItemClickListener((view1, position1) -> {
                        if (position1 < 0 || position1 >= 100) {
                            return;
                        }
                        int notifyMaxCount1 = position1 % 10 + 1;
                        int notifyDelay1 = position1 / 10 + 1;
                        SharedPreferences preferences1 = MessagesController.getNotificationsSettings(currentAccount);
                        preferences1.edit().putInt("smart_max_count_" + dialogId, notifyMaxCount1).commit();
                        preferences1.edit().putInt("smart_delay_" + dialogId, notifyDelay1 * 60).commit();
                        if (adapter != null) {
                            adapter.notifyItemChanged(smartRow);
                        }
                        dismissCurrentDialog();
                    });
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("SmartNotificationsAlert", R.string.SmartNotificationsAlert));
                    builder.setView(list);
                    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled", R.string.SmartNotificationsDisabled), (dialog, which) -> {
                        SharedPreferences preferences12 = MessagesController.getNotificationsSettings(currentAccount);
                        preferences12.edit().putInt("smart_max_count_" + dialogId, 0).commit();
                        if (adapter != null) {
                            adapter.notifyItemChanged(smartRow);
                        }
                        dismissCurrentDialog();
                    });
                    showDialog(builder.create());
                } else if (position == colorRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    showDialog(AlertsCreator.createColorSelectDialog(getParentActivity(), dialogId, -1, () -> {
                        if (adapter != null) {
                            adapter.notifyItemChanged(colorRow);
                        }
                    }));
                } else if (position == popupEnabledRow) {
                    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                    preferences.edit().putInt("popup_" + dialogId, 1).commit();
                    ((RadioCell) view).setChecked(true, true);
                    view = listView.findViewWithTag(2);
                    if (view != null) {
                        ((RadioCell) view).setChecked(false, true);
                    }
                } else if (position == popupDisabledRow) {
                    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                    preferences.edit().putInt("popup_" + dialogId, 2).commit();
                    ((RadioCell) view).setChecked(true, true);
                    view = listView.findViewWithTag(1);
                    if (view != null) {
                        ((RadioCell) view).setChecked(false, true);
                    }
                }
            }
        }
    });
    return fragmentView;
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Ringtone(android.media.Ringtone) Bundle(android.os.Bundle) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NotificationsController(org.telegram.messenger.NotificationsController) TextColorCell(org.telegram.ui.Cells.TextColorCell) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) UserCell2(org.telegram.ui.Cells.UserCell2) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) TextView(android.widget.TextView) RadioCell(org.telegram.ui.Cells.RadioCell) TextCheckBoxCell(org.telegram.ui.Cells.TextCheckBoxCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) 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) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) Settings(android.provider.Settings) Build(android.os.Build) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) DialogObject(org.telegram.messenger.DialogObject) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) MessagesStorage(org.telegram.messenger.MessagesStorage) RingtoneManager(android.media.RingtoneManager) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) RecyclerListView(org.telegram.ui.Components.RecyclerListView) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) RadioCell(org.telegram.ui.Cells.RadioCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Uri(android.net.Uri) TLRPC(org.telegram.tgnet.TLRPC) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) TextCheckBoxCell(org.telegram.ui.Cells.TextCheckBoxCell) Intent(android.content.Intent) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with TextCheckBoxCell

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

the class DataAutoDownloadActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    if (currentType == 0) {
        actionBar.setTitle(LocaleController.getString("AutoDownloadOnMobileData", R.string.AutoDownloadOnMobileData));
    } else if (currentType == 1) {
        actionBar.setTitle(LocaleController.getString("AutoDownloadOnWiFiData", R.string.AutoDownloadOnWiFiData));
    } else if (currentType == 2) {
        actionBar.setTitle(LocaleController.getString("AutoDownloadOnRoamingData", R.string.AutoDownloadOnRoamingData));
    }
    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);
    ((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(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 == autoDownloadRow) {
            if (currentPresetNum != 3) {
                if (currentPresetNum == 0) {
                    typePreset.set(lowPreset);
                } else if (currentPresetNum == 1) {
                    typePreset.set(mediumPreset);
                } else if (currentPresetNum == 2) {
                    typePreset.set(highPreset);
                }
            }
            TextCheckCell cell = (TextCheckCell) view;
            boolean checked = cell.isChecked();
            if (!checked && typePreset.enabled) {
                System.arraycopy(defaultPreset.mask, 0, typePreset.mask, 0, 4);
            } else {
                typePreset.enabled = !typePreset.enabled;
            }
            view.setTag(typePreset.enabled ? Theme.key_windowBackgroundChecked : Theme.key_windowBackgroundUnchecked);
            cell.setBackgroundColorAnimated(!checked, Theme.getColor(typePreset.enabled ? Theme.key_windowBackgroundChecked : Theme.key_windowBackgroundUnchecked));
            updateRows();
            if (typePreset.enabled) {
                listAdapter.notifyItemRangeInserted(autoDownloadSectionRow + 1, 8);
            } else {
                listAdapter.notifyItemRangeRemoved(autoDownloadSectionRow + 1, 8);
            }
            listAdapter.notifyItemChanged(autoDownloadSectionRow);
            SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
            editor.putString(key, typePreset.toString());
            editor.putInt(key2, currentPresetNum = 3);
            if (currentType == 0) {
                DownloadController.getInstance(currentAccount).currentMobilePreset = currentPresetNum;
            } else if (currentType == 1) {
                DownloadController.getInstance(currentAccount).currentWifiPreset = currentPresetNum;
            } else {
                DownloadController.getInstance(currentAccount).currentRoamingPreset = currentPresetNum;
            }
            editor.commit();
            cell.setChecked(!checked);
            DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
            wereAnyChanges = true;
        } else if (position == photosRow || position == videosRow || position == filesRow) {
            if (!view.isEnabled()) {
                return;
            }
            int type;
            if (position == photosRow) {
                type = DownloadController.AUTODOWNLOAD_TYPE_PHOTO;
            } else if (position == videosRow) {
                type = DownloadController.AUTODOWNLOAD_TYPE_VIDEO;
            } else {
                type = DownloadController.AUTODOWNLOAD_TYPE_DOCUMENT;
            }
            int index = DownloadController.typeToIndex(type);
            DownloadController.Preset currentPreset;
            String key;
            String key2;
            if (currentType == 0) {
                currentPreset = DownloadController.getInstance(currentAccount).getCurrentMobilePreset();
                key = "mobilePreset";
                key2 = "currentMobilePreset";
            } else if (currentType == 1) {
                currentPreset = DownloadController.getInstance(currentAccount).getCurrentWiFiPreset();
                key = "wifiPreset";
                key2 = "currentWifiPreset";
            } else {
                currentPreset = DownloadController.getInstance(currentAccount).getCurrentRoamingPreset();
                key = "roamingPreset";
                key2 = "currentRoamingPreset";
            }
            NotificationsCheckCell cell = (NotificationsCheckCell) view;
            boolean checked = cell.isChecked();
            if (LocaleController.isRTL && x <= AndroidUtilities.dp(76) || !LocaleController.isRTL && x >= view.getMeasuredWidth() - AndroidUtilities.dp(76)) {
                if (currentPresetNum != 3) {
                    if (currentPresetNum == 0) {
                        typePreset.set(lowPreset);
                    } else if (currentPresetNum == 1) {
                        typePreset.set(mediumPreset);
                    } else if (currentPresetNum == 2) {
                        typePreset.set(highPreset);
                    }
                }
                boolean hasAny = false;
                for (int a = 0; a < typePreset.mask.length; a++) {
                    if ((currentPreset.mask[a] & type) != 0) {
                        hasAny = true;
                        break;
                    }
                }
                for (int a = 0; a < typePreset.mask.length; a++) {
                    if (checked) {
                        typePreset.mask[a] &= ~type;
                    } else if (!hasAny) {
                        typePreset.mask[a] |= type;
                    }
                }
                SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
                editor.putString(key, typePreset.toString());
                editor.putInt(key2, currentPresetNum = 3);
                if (currentType == 0) {
                    DownloadController.getInstance(currentAccount).currentMobilePreset = currentPresetNum;
                } else if (currentType == 1) {
                    DownloadController.getInstance(currentAccount).currentWifiPreset = currentPresetNum;
                } else {
                    DownloadController.getInstance(currentAccount).currentRoamingPreset = currentPresetNum;
                }
                editor.commit();
                cell.setChecked(!checked);
                RecyclerView.ViewHolder holder = listView.findContainingViewHolder(view);
                if (holder != null) {
                    listAdapter.onBindViewHolder(holder, position);
                }
                DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
                wereAnyChanges = true;
                fillPresets();
            } else {
                if (getParentActivity() == null) {
                    return;
                }
                BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
                builder.setApplyTopPadding(false);
                builder.setApplyBottomPadding(false);
                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                builder.setCustomView(linearLayout);
                HeaderCell headerCell = new HeaderCell(getParentActivity(), Theme.key_dialogTextBlue2, 21, 15, false);
                if (position == photosRow) {
                    headerCell.setText(LocaleController.getString("AutoDownloadPhotosTitle", R.string.AutoDownloadPhotosTitle));
                } else if (position == videosRow) {
                    headerCell.setText(LocaleController.getString("AutoDownloadVideosTitle", R.string.AutoDownloadVideosTitle));
                } else {
                    headerCell.setText(LocaleController.getString("AutoDownloadFilesTitle", R.string.AutoDownloadFilesTitle));
                }
                linearLayout.addView(headerCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                final MaxFileSizeCell[] sizeCell = new MaxFileSizeCell[1];
                final TextCheckCell[] checkCell = new TextCheckCell[1];
                final AnimatorSet[] animatorSet = new AnimatorSet[1];
                TextCheckBoxCell[] cells = new TextCheckBoxCell[4];
                for (int a = 0; a < 4; a++) {
                    TextCheckBoxCell checkBoxCell = cells[a] = new TextCheckBoxCell(getParentActivity(), true, false);
                    if (a == 0) {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadContacts", R.string.AutodownloadContacts), (currentPreset.mask[DownloadController.PRESET_NUM_CONTACT] & type) != 0, true);
                    } else if (a == 1) {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadPrivateChats", R.string.AutodownloadPrivateChats), (currentPreset.mask[DownloadController.PRESET_NUM_PM] & type) != 0, true);
                    } else if (a == 2) {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadGroupChats", R.string.AutodownloadGroupChats), (currentPreset.mask[DownloadController.PRESET_NUM_GROUP] & type) != 0, true);
                    } else {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadChannels", R.string.AutodownloadChannels), (currentPreset.mask[DownloadController.PRESET_NUM_CHANNEL] & type) != 0, position != photosRow);
                    }
                    cells[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
                    cells[a].setOnClickListener(v -> {
                        if (!v.isEnabled()) {
                            return;
                        }
                        checkBoxCell.setChecked(!checkBoxCell.isChecked());
                        boolean hasAny = false;
                        for (int b = 0; b < cells.length; b++) {
                            if (cells[b].isChecked()) {
                                hasAny = true;
                                break;
                            }
                        }
                        if (position == videosRow && sizeCell[0].isEnabled() != hasAny) {
                            ArrayList<Animator> animators = new ArrayList<>();
                            sizeCell[0].setEnabled(hasAny, animators);
                            if (sizeCell[0].getSize() > 2 * 1024 * 1024) {
                                checkCell[0].setEnabled(hasAny, animators);
                            }
                            if (animatorSet[0] != null) {
                                animatorSet[0].cancel();
                                animatorSet[0] = null;
                            }
                            animatorSet[0] = new AnimatorSet();
                            animatorSet[0].playTogether(animators);
                            animatorSet[0].addListener(new AnimatorListenerAdapter() {

                                @Override
                                public void onAnimationEnd(Animator animator) {
                                    if (animator.equals(animatorSet[0])) {
                                        animatorSet[0] = null;
                                    }
                                }
                            });
                            animatorSet[0].setDuration(150);
                            animatorSet[0].start();
                        }
                    });
                    linearLayout.addView(cells[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50));
                }
                if (position != photosRow) {
                    TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(getParentActivity());
                    sizeCell[0] = new MaxFileSizeCell(getParentActivity()) {

                        @Override
                        protected void didChangedSizeValue(int value) {
                            if (position == videosRow) {
                                infoCell.setText(LocaleController.formatString("AutoDownloadPreloadVideoInfo", R.string.AutoDownloadPreloadVideoInfo, AndroidUtilities.formatFileSize(value)));
                                boolean enabled = value > 2 * 1024 * 1024;
                                if (enabled != checkCell[0].isEnabled()) {
                                    ArrayList<Animator> animators = new ArrayList<>();
                                    checkCell[0].setEnabled(enabled, animators);
                                    if (animatorSet[0] != null) {
                                        animatorSet[0].cancel();
                                        animatorSet[0] = null;
                                    }
                                    animatorSet[0] = new AnimatorSet();
                                    animatorSet[0].playTogether(animators);
                                    animatorSet[0].addListener(new AnimatorListenerAdapter() {

                                        @Override
                                        public void onAnimationEnd(Animator animator) {
                                            if (animator.equals(animatorSet[0])) {
                                                animatorSet[0] = null;
                                            }
                                        }
                                    });
                                    animatorSet[0].setDuration(150);
                                    animatorSet[0].start();
                                }
                            }
                        }
                    };
                    sizeCell[0].setSize(currentPreset.sizes[index]);
                    linearLayout.addView(sizeCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                    checkCell[0] = new TextCheckCell(getParentActivity(), 21, true);
                    linearLayout.addView(checkCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
                    checkCell[0].setOnClickListener(v -> checkCell[0].setChecked(!checkCell[0].isChecked()));
                    Drawable drawable = Theme.getThemedDrawable(getParentActivity(), R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
                    CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
                    combinedDrawable.setFullsize(true);
                    infoCell.setBackgroundDrawable(combinedDrawable);
                    linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                    if (position == videosRow) {
                        sizeCell[0].setText(LocaleController.getString("AutoDownloadMaxVideoSize", R.string.AutoDownloadMaxVideoSize));
                        checkCell[0].setTextAndCheck(LocaleController.getString("AutoDownloadPreloadVideo", R.string.AutoDownloadPreloadVideo), currentPreset.preloadVideo, false);
                        infoCell.setText(LocaleController.formatString("AutoDownloadPreloadVideoInfo", R.string.AutoDownloadPreloadVideoInfo, AndroidUtilities.formatFileSize(currentPreset.sizes[index])));
                    } else {
                        sizeCell[0].setText(LocaleController.getString("AutoDownloadMaxFileSize", R.string.AutoDownloadMaxFileSize));
                        checkCell[0].setTextAndCheck(LocaleController.getString("AutoDownloadPreloadMusic", R.string.AutoDownloadPreloadMusic), currentPreset.preloadMusic, false);
                        infoCell.setText(LocaleController.getString("AutoDownloadPreloadMusicInfo", R.string.AutoDownloadPreloadMusicInfo));
                    }
                } else {
                    sizeCell[0] = null;
                    checkCell[0] = null;
                    View divider = new View(getParentActivity());
                    divider.setBackgroundColor(Theme.getColor(Theme.key_divider));
                    linearLayout.addView(divider, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
                }
                if (position == videosRow) {
                    boolean hasAny = false;
                    for (int b = 0; b < cells.length; b++) {
                        if (cells[b].isChecked()) {
                            hasAny = true;
                            break;
                        }
                    }
                    if (!hasAny) {
                        sizeCell[0].setEnabled(false, null);
                        checkCell[0].setEnabled(false, null);
                    }
                    if (currentPreset.sizes[index] <= 2 * 1024 * 1024) {
                        checkCell[0].setEnabled(false, null);
                    }
                }
                FrameLayout buttonsLayout = new FrameLayout(getParentActivity());
                buttonsLayout.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
                linearLayout.addView(buttonsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 52));
                TextView textView = new TextView(getParentActivity());
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
                textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2));
                textView.setGravity(Gravity.CENTER);
                textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                textView.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
                textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
                buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.LEFT));
                textView.setOnClickListener(v14 -> builder.getDismissRunnable().run());
                textView = new TextView(getParentActivity());
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
                textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2));
                textView.setGravity(Gravity.CENTER);
                textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                textView.setText(LocaleController.getString("Save", R.string.Save).toUpperCase());
                textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
                buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
                textView.setOnClickListener(v1 -> {
                    if (currentPresetNum != 3) {
                        if (currentPresetNum == 0) {
                            typePreset.set(lowPreset);
                        } else if (currentPresetNum == 1) {
                            typePreset.set(mediumPreset);
                        } else if (currentPresetNum == 2) {
                            typePreset.set(highPreset);
                        }
                    }
                    for (int a = 0; a < 4; a++) {
                        if (cells[a].isChecked()) {
                            typePreset.mask[a] |= type;
                        } else {
                            typePreset.mask[a] &= ~type;
                        }
                    }
                    if (sizeCell[0] != null) {
                        int size = (int) sizeCell[0].getSize();
                        typePreset.sizes[index] = (int) sizeCell[0].getSize();
                    }
                    if (checkCell[0] != null) {
                        if (position == videosRow) {
                            typePreset.preloadVideo = checkCell[0].isChecked();
                        } else {
                            typePreset.preloadMusic = checkCell[0].isChecked();
                        }
                    }
                    SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
                    editor.putString(key, typePreset.toString());
                    editor.putInt(key2, currentPresetNum = 3);
                    if (currentType == 0) {
                        DownloadController.getInstance(currentAccount).currentMobilePreset = currentPresetNum;
                    } else if (currentType == 1) {
                        DownloadController.getInstance(currentAccount).currentWifiPreset = currentPresetNum;
                    } else {
                        DownloadController.getInstance(currentAccount).currentRoamingPreset = currentPresetNum;
                    }
                    editor.commit();
                    builder.getDismissRunnable().run();
                    RecyclerView.ViewHolder holder = listView.findContainingViewHolder(view);
                    if (holder != null) {
                        animateChecked = true;
                        listAdapter.onBindViewHolder(holder, position);
                        animateChecked = false;
                    }
                    DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
                    wereAnyChanges = true;
                    fillPresets();
                });
                showDialog(builder.create());
            }
        }
    });
    return fragmentView;
}
Also used : 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) ColorDrawable(android.graphics.drawable.ColorDrawable) LocaleController(org.telegram.messenger.LocaleController) Animator(android.animation.Animator) HeaderCell(org.telegram.ui.Cells.HeaderCell) MaxFileSizeCell(org.telegram.ui.Cells.MaxFileSizeCell) Drawable(android.graphics.drawable.Drawable) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ActionBar(org.telegram.ui.ActionBar.ActionBar) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Build(android.os.Build) DownloadController(org.telegram.messenger.DownloadController) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) SlideChooseView(org.telegram.ui.Components.SlideChooseView) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ViewGroup(android.view.ViewGroup) MessagesController(org.telegram.messenger.MessagesController) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) Gravity(android.view.Gravity) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) TextCheckBoxCell(org.telegram.ui.Cells.TextCheckBoxCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) HeaderCell(org.telegram.ui.Cells.HeaderCell) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) MaxFileSizeCell(org.telegram.ui.Cells.MaxFileSizeCell) SharedPreferences(android.content.SharedPreferences) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) TextCheckBoxCell(org.telegram.ui.Cells.TextCheckBoxCell) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SlideChooseView(org.telegram.ui.Components.SlideChooseView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) Animator(android.animation.Animator) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) FrameLayout(android.widget.FrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) LinearLayout(android.widget.LinearLayout)

Aggregations

Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 AnimatorSet (android.animation.AnimatorSet)2 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Build (android.os.Build)2 TypedValue (android.util.TypedValue)2 Gravity (android.view.Gravity)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 FrameLayout (android.widget.FrameLayout)2 TextView (android.widget.TextView)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 ArrayList (java.util.ArrayList)2 AndroidUtilities (org.telegram.messenger.AndroidUtilities)2 LocaleController (org.telegram.messenger.LocaleController)2 MessagesController (org.telegram.messenger.MessagesController)2 R (org.telegram.messenger.R)2 ActionBar (org.telegram.ui.ActionBar.ActionBar)2