Skip to content

Task: compose migration import export activity#3021

Open
amlwin wants to merge 6 commits intoCatimaLoyalty:mainfrom
amlwin:task/compose-migration-ImportExportActivity
Open

Task: compose migration import export activity#3021
amlwin wants to merge 6 commits intoCatimaLoyalty:mainfrom
amlwin:task/compose-migration-ImportExportActivity

Conversation

@amlwin
Copy link
Contributor

@amlwin amlwin commented Feb 12, 2026

Summary

  • Migrate ImportExportActivity from XML Views to Jetpack Compose
  • Add Compose UI testing support for unit tests
  • Remove deprecated XML layout file

Changes

ImportExportActivity.kt

  • Changed base class from CatimaAppCompatActivity to CatimaComponentActivity
  • Replaced XML view binding with Compose setContent using CatimaTheme
  • Added reactive dialog state management using mutableStateOf
  • Kept ActivityResultLaunchers in Activity (required for lifecycle)

ImportExportScreen.kt (new)

  • Created full Compose UI with CatimaTopAppBar and Material3 components
  • Added ImportOption data class and ImportExportDialogState sealed class for state management
  • Implemented Compose dialogs:
    • Export password dialog
    • Import type selection dialog
    • Import confirmation dialog
    • Import password retry dialog
    • Import/Export result dialogs
  • Added @Preview composables for Android Studio previews

ImportExportActivityTest.kt

  • Updated tests to use Compose testing APIs (createComposeRule, onNodeWithText, etc.)
  • Added tests for main screen, import type dialog, and export password dialog

Build Configuration

  • Added androidx-compose-ui-ui-tooling dependency for Compose previews
  • Added Compose testing dependencies for unit tests
  • Created robolectric.properties with graphics.mode=NATIVE for Compose rendering

Removed

  • import_export_activity.xml - no longer needed with Compose

Test plan

  • Verify export flow works (password dialog → file picker → export → result dialog → share option)
  • Verify import flow works (type selection → confirmation → file picker → import → result dialog)
  • Verify password retry works for encrypted imports
  • Verify back button navigation works
  • Verify screen renders correctly in light/dark themes
  • Run unit tests: ./gradlew :app:testFossDebugUnitTest --tests "protect.card_locker.ImportExportActivityTest"
Activity Activity with Export Dialog Activity with Import Dialog
image image image

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.
@amlwin amlwin mentioned this pull request Feb 12, 2026
27 tasks
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.
@TheLastProject
Copy link
Member

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

    debugImplementation(libs.androidx.compose.ui.ui.tooling)

is really needed?

If yes (or just really helpful), maybe you can try bumping disk-size for the Instrumented Tests steps in .github/workflows/android.yml.

I can't find a default size in the code, but it looks like it may be 800MB, so 1GB might already be sufficient.

@amlwin
Copy link
Contributor Author

amlwin commented Feb 12, 2026

debugImplementation(libs.androidx.compose.ui.ui.tooling)

it's required to render preview in preview pane for android studio.

maybe you can try bumping disk-size for the Instrumented Tests steps in .github/workflows/android.yml.

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.
@TheLastProject
Copy link
Member

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.
@amlwin
Copy link
Contributor Author

amlwin commented Feb 13, 2026

Fixied

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 :/

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.

2 participants

Comments