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 ++++++++++++++ app/src/main/res/layout/configure_activity.xml | 14 ++-- .../configure_browse_directories_fragment.xml | 58 +++++++++++++++++ .../layout/configure_tools_path_info_fragment.xml | 74 ---------------------- app/src/main/res/values/strings.xml | 8 +-- 7 files changed, 168 insertions(+), 125 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 create mode 100644 app/src/main/res/layout/configure_browse_directories_fragment.xml delete mode 100644 app/src/main/res/layout/configure_tools_path_info_fragment.xml (limited to 'app') 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 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 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + android:text="@string/configure_activity_title_directories"/> + android:text="@string/configure_activity_title_tools"/> diff --git a/app/src/main/res/layout/configure_browse_directories_fragment.xml b/app/src/main/res/layout/configure_browse_directories_fragment.xml new file mode 100644 index 0000000..e0fc64a --- /dev/null +++ b/app/src/main/res/layout/configure_browse_directories_fragment.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/configure_tools_path_info_fragment.xml b/app/src/main/res/layout/configure_tools_path_info_fragment.xml deleted file mode 100644 index 5704a0f..0000000 --- a/app/src/main/res/layout/configure_tools_path_info_fragment.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 72adb1d..8ded24f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,10 +85,10 @@ Invalid network name. Network configuration written. - Internal paths info - Configuration directory - Log directory - tinc binary + Directories + Open networks configuration directory + Open logs directory + No file browser found to open target. Tools Generate node configuration and keys -- cgit v1.2.3