Skip to content

Migrate WebViews activities to Jetpack Compose #5419

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

Merged
merged 13 commits into from
Jun 24, 2025
Merged

Conversation

TimoPtr
Copy link
Collaborator

@TimoPtr TimoPtr commented Jun 17, 2025

Summary

The application have multiple activities that uses WebViews. This PR migrate all the screens from XML views to Jetpack Compose. The end goal is for easier management of edge to edge so that this PR #5387 can be merged.

A first initiative was made #5346 and followed by #5390. On the latter we suggested to migrate to Compose to apply the same logic everywhere instead of dealing with XML and Compose.

The main challenge on this PR was on WebViewActivity that is quite complex. The MediaPlayer is displayed at a specific place on the screen given by the frontend through the external bus. It also has some bluring to hide the content of the WebView when the app is locked.

For the Bluring I've introduce the Haze library. For the player I've used the HAMediaPlayer made in #5408

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Screenshots

We cannot make a screenshot of the app in lock state because of biometric bottom is marked as SECURE.

WebViewMedia.mp4

Any other notes

I tried to limit as maximum the changes on the WebViewActivity to make the review easy, but to be honest it was hard a lot of things could be improved.

When adding haze-materials to the project it did brings material3 in our app and a new lint rule that verify that we are not mixing material 2 and 3, I've disabled it for now since it's too verbose and created an issue #5420

@TimoPtr TimoPtr marked this pull request as ready for review June 17, 2025 12:02
factory = { context ->
(factory() ?: WebView(context)).apply {
// We want the modifier to determine the size so the WebView should match the parent
this.layoutParams = FrameLayout.LayoutParams(

Choose a reason for hiding this comment

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

Today, I discovered that this this.layoutParams = [...] with match parent causes Webview to set correct CSS env(safe-area-insets-*) values. I tested it on webview 137, on 119 it is not working.
But I am not sure if it really matters because it's not very stable or/and documented.

Copy link
Member

@dshokouhi dshokouhi left a comment

Choose a reason for hiding this comment

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

Tested the debug build and did not see any issues on my end

@dshokouhi
Copy link
Member

Apologize but 1 minor difference I need to call out after testing a different PR, very minor. When you initially onboard and select your server this PR pushes down the login page.

This PR:
image

Prod:
image

again not a big deal as user can login and the dashboard is not impacted by this but still a difference I saw :)

@TimoPtr
Copy link
Collaborator Author

TimoPtr commented Jun 20, 2025

Apologize but 1 minor difference I need to call out after testing a different PR, very minor. When you initially onboard and select your server this PR pushes down the login page.

This PR:
image

Prod:
image

again not a big deal as user can login and the dashboard is not impacted by this but still a difference I saw :)

I think that actually I fixed it. Could you try on Chrome? It's because now I'm fixing the FrameLayout to fill the parents where because it was a wrap content.

@dshokouhi
Copy link
Member

Could you try on Chrome? It's because now I'm fixing the FrameLayout to fill the parents where because it was a wrap content.

in chrome on the same device it actually matches the changes in this PR 🙈

never noticed because I always use the app haha

Copy link
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

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

Tested on a modern real device and old emulator and seems to work OK. Code looks mostly good to.

Haze's blur seems a lot stronger/blurrier than the other library. On my dashboard I have a sensor card and with the old library I can see some yellow when blurred, but definitely not with the new one. Not an issue for me, just noting it.

There is a merge conflict.

@jpelgrom
Copy link
Member

jpelgrom commented Jun 23, 2025

LeakCanary is also giving me this, which I think is new from this PRs code but it's very generic.

Trace
┬───
│ GC Root: System class
│
├─ android.app.ActivityThread class
│    Leaking: NO (MessageQueue↓ is not leaking and a class is never leaking)
│    ↓ static ActivityThread.sMainThreadHandler
├─ android.app.ActivityThread$H instance
│    Leaking: NO (MessageQueue↓ is not leaking)
│    ↓ Handler.mQueue
├─ android.os.MessageQueue instance
│    Leaking: NO (MessageQueue#mQuitting is false)
│    HandlerThread: "main"
│    ↓ MessageQueue[0]
│                  ~~~
├─ android.os.Message instance
│    Leaking: UNKNOWN
│    Retaining 142.3 kB in 2647 objects
│    Message.what = 0
│    Message.when = 721496308 (2833 ms after heap dump)
│    Message.obj = null
│    Message.callback = instance @43424624 of io.homeassistant.companion.
│    android.webview.WebViewActivity$$ExternalSyntheticLambda23
│    Message.target = instance @43424592 of android.os.Handler
│    ↓ Message.callback
│              ~~~~~~~~
├─ io.homeassistant.companion.android.webview.
│  WebViewActivity$$ExternalSyntheticLambda23 instance
│    Leaking: UNKNOWN
│    Retaining 142.1 kB in 2644 objects
│    f$0 instance of io.homeassistant.companion.android.webview.WebViewActivity
│    with mDestroyed = true
│    ↓ WebViewActivity$$ExternalSyntheticLambda23.f$0
│                                                 ~~~
╰→ io.homeassistant.companion.android.webview.WebViewActivity instance
     Leaking: YES (ObjectWatcher was watching this because io.homeassistant.
     companion.android.webview.WebViewActivity received Activity#onDestroy()
     callback and Activity#mDestroyed is true)
     Retaining 142.1 kB in 2643 objects
     key = 2eca4818-ef44-4201-9e67-c0380b12160c
     watchDurationMillis = 5560
     retainedDurationMillis = 560
     mApplication instance of io.homeassistant.companion.android.
     HomeAssistantApplication
     mBase instance of androidx.appcompat.view.ContextThemeWrapper

METADATA

Build.VERSION.SDK_INT: 36
Build.MANUFACTURER: Google
LeakCanary version: 2.14
App process name: io.homeassistant.companion.android.debug
Class count: 44716
Instance count: 339697
Primitive array count: 228139
Object array count: 44842
Thread count: 80
Heap total bytes: 42273605
Bitmap count: 4
Bitmap total bytes: 37736
Large bitmap count: 0
Large bitmap total bytes: 0
Db 1: open /data/user/0/io.homeassistant.companion.android.
debug/no_backup/androidx.work.workdb
Db 2: open /data/user/0/io.homeassistant.companion.android.
debug/databases/HomeAssistantDB
Count of retained yet cleared: 11 KeyedWeakReference instances
Stats: LruCache[maxSize=3000,hits=137992,misses=273359,hitRate=33%]
RandomAccess[bytes=13290145,reads=273359,travel=135426990947,range=51035106,size
=63948790]
Analysis duration: 190581 ms

@TimoPtr
Copy link
Collaborator Author

TimoPtr commented Jun 24, 2025

I will use thin bluring instead of regular. If a user complain we could use ultraThin.

@TimoPtr TimoPtr requested a review from jpelgrom June 24, 2025 08:27
Copy link
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

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

Blur change hasn't made a noticeable difference, but it's OK.

@TimoPtr TimoPtr merged commit fa10e20 into main Jun 24, 2025
19 checks passed
@TimoPtr TimoPtr deleted the feature/compose-webview branch June 24, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants