From 6b94113a49087733c89cde445c3cf3707ed6523f Mon Sep 17 00:00:00 2001 From: Invinciblelee <1760316362@qq.com> Date: Wed, 22 May 2019 18:30:27 +0800 Subject: [PATCH 1/8] create BaseActivity --- app/build.gradle | 7 ++- .../java/io/legado/app/base/BaseActivity.kt | 55 +++++++++++++++++++ .../main/java/io/legado/app/base/README.md | 1 + .../java/io/legado/app/ui/widget/TitleBar.kt | 40 ++++++++++++++ app/src/main/res/layout/view_titlebar.xml | 16 ++++++ 5 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/io/legado/app/base/BaseActivity.kt create mode 100644 app/src/main/java/io/legado/app/base/README.md create mode 100644 app/src/main/java/io/legado/app/ui/widget/TitleBar.kt create mode 100644 app/src/main/res/layout/view_titlebar.xml diff --git a/app/build.gradle b/app/build.gradle index 5a4c99f24..22574a10c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,13 +36,14 @@ dependencies { implementation 'androidx.paging:paging-runtime:2.1.0' + //anko def anko_version = '0.10.8' implementation "org.jetbrains.anko:anko-sdk27:$anko_version" implementation "org.jetbrains.anko:anko-sdk27-listeners:$anko_version" - - + //协程 + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' -} \ No newline at end of file +} diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt new file mode 100644 index 000000000..45a4679a6 --- /dev/null +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -0,0 +1,55 @@ +package io.legado.app.base + +import android.os.Bundle +import android.view.MenuItem +import androidx.annotation.LayoutRes +import androidx.appcompat.app.AppCompatActivity + +abstract class BaseActivity : AppCompatActivity() { + + @LayoutRes + abstract fun getLayoutID(): Int + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(getLayoutID()) + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + item?.let { + if (it.itemId == android.R.id.home) { + supportFinishAfterTransition() + return true + } + } + return if (item == null) true else onCompatOptionsItemSelected(item) + } + + open fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + return true + } + + override fun setTitle(title: CharSequence?) { + supportActionBar?.let { + it.title = title + } + } + + override fun setTitle(titleId: Int) { + supportActionBar?.let { + it.setTitle(titleId) + } + } + + fun setSubTitle(subtitle: CharSequence?){ + supportActionBar?.let { + it.subtitle = subtitle; + } + } + + fun setSubTitle(subtitleId: Int){ + supportActionBar?.let { + it.setSubtitle(subtitleId) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/base/README.md b/app/src/main/java/io/legado/app/base/README.md new file mode 100644 index 000000000..d28e27909 --- /dev/null +++ b/app/src/main/java/io/legado/app/base/README.md @@ -0,0 +1 @@ +## 基类 \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt new file mode 100644 index 000000000..da7d6ba71 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -0,0 +1,40 @@ +package io.legado.app.ui.widget + +import android.content.Context +import android.util.AttributeSet +import android.widget.FrameLayout +import androidx.appcompat.app.AppCompatActivity +import io.legado.app.R +import kotlinx.android.synthetic.main.view_titlebar.view.* + +class TitleBar(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { + + init { + inflate(context, R.layout.view_titlebar, this) + } + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + attachToActivity() + } + + private fun attachToActivity(){ + val activity = getCompatActivity(context) + activity?.let { + activity.setSupportActionBar(toolbar) + activity.supportActionBar?.let { + it.setDisplayHomeAsUpEnabled(true) + } + } + } + + private fun getCompatActivity(context: Context?): AppCompatActivity? { + if (context == null) return null + return when (context) { + is AppCompatActivity -> context + is androidx.appcompat.view.ContextThemeWrapper -> getCompatActivity(context.baseContext) + is android.view.ContextThemeWrapper -> getCompatActivity(context.baseContext) + else -> null + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/view_titlebar.xml b/app/src/main/res/layout/view_titlebar.xml new file mode 100644 index 000000000..6f86e663a --- /dev/null +++ b/app/src/main/res/layout/view_titlebar.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file From 3bcd2bcddf34c74640be2d1324e8bd64c9e3f88f Mon Sep 17 00:00:00 2001 From: Invinciblelee <1760316362@qq.com> Date: Wed, 22 May 2019 18:33:16 +0800 Subject: [PATCH 2/8] create BaseActivity --- app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 18d6c561a..c11148349 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 @@ -22,7 +22,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte setSupportActionBar(toolbar) - fab.setOnClickListener { it.longSnackbar(R.string.action) } + fab.setOnClickListener { it.longSnackbar(R.string.app_name) } val toggle = ActionBarDrawerToggle( this, drawer_layout, toolbar, From 4e287449769970c54c3e2af29c77cda40b375f5e Mon Sep 17 00:00:00 2001 From: Antecer Date: Wed, 22 May 2019 19:02:26 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=90=AF=E7=94=A8dataBinding=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 89c0b7d53..1c6c7a570 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,6 +9,9 @@ androidExtensions { android { compileSdkVersion 28 + dataBinding { + enabled = true + } defaultConfig { applicationId "io.legado.app" minSdkVersion 21 From d5f242f8ab23d8ccd98af4c8eef6b686ba095b22 Mon Sep 17 00:00:00 2001 From: mabdc <747455334@qq.com> Date: Thu, 23 May 2019 01:17:56 +0800 Subject: [PATCH 4/8] branch --- app/src/main/java/io/legado/app/model/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/README.md b/app/src/main/java/io/legado/app/model/README.md index 3c6ca049c..a156e1dfc 100644 --- a/app/src/main/java/io/legado/app/model/README.md +++ b/app/src/main/java/io/legado/app/model/README.md @@ -1 +1 @@ -## 放置一些模块类 \ No newline at end of file +## 放置一些模块类 From d69880138e5bace99dcc81d0e301b635943287f9 Mon Sep 17 00:00:00 2001 From: GKF Date: Thu, 23 May 2019 09:50:10 +0800 Subject: [PATCH 5/8] 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 b0d684415c5fee0f2984374002946cfa9ad9a274 Mon Sep 17 00:00:00 2001 From: Antecer Date: Thu, 23 May 2019 11:15:59 +0800 Subject: [PATCH 6/8] =?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) From 10736d66d457ba3a7fc6f4860178c66fd606f263 Mon Sep 17 00:00:00 2001 From: GKF Date: Thu, 23 May 2019 12:16:18 +0800 Subject: [PATCH 7/8] descUrl --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index b6ad0ba40..6e71ae680 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -13,7 +13,7 @@ interface BookDao { @Query("SELECT * FROM books WHERE `group` = :group") fun observeByGroup(group: Int): DataSource.Factory - @Query("SELECT url FROM books WHERE `group` = :group") + @Query("SELECT descUrl FROM books WHERE `group` = :group") fun observeUrlsByGroup(group: Int): LiveData> } \ No newline at end of file From 2b11ac66647774b202d93dd9b7dc9ac608ce2577 Mon Sep 17 00:00:00 2001 From: Antecer Date: Thu, 23 May 2019 13:02:46 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0Book=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/Book.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 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 543bd5101..d9879a223 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 @@ -13,23 +13,23 @@ data class Book(@PrimaryKey var author: String? = null, // 作者名称(允许用户修改,适用于本地书籍) var tag: String? = null, // 分类信息(允许用户修改,适用于本地书籍) var coverUrl: String? = null, // 封面Url - var customCoverUrl: String? = null, // 自定义封面Url - var description: String? = null, // 简介内容 + 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 hasNewChapter: Boolean = false, // 最近一次更新书籍信息时是否发现新章节 var latestChapterTime: Long? = null, // 最近一次发现新章节的时间 - var lastUpdateChapters: Int = 0, // 最近一次发现新章节的数量 - var durChapterName: String = "", // 当前阅读的章节名称 - var durChapterIndex: Int = 0, // 当前阅读的章节分页索引 - var durChapterPage: Int = 0, // 当前阅读的章节总分页数 - var durChapterTime: Long = 0, // 最后一次阅读书籍的时间(打开正文的时间) + var latestCheckCount: Int = 0, // 最近一次发现新章节的数量 var totalChapterNum: Int = 0, // 书籍目录总数 - var hasNewChapter: Boolean = false, // 是否在最后一次更新书籍信息时找到新章节 - var allowUpdate: Boolean = true, // 是否允许阅读自动管理更新书籍信息 + var durChapterName: String = "", // 当前章节名称 + var durChapterIndex: Int = 0, // 当前章节索引 + var durChapterMark: Int = 0, // 当前阅读的进度(首行字符的索引位置) + var durChapterTime: Long = 0, // 最近一次阅读书籍的时间(打开正文的时间) + var canUpdate: Boolean = true, // 刷新书架时更新书籍信息 var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息) ) : Parcelable {