Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId "moe.apex.breadboard"
minSdk 26
targetSdk 36
versionCode 337
versionName "3.3.7"
versionCode 338
versionName "3.3.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/moe/apex/breadboard/image/ImageBoard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ object Danbooru : ImageBoard {
)
override val imageSearchUrl = "${baseUrl}posts.json?tags=%s&page=%d&limit=100"
override val authenticatedImageSearchUrl = "$imageSearchUrl&api_key=%s&login=%s"
private val popularUrl = "${baseUrl}posts.json?tags=%s order:favcount&limit=20"
override val totalPostCountUrl = "${baseUrl}counts/posts.json?tags=%s"
override val firstPageIndex = 1
override val apiKeyCreationUrl = "${baseUrl}/profile"
Expand Down Expand Up @@ -617,6 +618,21 @@ object Danbooru : ImageBoard {
)
}

suspend fun getMostPopularPosts(artistTag: String): List<Image> {
val url = popularUrl.format(formatTagNameString(listOf(artistTag, "rating:g")))
val body = RequestUtil.get(url)
if (body.isEmpty()) return emptyList()

val json = JSONArray(body)
val subjects = mutableListOf<Image>()

for (i in 0 until json.length()) {
val e = json.getJSONObject(i)
parseImage(e)?.let { subjects.add(it) }
}

return subjects.toList()
}

override fun getRatingFromString(rating: String): ImageRating {
return when (rating) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ class ArtistProfileViewModel(private val artistTag: String): ViewModel() {

Log.i("ArtistProfileViewModel", "Loading artist profile for $artistTag")

_artistProfile.value = Danbooru.getArtist(artistTag)
_images.value = DanbooruSafe.getMostPopularPosts(artistTag)
_artistProfile.value = runCatching { Danbooru.getArtist(artistTag) }
.onFailure { Log.e("ArtistProfileViewModel", "Failed to load artist profile for $artistTag", it) }
.getOrThrow()

runCatching { DanbooruSafe.getMostPopularPosts(artistTag) }
.onFailure { Log.e("ArtistProfileViewModel", "Failed to load posts with DanbooruSafe for artist $artistTag. Attempting regular Danbooru.", it) }
.recoverCatching { Danbooru.getMostPopularPosts(artistTag) }
.onFailure { Log.e("ArtistProfileViewModel", "Failed to load posts with Danbooru for artist $artistTag", it) }
.onSuccess { _images.value = it }

_isInitialised.value = true
}
Expand Down
Loading