From fc5c01de8b389ff744f9030b15c23675cc4d9f28 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 22 Aug 2019 22:17:05 +0300 Subject: [PATCH] Added ability to open calendar from long click of on floating date --- .../java/org/telegram/ui/ChatActivity.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index eb99db3bb..eacff3a7a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -3991,6 +3991,48 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not jumpToDate((int) (calendar.getTime().getTime() / 1000)); }); + floatingDateView.setOnLongClickListener(view -> { + if (getParentActivity() == null) { + return false; + } + AndroidUtilities.hideKeyboard(searchItem.getSearchField()); + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + int monthOfYear = calendar.get(Calendar.MONTH); + int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); + try { + DatePickerDialog dialog = new DatePickerDialog(getParentActivity(), (view1, year1, month, dayOfMonth1) -> { + Calendar calendar1 = Calendar.getInstance(); + calendar1.clear(); + calendar1.set(year1, month, dayOfMonth1); + int date = (int) (calendar1.getTime().getTime() / 1000); + jumpToDate(date); + }, year, monthOfYear, dayOfMonth); + final DatePicker datePicker = dialog.getDatePicker(); + datePicker.setMinDate(1375315200000L); + datePicker.setMaxDate(System.currentTimeMillis()); + dialog.setButton(DialogInterface.BUTTON_POSITIVE, LocaleController.getString("JumpToDate", R.string.JumpToDate), dialog); + dialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), (dialog1, which) -> { + + }); + if (Build.VERSION.SDK_INT >= 21) { + dialog.setOnShowListener(dialog12 -> { + int count = datePicker.getChildCount(); + for (int a = 0; a < count; a++) { + View child = datePicker.getChildAt(a); + ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); + layoutParams.width = LayoutHelper.MATCH_PARENT; + child.setLayoutParams(layoutParams); + } + }); + } + showDialog(dialog); + } catch (Exception e) { + FileLog.e(e); + } + return true; + }); + if (currentEncryptedChat == null) { pinnedMessageView = new FrameLayout(context); pinnedMessageView.setTag(1);