From 51a6275a04aa8ec6ef39e9908d7415504edeef34 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 19:42:29 +0800 Subject: [PATCH] =?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/constant/AppConst.kt | 11 ++++------- .../main/java/io/legado/app/data/AppDatabase.kt | 17 +++++++++-------- .../app/ui/book/arrange/ArrangeBookActivity.kt | 16 ++++++++-------- .../legado/app/ui/book/cache/CacheActivity.kt | 8 ++++---- .../ui/main/bookshelf/books/BooksFragment.kt | 8 ++++---- 5 files changed, 29 insertions(+), 31 deletions(-) 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 d6bb81302..b841ec595 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -1,9 +1,6 @@ package io.legado.app.constant import android.annotation.SuppressLint -import io.legado.app.App -import io.legado.app.R -import io.legado.app.data.entities.BookGroup import java.text.SimpleDateFormat import javax.script.ScriptEngine import javax.script.ScriptEngineManager @@ -47,10 +44,10 @@ object AppConst { ) } - val bookGroupAll = BookGroup(-1, App.INSTANCE.getString(R.string.all)) - val bookGroupLocal = BookGroup(-2, App.INSTANCE.getString(R.string.local)) - val bookGroupAudio = BookGroup(-3, App.INSTANCE.getString(R.string.audio)) - val bookGroupNone = BookGroup(-4, App.INSTANCE.getString(R.string.no_group)) + const val bookGroupAllId = -1L + const val bookGroupLocalId = -2L + const val bookGroupAudioId = -3L + const val bookGroupNoneId = -4L const val notificationIdRead = 1144771 const val notificationIdAudio = 1144772 diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 262fe014d..af4b1fb7a 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -7,6 +7,7 @@ import androidx.room.RoomDatabase import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase import io.legado.app.App +import io.legado.app.constant.AppConst import io.legado.app.data.dao.* import io.legado.app.data.entities.* @@ -47,26 +48,26 @@ abstract class AppDatabase: RoomDatabase() { override fun onOpen(db: SupportSQLiteDatabase) { db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -1, '全部', -10 - where not exists (select * from book_groups where groupId = -1) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupAllId}, '全部', -10 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAllId}) """ ) db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -2, '本地', -9 - where not exists (select * from book_groups where groupId = -2) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupLocalId}, '本地', -9 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalId}) """ ) db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -3, '音频', -8 - where not exists (select * from book_groups where groupId = -3) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupAudioId}, '音频', -8 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAudioId}) """ ) db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -4, '未分组', -7 - where not exists (select * from book_groups where groupId = -4) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupNoneId}, '未分组', -7 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNoneId}) """ ) } 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/arrange/ArrangeBookActivity.kt index d850b2f36..c980fe30c 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -111,10 +111,10 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi booksLiveData?.removeObservers(this) booksLiveData = when (groupId) { - AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() - AppConst.bookGroupLocal.groupId -> App.db.bookDao().observeLocal() - AppConst.bookGroupAudio.groupId -> App.db.bookDao().observeAudio() - AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() + AppConst.bookGroupAllId -> App.db.bookDao().observeAll() + AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() + AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() + AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } booksLiveData?.observe(this, { list -> @@ -135,22 +135,22 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi .show(supportFragmentManager, "groupManage") R.id.menu_no_group -> { title_bar.subtitle = getString(R.string.no_group) - groupId = AppConst.bookGroupNone.groupId + groupId = AppConst.bookGroupNoneId initBookData() } R.id.menu_all -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupAll.groupId + groupId = AppConst.bookGroupAllId initBookData() } R.id.menu_local -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupLocal.groupId + groupId = AppConst.bookGroupLocalId initBookData() } R.id.menu_audio -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupAudio.groupId + groupId = AppConst.bookGroupAudioId initBookData() } else -> if (item.groupId == R.id.menu_group) { diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 0ae61f349..97a16813c 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -97,12 +97,12 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) } R.id.menu_no_group -> { title_bar.subtitle = getString(R.string.no_group) - groupId = AppConst.bookGroupNone.groupId + groupId = AppConst.bookGroupNoneId initBookData() } R.id.menu_all -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupAll.groupId + groupId = AppConst.bookGroupAllId initBookData() } else -> if (item.groupId == R.id.menu_group) { @@ -123,8 +123,8 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) private fun initBookData() { booksLiveData?.removeObservers(this) booksLiveData = when (groupId) { - AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() - AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() + AppConst.bookGroupAllId -> App.db.bookDao().observeAll() + AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } booksLiveData?.observe(this, { list -> diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 64aac5e6e..ebd3e8cad 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -102,10 +102,10 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), private fun upRecyclerData() { bookshelfLiveData?.removeObservers(this) bookshelfLiveData = when (groupId) { - AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() - AppConst.bookGroupLocal.groupId -> App.db.bookDao().observeLocal() - AppConst.bookGroupAudio.groupId -> App.db.bookDao().observeAudio() - AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() + AppConst.bookGroupAllId -> App.db.bookDao().observeAll() + AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() + AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() + AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } bookshelfLiveData?.observe(this, { list ->