mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
e071f6cfdf
commit
ad904f660b
|
@ -1,7 +1,6 @@
|
|||
package io.legado.app.data
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
|
@ -17,7 +16,12 @@ import splitties.init.appCtx
|
|||
import java.util.*
|
||||
|
||||
val appDb by lazy {
|
||||
AppDatabase.createDatabase(appCtx)
|
||||
Room.databaseBuilder(appCtx, AppDatabase::class.java, AppDatabase.DATABASE_NAME)
|
||||
.fallbackToDestructiveMigrationFrom(1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
.addMigrations(*DatabaseMigrations.migrations)
|
||||
.allowMainThreadQueries()
|
||||
.addCallback(AppDatabase.dbCallback)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Database(
|
||||
|
@ -82,17 +86,9 @@ abstract class AppDatabase : RoomDatabase() {
|
|||
|
||||
companion object {
|
||||
|
||||
private const val DATABASE_NAME = "legado.db"
|
||||
const val DATABASE_NAME = "legado.db"
|
||||
|
||||
fun createDatabase(context: Context) = Room
|
||||
.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
|
||||
.fallbackToDestructiveMigrationFrom(1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
.addMigrations(*DatabaseMigrations.migrations)
|
||||
.allowMainThreadQueries()
|
||||
.addCallback(dbCallback)
|
||||
.build()
|
||||
|
||||
private val dbCallback = object : Callback() {
|
||||
val dbCallback = object : Callback() {
|
||||
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
db.setLocale(Locale.CHINESE)
|
||||
|
|
|
@ -67,7 +67,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||
private val groups = linkedSetOf<String>()
|
||||
private var groupMenu: SubMenu? = null
|
||||
private var sort = Sort.Default
|
||||
private var sortAscending = true
|
||||
override var sortAscending = true
|
||||
private set
|
||||
private var snackBar: Snackbar? = null
|
||||
private var isPaused = false
|
||||
private var searchKey: String? = null
|
||||
|
|
|
@ -24,7 +24,7 @@ import io.legado.app.utils.ColorUtils
|
|||
import io.legado.app.utils.invisible
|
||||
import io.legado.app.utils.startActivity
|
||||
import io.legado.app.utils.visible
|
||||
import java.util.*
|
||||
import java.util.Collections
|
||||
|
||||
|
||||
class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
||||
|
@ -290,7 +290,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
|||
sortNumberSet.add(it.customOrder)
|
||||
}
|
||||
if (movedItems.size > sortNumberSet.size) {
|
||||
callBack.upOrder(getItems())
|
||||
callBack.upOrder(getItems().mapIndexed { index, bookSourcePart ->
|
||||
bookSourcePart.customOrder = if (callBack.sortAscending) index else -index
|
||||
bookSourcePart
|
||||
})
|
||||
} else {
|
||||
callBack.upOrder(movedItems.toList())
|
||||
}
|
||||
|
@ -324,6 +327,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
|||
}
|
||||
|
||||
interface CallBack {
|
||||
val sortAscending: Boolean
|
||||
fun del(bookSource: BookSourcePart)
|
||||
fun edit(bookSource: BookSourcePart)
|
||||
fun toTop(bookSource: BookSourcePart)
|
||||
|
|
|
@ -9,12 +9,12 @@ import io.legado.app.data.entities.BookSource
|
|||
import io.legado.app.data.entities.BookSourcePart
|
||||
import io.legado.app.data.entities.toBookSource
|
||||
import io.legado.app.help.config.SourceConfig
|
||||
import io.legado.app.ui.book.source.manage.BookSourceActivity.Sort
|
||||
import io.legado.app.utils.*
|
||||
import splitties.init.appCtx
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import io.legado.app.ui.book.source.manage.BookSourceActivity.Sort
|
||||
|
||||
/**
|
||||
* 书源管理数据修改
|
||||
|
@ -60,11 +60,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
|||
fun upOrder(items: List<BookSourcePart>) {
|
||||
if (items.isEmpty()) return
|
||||
execute {
|
||||
val firstSortNumber = items[0].customOrder
|
||||
val array = items.mapIndexed { index, bookSource ->
|
||||
bookSource.copy(customOrder = firstSortNumber + index)
|
||||
}
|
||||
appDb.bookSourceDao.upOrder(array)
|
||||
appDb.bookSourceDao.upOrder(items)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ object RhinoClassShutter : ClassShutter {
|
|||
"java.security.AccessController",
|
||||
"java.nio.file.Paths",
|
||||
"java.nio.file.Files",
|
||||
"io.legado.app.data.AppDatabase",
|
||||
"io.legado.app.data.AppDatabaseKt",
|
||||
"io.legado.app.utils.ContextExtensionsKt",
|
||||
"android.content.Intent",
|
||||
|
|
|
@ -52,7 +52,13 @@ object RhinoWrapFactory : WrapFactory() {
|
|||
): Scriptable? {
|
||||
val classShutter = RhinoClassShutter
|
||||
return when (javaObject) {
|
||||
is ClassLoader, is Class<*>, is Member, is android.content.Context -> null
|
||||
is ClassLoader,
|
||||
is Class<*>,
|
||||
is Member,
|
||||
is android.content.Context -> {
|
||||
null
|
||||
}
|
||||
|
||||
else -> {
|
||||
val name = javaObject.javaClass.name
|
||||
if (classShutter.visibleToScripts(name)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user