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

[Room List] Show offline indicator when the device is offline #239

Merged
merged 7 commits into from
Apr 17, 2023

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Mar 21, 2023

What

  • Adds :feature:networkmonitor module containing a NetworkMonitor component that listens to the network connection status.
  • Creates a ConnectivityIndicatorView following the designs, that will appear and disappear with an animation.

Why

Implements #141 .

Tests

On both the room list and chat screens, turn airplane mode on and off.

@jmartinesp jmartinesp force-pushed the feature/jme/offline-status-banner branch from 1605097 to 73d12e8 Compare March 30, 2023 16:55
@jmartinesp jmartinesp requested review from a team and Florian14 and removed request for a team March 30, 2023 16:58
@github-actions
Copy link
Contributor

github-actions bot commented Mar 30, 2023

📱 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/3RH3ba

@codecov
Copy link

codecov bot commented Mar 30, 2023

Codecov Report

Patch coverage: 55.55% and project coverage change: +1.34 🎉

Comparison is base (775cf2a) 44.36% compared to head (3dbc173) 45.71%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #239      +/-   ##
===========================================
+ Coverage    44.36%   45.71%   +1.34%     
===========================================
  Files          544      590      +46     
  Lines        12584    13338     +754     
  Branches      2628     2807     +179     
===========================================
+ Hits          5583     6097     +514     
- Misses        5970     6095     +125     
- Partials      1031     1146     +115     
Impacted Files Coverage Δ
...features/networkmonitor/impl/NetworkMonitorImpl.kt 0.00% <0.00%> (ø)
.../element/android/samples/minimal/RoomListScreen.kt 0.00% <0.00%> (ø)
...networkmonitor/api/ui/ConnectivityIndicatorView.kt 62.22% <62.22%> (ø)
...ndroid/features/roomlist/impl/RoomListPresenter.kt 89.41% <66.66%> (-0.95%) ⬇️
...ndroid/features/messages/impl/MessagesPresenter.kt 83.60% <75.00%> (-0.61%) ⬇️
...ent/android/features/roomlist/impl/RoomListView.kt 63.04% <77.77%> (+0.99%) ⬆️
...ent/android/features/messages/impl/MessagesView.kt 58.00% <88.88%> (+2.32%) ⬆️
...nt/android/features/messages/impl/MessagesState.kt 100.00% <100.00%> (ø)
...id/features/messages/impl/MessagesStateProvider.kt 94.11% <100.00%> (+0.78%) ⬆️
...droid/features/networkmonitor/api/NetworkStatus.kt 100.00% <100.00%> (ø)
... and 8 more

... and 152 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jmartinesp jmartinesp marked this pull request as ready for review March 30, 2023 18:10
@Florian14
Copy link
Contributor

Just tested it on my device, the banner pops and disappears immediately

@jmartinesp
Copy link
Member Author

Just tested it on my device, the banner pops and disappears immediately

Could you add some more info or upload a video? I haven't seen anything like that while testing it on both an emulator and a real device.

@Florian14
Copy link
Contributor

Just tested it on my device, the banner pops and disappears immediately

Could you add some more info or upload a video? I haven't seen anything like that while testing it on both an emulator and a real device.

Screen_Recording_20230331_145328_ElementX.dbg.mp4

@jmartinesp
Copy link
Member Author

Ok, that's super weird. Which device model is it? And its Android version?

@Florian14
Copy link
Contributor

Florian14 commented Mar 31, 2023

Ok, that's super weird. Which device model is it? And its Android version?

S10e running Android 12, I can debug a bit if you want. I installed using the apk from diawi

Edit: I'll do the code review first, in case I find the problem

Copy link
Contributor

@Florian14 Florian14 left a comment

Choose a reason for hiding this comment

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

Some interesting logs:

16:44:34.935 NetworkMon...s$callback  V  Connectivity status (lost): Online
16:44:35.208 NetworkMon...s$callback  V  Connectivity status (available): Online
16:44:35.214 NetworkMon...s$callback  V  Connectivity status (changed): Online
16:44:36.148 NetworkMon...s$callback  V  Connectivity status (lost): Online

But the code looks good... I'll debug to see how the connectivity manager behaves on my device

modifier = Modifier.size(16.dp),
)
Spacer(modifier = Modifier.width(8.dp))
Text(text = "Offline", style = ElementTextStyles.Regular.bodyMD, color = tint)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this string should be defined in localazy

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in b7dfd75

@jmartinesp jmartinesp force-pushed the feature/jme/offline-status-banner branch from b7dfd75 to a9940e4 Compare April 5, 2023 09:36
@jmartinesp
Copy link
Member Author

@Florian14 did you have a chance to test it on your device again? Sadly, it seems like I can't reproduce the issue you mentioned 🙁 .

@Florian14
Copy link
Contributor

@Florian14 did you have a chance to test it on your device again? Sadly, it seems like I can't reproduce the issue you mentioned 🙁 .

Can you merge/rebase your branch on develop? It seems that the apk is not available anymore :/

@jmartinesp jmartinesp requested a review from Florian14 April 13, 2023 09:15
@Florian14
Copy link
Contributor

@jmartinesp I still have the issue :/ Maybe we can ask someone else to test it. Otherwise, I should probably do the investigation by myself as you're not able to reproduce but I don't have time to do it right now.

@jmartinesp
Copy link
Member Author

jmartinesp commented Apr 13, 2023

@jmartinesp I still have the issue :/ Maybe we can ask someone else to test it. Otherwise, I should probably do the investigation by myself as you're not able to reproduce but I don't have time to do it right now.

Ok, I'll re-assign the reviewer. I'll also try to get my hands in a Samsung device to check if it's a vendor issue, I might know someone who can lend me a test device.

@jmartinesp jmartinesp requested review from a team and bmarty and removed request for Florian14 and a team April 13, 2023 13:43
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.

I do not have the issue reported by Florian (tested on emu API 33), also if I test some of my remark the feature was sort of broken, so be careful, do no trust me too much :).

}
}

// Show missing status bar padding when the indicator is not visible
Copy link
Member

Choose a reason for hiding this comment

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

This comment does not really match the behavior, I would expect to have the code below surrounded by if (!isOnline).

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, the message is accurate, although it's a bit difficult to follow: the TopAppBar component has a default top padding equal to the statusbar height, but to present this indicator behind the statusbar we remove it by default. So when no indicator is shown we need a placeholder Spacer with that same height/padding to keep the TopAppBar in its expected position instead of below the statusbar.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I understand. I would have made the padding always visible and the network status bar not include the padding.

It would also fix the weird effect (to me!) to see the status bar moving under the system top status bar. But not a blocker, thanks for the explanaition.

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 tried to do that at first with a Box, but as the TopAppBar needs to move down when the indicator appears, it was quite hard to build it that way. There might be a simpler solution though.


private val connectivityManager: ConnectivityManager by lazy {
context.getSystemService(ConnectivityManager::class.java)
}
Copy link
Member

Choose a reason for hiding this comment

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

not useful to use lazy, since connectivityManager is used in the constructor.

private fun subscribeToConnectionChanges() {
if (callback != null) return

val callback = object : ConnectivityManager.NetworkCallback() {
Copy link
Member

Choose a reason for hiding this comment

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

Why not make this.callback a val and init it at declaration?

@@ -71,6 +73,7 @@ fun RoomListTopBar(
onFilterChanged: (String) -> Unit,
onOpenSettings: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
useStatusBarInsets: Boolean,
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?

import timber.log.Timber
import javax.inject.Inject

@ContributesBinding(scope = AppScope::class, boundType = NetworkMonitor::class)
Copy link
Member

Choose a reason for hiding this comment

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

Neat: this is not necessary to specify the boundType, since this class implement only one interface (it was maybe not the case before :))

visible = !isOnline,
enter = expandVertically(),
exit = shrinkVertically(),
) {
Copy link
Member

Choose a reason for hiding this comment

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

The animation is mixing with the animation when switching between room list and message list, this is a bit weird. It should just animate when the network state changes.

@jmartinesp
Copy link
Member Author

@bmarty I think all you comments should have been solved in 3dbc173.

Also, I tested the branch in a Samsung device (although not the same model as @Florian14 's) and I couldn't reproduce the issue, so either it's solved (there's always hope) or it's specific to some device/version of the OS.

@jmartinesp jmartinesp requested a review from bmarty April 17, 2023 05:46
@manuroe
Copy link
Member

manuroe commented Apr 17, 2023

If it can help, the offline banner works as expected on my Samsung A50.

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 udpate! (will test again and report issue (if any!) once on the nightly).

@jmartinesp jmartinesp merged commit bfac069 into develop Apr 17, 2023
@jmartinesp jmartinesp deleted the feature/jme/offline-status-banner branch April 17, 2023 15:01
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.

4 participants