mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-18 11:23:56 +00:00
feat: filter lists by genre
This commit is contained in:
@@ -646,7 +646,7 @@ class AnilistQueries {
|
||||
sortOrder: String? = null
|
||||
): MutableMap<String, ArrayList<Media>> {
|
||||
val response =
|
||||
executeQuery<Query.MediaListCollection>("""{ MediaListCollection(userId: $userId, type: ${if (anime) "ANIME" else "MANGA"}) { lists { name isCustomList entries { status progress private score(format:POINT_100) updatedAt media { id idMal isAdult type status chapters episodes nextAiringEpisode {episode} bannerImage meanScore isFavourite format coverImage{large} startDate{year month day} title {english romaji userPreferred } } } } user { id mediaListOptions { rowOrder animeList { sectionOrder } mangaList { sectionOrder } } } } }""")
|
||||
executeQuery<Query.MediaListCollection>("""{ MediaListCollection(userId: $userId, type: ${if (anime) "ANIME" else "MANGA"}) { lists { name isCustomList entries { status progress private score(format:POINT_100) updatedAt media { id idMal isAdult type status chapters episodes nextAiringEpisode {episode} bannerImage genres meanScore isFavourite format coverImage{large} startDate{year month day} title {english romaji userPreferred } } } } user { id mediaListOptions { rowOrder animeList { sectionOrder } mangaList { sectionOrder } } } } }""")
|
||||
val sorted = mutableMapOf<String, ArrayList<Media>>()
|
||||
val unsorted = mutableMapOf<String, ArrayList<Media>>()
|
||||
val all = arrayListOf<Media>()
|
||||
|
||||
@@ -109,6 +109,7 @@ data class Media(
|
||||
this.userScore = mediaList.score?.toInt() ?: 0
|
||||
this.userStatus = mediaList.status?.toString()
|
||||
this.userUpdatedAt = mediaList.updatedAt?.toLong()
|
||||
this.genres = mediaList.media?.genres?.toMutableList() as? ArrayList<String>? ?: arrayListOf()
|
||||
}
|
||||
|
||||
constructor(mediaEdge: MediaEdge) : this(mediaEdge.node!!) {
|
||||
|
||||
@@ -170,6 +170,21 @@ class ListActivity : AppCompatActivity() {
|
||||
popup.show()
|
||||
}
|
||||
|
||||
binding.filter.setOnClickListener {
|
||||
val genres = PrefManager.getVal<Set<String>>(PrefName.GenresList).toMutableSet().sorted()
|
||||
val popup = PopupMenu(this, it)
|
||||
popup.menu.add("All")
|
||||
genres.forEach { genre ->
|
||||
popup.menu.add(genre)
|
||||
}
|
||||
popup.setOnMenuItemClickListener { menuItem ->
|
||||
val selectedGenre = menuItem.title.toString()
|
||||
model.filterLists(selectedGenre)
|
||||
true
|
||||
}
|
||||
popup.show()
|
||||
}
|
||||
|
||||
binding.random.setOnClickListener {
|
||||
//get the current tab
|
||||
val currentTab =
|
||||
|
||||
@@ -13,10 +13,29 @@ class ListViewModel : ViewModel() {
|
||||
var grid = MutableLiveData(PrefManager.getVal<Boolean>(PrefName.ListGrid))
|
||||
|
||||
private val lists = MutableLiveData<MutableMap<String, ArrayList<Media>>>()
|
||||
private val unfilteredLists = MutableLiveData<MutableMap<String, ArrayList<Media>>>()
|
||||
fun getLists(): LiveData<MutableMap<String, ArrayList<Media>>> = lists
|
||||
suspend fun loadLists(anime: Boolean, userId: Int, sortOrder: String? = null) {
|
||||
tryWithSuspend {
|
||||
lists.postValue(Anilist.query.getMediaLists(anime, userId, sortOrder))
|
||||
val res = Anilist.query.getMediaLists(anime, userId, sortOrder)
|
||||
lists.postValue(res)
|
||||
unfilteredLists.postValue(res)
|
||||
}
|
||||
}
|
||||
|
||||
fun filterLists(genre: String) {
|
||||
if (genre == "All") {
|
||||
lists.postValue(unfilteredLists.value)
|
||||
return
|
||||
}
|
||||
val currentLists = unfilteredLists.value ?: return
|
||||
val filteredLists = currentLists.mapValues { entry ->
|
||||
entry.value.filter { media ->
|
||||
genre in media.genres
|
||||
} as ArrayList<Media>
|
||||
}.toMutableMap()
|
||||
|
||||
lists.postValue(filteredLists)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user