diff --git a/app/build.gradle b/app/build.gradle index 00ca2a56..9ab2647c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -134,7 +134,7 @@ dependencies { implementation "androidx.room:room-rxjava2:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion" - implementation "com.google.android.material:material:1.2.1" + implementation "com.google.android.material:material:1.3.0" implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt index 8fc48e9c..f3c00bde 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt @@ -18,7 +18,6 @@ package com.keylesspalace.tusky.components.compose import android.Manifest import android.app.Activity import android.app.ProgressDialog -import android.app.TimePickerDialog import android.content.Context import android.content.Intent import android.content.SharedPreferences @@ -61,6 +60,7 @@ import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener import com.keylesspalace.tusky.components.compose.dialog.makeCaptionDialog import com.keylesspalace.tusky.components.compose.dialog.showAddPollDialog import com.keylesspalace.tusky.components.compose.view.ComposeOptionsListener +import com.keylesspalace.tusky.components.compose.view.ComposeScheduleView import com.keylesspalace.tusky.db.AccountEntity import com.keylesspalace.tusky.db.DraftAttachment import com.keylesspalace.tusky.di.Injectable @@ -90,7 +90,7 @@ class ComposeActivity : BaseActivity(), OnEmojiSelectedListener, Injectable, InputConnectionCompat.OnCommitContentListener, - TimePickerDialog.OnTimeSetListener { + ComposeScheduleView.OnTimeSetListener { @Inject lateinit var viewModelFactory: ViewModelFactory @@ -348,6 +348,7 @@ class ComposeActivity : BaseActivity(), composeHideMediaButton.setOnClickListener { toggleHideMedia() } composeScheduleButton.setOnClickListener { onScheduleClick() } composeScheduleView.setResetOnClickListener { resetSchedule() } + composeScheduleView.setListener(this) atButton.setOnClickListener { atButtonClicked() } hashButton.setOnClickListener { hashButtonClicked() } @@ -992,9 +993,8 @@ class ComposeActivity : BaseActivity(), } } - override fun onTimeSet(view: TimePicker, hourOfDay: Int, minute: Int) { - composeScheduleView.onTimeSet(hourOfDay, minute) - viewModel.updateScheduledAt(composeScheduleView.time) + override fun onTimeSet(time: String) { + viewModel.updateScheduledAt(time) if (verifyScheduledTime()) { scheduleBehavior.state = BottomSheetBehavior.STATE_HIDDEN } else { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/view/ComposeScheduleView.java b/app/src/main/java/com/keylesspalace/tusky/components/compose/view/ComposeScheduleView.java index a1a99a7d..14c574a1 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/view/ComposeScheduleView.java +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/view/ComposeScheduleView.java @@ -17,7 +17,6 @@ package com.keylesspalace.tusky.components.compose.view; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Bundle; import android.util.AttributeSet; import android.widget.Button; import android.widget.TextView; @@ -31,8 +30,9 @@ import androidx.core.content.ContextCompat; import com.google.android.material.datepicker.CalendarConstraints; import com.google.android.material.datepicker.DateValidatorPointForward; import com.google.android.material.datepicker.MaterialDatePicker; +import com.google.android.material.timepicker.MaterialTimePicker; +import com.google.android.material.timepicker.TimeFormat; import com.keylesspalace.tusky.R; -import com.keylesspalace.tusky.fragment.TimePickerFragment; import java.text.DateFormat; import java.text.ParseException; @@ -44,6 +44,12 @@ import java.util.TimeZone; public class ComposeScheduleView extends ConstraintLayout { + public interface OnTimeSetListener { + void onTimeSet(String time); + } + + private OnTimeSetListener listener; + private DateFormat dateFormat; private DateFormat timeFormat; private SimpleDateFormat iso8601; @@ -92,6 +98,10 @@ public class ComposeScheduleView extends ConstraintLayout { setEditIcons(); } + public void setListener(OnTimeSetListener listener) { + this.listener = listener; + } + private void setScheduledDateTime() { if (scheduleDateTime == null) { scheduledDateTimeView.setText(""); @@ -144,13 +154,20 @@ public class ComposeScheduleView extends ConstraintLayout { } private void openPickTimeDialog() { - TimePickerFragment picker = new TimePickerFragment(); + MaterialTimePicker.Builder pickerBuilder = new MaterialTimePicker.Builder(); if (scheduleDateTime != null) { - Bundle args = new Bundle(); - args.putInt(TimePickerFragment.PICKER_TIME_HOUR, scheduleDateTime.get(Calendar.HOUR_OF_DAY)); - args.putInt(TimePickerFragment.PICKER_TIME_MINUTE, scheduleDateTime.get(Calendar.MINUTE)); - picker.setArguments(args); + pickerBuilder.setHour(scheduleDateTime.get(Calendar.HOUR_OF_DAY)) + .setMinute(scheduleDateTime.get(Calendar.MINUTE)); } + if (android.text.format.DateFormat.is24HourFormat(this.getContext())) { + pickerBuilder.setTimeFormat(TimeFormat.CLOCK_24H); + } else { + pickerBuilder.setTimeFormat(TimeFormat.CLOCK_12H); + } + + MaterialTimePicker picker = pickerBuilder.build(); + picker.addOnPositiveButtonClickListener(v -> onTimeSet(picker.getHour(), picker.getMinute())); + picker.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "time_picker"); } @@ -200,11 +217,14 @@ public class ComposeScheduleView extends ConstraintLayout { openPickTimeDialog(); } - public void onTimeSet(int hourOfDay, int minute) { + private void onTimeSet(int hourOfDay, int minute) { initializeSuggestedTime(); scheduleDateTime.set(Calendar.HOUR_OF_DAY, hourOfDay); scheduleDateTime.set(Calendar.MINUTE, minute); setScheduledDateTime(); + if (listener != null) { + listener.onTimeSet(getTime()); + } } public String getTime() { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/TimePickerFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/TimePickerFragment.java deleted file mode 100644 index 1349a59c..00000000 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimePickerFragment.java +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright 2019 kyori19 - * - * This file is a part of Tusky. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Tusky; if not, - * see . */ - -package com.keylesspalace.tusky.fragment; - -import android.app.Dialog; -import android.app.TimePickerDialog; -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.fragment.app.DialogFragment; - -import com.keylesspalace.tusky.components.compose.ComposeActivity; - -import java.util.Calendar; -import java.util.TimeZone; - -public class TimePickerFragment extends DialogFragment { - - public static final String PICKER_TIME_HOUR = "picker_time_hour"; - public static final String PICKER_TIME_MINUTE = "picker_time_minute"; - - @Override - @NonNull - public Dialog onCreateDialog(Bundle savedInstanceState) { - Bundle args = getArguments(); - Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); - if (args != null) { - calendar.set(Calendar.HOUR_OF_DAY, args.getInt(PICKER_TIME_HOUR)); - calendar.set(Calendar.MINUTE, args.getInt(PICKER_TIME_MINUTE)); - } - - return new TimePickerDialog(getContext(), - android.R.style.Theme_DeviceDefault_Dialog, - (ComposeActivity) getActivity(), - calendar.get(Calendar.HOUR_OF_DAY), - calendar.get(Calendar.MINUTE), - true); - } - -}