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
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

@ -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})
"""
)
}

@ -111,10 +111,10 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(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<ArrangeBookViewModel>(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) {

@ -97,12 +97,12 @@ class CacheActivity : VMBaseActivity<CacheViewModel>(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<CacheViewModel>(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 ->

@ -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 ->

Loading…
Cancel
Save