fix crash on myList element not present in overall itemMediaList

fixes #42
This commit is contained in:
Jannik 2021-07-03 13:36:15 +02:00
parent 5ccf907ed8
commit 03e9c3dae5
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
1 changed files with 13 additions and 13 deletions

View File

@ -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(myListMedia)
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.")
}
}
}
}
}