Search in sources :

Example 1 with CheckBoxSquare

use of org.telegram.ui.Components.CheckBoxSquare in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupCallActivity method onLeaveClick.

public static void onLeaveClick(Context context, Runnable onLeave, boolean fromOverlayWindow) {
    VoIPService service = VoIPService.getSharedInstance();
    if (service == null) {
        return;
    }
    TLRPC.Chat currentChat = service.getChat();
    ChatObject.Call call = service.groupCall;
    long selfId = service.getSelfId();
    if (!ChatObject.canManageCalls(currentChat)) {
        processOnLeave(call, false, selfId, onLeave);
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (ChatObject.isChannelOrGiga(currentChat)) {
        builder.setTitle(LocaleController.getString("VoipChannelLeaveAlertTitle", R.string.VoipChannelLeaveAlertTitle));
        builder.setMessage(LocaleController.getString("VoipChannelLeaveAlertText", R.string.VoipChannelLeaveAlertText));
    } else {
        builder.setTitle(LocaleController.getString("VoipGroupLeaveAlertTitle", R.string.VoipGroupLeaveAlertTitle));
        builder.setMessage(LocaleController.getString("VoipGroupLeaveAlertText", R.string.VoipGroupLeaveAlertText));
    }
    int currentAccount = service.getAccount();
    CheckBoxCell[] cells = new CheckBoxCell[1];
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    cells[0] = new CheckBoxCell(context, 1);
    cells[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
    if (fromOverlayWindow) {
        cells[0].setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    } else {
        cells[0].setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
        CheckBoxSquare checkBox = (CheckBoxSquare) cells[0].getCheckBoxView();
        checkBox.setColors(Theme.key_voipgroup_mutedIcon, Theme.key_voipgroup_listeningText, Theme.key_voipgroup_nameText);
    }
    cells[0].setTag(0);
    if (ChatObject.isChannelOrGiga(currentChat)) {
        cells[0].setText(LocaleController.getString("VoipChannelLeaveAlertEndChat", R.string.VoipChannelLeaveAlertEndChat), "", false, false);
    } else {
        cells[0].setText(LocaleController.getString("VoipGroupLeaveAlertEndChat", R.string.VoipGroupLeaveAlertEndChat), "", false, false);
    }
    cells[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
    linearLayout.addView(cells[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    cells[0].setOnClickListener(v -> {
        Integer num = (Integer) v.getTag();
        cells[num].setChecked(!cells[num].isChecked(), true);
    });
    builder.setCustomViewOffset(12);
    builder.setView(linearLayout);
    builder.setDialogButtonColorKey(Theme.key_voipgroup_listeningText);
    builder.setPositiveButton(LocaleController.getString("VoipGroupLeave", R.string.VoipGroupLeave), (dialogInterface, position) -> processOnLeave(call, cells[0].isChecked(), selfId, onLeave));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    if (fromOverlayWindow) {
        builder.setDimEnabled(false);
    }
    AlertDialog dialog = builder.create();
    if (fromOverlayWindow) {
        if (Build.VERSION.SDK_INT >= 26) {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        }
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }
    if (!fromOverlayWindow) {
        dialog.setBackgroundColor(Theme.getColor(Theme.key_voipgroup_dialogBackground));
    }
    dialog.show();
    if (!fromOverlayWindow) {
        TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
        if (button != null) {
            button.setTextColor(Theme.getColor(Theme.key_voipgroup_leaveCallMenu));
        }
        dialog.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) CheckBoxSquare(org.telegram.ui.Components.CheckBoxSquare) ChatObject(org.telegram.messenger.ChatObject) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) VoIPService(org.telegram.messenger.voip.VoIPService)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 ChatObject (org.telegram.messenger.ChatObject)1 VoIPService (org.telegram.messenger.voip.VoIPService)1 TLRPC (org.telegram.tgnet.TLRPC)1 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)1 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)1 CheckBoxCell (org.telegram.ui.Cells.CheckBoxCell)1 CheckBoxSquare (org.telegram.ui.Components.CheckBoxSquare)1