Java Code Examples for org.telegram.ui.ActionBar.AlertDialog#getButton()

The following examples show how to use org.telegram.ui.ActionBar.AlertDialog#getButton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogOrContactPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void showBlockAlert(TLRPC.User user) {
    if (user == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("BlockUser", R.string.BlockUser));
    builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureBlockContact2", R.string.AreYouSureBlockContact2, ContactsController.formatName(user.first_name, user.last_name))));
    builder.setPositiveButton(LocaleController.getString("BlockContact", R.string.BlockContact), (dialogInterface, i) -> {
        if (MessagesController.isSupportUser(user)) {
            AlertsCreator.showSimpleToast(DialogOrContactPickerActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
        } else {
            MessagesController.getInstance(currentAccount).blockUser(user.id);
            AlertsCreator.showSimpleToast(DialogOrContactPickerActivity.this, LocaleController.getString("UserBlocked", R.string.UserBlocked));
        }
        finishFragment();
    });
    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));
    }
}
 
Example 2
Source File: DialogOrContactPickerActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void showBlockAlert(TLRPC.User user) {
    if (user == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("BlockUser", R.string.BlockUser));
    builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureBlockContact2", R.string.AreYouSureBlockContact2, ContactsController.formatName(user.first_name, user.last_name))));
    builder.setPositiveButton(LocaleController.getString("BlockContact", R.string.BlockContact), (dialogInterface, i) -> {
        if (MessagesController.isSupportUser(user)) {
            AlertsCreator.showSimpleToast(DialogOrContactPickerActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
        } else {
            MessagesController.getInstance(currentAccount).blockUser(user.id);
            AlertsCreator.showSimpleToast(DialogOrContactPickerActivity.this, LocaleController.getString("UserBlocked", R.string.UserBlocked));
        }
        finishFragment();
    });
    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));
    }
}
 
Example 3
Source File: FilterCreateActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void showRemoveAlert(int position, CharSequence name, Object object, boolean include) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    if (include) {
        builder.setTitle(LocaleController.getString("FilterRemoveInclusionTitle", R.string.FilterRemoveInclusionTitle));
        if (object instanceof String) {
            builder.setMessage(LocaleController.formatString("FilterRemoveInclusionText", R.string.FilterRemoveInclusionText, name));
        } else if (object instanceof TLRPC.User) {
            builder.setMessage(LocaleController.formatString("FilterRemoveInclusionUserText", R.string.FilterRemoveInclusionUserText, name));
        } else {
            builder.setMessage(LocaleController.formatString("FilterRemoveInclusionChatText", R.string.FilterRemoveInclusionChatText, name));
        }
    } else {
        builder.setTitle(LocaleController.getString("FilterRemoveExclusionTitle", R.string.FilterRemoveExclusionTitle));
        if (object instanceof String) {
            builder.setMessage(LocaleController.formatString("FilterRemoveExclusionText", R.string.FilterRemoveExclusionText, name));
        } else if (object instanceof TLRPC.User) {
            builder.setMessage(LocaleController.formatString("FilterRemoveExclusionUserText", R.string.FilterRemoveExclusionUserText, name));
        } else {
            builder.setMessage(LocaleController.formatString("FilterRemoveExclusionChatText", R.string.FilterRemoveExclusionChatText, name));
        }
    }
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("StickersRemove", R.string.StickersRemove), (dialogInterface, i) -> {
        if (position == includeContactsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_CONTACTS;
        } else if (position == includeNonContactsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS;
        } else if (position == includeGroupsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_GROUPS;
        } else if (position == includeChannelsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_CHANNELS;
        } else if (position == includeBotsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_BOTS;
        } else if (position == excludeArchivedRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED;
        } else if (position == excludeMutedRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED;
        } else if (position == excludeReadRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_READ;
        } else {
            if (include) {
                newAlwaysShow.remove(position - includeStartRow);
            } else {
                newNeverShow.remove(position - excludeStartRow);
            }
        }
        fillFilterName();
        updateRows();
        checkDoneButton(true);
    });
    AlertDialog alertDialog = builder.create();
    showDialog(alertDialog);
    TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}
 
Example 4
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    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));
    }
}
 
Example 5
Source File: FilterCreateActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void showRemoveAlert(int position, CharSequence name, Object object, boolean include) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    if (include) {
        builder.setTitle(LocaleController.getString("FilterRemoveInclusionTitle", R.string.FilterRemoveInclusionTitle));
        if (object instanceof String) {
            builder.setMessage(LocaleController.formatString("FilterRemoveInclusionText", R.string.FilterRemoveInclusionText, name));
        } else if (object instanceof TLRPC.User) {
            builder.setMessage(LocaleController.formatString("FilterRemoveInclusionUserText", R.string.FilterRemoveInclusionUserText, name));
        } else {
            builder.setMessage(LocaleController.formatString("FilterRemoveInclusionChatText", R.string.FilterRemoveInclusionChatText, name));
        }
    } else {
        builder.setTitle(LocaleController.getString("FilterRemoveExclusionTitle", R.string.FilterRemoveExclusionTitle));
        if (object instanceof String) {
            builder.setMessage(LocaleController.formatString("FilterRemoveExclusionText", R.string.FilterRemoveExclusionText, name));
        } else if (object instanceof TLRPC.User) {
            builder.setMessage(LocaleController.formatString("FilterRemoveExclusionUserText", R.string.FilterRemoveExclusionUserText, name));
        } else {
            builder.setMessage(LocaleController.formatString("FilterRemoveExclusionChatText", R.string.FilterRemoveExclusionChatText, name));
        }
    }
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("StickersRemove", R.string.StickersRemove), (dialogInterface, i) -> {
        if (position == includeContactsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_CONTACTS;
        } else if (position == includeNonContactsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS;
        } else if (position == includeGroupsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_GROUPS;
        } else if (position == includeChannelsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_CHANNELS;
        } else if (position == includeBotsRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_BOTS;
        } else if (position == excludeArchivedRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED;
        } else if (position == excludeMutedRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED;
        } else if (position == excludeReadRow) {
            newFilterFlags &=~ MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_READ;
        } else {
            if (include) {
                newAlwaysShow.remove(position - includeStartRow);
            } else {
                newNeverShow.remove(position - excludeStartRow);
            }
        }
        fillFilterName();
        updateRows();
        checkDoneButton(true);
    });
    AlertDialog alertDialog = builder.create();
    showDialog(alertDialog);
    TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}
 
Example 6
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    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));
    }
}