From b40f9de6037d8a686f3dabb66280ce282da9198d Mon Sep 17 00:00:00 2001 From: atbest Date: Wed, 22 May 2019 06:09:40 -0400 Subject: [PATCH] Added room database and book entity --- app/build.gradle | 6 ++++ .../java/io/legado/app/data/entities/Book.kt | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/src/main/java/io/legado/app/data/entities/Book.kt diff --git a/app/build.gradle b/app/build.gradle index 5a4c99f24..80a899412 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,12 @@ dependencies { implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' + kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0' + + implementation 'androidx.room:room-runtime:2.0.0' + kapt 'androidx.room:room-compiler:2.0.0' + implementation 'androidx.paging:paging-runtime:2.1.0' def anko_version = '0.10.8' 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 new file mode 100644 index 000000000..8082605ab --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -0,0 +1,33 @@ +package io.legado.app.data.entities + +import android.os.Parcelable +import androidx.room.* +import kotlinx.android.parcel.Parcelize +import java.util.* + +@Parcelize +@Entity(tableName = "books", + indices = [(Index(value = ["url"]))]) +data class Book(@PrimaryKey + var url: String = "", + var name: String = "", + var tag: String = "", + var author: String? = null, + var coverUrl: String? = null, + var customCoverUrl: String? = null, + var introduction: String? = null, + var charset: String? = null, + var type: Int = 0, // 0: text, 1: audio + var latestChapterName: String? = null, + var lastUpdateTime: Date? = null, + var latestChapterTime: Date? = null, + var durChapterIndex: Int = 0, + var durChapterPage: Int = 0, + var totalChapterNum: Int = 0, + var hasNewChapter: Boolean = false, + var allowUpdate: Boolean = true + ) : Parcelable { + + fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0) + +} \ No newline at end of file