From d79e3d09b52623e9dabf0ee75aa16b84a26a298f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 5 Apr 2022 21:36:08 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../BookAdapter.kt} | 4 ++-- .../BookshelfManageActivity.kt} | 11 ++++++----- .../BookshelfManageViewModel.kt} | 4 ++-- .../ui/book/{arrange => management}/ComposeView.kt | 2 +- .../{arrange => management}/SourcePickerDialog.kt | 2 +- .../app/ui/main/bookshelf/BaseBookshelfFragment.kt | 4 ++-- app/src/main/res/layout/activity_arrange_book.xml | 2 +- app/src/main/res/menu/main_bookshelf.xml | 12 ++++++------ app/src/main/res/values-es-rES/strings.xml | 2 +- app/src/main/res/values-ja-rJP/strings.xml | 2 +- app/src/main/res/values-pt-rBR/strings.xml | 2 +- app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 16 files changed, 29 insertions(+), 28 deletions(-) rename app/src/main/java/io/legado/app/ui/book/{arrange/ArrangeBookAdapter.kt => management/BookAdapter.kt} (98%) rename app/src/main/java/io/legado/app/ui/book/{arrange/ArrangeBookActivity.kt => management/BookshelfManageActivity.kt} (96%) rename app/src/main/java/io/legado/app/ui/book/{arrange/ArrangeBookViewModel.kt => management/BookshelfManageViewModel.kt} (93%) rename app/src/main/java/io/legado/app/ui/book/{arrange => management}/ComposeView.kt (97%) rename app/src/main/java/io/legado/app/ui/book/{arrange => management}/SourcePickerDialog.kt (98%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6c95c79ce..473dba4f1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -249,7 +249,7 @@ android:screenOrientation="behind" /> diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/management/BookAdapter.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/management/BookAdapter.kt index d55938e5c..2aa3f43b3 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/management/BookAdapter.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.arrange +package io.legado.app.ui.book.management import android.annotation.SuppressLint import android.content.Context @@ -15,7 +15,7 @@ import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback -class ArrangeBookAdapter(context: Context, val callBack: CallBack) : +class BookAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context), ItemTouchCallback.Callback { diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageActivity.kt similarity index 96% rename from app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt rename to app/src/main/java/io/legado/app/ui/book/management/BookshelfManageActivity.kt index 85c67d54c..4cd6bc476 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageActivity.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.arrange +package io.legado.app.ui.book.management import android.annotation.SuppressLint import android.os.Bundle @@ -39,19 +39,20 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class ArrangeBookActivity : VMBaseActivity(), +class BookshelfManageActivity : + VMBaseActivity(), PopupMenu.OnMenuItemClickListener, SelectActionBar.CallBack, - ArrangeBookAdapter.CallBack, + BookAdapter.CallBack, SourcePickerDialog.Callback, GroupSelectDialog.CallBack { override val binding by viewBinding(ActivityArrangeBookBinding::inflate) - override val viewModel by viewModels() + override val viewModel by viewModels() override val groupList: ArrayList = arrayListOf() private val groupRequestCode = 22 private val addToGroupRequestCode = 34 - private val adapter by lazy { ArrangeBookAdapter(this, this) } + private val adapter by lazy { BookAdapter(this, this) } private var booksFlowJob: Job? = null private var menu: Menu? = null private var groupId: Long = -1 diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageViewModel.kt similarity index 93% rename from app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt rename to app/src/main/java/io/legado/app/ui/book/management/BookshelfManageViewModel.kt index da6ef4862..17c1cfbd2 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageViewModel.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.arrange +package io.legado.app.ui.book.management import android.app.Application import androidx.compose.runtime.mutableStateOf @@ -10,7 +10,7 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.webBook.WebBook -class ArrangeBookViewModel(application: Application) : BaseViewModel(application) { +class BookshelfManageViewModel(application: Application) : BaseViewModel(application) { val batchChangeSourceState = mutableStateOf(false) val batchChangeSourceSize = mutableStateOf(0) diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt b/app/src/main/java/io/legado/app/ui/book/management/ComposeView.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt rename to app/src/main/java/io/legado/app/ui/book/management/ComposeView.kt index bfb86ed15..01b2d2bf9 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt +++ b/app/src/main/java/io/legado/app/ui/book/management/ComposeView.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.arrange +package io.legado.app.ui.book.management import androidx.compose.foundation.layout.Column import androidx.compose.material.AlertDialog diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/SourcePickerDialog.kt b/app/src/main/java/io/legado/app/ui/book/management/SourcePickerDialog.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/arrange/SourcePickerDialog.kt rename to app/src/main/java/io/legado/app/ui/book/management/SourcePickerDialog.kt index 50101e9a6..01c4c088b 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/SourcePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/management/SourcePickerDialog.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.arrange +package io.legado.app.ui.book.management import android.content.Context import android.os.Bundle 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 e4f0847f0..739a2c111 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 @@ -19,10 +19,10 @@ import io.legado.app.help.DirectLinkUpload import io.legado.app.help.config.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.ui.about.AppLogDialog -import io.legado.app.ui.book.arrange.ArrangeBookActivity 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.management.BookshelfManageActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.main.MainViewModel @@ -80,7 +80,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment showDialogFragment() R.id.menu_add_local -> startActivity() R.id.menu_add_url -> addBookByUrl() - R.id.menu_arrange_bookshelf -> startActivity { + R.id.menu_bookshelf_manage -> startActivity { putExtra("groupId", groupId) } R.id.menu_download -> startActivity { diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index e85718977..b9875f283 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -9,7 +9,7 @@ android:id="@+id/title_bar" android:layout_width="match_parent" android:layout_height="wrap_content" - app:title="@string/arrange_bookshelf" + app:title="@string/bookshelf_management" app:layout_constraintTop_toTopOf="parent" /> + + - - Tiempo límite de carga Siga:%s Copiado con éxito - Organización de estantería + Organización de estantería Esto borrará a todos los libros. Por favor, tenga cuidado. Buscar fuentes de libros Buscar fuentes de suscripción diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index dfb209873..3385b091b 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -271,7 +271,7 @@ Loading timeout Follow:%s Copied successfully - Bookshelf arrangement + Bookshelf management It will delete all books. Be careful,please. Search book sources Search subscription sources diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index ac7d406b6..863b931ad 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -271,7 +271,7 @@ Tempo limite de carregamento Siga:%s Copiado com sucesso - A organização da estante + A organização da estante Isto excluirá todos os livros. Por favor, tenha cuidado. Pesquisar fontes de livros Buscar fontes de assinatura diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 56dab2441..416e92a93 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -268,7 +268,7 @@ 加載超時 關注: %s 拷貝咗 - 整理書架 + 書架管理 這將會刪除所有書籍,請謹慎操作。 搜索書源 搜索訂閲源 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 69805157e..874d66764 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -270,7 +270,7 @@ 載入超時 關注:%s 已複製 - 整理書架 + 書架管理 這將會刪除所有書籍,請謹慎操作。 搜尋書源 搜尋訂閱源 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 8f9c01346..6b9b415d0 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -270,7 +270,7 @@ 加载超时 关注:%s 已拷贝 - 整理书架 + 书架管理 这将会删除所有书籍,请谨慎操作。 搜索书源 搜索订阅源 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9423a4cf5..bc5f63327 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -271,7 +271,7 @@ Loading timeout Follow:%s Copied successfully - Bookshelf arrangement + Bookshelf management It will delete all books. Be careful,please. Search book sources Search subscription sources From ba491d388c66fb8079fd10cbb7710c2c5bec946c Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 5 Apr 2022 22:03:44 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../main/java/io/legado/app/constant/AppConst.kt | 1 + .../ui/book/{management => manage}/BookAdapter.kt | 2 +- .../BookshelfManageActivity.kt | 15 +++++++++++---- .../BookshelfManageViewModel.kt | 2 +- .../ui/book/{management => manage}/ComposeView.kt | 2 +- .../{management => manage}/SourcePickerDialog.kt | 2 +- .../ui/main/bookshelf/BaseBookshelfFragment.kt | 2 +- .../main/bookshelf/style2/BookshelfFragment2.kt | 11 +++++------ 9 files changed, 23 insertions(+), 16 deletions(-) rename app/src/main/java/io/legado/app/ui/book/{management => manage}/BookAdapter.kt (99%) rename app/src/main/java/io/legado/app/ui/book/{management => manage}/BookshelfManageActivity.kt (95%) rename app/src/main/java/io/legado/app/ui/book/{management => manage}/BookshelfManageViewModel.kt (97%) rename app/src/main/java/io/legado/app/ui/book/{management => manage}/ComposeView.kt (97%) rename app/src/main/java/io/legado/app/ui/book/{management => manage}/SourcePickerDialog.kt (98%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 473dba4f1..d33213e6e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -249,7 +249,7 @@ android:screenOrientation="behind" /> diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index d8c5b2d00..aed422165 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -39,6 +39,7 @@ object AppConst { SimpleDateFormat("yy-MM-dd-HH-mm-ss") } + const val rootGroupId = -100L const val bookGroupAllId = -1L const val bookGroupLocalId = -2L const val bookGroupAudioId = -3L diff --git a/app/src/main/java/io/legado/app/ui/book/management/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/manage/BookAdapter.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/book/management/BookAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/manage/BookAdapter.kt index 2aa3f43b3..a7564cf5b 100644 --- a/app/src/main/java/io/legado/app/ui/book/management/BookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/BookAdapter.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.management +package io.legado.app.ui.book.manage import android.annotation.SuppressLint import android.content.Context diff --git a/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageActivity.kt b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt similarity index 95% rename from app/src/main/java/io/legado/app/ui/book/management/BookshelfManageActivity.kt rename to app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt index 4cd6bc476..e60b27d85 100644 --- a/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.management +package io.legado.app.ui.book.manage import android.annotation.SuppressLint import android.os.Bundle @@ -140,6 +140,7 @@ class BookshelfManageActivity : booksFlowJob?.cancel() booksFlowJob = launch { when (groupId) { + AppConst.rootGroupId -> appDb.bookDao.flowNoGroup() AppConst.bookGroupAllId -> appDb.bookDao.flowAll() AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() @@ -147,12 +148,18 @@ class BookshelfManageActivity : else -> appDb.bookDao.flowByGroup(groupId) }.conflate().map { books -> when (getPrefInt(PreferKey.bookshelfSort)) { - 1 -> books.sortedByDescending { it.latestChapterTime } + 1 -> books.sortedByDescending { + it.latestChapterTime + } 2 -> books.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) } - 3 -> books.sortedBy { it.order } - else -> books.sortedByDescending { it.durChapterTime } + 3 -> books.sortedBy { + it.order + } + else -> books.sortedByDescending { + it.durChapterTime + } } }.conflate().collect { books -> adapter.setItems(books) diff --git a/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageViewModel.kt b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/book/management/BookshelfManageViewModel.kt rename to app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt index 17c1cfbd2..c404851e3 100644 --- a/app/src/main/java/io/legado/app/ui/book/management/BookshelfManageViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.management +package io.legado.app.ui.book.manage import android.app.Application import androidx.compose.runtime.mutableStateOf diff --git a/app/src/main/java/io/legado/app/ui/book/management/ComposeView.kt b/app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/book/management/ComposeView.kt rename to app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt index 01b2d2bf9..ffa57baa2 100644 --- a/app/src/main/java/io/legado/app/ui/book/management/ComposeView.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.management +package io.legado.app.ui.book.manage import androidx.compose.foundation.layout.Column import androidx.compose.material.AlertDialog diff --git a/app/src/main/java/io/legado/app/ui/book/management/SourcePickerDialog.kt b/app/src/main/java/io/legado/app/ui/book/manage/SourcePickerDialog.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/management/SourcePickerDialog.kt rename to app/src/main/java/io/legado/app/ui/book/manage/SourcePickerDialog.kt index 01c4c088b..1be0837dc 100644 --- a/app/src/main/java/io/legado/app/ui/book/management/SourcePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/SourcePickerDialog.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.management +package io.legado.app.ui.book.manage import android.content.Context import android.os.Bundle 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 739a2c111..78d16eb92 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 @@ -22,7 +22,7 @@ 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.management.BookshelfManageActivity +import io.legado.app.ui.book.manage.BookshelfManageActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.main.MainViewModel diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index 6cd545f29..cfa2c4304 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -43,7 +43,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), BaseBooksAdapter.CallBack { private val binding by viewBinding(FragmentBookshelf1Binding::bind) - private val rootGroupId = -100L private val bookshelfLayout by lazy { getPrefInt(PreferKey.bookshelfLayout) } @@ -56,7 +55,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), } private var bookGroups: List = emptyList() private var booksFlowJob: Job? = null - override var groupId = rootGroupId + override var groupId = AppConst.rootGroupId override var books: List = emptyList() override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { @@ -121,7 +120,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), booksFlowJob?.cancel() booksFlowJob = launch { when (groupId) { - rootGroupId -> appDb.bookDao.flowRoot() + AppConst.rootGroupId -> appDb.bookDao.flowRoot() AppConst.bookGroupAllId -> appDb.bookDao.flowAll() AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() @@ -212,7 +211,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), } override fun getItemCount(): Int { - return if (groupId == rootGroupId) { + return if (groupId == AppConst.rootGroupId) { bookGroups.size + books.size } else { books.size @@ -220,7 +219,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), } override fun getItemType(position: Int): Int { - if (groupId != rootGroupId) { + if (groupId != AppConst.rootGroupId) { return 0 } if (position < bookGroups.size) { @@ -230,7 +229,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), } override fun getItem(position: Int): Any? { - if (groupId != rootGroupId) { + if (groupId != AppConst.rootGroupId) { return books.getOrNull(position) } if (position < bookGroups.size) { From f6306574d4597a2180fdfaa24ddce03ea78238f4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 6 Apr 2022 20:19:46 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=88=A4=E6=96=AD,=E6=80=BB=E6=9C=89?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/association/FileAssociationViewModel.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index 3726127ff..47e72ae87 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -4,7 +4,6 @@ import android.app.Application import android.net.Uri import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData -import io.legado.app.constant.AppPattern.bookFileRegex import io.legado.app.exception.NoStackTraceException import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.isJson @@ -47,12 +46,7 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo importHttpTTS(content, finally) else -> errorLiveData.postValue("格式不对") } - (uri.path ?: uri.toString()).matches(bookFileRegex) -> { - importBookLiveData.postValue(uri) - } - else -> { - throw NoStackTraceException("暂未支持的本地书籍格式(TXT/UMD/EPUB)") - } + else -> importBookLiveData.postValue(uri) } } else { onLineImportLive.postValue(uri) From cbe075f9f777711da5e9922159dd623ff72c51da Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 6 Apr 2022 20:21:45 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1059ac467..8293acfc7 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,6 +11,11 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2022/04/06** + +* 实现epub的懒加载 by ag2s20150909 +* 去掉导入文件格式判断,总有人反馈txt无法导入 + **2022/04/05** * 更新cronet: 100.0.4896.79 From 6dc656f7fa6bd8a3a0e876ab5ef5b50ab86b2365 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 6 Apr 2022 20:24:58 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/manage/BookshelfManageActivity.kt | 4 ++-- .../main/res/menu/{arrange_book.xml => bookshelf_manage.xml} | 0 .../menu/{arrange_book_sel.xml => bookshelf_menage_sel.xml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename app/src/main/res/menu/{arrange_book.xml => bookshelf_manage.xml} (100%) rename app/src/main/res/menu/{arrange_book_sel.xml => bookshelf_menage_sel.xml} (100%) diff --git a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt index e60b27d85..f2dfd4a4f 100644 --- a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt @@ -71,7 +71,7 @@ class BookshelfManageActivity : } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { - menuInflater.inflate(R.menu.arrange_book, menu) + menuInflater.inflate(R.menu.bookshelf_manage, menu) return super.onCompatCreateOptionsMenu(menu) } @@ -108,7 +108,7 @@ class BookshelfManageActivity : // Note: need judge selection first, so add ItemTouchHelper after it. ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) binding.selectActionBar.setMainActionText(R.string.move_to_group) - binding.selectActionBar.inflateMenu(R.menu.arrange_book_sel) + binding.selectActionBar.inflateMenu(R.menu.bookshelf_menage_sel) binding.selectActionBar.setOnMenuItemClickListener(this) binding.selectActionBar.setCallBack(this) binding.composeView.setContent { diff --git a/app/src/main/res/menu/arrange_book.xml b/app/src/main/res/menu/bookshelf_manage.xml similarity index 100% rename from app/src/main/res/menu/arrange_book.xml rename to app/src/main/res/menu/bookshelf_manage.xml diff --git a/app/src/main/res/menu/arrange_book_sel.xml b/app/src/main/res/menu/bookshelf_menage_sel.xml similarity index 100% rename from app/src/main/res/menu/arrange_book_sel.xml rename to app/src/main/res/menu/bookshelf_menage_sel.xml From 00bbc0b824459bd5369e9077e732a777a9171cba Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Thu, 7 Apr 2022 10:10:41 +0800 Subject: [PATCH 06/14] =?UTF-8?q?fix:=E8=AF=86=E5=88=ABcontent://download/?= =?UTF-8?q?1234=E7=9A=84=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../association/FileAssociationViewModel.kt | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index 47e72ae87..5e90e51dc 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -4,6 +4,7 @@ import android.app.Application import android.net.Uri import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData +import io.legado.app.constant.AppPattern.bookFileRegex import io.legado.app.exception.NoStackTraceException import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.isJson @@ -23,15 +24,22 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo @Suppress("BlockingMethodInNonBlockingContext") fun dispatchIndent(uri: Uri, finally: (title: String, msg: String) -> Unit) { execute { + lateinit var fileName: String + lateinit var content: String //如果是普通的url,需要根据返回的内容判断是什么 if (uri.scheme == "file" || uri.scheme == "content") { - val content = if (uri.scheme == "file") { - File(uri.path.toString()).readText() + if (uri.scheme == "file") { + val file = File(uri.path.toString()) + content = file.readText() + fileName = file.name } else { - DocumentFile.fromSingleUri(context, uri)?.readText(context) - } ?: throw NoStackTraceException("文件不存在") - when { - content.isJson() -> when { + val file = DocumentFile.fromSingleUri(context, uri) + content = file?.readText(context) ?: throw NoStackTraceException("文件不存在") + fileName = file!!.name ?: "" + } + if (content.isJson()) { + //暂时根据文件内容判断属于什么 + when { content.contains("bookSourceUrl") -> importBookSourceLive.postValue(content) content.contains("sourceUrl") -> @@ -46,7 +54,10 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo importHttpTTS(content, finally) else -> errorLiveData.postValue("格式不对") } - else -> importBookLiveData.postValue(uri) + } else if (fileName.matches(bookFileRegex)) { + importBookLiveData.postValue(uri) + } else { + throw NoStackTraceException("$fileName 暂未支持的本地书籍格式(TXT/UMD/EPUB)") } } else { onLineImportLive.postValue(uri) From 492e3241e6d028bd7ae22d2c4639dafd6366d824 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 11:27:34 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../association/FileAssociationViewModel.kt | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index 5e90e51dc..403412fd9 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -35,29 +35,33 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo } else { val file = DocumentFile.fromSingleUri(context, uri) content = file?.readText(context) ?: throw NoStackTraceException("文件不存在") - fileName = file!!.name ?: "" + fileName = file.name ?: "" } - if (content.isJson()) { - //暂时根据文件内容判断属于什么 - when { - content.contains("bookSourceUrl") -> - importBookSourceLive.postValue(content) - content.contains("sourceUrl") -> - importRssSourceLive.postValue(content) - content.contains("pattern") -> - importReplaceRuleLive.postValue(content) - content.contains("themeName") -> - importTheme(content, finally) - content.contains("name") && content.contains("rule") -> - importTextTocRule(content, finally) - content.contains("name") && content.contains("url") -> - importHttpTTS(content, finally) - else -> errorLiveData.postValue("格式不对") + when { + content.isJson() -> { + //暂时根据文件内容判断属于什么 + when { + content.contains("bookSourceUrl") -> + importBookSourceLive.postValue(content) + content.contains("sourceUrl") -> + importRssSourceLive.postValue(content) + content.contains("pattern") -> + importReplaceRuleLive.postValue(content) + content.contains("themeName") -> + importTheme(content, finally) + content.contains("name") && content.contains("rule") -> + importTextTocRule(content, finally) + content.contains("name") && content.contains("url") -> + importHttpTTS(content, finally) + else -> errorLiveData.postValue("格式不对") + } + } + fileName.matches(bookFileRegex) -> { + importBookLiveData.postValue(uri) + } + else -> { + throw NoStackTraceException("$fileName 暂未支持的本地书籍格式(TXT/UMD/EPUB)") } - } else if (fileName.matches(bookFileRegex)) { - importBookLiveData.postValue(uri) - } else { - throw NoStackTraceException("$fileName 暂未支持的本地书籍格式(TXT/UMD/EPUB)") } } else { onLineImportLive.postValue(uri) From f377f3ca5ca5d1a3900ff6dcdb3b54cfe21088d4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 11:33:02 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 2aa8b9277..0fcfb9ee9 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -183,6 +183,9 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { bookData.value!!.changeTo(newBook, toc) bookData.postValue(newBook) chapterListData.postValue(toc) + if (inBookshelf) { + appDb.bookChapterDao.insert(*toc.toTypedArray()) + } }.onFinally { postEvent(EventBus.SOURCE_CHANGED, newBook.bookUrl) } From 7ae3838a01fd0c599775f1f66700a9bbb7292d17 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 15:14:44 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/config/AppConfig.kt | 12 ++++++++++-- .../ui/book/changesource/ChangeBookSourceDialog.kt | 9 ++++----- .../book/changesource/ChangeBookSourceViewModel.kt | 5 ++--- .../book/changesource/ChangeChapterSourceDialog.kt | 9 ++++----- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt index a851ce134..d9a045a2a 100644 --- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt @@ -276,9 +276,17 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { val autoChangeSource: Boolean get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true) - val changeSourceLoadInfo get() = appCtx.getPrefBoolean(PreferKey.changeSourceLoadInfo) + var changeSourceLoadInfo: Boolean + get() = appCtx.getPrefBoolean(PreferKey.changeSourceLoadInfo) + set(value) { + appCtx.putPrefBoolean(PreferKey.changeSourceLoadInfo, value) + } - val changeSourceLoadToc get() = appCtx.getPrefBoolean(PreferKey.changeSourceLoadToc) + var changeSourceLoadToc: Boolean + get() = appCtx.getPrefBoolean(PreferKey.changeSourceLoadToc) + set(value) { + appCtx.putPrefBoolean(PreferKey.changeSourceLoadToc, value) + } val importKeepName get() = appCtx.getPrefBoolean(PreferKey.importKeepName) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index 1ebcb9e1b..e0b7be1aa 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -16,7 +16,6 @@ import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.constant.AppPattern import io.legado.app.constant.EventBus -import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter @@ -207,12 +206,12 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ item.isChecked = !item.isChecked viewModel.refresh() } - R.id.menu_load_toc -> { - putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) + R.id.menu_load_info -> { + AppConfig.changeSourceLoadInfo = !item.isChecked item.isChecked = !item.isChecked } - R.id.menu_load_info -> { - putPrefBoolean(PreferKey.changeSourceLoadInfo, !item.isChecked) + R.id.menu_load_toc -> { + AppConfig.changeSourceLoadToc = !item.isChecked item.isChecked = !item.isChecked } R.id.menu_start_stop -> viewModel.startOrStopSearch() diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt index f3f1985a7..337d6fae9 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt @@ -184,12 +184,11 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a } private suspend fun loadBookInfo(scope: CoroutineScope, source: BookSource, book: Book) { - val mBook = WebBook.getBookInfoAwait(scope, source, book) + WebBook.getBookInfoAwait(scope, source, book) if (context.getPrefBoolean(PreferKey.changeSourceLoadToc)) { - loadBookToc(scope, source, mBook) + loadBookToc(scope, source, book) } else { //从详情页里获取最新章节 - book.latestChapterTitle = mBook.latestChapterTitle val searchBook = book.toSearchBook() searchCallback?.searchSuccess(searchBook) } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt index 21b61822e..fef913c26 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt @@ -16,7 +16,6 @@ import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.constant.AppPattern import io.legado.app.constant.EventBus -import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter @@ -231,12 +230,12 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c item.isChecked = !item.isChecked viewModel.refresh() } - R.id.menu_load_toc -> { - putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) + R.id.menu_load_info -> { + AppConfig.changeSourceLoadInfo = !item.isChecked item.isChecked = !item.isChecked } - R.id.menu_load_info -> { - putPrefBoolean(PreferKey.changeSourceLoadInfo, !item.isChecked) + R.id.menu_load_toc -> { + AppConfig.changeSourceLoadToc = !item.isChecked item.isChecked = !item.isChecked } R.id.menu_start_stop -> viewModel.startOrStopSearch() From aa6039273d2ae777d9a650d81fd4970111aebeb6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 15:31:43 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/info/BookInfoActivity.kt | 4 +--- .../java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 9cf8fa8f5..18872071e 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -300,9 +300,7 @@ class BookInfoActivity : } } tvChangeSource.setOnClickListener { - viewModel.bookData.value?.let { - showDialogFragment(ChangeBookSourceDialog(it.name, it.author)) - } + showDialogFragment(ChangeBookSourceDialog(viewModel.name, viewModel.author)) } tvTocView.setOnClickListener { if (!viewModel.inBookshelf) { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 0fcfb9ee9..35069c8ec 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -27,6 +27,8 @@ import kotlinx.coroutines.Dispatchers.IO class BookInfoViewModel(application: Application) : BaseViewModel(application) { val bookData = MutableLiveData() val chapterListData = MutableLiveData>() + var name = "" + var author = "" var durChapterIndex = 0 var inBookshelf = false var bookSource: BookSource? = null @@ -34,8 +36,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun initData(intent: Intent) { execute { - val name = intent.getStringExtra("name") ?: "" - val author = intent.getStringExtra("author") ?: "" + name = intent.getStringExtra("name") ?: "" + author = intent.getStringExtra("author") ?: "" val bookUrl = intent.getStringExtra("bookUrl") ?: "" appDb.bookDao.getBook(name, author)?.let { inBookshelf = true From 3a2ed37f1f48ffb3f9348a6a6a6d50ec2fb57293 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 15:46:14 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/entities/Book.kt | 4 ---- .../io/legado/app/ui/book/audio/AudioPlayActivity.kt | 2 ++ .../io/legado/app/ui/book/audio/AudioPlayViewModel.kt | 4 +++- .../io/legado/app/ui/book/info/BookInfoViewModel.kt | 11 ++++++----- .../app/ui/book/manage/BookshelfManageViewModel.kt | 1 + .../io/legado/app/ui/book/read/ReadBookActivity.kt | 1 + .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 3 ++- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 8a3a632d5..568778d14 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -287,10 +287,6 @@ data class Book( newBook.customTag = customTag newBook.canUpdate = canUpdate newBook.readConfig = readConfig - if (appDb.bookDao.has(bookUrl) == true) { - delete() - appDb.bookDao.insert(newBook) - } return newBook } diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index 4f9b53240..778aef4d2 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -16,6 +16,7 @@ import io.legado.app.constant.BookType import io.legado.app.constant.EventBus import io.legado.app.constant.Status import io.legado.app.constant.Theme +import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource @@ -212,6 +213,7 @@ class AudioPlayActivity : launch { withContext(IO) { AudioPlay.book?.changeTo(book, toc) + appDb.bookDao.insert(book) } startActivity { putExtra("bookUrl", book.bookUrl) diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt index 4ea1acad5..4938728a8 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt @@ -78,7 +78,9 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) fun changeTo(source: BookSource, book: Book, toc: List) { execute { - AudioPlay.book = AudioPlay.book!!.changeTo(book, toc) + AudioPlay.book?.changeTo(book, toc) + appDb.bookDao.insert(book) + AudioPlay.book = book AudioPlay.bookSource = source appDb.bookChapterDao.insert(*toc.toTypedArray()) AudioPlay.upDurChapter(book) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 35069c8ec..f127f754b 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -178,18 +178,19 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } } - fun changeTo(source: BookSource, newBook: Book, toc: List) { + fun changeTo(source: BookSource, book: Book, toc: List) { changeSourceCoroutine?.cancel() changeSourceCoroutine = execute { bookSource = source - bookData.value!!.changeTo(newBook, toc) - bookData.postValue(newBook) - chapterListData.postValue(toc) + bookData.value?.changeTo(book, toc) if (inBookshelf) { + appDb.bookDao.insert(book) appDb.bookChapterDao.insert(*toc.toTypedArray()) } + bookData.postValue(book) + chapterListData.postValue(toc) }.onFinally { - postEvent(EventBus.SOURCE_CHANGED, newBook.bookUrl) + postEvent(EventBus.SOURCE_CHANGED, book.bookUrl) } } diff --git a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt index c404851e3..340363742 100644 --- a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt @@ -50,6 +50,7 @@ class BookshelfManageViewModel(application: Application) : BaseViewModel(applica .getOrNull()?.let { newBook -> val toc = WebBook.getChapterListAwait(this, source, newBook) book.changeTo(newBook, toc) + appDb.bookDao.insert(newBook) appDb.bookChapterDao.insert(*toc.toTypedArray()) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 431b73029..b19e7325b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -724,6 +724,7 @@ class ReadBookActivity : BaseReadBookActivity(), ReadAloud.stop(this) launch { ReadBook.book?.changeTo(book, toc) + appDb.bookDao.insert(book) } startActivity { putExtra("bookUrl", book.bookUrl) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 3293dba25..ccdf872e7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -195,7 +195,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { changeSourceCoroutine?.cancel() changeSourceCoroutine = execute { ReadBook.upMsg(context.getString(R.string.loading)) - ReadBook.book!!.changeTo(book, toc) + ReadBook.book?.changeTo(book, toc) val nextChapter = toc.getOrElse(book.durChapterIndex) { toc.first() } @@ -206,6 +206,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { bookChapter = toc[book.durChapterIndex], nextChapterUrl = nextChapter.url ) + appDb.bookDao.insert(book) appDb.bookChapterDao.insert(*toc.toTypedArray()) ReadBook.resetData(book) ReadBook.upMsg(null) From 18914f94a7e62208109622c284dbaf98d505df75 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 16:23:01 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index ccdf872e7..2f98e9704 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -211,13 +211,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ReadBook.resetData(book) ReadBook.upMsg(null) ReadBook.loadContent(resetPageOffset = true) - }.timeout(60000) - .onError { - context.toastOnUi("换源失败\n${it.localizedMessage}") - ReadBook.upMsg(null) - }.onFinally { - postEvent(EventBus.SOURCE_CHANGED, book.bookUrl) - } + }.onError { + context.toastOnUi("换源失败\n${it.localizedMessage}") + ReadBook.upMsg(null) + }.onFinally { + postEvent(EventBus.SOURCE_CHANGED, book.bookUrl) + } } /** From 465f61da80eb4438cb4349189c7c21e6e3c18b99 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 16:24:35 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 8293acfc7..1cee633c9 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,10 +11,11 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! -**2022/04/06** +**2022/04/07** * 实现epub的懒加载 by ag2s20150909 -* 去掉导入文件格式判断,总有人反馈txt无法导入 +* 解决txt无法导入 +* 优化换源 **2022/04/05** From d5e7d05e47b8448ef2d9faf29e0efc02c10a77c5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 20:32:58 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/info/BookInfoActivity.kt | 12 +++++++----- .../legado/app/ui/book/info/BookInfoViewModel.kt | 16 +++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 18872071e..0efdf63d5 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -270,7 +270,7 @@ class BookInfoActivity : showDialogFragment( ChangeCoverDialog(it.name, it.author) ) - } + } ?: toastOnUi("Book is null") } ivCover.setOnLongClickListener { viewModel.bookData.value?.getDisplayCover()?.let { path -> @@ -281,7 +281,7 @@ class BookInfoActivity : tvRead.setOnClickListener { viewModel.bookData.value?.let { readBook(it) - } + } ?: toastOnUi("Book is null") } tvShelf.setOnClickListener { if (viewModel.inBookshelf) { @@ -297,10 +297,12 @@ class BookInfoActivity : startActivity { putExtra("sourceUrl", it.origin) } - } + } ?: toastOnUi("Book is null") } tvChangeSource.setOnClickListener { - showDialogFragment(ChangeBookSourceDialog(viewModel.name, viewModel.author)) + viewModel.bookData.value?.let { book -> + showDialogFragment(ChangeBookSourceDialog(book.name, book.author)) + } ?: toastOnUi("Book is null") } tvTocView.setOnClickListener { if (!viewModel.inBookshelf) { @@ -318,7 +320,7 @@ class BookInfoActivity : showDialogFragment( GroupSelectDialog(it.group) ) - } + } ?: toastOnUi("Book is null") } tvAuthor.setOnClickListener { startActivity { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index f127f754b..9eeda4018 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -27,8 +27,6 @@ import kotlinx.coroutines.Dispatchers.IO class BookInfoViewModel(application: Application) : BaseViewModel(application) { val bookData = MutableLiveData() val chapterListData = MutableLiveData>() - var name = "" - var author = "" var durChapterIndex = 0 var inBookshelf = false var bookSource: BookSource? = null @@ -36,22 +34,22 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun initData(intent: Intent) { execute { - name = intent.getStringExtra("name") ?: "" - author = intent.getStringExtra("author") ?: "" + val name = intent.getStringExtra("name") ?: "" + val author = intent.getStringExtra("author") ?: "" val bookUrl = intent.getStringExtra("bookUrl") ?: "" appDb.bookDao.getBook(name, author)?.let { inBookshelf = true - setBook(it) + upBook(it) return@execute } if (bookUrl.isNotBlank()) { appDb.searchBookDao.getSearchBook(bookUrl)?.toBook()?.let { - setBook(it) + upBook(it) return@execute } } appDb.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let { - setBook(it) + upBook(it) return@execute } throw NoStackTraceException("未找到书籍") @@ -65,12 +63,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { val name = intent.getStringExtra("name") ?: "" val author = intent.getStringExtra("author") ?: "" appDb.bookDao.getBook(name, author)?.let { book -> - setBook(book) + upBook(book) } } } - private fun setBook(book: Book) { + private fun upBook(book: Book) { execute { durChapterIndex = book.durChapterIndex bookData.postValue(book)