pull/2425/head
kunfei 2 years ago
parent f35ea2fc8e
commit 4f9e8c0840
  1. 3
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  2. 24
      app/src/main/java/io/legado/app/ui/book/import/BaseImportBookActivity.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt
  4. 7
      app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookActivity.kt

@ -33,7 +33,8 @@ class FileAssociationActivity :
AppConfig.defaultBookTreeUri = treeUri.toString() AppConfig.defaultBookTreeUri = treeUri.toString()
importBook(treeUri, uri) importBook(treeUri, uri)
} ?: let { } ?: let {
toastOnUi("不选择文件夹重启应用后可能没有权限访问") val storageHelp = String(assets.open("storageHelp.md").readBytes())
toastOnUi(storageHelp)
viewModel.importBook(uri) viewModel.importBook(uri)
} }
} }

@ -7,21 +7,33 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.document.HandleFileContract
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel>(): VMBaseActivity<VB, VM>() { abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel> : VMBaseActivity<VB, VM>() {
private var localBookTreeSelectListener: ((Boolean) -> Unit)? = null
private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) { private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) {
it.uri?.let { treeUri -> it.uri?.let { treeUri ->
AppConfig.defaultBookTreeUri = treeUri.toString() AppConfig.defaultBookTreeUri = treeUri.toString()
} localBookTreeSelectListener?.invoke(true)
} ?: localBookTreeSelectListener?.invoke(false)
} }
/** /**
* 设置书籍保存位置 * 设置书籍保存位置
*/ */
protected fun setBookStorage() { protected suspend fun setBookStorage() = suspendCoroutine { block ->
AppConfig.defaultBookTreeUri = ""
localBookTreeSelectListener = {
block.resume(it)
}
//测试书籍保存位置是否设置 //测试书籍保存位置是否设置
if (!AppConfig.defaultBookTreeUri.isNullOrBlank()) return if (!AppConfig.defaultBookTreeUri.isNullOrBlank()) {
block.resume(true)
return@suspendCoroutine
}
//测试读写?? //测试读写??
val storageHelp = String(assets.open("storageHelp.md").readBytes()) val storageHelp = String(assets.open("storageHelp.md").readBytes())
val hint = getString(R.string.select_book_folder) val hint = getString(R.string.select_book_folder)
@ -33,10 +45,10 @@ abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel>(): VMBas
} }
} }
noButton { noButton {
finish() block.resume(false)
} }
onCancelled { onCancelled {
finish() block.resume(false)
} }
} }
} }

@ -58,10 +58,12 @@ class ImportBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Imp
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.setTitle(R.string.book_local) binding.titleBar.setTitle(R.string.book_local)
launch {
setBookStorage()
initView() initView()
initEvent() initEvent()
initData() initData()
setBookStorage() }
} }
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {

@ -38,10 +38,15 @@ class RemoteBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Rem
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.setTitle(R.string.remote_book) binding.titleBar.setTitle(R.string.remote_book)
launch {
if (!setBookStorage()) {
finish()
return@launch
}
initView() initView()
initData() initData()
initEvent() initEvent()
setBookStorage() }
} }
private fun initView() { private fun initView() {

Loading…
Cancel
Save