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,6 +268,9 @@ class AnimeFragment : Fragment() {
model.loaded = true
model.loadTrending(1)
model.loadUpdated()
}
withContext(Dispatchers.Main) {
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))
}
@ -278,6 +281,8 @@ class AnimeFragment : Fragment() {
}
}
}
override fun onResume() {
if (!model.loaded) Refresh.activity[this.hashCode()]!!.postValue(true)
if (animePageAdapter.trendingViewPager != null) {

View file

@ -242,8 +242,12 @@ class MangaFragment : Fragment() {
model.loaded = true
model.loadTrending()
model.loadTrendingNovel()
model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("popular_list", false) )
}
withContext(Dispatchers.Main) {
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
@ -251,6 +255,7 @@ class MangaFragment : Fragment() {
}
}
}
}
override fun onResume() {
if (!model.loaded) Refresh.activity[this.hashCode()]!!.postValue(true)