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 @@ +