From e1cc8676cf1d4cece7a9740ec0b80dce31670069 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Mon, 30 May 2022 17:45:24 +0530 Subject: [PATCH] Add option to view internal directory With the Skyline document provider, easy access to the internal directory is required which may be hard to navigate to through the system file manager. This adds an option in settings to directly open up the directory in the system file manager. --- .../preference/DocumentsProviderPreference.kt | 39 +++++++++++++++++++ app/src/main/res/values/strings.xml | 7 +++- app/src/main/res/xml/preferences.xml | 4 ++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/emu/skyline/preference/DocumentsProviderPreference.kt diff --git a/app/src/main/java/emu/skyline/preference/DocumentsProviderPreference.kt b/app/src/main/java/emu/skyline/preference/DocumentsProviderPreference.kt new file mode 100644 index 00000000..5c68f68d --- /dev/null +++ b/app/src/main/java/emu/skyline/preference/DocumentsProviderPreference.kt @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: MPL-2.0 + * Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + */ + +package emu.skyline.preference + +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent +import android.provider.DocumentsContract +import android.util.AttributeSet +import androidx.preference.Preference +import androidx.preference.R +import com.google.android.material.snackbar.Snackbar +import emu.skyline.SettingsActivity +import emu.skyline.provider.DocumentsProvider + + +class DocumentsProviderPreference @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = R.attr.preferenceStyle) : Preference(context, attrs, defStyleAttr) { + fun launchOpenIntent(action : String) : Boolean { + return try { + val intent = Intent(action) + intent.addCategory(Intent.CATEGORY_DEFAULT) + intent.data = DocumentsContract.buildRootUri(DocumentsProvider.AUTHORITY, DocumentsProvider.ROOT_ID) + intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION or Intent.FLAG_GRANT_PREFIX_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) + context.startActivity(intent) + true + } catch (e: ActivityNotFoundException) { + false + } + } + + override fun onClick() { + if (launchOpenIntent(Intent.ACTION_VIEW) or launchOpenIntent("android.provider.action.BROWSE")) + return + Snackbar.make((context as SettingsActivity).binding.root, emu.skyline.R.string.failed_open_directory, Snackbar.LENGTH_SHORT).show() + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1fb6ada8..10de02ce 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,6 +24,9 @@ Emulator Search Location + View Internal Directory + Opens Skyline\'s internal directory in a file manager + Cannot find an external file manager to open Skyline\'s internal directory Theme Game Display Layout Always Show Game Information @@ -73,6 +76,8 @@ On-Screen Controls won\'t be shown On-Screen Controls will be shown Edit On-Screen Controls layout + Setup Guide + Sequentially map every stick and button Joystick Confirm Cancel @@ -164,6 +169,4 @@ Expand - Setup Guide - Sequentially map every stick and button diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 5d75c1c9..9134e5a6 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -6,6 +6,10 @@ +