This commit is contained in:
kunfei 2023-06-16 16:52:03 +08:00
parent e071f6cfdf
commit ad904f660b
6 changed files with 26 additions and 22 deletions

View File

@ -1,7 +1,6 @@
package io.legado.app.data package io.legado.app.data
import android.content.ContentValues import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteDatabase
import androidx.room.AutoMigration import androidx.room.AutoMigration
import androidx.room.Database import androidx.room.Database
@ -17,7 +16,12 @@ import splitties.init.appCtx
import java.util.* import java.util.*
val appDb by lazy { 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( @Database(
@ -82,17 +86,9 @@ abstract class AppDatabase : RoomDatabase() {
companion object { companion object {
private const val DATABASE_NAME = "legado.db" const val DATABASE_NAME = "legado.db"
fun createDatabase(context: Context) = Room val dbCallback = object : Callback() {
.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() {
override fun onCreate(db: SupportSQLiteDatabase) { override fun onCreate(db: SupportSQLiteDatabase) {
db.setLocale(Locale.CHINESE) db.setLocale(Locale.CHINESE)

View File

@ -67,7 +67,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private val groups = linkedSetOf<String>() private val groups = linkedSetOf<String>()
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
private var sort = Sort.Default private var sort = Sort.Default
private var sortAscending = true override var sortAscending = true
private set
private var snackBar: Snackbar? = null private var snackBar: Snackbar? = null
private var isPaused = false private var isPaused = false
private var searchKey: String? = null private var searchKey: String? = null

View File

@ -24,7 +24,7 @@ import io.legado.app.utils.ColorUtils
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.visible import io.legado.app.utils.visible
import java.util.* import java.util.Collections
class BookSourceAdapter(context: Context, val callBack: CallBack) : class BookSourceAdapter(context: Context, val callBack: CallBack) :
@ -290,7 +290,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
sortNumberSet.add(it.customOrder) sortNumberSet.add(it.customOrder)
} }
if (movedItems.size > sortNumberSet.size) { if (movedItems.size > sortNumberSet.size) {
callBack.upOrder(getItems()) callBack.upOrder(getItems().mapIndexed { index, bookSourcePart ->
bookSourcePart.customOrder = if (callBack.sortAscending) index else -index
bookSourcePart
})
} else { } else {
callBack.upOrder(movedItems.toList()) callBack.upOrder(movedItems.toList())
} }
@ -324,6 +327,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} }
interface CallBack { interface CallBack {
val sortAscending: Boolean
fun del(bookSource: BookSourcePart) fun del(bookSource: BookSourcePart)
fun edit(bookSource: BookSourcePart) fun edit(bookSource: BookSourcePart)
fun toTop(bookSource: BookSourcePart) fun toTop(bookSource: BookSourcePart)

View File

@ -9,12 +9,12 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.BookSourcePart import io.legado.app.data.entities.BookSourcePart
import io.legado.app.data.entities.toBookSource import io.legado.app.data.entities.toBookSource
import io.legado.app.help.config.SourceConfig import io.legado.app.help.config.SourceConfig
import io.legado.app.ui.book.source.manage.BookSourceActivity.Sort
import io.legado.app.utils.* import io.legado.app.utils.*
import splitties.init.appCtx import splitties.init.appCtx
import java.io.BufferedOutputStream import java.io.BufferedOutputStream
import java.io.File import java.io.File
import java.io.FileOutputStream 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>) { fun upOrder(items: List<BookSourcePart>) {
if (items.isEmpty()) return if (items.isEmpty()) return
execute { execute {
val firstSortNumber = items[0].customOrder appDb.bookSourceDao.upOrder(items)
val array = items.mapIndexed { index, bookSource ->
bookSource.copy(customOrder = firstSortNumber + index)
}
appDb.bookSourceDao.upOrder(array)
} }
} }

View File

@ -49,6 +49,7 @@ object RhinoClassShutter : ClassShutter {
"java.security.AccessController", "java.security.AccessController",
"java.nio.file.Paths", "java.nio.file.Paths",
"java.nio.file.Files", "java.nio.file.Files",
"io.legado.app.data.AppDatabase",
"io.legado.app.data.AppDatabaseKt", "io.legado.app.data.AppDatabaseKt",
"io.legado.app.utils.ContextExtensionsKt", "io.legado.app.utils.ContextExtensionsKt",
"android.content.Intent", "android.content.Intent",

View File

@ -52,7 +52,13 @@ object RhinoWrapFactory : WrapFactory() {
): Scriptable? { ): Scriptable? {
val classShutter = RhinoClassShutter val classShutter = RhinoClassShutter
return when (javaObject) { 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 -> { else -> {
val name = javaObject.javaClass.name val name = javaObject.javaClass.name
if (classShutter.visibleToScripts(name)) { if (classShutter.visibleToScripts(name)) {