From c59ee9e137a13f9c9ad772cca96ede365e6f3ed7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 3 Apr 2018 17:53:08 +0200 Subject: [PATCH] provide up navigation in start conversation activity --- .../ui/StartConversationActivity.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 01de9a8f0..8a7ea91d1 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -571,6 +571,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU return false; } switch (item.getItemId()) { + case android.R.id.home: + navigateBack(); + return true; case R.id.action_join_conference: showJoinConferenceDialog(null); return true; @@ -688,6 +691,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } } + private void configureHomeButton() { + final ActionBar actionBar = getSupportActionBar(); + if (actionBar == null) { + return; + } + boolean openConversations = !xmppConnectionService.isConversationsListEmpty(null); + actionBar.setDisplayHomeAsUpEnabled(openConversations); + actionBar.setDisplayHomeAsUpEnabled(openConversations); + + } + @Override protected void onBackendConnected() { if (mPostponedActivityResult != null) { @@ -704,13 +718,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } } } - final ActionBar ab = getSupportActionBar(); - boolean noConversations = xmppConnectionService.getConversations().size() == 0; - if (noConversations && ab != null) { - ab.setDisplayShowHomeEnabled(false); - ab.setDisplayHomeAsUpEnabled(false); - ab.setHomeButtonEnabled(false); - } + configureHomeButton(); Intent intent = pendingViewIntent.pop(); if (intent != null && processViewIntent(intent)) { filter(null); @@ -883,6 +891,21 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU if (mSearchEditText != null) { filter(mSearchEditText.getText().toString()); } + configureHomeButton(); + } + + @Override + public void onBackPressed() { + navigateBack(); + } + + private void navigateBack() { + if (xmppConnectionService != null && !xmppConnectionService.isConversationsListEmpty(null)) { + Intent intent = new Intent(this, ConversationsActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + finish(); } @Override