Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding +1 Minute Timer #1139

Merged
merged 9 commits into from
Jul 3, 2023
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
7.43
-----

* New Feature:
* Add capability to add +1 minute on the sleep timer
([#1139](https://github.com/Automattic/pocket-casts-android/pull/1139)).

7.42
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class SleepFragment : BaseDialogFragment() {
binding.customMinusButton.setOnClickListener { minusButtonClicked() }
binding.customPlusButton.setOnClickListener { plusButtonClicked() }
binding.buttonCustom.setOnClickListener { startCustomTimer() }
binding.buttonAddTime.setOnClickListener { addExtraMins() }
binding.buttonAdd5Minute.setOnClickListener { addExtra5minute() }
binding.buttonAdd1Minute.setOnClickListener { addExtra1minute() }
binding.buttonEndOfEpisode2.setOnClickListener {
analyticsTracker.track(AnalyticsEvent.PLAYER_SLEEP_TIMER_EXTENDED, mapOf(AMOUNT_KEY to END_OF_EPISODE))
startTimerEndOfEpisode()
Expand All @@ -98,8 +99,10 @@ class SleepFragment : BaseDialogFragment() {
val tintColor = theme.playerHighlightColor(viewModel.podcast)
val tintColorStateList = ColorStateList.valueOf(tintColor)
val binding = binding ?: return@Observer
binding.buttonAddTime.strokeColor = tintColorStateList
binding.buttonAddTime.setTextColor(tintColorStateList)
binding.buttonAdd5Minute.strokeColor = tintColorStateList
binding.buttonAdd5Minute.setTextColor(tintColorStateList)
binding.buttonAdd1Minute.strokeColor = tintColorStateList
binding.buttonAdd1Minute.setTextColor(tintColorStateList)
binding.buttonCancelEndOfEpisode.strokeColor = tintColorStateList
binding.buttonCancelEndOfEpisode.setTextColor(tintColorStateList)
binding.buttonCancelTime.strokeColor = tintColorStateList
Expand All @@ -116,14 +119,22 @@ class SleepFragment : BaseDialogFragment() {
(dialog as? BottomSheetDialog)?.behavior?.state = BottomSheetBehavior.STATE_EXPANDED
}

private fun addExtraMins() {
private fun addExtra5minute() {
viewModel.sleepTimerAddExtraMins(mins = 5)
analyticsTracker.track(AnalyticsEvent.PLAYER_SLEEP_TIMER_EXTENDED, mapOf(AMOUNT_KEY to TimeUnit.MILLISECONDS.toSeconds(5.minutes())))
viewModel.timeLeftInSeconds()?.let { timeLeft ->
binding?.root?.announceForAccessibility("5 minutes added to sleep timer. ${timeLeft / 60} minutes ${timeLeft % 60} seconds remaining")
}
}

private fun addExtra1minute() {
viewModel.sleepTimerAddExtraMins(mins = 1)
analyticsTracker.track(AnalyticsEvent.PLAYER_SLEEP_TIMER_EXTENDED, mapOf(AMOUNT_KEY to TimeUnit.MILLISECONDS.toSeconds(1.minutes())))
viewModel.timeLeftInSeconds()?.let { timeLeft ->
binding?.root?.announceForAccessibility("1 minute added to sleep timer. ${timeLeft / 60} minutes ${timeLeft % 60} seconds remaining")
}
}

private fun startCustomTimer() {
viewModel.sleepTimerAfter(mins = viewModel.sleepCustomTimeMins)
binding?.root?.announceForAccessibility("Sleep timer set for ${viewModel.sleepCustomTimeMins} minutes")
Expand Down
33 changes: 27 additions & 6 deletions modules/features/player/src/main/res/layout/fragment_sleep.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{safeUnbox(viewModel.isSleepRunning) && !safeUnbox(viewModel.isSleepAtEndOfEpisode)}"
app:constraint_referenced_ids="sleepTime,buttonAddTime,buttonEndOfEpisode2,buttonCancelTime"
app:constraint_referenced_ids="sleepTime,buttonAdd1Minute,buttonAdd5Minute,buttonEndOfEpisode2,buttonCancelTime"
tools:ignore="MissingConstraints" />

<androidx.constraintlayout.widget.Group
Expand Down Expand Up @@ -330,20 +330,41 @@
app:layout_constraintTop_toBottomOf="@+id/sleepAnimation" />

<com.google.android.material.button.MaterialButton
android:id="@+id/buttonAddTime"
android:id="@+id/buttonAdd1Minute"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_gravity="center"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:layout_gravity="center"
android:minWidth="172dp"
android:text="@string/player_sleep_add_1_minute"
android:textColor="?attr/player_contrast_01"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/buttonAdd5Minute"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sleepTime"
app:strokeColor="?attr/player_contrast_01"
app:textAllCaps="false" />

<com.google.android.material.button.MaterialButton
android:id="@+id/buttonAdd5Minute"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_gravity="center"
android:minWidth="172dp"
android:text="@string/player_sleep_add_5_minutes"
android:textColor="?attr/player_contrast_01"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="@+id/buttonAdd1Minute"
app:layout_constraintTop_toBottomOf="@+id/sleepTime"
app:strokeColor="?attr/player_contrast_01"
app:textAllCaps="false" />
Expand All @@ -363,7 +384,7 @@
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonAddTime"
app:layout_constraintTop_toBottomOf="@+id/buttonAdd5Minute"
app:strokeColor="?attr/player_contrast_01"
app:textAllCaps="false" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@
<string name="player_sleep_15_minutes">15 minutes</string>
<string name="player_sleep_30_minutes">30 minutes</string>
<string name="player_sleep_5_minutes">5 minutes</string>
<string name="player_sleep_1_minute">1 minute</string>
<string name="player_sleep_60_minutes">60 minutes</string>
<string name="player_sleep_add_5_minutes">+ 5 minutes</string>
<string name="player_sleep_add_1_minute">+ 1 minute</string>
<string name="player_sleep_cancel_timer">Cancel timer</string>
<string name="player_sleep_custom_minus">Custom minus</string>
<string name="player_sleep_custom_plus">Custom plus</string>
Expand Down