Browse Source

fix crash on myList element not present in overall itemMediaList

fixes #42
pull/43/head
Jannik 12 months ago
parent
commit
03e9c3dae5
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 24
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/HomeFragment.kt

24
app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/HomeFragment.kt

@ -72,12 +72,7 @@ class HomeFragment : Fragment() {
binding.recyclerTopTen.addItemDecoration(MediaItemDecoration(9))
// my list
val myListMedia = StorageController.myList.map { elementId ->
AoDParser.itemMediaList.first {
elementId == it.id
}
}
adapterMyList = MediaItemAdapter(myListMedia)
adapterMyList = MediaItemAdapter(mapMyListToItemMedia())
binding.recyclerMyList.adapter = adapterMyList
// new episodes
@ -153,14 +148,19 @@ class HomeFragment : Fragment() {
* * only update actual change and not all data (performance)
*/
fun updateMyListMedia() {
val myListMedia = StorageController.myList.map { elementId ->
AoDParser.itemMediaList.first {
elementId == it.id
adapterMyList.updateMediaList(mapMyListToItemMedia())
adapterMyList.notifyDataSetChanged()
}
private fun mapMyListToItemMedia(): List<ItemMedia> {
return StorageController.myList.mapNotNull { elementId ->
AoDParser.itemMediaList.firstOrNull { it.id == elementId }.also {
// it the my list entry wasn't found in itemMediaList Log it
if (it == null) {
Log.w(javaClass.name, "The element with the id $elementId was not found.")
}
}
}
adapterMyList.updateMediaList(myListMedia)
adapterMyList.notifyDataSetChanged()
}
}
Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close