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

Handle unsupported files when importing .mbtiles #6230

Merged
merged 3 commits into from
Jun 27, 2024

Conversation

grzesiek2010
Copy link
Member

@grzesiek2010 grzesiek2010 commented Jun 26, 2024

Closes #6199

Why is this the best possible solution? Were any other approaches considered?

The way we should inform users about unsupported files they selected has been discussed in the issue. When it comes to the implementation there is nothing I would like to discuss here.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

According to the issue, a warning should be displayed if some/all the selected files are not supported.

Do we need any specific form for testing your changes? If so, please attach one.

No.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@grzesiek2010 grzesiek2010 changed the title https://github.com/getodk/collect/issues/6199 Handle unsupported files when importing .mbtiles Jun 26, 2024
@grzesiek2010 grzesiek2010 requested a review from seadowg June 26, 2024 10:13
@grzesiek2010 grzesiek2010 marked this pull request as ready for review June 26, 2024 10:13
@@ -74,10 +76,6 @@ class OfflineMapLayersPicker(
private val getLayers = registerForActivityResult(ActivityResultContracts.GetMultipleContents(), registry) { uris ->
if (uris.isNotEmpty()) {
sharedViewModel.loadLayersToImport(uris, requireContext())
DialogFragmentUtils.showIfNotShowing(
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this would all be a bit more contained, if OfflineMapLayersImporter handles the warning cases? layersToImport could still be a Consumable, but it wouldn't care about if it had consumed or not for setting the adapter. In that world, there's no changes in OfflineMapLayersPicker and in OfflineMapLayersImporter we just get something like:

viewModel.layersToImport.observe(this) { layersToImport ->
    val adapter = OfflineMapLayersImporterAdapter(layersToImport.value.layers)
    binding.layers.setAdapter(adapter)

    if (layersToImport.isConsumed()) {
        // Show warning dialog if it make sense

        layersToImport.consume()
    }
}

For me that keeps the navigation simpler. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

But OfflineMapLayersImporter should not be displayed at all if all the selected files are not supported right?

Copy link
Member

Choose a reason for hiding this comment

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

True! In the case where we don't want to offer import (there's no supported layers), we can just dismiss the imported. So to expand my previous example:

viewModel.layersToImport.observe(this) { layersToImport ->
    val adapter = OfflineMapLayersImporterAdapter(layersToImport.value.layers)
    binding.layers.setAdapter(adapter)

    if (layersToImport.isConsumed()) {
        if (layersToImport.value.numberOfUnsupportedLayers == layersToImport.value.numberOfSelectedLayers) {
            dismiss()
            showNoSupportedLayersWarning()
        } else if (layersToImport.value.numberOfUnsupportedLayers > 0) {
            showSomeUnsuppotedLayersWarning()
        }

        layersToImport.consume()
    }
}

That prevents us from having to deal with multiple dialogs opening in the picker (maybe that's OK, but it feels off to me) and I still prefer that handling the layers to import all happens on the importer side.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok done.

@grzesiek2010 grzesiek2010 requested a review from seadowg June 26, 2024 11:19
Copy link
Member

@seadowg seadowg left a comment

Choose a reason for hiding this comment

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


val context = ApplicationProvider.getApplicationContext<Application>()
onView(withText(context.getLocalizedQuantityString(R.plurals.non_mbtiles_files_selected_title, 1, 1))).inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(R.string.all_non_mbtiles_files_selected_message)).inRoot(isDialog()).check(matches(isDisplayed()))
Copy link
Member

Choose a reason for hiding this comment

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

It'd be cleaner for these tests to use the helpers available in Assertions/Interactions, but I'm pretty sure that's something you were going to deal with in #6201 anyway.

@seadowg
Copy link
Member

seadowg commented Jun 27, 2024

@getodk/testers the warning messages shown here will not be maintained when rotating the device - that's OK and not something we'd look to change right now.

@seadowg seadowg merged commit e444bc8 into getodk:master Jun 27, 2024
6 checks passed
@dbemke
Copy link

dbemke commented Jun 28, 2024

Tested with Success!

Verified on a device with Android 10

Verified Cases:

@srujner
Copy link

srujner commented Jun 28, 2024

Tested with Success!

Verified on a device with Android 13

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.

Handle unsupported files when importing .mbtiles
4 participants