|
|
@ -46,22 +46,19 @@ class ImportBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Imp |
|
|
|
|
|
|
|
|
|
|
|
private val selectFolder = registerForActivityResult(HandleFileContract()) { |
|
|
|
private val selectFolder = registerForActivityResult(HandleFileContract()) { |
|
|
|
it.uri?.let { uri -> |
|
|
|
it.uri?.let { uri -> |
|
|
|
if (uri.isContentScheme()) { |
|
|
|
AppConfig.importBookPath = uri.toString() |
|
|
|
AppConfig.importBookPath = uri.toString() |
|
|
|
initRootDoc(true) |
|
|
|
initRootDoc(true) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
AppConfig.importBookPath = uri.path |
|
|
|
|
|
|
|
initRootDoc(true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
launch { |
|
|
|
setBookStorage() |
|
|
|
|
|
|
|
initView() |
|
|
|
initView() |
|
|
|
initEvent() |
|
|
|
initEvent() |
|
|
|
|
|
|
|
if (setBookStorage() && AppConfig.importBookPath.isNullOrBlank()) { |
|
|
|
|
|
|
|
AppConfig.importBookPath = AppConfig.defaultBookTreeUri |
|
|
|
|
|
|
|
} |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -150,35 +147,43 @@ class ImportBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Imp |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRootDoc(changedFolder: Boolean = false) { |
|
|
|
private fun initRootDoc(changedFolder: Boolean = false) { |
|
|
|
val lastPath = AppConfig.importBookPath |
|
|
|
if (viewModel.rootDoc != null && !changedFolder) { |
|
|
|
when { |
|
|
|
upPath() |
|
|
|
viewModel.rootDoc != null && !changedFolder -> upPath() |
|
|
|
} else { |
|
|
|
lastPath.isNullOrEmpty() -> { |
|
|
|
val lastPath = AppConfig.importBookPath |
|
|
|
|
|
|
|
if (lastPath.isNullOrBlank()) { |
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
selectFolder.launch() |
|
|
|
selectFolder.launch() |
|
|
|
} |
|
|
|
} else { |
|
|
|
lastPath.isContentScheme() -> { |
|
|
|
val rootUri = if (lastPath.isUri()) { |
|
|
|
val rootUri = Uri.parse(lastPath) |
|
|
|
Uri.parse(lastPath) |
|
|
|
kotlin.runCatching { |
|
|
|
} else { |
|
|
|
val doc = DocumentFile.fromTreeUri(this, rootUri) |
|
|
|
Uri.fromFile(File(lastPath)) |
|
|
|
if (doc == null || doc.name.isNullOrEmpty()) { |
|
|
|
} |
|
|
|
|
|
|
|
when { |
|
|
|
|
|
|
|
rootUri.isContentScheme() -> { |
|
|
|
|
|
|
|
kotlin.runCatching { |
|
|
|
|
|
|
|
val doc = DocumentFile.fromTreeUri(this, rootUri) |
|
|
|
|
|
|
|
if (doc == null || doc.name.isNullOrEmpty()) { |
|
|
|
|
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
|
|
|
|
selectFolder.launch() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
viewModel.subDocs.clear() |
|
|
|
|
|
|
|
viewModel.rootDoc = FileDoc.fromDocumentFile(doc) |
|
|
|
|
|
|
|
upDocs(viewModel.rootDoc!!) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.onFailure { |
|
|
|
|
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
|
|
|
|
selectFolder.launch() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Build.VERSION.SDK_INT > Build.VERSION_CODES.Q -> { |
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
selectFolder.launch() |
|
|
|
selectFolder.launch() |
|
|
|
} else { |
|
|
|
|
|
|
|
viewModel.subDocs.clear() |
|
|
|
|
|
|
|
viewModel.rootDoc = FileDoc.fromDocumentFile(doc) |
|
|
|
|
|
|
|
upDocs(viewModel.rootDoc!!) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}.onFailure { |
|
|
|
else -> initRootPath(rootUri.path!!) |
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
|
|
|
|
selectFolder.launch() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Build.VERSION.SDK_INT > Build.VERSION_CODES.Q -> { |
|
|
|
|
|
|
|
binding.tvEmptyMsg.visible() |
|
|
|
|
|
|
|
selectFolder.launch() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> initRootPath(lastPath) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|