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