|
|
|
@ -46,22 +46,19 @@ class ImportBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Imp |
|
|
|
|
|
|
|
|
|
private val selectFolder = registerForActivityResult(HandleFileContract()) { |
|
|
|
|
it.uri?.let { uri -> |
|
|
|
|
if (uri.isContentScheme()) { |
|
|
|
|
AppConfig.importBookPath = uri.toString() |
|
|
|
|
initRootDoc(true) |
|
|
|
|
} else { |
|
|
|
|
AppConfig.importBookPath = uri.path |
|
|
|
|
initRootDoc(true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
|
binding.titleBar.setTitle(R.string.book_local) |
|
|
|
|
launch { |
|
|
|
|
setBookStorage() |
|
|
|
|
initView() |
|
|
|
|
initEvent() |
|
|
|
|
if (setBookStorage() && AppConfig.importBookPath.isNullOrBlank()) { |
|
|
|
|
AppConfig.importBookPath = AppConfig.defaultBookTreeUri |
|
|
|
|
} |
|
|
|
|
initData() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -150,15 +147,21 @@ class ImportBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Imp |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initRootDoc(changedFolder: Boolean = false) { |
|
|
|
|
if (viewModel.rootDoc != null && !changedFolder) { |
|
|
|
|
upPath() |
|
|
|
|
} else { |
|
|
|
|
val lastPath = AppConfig.importBookPath |
|
|
|
|
when { |
|
|
|
|
viewModel.rootDoc != null && !changedFolder -> upPath() |
|
|
|
|
lastPath.isNullOrEmpty() -> { |
|
|
|
|
if (lastPath.isNullOrBlank()) { |
|
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
|
selectFolder.launch() |
|
|
|
|
} else { |
|
|
|
|
val rootUri = if (lastPath.isUri()) { |
|
|
|
|
Uri.parse(lastPath) |
|
|
|
|
} else { |
|
|
|
|
Uri.fromFile(File(lastPath)) |
|
|
|
|
} |
|
|
|
|
lastPath.isContentScheme() -> { |
|
|
|
|
val rootUri = Uri.parse(lastPath) |
|
|
|
|
when { |
|
|
|
|
rootUri.isContentScheme() -> { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
val doc = DocumentFile.fromTreeUri(this, rootUri) |
|
|
|
|
if (doc == null || doc.name.isNullOrEmpty()) { |
|
|
|
@ -178,7 +181,9 @@ class ImportBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Imp |
|
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
|
selectFolder.launch() |
|
|
|
|
} |
|
|
|
|
else -> initRootPath(lastPath) |
|
|
|
|
else -> initRootPath(rootUri.path!!) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|