Initial commit
This commit is contained in:
commit
6072b2ba29
844 changed files with 220532 additions and 0 deletions
126
app/src/main/java/com/aryan/reader/data/RecentFileItem.kt
Normal file
126
app/src/main/java/com/aryan/reader/data/RecentFileItem.kt
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
// RecentFileItem.kt
|
||||
package com.aryan.reader.data
|
||||
|
||||
import android.net.Uri
|
||||
import com.aryan.reader.FileType
|
||||
import androidx.core.net.toUri
|
||||
|
||||
data class RecentFileItem(
|
||||
val bookId: String,
|
||||
val uriString: String?,
|
||||
val type: FileType,
|
||||
val displayName: String,
|
||||
val timestamp: Long,
|
||||
val coverImagePath: String? = null,
|
||||
val title: String? = null,
|
||||
val author: String? = null,
|
||||
val lastChapterIndex: Int? = null,
|
||||
val lastPage: Int? = null,
|
||||
val lastPositionCfi: String? = null,
|
||||
val locatorBlockIndex: Int? = null,
|
||||
val locatorCharOffset: Int? = null,
|
||||
val progressPercentage: Float? = null,
|
||||
val isRecent: Boolean = true,
|
||||
val isAvailable: Boolean = true,
|
||||
val lastModifiedTimestamp: Long = 0L,
|
||||
val isDeleted: Boolean = false,
|
||||
val bookmarksJson: String? = null,
|
||||
val sourceFolderUri: String? = null
|
||||
) {
|
||||
fun getUri(): Uri? = uriString?.toUri()
|
||||
}
|
||||
|
||||
fun RecentFileEntity.toRecentFileItem(): RecentFileItem {
|
||||
return RecentFileItem(
|
||||
bookId = this.bookId,
|
||||
uriString = this.uriString,
|
||||
type = this.type,
|
||||
displayName = this.displayName,
|
||||
timestamp = this.timestamp,
|
||||
coverImagePath = this.coverImagePath,
|
||||
title = this.title,
|
||||
author = this.author,
|
||||
lastChapterIndex = this.lastChapterIndex,
|
||||
locatorBlockIndex = this.locatorBlockIndex,
|
||||
locatorCharOffset = this.locatorCharOffset,
|
||||
lastPage = this.lastPage,
|
||||
lastPositionCfi = this.lastPositionCfi,
|
||||
progressPercentage = this.progressPercentage,
|
||||
isRecent = this.isRecent,
|
||||
isAvailable = this.isAvailable,
|
||||
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
||||
isDeleted = this.isDeleted,
|
||||
bookmarksJson = this.bookmarks,
|
||||
sourceFolderUri = this.sourceFolderUri
|
||||
)
|
||||
}
|
||||
|
||||
fun RecentFileItem.toRecentFileEntity(): RecentFileEntity {
|
||||
return RecentFileEntity(
|
||||
bookId = this.bookId,
|
||||
uriString = this.uriString,
|
||||
type = this.type,
|
||||
displayName = this.displayName,
|
||||
timestamp = this.timestamp,
|
||||
coverImagePath = this.coverImagePath,
|
||||
title = this.title,
|
||||
author = this.author,
|
||||
lastChapterIndex = this.lastChapterIndex,
|
||||
locatorBlockIndex = this.locatorBlockIndex,
|
||||
locatorCharOffset = this.locatorCharOffset,
|
||||
lastPage = this.lastPage,
|
||||
lastPositionCfi = this.lastPositionCfi,
|
||||
progressPercentage = this.progressPercentage,
|
||||
isRecent = this.isRecent,
|
||||
isAvailable = this.isAvailable,
|
||||
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
||||
isDeleted = this.isDeleted,
|
||||
bookmarks = this.bookmarksJson,
|
||||
sourceFolderUri = this.sourceFolderUri
|
||||
)
|
||||
}
|
||||
|
||||
fun RecentFileItem.toBookMetadata(): BookMetadata {
|
||||
return BookMetadata(
|
||||
bookId = this.bookId,
|
||||
title = this.title,
|
||||
author = this.author,
|
||||
displayName = this.displayName,
|
||||
type = this.type.name,
|
||||
lastPositionCfi = this.lastPositionCfi,
|
||||
lastChapterIndex = this.lastChapterIndex,
|
||||
locatorBlockIndex = this.locatorBlockIndex,
|
||||
locatorCharOffset = this.locatorCharOffset,
|
||||
lastPage = this.lastPage,
|
||||
progressPercentage = this.progressPercentage,
|
||||
isRecent = this.isRecent,
|
||||
isDeleted = this.isDeleted,
|
||||
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
||||
bookmarksJson = this.bookmarksJson,
|
||||
hasAnnotations = false
|
||||
)
|
||||
}
|
||||
|
||||
fun BookMetadata.toRecentFileItem(): RecentFileItem {
|
||||
return RecentFileItem(
|
||||
bookId = this.bookId,
|
||||
uriString = null,
|
||||
type = try { FileType.valueOf(this.type) } catch (_: Exception) { FileType.EPUB },
|
||||
displayName = this.displayName,
|
||||
timestamp = this.lastModifiedTimestamp,
|
||||
coverImagePath = null,
|
||||
title = this.title,
|
||||
author = this.author,
|
||||
lastChapterIndex = this.lastChapterIndex,
|
||||
locatorBlockIndex = this.locatorBlockIndex,
|
||||
locatorCharOffset = this.locatorCharOffset,
|
||||
lastPositionCfi = this.lastPositionCfi,
|
||||
lastPage = this.lastPage,
|
||||
progressPercentage = this.progressPercentage,
|
||||
isRecent = this.isRecent,
|
||||
isAvailable = false,
|
||||
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
||||
isDeleted = this.isDeleted,
|
||||
bookmarksJson = this.bookmarksJson
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue