mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
Navigation : add simple fragment backstack management.
This commit is contained in:
parent
c42be8141e
commit
b696e4a6de
7 changed files with 37 additions and 15 deletions
|
@ -0,0 +1,10 @@
|
|||
package im.vector.riotredesign.core.platform
|
||||
|
||||
interface OnBackPressed {
|
||||
|
||||
/**
|
||||
* Returns true, if the on back pressed event has been handled by this Fragment.
|
||||
* Otherwise return false
|
||||
*/
|
||||
fun onBackPressed(): Boolean
|
||||
}
|
|
@ -2,12 +2,15 @@ package im.vector.riotredesign.core.platform
|
|||
|
||||
import com.airbnb.mvrx.BaseMvRxFragment
|
||||
|
||||
abstract class RiotFragment : BaseMvRxFragment() {
|
||||
abstract class RiotFragment : BaseMvRxFragment(), OnBackPressed {
|
||||
|
||||
val riotActivity: RiotActivity by lazy {
|
||||
activity as RiotActivity
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun invalidate() {
|
||||
//no-ops by default
|
||||
|
|
|
@ -5,14 +5,12 @@ import im.vector.matrix.android.api.Matrix
|
|||
import im.vector.riotredesign.core.platform.RiotActivity
|
||||
import im.vector.riotredesign.features.home.HomeActivity
|
||||
import im.vector.riotredesign.features.login.LoginActivity
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
|
||||
class MainActivity : RiotActivity() {
|
||||
|
||||
private val authenticator = Matrix.getInstance().authenticator()
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val intent = if (authenticator.hasActiveSessions()) {
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package im.vector.riotredesign.features
|
||||
|
||||
class RootFlowCoordinator {
|
||||
}
|
|
@ -3,6 +3,7 @@ package im.vector.riotredesign.features.home
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.view.GravityCompat
|
||||
import android.support.v4.widget.DrawerLayout
|
||||
import android.support.v7.app.ActionBarDrawerToggle
|
||||
|
@ -12,6 +13,7 @@ import android.view.MenuItem
|
|||
import android.view.View
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.extensions.replaceFragment
|
||||
import im.vector.riotredesign.core.platform.OnBackPressed
|
||||
import im.vector.riotredesign.core.platform.RiotActivity
|
||||
import im.vector.riotredesign.core.platform.ToolbarConfigurable
|
||||
import im.vector.riotredesign.features.home.room.detail.LoadingRoomDetailFragment
|
||||
|
@ -46,7 +48,6 @@ class HomeActivity : RiotActivity(), HomeNavigator, ToolbarConfigurable {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
// Android home
|
||||
android.R.id.home -> {
|
||||
drawerLayout.openDrawer(GravityCompat.START)
|
||||
return true
|
||||
|
@ -60,10 +61,30 @@ class HomeActivity : RiotActivity(), HomeNavigator, ToolbarConfigurable {
|
|||
if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
|
||||
drawerLayout.closeDrawer(Gravity.LEFT)
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
val handled = recursivelyDispatchOnBackPressed(supportFragmentManager)
|
||||
if (!handled) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun recursivelyDispatchOnBackPressed(fm: FragmentManager): Boolean {
|
||||
if (fm.backStackEntryCount == 0)
|
||||
return false
|
||||
val reverseOrder = fm.fragments.filter { it is OnBackPressed }.reversed()
|
||||
for (f in reverseOrder) {
|
||||
val handledByChildFragments = recursivelyDispatchOnBackPressed(f.childFragmentManager)
|
||||
if (handledByChildFragments) {
|
||||
return true
|
||||
}
|
||||
val backPressable = f as OnBackPressed
|
||||
if (backPressable.onBackPressed()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HomeNavigator *******************************************************************************
|
||||
|
||||
override fun openRoomDetail(roomId: String, eventId: String?) {
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package im.vector.riotredesign.features.home
|
||||
|
||||
class HomeFlowCoordinator {
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
package im.vector.riotredesign.features.login
|
||||
|
Loading…
Reference in a new issue