Skip to content

Commit

Permalink
feat: support tags filter for random unsplash wallpapers (closes #182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Mar 11, 2024
1 parent f3ce109 commit b439f96
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/us/Unsplash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ interface Unsplash {
): UsSearch

@GET("/napi/photos/random")
suspend fun getRandom(): UsImage
suspend fun getRandom(
@Query("query") query: String
): UsImage
}
10 changes: 7 additions & 3 deletions app/src/main/java/com/bnyro/wallpaper/api/us/UsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class UsApi() : Api() {

override suspend fun getWallpapers(page: Int): List<Wallpaper> {
val tags = getTags()
val sortOrder = getQuery("order_by")

val wallpapers = if (tags.isEmpty()) {
api.getWallpapers(page, getQuery("order_by"))
api.getWallpapers(page, sortOrder)
} else {
api.searchWallpapers(page, tags.joinToString(" "), getQuery("order_by")).results
val tagString = tags.joinToString(" ")
api.searchWallpapers(page, tagString, sortOrder).results
}

return wallpapers.filter { it.premium != true }.map {
Expand All @@ -36,7 +38,9 @@ class UsApi() : Api() {
}

override suspend fun getRandomWallpaperUrl(): String? {
return api.getRandom().let {
val tagString = getTags().joinToString(" ")

return api.getRandom(tagString).let {
it.links.download ?: it.urls?.raw ?: it.urls?.full
}
}
Expand Down

0 comments on commit b439f96

Please sign in to comment.