Added preference to acess all files permission

This commit is contained in:
Denis Çerri 2023-03-07 13:12:07 +01:00
parent 2669f2e44f
commit 224c22a5ff
No known key found for this signature in database
GPG key ID: 95C43D517D830350
5 changed files with 40 additions and 2 deletions

View file

@ -320,7 +320,7 @@
<PersistentState>
<option name="values">
<map>
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/select_all/baseline_select_all_24.xml" />
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/rule_folder/baseline_rule_folder_24.xml" />
</map>
</option>
</PersistentState>
@ -330,7 +330,7 @@
</option>
<option name="values">
<map>
<entry key="outputName" value="ic_select_all" />
<entry key="outputName" value="ic_access_folder" />
<entry key="sourceFile" value="C:\Users\denis\Desktop\adaptiveproduct_youtube_foreground_color_108 (1).svg" />
</map>
</option>

View file

@ -1,14 +1,20 @@
package com.deniscerri.ytdlnis.ui.more.settings
import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.core.os.LocaleListCompat
import androidx.preference.*
import com.deniscerri.ytdlnis.BuildConfig
@ -22,6 +28,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
private var musicPath: Preference? = null
private var videoPath: Preference? = null
private var commandPath: Preference? = null
private var accessAllFiles : Preference? = null
private var incognito: SwitchPreferenceCompat? = null
private var preferredDownloadType : ListPreference? = null
private var downloadCard: SwitchPreferenceCompat? = null
@ -64,6 +71,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
musicPath = findPreference("music_path")
videoPath = findPreference("video_path")
commandPath = findPreference("command_path")
accessAllFiles = findPreference("access_all_files")
incognito = findPreference("incognito")
preferredDownloadType = findPreference("preferred_download_type")
downloadCard = findPreference("download_card")
@ -112,6 +120,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
if (preferences.getString("command_path", "")!!.isEmpty()) {
editor.putString("command_path", getString(R.string.command_path))
}
if((Build.VERSION.SDK_INT >= 30 && Environment.isExternalStorageManager()) ||
Build.VERSION.SDK_INT < 30) {
accessAllFiles!!.isVisible = false
}
editor.putBoolean("incognito", incognito!!.isChecked)
editor.putString("preferred_download_type", preferredDownloadType!!.value)
editor.putBoolean("download_card", downloadCard!!.isChecked)
@ -182,6 +196,15 @@ class SettingsFragment : PreferenceFragmentCompat() {
commandPathResultLauncher.launch(intent)
true
}
accessAllFiles!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
val uri = Uri.parse("package:" + requireContext().packageName)
intent.data = uri
startActivity(intent)
true
}
incognito!!.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
val enable = newValue as Boolean

View file

@ -0,0 +1,5 @@
<vector android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="?android:colorAccent" android:pathData="M20,6h-8l-2,-2H4C2.9,4 2.01,4.9 2.01,6L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8C22,6.9 21.1,6 20,6zM7.83,16L5,13.17l1.41,-1.41l1.41,1.41l3.54,-3.54l1.41,1.41L7.83,16zM17.41,13L19,14.59L17.59,16L16,14.41L14.41,16L13,14.59L14.59,13L13,11.41L14.41,10L16,11.59L17.59,10L19,11.41L17.41,13z"/>
</vector>

View file

@ -206,4 +206,6 @@
<string name="select">Select</string>
<string name="selected">Selected</string>
<string name="all_items_selected">All items selected</string>
<string name="access_all_directories">Allow access to all directories</string>
<string name="access_all_directories_summary">Let the app download on directories that are restricted by default</string>
</resources>

View file

@ -10,6 +10,8 @@
app:title="@string/language" />
<PreferenceCategory android:title="@string/directories">
<Preference
app:icon="@drawable/ic_music_downloaded"
app:key="music_path"
@ -28,6 +30,12 @@
app:defaultValue="@string/command_path"
app:title="@string/command_directory" />
<Preference
app:icon="@drawable/ic_access_folder"
app:key="access_all_files"
android:summary="@string/access_all_directories_summary"
app:title="@string/access_all_directories" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/downloading">