diff options
author | euxane | 2024-09-18 23:41:13 +0200 |
---|---|---|
committer | euxane | 2024-09-18 23:41:13 +0200 |
commit | 58f563a79867ae5973d5d45dba265f1b293bb0c3 (patch) | |
tree | 5cdcd35c9f730b012b866a2d09ffef47ce1e4cd8 /app/src/main/java/org | |
parent | 86941d837d0fd4368b8a1daabece300a3ec1e0e2 (diff) | |
download | tincapp-58f563a79867ae5973d5d45dba265f1b293bb0c3.tar.gz |
activities/configure: replace config and log paths with browse links
Diffstat (limited to 'app/src/main/java/org')
-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.kt | 47 |
2 files changed, 68 insertions, 9 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 | |||
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 | ||
25 | import org.pacien.tincapp.activities.BaseFragment | 26 | import org.pacien.tincapp.activities.BaseFragment |
26 | import org.pacien.tincapp.context.AppPaths | 27 | import org.pacien.tincapp.databinding.ConfigureBrowseDirectoriesFragmentBinding |
27 | import org.pacien.tincapp.databinding.ConfigureToolsPathInfoFragmentBinding | 28 | import org.pacien.tincapp.storageprovider.BrowseFilesIntents |
28 | 29 | ||
29 | /** | 30 | /** |
30 | * @author euxane | 31 | * @author euxane |
31 | */ | 32 | */ |
32 | class PathInfoFragment : BaseFragment() { | 33 | class 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 | |||
19 | package org.pacien.tincapp.storageprovider | ||
20 | |||
21 | import android.content.Context | ||
22 | import android.content.Intent | ||
23 | import android.net.Uri | ||
24 | import android.provider.DocumentsContract | ||
25 | import android.provider.DocumentsContract.Document | ||
26 | import org.pacien.tincapp.BuildConfig | ||
27 | |||
28 | object 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 | ||