diff options
author | euxane | 2024-09-18 23:41:13 +0200 |
---|---|---|
committer | euxane | 2024-09-18 23:41:13 +0200 |
commit | 617acb7b7d068d0b18613d93e9f53df0f1633851 (patch) | |
tree | df37c7e704e4b655a752b0757671df79aee5f73e /app/src | |
parent | 4fab4e5972f4ca05d5b5f03112727ed4ac9c2909 (diff) | |
download | tincapp-617acb7b7d068d0b18613d93e9f53df0f1633851.tar.gz |
fragments: share openDocumentTree function
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt | 16 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt | 17 |
2 files changed, 17 insertions, 16 deletions
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 @@ | |||
18 | 18 | ||
19 | package org.pacien.tincapp.activities | 19 | package org.pacien.tincapp.activities |
20 | 20 | ||
21 | import android.content.ActivityNotFoundException | ||
21 | import androidx.fragment.app.Fragment | 22 | import androidx.fragment.app.Fragment |
23 | import org.pacien.tincapp.R | ||
24 | import org.pacien.tincapp.storageprovider.BrowseFilesIntents | ||
22 | 25 | ||
23 | /** | 26 | /** |
24 | * @author euxane | 27 | * @author euxane |
25 | */ | 28 | */ |
26 | abstract class BaseFragment : Fragment() { | 29 | abstract class BaseFragment : Fragment() { |
27 | protected val parentActivity by lazy { activity as BaseActivity } | 30 | protected val parentActivity by lazy { activity as BaseActivity } |
31 | |||
32 | fun openDocumentTree(documentId: String) { | ||
33 | try { | ||
34 | BrowseFilesIntents.openDocumentTree(requireContext(), documentId) | ||
35 | } catch (e: ActivityNotFoundException) { | ||
36 | parentActivity.runOnUiThread { | ||
37 | parentActivity.showErrorDialog( | ||
38 | R.string.configure_browse_directories_error_no_file_browser, | ||
39 | docTopic = "browse-files", | ||
40 | ) | ||
41 | } | ||
42 | } | ||
43 | } | ||
28 | } \ No newline at end of file | 44 | } \ 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 | |||
22 | import android.view.LayoutInflater | 22 | import android.view.LayoutInflater |
23 | import android.view.View | 23 | import android.view.View |
24 | import android.view.ViewGroup | 24 | import android.view.ViewGroup |
25 | import org.pacien.tincapp.R | ||
26 | import org.pacien.tincapp.activities.BaseFragment | 25 | import org.pacien.tincapp.activities.BaseFragment |
27 | import org.pacien.tincapp.databinding.ConfigureBrowseDirectoriesFragmentBinding | 26 | import org.pacien.tincapp.databinding.ConfigureBrowseDirectoriesFragmentBinding |
28 | import org.pacien.tincapp.storageprovider.BrowseFilesIntents | ||
29 | 27 | ||
30 | /** | 28 | /** |
31 | * @author euxane | 29 | * @author euxane |
@@ -36,17 +34,4 @@ class BrowseDirectoriesFragment : BaseFragment() { | |||
36 | binding.openDirectoryTree = { openDocumentTree(it) } | 34 | binding.openDirectoryTree = { openDocumentTree(it) } |
37 | return binding.root | 35 | return binding.root |
38 | } | 36 | } |
39 | 37 | } | |
40 | private fun openDocumentTree(documentId: String) { | ||
41 | try { | ||
42 | BrowseFilesIntents.openDocumentTree(requireContext(), documentId) | ||
43 | } catch (e: RuntimeException) { | ||
44 | parentActivity.runOnUiThread { | ||
45 | parentActivity.showErrorDialog( | ||
46 | R.string.configure_browse_directories_error_no_file_browser, | ||
47 | docTopic = "browse-files", | ||
48 | ) | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } \ No newline at end of file | ||