mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
fix: back gesture handling in no internet activity
This commit is contained in:
parent
c975568e9a
commit
0d334f7ba5
@ -3,6 +3,7 @@ package com.github.libretube.ui.activities
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.addCallback
|
import androidx.activity.addCallback
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.commit
|
import androidx.fragment.app.commit
|
||||||
import androidx.fragment.app.replace
|
import androidx.fragment.app.replace
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -43,17 +44,27 @@ class NoInternetActivity : BaseActivity() {
|
|||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
onBackPressedDispatcher.addCallback(this) {
|
onBackPressedDispatcher.addCallback(this) {
|
||||||
supportFragmentManager.fragments.filterIsInstance<DownloadsFragment>()
|
if (removeFragment<DownloadsFragment>() || removeFragment<AudioPlayerFragment>()) return@addCallback
|
||||||
.firstOrNull()
|
|
||||||
?.let {
|
finishAffinity()
|
||||||
supportFragmentManager.commit {
|
|
||||||
remove(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?: finishAffinity()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline fun <reified T: Fragment> removeFragment(): Boolean {
|
||||||
|
val fragment = supportFragmentManager.fragments.filterIsInstance<T>()
|
||||||
|
.firstOrNull()
|
||||||
|
|
||||||
|
if (fragment != null) {
|
||||||
|
supportFragmentManager.commit {
|
||||||
|
remove(fragment)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user