优化
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,7 @@ 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.*
|
||||||
import io.legado.app.help.DefaultData
|
import io.legado.app.help.DefaultData
|
||||||
|
import org.intellij.lang.annotations.Language
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ val appDb by lazy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
version = 62,
|
version = 63,
|
||||||
exportSchema = true,
|
exportSchema = true,
|
||||||
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
|
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
|
||||||
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
|
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
|
||||||
@@ -46,7 +47,8 @@ val appDb by lazy {
|
|||||||
AutoMigration(from = 58, to = 59),
|
AutoMigration(from = 58, to = 59),
|
||||||
AutoMigration(from = 59, to = 60),
|
AutoMigration(from = 59, to = 60),
|
||||||
AutoMigration(from = 60, to = 61),
|
AutoMigration(from = 60, to = 61),
|
||||||
AutoMigration(from = 61, to = 62)
|
AutoMigration(from = 61, to = 62),
|
||||||
|
AutoMigration(from = 62, to = 63)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
abstract class AppDatabase : RoomDatabase() {
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
@@ -91,40 +93,64 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onOpen(db: SupportSQLiteDatabase) {
|
override fun onOpen(db: SupportSQLiteDatabase) {
|
||||||
db.execSQL(
|
@Language("sql")
|
||||||
"""insert into book_groups(groupId, groupName, 'order', show)
|
val insertBookGroupAllSql = """
|
||||||
|
insert into book_groups(groupId, groupName, 'order', show)
|
||||||
select ${AppConst.bookGroupAllId}, '全部', -10, 1
|
select ${AppConst.bookGroupAllId}, '全部', -10, 1
|
||||||
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAllId})"""
|
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAllId})
|
||||||
)
|
""".trimIndent()
|
||||||
db.execSQL(
|
db.execSQL(insertBookGroupAllSql)
|
||||||
"""insert into book_groups(groupId, groupName, 'order', show)
|
@Language("sql")
|
||||||
select ${AppConst.bookGroupLocalId}, '本地', -9, 1
|
val insertBookGroupLocalSql = """
|
||||||
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalId})"""
|
insert into book_groups(groupId, groupName, 'order', enableRefresh, show)
|
||||||
)
|
select ${AppConst.bookGroupLocalId}, '本地', -9, 0, 1
|
||||||
db.execSQL(
|
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalId})
|
||||||
"""insert into book_groups(groupId, groupName, 'order', show)
|
""".trimIndent()
|
||||||
|
db.execSQL(insertBookGroupLocalSql)
|
||||||
|
@Language("sql")
|
||||||
|
val insertBookGroupMusicSql = """
|
||||||
|
insert into book_groups(groupId, groupName, 'order', show)
|
||||||
select ${AppConst.bookGroupAudioId}, '音频', -8, 1
|
select ${AppConst.bookGroupAudioId}, '音频', -8, 1
|
||||||
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAudioId})"""
|
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAudioId})
|
||||||
)
|
""".trimIndent()
|
||||||
db.execSQL(
|
db.execSQL(insertBookGroupMusicSql)
|
||||||
"""insert into book_groups(groupId, groupName, 'order', show)
|
@Language("sql")
|
||||||
|
val insertBookGroupNetNoneGroupSql = """
|
||||||
|
insert into book_groups(groupId, groupName, 'order', show)
|
||||||
select ${AppConst.bookGroupNetNoneId}, '网络未分组', -7, 1
|
select ${AppConst.bookGroupNetNoneId}, '网络未分组', -7, 1
|
||||||
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNetNoneId})"""
|
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNetNoneId})
|
||||||
)
|
""".trimIndent()
|
||||||
db.execSQL(
|
db.execSQL(insertBookGroupNetNoneGroupSql)
|
||||||
"""insert into book_groups(groupId, groupName, 'order', show)
|
@Language("sql")
|
||||||
|
val insertBookGroupLocalNoneGroupSql = """
|
||||||
|
insert into book_groups(groupId, groupName, 'order', show)
|
||||||
select ${AppConst.bookGroupLocalNoneId}, '本地未分组', -6, 0
|
select ${AppConst.bookGroupLocalNoneId}, '本地未分组', -6, 0
|
||||||
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalNoneId})"""
|
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalNoneId})
|
||||||
)
|
""".trimIndent()
|
||||||
db.execSQL(
|
db.execSQL(insertBookGroupLocalNoneGroupSql)
|
||||||
"""insert into book_groups(groupId, groupName, 'order', show)
|
@Language("sql")
|
||||||
|
val insertBookGroupErrorSql = """
|
||||||
|
insert into book_groups(groupId, groupName, 'order', show)
|
||||||
select ${AppConst.bookGroupErrorId}, '更新失败', -1, 1
|
select ${AppConst.bookGroupErrorId}, '更新失败', -1, 1
|
||||||
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupErrorId})"""
|
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupErrorId})
|
||||||
)
|
""".trimIndent()
|
||||||
db.execSQL("update book_sources set loginUi = null where loginUi = 'null'")
|
db.execSQL(insertBookGroupErrorSql)
|
||||||
db.execSQL("update rssSources set loginUi = null where loginUi = 'null'")
|
@Language("sql")
|
||||||
db.execSQL("update httpTTS set loginUi = null where loginUi = 'null'")
|
val upBookSourceLoginUiSql =
|
||||||
db.execSQL("update httpTTS set concurrentRate = '0' where loginUi is null")
|
"update book_sources set loginUi = null where loginUi = 'null'"
|
||||||
|
db.execSQL(upBookSourceLoginUiSql)
|
||||||
|
@Language("sql")
|
||||||
|
val upRssSourceLoginUiSql =
|
||||||
|
"update rssSources set loginUi = null where loginUi = 'null'"
|
||||||
|
db.execSQL(upRssSourceLoginUiSql)
|
||||||
|
@Language("sql")
|
||||||
|
val upHttpTtsLoginUiSql =
|
||||||
|
"update httpTTS set loginUi = null where loginUi = 'null'"
|
||||||
|
db.execSQL(upHttpTtsLoginUiSql)
|
||||||
|
@Language("sql")
|
||||||
|
val upHttpTtsConcurrentRateSql =
|
||||||
|
"update httpTTS set concurrentRate = '0' where concurrentRate is null"
|
||||||
|
db.execSQL(upHttpTtsConcurrentRateSql)
|
||||||
db.query("select * from keyboardAssists order by serialNo").use {
|
db.query("select * from keyboardAssists order by serialNo").use {
|
||||||
if (it.count == 0) {
|
if (it.count == 0) {
|
||||||
DefaultData.keyboardAssists.forEach { keyboardAssist ->
|
DefaultData.keyboardAssists.forEach { keyboardAssist ->
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ data class BookGroup(
|
|||||||
var groupName: String,
|
var groupName: String,
|
||||||
var cover: String? = null,
|
var cover: String? = null,
|
||||||
var order: Int = 0,
|
var order: Int = 0,
|
||||||
|
@ColumnInfo(defaultValue = "1")
|
||||||
|
var enableRefresh: Boolean = true,
|
||||||
|
@ColumnInfo(defaultValue = "1")
|
||||||
var show: Boolean = true,
|
var show: Boolean = true,
|
||||||
@ColumnInfo(defaultValue = "-1")
|
@ColumnInfo(defaultValue = "-1")
|
||||||
var bookSort: Int = -1
|
var bookSort: Int = -1
|
||||||
@@ -51,9 +54,10 @@ data class BookGroup(
|
|||||||
return other.groupId == groupId
|
return other.groupId == groupId
|
||||||
&& other.groupName == groupName
|
&& other.groupName == groupName
|
||||||
&& other.cover == cover
|
&& other.cover == cover
|
||||||
&& other.order == order
|
|
||||||
&& other.show == show
|
|
||||||
&& other.bookSort == bookSort
|
&& other.bookSort == bookSort
|
||||||
|
&& other.enableRefresh == enableRefresh
|
||||||
|
&& other.show == show
|
||||||
|
&& other.order == order
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
|
|||||||
return POSITION_NONE
|
return POSITION_NONE
|
||||||
}
|
}
|
||||||
val bookSort = group.getRealBookSort()
|
val bookSort = group.getRealBookSort()
|
||||||
|
fragment.setEnableRefresh(group.enableRefresh)
|
||||||
if (fragment.bookSort != bookSort) {
|
if (fragment.bookSort != bookSort) {
|
||||||
fragment.upBookSort(bookSort)
|
fragment.upBookSort(bookSort)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
bundle.putInt("position", position)
|
bundle.putInt("position", position)
|
||||||
bundle.putLong("groupId", group.groupId)
|
bundle.putLong("groupId", group.groupId)
|
||||||
bundle.putInt("bookSort", group.getRealBookSort())
|
bundle.putInt("bookSort", group.getRealBookSort())
|
||||||
|
bundle.putBoolean("enableRefresh", group.enableRefresh)
|
||||||
arguments = bundle
|
arguments = bundle
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +78,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
position = it.getInt("position", 0)
|
position = it.getInt("position", 0)
|
||||||
groupId = it.getLong("groupId", -1)
|
groupId = it.getLong("groupId", -1)
|
||||||
bookSort = it.getInt("bookSort", 0)
|
bookSort = it.getInt("bookSort", 0)
|
||||||
|
binding.refreshLayout.isEnabled = it.getBoolean("enableRefresh", true)
|
||||||
}
|
}
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
upRecyclerData()
|
upRecyclerData()
|
||||||
@@ -123,6 +125,10 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setEnableRefresh(enableRefresh: Boolean) {
|
||||||
|
binding.refreshLayout.isEnabled = enableRefresh
|
||||||
|
}
|
||||||
|
|
||||||
private fun upRecyclerData() {
|
private fun upRecyclerData() {
|
||||||
booksFlowJob?.cancel()
|
booksFlowJob?.cancel()
|
||||||
booksFlowJob = launch {
|
booksFlowJob = launch {
|
||||||
|
|||||||
@@ -114,11 +114,13 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
|||||||
private fun initBooksData() {
|
private fun initBooksData() {
|
||||||
if (groupId == -100L) {
|
if (groupId == -100L) {
|
||||||
binding.titleBar.title = getString(R.string.bookshelf)
|
binding.titleBar.title = getString(R.string.bookshelf)
|
||||||
|
binding.refreshLayout.isEnabled = true
|
||||||
} else {
|
} else {
|
||||||
bookGroups.forEach {
|
bookGroups.firstOrNull {
|
||||||
if (groupId == it.groupId) {
|
groupId == it.groupId
|
||||||
binding.titleBar.title = "${getString(R.string.bookshelf)}(${it.groupName})"
|
}?.let {
|
||||||
}
|
binding.titleBar.title = "${getString(R.string.bookshelf)}(${it.groupName})"
|
||||||
|
binding.refreshLayout.isEnabled = it.enableRefresh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
booksFlowJob?.cancel()
|
booksFlowJob?.cancel()
|
||||||
|
|||||||
Reference in New Issue
Block a user