feat: 软件启动时请求设置书籍保存位置 (#2366)

pull/2368/head
Xwite 2 years ago committed by GitHub
parent 5a26f87a71
commit 98083ac92b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/src/main/assets/storageHelp.md
  2. 2
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  3. 28
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -0,0 +1,2 @@
* 由于安卓的存储访问限制,阅读需要设置**公共目录下的子目录**来实现书籍拷贝、下载
* 如不设置,可能影响本地书籍、webDav书籍的正常阅读

@ -121,7 +121,7 @@ class FileAssociationActivity :
val treeUriStr = AppConfig.defaultBookTreeUri val treeUriStr = AppConfig.defaultBookTreeUri
if (treeUriStr.isNullOrEmpty()) { if (treeUriStr.isNullOrEmpty()) {
localBookTreeSelect.launch { localBookTreeSelect.launch {
title = "选择保存书籍的文件夹" title = getString(R.string.select_book_folder)
mode = HandleFileContract.DIR_SYS mode = HandleFileContract.DIR_SYS
} }
} else { } else {

@ -31,6 +31,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.elevation import io.legado.app.lib.theme.elevation
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.main.bookshelf.BaseBookshelfFragment import io.legado.app.ui.main.bookshelf.BaseBookshelfFragment
import io.legado.app.ui.main.bookshelf.style1.BookshelfFragment1 import io.legado.app.ui.main.bookshelf.style1.BookshelfFragment1
import io.legado.app.ui.main.bookshelf.style2.BookshelfFragment2 import io.legado.app.ui.main.bookshelf.style2.BookshelfFragment2
@ -70,6 +71,12 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
private var bottomMenuCount = 4 private var bottomMenuCount = 4
private val realPositions = arrayOf(idBookshelf, idExplore, idRss, idMy) private val realPositions = arrayOf(idBookshelf, idExplore, idRss, idMy)
private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) {
it.uri?.let { treeUri ->
AppConfig.defaultBookTreeUri = treeUri.toString()
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
upBottomMenu() upBottomMenu()
binding.run { binding.run {
@ -87,6 +94,8 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
super.onPostCreate(savedInstanceState) super.onPostCreate(savedInstanceState)
upVersion() upVersion()
privacyPolicy() privacyPolicy()
//请求设置书籍保存位置
setBookStorage()
//自动更新书籍 //自动更新书籍
val isAutoRefreshedBook = savedInstanceState?.getBoolean("isAutoRefreshedBook") ?: false val isAutoRefreshedBook = savedInstanceState?.getBoolean("isAutoRefreshedBook") ?: false
if (AppConfig.autoRefreshBook && !isAutoRefreshedBook) { if (AppConfig.autoRefreshBook && !isAutoRefreshedBook) {
@ -181,6 +190,25 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
} }
} }
/**
* 设置书籍保存位置
*/
private fun setBookStorage() {
//测试书籍保存位置是否设置
if (!AppConfig.defaultBookTreeUri.isNullOrBlank()) return
//测试读写??
val storageHelp = String(assets.open("storageHelp.md").readBytes())
alert("设置书籍保存位置", storageHelp) {
yesButton {
localBookTreeSelect.launch {
title = getString(R.string.select_book_folder)
mode = HandleFileContract.DIR_SYS
}
}
noButton()
}
}
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
event?.let { event?.let {
when (keyCode) { when (keyCode) {

Loading…
Cancel
Save