From 58f563a79867ae5973d5d45dba265f1b293bb0c3 Mon Sep 17 00:00:00 2001
From: euxane
Date: Wed, 18 Sep 2024 23:41:13 +0200
Subject: activities/configure: replace config and log paths with browse links
---
.../configure/BrowseDirectoriesFragment.kt | 52 ++++++++++++++++++++++
.../activities/configure/PathInfoFragment.kt | 40 -----------------
.../tincapp/storageprovider/BrowseFilesIntents.kt | 47 +++++++++++++++++++
3 files changed, 99 insertions(+), 40 deletions(-)
create mode 100644 app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt
delete mode 100644 app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt
create mode 100644 app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt
(limited to 'app/src/main/java')
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
new file mode 100644
index 0000000..abc7ffc
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt
@@ -0,0 +1,52 @@
+/*
+ * Tinc Mesh VPN: Android client and user interface
+ * Copyright (C) 2017-2024 Euxane P. TRAN-GIRARD
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.pacien.tincapp.activities.configure
+
+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
+ */
+class BrowseDirectoriesFragment : BaseFragment() {
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
+ val binding = ConfigureBrowseDirectoriesFragmentBinding.inflate(inflater, container, false)
+ 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
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt
deleted file mode 100644
index 1c436a3..0000000
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Tinc Mesh VPN: Android client and user interface
- * Copyright (C) 2017-2018 Euxane P. TRAN-GIRARD
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package org.pacien.tincapp.activities.configure
-
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import org.pacien.tincapp.activities.BaseFragment
-import org.pacien.tincapp.context.AppPaths
-import org.pacien.tincapp.databinding.ConfigureToolsPathInfoFragmentBinding
-
-/**
- * @author euxane
- */
-class PathInfoFragment : BaseFragment() {
- private val appPaths = AppPaths
-
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
- val binding = ConfigureToolsPathInfoFragmentBinding.inflate(inflater, container, false)
- binding.appPaths = appPaths
- return binding.root
- }
-}
diff --git a/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt b/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt
new file mode 100644
index 0000000..3ebd501
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt
@@ -0,0 +1,47 @@
+/*
+ * Tinc Mesh VPN: Android client and user interface
+ * Copyright (C) 2017-2024 Euxane P. TRAN-GIRARD
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.pacien.tincapp.storageprovider
+
+import android.content.Context
+import android.content.Intent
+import android.net.Uri
+import android.provider.DocumentsContract
+import android.provider.DocumentsContract.Document
+import org.pacien.tincapp.BuildConfig
+
+object BrowseFilesIntents {
+ private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files"
+
+ fun openDocumentTree(context: Context, documentId: String) {
+ val contentUri = DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId)
+ openDocumentTree(context, contentUri)
+ }
+
+ fun openDocumentTree(context: Context, contentUri: Uri) {
+ val intent = Intent(Intent.ACTION_VIEW).apply {
+ setDataAndType(contentUri, Document.MIME_TYPE_DIR)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
+ }
+
+ if (intent.resolveActivity(context.packageManager) == null)
+ throw RuntimeException("No opener found for " + Document.MIME_TYPE_DIR)
+
+ context.startActivity(intent)
+ }
+}
\ No newline at end of file
--
cgit v1.2.3