use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createLocationUpdateDialog.
public static Dialog createLocationUpdateDialog(final Activity parentActivity, TLRPC.User user, final MessagesStorage.IntCallback callback, Theme.ResourcesProvider resourcesProvider) {
final int[] selected = new int[1];
String[] descriptions = new String[] { LocaleController.getString("SendLiveLocationFor15m", R.string.SendLiveLocationFor15m), LocaleController.getString("SendLiveLocationFor1h", R.string.SendLiveLocationFor1h), LocaleController.getString("SendLiveLocationFor8h", R.string.SendLiveLocationFor8h) };
final LinearLayout linearLayout = new LinearLayout(parentActivity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView titleTextView = new TextView(parentActivity);
if (user != null) {
titleTextView.setText(LocaleController.formatString("LiveLocationAlertPrivate", R.string.LiveLocationAlertPrivate, UserObject.getFirstName(user)));
} else {
titleTextView.setText(LocaleController.getString("LiveLocationAlertGroup", R.string.LiveLocationAlertGroup));
}
int textColor = resourcesProvider != null ? resourcesProvider.getColorOrDefault(Theme.key_dialogTextBlack) : Theme.getColor(Theme.key_dialogTextBlack);
titleTextView.setTextColor(textColor);
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
titleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
linearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 0, 24, 8));
for (int a = 0; a < descriptions.length; a++) {
RadioColorCell cell = new RadioColorCell(parentActivity, resourcesProvider);
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
cell.setTag(a);
int color1 = resourcesProvider != null ? resourcesProvider.getColorOrDefault(Theme.key_radioBackground) : Theme.getColor(Theme.key_radioBackground);
int color2 = resourcesProvider != null ? resourcesProvider.getColorOrDefault(Theme.key_dialogRadioBackgroundChecked) : Theme.getColor(Theme.key_dialogRadioBackgroundChecked);
cell.setCheckColor(color1, color2);
cell.setTextAndValue(descriptions[a], selected[0] == a);
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
int num = (Integer) v.getTag();
selected[0] = num;
int count = linearLayout.getChildCount();
for (int a1 = 0; a1 < count; a1++) {
View child = linearLayout.getChildAt(a1);
if (child instanceof RadioColorCell) {
((RadioColorCell) child).setChecked(child == v, true);
}
}
});
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity, resourcesProvider);
int topImageColor = resourcesProvider != null ? resourcesProvider.getColorOrDefault(Theme.key_dialogTopBackground) : Theme.getColor(Theme.key_dialogTopBackground);
builder.setTopImage(new ShareLocationDrawable(parentActivity, 0), topImageColor);
builder.setView(linearLayout);
builder.setPositiveButton(LocaleController.getString("ShareFile", R.string.ShareFile), (dialog, which) -> {
int time;
if (selected[0] == 0) {
time = 15 * 60;
} else if (selected[0] == 1) {
time = 60 * 60;
} else {
time = 8 * 60 * 60;
}
callback.run(time);
});
builder.setNeutralButton(LocaleController.getString("Cancel", R.string.Cancel), null);
return builder.create();
}
use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createFreeSpaceDialog.
public static Dialog createFreeSpaceDialog(final LaunchActivity parentActivity) {
final int[] selected = new int[1];
if (SharedConfig.keepMedia == 2) {
selected[0] = 3;
} else if (SharedConfig.keepMedia == 0) {
selected[0] = 1;
} else if (SharedConfig.keepMedia == 1) {
selected[0] = 2;
} else if (SharedConfig.keepMedia == 3) {
selected[0] = 0;
}
String[] descriptions = new String[] { LocaleController.formatPluralString("Days", 3), LocaleController.formatPluralString("Weeks", 1), LocaleController.formatPluralString("Months", 1), LocaleController.getString("LowDiskSpaceNeverRemove", R.string.LowDiskSpaceNeverRemove) };
final LinearLayout linearLayout = new LinearLayout(parentActivity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView titleTextView = new TextView(parentActivity);
titleTextView.setText(LocaleController.getString("LowDiskSpaceTitle2", R.string.LowDiskSpaceTitle2));
titleTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
titleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
linearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 0, 24, 8));
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 -> {
int num = (Integer) v.getTag();
if (num == 0) {
selected[0] = 3;
} else if (num == 1) {
selected[0] = 0;
} else if (num == 2) {
selected[0] = 1;
} else if (num == 3) {
selected[0] = 2;
}
int count = linearLayout.getChildCount();
for (int a1 = 0; a1 < count; a1++) {
View child = linearLayout.getChildAt(a1);
if (child instanceof RadioColorCell) {
((RadioColorCell) child).setChecked(child == v, true);
}
}
});
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("LowDiskSpaceTitle", R.string.LowDiskSpaceTitle));
builder.setMessage(LocaleController.getString("LowDiskSpaceMessage", R.string.LowDiskSpaceMessage));
builder.setView(linearLayout);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> SharedConfig.setKeepMedia(selected[0]));
builder.setNeutralButton(LocaleController.getString("ClearMediaCache", R.string.ClearMediaCache), (dialog, which) -> parentActivity.presentFragment(new CacheControlActivity()));
return builder.create();
}
use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method showSecretLocationAlert.
public static AlertDialog showSecretLocationAlert(Context context, int currentAccount, final Runnable onSelectRunnable, boolean inChat, Theme.ResourcesProvider resourcesProvider) {
ArrayList<String> arrayList = new ArrayList<>();
ArrayList<Integer> types = new ArrayList<>();
int providers = MessagesController.getInstance(currentAccount).availableMapProviders;
if ((providers & 1) != 0) {
arrayList.add(LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram));
types.add(0);
}
if ((providers & 2) != 0) {
arrayList.add(LocaleController.getString("MapPreviewProviderGoogle", R.string.MapPreviewProviderGoogle));
types.add(1);
}
if ((providers & 4) != 0) {
arrayList.add(LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex));
types.add(3);
}
arrayList.add(LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody));
types.add(2);
AlertDialog.Builder builder = new AlertDialog.Builder(context, resourcesProvider);
builder.setTitle(LocaleController.getString("MapPreviewProviderTitle", R.string.MapPreviewProviderTitle));
final LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
for (int a = 0; a < arrayList.size(); a++) {
RadioColorCell cell = new RadioColorCell(context, resourcesProvider);
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(arrayList.get(a), SharedConfig.mapPreviewType == types.get(a));
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
Integer which = (Integer) v.getTag();
SharedConfig.setSecretMapPreviewType(types.get(which));
if (onSelectRunnable != null) {
onSelectRunnable.run();
}
builder.getDismissRunnable().run();
});
}
if (!inChat) {
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
}
AlertDialog dialog = builder.show();
if (inChat) {
dialog.setCanceledOnTouchOutside(false);
}
return dialog;
}
use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createSingleChoiceDialog.
public static Dialog createSingleChoiceDialog(Activity parentActivity, final String[] options, final String title, final int selected, final DialogInterface.OnClickListener listener) {
final LinearLayout linearLayout = new LinearLayout(parentActivity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
for (int a = 0; a < options.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(options[a], selected == a);
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
int sel = (Integer) v.getTag();
builder.getDismissRunnable().run();
listener.onClick(null, sel);
});
}
builder.setTitle(title);
builder.setView(linearLayout);
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
return builder.create();
}
use of org.telegram.ui.Cells.RadioColorCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createVibrationSelectDialog.
public static Dialog createVibrationSelectDialog(Activity parentActivity, final long dialogId, final String prefKeyPrefix, final Runnable onSelect) {
SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
final int[] selected = new int[1];
String[] descriptions;
if (dialogId != 0) {
selected[0] = preferences.getInt(prefKeyPrefix, 0);
if (selected[0] == 3) {
selected[0] = 2;
} else if (selected[0] == 2) {
selected[0] = 3;
}
descriptions = new String[] { LocaleController.getString("VibrationDefault", R.string.VibrationDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long), LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled) };
} else {
selected[0] = preferences.getInt(prefKeyPrefix, 0);
if (selected[0] == 0) {
selected[0] = 1;
} else if (selected[0] == 1) {
selected[0] = 2;
} else if (selected[0] == 2) {
selected[0] = 0;
}
descriptions = new String[] { LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled), LocaleController.getString("VibrationDefault", R.string.VibrationDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long), LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent) };
}
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 (dialogId != 0) {
if (selected[0] == 0) {
editor.putInt(prefKeyPrefix, 0);
} else if (selected[0] == 1) {
editor.putInt(prefKeyPrefix, 1);
} else if (selected[0] == 2) {
editor.putInt(prefKeyPrefix, 3);
} else if (selected[0] == 3) {
editor.putInt(prefKeyPrefix, 2);
}
NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannel(dialogId);
} else {
if (selected[0] == 0) {
editor.putInt(prefKeyPrefix, 2);
} else if (selected[0] == 1) {
editor.putInt(prefKeyPrefix, 0);
} else if (selected[0] == 2) {
editor.putInt(prefKeyPrefix, 1);
} else if (selected[0] == 3) {
editor.putInt(prefKeyPrefix, 3);
} else if (selected[0] == 4) {
editor.putInt(prefKeyPrefix, 4);
}
if (prefKeyPrefix.equals("vibrate_channel")) {
NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannelGlobal(NotificationsController.TYPE_CHANNEL);
} else if (prefKeyPrefix.equals("vibrate_group")) {
NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannelGlobal(NotificationsController.TYPE_GROUP);
} else {
NotificationsController.getInstance(UserConfig.selectedAccount).deleteNotificationChannelGlobal(NotificationsController.TYPE_PRIVATE);
}
}
editor.commit();
builder.getDismissRunnable().run();
if (onSelect != null) {
onSelect.run();
}
});
}
builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
builder.setView(linearLayout);
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
return builder.create();
}
Aggregations