pull/913/head
gedoor 4 years ago
parent c18b170351
commit 2dc6766f43
  1. 30
      app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt
  2. 18
      app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt
  3. 1
      avd.bat
  4. 1
      avd11.bat

@ -2,11 +2,9 @@ package io.legado.app.ui.filepicker
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Permissions
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
@Suppress("unused") @Suppress("unused")
@ -34,7 +32,6 @@ object FilePicker {
val intent = createSelectDirIntent() val intent = createSelectDirIntent()
activity.startActivityForResult(intent, requestCode) activity.startActivityForResult(intent, requestCode)
}.onFailure { }.onFailure {
checkPermissions(activity) {
FilePickerDialog.show( FilePickerDialog.show(
activity.supportFragmentManager, activity.supportFragmentManager,
requestCode, requestCode,
@ -42,17 +39,14 @@ object FilePicker {
) )
} }
} }
}
else -> { else -> {
val selectText = selectList[index] val selectText = selectList[index]
if (selectText == activity.getString(R.string.app_folder_picker)) { if (selectText == activity.getString(R.string.app_folder_picker)) {
checkPermissions(activity) {
FilePickerDialog.show( FilePickerDialog.show(
activity.supportFragmentManager, activity.supportFragmentManager,
requestCode, requestCode,
mode = FilePickerDialog.DIRECTORY mode = FilePickerDialog.DIRECTORY
) )
}
} else { } else {
otherFun?.invoke(selectText) otherFun?.invoke(selectText)
} }
@ -84,7 +78,6 @@ object FilePicker {
val intent = createSelectDirIntent() val intent = createSelectDirIntent()
fragment.startActivityForResult(intent, requestCode) fragment.startActivityForResult(intent, requestCode)
}.onFailure { }.onFailure {
checkPermissions(fragment) {
FilePickerDialog.show( FilePickerDialog.show(
fragment.childFragmentManager, fragment.childFragmentManager,
requestCode, requestCode,
@ -92,17 +85,14 @@ object FilePicker {
) )
} }
} }
}
else -> { else -> {
val selectText = selectList[index] val selectText = selectList[index]
if (selectText == fragment.getString(R.string.app_folder_picker)) { if (selectText == fragment.getString(R.string.app_folder_picker)) {
checkPermissions(fragment) {
FilePickerDialog.show( FilePickerDialog.show(
fragment.childFragmentManager, fragment.childFragmentManager,
requestCode, requestCode,
mode = FilePickerDialog.DIRECTORY mode = FilePickerDialog.DIRECTORY
) )
}
} else { } else {
otherFun?.invoke(selectText) otherFun?.invoke(selectText)
} }
@ -139,7 +129,6 @@ object FilePicker {
) )
activity.startActivityForResult(intent, requestCode) activity.startActivityForResult(intent, requestCode)
}.onFailure { }.onFailure {
checkPermissions(activity) {
FilePickerDialog.show( FilePickerDialog.show(
activity.supportFragmentManager, activity.supportFragmentManager,
requestCode, requestCode,
@ -148,18 +137,15 @@ object FilePicker {
) )
} }
} }
}
else -> { else -> {
val selectText = selectList[index] val selectText = selectList[index]
if (selectText == activity.getString(R.string.app_file_picker)) { if (selectText == activity.getString(R.string.app_file_picker)) {
checkPermissions(activity) {
FilePickerDialog.show( FilePickerDialog.show(
activity.supportFragmentManager, activity.supportFragmentManager,
requestCode, requestCode,
mode = FilePickerDialog.FILE, mode = FilePickerDialog.FILE,
allowExtensions = allowExtensions allowExtensions = allowExtensions
) )
}
} else { } else {
otherFun?.invoke(selectText) otherFun?.invoke(selectText)
} }
@ -196,7 +182,6 @@ object FilePicker {
) )
fragment.startActivityForResult(intent, requestCode) fragment.startActivityForResult(intent, requestCode)
}.onFailure { }.onFailure {
checkPermissions(fragment) {
FilePickerDialog.show( FilePickerDialog.show(
fragment.childFragmentManager, fragment.childFragmentManager,
requestCode, requestCode,
@ -205,18 +190,15 @@ object FilePicker {
) )
} }
} }
}
else -> { else -> {
val selectText = selectList[index] val selectText = selectList[index]
if (selectText == fragment.getString(R.string.app_file_picker)) { if (selectText == fragment.getString(R.string.app_file_picker)) {
checkPermissions(fragment) {
FilePickerDialog.show( FilePickerDialog.show(
fragment.childFragmentManager, fragment.childFragmentManager,
requestCode, requestCode,
mode = FilePickerDialog.FILE, mode = FilePickerDialog.FILE,
allowExtensions = allowExtensions allowExtensions = allowExtensions
) )
}
} else { } else {
otherFun?.invoke(selectText) otherFun?.invoke(selectText)
} }
@ -246,18 +228,6 @@ object FilePicker {
return intent return intent
} }
private fun checkPermissions(fragment: Fragment, success: (() -> Unit)? = null) {
fragment.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
success?.invoke()
}.launch(Permissions.Group.STORAGE)
}
private fun checkPermissions(activity: AppCompatActivity, success: (() -> Unit)? = null) {
activity.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
success?.invoke()
}.launch(Permissions.Group.STORAGE)
}
private fun typesOfExtensions(allowExtensions: Array<String>): Array<String> { private fun typesOfExtensions(allowExtensions: Array<String>): Array<String> {
val types = hashSetOf<String>() val types = hashSetOf<String>()
if (allowExtensions.isNullOrEmpty()) { if (allowExtensions.isNullOrEmpty()) {

@ -8,12 +8,14 @@ import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Permissions
import io.legado.app.databinding.DialogFileChooserBinding import io.legado.app.databinding.DialogFileChooserBinding
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.filepicker.adapter.FileAdapter import io.legado.app.ui.filepicker.adapter.FileAdapter
@ -69,7 +71,19 @@ class FilePickerDialog : DialogFragment(),
override var isShowHomeDir: Boolean = false override var isShowHomeDir: Boolean = false
override var isShowUpDir: Boolean = true override var isShowUpDir: Boolean = true
override var isShowHideDir: Boolean = false override var isShowHideDir: Boolean = false
private val queryPermission =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
var hasPermission = true
it.forEach { (t, u) ->
if (!u) {
hasPermission = false
toastOnUi(t)
}
}
if (hasPermission) {
refreshCurrentDirPath(initPath)
}
}
private var requestCode: Int = 0 private var requestCode: Int = 0
var title: String? = null var title: String? = null
private var initPath = FileUtils.getSdCardPath() private var initPath = FileUtils.getSdCardPath()
@ -118,7 +132,7 @@ class FilePickerDialog : DialogFragment(),
} }
initMenu() initMenu()
initContentView() initContentView()
refreshCurrentDirPath(initPath) queryPermission.launch(Permissions.Group.STORAGE)
} }
private fun initMenu() { private fun initMenu() {

@ -0,0 +1 @@
emulator -avd %1 -dns-server 8.8.8.8 -no-snapshot-load

@ -1 +0,0 @@
emulator -avd android11 -dns-server 8.8.8.8 -no-snapshot-load
Loading…
Cancel
Save