Commit 4a7aaf7d authored by dev-ritik's avatar dev-ritik

Fix app close on back button press

parent 9ecc0442
...@@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment ...@@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import chat.rocket.android.BuildConfig import chat.rocket.android.BuildConfig
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.chatrooms.ui.ChatRoomsFragment
import chat.rocket.android.main.adapter.AccountsAdapter import chat.rocket.android.main.adapter.AccountsAdapter
import chat.rocket.android.main.adapter.Selector import chat.rocket.android.main.adapter.Selector
import chat.rocket.android.main.presentation.MainPresenter import chat.rocket.android.main.presentation.MainPresenter
...@@ -98,6 +99,21 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, ...@@ -98,6 +99,21 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
} }
} }
override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START))
closeDrawer()
else
supportFragmentManager.findFragmentById(R.id.fragment_container)?.let {
if (it !is ChatRoomsFragment && supportFragmentManager.backStackEntryCount==0) {
presenter.toChatList(chatRoomId)
setCheckedNavDrawerItem(R.id.menu_action_chats)
}
else{
super.onBackPressed()
}
}
}
override fun activityInjector(): AndroidInjector<Activity> = activityDispatchingAndroidInjector override fun activityInjector(): AndroidInjector<Activity> = activityDispatchingAndroidInjector
override fun supportFragmentInjector(): AndroidInjector<Fragment> = override fun supportFragmentInjector(): AndroidInjector<Fragment> =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment