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.os.Build
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import io.legado.app.R
import io.legado.app.constant.Permissions
import io.legado.app.lib.dialogs.alert
@Suppress("unused")
@ -34,7 +32,6 @@ object FilePicker {
val intent = createSelectDirIntent()
activity.startActivityForResult(intent, requestCode)
}.onFailure {
checkPermissions(activity) {
FilePickerDialog.show(
activity.supportFragmentManager,
requestCode,
@ -42,17 +39,14 @@ object FilePicker {
)
}
}
}
else -> {
val selectText = selectList[index]
if (selectText == activity.getString(R.string.app_folder_picker)) {
checkPermissions(activity) {
FilePickerDialog.show(
activity.supportFragmentManager,
requestCode,
mode = FilePickerDialog.DIRECTORY
)
}
} else {
otherFun?.invoke(selectText)
}
@ -84,7 +78,6 @@ object FilePicker {
val intent = createSelectDirIntent()
fragment.startActivityForResult(intent, requestCode)
}.onFailure {
checkPermissions(fragment) {
FilePickerDialog.show(
fragment.childFragmentManager,
requestCode,
@ -92,17 +85,14 @@ object FilePicker {
)
}
}
}
else -> {
val selectText = selectList[index]
if (selectText == fragment.getString(R.string.app_folder_picker)) {
checkPermissions(fragment) {
FilePickerDialog.show(
fragment.childFragmentManager,
requestCode,
mode = FilePickerDialog.DIRECTORY
)
}
} else {
otherFun?.invoke(selectText)
}
@ -139,7 +129,6 @@ object FilePicker {
)
activity.startActivityForResult(intent, requestCode)
}.onFailure {
checkPermissions(activity) {
FilePickerDialog.show(
activity.supportFragmentManager,
requestCode,
@ -148,18 +137,15 @@ object FilePicker {
)
}
}
}
else -> {
val selectText = selectList[index]
if (selectText == activity.getString(R.string.app_file_picker)) {
checkPermissions(activity) {
FilePickerDialog.show(
activity.supportFragmentManager,
requestCode,
mode = FilePickerDialog.FILE,
allowExtensions = allowExtensions
)
}
} else {
otherFun?.invoke(selectText)
}
@ -196,7 +182,6 @@ object FilePicker {
)
fragment.startActivityForResult(intent, requestCode)
}.onFailure {
checkPermissions(fragment) {
FilePickerDialog.show(
fragment.childFragmentManager,
requestCode,
@ -205,18 +190,15 @@ object FilePicker {
)
}
}
}
else -> {
val selectText = selectList[index]
if (selectText == fragment.getString(R.string.app_file_picker)) {
checkPermissions(fragment) {
FilePickerDialog.show(
fragment.childFragmentManager,
requestCode,
mode = FilePickerDialog.FILE,
allowExtensions = allowExtensions
)
}
} else {
otherFun?.invoke(selectText)
}
@ -246,18 +228,6 @@ object FilePicker {
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> {
val types = hashSetOf<String>()
if (allowExtensions.isNullOrEmpty()) {

@ -8,12 +8,14 @@ import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.constant.Permissions
import io.legado.app.databinding.DialogFileChooserBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.filepicker.adapter.FileAdapter
@ -69,7 +71,19 @@ class FilePickerDialog : DialogFragment(),
override var isShowHomeDir: Boolean = false
override var isShowUpDir: Boolean = true
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
var title: String? = null
private var initPath = FileUtils.getSdCardPath()
@ -118,7 +132,7 @@ class FilePickerDialog : DialogFragment(),
}
initMenu()
initContentView()
refreshCurrentDirPath(initPath)
queryPermission.launch(Permissions.Group.STORAGE)
}
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