Skip to content

Commit

Permalink
feat: respect auto-add-to-favorites preference at wallpaper changes a…
Browse files Browse the repository at this point in the history
…nd quick tile (closes #195)
  • Loading branch information
Bnyro committed May 8, 2024
1 parent 5f20695 commit 9c76126
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/com/bnyro/wallpaper/util/BackgroundWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.graphics.Bitmap
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.bnyro.wallpaper.db.DatabaseHolder
import com.bnyro.wallpaper.db.obj.Wallpaper
import com.bnyro.wallpaper.obj.WallpaperConfig
import com.bnyro.wallpaper.enums.WallpaperSource
import com.bnyro.wallpaper.ext.awaitQuery
Expand Down Expand Up @@ -52,8 +53,14 @@ class BackgroundWorker(
return withContext(Dispatchers.IO) {
val url = runCatching {
Preferences.getApiByRoute(source).getRandomWallpaperUrl()
}.getOrElse { return@withContext null }
ImageHelper.getSuspend(applicationContext, url, true)
}.getOrNull() ?: return@withContext null

val bitmap = ImageHelper.getSuspend(applicationContext, url, true)
if (bitmap != null && Preferences.getBoolean(Preferences.autoAddToFavoritesKey, false)) {
DatabaseHolder.Database.favoritesDao().insertAll(Wallpaper(imgSrc = url))
}

bitmap
}
}

Expand Down

0 comments on commit 9c76126

Please sign in to comment.