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

Added Visual confirmation when Wake Up timer is set. Request solution #502. #554

Merged
merged 8 commits into from
Mar 11, 2021

Conversation

robercoding
Copy link
Contributor

@robercoding robercoding commented Mar 10, 2021

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

  • [✔️] Tested on a emulator device
  • [✔️] Added unit tests.
  • [✔️] Added UI test.

Others

Tell me if you like it or want some specific changes!

@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #554 (4ce7197) into master (9f286c7) will decrease coverage by 0.61%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
android 45.02% <0.00%> (-0.62%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...shutoshgngwr/noice/fragment/WakeUpTimerFragment.kt 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1843337...4ce7197. Read the comment docs.

@robercoding
Copy link
Contributor Author

I don't know why the commit 7e6fedf8 did that thing on strings.xml. I think it's because of different formating or something (I use Android Studio on Windows 10), but sorry about that!

@ashutoshgngwr
Copy link
Member

ashutoshgngwr commented Mar 10, 2021

I don't know why the commit 7e6fedf8 did that thing on strings.xml. I think it's because of different formating or something (I use Android Studio on Windows 10), but sorry about that!

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.

Comment on lines 144 to 184
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
)
}
}
}
}
Copy link
Member

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.

Copy link
Contributor Author

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.

Comment on lines 313 to 325
@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()))
}
Copy link
Member

@ashutoshgngwr ashutoshgngwr Mar 10, 2021

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.
Copy link
Member

@ashutoshgngwr ashutoshgngwr left a 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. :)

Comment on lines 322 to 329

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
}

Copy link
Member

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.

https://github.com/ashutoshgngwr/noice/blob/f1492f5fc1ff8788f5cdc5b5a1d0ab555b9a8630/app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/WakeUpTimerFragmentTest.kt#L157-L235

Comment on lines 161 to 165
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."
Copy link
Member

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>

Copy link
Contributor Author

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.

Copy link
Member

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.

@ashutoshgngwr ashutoshgngwr marked this pull request as ready for review March 11, 2021 09:03
Copy link
Member

@ashutoshgngwr ashutoshgngwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good now!

@ashutoshgngwr ashutoshgngwr merged commit 494f168 into trynoice:master Mar 11, 2021
@ashutoshgngwr
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visual confirmation that the Wake Up timer is set
2 participants