|
|
|
@ -7,21 +7,33 @@ import io.legado.app.base.VMBaseActivity |
|
|
|
|
import io.legado.app.help.config.AppConfig |
|
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
|
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()) { |
|
|
|
|
it.uri?.let { treeUri -> |
|
|
|
|
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 hint = getString(R.string.select_book_folder) |
|
|
|
@ -33,10 +45,10 @@ abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel>(): VMBas |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
noButton { |
|
|
|
|
finish() |
|
|
|
|
block.resume(false) |
|
|
|
|
} |
|
|
|
|
onCancelled { |
|
|
|
|
finish() |
|
|
|
|
block.resume(false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|