Task: compose migration import export activity#3021
Task: compose migration import export activity#3021amlwin wants to merge 6 commits intoCatimaLoyalty:mainfrom
Conversation
This commit refactors the `ImportExportActivity` from an XML-based layout to a modern UI using Jetpack Compose. The core logic is preserved, but the implementation is now more streamlined and uses declarative UI principles. Key changes include: * Replacing the `import_export_activity.xml` layout with a new `ImportExportScreen.kt` Composable. * Updating `ImportExportActivity` to use `setContent` and manage UI state with Compose `MutableState`. * Replacing traditional dialogs (`MaterialAlertDialogBuilder`) with Composable dialogs for a consistent UI. * Adding new Compose testing dependencies and updating `ImportExportActivityTest` to use `createComposeRule` for testing the new Composable UI.
The `onImportComplete` function was simplified by removing the `path: Uri` parameter, which was no longer used. Call sites in `openFileForImport` and `initiateImport` were updated accordingly to reflect this change. The unused `dataFormat` parameter was also removed from the `onImportWithPassword` lambda.
Moved `ImportExportActivityTest.kt` from the `test` source set to the `androidTest` source set. This change also adds the Robolectric dependency to the `androidTest` configuration in `app/build.gradle.kts` to support the test's execution environment.
|
Thanks, I'll try to review this later but I may not have time the coming week or two. For the failing tests, I guess the compose stuff is bloating the APK a bit (though not sure how much). Are you sure is really needed? If yes (or just really helpful), maybe you can try bumping disk-size for the Instrumented Tests steps in I can't find a default size in the code, but it looks like it may be 800MB, so 1GB might already be sufficient. |
it's required to render preview in preview pane for android studio.
will update in next commit |
Adds `disk-size: 1G` to the Android emulator setup for instrumented tests on API levels 23 and 35. This increases the available disk space for the emulators running in the CI workflow.
|
Not sure why the tests still fail, I ran it from the main branch to make sure the tests weren't just broken by something else but they work fine there :/ |
Moved `ImportExportActivityTest` from the `androidTest` directory to the `test` directory, converting it from an instrumented test to a local unit test. This change allows the test to run on the local JVM using Robolectric instead of requiring an Android emulator or device. To support this move, the Robolectric dependency was removed from `androidTestImplementation` as it is already included for unit tests. Additionally, a `ComponentActivity` declaration was added to `AndroidManifest.xml`, which is required for running Compose UI tests with Robolectric. The GitHub Actions workflow was also updated to remove the unnecessary `disk-size` parameter for the emulator runner.
Merge ComponentActivity manifest entries To resolve a manifest merger failed error during UI tests, this change adds `tools:replace="android:exported"` to the `androidx.activity.ComponentActivity` declaration in `AndroidManifest.xml`. This ensures that the `android:exported` attribute from the library's manifest is overridden, allowing the build to succeed.
|
Fixied
|
TheLastProject
left a comment
There was a problem hiding this comment.
Got a few comments from the first review. Didn't look super close yet. But it does seem to work "equally well" under testing (which sadly also means: everything is still cancelled when rotating the screen, but I guess it makes sense to fix that separately anyway).
I'll try to take a very close look after these initial issues are resolved, but it is looking good :)
| val importTypesArray = resources.getStringArray(R.array.import_types_array) | ||
| return listOf( | ||
| ImportOption( | ||
| title = importTypesArray.getOrElse(0) { getString(R.string.importCatima) }, |
There was a problem hiding this comment.
Can you explain this getOrElse behaviour and why you introduced this? What is this supposed to solve? The old version is way simpler and just uses the intended string directly.
| dataFormat = DataFormat.Catima | ||
| ), | ||
| ImportOption( | ||
| title = importTypesArray.getOrElse(1) { "Fidme" }, |
There was a problem hiding this comment.
This should keep using the R.string.importFidme value
| IconButton(onClick = { passwordVisible = !passwordVisible }) { | ||
| Icon( | ||
| imageVector = if (passwordVisible) Icons.Filled.VisibilityOff else Icons.Filled.Visibility, | ||
| contentDescription = if (passwordVisible) "Hide password" else "Show password" |
There was a problem hiding this comment.
These need to be translatable so non-English app users can understand it too.
There was a problem hiding this comment.
This file lacks a lot of DRY, having basically one-on-one duplicated ImportX and ExportX composables for a lot of situations. I'd rather see a single composable with an extra flag for the small part that is unique.
| title = "Catima", | ||
| message = "Import from Catima backup", |
There was a problem hiding this comment.
Any reasons these use plain strings instead of R.string references? I guess to make the preview simpler?
Summary
Changes
ImportExportActivity.kt
CatimaAppCompatActivitytoCatimaComponentActivitysetContentusingCatimaThememutableStateOfImportExportScreen.kt (new)
CatimaTopAppBarand Material3 componentsImportOptiondata class andImportExportDialogStatesealed class for state management@Previewcomposables for Android Studio previewsImportExportActivityTest.kt
createComposeRule,onNodeWithText, etc.)Build Configuration
androidx-compose-ui-ui-toolingdependency for Compose previewsrobolectric.propertieswithgraphics.mode=NATIVEfor Compose renderingRemoved
import_export_activity.xml- no longer needed with ComposeTest plan
./gradlew :app:testFossDebugUnitTest --tests "protect.card_locker.ImportExportActivityTest"