From d69880138e5bace99dcc81d0e301b635943287f9 Mon Sep 17 00:00:00 2001 From: GKF Date: Thu, 23 May 2019 09:50:10 +0800 Subject: [PATCH 1/4] ViewModel --- app/.gitignore | 1 + app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 3 ++- app/src/main/java/io/legado/app/ui/main/MainModel.kt | 5 +++++ app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 9 +++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/legado/app/ui/main/MainModel.kt create mode 100644 app/src/main/java/io/legado/app/ui/main/MainViewModel.kt diff --git a/app/.gitignore b/app/.gitignore index 796b96d1c..3f2a4d9f6 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,2 @@ /build +/schemas diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index c11148349..2b0156d5d 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -7,6 +7,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.app.AppCompatActivity import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout +import androidx.lifecycle.ViewModelProviders import com.google.android.material.navigation.NavigationView import io.legado.app.R import io.legado.app.utils.longSnackbar @@ -19,7 +20,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - setSupportActionBar(toolbar) fab.setOnClickListener { it.longSnackbar(R.string.app_name) } @@ -33,6 +33,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte toggle.syncState() nav_view.setNavigationItemSelectedListener(this) + val mainViewModel = ViewModelProviders.of(this).get(MainViewModel::class.java) } override fun onBackPressed() { diff --git a/app/src/main/java/io/legado/app/ui/main/MainModel.kt b/app/src/main/java/io/legado/app/ui/main/MainModel.kt new file mode 100644 index 000000000..86da567f6 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/MainModel.kt @@ -0,0 +1,5 @@ +package io.legado.app.ui.main + +class MainModel { + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt new file mode 100644 index 000000000..82a9146c5 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -0,0 +1,9 @@ +package io.legado.app.ui.main + +import android.app.Application +import androidx.lifecycle.AndroidViewModel + +class MainViewModel(application: Application) : AndroidViewModel(application) { + + +} \ No newline at end of file From 15c3eb8dd27f94496032fe27dd1dbceca489a273 Mon Sep 17 00:00:00 2001 From: atbest Date: Wed, 22 May 2019 22:42:50 -0400 Subject: [PATCH 2/4] Added database entities --- .../java/io/legado/app/data/AppDatabase.kt | 5 +++- .../java/io/legado/app/data/entities/Book.kt | 5 ++-- .../io/legado/app/data/entities/Chapter.kt | 23 +++++++++++++++++++ .../legado/app/data/entities/ReplaceRule.kt | 23 +++++++++++++++++++ .../java/io/legado/app/data/entities/Rule.kt | 5 ++++ .../io/legado/app/data/entities/Source.kt | 2 ++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/Chapter.kt create mode 100644 app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt create mode 100644 app/src/main/java/io/legado/app/data/entities/Rule.kt create mode 100644 app/src/main/java/io/legado/app/data/entities/Source.kt diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 71cb9dbb1..5fb47987f 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -8,9 +8,12 @@ import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase import io.legado.app.data.dao.BookDao import io.legado.app.data.entities.Book +import io.legado.app.data.entities.Chapter +import io.legado.app.data.entities.ReplaceRule +import javax.xml.transform.Source -@Database(entities = [Book::class], version = 1, exportSchema = true) +@Database(entities = [Book::class, Chapter::class, ReplaceRule::class, Source::class], version = 1, exportSchema = true) // @TypeConverters(Converters::class) abstract class AppDatabase : RoomDatabase() { diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 800ea42d9..f51e80159 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -1,6 +1,5 @@ package io.legado.app.data.entities -import android.annotation.SuppressLint import android.os.Parcelable import androidx.room.* import kotlinx.android.parcel.Parcelize @@ -14,7 +13,7 @@ data class Book(@PrimaryKey var tag: String = "", var author: String? = null, var coverUrl: String? = null, - var customCoverUrl: String? = null, + var userCoverUrl: String? = null, var introduction: String? = null, var charset: String? = null, var type: Int = 0, // 0: text, 1: audio @@ -26,7 +25,7 @@ data class Book(@PrimaryKey var durChapterPage: Int = 0, var totalChapterNum: Int = 0, var hasNewChapter: Boolean = false, - var allowUpdate: Boolean = true + var canUpdate: Boolean = true ) : Parcelable { fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0) diff --git a/app/src/main/java/io/legado/app/data/entities/Chapter.kt b/app/src/main/java/io/legado/app/data/entities/Chapter.kt new file mode 100644 index 000000000..c34838a1f --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/Chapter.kt @@ -0,0 +1,23 @@ +package io.legado.app.data.entities + +import android.os.Parcelable +import androidx.room.Entity +import androidx.room.Index +import androidx.room.PrimaryKey +import kotlinx.android.parcel.Parcelize + + +@Parcelize +@Entity(tableName = "chapters", + indices = [(Index(value = ["url"]))]) +data class Chapter(@PrimaryKey + var url: String = "", + var name: String = "", + var bookUrl: String = "", + var index: Int = 0, + var ResourceUrl: String? = null, + var tag: String? = null, + var start: Long? = null, + var end: Long? = null +) : Parcelable + diff --git a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt new file mode 100644 index 000000000..9c6d6b5b6 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt @@ -0,0 +1,23 @@ +package io.legado.app.data.entities + +import android.os.Parcelable +import androidx.room.Entity +import androidx.room.Index +import androidx.room.PrimaryKey +import kotlinx.android.parcel.Parcelize + +@Parcelize +@Entity(tableName = "replace_rules", + indices = [(Index(value = ["id"]))]) +data class ReplaceRule(@PrimaryKey + val id: Int = 0, + val summary: String? = null, + val pattern: String? = null, + val replacement: String? = null, + val scope: String? = null, + val isEnabled: Boolean? = null, + val isRegex: Boolean? = null, + val order: Int = 0 +) : Parcelable + + diff --git a/app/src/main/java/io/legado/app/data/entities/Rule.kt b/app/src/main/java/io/legado/app/data/entities/Rule.kt new file mode 100644 index 000000000..e83807c87 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/Rule.kt @@ -0,0 +1,5 @@ +package io.legado.app.data.entities + +class Rule { + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/Source.kt b/app/src/main/java/io/legado/app/data/entities/Source.kt new file mode 100644 index 000000000..feecd7295 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/Source.kt @@ -0,0 +1,2 @@ +package io.legado.app.data.entities + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f0dca604..e2bf2033a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,4 +13,5 @@ Tools Share Send + Replace with your own action From 227a6397b855b6568d05e9ab64e5e7b8f37b0b49 Mon Sep 17 00:00:00 2001 From: atbest Date: Wed, 22 May 2019 22:43:35 -0400 Subject: [PATCH 3/4] Added database entities --- app/src/main/java/io/legado/app/data/entities/Chapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Chapter.kt b/app/src/main/java/io/legado/app/data/entities/Chapter.kt index c34838a1f..b5ba5bf93 100644 --- a/app/src/main/java/io/legado/app/data/entities/Chapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/Chapter.kt @@ -15,7 +15,7 @@ data class Chapter(@PrimaryKey var name: String = "", var bookUrl: String = "", var index: Int = 0, - var ResourceUrl: String? = null, + var resourceUrl: String? = null, var tag: String? = null, var start: Long? = null, var end: Long? = null From b0d684415c5fee0f2984374002946cfa9ad9a274 Mon Sep 17 00:00:00 2001 From: Antecer Date: Thu, 23 May 2019 11:15:59 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=B8=BAbooks=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/Book.kt | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index f51e80159..543bd5101 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -5,28 +5,33 @@ import androidx.room.* import kotlinx.android.parcel.Parcelize @Parcelize -@Entity(tableName = "books", - indices = [(Index(value = ["url"]))]) +@Entity(tableName = "books", indices = [(Index(value = ["descUrl"]))]) data class Book(@PrimaryKey - var url: String = "", - var name: String = "", - var tag: String = "", - var author: String? = null, - var coverUrl: String? = null, - var userCoverUrl: String? = null, - var introduction: String? = null, - var charset: String? = null, - var type: Int = 0, // 0: text, 1: audio - var group: Int = 0, // fenqu - var latestChapterName: String? = null, - var lastUpdateTime: Long? = null, - var latestChapterTime: Long? = null, - var durChapterIndex: Int = 0, - var durChapterPage: Int = 0, - var totalChapterNum: Int = 0, - var hasNewChapter: Boolean = false, - var canUpdate: Boolean = true - ) : Parcelable { + var descUrl: String = "", // 详情页Url(本地书源存储完整文件路径) + var sourceId: Int = -1, // 书源规则id(默认-1,表示本地书籍) + var name: String = "", // 书籍名称(允许用户修改,适用于本地书籍) + var author: String? = null, // 作者名称(允许用户修改,适用于本地书籍) + var tag: String? = null, // 分类信息(允许用户修改,适用于本地书籍) + var coverUrl: String? = null, // 封面Url + var customCoverUrl: String? = null, // 自定义封面Url + var description: String? = null, // 简介内容 + var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍) + var type: Int = 0, // 0: 文本读物, 1: 有声读物 + var group: Int = 0, // 自定义分组索引号 + var tocUrl: String = "", // 目录页Url (toc=table of Contents) + var latestChapterName: String? = null, // 最新章节 + var lastCheckTime: Long? = null, // 最近一次更新书籍信息的时间 + var latestChapterTime: Long? = null, // 最近一次发现新章节的时间 + var lastUpdateChapters: Int = 0, // 最近一次发现新章节的数量 + var durChapterName: String = "", // 当前阅读的章节名称 + var durChapterIndex: Int = 0, // 当前阅读的章节分页索引 + var durChapterPage: Int = 0, // 当前阅读的章节总分页数 + var durChapterTime: Long = 0, // 最后一次阅读书籍的时间(打开正文的时间) + var totalChapterNum: Int = 0, // 书籍目录总数 + var hasNewChapter: Boolean = false, // 是否在最后一次更新书籍信息时找到新章节 + var allowUpdate: Boolean = true, // 是否允许阅读自动管理更新书籍信息 + var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息) +) : Parcelable { fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0)