Search in sources :

Example 6 with AlertDialog

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

the class AlertsCreator method createThemeCreateDialog.

public static void createThemeCreateDialog(BaseFragment fragment, int type, Theme.ThemeInfo switchToTheme, Theme.ThemeAccent switchToAccent) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    final EditTextBoldCursor editText = new EditTextBoldCursor(context);
    editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("Create", R.string.Create), (dialog, which) -> {
    });
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);
    final TextView message = new TextView(context);
    if (type != 0) {
        message.setText(AndroidUtilities.replaceTags(LocaleController.getString("EnterThemeNameEdit", R.string.EnterThemeNameEdit)));
    } else {
        message.setText(LocaleController.getString("EnterThemeName", R.string.EnterThemeName));
    }
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23), AndroidUtilities.dp(6));
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    linearLayout.addView(message, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    editText.setGravity(Gravity.LEFT | Gravity.TOP);
    editText.setSingleLine(true);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorSize(AndroidUtilities.dp(20));
    editText.setCursorWidth(1.5f);
    editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
    linearLayout.addView(editText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
    editText.setOnEditorActionListener((textView, i, keyEvent) -> {
        AndroidUtilities.hideKeyboard(textView);
        return false;
    });
    editText.setText(generateThemeName(switchToAccent));
    editText.setSelection(editText.length());
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    }));
    fragment.showDialog(alertDialog);
    editText.requestFocus();
    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (fragment.getParentActivity() == null) {
            return;
        }
        if (editText.length() == 0) {
            Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator != null) {
                vibrator.vibrate(200);
            }
            AndroidUtilities.shakeView(editText, 2, 0);
            return;
        }
        if (fragment instanceof ThemePreviewActivity) {
            Theme.applyPreviousTheme();
            fragment.finishFragment();
        }
        if (switchToAccent != null) {
            switchToTheme.setCurrentAccentId(switchToAccent.id);
            Theme.refreshThemeColors();
            Utilities.searchQueue.postRunnable(() -> AndroidUtilities.runOnUIThread(() -> processCreate(editText, alertDialog, fragment)));
            return;
        }
        processCreate(editText, alertDialog, fragment);
    });
}
Also used : Context(android.content.Context) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) TextView(android.widget.TextView) Vibrator(android.os.Vibrator) ThemePreviewActivity(org.telegram.ui.ThemePreviewActivity) LinearLayout(android.widget.LinearLayout)

Example 7 with AlertDialog

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

the class AlertsCreator method createClearOrDeleteDialogAlert.

public static void createClearOrDeleteDialogAlert(BaseFragment fragment, boolean clear, boolean admin, boolean second, TLRPC.Chat chat, TLRPC.User user, boolean secret, boolean checkDeleteForAll, MessagesStorage.BooleanCallback onProcessRunnable, Theme.ResourcesProvider resourcesProvider) {
    if (fragment == null || fragment.getParentActivity() == null || chat == null && user == null) {
        return;
    }
    int account = fragment.getCurrentAccount();
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context, resourcesProvider);
    long selfUserId = UserConfig.getInstance(account).getClientUserId();
    CheckBoxCell[] cell = new CheckBoxCell[1];
    TextView messageTextView = new TextView(context);
    messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    boolean clearingCache = ChatObject.isChannel(chat) && !TextUtils.isEmpty(chat.username);
    FrameLayout frameLayout = new FrameLayout(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            if (cell[0] != null) {
                setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + cell[0].getMeasuredHeight() + AndroidUtilities.dp(7));
            }
        }
    };
    builder.setView(frameLayout);
    AvatarDrawable avatarDrawable = new AvatarDrawable();
    avatarDrawable.setTextSize(AndroidUtilities.dp(12));
    BackupImageView imageView = new BackupImageView(context);
    imageView.setRoundRadius(AndroidUtilities.dp(20));
    frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
    TextView textView = new TextView(context);
    textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    if (clear) {
        if (clearingCache) {
            textView.setText(LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache));
        } else {
            textView.setText(LocaleController.getString("ClearHistory", R.string.ClearHistory));
        }
    } else {
        if (admin) {
            if (ChatObject.isChannel(chat)) {
                if (chat.megagroup) {
                    textView.setText(LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu));
                } else {
                    textView.setText(LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu));
                }
            } else {
                textView.setText(LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu));
            }
        } else {
            if (chat != null) {
                if (ChatObject.isChannel(chat)) {
                    if (chat.megagroup) {
                        textView.setText(LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu));
                    } else {
                        textView.setText(LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu));
                    }
                } else {
                    textView.setText(LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu));
                }
            } else {
                textView.setText(LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser));
            }
        }
    }
    frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
    frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
    boolean canRevokeInbox = user != null && !user.bot && user.id != selfUserId && MessagesController.getInstance(account).canRevokePmInbox;
    int revokeTimeLimit;
    if (user != null) {
        revokeTimeLimit = MessagesController.getInstance(account).revokeTimePmLimit;
    } else {
        revokeTimeLimit = MessagesController.getInstance(account).revokeTimeLimit;
    }
    boolean canDeleteInbox = !secret && user != null && canRevokeInbox && revokeTimeLimit == 0x7fffffff;
    final boolean[] deleteForAll = new boolean[1];
    boolean deleteChatForAll = false;
    if (!second && (secret && !clear || canDeleteInbox) && !UserObject.isDeleted(user) || (deleteChatForAll = checkDeleteForAll && !clear && chat != null && chat.creator)) {
        cell[0] = new CheckBoxCell(context, 1, resourcesProvider);
        cell[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (deleteChatForAll) {
            if (ChatObject.isChannel(chat) && !chat.megagroup) {
                cell[0].setText(LocaleController.getString("DeleteChannelForAll", R.string.DeleteChannelForAll), "", false, false);
            } else {
                cell[0].setText(LocaleController.getString("DeleteGroupForAll", R.string.DeleteGroupForAll), "", false, false);
            }
        } else if (clear) {
            cell[0].setText(LocaleController.formatString("ClearHistoryOptionAlso", R.string.ClearHistoryOptionAlso, UserObject.getFirstName(user)), "", false, false);
        } else {
            cell[0].setText(LocaleController.formatString("DeleteMessagesOptionAlso", R.string.DeleteMessagesOptionAlso, UserObject.getFirstName(user)), "", false, false);
        }
        cell[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        frameLayout.addView(cell[0], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 0));
        cell[0].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            deleteForAll[0] = !deleteForAll[0];
            cell1.setChecked(deleteForAll[0], true);
        });
    }
    if (user != null) {
        if (UserObject.isReplyUser(user)) {
            avatarDrawable.setSmallSize(true);
            avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
            imageView.setImage(null, null, avatarDrawable, user);
        } else if (user.id == selfUserId) {
            avatarDrawable.setSmallSize(true);
            avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
            imageView.setImage(null, null, avatarDrawable, user);
        } else {
            avatarDrawable.setSmallSize(false);
            avatarDrawable.setInfo(user);
            imageView.setForUserOrChat(user, avatarDrawable);
        }
    } else {
        avatarDrawable.setInfo(chat);
        imageView.setForUserOrChat(chat, avatarDrawable);
    }
    if (second) {
        if (UserObject.isUserSelf(user)) {
            messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllMessagesSavedAlert", R.string.DeleteAllMessagesSavedAlert)));
        } else {
            messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllMessagesAlert", R.string.DeleteAllMessagesAlert)));
        }
    } else {
        if (clear) {
            if (user != null) {
                if (secret) {
                    messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithSecretUser", R.string.AreYouSureClearHistoryWithSecretUser, UserObject.getUserName(user))));
                } else {
                    if (user.id == selfUserId) {
                        messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("AreYouSureClearHistorySavedMessages", R.string.AreYouSureClearHistorySavedMessages)));
                    } else {
                        messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithUser", R.string.AreYouSureClearHistoryWithUser, UserObject.getUserName(user))));
                    }
                }
            } else {
                if (!ChatObject.isChannel(chat) || chat.megagroup && TextUtils.isEmpty(chat.username)) {
                    messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithChat", R.string.AreYouSureClearHistoryWithChat, chat.title)));
                } else if (chat.megagroup) {
                    messageTextView.setText(LocaleController.getString("AreYouSureClearHistoryGroup", R.string.AreYouSureClearHistoryGroup));
                } else {
                    messageTextView.setText(LocaleController.getString("AreYouSureClearHistoryChannel", R.string.AreYouSureClearHistoryChannel));
                }
            }
        } else {
            if (admin) {
                if (ChatObject.isChannel(chat)) {
                    if (chat.megagroup) {
                        messageTextView.setText(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
                    } else {
                        messageTextView.setText(LocaleController.getString("AreYouSureDeleteAndExitChannel", R.string.AreYouSureDeleteAndExitChannel));
                    }
                } else {
                    messageTextView.setText(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
                }
            } else {
                if (user != null) {
                    if (secret) {
                        messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithSecretUser", R.string.AreYouSureDeleteThisChatWithSecretUser, UserObject.getUserName(user))));
                    } else {
                        if (user.id == selfUserId) {
                            messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("AreYouSureDeleteThisChatSavedMessages", R.string.AreYouSureDeleteThisChatSavedMessages)));
                        } else {
                            if (user.bot && !user.support) {
                                messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithBot", R.string.AreYouSureDeleteThisChatWithBot, UserObject.getUserName(user))));
                            } else {
                                messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithUser", R.string.AreYouSureDeleteThisChatWithUser, UserObject.getUserName(user))));
                            }
                        }
                    }
                } else if (ChatObject.isChannel(chat)) {
                    if (chat.megagroup) {
                        messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("MegaLeaveAlertWithName", R.string.MegaLeaveAlertWithName, chat.title)));
                    } else {
                        messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ChannelLeaveAlertWithName", R.string.ChannelLeaveAlertWithName, chat.title)));
                    }
                } else {
                    messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteAndExitName", R.string.AreYouSureDeleteAndExitName, chat.title)));
                }
            }
        }
    }
    String actionText;
    if (second) {
        actionText = LocaleController.getString("DeleteAll", R.string.DeleteAll);
    } else {
        if (clear) {
            if (clearingCache) {
                actionText = LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache);
            } else {
                actionText = LocaleController.getString("ClearHistory", R.string.ClearHistory);
            }
        } else {
            if (admin) {
                if (ChatObject.isChannel(chat)) {
                    if (chat.megagroup) {
                        actionText = LocaleController.getString("DeleteMega", R.string.DeleteMega);
                    } else {
                        actionText = LocaleController.getString("ChannelDelete", R.string.ChannelDelete);
                    }
                } else {
                    actionText = LocaleController.getString("DeleteMega", R.string.DeleteMega);
                }
            } else {
                if (ChatObject.isChannel(chat)) {
                    if (chat.megagroup) {
                        actionText = LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu);
                    } else {
                        actionText = LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu);
                    }
                } else {
                    actionText = LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser);
                }
            }
        }
    }
    builder.setPositiveButton(actionText, (dialogInterface, i) -> {
        if (!clearingCache && !second && !secret) {
            if (UserObject.isUserSelf(user)) {
                createClearOrDeleteDialogAlert(fragment, clear, admin, true, chat, user, false, checkDeleteForAll, onProcessRunnable, resourcesProvider);
                return;
            } else if (user != null && deleteForAll[0]) {
                MessagesStorage.getInstance(fragment.getCurrentAccount()).getMessagesCount(user.id, (count) -> {
                    if (count >= 50) {
                        createClearOrDeleteDialogAlert(fragment, clear, admin, true, chat, user, false, checkDeleteForAll, onProcessRunnable, resourcesProvider);
                    } else {
                        if (onProcessRunnable != null) {
                            onProcessRunnable.run(deleteForAll[0]);
                        }
                    }
                });
                return;
            }
        }
        if (onProcessRunnable != null) {
            onProcessRunnable.run(second || deleteForAll[0]);
        }
    });
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    AlertDialog alertDialog = builder.create();
    fragment.showDialog(alertDialog);
    TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}
Also used : Context(android.content.Context) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Arrays(java.util.Arrays) Bundle(android.os.Bundle) SvgHelper(org.telegram.messenger.SvgHelper) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) Manifest(android.Manifest) NotificationsController(org.telegram.messenger.NotificationsController) CacheControlActivity(org.telegram.ui.CacheControlActivity) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) CountDownLatch(java.util.concurrent.CountDownLatch) LaunchActivity(org.telegram.ui.LaunchActivity) Html(android.text.Html) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) InputFilter(android.text.InputFilter) TextWatcher(android.text.TextWatcher) ChatActivity(org.telegram.ui.ChatActivity) Dialog(android.app.Dialog) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) ThemePreviewActivity(org.telegram.ui.ThemePreviewActivity) Calendar(java.util.Calendar) TLRPC(org.telegram.tgnet.TLRPC) GradientDrawable(android.graphics.drawable.GradientDrawable) Toast(android.widget.Toast) Settings(android.provider.Settings) NotificationsCustomSettingsActivity(org.telegram.ui.NotificationsCustomSettingsActivity) URLSpan(android.text.style.URLSpan) SpannableString(android.text.SpannableString) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) EditText(android.widget.EditText) ProfileNotificationsActivity(org.telegram.ui.ProfileNotificationsActivity) RequiresApi(androidx.annotation.RequiresApi) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) PackageManager(android.content.pm.PackageManager) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LanguageSelectActivity(org.telegram.ui.LanguageSelectActivity) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) TextColorCell(org.telegram.ui.Cells.TextColorCell) Utilities(org.telegram.messenger.Utilities) TooManyCommunitiesActivity(org.telegram.ui.TooManyCommunitiesActivity) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) SecretChatHelper(org.telegram.messenger.SecretChatHelper) EditorInfo(android.view.inputmethod.EditorInfo) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Context(android.content.Context) IDN(java.net.IDN) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) NotificationsSettingsActivity(org.telegram.ui.NotificationsSettingsActivity) Build(android.os.Build) SerializedData(org.telegram.tgnet.SerializedData) DialogInterface(android.content.DialogInterface) Browser(org.telegram.messenger.browser.Browser) LoginActivity(org.telegram.ui.LoginActivity) DialogObject(org.telegram.messenger.DialogObject) FileLog(org.telegram.messenger.FileLog) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) Base64(android.util.Base64) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) Vibrator(android.os.Vibrator) Activity(android.app.Activity) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView)

Example 8 with AlertDialog

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

the class AlertsCreator method createCallDialogAlert.

public static void createCallDialogAlert(BaseFragment fragment, TLRPC.User user, boolean videoCall) {
    if (fragment == null || fragment.getParentActivity() == null || user == null || UserObject.isDeleted(user) || UserConfig.getInstance(fragment.getCurrentAccount()).getClientUserId() == user.id) {
        return;
    }
    final int account = fragment.getCurrentAccount();
    final Context context = fragment.getParentActivity();
    final FrameLayout frameLayout = new FrameLayout(context);
    final String title;
    final String message;
    if (videoCall) {
        title = LocaleController.getString("VideoCallAlertTitle", R.string.VideoCallAlertTitle);
        message = LocaleController.formatString("VideoCallAlert", R.string.VideoCallAlert, UserObject.getUserName(user));
    } else {
        title = LocaleController.getString("CallAlertTitle", R.string.CallAlertTitle);
        message = LocaleController.formatString("CallAlert", R.string.CallAlert, UserObject.getUserName(user));
    }
    TextView messageTextView = new TextView(context);
    messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    messageTextView.setText(AndroidUtilities.replaceTags(message));
    AvatarDrawable avatarDrawable = new AvatarDrawable();
    avatarDrawable.setTextSize(AndroidUtilities.dp(12));
    avatarDrawable.setSmallSize(false);
    avatarDrawable.setInfo(user);
    BackupImageView imageView = new BackupImageView(context);
    imageView.setRoundRadius(AndroidUtilities.dp(20));
    imageView.setForUserOrChat(user, avatarDrawable);
    frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
    TextView textView = new TextView(context);
    textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setText(title);
    frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
    frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
    AlertDialog dialog = new AlertDialog.Builder(context).setView(frameLayout).setPositiveButton(LocaleController.getString("Call", R.string.Call), (dialogInterface, i) -> {
        final TLRPC.UserFull userFull = fragment.getMessagesController().getUserFull(user.id);
        VoIPHelper.startCall(user, videoCall, userFull != null && userFull.video_calls_available, fragment.getParentActivity(), userFull, fragment.getAccountInstance());
    }).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null).create();
    fragment.showDialog(dialog);
}
Also used : Context(android.content.Context) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) FrameLayout(android.widget.FrameLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC)

Example 9 with AlertDialog

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

the class AlertsCreator method createChangeNameAlert.

public static void createChangeNameAlert(long peerId, Context context, int currentAccount) {
    String currentName;
    String currentLastName = null;
    if (DialogObject.isUserDialog(peerId)) {
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(peerId);
        currentName = user.first_name;
        currentLastName = user.last_name;
    } else {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-peerId);
        currentName = chat.title;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(peerId > 0 ? LocaleController.getString("VoipEditName", R.string.VoipEditName) : LocaleController.getString("VoipEditTitle", R.string.VoipEditTitle));
    LinearLayout dialogView = new LinearLayout(context);
    dialogView.setOrientation(LinearLayout.VERTICAL);
    EditText firstNameEditTextView = new EditText(context);
    firstNameEditTextView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
    firstNameEditTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    firstNameEditTextView.setMaxLines(1);
    firstNameEditTextView.setLines(1);
    firstNameEditTextView.setSingleLine(true);
    firstNameEditTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    firstNameEditTextView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    firstNameEditTextView.setImeOptions(peerId > 0 ? EditorInfo.IME_ACTION_NEXT : EditorInfo.IME_ACTION_DONE);
    firstNameEditTextView.setHint(peerId > 0 ? LocaleController.getString("FirstName", R.string.FirstName) : LocaleController.getString("VoipEditTitleHint", R.string.VoipEditTitleHint));
    firstNameEditTextView.setBackground(Theme.createEditTextDrawable(context, true));
    firstNameEditTextView.setPadding(0, AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8));
    firstNameEditTextView.requestFocus();
    EditText lastNameEditTextView = null;
    if (peerId > 0) {
        lastNameEditTextView = new EditText(context);
        lastNameEditTextView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
        lastNameEditTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        lastNameEditTextView.setMaxLines(1);
        lastNameEditTextView.setLines(1);
        lastNameEditTextView.setSingleLine(true);
        lastNameEditTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        lastNameEditTextView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        lastNameEditTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        lastNameEditTextView.setHint(LocaleController.getString("LastName", R.string.LastName));
        lastNameEditTextView.setBackground(Theme.createEditTextDrawable(context, true));
        lastNameEditTextView.setPadding(0, AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8));
    }
    AndroidUtilities.showKeyboard(firstNameEditTextView);
    dialogView.addView(firstNameEditTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 23, 12, 23, 21));
    if (lastNameEditTextView != null) {
        dialogView.addView(lastNameEditTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 23, 12, 23, 21));
    }
    firstNameEditTextView.setText(currentName);
    firstNameEditTextView.setSelection(firstNameEditTextView.getText().toString().length());
    if (lastNameEditTextView != null) {
        lastNameEditTextView.setText(currentLastName);
        lastNameEditTextView.setSelection(lastNameEditTextView.getText().toString().length());
    }
    builder.setView(dialogView);
    EditText finalLastNameEditTextView = lastNameEditTextView;
    DialogInterface.OnClickListener onDoneListener = (dialogInterface, i) -> {
        if (firstNameEditTextView.getText() == null) {
            return;
        }
        if (peerId > 0) {
            TLRPC.User currentUser = MessagesController.getInstance(currentAccount).getUser(peerId);
            String newFirst = firstNameEditTextView.getText().toString();
            String newLast = finalLastNameEditTextView.getText().toString();
            String oldFirst = currentUser.first_name;
            String oldLast = currentUser.last_name;
            if (oldFirst == null) {
                oldFirst = "";
            }
            if (oldLast == null) {
                oldLast = "";
            }
            if (oldFirst.equals(newFirst) && oldLast.equals(newLast)) {
                dialogInterface.dismiss();
                return;
            }
            TLRPC.TL_account_updateProfile req = new TLRPC.TL_account_updateProfile();
            req.flags = 3;
            currentUser.first_name = req.first_name = newFirst;
            currentUser.last_name = req.last_name = newLast;
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());
            if (user != null) {
                user.first_name = req.first_name;
                user.last_name = req.last_name;
            }
            UserConfig.getInstance(currentAccount).saveConfig(true);
            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.mainUserInfoChanged);
            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
            ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
            });
            NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.showBulletin, Bulletin.TYPE_NAME_CHANGED, peerId);
        } else {
            TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-peerId);
            String newFirst = firstNameEditTextView.getText().toString();
            if (chat.title != null && chat.title.equals(newFirst)) {
                dialogInterface.dismiss();
                return;
            }
            chat.title = newFirst;
            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_CHAT_NAME);
            MessagesController.getInstance(currentAccount).changeChatTitle(-peerId, newFirst);
            NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.showBulletin, Bulletin.TYPE_NAME_CHANGED, peerId);
        }
        dialogInterface.dismiss();
    };
    builder.setPositiveButton(LocaleController.getString("Save", R.string.Save), onDoneListener);
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setOnPreDismissListener(dialogInterface -> {
        AndroidUtilities.hideKeyboard(firstNameEditTextView);
        AndroidUtilities.hideKeyboard(finalLastNameEditTextView);
    });
    AlertDialog dialog = builder.create();
    dialog.setBackgroundColor(Theme.getColor(Theme.key_voipgroup_dialogBackground));
    dialog.show();
    dialog.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
    TextView.OnEditorActionListener actionListener = (textView, i, keyEvent) -> {
        if ((i == EditorInfo.IME_ACTION_DONE || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) && dialog.isShowing()) {
            onDoneListener.onClick(dialog, 0);
            return true;
        }
        return false;
    };
    if (lastNameEditTextView != null) {
        lastNameEditTextView.setOnEditorActionListener(actionListener);
    } else {
        firstNameEditTextView.setOnEditorActionListener(actionListener);
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) Arrays(java.util.Arrays) Bundle(android.os.Bundle) SvgHelper(org.telegram.messenger.SvgHelper) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) Manifest(android.Manifest) NotificationsController(org.telegram.messenger.NotificationsController) CacheControlActivity(org.telegram.ui.CacheControlActivity) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) CountDownLatch(java.util.concurrent.CountDownLatch) LaunchActivity(org.telegram.ui.LaunchActivity) Html(android.text.Html) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) InputFilter(android.text.InputFilter) TextWatcher(android.text.TextWatcher) ChatActivity(org.telegram.ui.ChatActivity) Dialog(android.app.Dialog) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) ThemePreviewActivity(org.telegram.ui.ThemePreviewActivity) Calendar(java.util.Calendar) TLRPC(org.telegram.tgnet.TLRPC) GradientDrawable(android.graphics.drawable.GradientDrawable) Toast(android.widget.Toast) Settings(android.provider.Settings) NotificationsCustomSettingsActivity(org.telegram.ui.NotificationsCustomSettingsActivity) URLSpan(android.text.style.URLSpan) SpannableString(android.text.SpannableString) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) EditText(android.widget.EditText) ProfileNotificationsActivity(org.telegram.ui.ProfileNotificationsActivity) RequiresApi(androidx.annotation.RequiresApi) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) PackageManager(android.content.pm.PackageManager) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LanguageSelectActivity(org.telegram.ui.LanguageSelectActivity) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) TextColorCell(org.telegram.ui.Cells.TextColorCell) Utilities(org.telegram.messenger.Utilities) TooManyCommunitiesActivity(org.telegram.ui.TooManyCommunitiesActivity) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) SecretChatHelper(org.telegram.messenger.SecretChatHelper) EditorInfo(android.view.inputmethod.EditorInfo) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Context(android.content.Context) IDN(java.net.IDN) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) NotificationsSettingsActivity(org.telegram.ui.NotificationsSettingsActivity) Build(android.os.Build) SerializedData(org.telegram.tgnet.SerializedData) DialogInterface(android.content.DialogInterface) Browser(org.telegram.messenger.browser.Browser) LoginActivity(org.telegram.ui.LoginActivity) DialogObject(org.telegram.messenger.DialogObject) FileLog(org.telegram.messenger.FileLog) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) Base64(android.util.Base64) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) Vibrator(android.os.Vibrator) Activity(android.app.Activity) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 10 with AlertDialog

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

the class ChangePhoneActivity method needShowProgress.

public void needShowProgress() {
    if (getParentActivity() == null || getParentActivity().isFinishing() || progressDialog != null) {
        return;
    }
    progressDialog = new AlertDialog(getParentActivity(), 3);
    progressDialog.setCanCacnel(false);
    progressDialog.show();
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog)

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