Skip to content

Commit

Permalink
feat: new wallpaper source - pixel walls
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Oct 30, 2023
1 parent a4c4f97 commit 2b27bfc
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 19,
"versionName": "4.1",
"versionCode": 22,
"versionName": "6.1",
"outputFile": "app-release.apk"
}
],
Expand Down
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()
}
}
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 @@ -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 2b27bfc

Please sign in to comment.