From 9af466c24b9c69ca401a78d87ed393bc5b596332 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 14 Dec 2018 19:22:55 +0100 Subject: [PATCH] Home : open detail only when drawer is closed --- .../features/home/HomeActivity.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index c2176ec7..0ea44698 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -4,10 +4,12 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.support.v4.view.GravityCompat +import android.support.v4.widget.DrawerLayout import android.support.v7.app.ActionBarDrawerToggle import android.support.v7.widget.Toolbar import android.view.Gravity 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.RiotActivity @@ -64,8 +66,21 @@ class HomeActivity : RiotActivity(), HomeNavigator, ToolbarConfigurable { override fun openRoomDetail(roomId: String) { val roomDetailFragment = RoomDetailFragment.newInstance(roomId) - replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer) - drawerLayout.closeDrawer(Gravity.LEFT) + if (drawerLayout.isDrawerOpen(Gravity.LEFT)) { + closeDrawerLayout(Gravity.LEFT) { replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer) } + } else { + replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer) + } + } + + private fun closeDrawerLayout(gravity: Int, actionOnClose: () -> Unit) { + drawerLayout.addDrawerListener(object : DrawerLayout.SimpleDrawerListener() { + override fun onDrawerClosed(p0: View) { + drawerLayout.removeDrawerListener(this) + actionOnClose() + } + }) + drawerLayout.closeDrawer(gravity) } companion object {