check for activity context

This commit is contained in:
Finnley Somdahl 2024-01-23 14:15:04 -06:00
parent 8a9668bc79
commit b8fbeed785
2 changed files with 18 additions and 8 deletions

View file

@ -268,14 +268,19 @@ class AnimeFragment : Fragment() {
model.loaded = true model.loaded = true
model.loadTrending(1) model.loadTrending(1)
model.loadUpdated() model.loadUpdated()
model.loadPopular("ANIME", sort = Anilist.sortBy[1], onList = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("popular_list", false))
} }
live.postValue(false) withContext(Dispatchers.Main) {
_binding?.animeRefresh?.isRefreshing = false if (isAdded) { // Check if the fragment is still attached
model.loadPopular("ANIME", sort = Anilist.sortBy[1], onList = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("popular_list", false))
}
live.postValue(false)
_binding?.animeRefresh?.isRefreshing = false
}
} }
} }
} }
} }
override fun onResume() { override fun onResume() {

View file

@ -242,11 +242,16 @@ class MangaFragment : Fragment() {
model.loaded = true model.loaded = true
model.loadTrending() model.loadTrending()
model.loadTrendingNovel() model.loadTrendingNovel()
model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("popular_list", false) )
} }
live.postValue(false) withContext(Dispatchers.Main) {
_binding?.mangaRefresh?.isRefreshing = false if (isAdded) {
val sharedPrefs = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
val isPopularList = sharedPrefs.getBoolean("popular_list", false)
model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = isPopularList)
}
live.postValue(false)
_binding?.mangaRefresh?.isRefreshing = false
}
} }
} }
} }