Search in sources :

Example 36 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogsActivity method onItemLongClick.

private boolean onItemLongClick(View view, int position, float x, float y, int dialogsType, RecyclerListView.Adapter adapter) {
    if (getParentActivity() == null) {
        return false;
    }
    if (!actionBar.isActionModeShowed() && !AndroidUtilities.isTablet() && !onlySelect && view instanceof DialogCell) {
        DialogCell cell = (DialogCell) view;
        if (cell.isPointInsideAvatar(x, y)) {
            return showChatPreview(cell);
        }
    }
    if (adapter == searchViewPager.dialogsSearchAdapter) {
        Object item = searchViewPager.dialogsSearchAdapter.getItem(position);
        if (searchViewPager.dialogsSearchAdapter.isRecentSearchDisplayed()) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("ClearSearchSingleAlertTitle", R.string.ClearSearchSingleAlertTitle));
            long did;
            if (item instanceof TLRPC.Chat) {
                TLRPC.Chat chat = (TLRPC.Chat) item;
                builder.setMessage(LocaleController.formatString("ClearSearchSingleChatAlertText", R.string.ClearSearchSingleChatAlertText, chat.title));
                did = -chat.id;
            } else if (item instanceof TLRPC.User) {
                TLRPC.User user = (TLRPC.User) item;
                if (user.id == getUserConfig().clientUserId) {
                    builder.setMessage(LocaleController.formatString("ClearSearchSingleChatAlertText", R.string.ClearSearchSingleChatAlertText, LocaleController.getString("SavedMessages", R.string.SavedMessages)));
                } else {
                    builder.setMessage(LocaleController.formatString("ClearSearchSingleUserAlertText", R.string.ClearSearchSingleUserAlertText, ContactsController.formatName(user.first_name, user.last_name)));
                }
                did = user.id;
            } else if (item instanceof TLRPC.EncryptedChat) {
                TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat) item;
                TLRPC.User user = getMessagesController().getUser(encryptedChat.user_id);
                builder.setMessage(LocaleController.formatString("ClearSearchSingleUserAlertText", R.string.ClearSearchSingleUserAlertText, ContactsController.formatName(user.first_name, user.last_name)));
                did = DialogObject.makeEncryptedDialogId(encryptedChat.id);
            } else {
                return false;
            }
            builder.setPositiveButton(LocaleController.getString("ClearSearchRemove", R.string.ClearSearchRemove).toUpperCase(), (dialogInterface, i) -> searchViewPager.dialogsSearchAdapter.removeRecentSearch(did));
            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 true;
        }
    }
    TLRPC.Dialog dialog;
    if (adapter == searchViewPager.dialogsSearchAdapter) {
        long dialogId = 0;
        if (view instanceof ProfileSearchCell && !searchViewPager.dialogsSearchAdapter.isGlobalSearch(position)) {
            dialogId = ((ProfileSearchCell) view).getDialogId();
        }
        if (dialogId != 0) {
            showOrUpdateActionMode(dialogId, view);
            return true;
        }
        return false;
    } else {
        DialogsAdapter dialogsAdapter = (DialogsAdapter) adapter;
        ArrayList<TLRPC.Dialog> dialogs = getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
        position = dialogsAdapter.fixPosition(position);
        if (position < 0 || position >= dialogs.size()) {
            return false;
        }
        dialog = dialogs.get(position);
    }
    if (dialog == null) {
        return false;
    }
    if (onlySelect) {
        if (initialDialogsType != 3 && initialDialogsType != 10) {
            return false;
        }
        if (!validateSlowModeDialog(dialog.id)) {
            return false;
        }
        if (!(initialDialogsType == 3 && selectAlertString != null)) {
            addOrRemoveSelectedDialog(dialog.id, view);
            updateSelectedCount();
        }
    } else {
        if (dialog instanceof TLRPC.TL_dialogFolder) {
            view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
            BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
            final boolean hasUnread = getMessagesStorage().getArchiveUnreadCount() != 0;
            int[] icons = new int[] { hasUnread ? R.drawable.menu_read : 0, SharedConfig.archiveHidden ? R.drawable.chats_pin : R.drawable.chats_unpin };
            CharSequence[] items = new CharSequence[] { hasUnread ? LocaleController.getString("MarkAllAsRead", R.string.MarkAllAsRead) : null, SharedConfig.archiveHidden ? LocaleController.getString("PinInTheList", R.string.PinInTheList) : LocaleController.getString("HideAboveTheList", R.string.HideAboveTheList) };
            builder.setItems(items, icons, (d, which) -> {
                if (which == 0) {
                    getMessagesStorage().readAllDialogs(1);
                } else if (which == 1 && viewPages != null) {
                    for (int a = 0; a < viewPages.length; a++) {
                        if (viewPages[a].dialogsType != 0 || viewPages[a].getVisibility() != View.VISIBLE) {
                            continue;
                        }
                        View child = viewPages[a].listView.getChildAt(0);
                        DialogCell dialogCell = null;
                        if (child instanceof DialogCell && ((DialogCell) child).isFolderCell()) {
                            dialogCell = (DialogCell) child;
                        }
                        viewPages[a].listView.toggleArchiveHidden(true, dialogCell);
                    }
                }
            });
            showDialog(builder.create());
            return false;
        }
        if (actionBar.isActionModeShowed() && isDialogPinned(dialog)) {
            return false;
        }
        showOrUpdateActionMode(dialog.id, view);
    }
    return true;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TLRPC(org.telegram.tgnet.TLRPC) DialogCell(org.telegram.ui.Cells.DialogCell) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) Dialog(android.app.Dialog) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) DialogsAdapter(org.telegram.ui.Adapters.DialogsAdapter) ImageView(android.widget.ImageView) FilterTabsView(org.telegram.ui.Components.FilterTabsView) UndoView(org.telegram.ui.Components.UndoView) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) FragmentContextView(org.telegram.ui.Components.FragmentContextView) ScrollView(android.widget.ScrollView) FiltersView(org.telegram.ui.Adapters.FiltersView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) BackupImageView(org.telegram.ui.Components.BackupImageView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) NumberTextView(org.telegram.ui.Components.NumberTextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) FiltersListBottomSheet(org.telegram.ui.Components.FiltersListBottomSheet)

Example 37 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class VoIPHelper method showRateAlert.

public static void showRateAlert(final Context context, final Runnable onDismiss, boolean isVideo, final long callID, final long accessHash, final int account, final boolean userInitiative) {
    final File log = getLogFile(callID);
    final int[] page = { 0 };
    LinearLayout alertView = new LinearLayout(context);
    alertView.setOrientation(LinearLayout.VERTICAL);
    int pad = AndroidUtilities.dp(16);
    alertView.setPadding(pad, pad, pad, 0);
    TextView text = new TextView(context);
    text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    text.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    text.setGravity(Gravity.CENTER);
    text.setText(LocaleController.getString("VoipRateCallAlert", R.string.VoipRateCallAlert));
    alertView.addView(text);
    final BetterRatingView bar = new BetterRatingView(context);
    alertView.addView(bar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 0));
    final LinearLayout problemsWrap = new LinearLayout(context);
    problemsWrap.setOrientation(LinearLayout.VERTICAL);
    View.OnClickListener problemCheckboxClickListener = v -> {
        CheckBoxCell check = (CheckBoxCell) v;
        check.setChecked(!check.isChecked(), true);
    };
    final String[] problems = { isVideo ? "distorted_video" : null, isVideo ? "pixelated_video" : null, "echo", "noise", "interruptions", "distorted_speech", "silent_local", "silent_remote", "dropped" };
    for (int i = 0; i < problems.length; i++) {
        if (problems[i] == null) {
            continue;
        }
        CheckBoxCell check = new CheckBoxCell(context, 1);
        check.setClipToPadding(false);
        check.setTag(problems[i]);
        String label = null;
        switch(i) {
            case 0:
                label = LocaleController.getString("RateCallVideoDistorted", R.string.RateCallVideoDistorted);
                break;
            case 1:
                label = LocaleController.getString("RateCallVideoPixelated", R.string.RateCallVideoPixelated);
                break;
            case 2:
                label = LocaleController.getString("RateCallEcho", R.string.RateCallEcho);
                break;
            case 3:
                label = LocaleController.getString("RateCallNoise", R.string.RateCallNoise);
                break;
            case 4:
                label = LocaleController.getString("RateCallInterruptions", R.string.RateCallInterruptions);
                break;
            case 5:
                label = LocaleController.getString("RateCallDistorted", R.string.RateCallDistorted);
                break;
            case 6:
                label = LocaleController.getString("RateCallSilentLocal", R.string.RateCallSilentLocal);
                break;
            case 7:
                label = LocaleController.getString("RateCallSilentRemote", R.string.RateCallSilentRemote);
                break;
            case 8:
                label = LocaleController.getString("RateCallDropped", R.string.RateCallDropped);
                break;
        }
        check.setText(label, null, false, false);
        check.setOnClickListener(problemCheckboxClickListener);
        check.setTag(problems[i]);
        problemsWrap.addView(check);
    }
    alertView.addView(problemsWrap, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
    problemsWrap.setVisibility(View.GONE);
    final EditTextBoldCursor commentBox = new EditTextBoldCursor(context);
    commentBox.setHint(LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
    commentBox.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    commentBox.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    commentBox.setHintTextColor(Theme.getColor(Theme.key_dialogTextHint));
    commentBox.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
    commentBox.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4));
    commentBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    commentBox.setVisibility(View.GONE);
    alertView.addView(commentBox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 8, 8, 8, 0));
    final boolean[] includeLogs = { true };
    final CheckBoxCell checkbox = new CheckBoxCell(context, 1);
    View.OnClickListener checkClickListener = v -> {
        includeLogs[0] = !includeLogs[0];
        checkbox.setChecked(includeLogs[0], true);
    };
    checkbox.setText(LocaleController.getString("CallReportIncludeLogs", R.string.CallReportIncludeLogs), null, true, false);
    checkbox.setClipToPadding(false);
    checkbox.setOnClickListener(checkClickListener);
    alertView.addView(checkbox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
    final TextView logsText = new TextView(context);
    logsText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
    logsText.setTextColor(Theme.getColor(Theme.key_dialogTextGray3));
    logsText.setText(LocaleController.getString("CallReportLogsExplain", R.string.CallReportLogsExplain));
    logsText.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
    logsText.setOnClickListener(checkClickListener);
    alertView.addView(logsText);
    checkbox.setVisibility(View.GONE);
    logsText.setVisibility(View.GONE);
    if (!log.exists()) {
        includeLogs[0] = false;
    }
    final AlertDialog alert = new AlertDialog.Builder(context).setTitle(LocaleController.getString("CallMessageReportProblem", R.string.CallMessageReportProblem)).setView(alertView).setPositiveButton(LocaleController.getString("Send", R.string.Send), (dialog, which) -> {
    // SendMessagesHelper.getInstance(currentAccount).sendMessage(commentBox.getText().toString(), VOIP_SUPPORT_ID, null, null, true, null, null, null);
    }).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null).setOnDismissListener(dialog -> {
        if (onDismiss != null)
            onDismiss.run();
    }).create();
    if (BuildVars.LOGS_ENABLED && log.exists()) {
        alert.setNeutralButton("Send log", (dialog, which) -> {
            Intent intent = new Intent(context, LaunchActivity.class);
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(log));
            context.startActivity(intent);
        });
    }
    alert.show();
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    final View btn = alert.getButton(DialogInterface.BUTTON_POSITIVE);
    btn.setEnabled(false);
    bar.setOnRatingChangeListener(rating -> {
        btn.setEnabled(rating > 0);
        /*commentBox.setHint(rating<4 ? LocaleController.getString("CallReportHint", R.string.CallReportHint) : LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
			commentBox.setVisibility(rating < 5 && rating > 0 ? View.VISIBLE : View.GONE);
			if (commentBox.getVisibility() == View.GONE) {
				((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(commentBox.getWindowToken(), 0);
			}
			*/
        ((TextView) btn).setText((rating < 4 ? LocaleController.getString("Next", R.string.Next) : LocaleController.getString("Send", R.string.Send)).toUpperCase());
    });
    btn.setOnClickListener(v -> {
        int rating = bar.getRating();
        if (rating >= 4 || page[0] == 1) {
            final int currentAccount = UserConfig.selectedAccount;
            final TLRPC.TL_phone_setCallRating req = new TLRPC.TL_phone_setCallRating();
            req.rating = bar.getRating();
            ArrayList<String> problemTags = new ArrayList<>();
            for (int i = 0; i < problemsWrap.getChildCount(); i++) {
                CheckBoxCell check = (CheckBoxCell) problemsWrap.getChildAt(i);
                if (check.isChecked())
                    problemTags.add("#" + check.getTag());
            }
            if (req.rating < 5) {
                req.comment = commentBox.getText().toString();
            } else {
                req.comment = "";
            }
            if (!problemTags.isEmpty() && !includeLogs[0]) {
                req.comment += " " + TextUtils.join(" ", problemTags);
            }
            req.peer = new TLRPC.TL_inputPhoneCall();
            req.peer.access_hash = accessHash;
            req.peer.id = callID;
            req.user_initiative = userInitiative;
            ConnectionsManager.getInstance(account).sendRequest(req, (response, error) -> {
                if (response instanceof TLRPC.TL_updates) {
                    TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
                    MessagesController.getInstance(currentAccount).processUpdates(updates, false);
                }
                if (includeLogs[0] && log.exists() && req.rating < 4) {
                    AccountInstance accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount);
                    SendMessagesHelper.prepareSendingDocument(accountInstance, log.getAbsolutePath(), log.getAbsolutePath(), null, TextUtils.join(" ", problemTags), "text/plain", VOIP_SUPPORT_ID, null, null, null, null, true, 0);
                    Toast.makeText(context, LocaleController.getString("CallReportSent", R.string.CallReportSent), Toast.LENGTH_LONG).show();
                }
            });
            alert.dismiss();
        } else {
            page[0] = 1;
            bar.setVisibility(View.GONE);
            // text.setText(LocaleController.getString("CallReportHint", R.string.CallReportHint));
            text.setVisibility(View.GONE);
            alert.setTitle(LocaleController.getString("CallReportHint", R.string.CallReportHint));
            commentBox.setVisibility(View.VISIBLE);
            if (log.exists()) {
                checkbox.setVisibility(View.VISIBLE);
                logsText.setVisibility(View.VISIBLE);
            }
            problemsWrap.setVisibility(View.VISIBLE);
            ((TextView) btn).setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
        }
    });
}
Also used : LinearLayout(android.widget.LinearLayout) Arrays(java.util.Arrays) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) BetterRatingView(org.telegram.ui.Components.BetterRatingView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) JoinCallByUrlAlert(org.telegram.ui.Components.JoinCallByUrlAlert) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) Manifest(android.Manifest) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) View(android.view.View) TargetApi(android.annotation.TargetApi) InputType(android.text.InputType) Set(java.util.Set) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) Instance(org.telegram.messenger.voip.Instance) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) GroupCallActivity(org.telegram.ui.GroupCallActivity) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) LaunchActivity(org.telegram.ui.LaunchActivity) Context(android.content.Context) VoIPService(org.telegram.messenger.voip.VoIPService) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) Settings(android.provider.Settings) MessageObject(org.telegram.messenger.MessageObject) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) DownloadController(org.telegram.messenger.DownloadController) DialogInterface(android.content.DialogInterface) R(org.telegram.messenger.R) JoinCallAlert(org.telegram.ui.Components.JoinCallAlert) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) TextView(android.widget.TextView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Intent(android.content.Intent) BetterRatingView(org.telegram.ui.Components.BetterRatingView) View(android.view.View) TextView(android.widget.TextView) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) AccountInstance(org.telegram.messenger.AccountInstance) File(java.io.File) LinearLayout(android.widget.LinearLayout) BetterRatingView(org.telegram.ui.Components.BetterRatingView)

Example 38 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class VoIPHelper method permissionDenied.

@TargetApi(Build.VERSION_CODES.M)
public static void permissionDenied(final Activity activity, final Runnable onFinish, int code) {
    if (!activity.shouldShowRequestPermissionRationale(Manifest.permission.RECORD_AUDIO) || code == 102 && !activity.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
        AlertDialog dlg = new AlertDialog.Builder(activity).setTitle(LocaleController.getString("AppName", R.string.AppName)).setMessage(code == 102 ? LocaleController.getString("VoipNeedMicCameraPermission", R.string.VoipNeedMicCameraPermission) : LocaleController.getString("VoipNeedMicPermission", R.string.VoipNeedMicPermission)).setPositiveButton(LocaleController.getString("OK", R.string.OK), null).setNegativeButton(LocaleController.getString("Settings", R.string.Settings), (dialog, which) -> {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
            intent.setData(uri);
            activity.startActivity(intent);
        }).show();
        dlg.setOnDismissListener(dialog -> {
            if (onFinish != null)
                onFinish.run();
        });
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) LinearLayout(android.widget.LinearLayout) Arrays(java.util.Arrays) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) BetterRatingView(org.telegram.ui.Components.BetterRatingView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) JoinCallByUrlAlert(org.telegram.ui.Components.JoinCallByUrlAlert) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) Manifest(android.Manifest) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) View(android.view.View) TargetApi(android.annotation.TargetApi) InputType(android.text.InputType) Set(java.util.Set) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) Instance(org.telegram.messenger.voip.Instance) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) GroupCallActivity(org.telegram.ui.GroupCallActivity) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) LaunchActivity(org.telegram.ui.LaunchActivity) Context(android.content.Context) VoIPService(org.telegram.messenger.voip.VoIPService) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) Settings(android.provider.Settings) MessageObject(org.telegram.messenger.MessageObject) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) DownloadController(org.telegram.messenger.DownloadController) DialogInterface(android.content.DialogInterface) R(org.telegram.messenger.R) JoinCallAlert(org.telegram.ui.Components.JoinCallAlert) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) Intent(android.content.Intent) Uri(android.net.Uri) TargetApi(android.annotation.TargetApi)

Example 39 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class DataUsageActivity method createView.

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

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    hasOwnBackground = true;
    mobileAdapter = new ListAdapter(context, 0);
    wifiAdapter = new ListAdapter(context, 1);
    roamingAdapter = new ListAdapter(context, 2);
    scrollSlidingTextTabStrip = new ScrollSlidingTextTabStrip(context);
    scrollSlidingTextTabStrip.setUseSameWidth(true);
    actionBar.addView(scrollSlidingTextTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 44, Gravity.LEFT | Gravity.BOTTOM));
    scrollSlidingTextTabStrip.setDelegate(new ScrollSlidingTextTabStrip.ScrollSlidingTabStripDelegate() {

        @Override
        public void onPageSelected(int id, boolean forward) {
            if (viewPages[0].selectedType == id) {
                return;
            }
            swipeBackEnabled = id == scrollSlidingTextTabStrip.getFirstTabId();
            viewPages[1].selectedType = id;
            viewPages[1].setVisibility(View.VISIBLE);
            switchToCurrentSelectedMode(true);
            animatingForward = forward;
        }

        @Override
        public void onPageScrolled(float progress) {
            if (progress == 1 && viewPages[1].getVisibility() != View.VISIBLE) {
                return;
            }
            if (animatingForward) {
                viewPages[0].setTranslationX(-progress * viewPages[0].getMeasuredWidth());
                viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() - progress * viewPages[0].getMeasuredWidth());
            } else {
                viewPages[0].setTranslationX(progress * viewPages[0].getMeasuredWidth());
                viewPages[1].setTranslationX(progress * viewPages[0].getMeasuredWidth() - viewPages[0].getMeasuredWidth());
            }
            if (progress == 1) {
                ViewPage tempPage = viewPages[0];
                viewPages[0] = viewPages[1];
                viewPages[1] = tempPage;
                viewPages[1].setVisibility(View.GONE);
            }
        }
    });
    ViewConfiguration configuration = ViewConfiguration.get(context);
    maximumVelocity = configuration.getScaledMaximumFlingVelocity();
    FrameLayout frameLayout;
    fragmentView = frameLayout = new FrameLayout(context) {

        private int startedTrackingPointerId;

        private boolean startedTracking;

        private boolean maybeStartTracking;

        private int startedTrackingX;

        private int startedTrackingY;

        private VelocityTracker velocityTracker;

        private boolean globalIgnoreLayout;

        private boolean prepareForMoving(MotionEvent ev, boolean forward) {
            int id = scrollSlidingTextTabStrip.getNextPageId(forward);
            if (id < 0) {
                return false;
            }
            getParent().requestDisallowInterceptTouchEvent(true);
            maybeStartTracking = false;
            startedTracking = true;
            startedTrackingX = (int) ev.getX();
            actionBar.setEnabled(false);
            scrollSlidingTextTabStrip.setEnabled(false);
            viewPages[1].selectedType = id;
            viewPages[1].setVisibility(View.VISIBLE);
            animatingForward = forward;
            switchToCurrentSelectedMode(true);
            if (forward) {
                viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
            } else {
                viewPages[1].setTranslationX(-viewPages[0].getMeasuredWidth());
            }
            return true;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(widthSize, heightSize);
            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar.getMeasuredHeight();
            globalIgnoreLayout = true;
            for (int a = 0; a < viewPages.length; a++) {
                if (viewPages[a] == null) {
                    continue;
                }
                if (viewPages[a].listView != null) {
                    viewPages[a].listView.setPadding(0, actionBarHeight, 0, AndroidUtilities.dp(4));
                }
            }
            globalIgnoreLayout = false;
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE || child == actionBar) {
                    continue;
                }
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
            }
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            if (parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas, actionBar.getMeasuredHeight() + (int) actionBar.getTranslationY());
            }
        }

        @Override
        public void requestLayout() {
            if (globalIgnoreLayout) {
                return;
            }
            super.requestLayout();
        }

        public boolean checkTabsAnimationInProgress() {
            if (tabsAnimationInProgress) {
                boolean cancel = false;
                if (backAnimation) {
                    if (Math.abs(viewPages[0].getTranslationX()) < 1) {
                        viewPages[0].setTranslationX(0);
                        viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? 1 : -1));
                        cancel = true;
                    }
                } else if (Math.abs(viewPages[1].getTranslationX()) < 1) {
                    viewPages[0].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? -1 : 1));
                    viewPages[1].setTranslationX(0);
                    cancel = true;
                }
                if (cancel) {
                    if (tabsAnimation != null) {
                        tabsAnimation.cancel();
                        tabsAnimation = null;
                    }
                    tabsAnimationInProgress = false;
                }
                return tabsAnimationInProgress;
            }
            return false;
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return checkTabsAnimationInProgress() || scrollSlidingTextTabStrip.isAnimatingIndicator() || onTouchEvent(ev);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            backgroundPaint.setColor(Theme.getColor(Theme.key_windowBackgroundGray));
            canvas.drawRect(0, actionBar.getMeasuredHeight() + actionBar.getTranslationY(), getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
        }

        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            if (!parentLayout.checkTransitionAnimation() && !checkTabsAnimationInProgress()) {
                if (ev != null) {
                    if (velocityTracker == null) {
                        velocityTracker = VelocityTracker.obtain();
                    }
                    velocityTracker.addMovement(ev);
                }
                if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
                    startedTrackingPointerId = ev.getPointerId(0);
                    maybeStartTracking = true;
                    startedTrackingX = (int) ev.getX();
                    startedTrackingY = (int) ev.getY();
                    velocityTracker.clear();
                } else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
                    int dx = (int) (ev.getX() - startedTrackingX);
                    int dy = Math.abs((int) ev.getY() - startedTrackingY);
                    if (startedTracking && (animatingForward && dx > 0 || !animatingForward && dx < 0)) {
                        if (!prepareForMoving(ev, dx < 0)) {
                            maybeStartTracking = true;
                            startedTracking = false;
                            viewPages[0].setTranslationX(0);
                            viewPages[1].setTranslationX(animatingForward ? viewPages[0].getMeasuredWidth() : -viewPages[0].getMeasuredWidth());
                            scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, 0);
                        }
                    }
                    if (maybeStartTracking && !startedTracking) {
                        float touchSlop = AndroidUtilities.getPixelsInCM(0.3f, true);
                        if (Math.abs(dx) >= touchSlop && Math.abs(dx) > dy) {
                            prepareForMoving(ev, dx < 0);
                        }
                    } else if (startedTracking) {
                        if (animatingForward) {
                            viewPages[0].setTranslationX(dx);
                            viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() + dx);
                        } else {
                            viewPages[0].setTranslationX(dx);
                            viewPages[1].setTranslationX(dx - viewPages[0].getMeasuredWidth());
                        }
                        float scrollProgress = Math.abs(dx) / (float) viewPages[0].getMeasuredWidth();
                        scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                    }
                } else if (ev == null || ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
                    velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
                    float velX;
                    float velY;
                    if (ev != null && ev.getAction() != MotionEvent.ACTION_CANCEL) {
                        velX = velocityTracker.getXVelocity();
                        velY = velocityTracker.getYVelocity();
                        if (!startedTracking) {
                            if (Math.abs(velX) >= 3000 && Math.abs(velX) > Math.abs(velY)) {
                                prepareForMoving(ev, velX < 0);
                            }
                        }
                    } else {
                        velX = 0;
                        velY = 0;
                    }
                    if (startedTracking) {
                        float x = viewPages[0].getX();
                        tabsAnimation = new AnimatorSet();
                        backAnimation = Math.abs(x) < viewPages[0].getMeasuredWidth() / 3.0f && (Math.abs(velX) < 3500 || Math.abs(velX) < Math.abs(velY));
                        float distToMove;
                        float dx;
                        if (backAnimation) {
                            dx = Math.abs(x);
                            if (animatingForward) {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, viewPages[1].getMeasuredWidth()));
                            } else {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, -viewPages[1].getMeasuredWidth()));
                            }
                        } else {
                            dx = viewPages[0].getMeasuredWidth() - Math.abs(x);
                            if (animatingForward) {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, -viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
                            } else {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
                            }
                        }
                        tabsAnimation.setInterpolator(interpolator);
                        int width = getMeasuredWidth();
                        int halfWidth = width / 2;
                        float distanceRatio = Math.min(1.0f, 1.0f * dx / (float) width);
                        float distance = (float) halfWidth + (float) halfWidth * AndroidUtilities.distanceInfluenceForSnapDuration(distanceRatio);
                        velX = Math.abs(velX);
                        int duration;
                        if (velX > 0) {
                            duration = 4 * Math.round(1000.0f * Math.abs(distance / velX));
                        } else {
                            float pageDelta = dx / getMeasuredWidth();
                            duration = (int) ((pageDelta + 1.0f) * 100.0f);
                        }
                        duration = Math.max(150, Math.min(duration, 600));
                        tabsAnimation.setDuration(duration);
                        tabsAnimation.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationEnd(Animator animator) {
                                tabsAnimation = null;
                                if (backAnimation) {
                                    viewPages[1].setVisibility(View.GONE);
                                } else {
                                    ViewPage tempPage = viewPages[0];
                                    viewPages[0] = viewPages[1];
                                    viewPages[1] = tempPage;
                                    viewPages[1].setVisibility(View.GONE);
                                    swipeBackEnabled = viewPages[0].selectedType == scrollSlidingTextTabStrip.getFirstTabId();
                                    scrollSlidingTextTabStrip.selectTabWithId(viewPages[0].selectedType, 1.0f);
                                }
                                tabsAnimationInProgress = false;
                                maybeStartTracking = false;
                                startedTracking = false;
                                actionBar.setEnabled(true);
                                scrollSlidingTextTabStrip.setEnabled(true);
                            }
                        });
                        tabsAnimation.start();
                        tabsAnimationInProgress = true;
                        startedTracking = false;
                    } else {
                        maybeStartTracking = false;
                        actionBar.setEnabled(true);
                        scrollSlidingTextTabStrip.setEnabled(true);
                    }
                    if (velocityTracker != null) {
                        velocityTracker.recycle();
                        velocityTracker = null;
                    }
                }
                return startedTracking;
            }
            return false;
        }
    };
    frameLayout.setWillNotDraw(false);
    int scrollToPositionOnRecreate = -1;
    int scrollToOffsetOnRecreate = 0;
    for (int a = 0; a < viewPages.length; a++) {
        if (a == 0) {
            if (viewPages[a] != null && viewPages[a].layoutManager != null) {
                scrollToPositionOnRecreate = viewPages[a].layoutManager.findFirstVisibleItemPosition();
                if (scrollToPositionOnRecreate != viewPages[a].layoutManager.getItemCount() - 1) {
                    RecyclerListView.Holder holder = (RecyclerListView.Holder) viewPages[a].listView.findViewHolderForAdapterPosition(scrollToPositionOnRecreate);
                    if (holder != null) {
                        scrollToOffsetOnRecreate = holder.itemView.getTop();
                    } else {
                        scrollToPositionOnRecreate = -1;
                    }
                } else {
                    scrollToPositionOnRecreate = -1;
                }
            }
        }
        final ViewPage ViewPage = new ViewPage(context) {

            @Override
            public void setTranslationX(float translationX) {
                super.setTranslationX(translationX);
                if (tabsAnimationInProgress) {
                    if (viewPages[0] == this) {
                        float scrollProgress = Math.abs(viewPages[0].getTranslationX()) / (float) viewPages[0].getMeasuredWidth();
                        scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                    }
                }
            }
        };
        frameLayout.addView(ViewPage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        viewPages[a] = ViewPage;
        final LinearLayoutManager layoutManager = viewPages[a].layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {

            @Override
            public boolean supportsPredictiveItemAnimations() {
                return false;
            }
        };
        RecyclerListView listView = new RecyclerListView(context);
        viewPages[a].listView = listView;
        viewPages[a].listView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
        viewPages[a].listView.setItemAnimator(null);
        viewPages[a].listView.setClipToPadding(false);
        viewPages[a].listView.setSectionsType(2);
        viewPages[a].listView.setLayoutManager(layoutManager);
        viewPages[a].addView(viewPages[a].listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        viewPages[a].listView.setOnItemClickListener((view, position) -> {
            if (getParentActivity() == null) {
                return;
            }
            ListAdapter adapter = (ListAdapter) listView.getAdapter();
            if (position == adapter.resetRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("ResetStatisticsAlertTitle", R.string.ResetStatisticsAlertTitle));
                builder.setMessage(LocaleController.getString("ResetStatisticsAlert", R.string.ResetStatisticsAlert));
                builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
                    StatsController.getInstance(currentAccount).resetStats(adapter.currentType);
                    adapter.notifyDataSetChanged();
                });
                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));
                }
            }
        });
        viewPages[a].listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState != RecyclerView.SCROLL_STATE_DRAGGING) {
                    int scrollY = (int) -actionBar.getTranslationY();
                    int actionBarHeight = ActionBar.getCurrentActionBarHeight();
                    if (scrollY != 0 && scrollY != actionBarHeight) {
                        if (scrollY < actionBarHeight / 2) {
                            viewPages[0].listView.smoothScrollBy(0, -scrollY);
                        } else {
                            viewPages[0].listView.smoothScrollBy(0, actionBarHeight - scrollY);
                        }
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (recyclerView == viewPages[0].listView) {
                    float currentTranslation = actionBar.getTranslationY();
                    float newTranslation = currentTranslation - dy;
                    if (newTranslation < -ActionBar.getCurrentActionBarHeight()) {
                        newTranslation = -ActionBar.getCurrentActionBarHeight();
                    } else if (newTranslation > 0) {
                        newTranslation = 0;
                    }
                    if (newTranslation != currentTranslation) {
                        setScrollY(newTranslation);
                    }
                }
            }
        });
        if (a == 0 && scrollToPositionOnRecreate != -1) {
            layoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
        }
        if (a != 0) {
            viewPages[a].setVisibility(View.GONE);
        }
    }
    frameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    updateTabs();
    switchToCurrentSelectedMode(false);
    swipeBackEnabled = scrollSlidingTextTabStrip.getCurrentTabId() == scrollSlidingTextTabStrip.getFirstTabId();
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) AnimatorSet(android.animation.AnimatorSet) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ViewConfiguration(android.view.ViewConfiguration) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView) ScrollSlidingTextTabStrip(org.telegram.ui.Components.ScrollSlidingTextTabStrip) ActionBar(org.telegram.ui.ActionBar.ActionBar) VelocityTracker(android.view.VelocityTracker) Canvas(android.graphics.Canvas) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 40 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog 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)

Aggregations

AlertDialog (org.telegram.ui.ActionBar.AlertDialog)101 TLRPC (org.telegram.tgnet.TLRPC)71 TextView (android.widget.TextView)63 FrameLayout (android.widget.FrameLayout)47 ArrayList (java.util.ArrayList)47 Context (android.content.Context)45 View (android.view.View)44 AndroidUtilities (org.telegram.messenger.AndroidUtilities)41 LocaleController (org.telegram.messenger.LocaleController)41 Theme (org.telegram.ui.ActionBar.Theme)41 R (org.telegram.messenger.R)40 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)40 LinearLayout (android.widget.LinearLayout)38 Paint (android.graphics.Paint)37 MessagesController (org.telegram.messenger.MessagesController)37 SuppressLint (android.annotation.SuppressLint)36 TextUtils (android.text.TextUtils)36 FileLog (org.telegram.messenger.FileLog)36 Build (android.os.Build)34 Gravity (android.view.Gravity)34