Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to import external epub books #155

Merged
merged 6 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'dagger.hilt.android.plugin'
id 'com.google.devtools.ksp'
id "com.mikepenz.aboutlibraries.plugin" version "10.5.2"
id "com.mikepenz.aboutlibraries.plugin" version "11.1.3"
}

apply plugin: 'com.mikepenz.aboutlibraries.plugin'
Expand Down Expand Up @@ -88,14 +88,14 @@ aboutLibraries {


dependencies {
def composeBom = platform('androidx.compose:compose-bom:2024.04.00')
def composeBom = platform('androidx.compose:compose-bom:2024.04.01')
implementation composeBom
androidTestImplementation composeBom

// Android core components.
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.core:core-ktx:1.13.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
implementation 'androidx.activity:activity-compose:1.8.2'
implementation 'androidx.activity:activity-compose:1.9.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0"
implementation "androidx.navigation:navigation-compose:2.7.7"
// Jetpack compose.
Expand All @@ -108,7 +108,7 @@ dependencies {
// Accompanist compose.
implementation "com.google.accompanist:accompanist-systemuicontroller:0.28.0"
// Material icons.
implementation 'androidx.compose.material:material-icons-extended:1.6.4'
implementation 'androidx.compose.material:material-icons-extended:1.6.6'
// Material theme for main activity.
implementation 'com.google.android.material:material:1.11.0'
// Android 12+ splash API.
Expand All @@ -131,12 +131,12 @@ dependencies {
// Jsoup HTML Parser.
implementation "org.jsoup:jsoup:1.17.2"
// Lottie animations.
implementation "com.airbnb.android:lottie-compose:4.1.0"
// DataStore Preferences
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation "com.airbnb.android:lottie-compose:6.4.0"
// DataStore Preferences.
implementation("androidx.datastore:datastore-preferences:1.1.0")
// Open Source Libraries Screen.
implementation "com.mikepenz:aboutlibraries-core:10.5.2"
implementation "com.mikepenz:aboutlibraries-compose:10.5.2"
implementation "com.mikepenz:aboutlibraries-core:11.1.3"
implementation "com.mikepenz:aboutlibraries-compose:11.1.3"
// Swipe actions.
implementation "me.saket.swipe:swipe:1.2.0"
// Crash Handler.
Expand Down
109 changes: 109 additions & 0 deletions app/schemas/com.starry.myne.database.MyneDatabase/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "c623113d83374eb42b85d35d0ce0118e",
"entities": [
{
"tableName": "book_library",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`book_id` INTEGER NOT NULL, `title` TEXT NOT NULL, `authors` TEXT NOT NULL, `file_path` TEXT NOT NULL, `created_at` INTEGER NOT NULL, `is_external_book` INTEGER NOT NULL DEFAULT false, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "bookId",
"columnName": "book_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "authors",
"columnName": "authors",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "filePath",
"columnName": "file_path",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createdAt",
"columnName": "created_at",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isExternalBook",
"columnName": "is_external_book",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "false"
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "reader_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`book_id` INTEGER NOT NULL, `last_chapter_index` INTEGER NOT NULL, `last_chapter_offset` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "bookId",
"columnName": "book_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastChapterIndex",
"columnName": "last_chapter_index",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastChapterOffset",
"columnName": "last_chapter_offset",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c623113d83374eb42b85d35d0ce0118e')"
]
}
}
109 changes: 109 additions & 0 deletions app/schemas/com.starry.myne.database.MyneDatabase/4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"formatVersion": 1,
"database": {
"version": 4,
"identityHash": "73dddecebf5b45bc31c3d462376c1251",
"entities": [
{
"tableName": "book_library",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`book_id` INTEGER NOT NULL, `title` TEXT NOT NULL, `authors` TEXT NOT NULL, `file_path` TEXT NOT NULL, `created_at` INTEGER NOT NULL, `is_external_book` INTEGER NOT NULL DEFAULT false, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "bookId",
"columnName": "book_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "authors",
"columnName": "authors",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "filePath",
"columnName": "file_path",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createdAt",
"columnName": "created_at",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isExternalBook",
"columnName": "is_external_book",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "false"
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "reader_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`library_item_id` INTEGER NOT NULL, `last_chapter_index` INTEGER NOT NULL, `last_chapter_offset` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "libraryItemId",
"columnName": "library_item_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastChapterIndex",
"columnName": "last_chapter_index",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastChapterOffset",
"columnName": "last_chapter_offset",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '73dddecebf5b45bc31c3d462376c1251')"
]
}
}
14 changes: 11 additions & 3 deletions app/src/main/java/com/starry/myne/database/MyneDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import com.starry.myne.database.library.LibraryDao
import com.starry.myne.database.library.LibraryItem
import com.starry.myne.database.reader.ReaderDao
Expand All @@ -29,9 +30,12 @@ import com.starry.myne.utils.Constants

@Database(
entities = [LibraryItem::class, ReaderData::class],
version = 2,
version = 4,
exportSchema = true,
autoMigrations = [AutoMigration(from = 1, to = 2)]
autoMigrations = [
AutoMigration(from = 1, to = 2),
AutoMigration(from = 2, to = 3),
]
)
abstract class MyneDatabase : RoomDatabase() {

Expand All @@ -40,6 +44,10 @@ abstract class MyneDatabase : RoomDatabase() {

companion object {

private val migration3to4 = Migration(3, 4) { database ->
database.execSQL("ALTER TABLE reader_table RENAME COLUMN book_id TO library_item_id")
}

@Volatile
private var INSTANCE: MyneDatabase? = null

Expand All @@ -54,7 +62,7 @@ abstract class MyneDatabase : RoomDatabase() {
context.applicationContext,
MyneDatabase::class.java,
Constants.DATABASE_NAME
).build()
).addMigrations(migration3to4).build()
INSTANCE = instance
// return instance
instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ interface LibraryDao {
@Query("SELECT * FROM book_library ORDER BY id ASC")
fun getAllItems(): LiveData<List<LibraryItem>>

@Query("SELECT * FROM book_library WHERE id = :id")
fun getItemById(id: Int): LibraryItem?

@Query("SELECT * FROM book_library WHERE book_id = :bookId")
fun getItemById(bookId: Int): LibraryItem?
fun getItemByBookId(bookId: Int): LibraryItem?
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ data class LibraryItem(
@ColumnInfo(name = "file_path")
val filePath: String,
@ColumnInfo(name = "created_at")
val createdAt: Long
val createdAt: Long,
// Added in database schema version 3
@ColumnInfo(name = "is_external_book", defaultValue = "false")
val isExternalBook: Boolean = false
) {
@PrimaryKey(autoGenerate = true)
var id: Int = 0
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ interface ReaderDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(readerData: ReaderData)

@Query("DELETE FROM reader_table WHERE book_id = :bookId")
fun delete(bookId: Int)
@Query("DELETE FROM reader_table WHERE library_item_id = :libraryItemId")
fun delete(libraryItemId: Int)

@Query(
"UPDATE reader_table SET "
+ "last_chapter_index = :lastChapterIndex,"
+ "last_chapter_offset = :lastChapterOffset"
+ " WHERE book_id = :bookId"
+ " WHERE library_item_id = :libraryItemId"
)
fun update(bookId: Int, lastChapterIndex: Int, lastChapterOffset: Int)
fun update(libraryItemId: Int, lastChapterIndex: Int, lastChapterOffset: Int)

@Query("SELECT * FROM reader_table WHERE book_id = :bookId")
fun getReaderData(bookId: Int): ReaderData?
@Query("SELECT * FROM reader_table WHERE library_item_id = :libraryItemId")
fun getReaderData(libraryItemId: Int): ReaderData?

@Query("SELECT * FROM reader_table WHERE book_id = :bookId")
fun getReaderDataAsFlow(bookId: Int): Flow<ReaderData?>
@Query("SELECT * FROM reader_table WHERE library_item_id = :libraryItemId")
fun getReaderDataAsFlow(libraryItemId: Int): Flow<ReaderData?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.room.PrimaryKey

@Entity(tableName = "reader_table")
data class ReaderData(
@ColumnInfo(name = "book_id") val bookId: Int,
@ColumnInfo(name = "library_item_id") val libraryItemId: Int,
@ColumnInfo(name = "last_chapter_index") val lastChapterIndex: Int,
@ColumnInfo(name = "last_chapter_offset") val lastChapterOffset: Int
) {
Expand Down
Loading
Loading