mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Fix the mess up with OnBackPress support on Fragment
This commit is contained in:
parent
3ccdf4a244
commit
b22b8fba02
6 changed files with 15 additions and 23 deletions
|
@ -265,18 +265,21 @@ abstract class VectorBaseActivity : BaseMvRxActivity(), HasScreenInjector {
|
|||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
protected fun recursivelyDispatchOnBackPressed(fm: FragmentManager): Boolean {
|
||||
// if (fm.backStackEntryCount == 0)
|
||||
// return false
|
||||
override fun onBackPressed() {
|
||||
val handled = recursivelyDispatchOnBackPressed(supportFragmentManager)
|
||||
if (!handled) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
val reverseOrder = fm.fragments.filter { it is OnBackPressed }.reversed()
|
||||
private fun recursivelyDispatchOnBackPressed(fm: FragmentManager): Boolean {
|
||||
val reverseOrder = fm.fragments.filter { it is VectorBaseFragment }.reversed()
|
||||
for (f in reverseOrder) {
|
||||
val handledByChildFragments = recursivelyDispatchOnBackPressed(f.childFragmentManager)
|
||||
if (handledByChildFragments) {
|
||||
return true
|
||||
}
|
||||
val backPressable = f as OnBackPressed
|
||||
if (backPressable.onBackPressed()) {
|
||||
if (f is OnBackPressed && f.onBackPressed()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,7 @@ package im.vector.riotx.core.platform
|
|||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.*
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.annotation.MainThread
|
||||
|
@ -42,7 +38,7 @@ import io.reactivex.disposables.CompositeDisposable
|
|||
import io.reactivex.disposables.Disposable
|
||||
import timber.log.Timber
|
||||
|
||||
abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed, HasScreenInjector {
|
||||
abstract class VectorBaseFragment : BaseMvRxFragment(), HasScreenInjector {
|
||||
|
||||
// Butterknife unbinder
|
||||
private var mUnBinder: Unbinder? = null
|
||||
|
@ -132,10 +128,6 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed, HasScreen
|
|||
super.onViewStateRestored(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun invalidate() {
|
||||
//no-ops by default
|
||||
Timber.w("invalidate() method has not been implemented")
|
||||
|
|
|
@ -202,10 +202,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
drawerLayout.closeDrawer(GravityCompat.START)
|
||||
} else {
|
||||
val handled = recursivelyDispatchOnBackPressed(supportFragmentManager)
|
||||
if (!handled) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -250,7 +250,7 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O
|
|||
return true
|
||||
}
|
||||
|
||||
return super.onBackPressed()
|
||||
return false
|
||||
}
|
||||
|
||||
// RoomSummaryController.Callback **************************************************************
|
||||
|
|
|
@ -79,7 +79,6 @@ class LoginActivity : VectorBaseActivity() {
|
|||
showDisclaimerDialog(this)
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
fun newIntent(context: Context): Intent {
|
||||
return Intent(context, LoginActivity::class.java)
|
||||
|
|
|
@ -33,6 +33,7 @@ import im.vector.matrix.android.api.auth.data.Credentials
|
|||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.ScreenComponent
|
||||
import im.vector.riotx.core.platform.OnBackPressed
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import kotlinx.android.synthetic.main.fragment_login_sso_fallback.*
|
||||
import timber.log.Timber
|
||||
|
@ -42,7 +43,7 @@ import java.net.URLDecoder
|
|||
/**
|
||||
* Only login is supported for the moment
|
||||
*/
|
||||
class LoginSsoFallbackFragment : VectorBaseFragment() {
|
||||
class LoginSsoFallbackFragment : VectorBaseFragment(), OnBackPressed {
|
||||
|
||||
private val viewModel: LoginViewModel by activityViewModel()
|
||||
|
||||
|
|
Loading…
Reference in a new issue