aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt (renamed from app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt)30
-rw-r--r--app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt47
-rw-r--r--app/src/main/res/layout/configure_activity.xml14
-rw-r--r--app/src/main/res/layout/configure_browse_directories_fragment.xml (renamed from app/src/main/res/layout/configure_tools_path_info_fragment.xml)44
-rw-r--r--app/src/main/res/values/strings.xml8
5 files changed, 93 insertions, 50 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt
index 1c436a3..abc7ffc 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/BrowseDirectoriesFragment.kt
@@ -1,6 +1,6 @@
1/* 1/*
2 * Tinc Mesh VPN: Android client and user interface 2 * Tinc Mesh VPN: Android client and user interface
3 * Copyright (C) 2017-2018 Euxane P. TRAN-GIRARD 3 * Copyright (C) 2017-2024 Euxane P. TRAN-GIRARD
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -22,19 +22,31 @@ import android.os.Bundle
22import android.view.LayoutInflater 22import android.view.LayoutInflater
23import android.view.View 23import android.view.View
24import android.view.ViewGroup 24import android.view.ViewGroup
25import org.pacien.tincapp.R
25import org.pacien.tincapp.activities.BaseFragment 26import org.pacien.tincapp.activities.BaseFragment
26import org.pacien.tincapp.context.AppPaths 27import org.pacien.tincapp.databinding.ConfigureBrowseDirectoriesFragmentBinding
27import org.pacien.tincapp.databinding.ConfigureToolsPathInfoFragmentBinding 28import org.pacien.tincapp.storageprovider.BrowseFilesIntents
28 29
29/** 30/**
30 * @author euxane 31 * @author euxane
31 */ 32 */
32class PathInfoFragment : BaseFragment() { 33class BrowseDirectoriesFragment : BaseFragment() {
33 private val appPaths = AppPaths
34
35 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { 34 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
36 val binding = ConfigureToolsPathInfoFragmentBinding.inflate(inflater, container, false) 35 val binding = ConfigureBrowseDirectoriesFragmentBinding.inflate(inflater, container, false)
37 binding.appPaths = appPaths 36 binding.openDirectoryTree = { openDocumentTree(it) }
38 return binding.root 37 return binding.root
39 } 38 }
40} 39
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
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 @@
1/*
2 * Tinc Mesh VPN: Android client and user interface
3 * Copyright (C) 2017-2024 Euxane P. TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.storageprovider
20
21import android.content.Context
22import android.content.Intent
23import android.net.Uri
24import android.provider.DocumentsContract
25import android.provider.DocumentsContract.Document
26import org.pacien.tincapp.BuildConfig
27
28object BrowseFilesIntents {
29 private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files"
30
31 fun openDocumentTree(context: Context, documentId: String) {
32 val contentUri = DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId)
33 openDocumentTree(context, contentUri)
34 }
35
36 fun openDocumentTree(context: Context, contentUri: Uri) {
37 val intent = Intent(Intent.ACTION_VIEW).apply {
38 setDataAndType(contentUri, Document.MIME_TYPE_DIR)
39 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
40 }
41
42 if (intent.resolveActivity(context.packageManager) == null)
43 throw RuntimeException("No opener found for " + Document.MIME_TYPE_DIR)
44
45 context.startActivity(intent)
46 }
47} \ No newline at end of file
diff --git a/app/src/main/res/layout/configure_activity.xml b/app/src/main/res/layout/configure_activity.xml
index dfb47c2..67a35d2 100644
--- a/app/src/main/res/layout/configure_activity.xml
+++ b/app/src/main/res/layout/configure_activity.xml
@@ -28,23 +28,23 @@
28 android:layout_height="wrap_content" 28 android:layout_height="wrap_content"
29 android:orientation="vertical"> 29 android:orientation="vertical">
30 30
31 <TextView 31 <TextView
32 style="@style/AppTheme.SectionTitle" 32 style="@style/AppTheme.SectionTitle"
33 android:text="@string/configure_activity_title_tools"/> 33 android:text="@string/configure_activity_title_directories"/>
34 34
35 <fragment 35 <fragment
36 android:id="@+id/configure_activity_tools_fragment" 36 android:id="@+id/configure_activity_path_info_fragment"
37 android:name="org.pacien.tincapp.activities.configure.ToolsFragment" 37 android:name="org.pacien.tincapp.activities.configure.BrowseDirectoriesFragment"
38 android:layout_width="match_parent" 38 android:layout_width="match_parent"
39 android:layout_height="wrap_content"/> 39 android:layout_height="wrap_content"/>
40 40
41 <TextView 41 <TextView
42 style="@style/AppTheme.SectionTitle" 42 style="@style/AppTheme.SectionTitle"
43 android:text="@string/configure_activity_title_internal_paths_info"/> 43 android:text="@string/configure_activity_title_tools"/>
44 44
45 <fragment 45 <fragment
46 android:id="@+id/configure_activity_path_info_fragment" 46 android:id="@+id/configure_activity_tools_fragment"
47 android:name="org.pacien.tincapp.activities.configure.PathInfoFragment" 47 android:name="org.pacien.tincapp.activities.configure.ToolsFragment"
48 android:layout_width="match_parent" 48 android:layout_width="match_parent"
49 android:layout_height="wrap_content"/> 49 android:layout_height="wrap_content"/>
50 50
diff --git a/app/src/main/res/layout/configure_tools_path_info_fragment.xml b/app/src/main/res/layout/configure_browse_directories_fragment.xml
index 5704a0f..e0fc64a 100644
--- a/app/src/main/res/layout/configure_tools_path_info_fragment.xml
+++ b/app/src/main/res/layout/configure_browse_directories_fragment.xml
@@ -2,7 +2,7 @@
2 2
3<!-- 3<!--
4 * Tinc Mesh VPN: Android client and user interface 4 * Tinc Mesh VPN: Android client and user interface
5 * Copyright (C) 2017-2018 Euxane P. TRAN-GIRARD 5 * Copyright (C) 2017-2024 Euxane P. TRAN-GIRARD
6 * 6 *
7 * This program is free software: you can redistribute it and/or modify 7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -22,50 +22,34 @@
22 22
23 <data> 23 <data>
24 24
25 <import
26 type="org.pacien.tincapp.storageprovider.FilesDocumentsProvider"/>
27
25 <variable 28 <variable
26 name="appPaths" 29 name="openDirectoryTree"
27 type="org.pacien.tincapp.context.AppPaths"/> 30 type="kotlin.jvm.functions.Function1&lt;String, kotlin.Unit>"/>
28 31
29 </data> 32 </data>
30 33
31 <LinearLayout style="@style/AppTheme.List"> 34 <LinearLayout style="@style/AppTheme.List">
32 35
33 <LinearLayout style="@style/AppTheme.ListBlock"> 36 <LinearLayout
37 style="@style/AppTheme.ListBlock.Clickable"
38 android:onClick="@{() -> openDirectoryTree.invoke(FilesDocumentsProvider.VIRTUAL_ROOT_NETWORKS)}">
34 39
35 <TextView 40 <TextView
36 style="@style/AppTheme.BlockTitle" 41 style="@style/AppTheme.BlockTitle"
37 android:text="@string/configure_path_info_title_configuration_directory"/> 42 android:text="@string/configure_browse_directories_action_open_networks_config" />
38