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

Refresh room summaries when date or time changes in the device #3683

Merged

Conversation

jmartinesp
Copy link
Member

Content

  • Create DateTimeObserver, which will register a receiver for date and time changes in the devices and emit updates.
  • Have RoomListDataSource listen to those updates.
  • Refresh the summary timestamps when an update is received.
  • Modify the DI so we have a TimezoneProvider instead of injecting the Timezone used when the app was opened.

Alternative to #3650.

Motivation and context

There is a bug where in the room list you might be able to see rooms whose state hasn't changed since yesterday still displaying the time at which some event happened instead of 'Yesterday', making you think they happened at some time today and they're out of order.

If you open one of these rooms, the room list item is also refreshed and the right 'Yesterday' formatted timestamp is used.

The same happens with the time if you change the timezone of your device.

Screenshots / GIFs

They should be the same.

Tests

  • Open the app and let the room list load completely until it doesn't receive new updates.
  • Go to system settings -> change the day. Check the timestamps change in the room list.
  • Restore the current value, check it changes back to what's expected.
  • Now change the timezone and check the time also changes in the room list.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • Pull request includes a sign off
  • You've made a self review of your PR

@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Oct 15, 2024
@jmartinesp jmartinesp requested a review from a team as a code owner October 15, 2024 09:56
@jmartinesp jmartinesp requested review from bmarty and removed request for a team October 15, 2024 09:56
Copy link
Contributor

github-actions bot commented Oct 15, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/2aVDVR

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 51.28205% with 19 lines in your changes missing coverage. Please review.

Project coverage is 82.79%. Comparing base (a4966ef) to head (fdd71e4).
Report is 5 commits behind head on develop.

Files with missing lines Patch % Lines
.../libraries/androidutils/system/DateTimeObserver.kt 11.11% 16 Missing ⚠️
...res/roomlist/impl/datasource/RoomListDataSource.kt 86.66% 0 Missing and 2 partials ⚠️
...aries/dateformatter/impl/di/DateFormatterModule.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3683      +/-   ##
===========================================
- Coverage    82.81%   82.79%   -0.03%     
===========================================
  Files         1748     1749       +1     
  Lines        41777    41808      +31     
  Branches      5108     5113       +5     
===========================================
+ Hits         34597    34614      +17     
- Misses        5365     5379      +14     
  Partials      1815     1815              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

A few remarks.

}

@ContributesBinding(AppScope::class)
class DefaultDateTimeObserver @Inject constructor(
Copy link
Member

Choose a reason for hiding this comment

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

This need to be a singleton, else you are registering many BroadcastReceiver, and they are never unregistered.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch, I completely forgot to add the @SingleIn annotation.

Intent.ACTION_DATE_CHANGED -> changes.tryEmit(Event.DateChanged(lastTime, newDate))
Intent.ACTION_TIME_CHANGED -> changes.tryEmit(Event.DateChanged(lastTime, newDate))
}
lastTime = newDate
Copy link
Member

Choose a reason for hiding this comment

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

Maybe update lastTime only for the cases Intent.ACTION_DATE_CHANGED and Intent.ACTION_TIME_CHANGED? But actually previous and new does not seem to be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added them in case we wanted to generate new timestamps only if >= 1 day had elapsed between them, but there's not really a need for that now that I think about it... they might not be worth keeping.

@@ -24,6 +24,7 @@ interface MutableDiffCache<E> : DiffCache<E> {
fun removeAt(index: Int): E?
fun add(index: Int, element: E?)
operator fun set(index: Int, element: E?)
fun clear()
Copy link
Member

Choose a reason for hiding this comment

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

Not used?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a leftover from previous tests that I forgot to remove, thanks!

@@ -25,5 +26,5 @@ object DateFormatterModule {
fun providesLocale(): Locale = Locale.getDefault()

@Provides
fun providesTimezone(): TimeZone = TimeZone.currentSystemDefault()
fun providesTimezone(): TimezoneProvider = TimezoneProvider { TimeZone.currentSystemDefault() }
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if requesting TimeZone.currentSystemDefault() for all Events could come at a cost. We could maybe have a flow of TimeZone that emit new item when the timezone change?

Copy link
Member Author

Choose a reason for hiding this comment

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

There might be some tiny overhead from instantiating the value, but I don't think it's noticeable at all. The underlying code is cloning an existing value AFAICT, then just wrapping it in a new object. Reusing the observer for this feels like an overkill, to be honest.

@jmartinesp jmartinesp force-pushed the fix/jme/add-datetime-observer-to-update-the-room-list branch from e63d5cb to b3be170 Compare October 15, 2024 16:21
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Thanks for the update! I took the liberty to add a few commits to improve the test.

@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Oct 16, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Oct 16, 2024
@jmartinesp jmartinesp enabled auto-merge (squash) October 16, 2024 08:46
Copy link

sonarcloud bot commented Oct 16, 2024

@jmartinesp jmartinesp merged commit 2e9dce3 into develop Oct 16, 2024
28 of 30 checks passed
@jmartinesp jmartinesp deleted the fix/jme/add-datetime-observer-to-update-the-room-list branch October 16, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants