feat: add five, ten and twenty minutes sleep timer extend buttons (#4803)
This commit is contained in:
parent
5998e28497
commit
054a4f42a3
|
@ -87,6 +87,27 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
timeSetup = content.findViewById(R.id.timeSetup);
|
||||
timeDisplay = content.findViewById(R.id.timeDisplay);
|
||||
time = content.findViewById(R.id.time);
|
||||
Button extendSleepFiveMinutesButton = content.findViewById(R.id.extendSleepFiveMinutesButton);
|
||||
extendSleepFiveMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 5));
|
||||
Button extendSleepTenMinutesButton = content.findViewById(R.id.extendSleepTenMinutesButton);
|
||||
extendSleepTenMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 10));
|
||||
Button extendSleepTwentyMinutesButton = content.findViewById(R.id.extendSleepTwentyMinutesButton);
|
||||
extendSleepTwentyMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 20));
|
||||
extendSleepFiveMinutesButton.setOnClickListener(v -> {
|
||||
if (controller != null) {
|
||||
controller.extendSleepTimer(5 * 1000 * 60);
|
||||
}
|
||||
});
|
||||
extendSleepTenMinutesButton.setOnClickListener(v -> {
|
||||
if (controller != null) {
|
||||
controller.extendSleepTimer(10 * 1000 * 60);
|
||||
}
|
||||
});
|
||||
extendSleepTwentyMinutesButton.setOnClickListener(v -> {
|
||||
if (controller != null) {
|
||||
controller.extendSleepTimer(20 * 1000 * 60);
|
||||
}
|
||||
});
|
||||
|
||||
etxtTime.setText(SleepTimerPreferences.lastTimerValue());
|
||||
etxtTime.postDelayed(() -> {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:padding="16dp">
|
||||
|
@ -52,10 +53,11 @@
|
|||
<TextView
|
||||
android:text="00:00:00"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:textSize="32sp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/time"/>
|
||||
|
||||
<Button
|
||||
|
@ -64,6 +66,45 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:id="@+id/disableSleeptimerButton"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/extendSleepFiveMinutesButton"
|
||||
style="?attr/materialButtonOutlinedStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_weight="1"
|
||||
android:padding="5dp"
|
||||
tools:text="+5 min" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/extendSleepTenMinutesButton"
|
||||
style="?attr/materialButtonOutlinedStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_weight="1"
|
||||
tools:text="+10 min" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/extendSleepTwentyMinutesButton"
|
||||
style="?attr/materialButtonOutlinedStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
tools:text="+20 min" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
|
|
@ -564,6 +564,13 @@ public class PlaybackController {
|
|||
}
|
||||
}
|
||||
|
||||
public void extendSleepTimer(long extendTime) {
|
||||
long timeLeft = getSleepTimerTimeLeft();
|
||||
if (playbackService != null && timeLeft != INVALID_TIME) {
|
||||
setSleepTimer(timeLeft + extendTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSleepTimer(long time) {
|
||||
if (playbackService != null) {
|
||||
playbackService.setSleepTimer(time);
|
||||
|
|
|
@ -602,6 +602,7 @@
|
|||
<!-- Sleep timer -->
|
||||
<string name="set_sleeptimer_label">Set sleep timer</string>
|
||||
<string name="disable_sleeptimer_label">Disable sleep timer</string>
|
||||
<string name="extend_sleep_timer_label">+%d min</string>
|
||||
<string name="sleep_timer_label">Sleep timer</string>
|
||||
<string name="time_dialog_invalid_input">Invalid input, time has to be an integer</string>
|
||||
<string name="shake_to_reset_label">Shake to reset</string>
|
||||
|
|
Loading…
Reference in New Issue