Skip to content

Commit

Permalink
πŸš€ Flexible text parsing and storing system
Browse files Browse the repository at this point in the history
Pros:
* Removed text update (now it is always updated and parsed from the file each time)
* Removed text storage (smaller app size)
* Dramatically sped up loading in Browse (10 books in ~1s)

Cons:
* Longer Reader loading time (~3x, partly fixable)
* More dependency on the file (fixable)

Resolves: #134
  • Loading branch information
Acclorite committed Dec 30, 2024
1 parent aa65779 commit 3853727
Show file tree
Hide file tree
Showing 70 changed files with 290 additions and 1,605 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"formatVersion": 1,
"database": {
"version": 8,
"identityHash": "095e8b560edd2bf64b64720308b686c4",
"entities": [
{
"tableName": "BookEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT NOT NULL, `author` TEXT, `description` TEXT, `filePath` TEXT NOT NULL, `scrollIndex` INTEGER NOT NULL, `scrollOffset` INTEGER NOT NULL, `progress` REAL NOT NULL, `image` TEXT, `category` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "author",
"columnName": "author",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "filePath",
"columnName": "filePath",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "scrollIndex",
"columnName": "scrollIndex",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "scrollOffset",
"columnName": "scrollOffset",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "progress",
"columnName": "progress",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "image",
"columnName": "image",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "category",
"columnName": "category",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "HistoryEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `bookId` INTEGER NOT NULL, `time` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "bookId",
"columnName": "bookId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "time",
"columnName": "time",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "ColorPresetEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `backgroundColor` INTEGER NOT NULL, `fontColor` INTEGER NOT NULL, `isSelected` INTEGER NOT NULL, `order` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "backgroundColor",
"columnName": "backgroundColor",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "fontColor",
"columnName": "fontColor",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isSelected",
"columnName": "isSelected",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "order",
"columnName": "order",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "FavoriteDirectoryEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`path` TEXT NOT NULL, PRIMARY KEY(`path`))",
"fields": [
{
"fieldPath": "path",
"columnName": "path",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"path"
]
},
"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, '095e8b560edd2bf64b64720308b686c4')"
]
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
package ua.acclorite.book_story.data.local.dto

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import ua.acclorite.book_story.data.local.converter.ChapterConverter
import ua.acclorite.book_story.domain.library.category.Category
import ua.acclorite.book_story.domain.reader.Chapter

@Entity
@TypeConverters(ChapterConverter::class)
data class BookEntity(
@PrimaryKey(true) val id: Int = 0,
val title: String,
val author: String?,
val description: String?,
val textPath: String,
@ColumnInfo(defaultValue = "[]")
val chapters: List<Chapter>,
val filePath: String,
val scrollIndex: Int,
val scrollOffset: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ interface BookDao {

/* ------ BookEntity ------------------------ */
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertBooks(
books: List<BookEntity>
suspend fun insertBook(
book: BookEntity
)

@Query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import ua.acclorite.book_story.data.local.dto.HistoryEntity
ColorPresetEntity::class,
FavoriteDirectoryEntity::class,
],
version = 7,
version = 8,
autoMigrations = [
AutoMigration(1, 2),
AutoMigration(2, 3),
AutoMigration(3, 4, spec = DatabaseHelper.MIGRATION_3_4::class),
AutoMigration(4, 5),
AutoMigration(5, 6),
AutoMigration(6, 7),
AutoMigration(7, 8, spec = DatabaseHelper.MIGRATION_7_8::class)
],
exportSchema = true
)
Expand Down Expand Up @@ -83,4 +84,8 @@ object DatabaseHelper {
)
}
}

@DeleteColumn("BookEntity", "textPath")
@DeleteColumn("BookEntity", "chapters")
class MIGRATION_7_8 : AutoMigrationSpec
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ class BookMapperImpl @Inject constructor() : BookMapper {
scrollOffset = book.scrollOffset,
progress = book.progress,
author = book.author.getAsString(),
textPath = book.textPath,
description = book.description,
image = book.coverImage?.toString(),
category = book.category,
chapters = book.chapters
category = book.category
)
}

Expand All @@ -36,12 +34,10 @@ class BookMapperImpl @Inject constructor() : BookMapper {
scrollIndex = bookEntity.scrollIndex,
scrollOffset = bookEntity.scrollOffset,
progress = bookEntity.progress,
textPath = bookEntity.textPath,
filePath = bookEntity.filePath,
lastOpened = null,
category = bookEntity.category,
coverImage = if (bookEntity.image != null) Uri.parse(bookEntity.image) else null,
chapters = bookEntity.chapters
coverImage = if (bookEntity.image != null) Uri.parse(bookEntity.image) else null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class EpubFileParser @Inject constructor() : FileParser {
title = title,
author = author,
description = description,
textPath = "",
scrollIndex = 0,
scrollOffset = 0,
progress = 0f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class Fb2FileParser @Inject constructor() : FileParser {
title = title,
author = author,
description = descriptionFromFile,
textPath = "",
scrollIndex = 0,
scrollOffset = 0,
progress = 0f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class HtmlFileParser @Inject constructor() : FileParser {
title = title,
author = UIText.StringResource(R.string.unknown_author),
description = null,
textPath = "",
scrollIndex = 0,
scrollOffset = 0,
progress = 0f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class PdfFileParser @Inject constructor(
title = title,
author = author,
description = description,
textPath = "",
scrollIndex = 0,
scrollOffset = 0,
progress = 0f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class TxtFileParser @Inject constructor() : FileParser {
title = title,
author = author,
description = null,
textPath = "",
scrollIndex = 0,
scrollOffset = 0,
progress = 0f,
Expand Down
Loading

0 comments on commit 3853727

Please sign in to comment.