pull/90/head^2
kunfei 5 years ago
parent 8501b6a35f
commit 8db7c3943f
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 4
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  3. 2
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  4. 3
      app/src/main/java/io/legado/app/data/dao/RssStarDao.kt
  5. 50
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  6. 2
      app/src/main/java/io/legado/app/web/controller/BookshelfController.kt

@ -45,7 +45,7 @@ interface BookDao {
val hasUpdateBooks: List<Book>
@get:Query("SELECT * FROM books")
val allBooks: List<Book>
val all: List<Book>
@get:Query("SELECT * FROM books where type = 0 ORDER BY durChapterTime DESC limit 1")
val lastReadBook: Book?

@ -19,8 +19,8 @@ interface BookGroupDao {
@get:Query("SELECT MAX(`order`) FROM book_groups")
val maxOrder: Int
@Query("SELECT * FROM book_groups ORDER BY `order`")
fun all(): List<BookGroup>
@get:Query("SELECT * FROM book_groups ORDER BY `order`")
val all: List<BookGroup>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookGroup: BookGroup)

@ -32,4 +32,6 @@ interface RssArticleDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insertRecord(vararg rssReadRecord: RssReadRecord)
}

@ -7,6 +7,9 @@ import io.legado.app.data.entities.RssStar
@Dao
interface RssStarDao {
@get:Query("select * from rssStars order by starTime desc")
val all: List<RssStar>
@Query("select * from rssStars where origin = :origin and link = :link")
fun get(origin: String, link: String): RssStar?

@ -36,6 +36,7 @@ object Backup {
"bookGroup.json",
"bookSource.json",
"rssSource.json",
"rssStar.json",
"replaceRule.json",
ReadBookConfig.readConfigFileName,
"config.xml"
@ -44,41 +45,13 @@ object Backup {
suspend fun backup(context: Context, uri: Uri?) {
withContext(IO) {
App.db.bookDao().allBooks.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
FileUtils.createFileIfNotExist(backupPath + File.separator + "bookshelf.json")
.writeText(json)
}
}
App.db.bookGroupDao().all().let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
FileUtils.createFileIfNotExist(backupPath + File.separator + "bookGroup.json")
.writeText(json)
}
}
App.db.bookSourceDao().all.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
FileUtils.createFileIfNotExist(backupPath + File.separator + "bookSource.json")
.writeText(json)
}
}
App.db.rssSourceDao().all.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
FileUtils.createFileIfNotExist(backupPath + File.separator + "rssSource.json")
.writeText(json)
}
}
App.db.replaceRuleDao().all.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
FileUtils.createFileIfNotExist(backupPath + File.separator + "replaceRule.json")
.writeText(json)
}
}
writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath)
writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath)
writeListToJson(App.db.bookSourceDao().all, "bookSource.json", backupPath)
writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath)
writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath)
writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath)
GSON.toJson(ReadBookConfig.configList)?.let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.readConfigFileName)
.writeText(it)
@ -106,6 +79,13 @@ object Backup {
}
}
private fun writeListToJson(list: List<Any>, fileName: String, path: String) {
if (list.isNotEmpty()) {
val json = GSON.toJson(list)
FileUtils.createFileIfNotExist(path + File.separator + fileName).writeText(json)
}
}
private fun copyBackup(context: Context, uri: Uri) {
DocumentFile.fromTreeUri(context, uri)?.let { treeDoc ->
for (fileName in backupFileNames) {

@ -13,7 +13,7 @@ class BookshelfController {
val bookshelf: ReturnData
get() {
val books = App.db.bookDao().allBooks
val books = App.db.bookDao().all
val returnData = ReturnData()
return if (books.isEmpty()) {
returnData.setErrorMsg("还没有添加小说")

Loading…
Cancel
Save