From 617acb7b7d068d0b18613d93e9f53df0f1633851 Mon Sep 17 00:00:00 2001 From: euxane Date: Wed, 18 Sep 2024 23:41:13 +0200 Subject: fragments: share openDocumentTree function --- .../java/org/pacien/tincapp/activities/BaseFragment.kt | 16 ++++++++++++++++ .../activities/configure/BrowseDirectoriesFragment.kt | 17 +---------------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'app/src/main/java/org/pacien') diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt index 45c6832..d37abdf 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt @@ -18,11 +18,27 @@ package org.pacien.tincapp.activities +import android.content.ActivityNotFoundException import androidx.fragment.app.Fragment +import org.pacien.tincapp.R +import org.pacien.tincapp.storageprovider.BrowseFilesIntents /** * @author euxane */ abstract class BaseFragment : Fragment() { protected val parentActivity by lazy { activity as BaseActivity } + + fun openDocumentTree(documentId: String) { + try { + BrowseFilesIntents.openDocumentTree(requireContext(), documentId) + } catch (e: ActivityNotFoundException) { + parentActivity.runOnUiThread { + parentActivity.showErrorDialog( + R.string.configure_browse_directories_error_no_file_browser, + docTopic = "browse-files", + ) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt index abc7ffc..7d37f78 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt @@ -22,10 +22,8 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseFragment import org.pacien.tincapp.databinding.ConfigureBrowseDirectoriesFragmentBinding -import org.pacien.tincapp.storageprovider.BrowseFilesIntents /** * @author euxane @@ -36,17 +34,4 @@ class BrowseDirectoriesFragment : BaseFragment() { binding.openDirectoryTree = { openDocumentTree(it) } return binding.root } - - private fun openDocumentTree(documentId: String) { - try { - BrowseFilesIntents.openDocumentTree(requireContext(), documentId) - } catch (e: RuntimeException) { - parentActivity.runOnUiThread { - parentActivity.showErrorDialog( - R.string.configure_browse_directories_error_no_file_browser, - docTopic = "browse-files", - ) - } - } - } -} \ No newline at end of file +} -- cgit v1.2.3