Browse Source

fix fragments cleanup on recreation

after back press if other MediaFragments where created via similar tab
develop
Jannik 3 months ago
parent
commit
7abb5cd3e8
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 20
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragment.kt

20
app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragment.kt

@ -129,8 +129,12 @@ class MediaFragment(private val mediaIdStr: String) : Fragment() {
val watchlistIcon = if (isWatchlist) R.drawable.ic_baseline_check_24 else R.drawable.ic_baseline_add_24
Glide.with(requireContext()).load(watchlistIcon).into(binding.imageMyListAction)
// clear fragments, since it lives in onCreate scope (don't do this in onPause/onStop -> FragmentManager transaction)
val fragmentsSize = if (fragments.lastIndex < 0) 0 else fragments.lastIndex
/**
* clear fragments, since it lives in onCreate scope,
* don't do this in onPause/onStop -> FragmentManager transaction
* (will be called on similar -> new MediaFragment -> onBackPressed)
*/
val fragmentsSize = fragments.size
fragments.clear()
pagerAdapter.notifyItemRangeRemoved(0, fragmentsSize)
@ -168,12 +172,12 @@ class MediaFragment(private val mediaIdStr: String) : Fragment() {
}
// if has similar titles
// if (model.similarTo.total > 0) {
// MediaFragmentSimilar().also {
// fragments.add(it)
// pagerAdapter.notifyItemInserted(fragments.indexOf(it))
// }
// }
if (model.similarTo.total > 0) {
MediaFragmentSimilar().also {
fragments.add(it)
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
}
}
// disable scrolling on appbar, if no tabs where added
if(fragments.isEmpty()) {

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