-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new wallpaper source - pixel walls
- Loading branch information
Showing
9 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
app/src/main/java/com/bnyro/wallpaper/api/px/obj/PixelWall.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/bnyro/wallpaper/api/px/obj/PixelWallsResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters