From f9d68185e2b18d0c589e578d8f73e3a8a3130b95 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 27 Apr 2018 23:50:11 +0530 Subject: wg: Collapse fab when pressing back before exiting Signed-off-by: Harsh Shandilya --- .../java/com/wireguard/android/activity/MainActivity.java | 13 +++++++++++-- .../com/wireguard/android/fragment/TunnelListFragment.java | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/src/main/java/com/wireguard/android/activity/MainActivity.java b/app/src/main/java/com/wireguard/android/activity/MainActivity.java index c43c0023..bfb3be7e 100644 --- a/app/src/main/java/com/wireguard/android/activity/MainActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/MainActivity.java @@ -63,8 +63,17 @@ public class MainActivity extends BaseActivity { @Override public void onBackPressed() { - if (!moveToState(State.ofLayer(state.layer - 1))) - super.onBackPressed(); + TunnelListFragment fragment = null; + try { + fragment = + ((TunnelListFragment) + getSupportFragmentManager().getFragments().get(0)); + } catch (ClassCastException ignored) { + } + if (fragment == null || !(fragment.collapseActionMenu())) { + if (!moveToState(State.ofLayer(state.layer - 1))) + super.onBackPressed(); + } } @Override diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java index f8a35d89..683a8b6d 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -193,6 +193,14 @@ public class TunnelListFragment extends BaseFragment { super.onDestroyView(); } + public boolean collapseActionMenu() { + if (binding.createMenu.isExpanded()) { + binding.createMenu.collapse(); + return true; + } + return false; + } + public void onRequestCreateConfig(@SuppressWarnings("unused") final View view) { startActivity(new Intent(getActivity(), TunnelCreatorActivity.class)); if (binding != null) -- cgit v1.2.3