mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
优化
This commit is contained in:
parent
f35ea2fc8e
commit
4f9e8c0840
@ -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)
|
||||||
initView()
|
launch {
|
||||||
initEvent()
|
setBookStorage()
|
||||||
initData()
|
initView()
|
||||||
setBookStorage()
|
initEvent()
|
||||||
|
initData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
initView()
|
launch {
|
||||||
initData()
|
if (!setBookStorage()) {
|
||||||
initEvent()
|
finish()
|
||||||
setBookStorage()
|
return@launch
|
||||||
|
}
|
||||||
|
initView()
|
||||||
|
initData()
|
||||||
|
initEvent()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
|
Loading…
Reference in New Issue
Block a user