[feat] Comic Resume
This commit is contained in:
@@ -47,4 +47,22 @@ class Comic(
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
fun getPageChapterIndex(page: Int): Pair<BookMark, Int>?
|
||||
{
|
||||
var p = page
|
||||
while(p >= 0 && !comic.bookmarks.any{ x -> x.page == comic.list[p] })
|
||||
{
|
||||
p--
|
||||
}
|
||||
for(i in comic.bookmarks)
|
||||
{
|
||||
if(i.page == comic.list[p])
|
||||
{
|
||||
return Pair(i, page - comic.list.indexOf(i.page) + 1)
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
13
app/src/main/java/com/acitelight/aether/model/ComicRecord.kt
Normal file
13
app/src/main/java/com/acitelight/aether/model/ComicRecord.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.acitelight.aether.model
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
|
||||
@Entity
|
||||
data class ComicRecord(
|
||||
@PrimaryKey(autoGenerate = false) val id: Int = 0,
|
||||
@ColumnInfo(name = "name") val name: String,
|
||||
@ColumnInfo(name = "position") val position: Int
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.acitelight.aether.model
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ComicRecordDao {
|
||||
@Query("SELECT * FROM comicrecord")
|
||||
fun getAll(): Flow<List<ComicRecord>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insert(rec: ComicRecord)
|
||||
|
||||
@Update
|
||||
suspend fun update(rec: ComicRecord)
|
||||
|
||||
@Delete
|
||||
suspend fun delete(rec: ComicRecord)
|
||||
|
||||
@Query("SELECT * FROM comicrecord WHERE id = :id")
|
||||
suspend fun getById(id: Int): ComicRecord?
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.acitelight.aether.model
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
|
||||
@Database(entities = [ComicRecord::class], version = 1)
|
||||
abstract class ComicRecordDatabase : RoomDatabase() {
|
||||
abstract fun userDao(): ComicRecordDao
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: ComicRecordDatabase? = null
|
||||
|
||||
fun getDatabase(context: Context): ComicRecordDatabase {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
val instance = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
ComicRecordDatabase::class.java,
|
||||
"comicrecord_database"
|
||||
).build()
|
||||
INSTANCE = instance
|
||||
instance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user