Search in sources :

Example 11 with BottomSheet

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;
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) SvgHelper(org.telegram.messenger.SvgHelper) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) Manifest(android.Manifest) NotificationsController(org.telegram.messenger.NotificationsController) CacheControlActivity(org.telegram.ui.CacheControlActivity) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) CountDownLatch(java.util.concurrent.CountDownLatch) LaunchActivity(org.telegram.ui.LaunchActivity) Html(android.text.Html) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) InputFilter(android.text.InputFilter) TextWatcher(android.text.TextWatcher) ChatActivity(org.telegram.ui.ChatActivity) Dialog(android.app.Dialog) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) ThemePreviewActivity(org.telegram.ui.ThemePreviewActivity) Calendar(java.util.Calendar) TLRPC(org.telegram.tgnet.TLRPC) GradientDrawable(android.graphics.drawable.GradientDrawable) Toast(android.widget.Toast) Settings(android.provider.Settings) NotificationsCustomSettingsActivity(org.telegram.ui.NotificationsCustomSettingsActivity) URLSpan(android.text.style.URLSpan) SpannableString(android.text.SpannableString) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) EditText(android.widget.EditText) ProfileNotificationsActivity(org.telegram.ui.ProfileNotificationsActivity) RequiresApi(androidx.annotation.RequiresApi) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) PackageManager(android.content.pm.PackageManager) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LanguageSelectActivity(org.telegram.ui.LanguageSelectActivity) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) TextColorCell(org.telegram.ui.Cells.TextColorCell) Utilities(org.telegram.messenger.Utilities) TooManyCommunitiesActivity(org.telegram.ui.TooManyCommunitiesActivity) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) SecretChatHelper(org.telegram.messenger.SecretChatHelper) EditorInfo(android.view.inputmethod.EditorInfo) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Context(android.content.Context) IDN(java.net.IDN) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) NotificationsSettingsActivity(org.telegram.ui.NotificationsSettingsActivity) Build(android.os.Build) SerializedData(org.telegram.tgnet.SerializedData) DialogInterface(android.content.DialogInterface) Browser(org.telegram.messenger.browser.Browser) LoginActivity(org.telegram.ui.LoginActivity) DialogObject(org.telegram.messenger.DialogObject) FileLog(org.telegram.messenger.FileLog) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) Base64(android.util.Base64) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) Vibrator(android.os.Vibrator) Activity(android.app.Activity) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) SuppressLint(android.annotation.SuppressLint) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) LinearLayout(android.widget.LinearLayout)

Example 12 with BottomSheet

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();
    });
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) TextView(android.widget.TextView) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) LinearLayout(android.widget.LinearLayout)

Example 13 with BottomSheet

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;
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) SvgHelper(org.telegram.messenger.SvgHelper) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) Manifest(android.Manifest) NotificationsController(org.telegram.messenger.NotificationsController) CacheControlActivity(org.telegram.ui.CacheControlActivity) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) CountDownLatch(java.util.concurrent.CountDownLatch) LaunchActivity(org.telegram.ui.LaunchActivity) Html(android.text.Html) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) InputFilter(android.text.InputFilter) TextWatcher(android.text.TextWatcher) ChatActivity(org.telegram.ui.ChatActivity) Dialog(android.app.Dialog) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) ThemePreviewActivity(org.telegram.ui.ThemePreviewActivity) Calendar(java.util.Calendar) TLRPC(org.telegram.tgnet.TLRPC) GradientDrawable(android.graphics.drawable.GradientDrawable) Toast(android.widget.Toast) Settings(android.provider.Settings) NotificationsCustomSettingsActivity(org.telegram.ui.NotificationsCustomSettingsActivity) URLSpan(android.text.style.URLSpan) SpannableString(android.text.SpannableString) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) EditText(android.widget.EditText) ProfileNotificationsActivity(org.telegram.ui.ProfileNotificationsActivity) RequiresApi(androidx.annotation.RequiresApi) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) PackageManager(android.content.pm.PackageManager) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LanguageSelectActivity(org.telegram.ui.LanguageSelectActivity) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) TextColorCell(org.telegram.ui.Cells.TextColorCell) Utilities(org.telegram.messenger.Utilities) TooManyCommunitiesActivity(org.telegram.ui.TooManyCommunitiesActivity) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) SecretChatHelper(org.telegram.messenger.SecretChatHelper) EditorInfo(android.view.inputmethod.EditorInfo) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Context(android.content.Context) IDN(java.net.IDN) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) NotificationsSettingsActivity(org.telegram.ui.NotificationsSettingsActivity) Build(android.os.Build) SerializedData(org.telegram.tgnet.SerializedData) DialogInterface(android.content.DialogInterface) Browser(org.telegram.messenger.browser.Browser) LoginActivity(org.telegram.ui.LoginActivity) DialogObject(org.telegram.messenger.DialogObject) FileLog(org.telegram.messenger.FileLog) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) Base64(android.util.Base64) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) Vibrator(android.os.Vibrator) Activity(android.app.Activity) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) LinearLayout(android.widget.LinearLayout)

Aggregations

BottomSheet (org.telegram.ui.ActionBar.BottomSheet)13 SpannableStringBuilder (android.text.SpannableStringBuilder)8 SuppressLint (android.annotation.SuppressLint)6 LinearLayout (android.widget.LinearLayout)6 SharedPreferences (android.content.SharedPreferences)5 SpannableString (android.text.SpannableString)5 Manifest (android.Manifest)4 Activity (android.app.Activity)4 Dialog (android.app.Dialog)4 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 PackageManager (android.content.pm.PackageManager)4 Color (android.graphics.Color)4 PorterDuff (android.graphics.PorterDuff)4 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)4 Rect (android.graphics.Rect)4 Drawable (android.graphics.drawable.Drawable)4 ArrayList (java.util.ArrayList)4 TLRPC (org.telegram.tgnet.TLRPC)4