Merge pull request #26 from gedoor/master

Sync upstream
pull/27/head^2
atbest 6 years ago committed by GitHub
commit beefe18994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/.gitignore
  2. 8
      app/build.gradle
  3. 55
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  4. 1
      app/src/main/java/io/legado/app/base/README.md
  5. 2
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  6. 47
      app/src/main/java/io/legado/app/data/entities/Book.kt
  7. 5
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  8. 5
      app/src/main/java/io/legado/app/ui/main/MainModel.kt
  9. 9
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  10. 40
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  11. 16
      app/src/main/res/layout/view_titlebar.xml

1
app/.gitignore vendored

@ -1 +1,2 @@
/build /build
/schemas

@ -9,6 +9,9 @@ androidExtensions {
android { android {
compileSdkVersion 28 compileSdkVersion 28
dataBinding {
enabled = true
}
defaultConfig { defaultConfig {
applicationId "io.legado.app" applicationId "io.legado.app"
minSdkVersion 21 minSdkVersion 21
@ -59,11 +62,12 @@ dependencies {
implementation 'androidx.paging:paging-runtime:2.1.0' implementation 'androidx.paging:paging-runtime:2.1.0'
//anko
def anko_version = '0.10.8' def anko_version = '0.10.8'
implementation "org.jetbrains.anko:anko-sdk27:$anko_version" implementation "org.jetbrains.anko:anko-sdk27:$anko_version"
implementation "org.jetbrains.anko:anko-sdk27-listeners:$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' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test:runner:1.1.1'

@ -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)
}
}
}

@ -13,7 +13,7 @@ interface BookDao {
@Query("SELECT * FROM books WHERE `group` = :group") @Query("SELECT * FROM books WHERE `group` = :group")
fun observeByGroup(group: Int): DataSource.Factory<Int, Book> fun observeByGroup(group: Int): DataSource.Factory<Int, Book>
@Query("SELECT url FROM books WHERE `group` = :group") @Query("SELECT descUrl FROM books WHERE `group` = :group")
fun observeUrlsByGroup(group: Int): LiveData<List<String>> fun observeUrlsByGroup(group: Int): LiveData<List<String>>
} }

@ -5,28 +5,33 @@ import androidx.room.*
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@Entity(tableName = "books", @Entity(tableName = "books", indices = [(Index(value = ["descUrl"]))])
indices = [(Index(value = ["url"]))])
data class Book(@PrimaryKey data class Book(@PrimaryKey
var url: String = "", var descUrl: String = "", // 详情页Url(本地书源存储完整文件路径)
var name: String = "", var sourceId: Int = -1, // 书源规则id(默认-1,表示本地书籍)
var tag: String = "", var name: String = "", // 书籍名称(允许用户修改,适用于本地书籍)
var author: String? = null, var author: String? = null, // 作者名称(允许用户修改,适用于本地书籍)
var coverUrl: String? = null, var tag: String? = null, // 分类信息(允许用户修改,适用于本地书籍)
var userCoverUrl: String? = null, var coverUrl: String? = null, // 封面Url
var introduction: String? = null, var customCoverUrl: String? = null, // 自定义封面Url(允许用户修改,适用于网络和本地书籍)
var charset: String? = null, var description: String? = null, // 简介内容(允许用户修改,适用于网络和本地书籍)
var type: Int = 0, // 0: text, 1: audio var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍)
var group: Int = 0, // fenqu var type: Int = 0, // 0: 文本读物, 1: 有声读物
var latestChapterName: String? = null, var group: Int = 0, // 自定义分组索引号
var lastUpdateTime: Long? = null, var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var latestChapterTime: Long? = null, var latestChapterName: String? = null, // 最新章节
var durChapterIndex: Int = 0, var lastCheckTime: Long? = null, // 最近一次更新书籍信息的时间
var durChapterPage: Int = 0, var hasNewChapter: Boolean = false, // 最近一次更新书籍信息时是否发现新章节
var totalChapterNum: Int = 0, var latestChapterTime: Long? = null, // 最近一次发现新章节的时间
var hasNewChapter: Boolean = false, var latestCheckCount: Int = 0, // 最近一次发现新章节的数量
var canUpdate: Boolean = true var totalChapterNum: Int = 0, // 书籍目录总数
) : Parcelable { var durChapterName: String = "", // 当前章节名称
var durChapterIndex: Int = 0, // 当前章节索引
var durChapterMark: Int = 0, // 当前阅读的进度(首行字符的索引位置)
var durChapterTime: Long = 0, // 最近一次阅读书籍的时间(打开正文的时间)
var canUpdate: Boolean = true, // 刷新书架时更新书籍信息
var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息)
) : Parcelable {
fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0) fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0)

@ -7,6 +7,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.GravityCompat import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.ViewModelProviders
import com.google.android.material.navigation.NavigationView import com.google.android.material.navigation.NavigationView
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.longSnackbar import io.legado.app.utils.longSnackbar
@ -19,10 +20,9 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
fab.setOnClickListener { it.longSnackbar(R.string.action) } fab.setOnClickListener { it.longSnackbar(R.string.app_name) }
val toggle = ActionBarDrawerToggle( val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, this, drawer_layout, toolbar,
@ -33,6 +33,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
toggle.syncState() toggle.syncState()
nav_view.setNavigationItemSelectedListener(this) nav_view.setNavigationItemSelectedListener(this)
val mainViewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
} }
override fun onBackPressed() { override fun onBackPressed() {

@ -0,0 +1,5 @@
package io.legado.app.ui.main
class MainModel {
}

@ -0,0 +1,9 @@
package io.legado.app.ui.main
import android.app.Application
import androidx.lifecycle.AndroidViewModel
class MainViewModel(application: Application) : AndroidViewModel(application) {
}

@ -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
}
}
}

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</com.google.android.material.appbar.AppBarLayout>
Loading…
Cancel
Save