Search in sources :

Example 11 with RadioColorCell

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

the class AlertsCreator method createPrioritySelectDialog.

public static Dialog createPrioritySelectDialog(Activity parentActivity, final long dialog_id, final int globalType, final Runnable onSelect) {
    SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
    final int[] selected = new int[1];
    String[] descriptions;
    if (dialog_id != 0) {
        selected[0] = preferences.getInt("priority_" + dialog_id, 3);
        if (selected[0] == 3) {
            selected[0] = 0;
        } else if (selected[0] == 4) {
            selected[0] = 1;
        } else if (selected[0] == 5) {
            selected[0] = 2;
        } else if (selected[0] == 0) {
            selected[0] = 3;
        } else {
            selected[0] = 4;
        }
        descriptions = new String[] { LocaleController.getString("NotificationsPrioritySettings", R.string.NotificationsPrioritySettings), LocaleController.getString("NotificationsPriorityLow", R.string.NotificationsPriorityLow), LocaleController.getString("NotificationsPriorityMedium", R.string.NotificationsPriorityMedium), LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh), LocaleController.getString("NotificationsPriorityUrgent", R.string.NotificationsPriorityUrgent) };
    } else {
        if (globalType == NotificationsController.TYPE_PRIVATE) {
            selected[0] = preferences.getInt("priority_messages", 1);
        } else if (globalType == NotificationsController.TYPE_GROUP) {
            selected[0] = preferences.getInt("priority_group", 1);
        } else if (globalType == NotificationsController.TYPE_CHANNEL) {
            selected[0] = preferences.getInt("priority_channel", 1);
        }
        if (selected[0] == 4) {
            selected[0] = 0;
        } else if (selected[0] == 5) {
            selected[0] = 1;
        } else if (selected[0] == 0) {
            selected[0] = 2;
        } else {
            selected[0] = 3;
        }
        descriptions = new String[] { LocaleController.getString("NotificationsPriorityLow", R.string.NotificationsPriorityLow), LocaleController.getString("NotificationsPriorityMedium", R.string.NotificationsPriorityMedium), LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh), LocaleController.getString("NotificationsPriorityUrgent", R.string.NotificationsPriorityUrgent) };
    }
    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    for (int a = 0; a < descriptions.length; a++) {
        RadioColorCell cell = new RadioColorCell(parentActivity);
        cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
        cell.setTag(a);
        cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
        cell.setTextAndValue(descriptions[a], selected[0] == a);
        linearLayout.addView(cell);
        cell.setOnClickListener(v -> {
            selected[0] = (Integer) v.getTag();
            final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
            SharedPreferences.Editor editor = preferences1.edit();
            if (dialog_id != 0) {
                int option;
                if (selected[0] == 0) {
                    option = 3;
                } else if (selected[0] == 1) {
                    option = 4;
                } else if (selected[0] == 2) {
                    option = 5;
                } else if (selected[0] == 3) {
                    option = 0;
                } else {
                    option = 1;
                }
                editor.putInt("priority_" + dialog_id, option);
                NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannel(dialog_id);
            } else {
                int option;
                if (selected[0] == 0) {
                    option = 4;
                } else if (selected[0] == 1) {
                    option = 5;
                } else if (selected[0] == 2) {
                    option = 0;
                } else {
                    option = 1;
                }
                if (globalType == NotificationsController.TYPE_PRIVATE) {
                    editor.putInt("priority_messages", option);
                    selected[0] = preferences.getInt("priority_messages", 1);
                } else if (globalType == NotificationsController.TYPE_GROUP) {
                    editor.putInt("priority_group", option);
                    selected[0] = preferences.getInt("priority_group", 1);
                } else if (globalType == NotificationsController.TYPE_CHANNEL) {
                    editor.putInt("priority_channel", option);
                    selected[0] = preferences.getInt("priority_channel", 1);
                }
                NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannelGlobal(globalType);
            }
            editor.commit();
            builder.getDismissRunnable().run();
            if (onSelect != null) {
                onSelect.run();
            }
        });
    }
    builder.setTitle(LocaleController.getString("NotificationsImportance", R.string.NotificationsImportance));
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder.create();
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SharedPreferences(android.content.SharedPreferences) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 12 with RadioColorCell

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

the class AlertsCreator method createColorSelectDialog.

public static Dialog createColorSelectDialog(Activity parentActivity, final long dialog_id, final int globalType, final Runnable onSelect) {
    int currentColor;
    SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
    if (dialog_id != 0) {
        if (preferences.contains("color_" + dialog_id)) {
            currentColor = preferences.getInt("color_" + dialog_id, 0xff0000ff);
        } else {
            if (DialogObject.isChatDialog(dialog_id)) {
                currentColor = preferences.getInt("GroupLed", 0xff0000ff);
            } else {
                currentColor = preferences.getInt("MessagesLed", 0xff0000ff);
            }
        }
    } else if (globalType == NotificationsController.TYPE_PRIVATE) {
        currentColor = preferences.getInt("MessagesLed", 0xff0000ff);
    } else if (globalType == NotificationsController.TYPE_GROUP) {
        currentColor = preferences.getInt("GroupLed", 0xff0000ff);
    } else {
        currentColor = preferences.getInt("ChannelLed", 0xff0000ff);
    }
    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    String[] descriptions = new String[] { LocaleController.getString("ColorRed", R.string.ColorRed), LocaleController.getString("ColorOrange", R.string.ColorOrange), LocaleController.getString("ColorYellow", R.string.ColorYellow), LocaleController.getString("ColorGreen", R.string.ColorGreen), LocaleController.getString("ColorCyan", R.string.ColorCyan), LocaleController.getString("ColorBlue", R.string.ColorBlue), LocaleController.getString("ColorViolet", R.string.ColorViolet), LocaleController.getString("ColorPink", R.string.ColorPink), LocaleController.getString("ColorWhite", R.string.ColorWhite) };
    final int[] selectedColor = new int[] { currentColor };
    for (int a = 0; a < 9; a++) {
        RadioColorCell cell = new RadioColorCell(parentActivity);
        cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
        cell.setTag(a);
        cell.setCheckColor(TextColorCell.colors[a], TextColorCell.colors[a]);
        cell.setTextAndValue(descriptions[a], currentColor == TextColorCell.colorsToSave[a]);
        linearLayout.addView(cell);
        cell.setOnClickListener(v -> {
            int count = linearLayout.getChildCount();
            for (int a1 = 0; a1 < count; a1++) {
                RadioColorCell cell1 = (RadioColorCell) linearLayout.getChildAt(a1);
                cell1.setChecked(cell1 == v, true);
            }
            selectedColor[0] = TextColorCell.colorsToSave[(Integer) v.getTag()];
        });
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), (dialogInterface, which) -> {
        final SharedPreferences preferences1 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
        SharedPreferences.Editor editor = preferences1.edit();
        if (dialog_id != 0) {
            editor.putInt("color_" + dialog_id, selectedColor[0]);
            NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannel(dialog_id);
        } else {
            if (globalType == NotificationsController.TYPE_PRIVATE) {
                editor.putInt("MessagesLed", selectedColor[0]);
            } else if (globalType == NotificationsController.TYPE_GROUP) {
                editor.putInt("GroupLed", selectedColor[0]);
            } else {
                editor.putInt("ChannelLed", selectedColor[0]);
            }
            NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannelGlobal(globalType);
        }
        editor.commit();
        if (onSelect != null) {
            onSelect.run();
        }
    });
    builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), (dialog, which) -> {
        final SharedPreferences preferences12 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
        SharedPreferences.Editor editor = preferences12.edit();
        if (dialog_id != 0) {
            editor.putInt("color_" + dialog_id, 0);
        } else if (globalType == NotificationsController.TYPE_PRIVATE) {
            editor.putInt("MessagesLed", 0);
        } else if (globalType == NotificationsController.TYPE_GROUP) {
            editor.putInt("GroupLed", 0);
        } else {
            editor.putInt("ChannelLed", 0);
        }
        editor.commit();
        if (onSelect != null) {
            onSelect.run();
        }
    });
    if (dialog_id != 0) {
        builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), (dialog, which) -> {
            final SharedPreferences preferences13 = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
            SharedPreferences.Editor editor = preferences13.edit();
            editor.remove("color_" + dialog_id);
            editor.commit();
            if (onSelect != null) {
                onSelect.run();
            }
        });
    }
    return builder.create();
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SharedPreferences(android.content.SharedPreferences) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) SuppressLint(android.annotation.SuppressLint) LinearLayout(android.widget.LinearLayout)

Aggregations

LinearLayout (android.widget.LinearLayout)12 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)12 RadioColorCell (org.telegram.ui.Cells.RadioColorCell)12 SpannableStringBuilder (android.text.SpannableStringBuilder)10 SuppressLint (android.annotation.SuppressLint)9 SpannableString (android.text.SpannableString)7 SharedPreferences (android.content.SharedPreferences)6 View (android.view.View)5 TextView (android.widget.TextView)5 FrameLayout (android.widget.FrameLayout)4 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 ArrayList (java.util.ArrayList)4 TLRPC (org.telegram.tgnet.TLRPC)4 ActionBar (org.telegram.ui.ActionBar.ActionBar)4 RecyclerListView (org.telegram.ui.Components.RecyclerListView)4 Context (android.content.Context)3 DialogInterface (android.content.DialogInterface)3 ViewGroup (android.view.ViewGroup)3 AndroidUtilities (org.telegram.messenger.AndroidUtilities)3