mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
update SavedItemCardData class
This commit is contained in:
parent
bbe8508753
commit
4985508702
3 changed files with 66 additions and 7 deletions
|
|
@ -0,0 +1,42 @@
|
|||
package app.omnivore.omnivore.persistence
|
||||
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Update
|
||||
|
||||
|
||||
interface BaseDao<T> {
|
||||
|
||||
/**
|
||||
* Insert an object in the database.
|
||||
*
|
||||
* @param obj the object to be inserted.
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(obj: T)
|
||||
|
||||
/**
|
||||
* Insert an array of objects in the database.
|
||||
*
|
||||
* @param obj the objects to be inserted.
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg obj: T)
|
||||
|
||||
/**
|
||||
* Update an object from the database.
|
||||
*
|
||||
* @param obj the object to be updated
|
||||
*/
|
||||
@Update
|
||||
fun update(obj: T)
|
||||
|
||||
/**
|
||||
* Delete an object from the database
|
||||
*
|
||||
* @param obj the object to be deleted
|
||||
*/
|
||||
@Delete
|
||||
fun delete(obj: T)
|
||||
}
|
||||
|
|
@ -51,6 +51,20 @@ data class SavedItem(
|
|||
return contentReader == "PDF" || hasPDFSuffix
|
||||
}
|
||||
|
||||
fun asSavedItemCardData(): SavedItemCardData {
|
||||
return SavedItemCardData(
|
||||
id = id,
|
||||
slug = slug,
|
||||
publisherURLString = publisherURLString,
|
||||
title = title,
|
||||
author = author,
|
||||
imageURLString = imageURLString,
|
||||
isArchived = isArchived,
|
||||
pageURLString = pageURLString,
|
||||
contentReader = contentReader,
|
||||
)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
|
@ -69,20 +83,28 @@ data class SavedItem(
|
|||
|
||||
data class SavedItemCardData(
|
||||
val id: String,
|
||||
val slug: String,
|
||||
val publisherURLString: String?,
|
||||
val title: String,
|
||||
val author: String?,
|
||||
val imageURLString: String?,
|
||||
val isArchived: Boolean
|
||||
val isArchived: Boolean,
|
||||
val pageURLString: String,
|
||||
val contentReader: String?
|
||||
) {
|
||||
fun publisherDisplayName(): String? {
|
||||
return publisherURLString?.toUri()?.host
|
||||
}
|
||||
|
||||
fun isPDF(): Boolean {
|
||||
val hasPDFSuffix = pageURLString.endsWith("pdf")
|
||||
return contentReader == "PDF" || hasPDFSuffix
|
||||
}
|
||||
}
|
||||
|
||||
@Dao
|
||||
interface SavedItemDao {
|
||||
@Query("SELECT id, publisherURLString, title, author, imageURLString, isArchived FROM SavedItem")
|
||||
@Query("SELECT id, slug, publisherURLString, title, author, imageURLString, isArchived, pageURLString, contentReader FROM SavedItem")
|
||||
fun getLibraryData(): List<SavedItemCardData>
|
||||
|
||||
@Query("SELECT * FROM savedItem")
|
||||
|
|
|
|||
|
|
@ -57,11 +57,6 @@ class LibraryViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
val viewers = dataService.db.viewerDao().getAll()
|
||||
Log.d("appDatabase", "found ${viewers.count()} viewers in db")
|
||||
}
|
||||
|
||||
val thisSearchIdx = searchIdx
|
||||
searchIdx += 1
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue