Skip to content

Commit

Permalink
Merge pull request #148 from you-apps/pixel-walls
Browse files Browse the repository at this point in the history
feat: new wallpaper source - pixel walls
  • Loading branch information
Bnyro authored Oct 31, 2023
2 parents bfe1886 + 9a54254 commit d2a6f36
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/bnyro/wallpaper/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.bnyro.wallpaper.api.bi.BiApi
import com.bnyro.wallpaper.api.le.LeApi
import com.bnyro.wallpaper.api.ow.OwApi
import com.bnyro.wallpaper.api.ps.PsApi
import com.bnyro.wallpaper.api.px.PxApi
import com.bnyro.wallpaper.api.re.ReApi
import com.bnyro.wallpaper.api.us.UsApi
import com.bnyro.wallpaper.api.wh.WhApi
Expand Down Expand Up @@ -51,5 +52,6 @@ class App : Application(), ImageLoaderFactory {
val reApi = ReApi()
val leApi = LeApi()
val whApi = WhApi()
val pxApi = PxApi()
}
}
1 change: 0 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 @@ -21,7 +21,6 @@ class BiApi() : Api() {
title = it.title,
url = "$baseUrl${it.quiz}",
resolution = "1920x1080",
thumb = imgUrl,
// creation date doesn't contain any dividers by default
creationDate = it.startDate
?.replaceRange(6, 6, "-")
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/api/ow/OwApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class OwApi() : Api() {
0,
Wallpaper(
imgSrc = it.value.textValue(),
thumb = it.value.textValue(),
category = it.key
)
)
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/bnyro/wallpaper/api/ps/PsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class PsApi : Api() {
imgSrc = it.download_url!!,
author = it.author,
resolution = "${it.width}x${it.height}",
url = it.url,
thumb = it.download_url
url = it.url
)
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/bnyro/wallpaper/api/px/Pixel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bnyro.wallpaper.api.px

import com.bnyro.wallpaper.api.px.obj.PixelWallsResponse
import retrofit2.http.GET

interface Pixel {
@GET("/repos/wacko1805/Pixel-Wallpapers/git/trees/main?recursive=1")
suspend fun getWallpapers(): PixelWallsResponse
}
41 changes: 41 additions & 0 deletions app/src/main/java/com/bnyro/wallpaper/api/px/PxApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.bnyro.wallpaper.api.px

import com.bnyro.wallpaper.api.Api
import com.bnyro.wallpaper.db.obj.Wallpaper
import com.bnyro.wallpaper.util.RetrofitBuilder

class PxApi : Api() {
override val name: String = "Google Pixel"
override val baseUrl: String = "https://api.github.com"
private val api = RetrofitBuilder.create(baseUrl, Pixel::class.java)
private val imgSrcPrefix = "https://raw.githubusercontent.com/wacko1805/Pixel-Wallpapers/main/"

private var wallpapers: List<Wallpaper> = emptyList()
private val resultsPerPage = 20

private suspend fun updateWallpaperList() {
wallpapers = api.getWallpapers()
.tree
.filter { it.path.endsWith(".jpg") || it.path.endsWith(".png") }
.map {
Wallpaper(
title = it.path.split("/").last().split(".").first(),
imgSrc = imgSrcPrefix + it.path,
category = it.path.split("/").first(),
fileSize = it.size
)
}
}

override suspend fun getWallpapers(page: Int): List<Wallpaper> {
if (wallpapers.isEmpty()) {
updateWallpaperList()
}
return wallpapers.subList((page - 1) * resultsPerPage, page * resultsPerPage)
}

override suspend fun getRandomWallpaperUrl(): String? {
if (wallpapers.isEmpty()) updateWallpaperList()
return wallpapers.randomOrNull()?.imgSrc
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/bnyro/wallpaper/api/px/obj/PixelWall.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bnyro.wallpaper.api.px.obj

data class PixelWall(
val mode: String = "",
val path: String = "",
val sha: String = "",
val size: Long = 0,
val type: String = "",
val url: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bnyro.wallpaper.api.px.obj

data class PixelWallsResponse(
val sha: String = "",
val tree: List<PixelWall> = emptyList(),
val truncated: Boolean = false,
val url: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fun WallpaperGrid(
) {
Box {
AsyncImage(
model = it.thumb,
model = it.thumb ?: it.imgSrc,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ sealed class DrawerScreens(
object BingDaily : DrawerScreens(R.string.bing_daily, "bi", Icons.Default.Nightlight)
object Reddit : DrawerScreens(R.string.reddit, "redd", Icons.Default.Forum)
object Lemmy : DrawerScreens(R.string.lemmy, "le", Icons.Default.Book)
object Pixel : DrawerScreens(R.string.pixel, "px", Icons.Default.Pix)
object Favorites : DrawerScreens(R.string.favorites, "favorites", Icons.Default.Favorite, true)
object Settings : DrawerScreens(R.string.settings, "settings", Icons.Default.Settings, true)
object About : DrawerScreens(R.string.about, "about", Icons.Default.Info)

companion object {
val apiScreens by lazy { listOf(Wallhaven, Unsplash, OWalls, Picsum, BingDaily, Reddit, Lemmy) }
val apiScreens by lazy { listOf(Wallhaven, Unsplash, OWalls, Picsum, BingDaily, Reddit, Lemmy, Pixel) }
val screens by lazy { listOf(*apiScreens.toTypedArray(), Favorites, Settings, About) }
}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/bnyro/wallpaper/util/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object Preferences {
DrawerScreens.BingDaily.route -> App.biApi
DrawerScreens.Reddit.route -> App.reApi
DrawerScreens.Lemmy.route -> App.leApi
DrawerScreens.Pixel.route -> App.pxApi
else -> App.whApi
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<string name="bing_daily" translatable="false">Bing daily</string>
<string name="reddit" translatable="false">Reddit</string>
<string name="lemmy" translatable="false">Lemmy</string>
<string name="pixel" translatable="false">Google Pixel</string>
<!-- Navigation Drawer -->
<string name="favorites">Favorites</string>
<string name="settings">Settings</string>
Expand Down

0 comments on commit d2a6f36

Please sign in to comment.