From e231f45ca672fb2f909cc6f337098e9ea6baaccb Mon Sep 17 00:00:00 2001 From: Roberto Fuentes Date: Wed, 10 Mar 2021 14:45:14 +0100 Subject: [PATCH 1/7] feat(app) Now notifies user when alarm will go off with a snackbar. --- .../noice/fragment/WakeUpTimerFragment.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt index 8f7e5c419..57cc7985a 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt @@ -16,6 +16,7 @@ import com.github.ashutoshgngwr.noice.databinding.WakeUpTimerFragmentBinding import com.github.ashutoshgngwr.noice.sound.Preset import com.google.android.material.snackbar.Snackbar import java.util.* +import java.util.concurrent.TimeUnit class WakeUpTimerFragment : Fragment() { @@ -121,7 +122,9 @@ class WakeUpTimerFragment : Fragment() { } selectedTime = calendar.timeInMillis + notifyUpdate() + notifyScheduleLeftTime() // maybe show in-app review dialog to the user InAppReviewFlowManager.maybeAskForReview(requireActivity()) @@ -200,6 +203,22 @@ class WakeUpTimerFragment : Fragment() { } } + + private fun notifyScheduleLeftTime() { + val actualTime = System.currentTimeMillis() + var differenceMillis = selectedTime - actualTime + + val diffHours = TimeUnit.MILLISECONDS.toHours(differenceMillis) + differenceMillis -= TimeUnit.HOURS.toMillis(diffHours) + val diffMinutes = TimeUnit.MILLISECONDS.toMinutes(differenceMillis) + + Snackbar.make( + requireView(), + "Alarm will go off in $diffHours hours and $diffMinutes minutes", + Snackbar.LENGTH_SHORT + ).show() + } + private fun resetControls() { loadSelectedPresetID() selectedTime = 0 From 7e6fedf8d268d488b44e0b4bb90ebf6582feec05 Mon Sep 17 00:00:00 2001 From: Roberto Fuentes Date: Wed, 10 Mar 2021 15:13:06 +0100 Subject: [PATCH 2/7] feat(app): Added multiple strings for a good syntax. Added function to get the correct string to notify user the schedule left time. --- .../ashutoshgngwr/noice/WakeUpTimerManager.kt | 27 ++ .../noice/fragment/WakeUpTimerFragment.kt | 6 +- app/src/main/res/values/strings.xml | 314 +++++++++--------- 3 files changed, 193 insertions(+), 154 deletions(-) diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt index 04a08c235..5d518e359 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt @@ -141,6 +141,33 @@ object WakeUpTimerManager { } } + fun getStringScheduleLeftTime(context: Context, diffHours: Int, diffMinutes: Int): String{ + return when(diffHours){ + 0 -> { + when(diffMinutes){ + 0 -> context.getString(R.string.wake_up_timer_schedule_set_minute, diffMinutes) + 1 -> context.getString(R.string.wake_up_timer_schedule_set_minute, diffMinutes) + else -> context.getString(R.string.wake_up_timer_schedule_set_minutes, diffMinutes) + } + } + 1 -> { + when(diffMinutes){ + 0 -> context.getString(R.string.wake_up_timer_schedule_set_hour_minute, diffHours, diffMinutes) + 1 -> context.getString(R.string.wake_up_timer_schedule_set_hour_minute, diffHours, diffMinutes) + else -> context.getString(R.string.wake_up_timer_schedule_set_hour_minutes, diffHours, diffMinutes) + } + } + else -> { + when(diffMinutes){ + 0 -> context.getString(R.string.wake_up_timer_schedule_set_hours_minute, diffHours, diffMinutes) + 1 -> context.getString(R.string.wake_up_timer_schedule_set_hours_minute, diffHours, diffMinutes) + else -> context.getString(R.string.wake_up_timer_schedule_set_hours_minutes, diffHours, diffMinutes) + } + } + } + + } + /** * [BootReceiver] ensures that a scheduled [Timer] is able to persist across device restarts. */ diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt index 57cc7985a..d7591bb59 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt @@ -214,7 +214,11 @@ class WakeUpTimerFragment : Fragment() { Snackbar.make( requireView(), - "Alarm will go off in $diffHours hours and $diffMinutes minutes", + WakeUpTimerManager.getStringScheduleLeftTime( + requireContext(), + diffHours.toInt(), + diffMinutes.toInt() + ), Snackbar.LENGTH_SHORT ).show() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47f4fec3d..ac8a6cfa2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,196 +1,204 @@ - - About - Theme - Close navigation drawer - Help - Library - Open navigation drawer - Report Issues - Saved Presets - Sleep Timer - Support Development - Wake-up Timer - Submit Feedback - - Any - Dense - Focus - Intensity - Dense presets will try to play more sounds at once. - Light - Mood - Okay - Random Preset - Relax - - Cancel - Dismiss - Name - Pause - Preset with the given name already exists! - Preset name cannot be empty! - Preset saved! - Save - Save Preset - - Play - play or pause - Repeat time period - Stop - Sound volume - - Life - Monsoon - Public Gatherings - Raw Noise - Times of Day - Vehicles - Water - Wind - - Airplane in-flight - Airplane seat-belt beeps - Birds - Bonfire - Brownian noise - Coffee shop - Creaking ship - Crickets - Distant thunder - Electric car - Heavy rain - Howling wolf - Human heartbeat - Light rain - Moderate rain - Morning in a village - Moving train - Night - Office - Pink noise - Public library - Purring cat - Quiet conversation - Rolling thunder - Screeching seagulls - Seaside - Soft wind - Thunder crack - Train horn - Walking through the snow - Water hose - Water stream - White noise - Wind in chimes of shells - Wind in palm trees - - Add to home screen - Delete - Open context menu - Confirm delete %s? - Preset deleted! - Preset does not exist. It may have been deleted! - + + About + Theme + Close navigation drawer + Help + Library + Open navigation drawer + Report Issues + Saved Presets + Sleep Timer + Support Development + Wake-up Timer + Submit Feedback + + Any + Dense + Focus + Intensity + Dense presets will try to play more sounds at once. + Light + Mood + Okay + Random Preset + Relax + + Cancel + Dismiss + Name + Pause + Preset with the given name already exists! + Preset name cannot be empty! + Preset saved! + Save + Save Preset + + Play + play or pause + Repeat time period + Stop + Sound volume + + Life + Monsoon + Public Gatherings + Raw Noise + Times of Day + Vehicles + Water + Wind + + Airplane in-flight + Airplane seat-belt beeps + Birds + Bonfire + Brownian noise + Coffee shop + Creaking ship + Crickets + Distant thunder + Electric car + Heavy rain + Howling wolf + Human heartbeat + Light rain + Moderate rain + Morning in a village + Moving train + Night + Office + Pink noise + Public library + Purring cat + Quiet conversation + Rolling thunder + Screeching seagulls + Seaside + Soft wind + Thunder crack + Train horn + Walking through the snow + Water hose + Water stream + White noise + Wind in chimes of shells + Wind in palm trees + + Add to home screen + Delete + Open context menu + Confirm delete %s? + Preset deleted! + Preset does not exist. It may have been deleted! + You haven\'t created any presets yet. To create a preset, go to the Library and play sounds. Then click on the Save button that appears on the bottom corner of the screen. - Rename - Your default launcher does not support adding shortcuts. - Show saved presets on app startup - - Auto sleep timer cancelled! - Reset - + Rename + Your default launcher does not support adding shortcuts. + Show saved presets on app startup + + Auto sleep timer cancelled! + Reset + Noice will shutdown itself when the timer ends. Use the buttons below to add time and start the timer. - - Schedule - Select Preset - Wake-up Timer cancelled! - + + Schedule + Select Preset + Wake-up Timer cancelled! + Alarm will go off in %1$d hours and %2$d minutes + Alarm will go off in %1$d hours and %2$d minute + Alarm will go off in %1$d hour and %2$d minutes + Alarm will go off in %1$d hour and %2$d minute + Alarm will go off in %1$d hour + Alarm will go off in %1$d hours + Alarm will go off in %1$d minutes + Alarm will go off in %1$d minute + Noice will start the selected preset when the timer ends. Use the buttons below to select a preset and set the desired time to start the wake-up timer. - Use 24-hour format - Device media volume - Update device media volume before starting preset - - - Light - Dark - System default - - - Email - GitHub - Translations - Twitter - Relax and boost productivity with minimal background noise. - Connect with Author - Credits - - + Use 24-hour format + Device media volume + Update device media volume before starting preset + + + Light + Dark + System default + + + Email + GitHub + Translations + Twitter + Relax and boost productivity with minimal background noise. + Connect with Author + Credits + + Use Noice to cast its ambience to other Chromecast enabled devices such as speakers, TVs, etc. - Chromecast enabled - Swipe left to get to know all the features! - Let\'s get started! - Welcome - + Chromecast enabled + Swipe left to get to know all the features! + Let\'s get started! + Welcome + After playing a few sounds, you can use the button in the bottom end corner to save your mix. To reuse a stored mix, you can visit the preset list from the app menu. - Save your favourite mixes - + Save your favourite mixes + Use the volume slider to adjust sound volumes. At each repetition of non-looping sounds, a delay period is selected randomly from the range set by the time slider. - Create your perfect surroundings - + Create your perfect surroundings + A little ambience can help you fall asleep effortlessly. Use the sleep timer to let Noice shut itself down. Similarly, to wake up to a calm environment, use the wake-up timer to set the alarm. - Trouble falling asleep or waking up? - - Donate - + Trouble falling asleep or waking up? + + Donate + Donations will help us in\n - investing in new features\n - curating better sound samples\n - buying coffee\n - + Your payment will be securely handled by the Google Play. The amount will be converted to your local currency. Depending on your location, additional taxes _may be_ added to the final amount. - Thank you! - + Thank you! + We wholeheartedly thank you for your generous contribution to the Noice project. - Share with friends - + Share with friends + Sharing Noice with friends is similar to donating money. With higher downloads, we will be able to receive feedback from a number of different perspectives which will help us in making Noice better than ever. - Why should you support? - + Why should you support? + - To make future updates possible\n - To keep Noice ad-free forever\n - - Cast media to another device - + + Cast media to another device + We\'d love to hear from you about the app. Please take a moment to visit our GitHub repository. If you didn\'t love the app, please consider opening up an issue explaining your concerns. Otherwise, please star the project to show love and support. - Submit a review - Later - Never - Media playback controls - Media Playback - \ No newline at end of file + Submit a review + Later + Never + Media playback controls + Media Playback + From c2e1eb0a34f138f035f18177a60c4309d2bc968a Mon Sep 17 00:00:00 2001 From: Roberto Fuentes Date: Wed, 10 Mar 2021 15:43:33 +0100 Subject: [PATCH 3/7] test(app): Added unit tests. Fixed a small mistake when getting the correct string. --- .../ashutoshgngwr/noice/WakeUpTimerManager.kt | 4 +- .../noice/WakeUpTimerManagerTest.kt | 67 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt index 5d518e359..6cb12c3e0 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt @@ -152,14 +152,14 @@ object WakeUpTimerManager { } 1 -> { when(diffMinutes){ - 0 -> context.getString(R.string.wake_up_timer_schedule_set_hour_minute, diffHours, diffMinutes) + 0 -> context.getString(R.string.wake_up_timer_schedule_set_hour, diffHours) 1 -> context.getString(R.string.wake_up_timer_schedule_set_hour_minute, diffHours, diffMinutes) else -> context.getString(R.string.wake_up_timer_schedule_set_hour_minutes, diffHours, diffMinutes) } } else -> { when(diffMinutes){ - 0 -> context.getString(R.string.wake_up_timer_schedule_set_hours_minute, diffHours, diffMinutes) + 0 -> context.getString(R.string.wake_up_timer_schedule_set_hours, diffHours) 1 -> context.getString(R.string.wake_up_timer_schedule_set_hours_minute, diffHours, diffMinutes) else -> context.getString(R.string.wake_up_timer_schedule_set_hours_minutes, diffHours, diffMinutes) } diff --git a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt index 83b9e6a73..b18f01155 100644 --- a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt +++ b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt @@ -188,4 +188,71 @@ class WakeUpTimerManagerTest { assertEquals(presetID, WakeUpTimerManager.getLastUsedPresetID(context)) } + + @Test + fun testGetStringScheduleLeftTime_returnStringMinute(){ + val context = ApplicationProvider.getApplicationContext() + val stringMinute1 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 0) + val stringMinute2 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 1) + + val stringShouldDisplay1 = context.getString(R.string.wake_up_timer_schedule_set_minute,0) + val stringShouldDisplay2 = context.getString(R.string.wake_up_timer_schedule_set_minute,1) + + assertEquals(stringShouldDisplay1, stringMinute1) + assertEquals(stringShouldDisplay2, stringMinute2) + } + + @Test + fun testGetStringScheduleLeftTime_returnStringHour(){ + val context = ApplicationProvider.getApplicationContext() + val stringHour = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 0) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour,1) + + assertEquals(stringShouldDisplay, stringHour) + } + + @Test + fun testGetStringScheduleLeftTime_returnStringHourAndMinute(){ + val context = ApplicationProvider.getApplicationContext() + val stringHourAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 1) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour_minute,1, 1) + + assertEquals(stringShouldDisplay, stringHourAndMinute) + } + + @Test + fun testGetStringScheduleLeftTime_returnStringHourAndMinutes(){ + val context = ApplicationProvider.getApplicationContext() + val stringHourAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 2) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour_minutes,1, 2) + + assertEquals(stringShouldDisplay, stringHourAndMinutes) + } + + @Test + fun testGetStringScheduleLeftTime_returnStringHours(){ + val context = ApplicationProvider.getApplicationContext() + val stringHours = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 0) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours,2, 0) + + assertEquals(stringShouldDisplay, stringHours) + } + + @Test + fun testGetStringScheduleLeftTime_returnStringHoursAndMinute(){ + val context = ApplicationProvider.getApplicationContext() + val stringHoursAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 1) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours_minute,2, 1) + + assertEquals(stringShouldDisplay, stringHoursAndMinute) + } + + @Test + fun testGetStringScheduleLeftTime_returnStringHoursAndMinutes(){ + val context = ApplicationProvider.getApplicationContext() + val stringHoursAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 2) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours_minutes,2, 2) + + assertEquals(stringShouldDisplay, stringHoursAndMinutes) + } } From 17019b0a64ec80adddadcb7d3974303e9d232100 Mon Sep 17 00:00:00 2001 From: Roberto Fuentes Date: Wed, 10 Mar 2021 16:28:16 +0100 Subject: [PATCH 4/7] test(app): Added UI test checking that SnackBar notifies to the user. --- .../noice/fragment/WakeUpTimerFragmentTest.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt index 0a5b1a086..a941bc250 100644 --- a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt +++ b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt @@ -310,4 +310,18 @@ class WakeUpTimerFragmentTest { onView(withId(R.id.select_preset_button)) .check(matches(withText("test-not-saved-preset-1"))) } + + @Test + fun testSetSchedule_ShowNotifySnackBar() { + every { Preset.readAllFromUserPreferences(any()) } returns arrayOf( + mockk(relaxed = true) { + every { id } returns "test-preset" + every { name } returns "test-preset" + } + ) + fragmentScenario.recreate() + + onView(withId(R.id.set_time_button)).perform(click()) + onView(withSubstring("Alarm will go off")).check(matches(isDisplayed())) + } } From a74843aebd8ff479bdfd62b99816c683cea00b12 Mon Sep 17 00:00:00 2001 From: Roberto Fuentes Date: Wed, 10 Mar 2021 16:37:14 +0100 Subject: [PATCH 5/7] clean(app): Clean up. --- .../noice/fragment/WakeUpTimerFragmentTest.kt | 3 +- .../ashutoshgngwr/noice/WakeUpTimerManager.kt | 35 +++++++++++++------ .../noice/WakeUpTimerManagerTest.kt | 34 ++++++++++-------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt index a941bc250..12c0025a8 100644 --- a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt +++ b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt @@ -271,8 +271,7 @@ class WakeUpTimerFragmentTest { mockk(relaxed = true) { every { id } returns "test-not-saved-preset-id-1" every { name } returns "test-not-saved-preset-1" - } - , + }, mockk(relaxed = true) { every { id } returns "test-saved-preset-id" every { name } returns "test-saved-preset" diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt index 6cb12c3e0..3ba8a6a84 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt @@ -141,31 +141,46 @@ object WakeUpTimerManager { } } - fun getStringScheduleLeftTime(context: Context, diffHours: Int, diffMinutes: Int): String{ - return when(diffHours){ + fun getStringScheduleLeftTime(context: Context, diffHours: Int, diffMinutes: Int): String { + return when (diffHours) { 0 -> { - when(diffMinutes){ + when (diffMinutes) { 0 -> context.getString(R.string.wake_up_timer_schedule_set_minute, diffMinutes) 1 -> context.getString(R.string.wake_up_timer_schedule_set_minute, diffMinutes) else -> context.getString(R.string.wake_up_timer_schedule_set_minutes, diffMinutes) } } 1 -> { - when(diffMinutes){ + when (diffMinutes) { 0 -> context.getString(R.string.wake_up_timer_schedule_set_hour, diffHours) - 1 -> context.getString(R.string.wake_up_timer_schedule_set_hour_minute, diffHours, diffMinutes) - else -> context.getString(R.string.wake_up_timer_schedule_set_hour_minutes, diffHours, diffMinutes) + 1 -> context.getString( + R.string.wake_up_timer_schedule_set_hour_minute, + diffHours, + diffMinutes + ) + else -> context.getString( + R.string.wake_up_timer_schedule_set_hour_minutes, + diffHours, + diffMinutes + ) } } else -> { - when(diffMinutes){ + when (diffMinutes) { 0 -> context.getString(R.string.wake_up_timer_schedule_set_hours, diffHours) - 1 -> context.getString(R.string.wake_up_timer_schedule_set_hours_minute, diffHours, diffMinutes) - else -> context.getString(R.string.wake_up_timer_schedule_set_hours_minutes, diffHours, diffMinutes) + 1 -> context.getString( + R.string.wake_up_timer_schedule_set_hours_minute, + diffHours, + diffMinutes + ) + else -> context.getString( + R.string.wake_up_timer_schedule_set_hours_minutes, + diffHours, + diffMinutes + ) } } } - } /** diff --git a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt index b18f01155..f11c679c5 100644 --- a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt +++ b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt @@ -190,68 +190,72 @@ class WakeUpTimerManagerTest { } @Test - fun testGetStringScheduleLeftTime_returnStringMinute(){ + fun testGetStringScheduleLeftTime_returnStringMinute() { val context = ApplicationProvider.getApplicationContext() val stringMinute1 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 0) val stringMinute2 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 1) - val stringShouldDisplay1 = context.getString(R.string.wake_up_timer_schedule_set_minute,0) - val stringShouldDisplay2 = context.getString(R.string.wake_up_timer_schedule_set_minute,1) + val stringShouldDisplay1 = context.getString(R.string.wake_up_timer_schedule_set_minute, 0) + val stringShouldDisplay2 = context.getString(R.string.wake_up_timer_schedule_set_minute, 1) assertEquals(stringShouldDisplay1, stringMinute1) assertEquals(stringShouldDisplay2, stringMinute2) } @Test - fun testGetStringScheduleLeftTime_returnStringHour(){ + fun testGetStringScheduleLeftTime_returnStringHour() { val context = ApplicationProvider.getApplicationContext() val stringHour = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 0) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour,1) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour, 1) assertEquals(stringShouldDisplay, stringHour) } @Test - fun testGetStringScheduleLeftTime_returnStringHourAndMinute(){ + fun testGetStringScheduleLeftTime_returnStringHourAndMinute() { val context = ApplicationProvider.getApplicationContext() val stringHourAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 1) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour_minute,1, 1) + val stringShouldDisplay = + context.getString(R.string.wake_up_timer_schedule_set_hour_minute, 1, 1) assertEquals(stringShouldDisplay, stringHourAndMinute) } @Test - fun testGetStringScheduleLeftTime_returnStringHourAndMinutes(){ + fun testGetStringScheduleLeftTime_returnStringHourAndMinutes() { val context = ApplicationProvider.getApplicationContext() val stringHourAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 2) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour_minutes,1, 2) + val stringShouldDisplay = + context.getString(R.string.wake_up_timer_schedule_set_hour_minutes, 1, 2) assertEquals(stringShouldDisplay, stringHourAndMinutes) } @Test - fun testGetStringScheduleLeftTime_returnStringHours(){ + fun testGetStringScheduleLeftTime_returnStringHours() { val context = ApplicationProvider.getApplicationContext() val stringHours = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 0) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours,2, 0) + val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours, 2, 0) assertEquals(stringShouldDisplay, stringHours) } @Test - fun testGetStringScheduleLeftTime_returnStringHoursAndMinute(){ + fun testGetStringScheduleLeftTime_returnStringHoursAndMinute() { val context = ApplicationProvider.getApplicationContext() val stringHoursAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 1) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours_minute,2, 1) + val stringShouldDisplay = + context.getString(R.string.wake_up_timer_schedule_set_hours_minute, 2, 1) assertEquals(stringShouldDisplay, stringHoursAndMinute) } @Test - fun testGetStringScheduleLeftTime_returnStringHoursAndMinutes(){ + fun testGetStringScheduleLeftTime_returnStringHoursAndMinutes() { val context = ApplicationProvider.getApplicationContext() val stringHoursAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 2) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours_minutes,2, 2) + val stringShouldDisplay = + context.getString(R.string.wake_up_timer_schedule_set_hours_minutes, 2, 2) assertEquals(stringShouldDisplay, stringHoursAndMinutes) } From f1492f5fc1ff8788f5cdc5b5a1d0ab555b9a8630 Mon Sep 17 00:00:00 2001 From: Roberto Fuentes Date: Wed, 10 Mar 2021 21:33:34 +0100 Subject: [PATCH 6/7] test(app): Add WakeUpTimerManager.get() to return timer. fix(app): Change normal strings to plurals. Now code is more readable and smaller. test(app): Update unit tests. --- .../noice/fragment/WakeUpTimerFragmentTest.kt | 14 ++++- .../ashutoshgngwr/noice/WakeUpTimerManager.kt | 59 +++++++------------ app/src/main/res/values/strings.xml | 21 ++++--- .../noice/WakeUpTimerManagerTest.kt | 56 ++++++++++-------- 4 files changed, 79 insertions(+), 71 deletions(-) diff --git a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt index 12c0025a8..d7c4ba904 100644 --- a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt +++ b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt @@ -312,15 +312,25 @@ class WakeUpTimerFragmentTest { @Test fun testSetSchedule_ShowNotifySnackBar() { + val context = ApplicationProvider.getApplicationContext() every { Preset.readAllFromUserPreferences(any()) } returns arrayOf( mockk(relaxed = true) { - every { id } returns "test-preset" + every { id } returns "test-preset-id" every { name } returns "test-preset" } ) + + every { WakeUpTimerManager.get(any()) } returns mockk { + every { presetID } returns "test-preset-id" + every { atMillis } returns System.currentTimeMillis() + 10000L + every { shouldUpdateMediaVolume } returns true + every { mediaVolume } returns 10 + } + fragmentScenario.recreate() onView(withId(R.id.set_time_button)).perform(click()) - onView(withSubstring("Alarm will go off")).check(matches(isDisplayed())) + onView(withSubstring(context.getString(R.string.wake_up_timer_schedule_set))) + .check(matches(isDisplayed())) } } diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt index 3ba8a6a84..722366443 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt @@ -142,44 +142,27 @@ object WakeUpTimerManager { } fun getStringScheduleLeftTime(context: Context, diffHours: Int, diffMinutes: Int): String { - return when (diffHours) { - 0 -> { - when (diffMinutes) { - 0 -> context.getString(R.string.wake_up_timer_schedule_set_minute, diffMinutes) - 1 -> context.getString(R.string.wake_up_timer_schedule_set_minute, diffMinutes) - else -> context.getString(R.string.wake_up_timer_schedule_set_minutes, diffMinutes) - } - } - 1 -> { - when (diffMinutes) { - 0 -> context.getString(R.string.wake_up_timer_schedule_set_hour, diffHours) - 1 -> context.getString( - R.string.wake_up_timer_schedule_set_hour_minute, - diffHours, - diffMinutes - ) - else -> context.getString( - R.string.wake_up_timer_schedule_set_hour_minutes, - diffHours, - diffMinutes - ) - } - } - else -> { - when (diffMinutes) { - 0 -> context.getString(R.string.wake_up_timer_schedule_set_hours, diffHours) - 1 -> context.getString( - R.string.wake_up_timer_schedule_set_hours_minute, - diffHours, - diffMinutes - ) - else -> context.getString( - R.string.wake_up_timer_schedule_set_hours_minutes, - diffHours, - diffMinutes - ) - } - } + val startString = context.getString(R.string.wake_up_timer_schedule_set) + + val stringHours = if (diffHours == 0) { + "" + } else { + context.resources.getQuantityString(R.plurals.hours, diffHours, diffHours) + } + + val stringMinutes = if (diffMinutes == 0 && diffHours > 0) { + "" + } else if (diffMinutes == 0 && diffHours == 0) { + context.getString(R.string.wake_up_timer_schedule_set_0_minutes) + } else { + context.resources.getQuantityString(R.plurals.minutes, diffMinutes, diffMinutes) + } + + return if (diffHours > 0 && diffMinutes > 0) { + val bridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) + "$startString $stringHours $bridge $stringMinutes." + } else { + "$startString $stringHours$stringMinutes." } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac8a6cfa2..a91dd1b14 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -110,14 +110,19 @@ Schedule Select Preset Wake-up Timer cancelled! - Alarm will go off in %1$d hours and %2$d minutes - Alarm will go off in %1$d hours and %2$d minute - Alarm will go off in %1$d hour and %2$d minutes - Alarm will go off in %1$d hour and %2$d minute - Alarm will go off in %1$d hour - Alarm will go off in %1$d hours - Alarm will go off in %1$d minutes - Alarm will go off in %1$d minute + Alarm will go off in + and + 0 minutes + + %1$d hour + %1$d hours + + + + %1$d minute + %1$d minutes + + Noice will start the selected preset when the timer ends. Use the buttons below to select a preset and set the desired time to start the wake-up timer. diff --git a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt index f11c679c5..32fb30aa6 100644 --- a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt +++ b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt @@ -195,68 +195,78 @@ class WakeUpTimerManagerTest { val stringMinute1 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 0) val stringMinute2 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 1) - val stringShouldDisplay1 = context.getString(R.string.wake_up_timer_schedule_set_minute, 0) - val stringShouldDisplay2 = context.getString(R.string.wake_up_timer_schedule_set_minute, 1) - - assertEquals(stringShouldDisplay1, stringMinute1) - assertEquals(stringShouldDisplay2, stringMinute2) + val stringStart = context.getString(R.string.wake_up_timer_schedule_set) + val stringShouldDisplayMinute1 = context.resources.getQuantityString(R.plurals.minutes, 0, 0) + val stringShouldDisplayMinute2 = context.resources.getQuantityString(R.plurals.minutes, 1, 1) + assertEquals("$stringStart $stringShouldDisplayMinute1.", stringMinute1) + assertEquals("$stringStart $stringShouldDisplayMinute2.", stringMinute2) } @Test fun testGetStringScheduleLeftTime_returnStringHour() { val context = ApplicationProvider.getApplicationContext() val stringHour = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 0) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hour, 1) - assertEquals(stringShouldDisplay, stringHour) + val stringStart = context.getString(R.string.wake_up_timer_schedule_set) + val stringShouldDisplayHour = context.resources.getQuantityString(R.plurals.hours, 1, 1) + assertEquals("$stringStart $stringShouldDisplayHour.", stringHour) } @Test fun testGetStringScheduleLeftTime_returnStringHourAndMinute() { val context = ApplicationProvider.getApplicationContext() val stringHourAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 1) - val stringShouldDisplay = - context.getString(R.string.wake_up_timer_schedule_set_hour_minute, 1, 1) - assertEquals(stringShouldDisplay, stringHourAndMinute) + val stringStart = context.getString(R.string.wake_up_timer_schedule_set) + val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) + val stringShouldDisplayHour = context.resources.getQuantityString(R.plurals.hours, 1, 1) + val stringShouldDisplayMinute = context.resources.getQuantityString(R.plurals.minutes, 1, 1) + assertEquals("$stringStart $stringShouldDisplayHour $stringBridge $stringShouldDisplayMinute.", stringHourAndMinute) } @Test fun testGetStringScheduleLeftTime_returnStringHourAndMinutes() { val context = ApplicationProvider.getApplicationContext() - val stringHourAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 2) - val stringShouldDisplay = - context.getString(R.string.wake_up_timer_schedule_set_hour_minutes, 1, 2) + val stringHourAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 30) - assertEquals(stringShouldDisplay, stringHourAndMinutes) + val stringStart = context.getString(R.string.wake_up_timer_schedule_set) + val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) + val stringShouldDisplayHour = context.resources.getQuantityString(R.plurals.hours, 1, 1) + val stringShouldDisplayMinutes = context.resources.getQuantityString(R.plurals.minutes, 30, 30) + assertEquals("$stringStart $stringShouldDisplayHour $stringBridge $stringShouldDisplayMinutes.", stringHourAndMinutes) } @Test fun testGetStringScheduleLeftTime_returnStringHours() { val context = ApplicationProvider.getApplicationContext() val stringHours = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 0) - val stringShouldDisplay = context.getString(R.string.wake_up_timer_schedule_set_hours, 2, 0) - assertEquals(stringShouldDisplay, stringHours) + val stringStart = context.getString(R.string.wake_up_timer_schedule_set) + val stringShouldDisplayHours = context.resources.getQuantityString(R.plurals.hours, 2, 2) + assertEquals("$stringStart $stringShouldDisplayHours.", stringHours) } @Test fun testGetStringScheduleLeftTime_returnStringHoursAndMinute() { val context = ApplicationProvider.getApplicationContext() val stringHoursAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 1) - val stringShouldDisplay = - context.getString(R.string.wake_up_timer_schedule_set_hours_minute, 2, 1) - assertEquals(stringShouldDisplay, stringHoursAndMinute) + val stringStart = context.getString(R.string.wake_up_timer_schedule_set) + val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) + val stringShouldDisplayHours = context.resources.getQuantityString(R.plurals.hours, 2, 2) + val stringShouldDisplayMinute = context.resources.getQuantityString(R.plurals.minutes, 1, 1) + assertEquals("$stringStart $stringShouldDisplayHours $stringBridge $stringShouldDisplayMinute.", stringHoursAndMinute) } @Test fun testGetStringScheduleLeftTime_returnStringHoursAndMinutes() { val context = ApplicationProvider.getApplicationContext() - val stringHoursAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 2) - val stringShouldDisplay = - context.getString(R.string.wake_up_timer_schedule_set_hours_minutes, 2, 2) + val stringHoursAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 30) - assertEquals(stringShouldDisplay, stringHoursAndMinutes) + val stringStart = context.getString(R.string.wake_up_timer_schedule_set) + val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) + val stringShouldDisplayHours = context.resources.getQuantityString(R.plurals.hours, 2, 2) + val stringShouldDisplayMinutes = context.resources.getQuantityString(R.plurals.minutes, 30, 30) + assertEquals("$stringStart $stringShouldDisplayHours $stringBridge $stringShouldDisplayMinutes.", stringHoursAndMinutes) } } From bb3f82f3109685c767920c19b09da4bca934b757 Mon Sep 17 00:00:00 2001 From: Ashutosh Gangwar Date: Thu, 11 Mar 2021 14:31:27 +0530 Subject: [PATCH 7/7] refactor(app): clean up plurals logic for time in WakeUpTimeFragment --- .../noice/fragment/WakeUpTimerFragmentTest.kt | 69 ++++++---------- .../ashutoshgngwr/noice/WakeUpTimerManager.kt | 25 ------ .../noice/fragment/WakeUpTimerFragment.kt | 41 +++++++--- app/src/main/res/values/strings.xml | 11 +-- .../noice/WakeUpTimerManagerTest.kt | 81 ------------------- 5 files changed, 57 insertions(+), 170 deletions(-) diff --git a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt index d7c4ba904..13f84878b 100644 --- a/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt +++ b/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt @@ -50,9 +50,7 @@ class WakeUpTimerFragmentTest { @Before fun setup() { - mockkObject(InAppReviewFlowManager) - mockkObject(Preset.Companion) - mockkObject(WakeUpTimerManager) + mockkObject(InAppReviewFlowManager, Preset.Companion, WakeUpTimerManager) every { WakeUpTimerManager.set(any(), any()) } returns Unit fragmentScenario = launchFragmentInContainer(null, R.style.Theme_App) } @@ -167,25 +165,6 @@ class WakeUpTimerFragmentTest { } ) - onView(withId(R.id.select_preset_button)) - .check(matches(withText(R.string.select_preset))) - .perform(click()) - - EspressoX.waitForView(withId(android.R.id.list)) - .check(matches(withChild(withText("test-1")))) - .check(matches(withChild(withText("test-2")))) - - onView(withText("test-1")) - .perform(click()) - - onView(withId(R.id.select_preset_button)) - .check(matches(withText("test-1"))) - - verify(exactly = 0) { WakeUpTimerManager.set(any(), any()) } - - onView(withId(R.id.time_picker)) - .perform(PickerActions.setTime(1, 2)) - val am = ApplicationProvider.getApplicationContext().getSystemService() requireNotNull(am) val maxVol = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC) @@ -193,6 +172,24 @@ class WakeUpTimerFragmentTest { val expectedVolume = Random.nextInt(minVol, maxVol) for (shouldUpdateMediaVolume in arrayOf(true, false)) { + onView(withId(R.id.select_preset_button)) + .perform(click()) + + EspressoX.waitForView(withId(android.R.id.list)) + .check(matches(withChild(withText("test-1")))) + .check(matches(withChild(withText("test-2")))) + + onView(withText("test-1")) + .perform(click()) + + onView(withId(R.id.select_preset_button)) + .check(matches(withText("test-1"))) + + verify(exactly = 0) { WakeUpTimerManager.set(any(), any()) } + + onView(withId(R.id.time_picker)) + .perform(PickerActions.setTime(1, 2)) + onView(withId(R.id.should_update_media_volume)) .perform(scrollTo(), EspressoX.setChecked(shouldUpdateMediaVolume)) @@ -231,6 +228,10 @@ class WakeUpTimerFragmentTest { } onView(withId(R.id.reset_time_button)).check(matches(isEnabled())) + onView(withSubstring("The alarm will go off in")) + .check(matches(isDisplayed())) + + fragmentScenario.recreate() } } @@ -309,28 +310,4 @@ class WakeUpTimerFragmentTest { onView(withId(R.id.select_preset_button)) .check(matches(withText("test-not-saved-preset-1"))) } - - @Test - fun testSetSchedule_ShowNotifySnackBar() { - val context = ApplicationProvider.getApplicationContext() - every { Preset.readAllFromUserPreferences(any()) } returns arrayOf( - mockk(relaxed = true) { - every { id } returns "test-preset-id" - every { name } returns "test-preset" - } - ) - - every { WakeUpTimerManager.get(any()) } returns mockk { - every { presetID } returns "test-preset-id" - every { atMillis } returns System.currentTimeMillis() + 10000L - every { shouldUpdateMediaVolume } returns true - every { mediaVolume } returns 10 - } - - fragmentScenario.recreate() - - onView(withId(R.id.set_time_button)).perform(click()) - onView(withSubstring(context.getString(R.string.wake_up_timer_schedule_set))) - .check(matches(isDisplayed())) - } } diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt index 722366443..04a08c235 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/WakeUpTimerManager.kt @@ -141,31 +141,6 @@ object WakeUpTimerManager { } } - fun getStringScheduleLeftTime(context: Context, diffHours: Int, diffMinutes: Int): String { - val startString = context.getString(R.string.wake_up_timer_schedule_set) - - val stringHours = if (diffHours == 0) { - "" - } else { - context.resources.getQuantityString(R.plurals.hours, diffHours, diffHours) - } - - val stringMinutes = if (diffMinutes == 0 && diffHours > 0) { - "" - } else if (diffMinutes == 0 && diffHours == 0) { - context.getString(R.string.wake_up_timer_schedule_set_0_minutes) - } else { - context.resources.getQuantityString(R.plurals.minutes, diffMinutes, diffMinutes) - } - - return if (diffHours > 0 && diffMinutes > 0) { - val bridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) - "$startString $stringHours $bridge $stringMinutes." - } else { - "$startString $stringHours$stringMinutes." - } - } - /** * [BootReceiver] ensures that a scheduled [Timer] is able to persist across device restarts. */ diff --git a/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt b/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt index d7591bb59..50a45bdbd 100644 --- a/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt +++ b/app/src/main/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragment.kt @@ -205,24 +205,43 @@ class WakeUpTimerFragment : Fragment() { private fun notifyScheduleLeftTime() { - val actualTime = System.currentTimeMillis() - var differenceMillis = selectedTime - actualTime + val differenceMillis = selectedTime - System.currentTimeMillis() + if (differenceMillis < 0) { + return // should it ever happen? + } - val diffHours = TimeUnit.MILLISECONDS.toHours(differenceMillis) - differenceMillis -= TimeUnit.HOURS.toMillis(diffHours) - val diffMinutes = TimeUnit.MILLISECONDS.toMinutes(differenceMillis) + val diffHours = TimeUnit.MILLISECONDS.toHours(differenceMillis).toInt() + val diffMinutes = TimeUnit.MILLISECONDS.toMinutes(differenceMillis).toInt() % 60 Snackbar.make( requireView(), - WakeUpTimerManager.getStringScheduleLeftTime( - requireContext(), - diffHours.toInt(), - diffMinutes.toInt() - ), - Snackbar.LENGTH_SHORT + getRelativeDurationString(diffHours, diffMinutes), + Snackbar.LENGTH_LONG ).show() } + private val matchSpacesRegex = """\s+""".toRegex() + + private fun getRelativeDurationString(hours: Int, minutes: Int): String { + var minutePlural = "" + if (minutes > 0 || hours == 0) { + minutePlural = resources.getQuantityString(R.plurals.time_minutes, minutes, minutes) + } + + var hourPlural = "" + if (hours > 0) { + hourPlural = resources.getQuantityString(R.plurals.time_hours, hours, hours) + } + + var timeBridge = "" + if (hours * minutes != 0) { + timeBridge = getString(R.string.time_bridge) + } + + return getString(R.string.wake_up_timer_schedule_set, hourPlural, timeBridge, minutePlural) + .replace(matchSpacesRegex, " ") + } + private fun resetControls() { loadSelectedPresetID() selectedTime = 0 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a91dd1b14..1885b9ad1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -110,19 +110,16 @@ Schedule Select Preset Wake-up Timer cancelled! - Alarm will go off in - and - 0 minutes - + The alarm will go off in %1$s %2$s %3$s + and + %1$d hour %1$d hours - - + %1$d minute %1$d minutes - Noice will start the selected preset when the timer ends. Use the buttons below to select a preset and set the desired time to start the wake-up timer. diff --git a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt index 32fb30aa6..83b9e6a73 100644 --- a/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt +++ b/app/src/test/java/com/github/ashutoshgngwr/noice/WakeUpTimerManagerTest.kt @@ -188,85 +188,4 @@ class WakeUpTimerManagerTest { assertEquals(presetID, WakeUpTimerManager.getLastUsedPresetID(context)) } - - @Test - fun testGetStringScheduleLeftTime_returnStringMinute() { - val context = ApplicationProvider.getApplicationContext() - val stringMinute1 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 0) - val stringMinute2 = WakeUpTimerManager.getStringScheduleLeftTime(context, 0, 1) - - val stringStart = context.getString(R.string.wake_up_timer_schedule_set) - val stringShouldDisplayMinute1 = context.resources.getQuantityString(R.plurals.minutes, 0, 0) - val stringShouldDisplayMinute2 = context.resources.getQuantityString(R.plurals.minutes, 1, 1) - assertEquals("$stringStart $stringShouldDisplayMinute1.", stringMinute1) - assertEquals("$stringStart $stringShouldDisplayMinute2.", stringMinute2) - } - - @Test - fun testGetStringScheduleLeftTime_returnStringHour() { - val context = ApplicationProvider.getApplicationContext() - val stringHour = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 0) - - val stringStart = context.getString(R.string.wake_up_timer_schedule_set) - val stringShouldDisplayHour = context.resources.getQuantityString(R.plurals.hours, 1, 1) - assertEquals("$stringStart $stringShouldDisplayHour.", stringHour) - } - - @Test - fun testGetStringScheduleLeftTime_returnStringHourAndMinute() { - val context = ApplicationProvider.getApplicationContext() - val stringHourAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 1) - - val stringStart = context.getString(R.string.wake_up_timer_schedule_set) - val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) - val stringShouldDisplayHour = context.resources.getQuantityString(R.plurals.hours, 1, 1) - val stringShouldDisplayMinute = context.resources.getQuantityString(R.plurals.minutes, 1, 1) - assertEquals("$stringStart $stringShouldDisplayHour $stringBridge $stringShouldDisplayMinute.", stringHourAndMinute) - } - - @Test - fun testGetStringScheduleLeftTime_returnStringHourAndMinutes() { - val context = ApplicationProvider.getApplicationContext() - val stringHourAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 1, 30) - - val stringStart = context.getString(R.string.wake_up_timer_schedule_set) - val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) - val stringShouldDisplayHour = context.resources.getQuantityString(R.plurals.hours, 1, 1) - val stringShouldDisplayMinutes = context.resources.getQuantityString(R.plurals.minutes, 30, 30) - assertEquals("$stringStart $stringShouldDisplayHour $stringBridge $stringShouldDisplayMinutes.", stringHourAndMinutes) - } - - @Test - fun testGetStringScheduleLeftTime_returnStringHours() { - val context = ApplicationProvider.getApplicationContext() - val stringHours = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 0) - - val stringStart = context.getString(R.string.wake_up_timer_schedule_set) - val stringShouldDisplayHours = context.resources.getQuantityString(R.plurals.hours, 2, 2) - assertEquals("$stringStart $stringShouldDisplayHours.", stringHours) - } - - @Test - fun testGetStringScheduleLeftTime_returnStringHoursAndMinute() { - val context = ApplicationProvider.getApplicationContext() - val stringHoursAndMinute = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 1) - - val stringStart = context.getString(R.string.wake_up_timer_schedule_set) - val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) - val stringShouldDisplayHours = context.resources.getQuantityString(R.plurals.hours, 2, 2) - val stringShouldDisplayMinute = context.resources.getQuantityString(R.plurals.minutes, 1, 1) - assertEquals("$stringStart $stringShouldDisplayHours $stringBridge $stringShouldDisplayMinute.", stringHoursAndMinute) - } - - @Test - fun testGetStringScheduleLeftTime_returnStringHoursAndMinutes() { - val context = ApplicationProvider.getApplicationContext() - val stringHoursAndMinutes = WakeUpTimerManager.getStringScheduleLeftTime(context, 2, 30) - - val stringStart = context.getString(R.string.wake_up_timer_schedule_set) - val stringBridge = context.getString(R.string.wake_up_timer_schedule_set_bridge) - val stringShouldDisplayHours = context.resources.getQuantityString(R.plurals.hours, 2, 2) - val stringShouldDisplayMinutes = context.resources.getQuantityString(R.plurals.minutes, 30, 30) - assertEquals("$stringStart $stringShouldDisplayHours $stringBridge $stringShouldDisplayMinutes.", stringHoursAndMinutes) - } }