Skip to content

Commit

Permalink
feat: support for image descriptions (closes #214)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Oct 29, 2024
1 parent 5044ea5 commit 31b13a9
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 50 deletions.
110 changes: 110 additions & 0 deletions app/schemas/com.bnyro.wallpaper.db.AppDatabase/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "f559659dec04a927d7671dc5d8e98476",
"entities": [
{
"tableName": "favorites",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`imgSrc` TEXT NOT NULL, `title` TEXT, `url` TEXT, `author` TEXT, `category` TEXT, `resolution` TEXT, `fileSize` INTEGER, `thumb` TEXT, `creationDate` TEXT, `description` TEXT DEFAULT NULL, `favorite` INTEGER NOT NULL DEFAULT 1, `inHistory` INTEGER NOT NULL DEFAULT 0, `timeAdded` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`imgSrc`))",
"fields": [
{
"fieldPath": "imgSrc",
"columnName": "imgSrc",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "author",
"columnName": "author",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "category",
"columnName": "category",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "resolution",
"columnName": "resolution",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "fileSize",
"columnName": "fileSize",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "thumb",
"columnName": "thumb",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "creationDate",
"columnName": "creationDate",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "NULL"
},
{
"fieldPath": "favorite",
"columnName": "favorite",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "inHistory",
"columnName": "inHistory",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "timeAdded",
"columnName": "timeAdded",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"imgSrc"
]
},
"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, 'f559659dec04a927d7671dc5d8e98476')"
]
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/bi/BiApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class BiApi : Api() {
// creation date doesn't contain any dividers by default
creationDate = it.startDate
?.replaceRange(6, 6, "-")
?.replaceRange(4, 4, "-")
?.replaceRange(4, 4, "-"),
author = it.copyright
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/bnyro/wallpaper/api/le/LeApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.material.icons.filled.Book
import com.bnyro.wallpaper.api.CommunityApi
import com.bnyro.wallpaper.db.obj.Wallpaper
import com.bnyro.wallpaper.util.RetrofitHelper
import com.bnyro.wallpaper.util.TextUtils

class LeApi : CommunityApi() {
override val name = "Lemmy"
Expand Down Expand Up @@ -51,6 +52,7 @@ class LeApi : CommunityApi() {
imgSrc = it.post.thumbnailUrl!!,
thumb = "${it.post.thumbnailUrl}?format=jpg&thumbnail=1080",
title = it.post.name,
description = it.post.body?.let { text -> TextUtils.removeMarkdownSymbols(text) },
url = it.post.postUrl,
author = it.creator.name,
creationDate = it.post.published
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.serialization.Serializable
data class LemmyPost(
@SerialName("ap_id") val postUrl: String = "",
@SerialName("name") val name: String = "",
@SerialName("body") val body: String? = null,
@SerialName("published") val published: String = "",
@SerialName("thumbnail_url") val thumbnailUrl: String? = null,
)
2 changes: 1 addition & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/ps/PsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PsApi : Api() {
override suspend fun getWallpapers(page: Int): List<Wallpaper> {
return api.getWallpapers(page).map {
Wallpaper(
imgSrc = it.download_url!!,
imgSrc = it.downloadUrl!!,
author = it.author,
resolution = "${it.width}x${it.height}",
url = it.url
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/ps/obj/PsImage.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.bnyro.wallpaper.api.ps.obj

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class PsImage(
val author: String? = null,
val download_url: String? = null,
@SerialName("download_url") val downloadUrl: String? = null,
val height: Int? = null,
val id: String? = null,
val url: String? = null,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/bnyro/wallpaper/api/re/ReApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ReApi : CommunityApi() {
}?.map {
with(it.childData) {
Wallpaper(
preview?.images?.firstOrNull()?.source?.imgUrl ?: url!!,
it.childData.title,
imgSrc = preview?.images?.firstOrNull()?.source?.imgUrl ?: url!!,
title = it.childData.title,
thumb = url,
resolution = preview?.images?.firstOrNull()?.source?.let { img -> "${img.width}x${img.height}" }
)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/sp/SpApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class SpApi: Api() {
title = it.ad.title,
imgSrc = it.ad.portraitImage.asset,
author = it.ad.copyright,
url = it.ad.ctaUri.replaceFirst("microsoft-edge:", "")
url = it.ad.ctaUri.replaceFirst("microsoft-edge:", ""),
description = it.ad.description
)
}
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/sp/Spotlight.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bnyro.wallpaper.api.sp

import com.bnyro.wallpaper.api.sp.obj.SpotlightImage
import com.bnyro.wallpaper.api.sp.obj.SpotlightImageItem
import com.bnyro.wallpaper.api.sp.obj.SpotlightPage
import retrofit2.http.GET
import retrofit2.http.Query
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/us/UsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.bnyro.wallpaper.api.Api
import com.bnyro.wallpaper.db.obj.Wallpaper
import com.bnyro.wallpaper.util.RetrofitHelper

class UsApi() : Api() {
class UsApi : Api() {
override val name: String = "Unsplash"
override val baseUrl: String = "https://unsplash.com"
override val icon = Icons.Default.WaterDrop
Expand All @@ -32,6 +32,7 @@ class UsApi() : Api() {
return wallpapers.filter { it.premium != true }.map {
Wallpaper(
imgSrc = it.links.download ?: it.urls?.raw ?: "",
description = it.alt_description,
author = it.user?.username,
url = it.links.html,
resolution = "${it.width}x${it.height}",
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/wh/WhApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class WhApi : Api() {
fileSize = it.file_size,
resolution = it.resolution,
thumb = it.thumbs?.original,
author = null,
creationDate = it.created_at
)
}.orEmpty()
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/bnyro/wallpaper/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import com.bnyro.wallpaper.db.dao.FavoritesDao
import com.bnyro.wallpaper.db.obj.Wallpaper

@Database(
version = 2,
version = 3,
autoMigrations = [
AutoMigration(1, 2)
AutoMigration(1, 2),
AutoMigration(2, 3)
],
entities = [
Wallpaper::class
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/db/obj/Wallpaper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ data class Wallpaper(
@ColumnInfo val fileSize: Long? = null,
@ColumnInfo val thumb: String? = null,
@ColumnInfo val creationDate: String? = null,
@ColumnInfo(defaultValue = "NULL") val description: String? = null,
@ColumnInfo(defaultValue = "1") var favorite: Boolean = false,
@ColumnInfo(defaultValue = "0") var inHistory: Boolean = false,
@ColumnInfo(defaultValue = "0") var timeAdded: Long = 0,
)
) {
val preview get() = thumb ?: imgSrc
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fun WallpaperFilterEditor(
.background(Color.Black)
.zoomArea(zoomState)
) {
val lowRes = rememberAsyncImagePainter(model = wallpaper.thumb ?: wallpaper.imgSrc)
val lowRes = rememberAsyncImagePainter(model = wallpaper.preview)
val colorMatrix = remember(grayscaleEnabled, invertPreview, contrastValue) {
val sat = if (grayscaleEnabled) 0f else 1f
val invSat = 1 - sat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fun WallpaperGrid(
) {
Box {
AsyncImage(
model = wallpaper.thumb ?: wallpaper.imgSrc,
model = wallpaper.preview,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fun WallpaperView(
animationSpec = tween(500)
)
AsyncImage(
model = wallpaper.thumb ?: wallpaper.imgSrc,
model = wallpaper.preview,
contentDescription = null,
contentScale = ContentScale.FillBounds,
modifier = Modifier
Expand All @@ -109,7 +109,7 @@ fun WallpaperView(
.zoomArea(zoomState),
contentAlignment = Alignment.Center
) {
val lowRes = rememberAsyncImagePainter(model = wallpaper.thumb ?: wallpaper.imgSrc)
val lowRes = rememberAsyncImagePainter(model = wallpaper.preview)
AsyncImage(
model = wallpaper.imgSrc,
contentDescription = stringResource(id = R.string.wallpaper),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun InfoSheetColors(
LaunchedEffect(wallpaper) {
ImageHelper.urlToBitmap(
this,
wallpaper.thumb,
wallpaper.preview,
context.applicationContext
) {
Palette.from(it).generate { palette ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccessTime
import androidx.compose.material.icons.filled.Category
import androidx.compose.material.icons.filled.Description
import androidx.compose.material.icons.filled.Image
import androidx.compose.material.icons.filled.Label
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.PhotoSizeSelectLarge
import androidx.compose.material.icons.filled.Storage
import androidx.compose.material.icons.filled.Web
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
Expand All @@ -37,14 +40,17 @@ fun WallpaperInfoSheet(onDismissRequest: () -> Unit, wallpaper: Wallpaper) {
val state = rememberModalBottomSheetState(skipPartiallyExpanded = true)

ModalBottomSheet(onDismissRequest, sheetState = state) {
Column(Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
Column(
Modifier
.padding(horizontal = 16.dp, vertical = 8.dp)
) {
Text(
text = stringResource(R.string.colors),
style = MaterialTheme.typography.titleLarge
)
Spacer(Modifier.height(16.dp))
InfoSheetColors(wallpaper = wallpaper)
Divider(
HorizontalDivider(
Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
Expand All @@ -53,28 +59,39 @@ fun WallpaperInfoSheet(onDismissRequest: () -> Unit, wallpaper: Wallpaper) {
text = stringResource(R.string.details),
style = MaterialTheme.typography.titleLarge
)
wallpaper.title?.let {
WallpaperInfoItem(Icons.Default.Label, R.string.label, it)
Column(
modifier = Modifier.verticalScroll(rememberScrollState())
) {
wallpaper.title?.let {
WallpaperInfoItem(Icons.Default.Label, R.string.label, it)
}
wallpaper.description?.let {
WallpaperInfoItem(Icons.Default.Description, R.string.description, it)
}
wallpaper.author?.let {
WallpaperInfoItem(Icons.Default.Person, R.string.author, it)
}
wallpaper.category?.let {
WallpaperInfoItem(Icons.Default.Category, R.string.category, it)
}
wallpaper.resolution?.let {
WallpaperInfoItem(Icons.Default.PhotoSizeSelectLarge, R.string.resolution, it)
}
wallpaper.fileSize?.let {
WallpaperInfoItem(
Icons.Default.Storage,
R.string.fileSize,
Formatter.formatFileSize(context, it)
)
}
wallpaper.creationDate?.let {
WallpaperInfoItem(Icons.Default.AccessTime, R.string.creationDate, it)
}
wallpaper.url?.let {
WallpaperInfoItem(Icons.Default.Web, R.string.source, it, true)
}
WallpaperInfoItem(Icons.Default.Image, R.string.image_url, wallpaper.imgSrc, true)
}
wallpaper.author?.let {
WallpaperInfoItem(Icons.Default.Person, R.string.author, it)
}
wallpaper.category?.let {
WallpaperInfoItem(Icons.Default.Category, R.string.category, it)
}
wallpaper.resolution?.let {
WallpaperInfoItem(Icons.Default.PhotoSizeSelectLarge, R.string.resolution, it)
}
wallpaper.fileSize?.let {
WallpaperInfoItem(Icons.Default.Storage, R.string.fileSize, Formatter.formatFileSize(context, it))
}
wallpaper.creationDate?.let {
WallpaperInfoItem(Icons.Default.AccessTime, R.string.creationDate, it)
}
wallpaper.url?.let {
WallpaperInfoItem(Icons.Default.Web, R.string.source, it, true)
}
WallpaperInfoItem(Icons.Default.Image, R.string.image_url, wallpaper.imgSrc, true)
}
}
}
Loading

0 comments on commit 31b13a9

Please sign in to comment.