diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 99f2c64c5..69aa284fd 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -16,6 +16,9 @@ interface BookSourceDao { @Query("select * from book_sources where exploreIsEnabled = 1 order by customOrder asc") fun observeFind(): DataSource.Factory + @get:Query("select * from book_sources order by customOrder asc") + val all: List + @Query("select * from book_sources where origin = :key") fun findByKey(key: String): BookSource? diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 021b8585c..f698fcb0c 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -8,6 +8,7 @@ import com.jayway.jsonpath.Option import io.legado.app.App import io.legado.app.constant.AppConst import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.ReplaceRule import io.legado.app.utils.* import org.jetbrains.anko.doAsync @@ -87,6 +88,32 @@ object Restore { context.toast("Unable to import books:\n${e.localizedMessage}") } + // Book source + val sourceFile = File(yuedu, "myBookSource.json") + val bookSources = mutableListOf() + if (shelfFile.exists()) try { + doAsync { + val items: List> = jsonPath.parse(sourceFile.readText()).read("$") + val existings = App.db.bookSourceDao().all.map { it.origin }.toSet() + for (item in items) { + val jsonItem = jsonPath.parse(item) + val source = BookSource() + source.origin = jsonItem.readString("bookSourceUrl") ?: "" + if (source.origin.isBlank()) continue + if (source.origin in existings) continue + source.name = jsonItem.readString("bookSourceName") ?: "" + source.group = jsonItem.readString("bookSourceGroup") ?: "" + source.loginUrl = jsonItem.readString("loginUrl") + + bookSources.add(source) + } + App.db.bookSourceDao().insert(*bookSources.toTypedArray()) + } + } catch (e: Exception) { + error(e.localizedMessage) + } + + // Replace rules val ruleFile = File(yuedu, "myBookReplaceRule.json") val replaceRules = mutableListOf()