pull/433/head
gedoor 4 years ago
parent b2d6249cfc
commit 51a6275a04
  1. 11
      app/src/main/java/io/legado/app/constant/AppConst.kt
  2. 17
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  3. 16
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  4. 8
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  5. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

@ -1,9 +1,6 @@
package io.legado.app.constant package io.legado.app.constant
import android.annotation.SuppressLint 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 java.text.SimpleDateFormat
import javax.script.ScriptEngine import javax.script.ScriptEngine
import javax.script.ScriptEngineManager import javax.script.ScriptEngineManager
@ -47,10 +44,10 @@ object AppConst {
) )
} }
val bookGroupAll = BookGroup(-1, App.INSTANCE.getString(R.string.all)) const val bookGroupAllId = -1L
val bookGroupLocal = BookGroup(-2, App.INSTANCE.getString(R.string.local)) const val bookGroupLocalId = -2L
val bookGroupAudio = BookGroup(-3, App.INSTANCE.getString(R.string.audio)) const val bookGroupAudioId = -3L
val bookGroupNone = BookGroup(-4, App.INSTANCE.getString(R.string.no_group)) const val bookGroupNoneId = -4L
const val notificationIdRead = 1144771 const val notificationIdRead = 1144771
const val notificationIdAudio = 1144772 const val notificationIdAudio = 1144772

@ -7,6 +7,7 @@ import androidx.room.RoomDatabase
import androidx.room.migration.Migration import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.data.dao.* import io.legado.app.data.dao.*
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
@ -47,26 +48,26 @@ abstract class AppDatabase: RoomDatabase() {
override fun onOpen(db: SupportSQLiteDatabase) { override fun onOpen(db: SupportSQLiteDatabase) {
db.execSQL( db.execSQL(
""" """
insert into book_groups(groupId, groupName, 'order') select -1, '全部', -10 insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupAllId}, '全部', -10
where not exists (select * from book_groups where groupId = -1) where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAllId})
""" """
) )
db.execSQL( db.execSQL(
""" """
insert into book_groups(groupId, groupName, 'order') select -2, '本地', -9 insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupLocalId}, '本地', -9
where not exists (select * from book_groups where groupId = -2) where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalId})
""" """
) )
db.execSQL( db.execSQL(
""" """
insert into book_groups(groupId, groupName, 'order') select -3, '音频', -8 insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupAudioId}, '音频', -8
where not exists (select * from book_groups where groupId = -3) where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAudioId})
""" """
) )
db.execSQL( db.execSQL(
""" """
insert into book_groups(groupId, groupName, 'order') select -4, '未分组', -7 insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupNoneId}, '未分组', -7
where not exists (select * from book_groups where groupId = -4) where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNoneId})
""" """
) )
} }

@ -111,10 +111,10 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
booksLiveData?.removeObservers(this) booksLiveData?.removeObservers(this)
booksLiveData = booksLiveData =
when (groupId) { when (groupId) {
AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() AppConst.bookGroupAllId -> App.db.bookDao().observeAll()
AppConst.bookGroupLocal.groupId -> App.db.bookDao().observeLocal() AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal()
AppConst.bookGroupAudio.groupId -> App.db.bookDao().observeAudio() AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio()
AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao().observeByGroup(groupId)
} }
booksLiveData?.observe(this, { list -> booksLiveData?.observe(this, { list ->
@ -135,22 +135,22 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
.show(supportFragmentManager, "groupManage") .show(supportFragmentManager, "groupManage")
R.id.menu_no_group -> { R.id.menu_no_group -> {
title_bar.subtitle = getString(R.string.no_group) title_bar.subtitle = getString(R.string.no_group)
groupId = AppConst.bookGroupNone.groupId groupId = AppConst.bookGroupNoneId
initBookData() initBookData()
} }
R.id.menu_all -> { R.id.menu_all -> {
title_bar.subtitle = item.title title_bar.subtitle = item.title
groupId = AppConst.bookGroupAll.groupId groupId = AppConst.bookGroupAllId
initBookData() initBookData()
} }
R.id.menu_local -> { R.id.menu_local -> {
title_bar.subtitle = item.title title_bar.subtitle = item.title
groupId = AppConst.bookGroupLocal.groupId groupId = AppConst.bookGroupLocalId
initBookData() initBookData()
} }
R.id.menu_audio -> { R.id.menu_audio -> {
title_bar.subtitle = item.title title_bar.subtitle = item.title
groupId = AppConst.bookGroupAudio.groupId groupId = AppConst.bookGroupAudioId
initBookData() initBookData()
} }
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {

@ -97,12 +97,12 @@ class CacheActivity : VMBaseActivity<CacheViewModel>(R.layout.activity_download)
} }
R.id.menu_no_group -> { R.id.menu_no_group -> {
title_bar.subtitle = getString(R.string.no_group) title_bar.subtitle = getString(R.string.no_group)
groupId = AppConst.bookGroupNone.groupId groupId = AppConst.bookGroupNoneId
initBookData() initBookData()
} }
R.id.menu_all -> { R.id.menu_all -> {
title_bar.subtitle = item.title title_bar.subtitle = item.title
groupId = AppConst.bookGroupAll.groupId groupId = AppConst.bookGroupAllId
initBookData() initBookData()
} }
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
@ -123,8 +123,8 @@ class CacheActivity : VMBaseActivity<CacheViewModel>(R.layout.activity_download)
private fun initBookData() { private fun initBookData() {
booksLiveData?.removeObservers(this) booksLiveData?.removeObservers(this)
booksLiveData = when (groupId) { booksLiveData = when (groupId) {
AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() AppConst.bookGroupAllId -> App.db.bookDao().observeAll()
AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao().observeByGroup(groupId)
} }
booksLiveData?.observe(this, { list -> booksLiveData?.observe(this, { list ->

@ -102,10 +102,10 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private fun upRecyclerData() { private fun upRecyclerData() {
bookshelfLiveData?.removeObservers(this) bookshelfLiveData?.removeObservers(this)
bookshelfLiveData = when (groupId) { bookshelfLiveData = when (groupId) {
AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() AppConst.bookGroupAllId -> App.db.bookDao().observeAll()
AppConst.bookGroupLocal.groupId -> App.db.bookDao().observeLocal() AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal()
AppConst.bookGroupAudio.groupId -> App.db.bookDao().observeAudio() AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio()
AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao().observeByGroup(groupId)
} }
bookshelfLiveData?.observe(this, { list -> bookshelfLiveData?.observe(this, { list ->

Loading…
Cancel
Save