Search in sources :

Example 16 with CheckBoxCell

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

the class AlertsCreator method createClearDaysDialogAlert.

public static void createClearDaysDialogAlert(BaseFragment fragment, int days, TLRPC.User user, MessagesStorage.BooleanCallback onProcessRunnable, Theme.ResourcesProvider resourcesProvider) {
    if (fragment == null || fragment.getParentActivity() == 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);
    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());
            }
        }
    };
    builder.setView(frameLayout);
    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(LocaleController.formatPluralString("DeleteDays", days));
    frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 11, 24, 0));
    frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 48, 24, 18));
    messageTextView.setText(LocaleController.getString("DeleteHistoryByDaysMessage", R.string.DeleteHistoryByDaysMessage));
    final boolean[] deleteForAll = new boolean[] { false };
    if (user.id != selfUserId) {
        cell[0] = new CheckBoxCell(context, 1, resourcesProvider);
        cell[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        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].setChecked(false, false);
        cell[0].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            deleteForAll[0] = !deleteForAll[0];
            cell1.setChecked(deleteForAll[0], true);
        });
    }
    builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
        onProcessRunnable.run(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) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) SpannableStringBuilder(android.text.SpannableStringBuilder) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 17 with CheckBoxCell

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

the class AlertsCreator method createBlockDialogAlert.

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));
    }
}
Also used : Context(android.content.Context) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) SpannableStringBuilder(android.text.SpannableStringBuilder) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 18 with CheckBoxCell

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

the class AlertsCreator method showBlockReportSpamAlert.

public static void showBlockReportSpamAlert(BaseFragment fragment, long dialog_id, TLRPC.User currentUser, TLRPC.Chat currentChat, TLRPC.EncryptedChat encryptedChat, boolean isLocation, TLRPC.ChatFull chatInfo, MessagesStorage.IntCallback callback, Theme.ResourcesProvider resourcesProvider) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    AccountInstance accountInstance = fragment.getAccountInstance();
    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity(), resourcesProvider);
    CharSequence reportText;
    CheckBoxCell[] cells;
    SharedPreferences preferences = MessagesController.getNotificationsSettings(fragment.getCurrentAccount());
    boolean showReport = encryptedChat != null || preferences.getBoolean("dialog_bar_report" + dialog_id, false);
    if (currentUser != null) {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, UserObject.getFirstName(currentUser)));
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserAlert", R.string.BlockUserAlert, UserObject.getFirstName(currentUser))));
        reportText = LocaleController.getString("BlockContact", R.string.BlockContact);
        cells = new CheckBoxCell[2];
        LinearLayout linearLayout = new LinearLayout(fragment.getParentActivity());
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        for (int a = 0; a < 2; a++) {
            if (a == 0 && !showReport) {
                continue;
            }
            cells[a] = new CheckBoxCell(fragment.getParentActivity(), 1, resourcesProvider);
            cells[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
            cells[a].setTag(a);
            if (a == 0) {
                cells[a].setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", true, false);
            } else {
                cells[a].setText(LocaleController.formatString("DeleteThisChat", R.string.DeleteThisChat), "", true, false);
            }
            cells[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
            linearLayout.addView(cells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            cells[a].setOnClickListener(v -> {
                Integer num = (Integer) v.getTag();
                cells[num].setChecked(!cells[num].isChecked(), true);
            });
        }
        builder.setCustomViewOffset(12);
        builder.setView(linearLayout);
    } else {
        cells = null;
        if (currentChat != null && isLocation) {
            builder.setTitle(LocaleController.getString("ReportUnrelatedGroup", R.string.ReportUnrelatedGroup));
            if (chatInfo != null && chatInfo.location instanceof TLRPC.TL_channelLocation) {
                TLRPC.TL_channelLocation location = (TLRPC.TL_channelLocation) chatInfo.location;
                builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("ReportUnrelatedGroupText", R.string.ReportUnrelatedGroupText, location.address)));
            } else {
                builder.setMessage(LocaleController.getString("ReportUnrelatedGroupTextNoAddress", R.string.ReportUnrelatedGroupTextNoAddress));
            }
        } else {
            builder.setTitle(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle));
            if (ChatObject.isChannel(currentChat) && !currentChat.megagroup) {
                builder.setMessage(LocaleController.getString("ReportSpamAlertChannel", R.string.ReportSpamAlertChannel));
            } else {
                builder.setMessage(LocaleController.getString("ReportSpamAlertGroup", R.string.ReportSpamAlertGroup));
            }
        }
        reportText = LocaleController.getString("ReportChat", R.string.ReportChat);
    }
    builder.setPositiveButton(reportText, (dialogInterface, i) -> {
        if (currentUser != null) {
            accountInstance.getMessagesController().blockPeer(currentUser.id);
        }
        if (cells == null || cells[0] != null && cells[0].isChecked()) {
            accountInstance.getMessagesController().reportSpam(dialog_id, currentUser, currentChat, encryptedChat, currentChat != null && isLocation);
        }
        if (cells == null || cells[1].isChecked()) {
            if (currentChat != null) {
                if (ChatObject.isNotInChat(currentChat)) {
                    accountInstance.getMessagesController().deleteDialog(dialog_id, 0);
                } else {
                    accountInstance.getMessagesController().deleteParticipantFromChat(-dialog_id, accountInstance.getMessagesController().getUser(accountInstance.getUserConfig().getClientUserId()), null);
                }
            } else {
                accountInstance.getMessagesController().deleteDialog(dialog_id, 0);
            }
            callback.run(1);
        } else {
            callback.run(0);
        }
    });
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    AlertDialog dialog = builder.create();
    fragment.showDialog(dialog);
    TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SharedPreferences(android.content.SharedPreferences) SpannableStringBuilder(android.text.SpannableStringBuilder) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) AccountInstance(org.telegram.messenger.AccountInstance) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

CheckBoxCell (org.telegram.ui.Cells.CheckBoxCell)18 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)16 LinearLayout (android.widget.LinearLayout)15 TextView (android.widget.TextView)14 TLRPC (org.telegram.tgnet.TLRPC)14 SpannableStringBuilder (android.text.SpannableStringBuilder)13 FrameLayout (android.widget.FrameLayout)11 SuppressLint (android.annotation.SuppressLint)10 Context (android.content.Context)9 SharedPreferences (android.content.SharedPreferences)8 View (android.view.View)8 ArrayList (java.util.ArrayList)8 DialogInterface (android.content.DialogInterface)7 Toast (android.widget.Toast)7 AccountInstance (org.telegram.messenger.AccountInstance)7 AndroidUtilities (org.telegram.messenger.AndroidUtilities)7 FileLog (org.telegram.messenger.FileLog)7 LocaleController (org.telegram.messenger.LocaleController)7 MessagesController (org.telegram.messenger.MessagesController)7 R (org.telegram.messenger.R)7