2025-08-08 23:21:33 +03:00
|
|
|
package xyz.pixelatedw.recipe.data
|
|
|
|
|
|
2025-08-09 18:09:09 +03:00
|
|
|
import android.content.Context
|
2025-08-09 13:21:06 +03:00
|
|
|
import android.graphics.Bitmap
|
2025-08-09 18:09:09 +03:00
|
|
|
import android.graphics.BitmapFactory
|
|
|
|
|
import androidx.core.net.toUri
|
|
|
|
|
import androidx.room.Dao
|
|
|
|
|
import androidx.room.Entity
|
|
|
|
|
import androidx.room.Insert
|
|
|
|
|
import androidx.room.OnConflictStrategy
|
|
|
|
|
import androidx.room.PrimaryKey
|
|
|
|
|
import java.io.File
|
2025-08-09 13:21:06 +03:00
|
|
|
|
2025-08-09 18:09:09 +03:00
|
|
|
@Entity
|
2025-08-08 23:21:33 +03:00
|
|
|
data class Recipe(
|
2025-08-09 18:09:09 +03:00
|
|
|
@PrimaryKey
|
2025-08-08 23:21:33 +03:00
|
|
|
val title: String,
|
2025-08-09 18:09:09 +03:00
|
|
|
val preview: String?,
|
2025-08-08 23:21:33 +03:00
|
|
|
val lastModified: Long,
|
|
|
|
|
val content: String
|
2025-08-09 13:21:06 +03:00
|
|
|
) {
|
2025-08-10 02:07:45 +03:00
|
|
|
fun previewImage(ctx: Context): Bitmap? {
|
2025-08-09 18:09:09 +03:00
|
|
|
if (this.preview != null) {
|
|
|
|
|
val file = File(ctx.filesDir, this.preview)
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
ctx.contentResolver.openInputStream(file.toUri()).use {
|
2025-08-10 02:07:45 +03:00
|
|
|
return BitmapFactory.decodeStream(it)
|
2025-08-09 18:09:09 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null
|
2025-08-09 13:21:06 +03:00
|
|
|
}
|
|
|
|
|
}
|
2025-08-09 18:09:09 +03:00
|
|
|
|
|
|
|
|
@Dao
|
|
|
|
|
interface RecipeDao {
|
|
|
|
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
|
|
|
fun insert(recipe: Recipe)
|
|
|
|
|
}
|