bitfireAT/cert4android

Migrate to Jetpack Compose

Closed this issue · 8 comments

There's currently just TrustCertificateActivity in cert4android, so we can migrate it to Jetpack Compose, and see how it goes, before migrating icsx5 and the bigger projects.

Steps:

  • Disable dataBinding and enable compose
  • Configure Jetpack Compose
    • Configure app's build.gradle
    • Add dependencies
  • Add Accompanist Theme Adapter for testing automatic theme migration.
  • Migrate all the UI inside TrustCertificateActivity
  • Remove activity_trust_certificate from layouts.
  • Remove all the XML libraries from build.gradle

Add Accompanist Theme Adapter for testing automatic theme migration.

Do we have to add that here or in the apps that embeds cert4android?

Do we have to add that here or in the apps that embeds cert4android?

That just converts the XML theme to Jetpack Compose, so it's only required here. In fact, we should probably simply create a custom Compose theme for cert4android using the Theme Builder.

However, if some application is currently overriding the XML theme for some reason, which I don't know, we should stick with the XML theme, and use Accompanist Theme Adapter.

The thing is that Jetpack Compose uses a completely different theming approach than the XML design. The designing way is to build a kind of tree of modules inside modules. So for example, you create the main app theme, and call it AppTheme, the syntax would be:

AppTheme {
  // Everything that is inside of here will be themed with AppTheme
}
// Everything here won't be themed

So what Accompanist's Theme Adapter does is to create a theme called MdcTheme, which is made from the styles stored in the XML styles, and linked though the manifest.

I'm afraid that I still don't understand it 😢

In fact, we should probably simply create a custom Compose theme for cert4android using the Theme Builder.

Will it then use the colors of the embedding application?

Currently cert4android uses the DAVx5 colors for DAVx5 and ICSx5 colors for ICSx5.

If we create the custom theme no, that's why I suggested using Theme Adapter. Using this library "third-party" applications such as ICSx⁵ or DAVx⁵ can modify the colors.

Ok, then the theme-adapter would take the XML values from the application, right?

But what's the Compose-native way? If ICSx⁵ was completely Compose (without XML) and cert4android was completely Compose, how could cert4android be themed like ICSx5?

Ok, then the theme-adapter would take the XML values from the application, right?

Correct

But what's the Compose-native way?

Nope

If ICSx⁵ was completely Compose (without XML) and cert4android was completely Compose, how could cert4android be themed like ICSx5?

That's actually a good question, I'll take a look at it and see what's the "official" approach

Okay, so after thinking and searching about this for a bit. I think the best option would be to pass the color as an extra to the Activity. So have a default/fallback color for the theme, and if when launching the activity and extra with the color is passed, override the default one.

This means that, in fact, Accompanist Theme Adapter is not necessary.

Here's an screenshot of the current design:
Screenshot_20230417_194632

The theme in this case is provided by the system, for Android S+.