use of org.telegram.ui.NotificationsCustomSettingsActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method showCustomNotificationsDialog.
public static void showCustomNotificationsDialog(BaseFragment parentFragment, long did, int globalType, ArrayList<NotificationsSettingsActivity.NotificationException> exceptions, int currentAccount, MessagesStorage.IntCallback callback, MessagesStorage.IntCallback resultCallback) {
if (parentFragment == null || parentFragment.getParentActivity() == null) {
return;
}
boolean enabled;
boolean defaultEnabled = NotificationsController.getInstance(currentAccount).isGlobalNotificationsEnabled(did);
String[] descriptions = new String[] { LocaleController.getString("NotificationsTurnOn", R.string.NotificationsTurnOn), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)), did == 0 && parentFragment instanceof NotificationsCustomSettingsActivity ? null : LocaleController.getString("NotificationsCustomize", R.string.NotificationsCustomize), LocaleController.getString("NotificationsTurnOff", R.string.NotificationsTurnOff) };
int[] icons = new int[] { R.drawable.notifications_on, R.drawable.notifications_mute1h, R.drawable.notifications_mute2d, R.drawable.notifications_settings, R.drawable.notifications_off };
final LinearLayout linearLayout = new LinearLayout(parentFragment.getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
for (int a = 0; a < descriptions.length; a++) {
if (descriptions[a] == null) {
continue;
}
TextView textView = new TextView(parentFragment.getParentActivity());
Drawable drawable = parentFragment.getParentActivity().getResources().getDrawable(icons[a]);
if (a == descriptions.length - 1) {
textView.setTextColor(Theme.getColor(Theme.key_dialogTextRed));
drawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogRedIcon), PorterDuff.Mode.MULTIPLY));
} else {
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
drawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogIcon), PorterDuff.Mode.MULTIPLY));
}
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setLines(1);
textView.setMaxLines(1);
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
textView.setTag(a);
textView.setBackgroundDrawable(Theme.getSelectorDrawable(false));
textView.setPadding(AndroidUtilities.dp(24), 0, AndroidUtilities.dp(24), 0);
textView.setSingleLine(true);
textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
textView.setCompoundDrawablePadding(AndroidUtilities.dp(26));
textView.setText(descriptions[a]);
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
textView.setOnClickListener(v -> {
int i = (Integer) v.getTag();
if (i == 0) {
if (did != 0) {
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
SharedPreferences.Editor editor = preferences.edit();
if (defaultEnabled) {
editor.remove("notify2_" + did);
} else {
editor.putInt("notify2_" + did, 0);
}
MessagesStorage.getInstance(currentAccount).setDialogFlags(did, 0);
editor.commit();
TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(did);
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
}
NotificationsController.getInstance(currentAccount).updateServerNotificationsSettings(did);
if (resultCallback != null) {
if (defaultEnabled) {
resultCallback.run(0);
} else {
resultCallback.run(1);
}
}
} else {
NotificationsController.getInstance(currentAccount).setGlobalNotificationsEnabled(globalType, 0);
}
} else if (i == 3) {
if (did != 0) {
Bundle args = new Bundle();
args.putLong("dialog_id", did);
parentFragment.presentFragment(new ProfileNotificationsActivity(args));
} else {
parentFragment.presentFragment(new NotificationsCustomSettingsActivity(globalType, exceptions));
}
} else {
int untilTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
if (i == 1) {
untilTime += 60 * 60;
} else if (i == 2) {
untilTime += 60 * 60 * 48;
} else if (i == 4) {
untilTime = Integer.MAX_VALUE;
}
if (did != 0) {
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
SharedPreferences.Editor editor = preferences.edit();
long flags;
if (i == 4) {
if (!defaultEnabled) {
editor.remove("notify2_" + did);
flags = 0;
} else {
editor.putInt("notify2_" + did, 2);
flags = 1;
}
} else {
editor.putInt("notify2_" + did, 3);
editor.putInt("notifyuntil_" + did, untilTime);
flags = ((long) untilTime << 32) | 1;
}
NotificationsController.getInstance(currentAccount).removeNotificationsForDialog(did);
MessagesStorage.getInstance(currentAccount).setDialogFlags(did, flags);
editor.commit();
TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(did);
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
if (i != 4 || defaultEnabled) {
dialog.notify_settings.mute_until = untilTime;
}
}
NotificationsController.getInstance(currentAccount).updateServerNotificationsSettings(did);
if (resultCallback != null) {
if (i == 4 && !defaultEnabled) {
resultCallback.run(0);
} else {
resultCallback.run(1);
}
}
} else {
if (i == 4) {
NotificationsController.getInstance(currentAccount).setGlobalNotificationsEnabled(globalType, Integer.MAX_VALUE);
} else {
NotificationsController.getInstance(currentAccount).setGlobalNotificationsEnabled(globalType, untilTime);
}
}
}
if (callback != null) {
callback.run(i);
}
builder.getDismissRunnable().run();
int setting = -1;
if (i == 0) {
setting = NotificationsController.SETTING_MUTE_UNMUTE;
} else if (i == 1) {
setting = NotificationsController.SETTING_MUTE_HOUR;
} else if (i == 2) {
setting = NotificationsController.SETTING_MUTE_2_DAYS;
} else if (i == 4) {
setting = NotificationsController.SETTING_MUTE_FOREVER;
}
if (setting >= 0) {
if (BulletinFactory.canShowBulletin(parentFragment)) {
BulletinFactory.createMuteBulletin(parentFragment, setting).show();
}
}
});
}
builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications));
builder.setView(linearLayout);
parentFragment.showDialog(builder.create());
}
Aggregations