pull/433/head
gedoor 4 years ago
parent 8ffc204ae2
commit 1c957e9627
  1. 13
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 3
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/BookGroup.kt
  4. 11
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  5. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  6. 6
      app/src/main/res/layout/item_group_manage.xml

@ -17,7 +17,7 @@ import io.legado.app.data.entities.*
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class], RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class],
version = 20, version = 21,
exportSchema = true exportSchema = true
) )
abstract class AppDatabase: RoomDatabase() { abstract class AppDatabase: RoomDatabase() {
@ -38,7 +38,8 @@ abstract class AppDatabase: RoomDatabase() {
migration_15_17, migration_15_17,
migration_17_18, migration_17_18,
migration_18_19, migration_18_19,
migration_19_20 migration_19_20,
migration_20_21
) )
.allowMainThreadQueries() .allowMainThreadQueries()
.addCallback(dbCallback) .addCallback(dbCallback)
@ -143,11 +144,17 @@ abstract class AppDatabase: RoomDatabase() {
database.execSQL("ALTER TABLE readRecordNew RENAME TO readRecord") 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) { override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE book_sources ADD bookSourceComment TEXT") 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 abstract fun bookDao(): BookDao

@ -16,6 +16,9 @@ interface BookGroupDao {
@Query("SELECT * FROM book_groups ORDER BY `order`") @Query("SELECT * FROM book_groups ORDER BY `order`")
fun liveDataAll(): LiveData<List<BookGroup>> fun liveDataAll(): LiveData<List<BookGroup>>
@Query("SELECT * FROM book_groups where show > 0 ORDER BY `order`")
fun liveDataShow(): LiveData<List<BookGroup>>
@Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`")
fun liveDataSelect(): LiveData<List<BookGroup>> fun liveDataSelect(): LiveData<List<BookGroup>>

@ -11,5 +11,6 @@ data class BookGroup(
@PrimaryKey @PrimaryKey
val groupId: Long = 0b1, val groupId: Long = 0b1,
var groupName: String, var groupName: String,
var order: Int = 0 var order: Int = 0,
var show: Boolean = true
) : Parcelable ) : Parcelable

@ -10,6 +10,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.EditText import android.widget.EditText
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.view.isGone
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -184,6 +185,9 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
holder.itemView.apply { holder.itemView.apply {
setBackgroundColor(context.backgroundColor) setBackgroundColor(context.backgroundColor)
tv_group.text = item.groupName 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 { holder.itemView.apply {
tv_edit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } tv_edit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } }
tv_del.onClick { getItem(holder.layoutPosition)?.let { deleteGroup(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))
}
}
}
} }
} }

@ -105,7 +105,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private fun initBookGroupData() { private fun initBookGroupData() {
bookGroupLiveData?.removeObservers(viewLifecycleOwner) bookGroupLiveData?.removeObservers(viewLifecycleOwner)
bookGroupLiveData = App.db.bookGroupDao().liveDataAll() bookGroupLiveData = App.db.bookGroupDao().liveDataShow()
bookGroupLiveData?.observe(viewLifecycleOwner, { bookGroupLiveData?.observe(viewLifecycleOwner, {
viewModel.checkGroup(it) viewModel.checkGroup(it)
upGroup(it) upGroup(it)

@ -29,4 +29,10 @@
android:padding="8dp" android:padding="8dp"
android:text="@string/delete" /> android:text="@string/delete" />
<io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/sw_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save