pull/1463/head^2
gedoor 3 years ago
parent adfc8d9d71
commit 98bb0b8f14
  1. 12
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  2. 5
      app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt

@ -72,7 +72,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_select_folder -> selectFolder.launch { }
R.id.menu_select_folder -> selectFolder.launch()
R.id.menu_scan_folder -> scanFolder()
R.id.menu_import_file_name -> alertImportFileName()
}
@ -133,7 +133,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
when {
lastPath.isNullOrEmpty() -> {
binding.tvEmptyMsg.visible()
selectFolder.launch { }
selectFolder.launch()
}
lastPath.isContentScheme() -> {
val rootUri = Uri.parse(lastPath)
@ -141,7 +141,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
val doc = DocumentFile.fromTreeUri(this, rootUri)
if (doc == null || doc.name.isNullOrEmpty()) {
binding.tvEmptyMsg.visible()
selectFolder.launch { }
selectFolder.launch()
} else {
subDocs.clear()
rootDoc = FileDoc.fromDocumentFile(doc)
@ -149,12 +149,12 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
}
}.onFailure {
binding.tvEmptyMsg.visible()
selectFolder.launch { }
selectFolder.launch()
}
}
Build.VERSION.SDK_INT > Build.VERSION_CODES.Q -> {
binding.tvEmptyMsg.visible()
selectFolder.launch { }
selectFolder.launch()
}
else -> initRootPath(lastPath)
}
@ -172,7 +172,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
upPath()
}.onFailure {
binding.tvEmptyMsg.visible()
selectFolder.launch { }
selectFolder.launch()
}
}
.request()

@ -5,8 +5,13 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContract
fun ActivityResultLauncher<*>.launch() {
launch(null)
}
class SelectImageContract : ActivityResultContract<Int?, SelectImageContract.Result>() {
var requestCode: Int? = null

Loading…
Cancel
Save