fix crash on myList element not present in overall itemMediaList
fixes #42
This commit is contained in:
parent
5ccf907ed8
commit
03e9c3dae5
|
@ -72,12 +72,7 @@ class HomeFragment : Fragment() {
|
||||||
binding.recyclerTopTen.addItemDecoration(MediaItemDecoration(9))
|
binding.recyclerTopTen.addItemDecoration(MediaItemDecoration(9))
|
||||||
|
|
||||||
// my list
|
// my list
|
||||||
val myListMedia = StorageController.myList.map { elementId ->
|
adapterMyList = MediaItemAdapter(mapMyListToItemMedia())
|
||||||
AoDParser.itemMediaList.first {
|
|
||||||
elementId == it.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
adapterMyList = MediaItemAdapter(myListMedia)
|
|
||||||
binding.recyclerMyList.adapter = adapterMyList
|
binding.recyclerMyList.adapter = adapterMyList
|
||||||
|
|
||||||
// new episodes
|
// new episodes
|
||||||
|
@ -153,14 +148,19 @@ class HomeFragment : Fragment() {
|
||||||
* * only update actual change and not all data (performance)
|
* * only update actual change and not all data (performance)
|
||||||
*/
|
*/
|
||||||
fun updateMyListMedia() {
|
fun updateMyListMedia() {
|
||||||
val myListMedia = StorageController.myList.map { elementId ->
|
adapterMyList.updateMediaList(mapMyListToItemMedia())
|
||||||
AoDParser.itemMediaList.first {
|
|
||||||
elementId == it.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adapterMyList.updateMediaList(myListMedia)
|
|
||||||
adapterMyList.notifyDataSetChanged()
|
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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue