From d45e8b9a18c872c18cdf4e57ebce1df2536e18f6 Mon Sep 17 00:00:00 2001 From: darken Date: Tue, 6 Aug 2024 20:50:27 +0200 Subject: [PATCH] Analyzer: Better error handling if content can't opened --- .../analyzer/ui/storage/content/ContentFragment.kt | 10 ++++++++++ .../analyzer/ui/storage/content/ContentItemEvents.kt | 2 ++ .../analyzer/ui/storage/content/ContentViewModel.kt | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentFragment.kt b/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentFragment.kt index 73b5fdb62..d0e465833 100644 --- a/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentFragment.kt +++ b/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentFragment.kt @@ -1,5 +1,6 @@ package eu.darken.sdmse.analyzer.ui.storage.content +import android.content.ActivityNotFoundException import android.os.Bundle import android.text.format.Formatter import android.view.MenuItem @@ -16,6 +17,7 @@ import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint import eu.darken.sdmse.R import eu.darken.sdmse.common.debug.logging.logTag +import eu.darken.sdmse.common.error.asErrorDialogBuilder import eu.darken.sdmse.common.getQuantityString2 import eu.darken.sdmse.common.lists.differ.update import eu.darken.sdmse.common.lists.installListSelection @@ -140,6 +142,14 @@ class ContentFragment : Fragment3(R.layout.analyzer_content_fragment) { ), Snackbar.LENGTH_LONG ).show() + + is ContentItemEvents.OpenContent -> { + try { + startActivity(event.intent) + } catch (e: ActivityNotFoundException) { + e.asErrorDialogBuilder(requireActivity()).show() + } + } } } diff --git a/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentItemEvents.kt b/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentItemEvents.kt index 017c4b12e..1b038347d 100644 --- a/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentItemEvents.kt +++ b/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentItemEvents.kt @@ -1,9 +1,11 @@ package eu.darken.sdmse.analyzer.ui.storage.content +import android.content.Intent import eu.darken.sdmse.analyzer.core.content.ContentItem sealed class ContentItemEvents { data class ShowNoAccessHint(val item: ContentItem) : ContentItemEvents() data class ExclusionsCreated(val count: Int) : ContentItemEvents() data class ContentDeleted(val count: Int, val freedSpace: Long) : ContentItemEvents() + data class OpenContent(val intent: Intent) : ContentItemEvents() } diff --git a/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentViewModel.kt b/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentViewModel.kt index e056cb49c..f584f8beb 100644 --- a/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentViewModel.kt +++ b/app/src/main/java/eu/darken/sdmse/analyzer/ui/storage/content/ContentViewModel.kt @@ -166,7 +166,7 @@ class ContentViewModel @Inject constructor( } log(TAG) { "open() launching chooser $chooserIntent" } - context.startActivity(chooserIntent) + events.postValue(ContentItemEvents.OpenContent(chooserIntent)) } fun delete(items: Set) = launch {