From 75bd60ad190e808c299fd0b53543ed5401dfdea4 Mon Sep 17 00:00:00 2001 From: Xwite <82232510+Xwite@users.noreply.github.com> Date: Sat, 8 Oct 2022 08:33:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9C=AC=E5=9C=B0=E4=B9=A6?= =?UTF-8?q?=E7=B1=8D=E5=AF=BC=E5=85=A5=E5=92=8CwebDav=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E6=97=B6=E8=AF=B7=E6=B1=82=E8=AE=BE=E7=BD=AE=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=BD=8D=E7=BD=AE=20(#2386)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: remove storage setting request * refactor: request storage setting when needed --- app/src/main/AndroidManifest.xml | 6 +-- app/src/main/assets/storageHelp.md | 4 +- .../legado/app/model/localBook/LocalBook.kt | 4 +- .../ui/association/FileAssociationActivity.kt | 2 +- .../ui/book/import/BaseImportBookActivity.kt | 45 +++++++++++++++++++ .../{ => import}/local/ImportBookActivity.kt | 7 +-- .../{ => import}/local/ImportBookAdapter.kt | 2 +- .../{ => import}/local/ImportBookViewModel.kt | 2 +- .../local/rule/TxtTocRuleActivity.kt | 2 +- .../local/rule/TxtTocRuleAdapter.kt | 2 +- .../local/rule/TxtTocRuleViewModel.kt | 2 +- .../{ => import}/remote/RemoteBookActivity.kt | 7 +-- .../{ => import}/remote/RemoteBookAdapter.kt | 2 +- .../{ => import}/remote/RemoteBookSort.kt | 2 +- .../remote/RemoteBookViewModel.kt | 2 +- .../book/source/manage/BookSourceActivity.kt | 2 +- .../io/legado/app/ui/main/MainActivity.kt | 31 ------------- .../main/bookshelf/BaseBookshelfFragment.kt | 4 +- 18 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/import/BaseImportBookActivity.kt rename app/src/main/java/io/legado/app/ui/book/{ => import}/local/ImportBookActivity.kt (97%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/local/ImportBookAdapter.kt (99%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/local/ImportBookViewModel.kt (99%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/local/rule/TxtTocRuleActivity.kt (99%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/local/rule/TxtTocRuleAdapter.kt (99%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/local/rule/TxtTocRuleViewModel.kt (98%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/remote/RemoteBookActivity.kt (96%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/remote/RemoteBookAdapter.kt (98%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/remote/RemoteBookSort.kt (51%) rename app/src/main/java/io/legado/app/ui/book/{ => import}/remote/RemoteBookViewModel.kt (98%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d461e6c76..0f89a8673 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -201,7 +201,7 @@ android:screenOrientation="behind" /> @@ -241,11 +241,11 @@ android:launchMode="singleTop" /> localBookTreeSelect.launch { - title = "选择保存书籍的文件夹" + title = getString(R.string.select_book_folder) mode = HandleFileContract.DIR_SYS } else -> { diff --git a/app/src/main/java/io/legado/app/ui/book/import/BaseImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/import/BaseImportBookActivity.kt new file mode 100644 index 000000000..12219caf1 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/import/BaseImportBookActivity.kt @@ -0,0 +1,45 @@ +package io.legado.app.ui.book.import + +import androidx.lifecycle.ViewModel +import androidx.viewbinding.ViewBinding +import io.legado.app.R +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 + +abstract class BaseImportBookActivity(): VMBaseActivity() { + + private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) { + it.uri?.let { treeUri -> + AppConfig.defaultBookTreeUri = treeUri.toString() + } + } + + /** + * 设置书籍保存位置 + */ + protected fun setBookStorage() { + //测试书籍保存位置是否设置 + if (!AppConfig.defaultBookTreeUri.isNullOrBlank()) return + //测试读写?? + val storageHelp = String(assets.open("storageHelp.md").readBytes()) + val hint = getString(R.string.select_book_folder) + alert(hint, storageHelp) { + yesButton { + localBookTreeSelect.launch { + title = hint + mode = HandleFileContract.DIR_SYS + } + } + noButton { + finish() + } + onCancelled { + finish() + } + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt rename to app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt index 113fb5f25..4e9cbb1db 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.local +package io.legado.app.ui.book.import.local import android.annotation.SuppressLint import android.net.Uri @@ -11,7 +11,6 @@ import androidx.appcompat.widget.PopupMenu import androidx.documentfile.provider.DocumentFile import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R -import io.legado.app.base.VMBaseActivity import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.databinding.ActivityImportBookBinding @@ -21,6 +20,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.theme.backgroundColor +import io.legado.app.ui.book.import.BaseImportBookActivity import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.widget.SelectActionBar import io.legado.app.utils.* @@ -34,7 +34,7 @@ import java.io.File /** * 导入本地书籍界面 */ -class ImportBookActivity : VMBaseActivity(), +class ImportBookActivity : BaseImportBookActivity(), PopupMenu.OnMenuItemClickListener, ImportBookAdapter.CallBack, SelectActionBar.CallBack { @@ -61,6 +61,7 @@ class ImportBookActivity : VMBaseActivity(), +class RemoteBookActivity : BaseImportBookActivity(), RemoteBookAdapter.CallBack, SelectActionBar.CallBack { override val binding by viewBinding(ActivityImportBookBinding::inflate) @@ -41,6 +41,7 @@ class RemoteBookActivity : VMBaseActivity(), private var bottomMenuCount = 4 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?) { upBottomMenu() binding.run { @@ -99,8 +92,6 @@ class MainActivity : VMBaseActivity(), if (!privacyPolicy()) return@launch //版本更新 upVersion() - //请求设置书籍保存位置 - setBookStorage() //自动更新书籍 val isAutoRefreshedBook = savedInstanceState?.getBoolean("isAutoRefreshedBook") ?: false if (AppConfig.autoRefreshBook && !isAutoRefreshedBook) { @@ -219,28 +210,6 @@ class MainActivity : VMBaseActivity(), } } - /** - * 设置书籍保存位置 - */ - 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 - } - } - neutralButton("不想设置") { - AppConfig.defaultBookTreeUri = "null" - } - noButton() - } - } - override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { event?.let { when (keyCode) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt index 85f19c0e5..1e04585e9 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt @@ -21,9 +21,9 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.book.cache.CacheActivity import io.legado.app.ui.book.group.GroupManageDialog -import io.legado.app.ui.book.local.ImportBookActivity +import io.legado.app.ui.book.import.local.ImportBookActivity +import io.legado.app.ui.book.import.remote.RemoteBookActivity import io.legado.app.ui.book.manage.BookshelfManageActivity -import io.legado.app.ui.book.remote.RemoteBookActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.main.MainViewModel