Fix redundant fragments in DetailsActivity
This commit is contained in:
@@ -97,8 +97,8 @@ dependencies {
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
|
||||
implementation 'com.squareup.okio:okio:3.0.0'
|
||||
|
||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.1'
|
||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.1'
|
||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||
|
||||
implementation 'io.insert-koin:koin-android:3.1.5'
|
||||
implementation 'io.coil-kt:coil-base:1.4.0'
|
||||
|
||||
@@ -93,6 +93,7 @@ class KotatsuApp : Application() {
|
||||
.detectWrongFragmentContainer()
|
||||
.detectRetainInstanceUsage()
|
||||
.detectSetUserVisibleHint()
|
||||
.detectFragmentTagUsage()
|
||||
.build()
|
||||
}
|
||||
}
|
||||
@@ -75,10 +75,7 @@ class ChaptersFragment : BaseFragment<FragmentChaptersBinding>(),
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
// workaround: duplication after screen rotation
|
||||
if (menu.findItem(R.id.action_reversed) == null) {
|
||||
inflater.inflate(R.menu.opt_chapters, menu)
|
||||
}
|
||||
inflater.inflate(R.menu.opt_chapters, menu)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.core.net.toFile
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.commit
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
@@ -63,6 +64,7 @@ class DetailsActivity : BaseActivity<ActivityDetailsBinding>(), TabLayoutMediato
|
||||
pager.adapter = MangaDetailsAdapter(this)
|
||||
TabLayoutMediator(checkNotNull(binding.tabs), pager, this).attach()
|
||||
}
|
||||
gcFragments()
|
||||
binding.spinnerBranches?.let(::initSpinner)
|
||||
|
||||
viewModel.manga.observe(this, ::onMangaUpdated)
|
||||
@@ -293,6 +295,23 @@ class DetailsActivity : BaseActivity<ActivityDetailsBinding>(), TabLayoutMediato
|
||||
}
|
||||
}
|
||||
|
||||
private fun gcFragments() {
|
||||
val mustHaveId = binding.pager == null
|
||||
val fm = supportFragmentManager
|
||||
val fragmentsToRemove = fm.fragments.filter { f ->
|
||||
(f.id == 0) == mustHaveId
|
||||
}
|
||||
if (fragmentsToRemove.isEmpty()) {
|
||||
return
|
||||
}
|
||||
fm.commit {
|
||||
setReorderingAllowed(true)
|
||||
for (f in fragmentsToRemove) {
|
||||
remove(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun newIntent(context: Context, manga: Manga): Intent {
|
||||
|
||||
Reference in New Issue
Block a user