use of org.telegram.ui.ActionBar.BottomSheet in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createDatePickerDialog.
public static BottomSheet.Builder createDatePickerDialog(Context context, long currentDate, final ScheduleDatePickerDelegate datePickerDelegate) {
if (context == null) {
return null;
}
ScheduleDatePickerColors datePickerColors = new ScheduleDatePickerColors();
BottomSheet.Builder builder = new BottomSheet.Builder(context, false);
builder.setApplyBottomPadding(false);
final NumberPicker dayPicker = new NumberPicker(context);
dayPicker.setTextColor(datePickerColors.textColor);
dayPicker.setTextOffset(AndroidUtilities.dp(10));
dayPicker.setItemCount(5);
final NumberPicker hourPicker = new NumberPicker(context) {
@Override
protected CharSequence getContentDescription(int value) {
return LocaleController.formatPluralString("Hours", value);
}
};
hourPicker.setItemCount(5);
hourPicker.setTextColor(datePickerColors.textColor);
hourPicker.setTextOffset(-AndroidUtilities.dp(10));
final NumberPicker minutePicker = new NumberPicker(context) {
@Override
protected CharSequence getContentDescription(int value) {
return LocaleController.formatPluralString("Minutes", value);
}
};
minutePicker.setItemCount(5);
minutePicker.setTextColor(datePickerColors.textColor);
minutePicker.setTextOffset(-AndroidUtilities.dp(34));
LinearLayout container = new LinearLayout(context) {
boolean ignoreLayout = false;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
ignoreLayout = true;
int count;
if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
count = 3;
} else {
count = 5;
}
dayPicker.setItemCount(count);
hourPicker.setItemCount(count);
minutePicker.setItemCount(count);
dayPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
hourPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
minutePicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
ignoreLayout = false;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public void requestLayout() {
if (ignoreLayout) {
return;
}
super.requestLayout();
}
};
container.setOrientation(LinearLayout.VERTICAL);
FrameLayout titleLayout = new FrameLayout(context);
container.addView(titleLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 22, 0, 0, 4));
TextView titleView = new TextView(context);
titleView.setText(LocaleController.getString("ExpireAfter", R.string.ExpireAfter));
titleView.setTextColor(datePickerColors.textColor);
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
titleLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 12, 0, 0));
titleView.setOnTouchListener((v, event) -> true);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setWeightSum(1.0f);
container.addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
long currentTime = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(currentTime);
int currentYear = calendar.get(Calendar.YEAR);
TextView buttonTextView = new TextView(context) {
@Override
public CharSequence getAccessibilityClassName() {
return Button.class.getName();
}
};
linearLayout.addView(dayPicker, LayoutHelper.createLinear(0, 54 * 5, 0.5f));
dayPicker.setMinValue(0);
dayPicker.setMaxValue(365);
dayPicker.setWrapSelectorWheel(false);
dayPicker.setFormatter(value -> {
if (value == 0) {
return LocaleController.getString("MessageScheduleToday", R.string.MessageScheduleToday);
} else {
long date = currentTime + (long) value * 86400000L;
calendar.setTimeInMillis(date);
int year = calendar.get(Calendar.YEAR);
if (year == currentYear) {
return LocaleController.getInstance().formatterScheduleDay.format(date);
} else {
return LocaleController.getInstance().formatterScheduleYear.format(date);
}
}
});
final NumberPicker.OnValueChangeListener onValueChangeListener = (picker, oldVal, newVal) -> {
try {
container.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
} catch (Exception ignore) {
}
checkScheduleDate(null, null, 0, dayPicker, hourPicker, minutePicker);
};
dayPicker.setOnValueChangedListener(onValueChangeListener);
hourPicker.setMinValue(0);
hourPicker.setMaxValue(23);
linearLayout.addView(hourPicker, LayoutHelper.createLinear(0, 54 * 5, 0.2f));
hourPicker.setFormatter(value -> String.format("%02d", value));
hourPicker.setOnValueChangedListener(onValueChangeListener);
minutePicker.setMinValue(0);
minutePicker.setMaxValue(59);
minutePicker.setValue(0);
minutePicker.setFormatter(value -> String.format("%02d", value));
linearLayout.addView(minutePicker, LayoutHelper.createLinear(0, 54 * 5, 0.3f));
minutePicker.setOnValueChangedListener(onValueChangeListener);
if (currentDate > 0 && currentDate != 0x7FFFFFFE) {
currentDate *= 1000;
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
int days = (int) ((currentDate - calendar.getTimeInMillis()) / (24 * 60 * 60 * 1000));
calendar.setTimeInMillis(currentDate);
if (days >= 0) {
minutePicker.setValue(calendar.get(Calendar.MINUTE));
hourPicker.setValue(calendar.get(Calendar.HOUR_OF_DAY));
dayPicker.setValue(days);
}
}
checkScheduleDate(null, null, 0, dayPicker, hourPicker, minutePicker);
buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
buttonTextView.setGravity(Gravity.CENTER);
buttonTextView.setTextColor(datePickerColors.buttonTextColor);
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), datePickerColors.buttonBackgroundColor, datePickerColors.buttonBackgroundPressedColor));
buttonTextView.setText(LocaleController.getString("SetTimeLimit", R.string.SetTimeLimit));
container.addView(buttonTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM, 16, 15, 16, 16));
buttonTextView.setOnClickListener(v -> {
boolean setSeconds = checkScheduleDate(null, null, 0, dayPicker, hourPicker, minutePicker);
calendar.setTimeInMillis(System.currentTimeMillis() + (long) dayPicker.getValue() * 24 * 3600 * 1000);
calendar.set(Calendar.HOUR_OF_DAY, hourPicker.getValue());
calendar.set(Calendar.MINUTE, minutePicker.getValue());
if (setSeconds) {
calendar.set(Calendar.SECOND, 0);
}
datePickerDelegate.didSelectDate(true, (int) (calendar.getTimeInMillis() / 1000));
builder.getDismissRunnable().run();
});
builder.setCustomView(container);
BottomSheet bottomSheet = builder.show();
bottomSheet.setBackgroundColor(datePickerColors.backgroundColor);
return builder;
}
use of org.telegram.ui.ActionBar.BottomSheet in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method showChatWithAdmin.
public static void showChatWithAdmin(BaseFragment fragment, TLRPC.User user, String chatWithAdmin, boolean isChannel, int chatWithAdminDate) {
if (fragment.getParentActivity() == null) {
return;
}
BottomSheet.Builder builder = new BottomSheet.Builder(fragment.getParentActivity());
builder.setTitle(isChannel ? LocaleController.getString("ChatWithAdminChannelTitle", R.string.ChatWithAdminChannelTitle) : LocaleController.getString("ChatWithAdminGroupTitle", R.string.ChatWithAdminGroupTitle), true);
LinearLayout linearLayout = new LinearLayout(fragment.getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView messageTextView = new TextView(fragment.getParentActivity());
linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 24, 16, 24, 24));
messageTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ChatWithAdminMessage", R.string.ChatWithAdminMessage, chatWithAdmin, LocaleController.formatDateAudio(chatWithAdminDate, false))));
TextView buttonTextView = new TextView(fragment.getParentActivity());
buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
buttonTextView.setGravity(Gravity.CENTER);
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
buttonTextView.setText(LocaleController.getString("IUnderstand", R.string.IUnderstand));
buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(6), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
linearLayout.addView(buttonTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, 0, 24, 15, 16, 24));
builder.setCustomView(linearLayout);
BottomSheet bottomSheet = builder.show();
buttonTextView.setOnClickListener((v) -> {
bottomSheet.dismiss();
});
}
use of org.telegram.ui.ActionBar.BottomSheet in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createScheduleDatePickerDialog.
public static BottomSheet.Builder createScheduleDatePickerDialog(Context context, long dialogId, long currentDate, final ScheduleDatePickerDelegate datePickerDelegate, final Runnable cancelRunnable, final ScheduleDatePickerColors datePickerColors, Theme.ResourcesProvider resourcesProvider) {
if (context == null) {
return null;
}
long selfUserId = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId();
BottomSheet.Builder builder = new BottomSheet.Builder(context, false, resourcesProvider);
builder.setApplyBottomPadding(false);
final NumberPicker dayPicker = new NumberPicker(context, resourcesProvider);
dayPicker.setTextColor(datePickerColors.textColor);
dayPicker.setTextOffset(AndroidUtilities.dp(10));
dayPicker.setItemCount(5);
final NumberPicker hourPicker = new NumberPicker(context, resourcesProvider) {
@Override
protected CharSequence getContentDescription(int value) {
return LocaleController.formatPluralString("Hours", value);
}
};
hourPicker.setItemCount(5);
hourPicker.setTextColor(datePickerColors.textColor);
hourPicker.setTextOffset(-AndroidUtilities.dp(10));
final NumberPicker minutePicker = new NumberPicker(context, resourcesProvider) {
@Override
protected CharSequence getContentDescription(int value) {
return LocaleController.formatPluralString("Minutes", value);
}
};
minutePicker.setItemCount(5);
minutePicker.setTextColor(datePickerColors.textColor);
minutePicker.setTextOffset(-AndroidUtilities.dp(34));
LinearLayout container = new LinearLayout(context) {
boolean ignoreLayout = false;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
ignoreLayout = true;
int count;
if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
count = 3;
} else {
count = 5;
}
dayPicker.setItemCount(count);
hourPicker.setItemCount(count);
minutePicker.setItemCount(count);
dayPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
hourPicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
minutePicker.getLayoutParams().height = AndroidUtilities.dp(54) * count;
ignoreLayout = false;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public void requestLayout() {
if (ignoreLayout) {
return;
}
super.requestLayout();
}
};
container.setOrientation(LinearLayout.VERTICAL);
FrameLayout titleLayout = new FrameLayout(context);
container.addView(titleLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 22, 0, 0, 4));
TextView titleView = new TextView(context);
if (dialogId == selfUserId) {
titleView.setText(LocaleController.getString("SetReminder", R.string.SetReminder));
} else {
titleView.setText(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage));
}
titleView.setTextColor(datePickerColors.textColor);
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
titleLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 12, 0, 0));
titleView.setOnTouchListener((v, event) -> true);
if (DialogObject.isUserDialog(dialogId) && dialogId != selfUserId) {
TLRPC.User user = MessagesController.getInstance(UserConfig.selectedAccount).getUser(dialogId);
if (user != null && !user.bot && user.status != null && user.status.expires > 0) {
String name = UserObject.getFirstName(user);
if (name.length() > 10) {
name = name.substring(0, 10) + "\u2026";
}
ActionBarMenuItem optionsButton = new ActionBarMenuItem(context, null, 0, datePickerColors.iconColor, false, resourcesProvider);
optionsButton.setLongClickEnabled(false);
optionsButton.setSubMenuOpenSide(2);
optionsButton.setIcon(R.drawable.ic_ab_other);
optionsButton.setBackgroundDrawable(Theme.createSelectorDrawable(datePickerColors.iconSelectorColor, 1));
titleLayout.addView(optionsButton, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 8, 5, 0));
optionsButton.addSubItem(1, LocaleController.formatString("ScheduleWhenOnline", R.string.ScheduleWhenOnline, name));
optionsButton.setOnClickListener(v -> {
optionsButton.toggleSubMenu();
optionsButton.setPopupItemsColor(datePickerColors.subMenuTextColor, false);
optionsButton.setupPopupRadialSelectors(datePickerColors.subMenuSelectorColor);
optionsButton.redrawPopup(datePickerColors.subMenuBackgroundColor);
});
optionsButton.setDelegate(id -> {
if (id == 1) {
datePickerDelegate.didSelectDate(true, 0x7ffffffe);
builder.getDismissRunnable().run();
}
});
optionsButton.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
}
}
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setWeightSum(1.0f);
container.addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
long currentTime = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(currentTime);
int currentYear = calendar.get(Calendar.YEAR);
TextView buttonTextView = new TextView(context) {
@Override
public CharSequence getAccessibilityClassName() {
return Button.class.getName();
}
};
linearLayout.addView(dayPicker, LayoutHelper.createLinear(0, 54 * 5, 0.5f));
dayPicker.setMinValue(0);
dayPicker.setMaxValue(365);
dayPicker.setWrapSelectorWheel(false);
dayPicker.setFormatter(value -> {
if (value == 0) {
return LocaleController.getString("MessageScheduleToday", R.string.MessageScheduleToday);
} else {
long date = currentTime + (long) value * 86400000L;
calendar.setTimeInMillis(date);
int year = calendar.get(Calendar.YEAR);
if (year == currentYear) {
return LocaleController.getInstance().formatterScheduleDay.format(date);
} else {
return LocaleController.getInstance().formatterScheduleYear.format(date);
}
}
});
final NumberPicker.OnValueChangeListener onValueChangeListener = (picker, oldVal, newVal) -> {
try {
container.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
} catch (Exception ignore) {
}
checkScheduleDate(buttonTextView, null, selfUserId == dialogId ? 1 : 0, dayPicker, hourPicker, minutePicker);
};
dayPicker.setOnValueChangedListener(onValueChangeListener);
hourPicker.setMinValue(0);
hourPicker.setMaxValue(23);
linearLayout.addView(hourPicker, LayoutHelper.createLinear(0, 54 * 5, 0.2f));
hourPicker.setFormatter(value -> String.format("%02d", value));
hourPicker.setOnValueChangedListener(onValueChangeListener);
minutePicker.setMinValue(0);
minutePicker.setMaxValue(59);
minutePicker.setValue(0);
minutePicker.setFormatter(value -> String.format("%02d", value));
linearLayout.addView(minutePicker, LayoutHelper.createLinear(0, 54 * 5, 0.3f));
minutePicker.setOnValueChangedListener(onValueChangeListener);
if (currentDate > 0 && currentDate != 0x7FFFFFFE) {
currentDate *= 1000;
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
int days = (int) ((currentDate - calendar.getTimeInMillis()) / (24 * 60 * 60 * 1000));
calendar.setTimeInMillis(currentDate);
if (days >= 0) {
minutePicker.setValue(calendar.get(Calendar.MINUTE));
hourPicker.setValue(calendar.get(Calendar.HOUR_OF_DAY));
dayPicker.setValue(days);
}
}
final boolean[] canceled = { true };
checkScheduleDate(buttonTextView, null, selfUserId == dialogId ? 1 : 0, dayPicker, hourPicker, minutePicker);
buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
buttonTextView.setGravity(Gravity.CENTER);
buttonTextView.setTextColor(datePickerColors.buttonTextColor);
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), datePickerColors.buttonBackgroundColor, datePickerColors.buttonBackgroundPressedColor));
container.addView(buttonTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM, 16, 15, 16, 16));
buttonTextView.setOnClickListener(v -> {
canceled[0] = false;
boolean setSeconds = checkScheduleDate(null, null, selfUserId == dialogId ? 1 : 0, dayPicker, hourPicker, minutePicker);
calendar.setTimeInMillis(System.currentTimeMillis() + (long) dayPicker.getValue() * 24 * 3600 * 1000);
calendar.set(Calendar.HOUR_OF_DAY, hourPicker.getValue());
calendar.set(Calendar.MINUTE, minutePicker.getValue());
if (setSeconds) {
calendar.set(Calendar.SECOND, 0);
}
datePickerDelegate.didSelectDate(true, (int) (calendar.getTimeInMillis() / 1000));
builder.getDismissRunnable().run();
});
builder.setCustomView(container);
BottomSheet bottomSheet = builder.show();
bottomSheet.setOnDismissListener(dialog -> {
if (cancelRunnable != null && canceled[0]) {
cancelRunnable.run();
}
});
bottomSheet.setBackgroundColor(datePickerColors.backgroundColor);
return builder;
}
Aggregations