Search in sources :

Example 6 with AccountInstance

use of org.telegram.messenger.AccountInstance 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

AccountInstance (org.telegram.messenger.AccountInstance)6 TLRPC (org.telegram.tgnet.TLRPC)5 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)5 LinearLayout (android.widget.LinearLayout)4 TextView (android.widget.TextView)4 SharedPreferences (android.content.SharedPreferences)3 Uri (android.net.Uri)3 SpannableStringBuilder (android.text.SpannableStringBuilder)3 ArrayList (java.util.ArrayList)3 Manifest (android.Manifest)2 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Context (android.content.Context)2 PackageManager (android.content.pm.PackageManager)2 Paint (android.graphics.Paint)2 Bundle (android.os.Bundle)2 CheckBoxCell (org.telegram.ui.Cells.CheckBoxCell)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1