mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
重新安装应用后没有权限的本地书籍会提示选择文件所在文件夹,不需要重新添加
This commit is contained in:
parent
9d5a5f9ddc
commit
f3c952ed56
@ -29,7 +29,7 @@ object LocalBook {
|
||||
FileUtils.createFolderIfNotExist(appCtx.externalFiles, folderName)
|
||||
}
|
||||
|
||||
@Throws(FileNotFoundException::class)
|
||||
@Throws(FileNotFoundException::class, SecurityException::class)
|
||||
fun getBookInputStream(book: Book): InputStream {
|
||||
if (book.bookUrl.isContentScheme()) {
|
||||
val uri = Uri.parse(book.bookUrl)
|
||||
|
@ -29,6 +29,7 @@ import io.legado.app.model.ReadBook
|
||||
import io.legado.app.ui.book.read.config.BgTextConfigDialog
|
||||
import io.legado.app.ui.book.read.config.ClickActionConfigDialog
|
||||
import io.legado.app.ui.book.read.config.PaddingConfigDialog
|
||||
import io.legado.app.ui.document.HandleFileContract
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
@ -41,6 +42,13 @@ abstract class BaseReadBookActivity :
|
||||
override val binding by viewBinding(ActivityBookReadBinding::inflate)
|
||||
override val viewModel by viewModels<ReadBookViewModel>()
|
||||
var bottomDialog = 0
|
||||
private val selectBookFolderResult = registerForActivityResult(HandleFileContract()){
|
||||
it.uri?.let {
|
||||
ReadBook.book?.let { book ->
|
||||
viewModel.loadChapterList(book)
|
||||
}
|
||||
} ?: ReadBook.upMsg("没有权限访问")
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
ReadBook.msg = null
|
||||
@ -51,6 +59,12 @@ abstract class BaseReadBookActivity :
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
binding.navigationBar.setBackgroundColor(bottomBackground)
|
||||
viewModel.permissionDenialLiveData.observe(this) {
|
||||
selectBookFolderResult.launch {
|
||||
mode = HandleFileContract.SYS_DIR
|
||||
title = "选择书籍所在文件夹"
|
||||
}
|
||||
}
|
||||
if (!LocalConfig.readHelpVersionIsLast) {
|
||||
showClickRegionalConfig()
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.legado.app.ui.book.read
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseViewModel
|
||||
@ -30,6 +31,7 @@ import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.ensureActive
|
||||
|
||||
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
val permissionDenialLiveData = MutableLiveData<Int>()
|
||||
var isInitFinish = false
|
||||
var searchContentQuery = ""
|
||||
private var changeSourceCoroutine: Coroutine<*>? = null
|
||||
@ -121,7 +123,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
ReadBook.loadContent(resetPageOffset = true)
|
||||
}
|
||||
}.onError {
|
||||
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
|
||||
when (it) {
|
||||
is SecurityException -> {
|
||||
permissionDenialLiveData.postValue(1)
|
||||
}
|
||||
else -> ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ReadBook.bookSource?.let {
|
||||
|
@ -58,6 +58,7 @@ class HandleFileActivity :
|
||||
}
|
||||
val allowExtensions = intent.getStringArrayExtra("allowExtensions")
|
||||
val selectList: ArrayList<SelectItem<Int>> = when (mode) {
|
||||
HandleFileContract.SYS_DIR -> getDirActions(true)
|
||||
HandleFileContract.DIR -> getDirActions()
|
||||
HandleFileContract.FILE -> getFileActions()
|
||||
HandleFileContract.EXPORT -> arrayListOf(
|
||||
@ -141,14 +142,14 @@ class HandleFileActivity :
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getDirActions(): ArrayList<SelectItem<Int>> {
|
||||
return if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
||||
private fun getDirActions(onlySys: Boolean = false): ArrayList<SelectItem<Int>> {
|
||||
return if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q || onlySys) {
|
||||
arrayListOf(SelectItem(getString(R.string.sys_folder_picker), HandleFileContract.DIR))
|
||||
} else {
|
||||
arrayListOf(
|
||||
SelectItem(getString(R.string.sys_folder_picker), HandleFileContract.DIR),
|
||||
SelectItem(getString(R.string.app_folder_picker), 10)
|
||||
)
|
||||
} else {
|
||||
arrayListOf(SelectItem(getString(R.string.sys_folder_picker), HandleFileContract.DIR))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ class HandleFileContract :
|
||||
companion object {
|
||||
const val DIR = 0
|
||||
const val FILE = 1
|
||||
const val SYS_DIR = 2
|
||||
const val EXPORT = 3
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user