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.
This commit is contained in:
PixelyIon 2022-05-30 17:45:24 +05:30
parent ba97985b55
commit e1cc8676cf
3 changed files with 48 additions and 2 deletions

View File

@ -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()
}
}

View File

@ -24,6 +24,9 @@
<!-- Settings - Emulator --> <!-- Settings - Emulator -->
<string name="emulator">Emulator</string> <string name="emulator">Emulator</string>
<string name="search_location">Search Location</string> <string name="search_location">Search Location</string>
<string name="open_data_directory">View Internal Directory</string>
<string name="open_data_directory_summary">Opens Skyline\'s internal directory in a file manager</string>
<string name="failed_open_directory">Cannot find an external file manager to open Skyline\'s internal directory</string>
<string name="theme">Theme</string> <string name="theme">Theme</string>
<string name="layout_type">Game Display Layout</string> <string name="layout_type">Game Display Layout</string>
<string name="select_action">Always Show Game Information</string> <string name="select_action">Always Show Game Information</string>
@ -73,6 +76,8 @@
<string name="osc_not_shown">On-Screen Controls won\'t be shown</string> <string name="osc_not_shown">On-Screen Controls won\'t be shown</string>
<string name="osc_shown">On-Screen Controls will be shown</string> <string name="osc_shown">On-Screen Controls will be shown</string>
<string name="osc_edit">Edit On-Screen Controls layout</string> <string name="osc_edit">Edit On-Screen Controls layout</string>
<string name="setup_guide">Setup Guide</string>
<string name="setup_guide_description">Sequentially map every stick and button</string>
<string name="joystick">Joystick</string> <string name="joystick">Joystick</string>
<string name="confirm">Confirm</string> <string name="confirm">Confirm</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
@ -164,6 +169,4 @@
<!-- Misc --> <!-- Misc -->
<!--suppress AndroidLintUnusedResources --> <!--suppress AndroidLintUnusedResources -->
<string name="expand_button_title" tools:override="true">Expand</string> <string name="expand_button_title" tools:override="true">Expand</string>
<string name="setup_guide">Setup Guide</string>
<string name="setup_guide_description">Sequentially map every stick and button</string>
</resources> </resources>

View File

@ -6,6 +6,10 @@
<emu.skyline.preference.FolderPickerPreference <emu.skyline.preference.FolderPickerPreference
app:key="search_location" app:key="search_location"
app:title="@string/search_location" /> app:title="@string/search_location" />
<emu.skyline.preference.DocumentsProviderPreference
app:key="document_provider"
app:title="@string/open_data_directory"
app:summary="@string/open_data_directory_summary"/>
<emu.skyline.preference.ThemePreference <emu.skyline.preference.ThemePreference
android:defaultValue="2" android:defaultValue="2"
android:entries="@array/app_theme" android:entries="@array/app_theme"