From 1c957e9627c8205eba2a1ad86c496d84012c8e4d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 20:34:28 +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 --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 13 ++++++++++--- .../java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../java/io/legado/app/data/entities/BookGroup.kt | 3 ++- .../legado/app/ui/book/group/GroupManageDialog.kt | 11 +++++++++++ .../app/ui/main/bookshelf/BookshelfFragment.kt | 2 +- app/src/main/res/layout/item_group_manage.xml | 6 ++++++ 6 files changed, 33 insertions(+), 5 deletions(-) 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 af4b1fb7a..82407528f 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -17,7 +17,7 @@ import io.legado.app.data.entities.* ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class], - version = 20, + version = 21, exportSchema = true ) abstract class AppDatabase: RoomDatabase() { @@ -38,7 +38,8 @@ abstract class AppDatabase: RoomDatabase() { migration_15_17, migration_17_18, migration_18_19, - migration_19_20 + migration_19_20, + migration_20_21 ) .allowMainThreadQueries() .addCallback(dbCallback) @@ -143,11 +144,17 @@ abstract class AppDatabase: RoomDatabase() { database.execSQL("ALTER TABLE readRecordNew RENAME TO readRecord") } } - private val migration_19_20 = object: Migration(19, 20) { + private val migration_19_20 = object : Migration(19, 20) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("ALTER TABLE book_sources ADD bookSourceComment TEXT") } } + + private val migration_20_21 = object : Migration(20, 21) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE book_groups ADD show INTEGER NOT NULL DEFAULT 1") + } + } } abstract fun bookDao(): BookDao diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index 815c6cbda..a7d29d750 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -16,6 +16,9 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> + @Query("SELECT * FROM book_groups where show > 0 ORDER BY `order`") + fun liveDataShow(): LiveData> + @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") fun liveDataSelect(): LiveData> diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index 2d2c68698..20a8263a3 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -11,5 +11,6 @@ data class BookGroup( @PrimaryKey val groupId: Long = 0b1, var groupName: String, - var order: Int = 0 + var order: Int = 0, + var show: Boolean = true ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 6eac527d4..66fb7ebec 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.widget.Toolbar +import androidx.core.view.isGone import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -184,6 +185,9 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener holder.itemView.apply { setBackgroundColor(context.backgroundColor) tv_group.text = item.groupName + sw_show.isChecked = item.show + tv_del.isGone = item.groupId < 0 + sw_show.isGone = item.groupId >= 0 } } @@ -191,6 +195,13 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener holder.itemView.apply { tv_edit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } tv_del.onClick { getItem(holder.layoutPosition)?.let { deleteGroup(it) } } + sw_show.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed) { + getItem(holder.layoutPosition)?.let { + viewModel.upGroup(it.copy(show = isChecked)) + } + } + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 1647f5a86..cd967ad33 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -105,7 +105,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b private fun initBookGroupData() { bookGroupLiveData?.removeObservers(viewLifecycleOwner) - bookGroupLiveData = App.db.bookGroupDao().liveDataAll() + bookGroupLiveData = App.db.bookGroupDao().liveDataShow() bookGroupLiveData?.observe(viewLifecycleOwner, { viewModel.checkGroup(it) upGroup(it) diff --git a/app/src/main/res/layout/item_group_manage.xml b/app/src/main/res/layout/item_group_manage.xml index 763a19acd..9aa18e82a 100644 --- a/app/src/main/res/layout/item_group_manage.xml +++ b/app/src/main/res/layout/item_group_manage.xml @@ -29,4 +29,10 @@ android:padding="8dp" android:text="@string/delete" /> + + \ No newline at end of file