From efe9a8fa674cba3e13b8fe1530416bc5b3169020 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 23 Apr 2020 12:38:18 +0200 Subject: [PATCH] Make drawer owner for live updates --- .../java/eu/faircode/email/ActivityView.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 8ad862c861..b3e110b79f 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -90,6 +90,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private View content_separator; private View content_pane; + private TwoStateOwner owner = new TwoStateOwner("drawer"); private DrawerLayoutEx drawerLayout; private ActionBarDrawerToggle drawerToggle; private ScrollView drawerContainer; @@ -169,13 +170,19 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB final ViewGroup childDrawer = (ViewGroup) drawerLayout.getChildAt(1); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.app_name, R.string.app_name) { public void onDrawerClosed(View view) { + owner.stop(); + drawerLayout.setDrawerLockMode(LOCK_MODE_UNLOCKED); childContent.setPaddingRelative(0, 0, 0, 0); + super.onDrawerClosed(view); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); + + owner.start(); + if (normal && landscape && landscape3 && config.orientation == Configuration.ORIENTATION_LANDSCAPE) { drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_OPEN); @@ -186,6 +193,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); + + if (slideOffset > 0) + owner.start(); + else + owner.stop(); + if (normal && landscape && landscape3 && config.orientation == Configuration.ORIENTATION_LANDSCAPE) childContent.setPaddingRelative( @@ -364,8 +377,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB drawerLayout.setup(getResources().getConfiguration(), drawerContainer, drawerToggle); drawerToggle.syncState(); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - // Fixed menus PackageManager pm = getPackageManager(); @@ -540,7 +551,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB DB db = DB.getInstance(this); - db.account().liveAccountsEx(false).observe(this, new Observer>() { + db.account().liveAccountsEx(false).observe(owner, new Observer>() { @Override public void onChanged(@Nullable List accounts) { if (accounts == null) @@ -549,7 +560,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }); - db.folder().liveUnified().observe(this, new Observer>() { + db.folder().liveUnified().observe(owner, new Observer>() { @Override public void onChanged(List folders) { if (folders == null) @@ -558,7 +569,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }); - db.folder().liveNavigation().observe(this, new Observer>() { + db.folder().liveNavigation().observe(owner, new Observer>() { @Override public void onChanged(List folders) { if (folders == null) @@ -567,7 +578,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }); - db.operation().liveStats().observe(this, new Observer() { + db.operation().liveStats().observe(owner, new Observer() { @Override public void onChanged(TupleOperationStats stats) { navOperations.setWarning(stats != null && stats.errors != null && stats.errors > 0);