-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Added Visual confirmation when Wake Up timer is set. Request solution #502. #554
Conversation
…o get the correct string to notify user the schedule left time.
Codecov Report
@@ Coverage Diff @@
## master #554 +/- ##
==========================================
- Coverage 49.09% 48.48% -0.62%
==========================================
Files 32 32
Lines 1821 1844 +23
Branches 175 179 +4
==========================================
Hits 894 894
- Misses 880 903 +23
Partials 47 47
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I don't know why the commit |
It's an issue with editorconfig and Weblate. Android Studio has built-in support for editorconfig, and Weblate doesn't support it at all. Leave it be for now! I'll add another editorconfig file with weblate-styles for string resources later. |
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 | ||
) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed if you switch to Plurals. But plurals don't support multiple params so you'll have to concatenate strings together. Both ways are hell to translate. Your call.
Plural string should look something like:
<string name="...">Alarm will go off in %1$s %2$s.</string><!-- but, you can't add 'and' now -->
<plurals name="hours">
<item quantity="zero"></item>
<item quantity="one">%d hour</item>
<item quantity="other">%d hours</item>
</plurals>
<plurals name="minutes">
<item quantity="zero"></item>
<item quantity="one">%d minute</item>
<item quantity="other">%d minutes</item>
</plurals>
The code is just for demo. It may not work as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the first time I heard about plurals and this is a much better solution when it comes to reading code. So after playing with plurals I've decided to keep it and I'll update unit tests. Tell me which solution do you preffer once I update changes.
@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())) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this test-case to work, you need to mock WakeUpTimerManager.get()
and return a timer in future.
fix(app): Change normal strings to plurals. Now code is more readable and smaller. test(app): Update unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me see if I can make plural logic cleaner. :)
|
||
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 | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it appears that I made the wrong suggestion. I forgot to consider that the snack bar is only shown after the "Schedule" button is clicked. You can verify this behaviour in testSetTimer()
test-case. Add your assertions after the action on line 208.
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." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This concatenation will work for English, but it may not work for other languages. e.g., in my native language, the translation would be
अलार्म 1 घंटे और 20 मिनट में बजेगा।
which, if translated one word at a time, translates to
Alarm 1 hour and 20 minutes in will-ring.
I'd suggest using the original suggestion I made. Leave a placeholder in the message string to insert pluralised versions of minute and hour strings. e.g.
Alarm will go off in %1$s and %2$s.
And then you can format it with the hour and minutes plurals.
Bonus: you can also make your bridge a plural. e.g.
<plurals name="hours">
<item quantity="zero"></item>
<item quantity="zero"></item>
<item quantity="other">and</item>
</plurals>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I didn't think about that, I'll set the string format with placeholders. About making bridge plural I've tried that but had no luck to make it work, maybe I'm doing something wrong? For now I'll set the string like you told me.
Alarm will go off in %1$s and %2$s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already fixed it in my local copy. Working on the test-case. Will push it soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good now!
@robercoding Thanks for putting in the work to fix these issues. I see a lot of your work was undone in refactoring. PS, discussing changes before heading into implementation and creating a PR right after your first commit will help prevent these situations. Let me know if you'd like to continue working. |
Changes
Implemented solution showing with a snackbar to user of when alarm will go of.
For that I have added different strings so it's more clear to the user.
Added unit tests tests making sure appropiate strings appear on screen.
Added UI Test checking snackbar shows up.
Testing
Others
Tell me if you like it or want some specific changes!