From 681b0bfb48d9bd3ba4ff0e68c4431cba272ce32c Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 28 Apr 2019 20:48:45 +0200 Subject: [PATCH] Refactoring --- .../java/eu/faircode/email/ActivitySetup.java | 21 +++++++++------- .../java/eu/faircode/email/ActivityView.java | 25 +++++++++++-------- .../res/layout-w600dp-land/activity_view.xml | 21 +++++++++++----- app/src/main/res/layout/activity_setup.xml | 22 +++++++++++----- app/src/main/res/layout/activity_view.xml | 22 +++++++++++----- 5 files changed, 73 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index b65badafcf..0a17ae5417 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -43,6 +43,7 @@ import android.widget.RadioGroup; import android.widget.TextView; import androidx.appcompat.app.ActionBarDrawerToggle; +import androidx.constraintlayout.widget.ConstraintLayout; import androidx.documentfile.provider.DocumentFile; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.FragmentManager; @@ -86,7 +87,8 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On private View view; private DrawerLayout drawerLayout; private ActionBarDrawerToggle drawerToggle; - private ListView drawerList; + private ConstraintLayout drawerContainer; + private ListView drawerMenu; private DrawerAdapter drawerArray; private boolean hasAccount; @@ -131,12 +133,13 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On }; drawerLayout.addDrawerListener(drawerToggle); - drawerList = findViewById(R.id.drawer_list); + drawerContainer = findViewById(R.id.drawer_container); + drawerMenu = drawerContainer.findViewById(R.id.drawer_menu); drawerArray = new DrawerAdapter(this, false); - drawerList.setAdapter(drawerArray); + drawerMenu.setAdapter(drawerArray); - drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + drawerMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { DrawerItem item = drawerArray.getItem(position); @@ -176,7 +179,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On break; } - drawerLayout.closeDrawer(drawerList); + drawerLayout.closeDrawer(drawerContainer); } }); @@ -264,8 +267,8 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On @Override public void onBackPressed() { - if (drawerLayout.isDrawerOpen(drawerList)) - drawerLayout.closeDrawer(drawerList); + if (drawerLayout.isDrawerOpen(drawerContainer)) + drawerLayout.closeDrawer(drawerContainer); else super.onBackPressed(); } @@ -278,8 +281,8 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On startActivity(new Intent(this, ActivityView.class)); finish(); } else { - if (drawerLayout.isDrawerOpen(drawerList)) - drawerLayout.closeDrawer(drawerList); + if (drawerLayout.isDrawerOpen(drawerContainer)) + drawerLayout.closeDrawer(drawerContainer); drawerToggle.setDrawerIndicatorEnabled(count == 1); } } diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 66720392a4..bcb6b876fb 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -50,6 +50,7 @@ import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBarDrawerToggle; +import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.Group; import androidx.documentfile.provider.DocumentFile; import androidx.drawerlayout.widget.DrawerLayout; @@ -101,7 +102,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private Group grpPane; private DrawerLayout drawerLayout; private ActionBarDrawerToggle drawerToggle; - private ListView drawerList; + private ConstraintLayout drawerContainer; + private ListView drawerMenu; private DrawerAdapter drawerArray; private long message = -1; @@ -175,14 +177,15 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB }; drawerLayout.addDrawerListener(drawerToggle); - drawerList = findViewById(R.id.drawer_list); + drawerContainer = findViewById(R.id.drawer_container); + drawerMenu = drawerContainer.findViewById(R.id.drawer_menu); boolean minimal = prefs.getBoolean("minimal", false); drawerArray = new DrawerAdapter(this, minimal); - drawerList.setAdapter(drawerArray); + drawerMenu.setAdapter(drawerArray); - drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + drawerMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { DrawerItem item = drawerArray.getItem(position); @@ -235,11 +238,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB onMenuOutbox(); } - drawerLayout.closeDrawer(drawerList); + drawerLayout.closeDrawer(drawerContainer); } }); - drawerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + drawerMenu.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { DrawerItem item = drawerArray.getItem(position); @@ -272,7 +275,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB onMenuInbox(account); } - drawerLayout.closeDrawer(drawerList); + drawerLayout.closeDrawer(drawerContainer); return true; } }); @@ -603,8 +606,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB @Override public void onBackPressed() { - if (drawerLayout.isDrawerOpen(drawerList)) - drawerLayout.closeDrawer(drawerList); + if (drawerLayout.isDrawerOpen(drawerContainer)) + drawerLayout.closeDrawer(drawerContainer); else super.onBackPressed(); } @@ -615,8 +618,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB if (count == 0) finish(); else { - if (drawerLayout.isDrawerOpen(drawerList)) - drawerLayout.closeDrawer(drawerList); + if (drawerLayout.isDrawerOpen(drawerContainer)) + drawerLayout.closeDrawer(drawerContainer); drawerToggle.setDrawerIndicatorEnabled(count == 1); if (grpPane != null) { diff --git a/app/src/main/res/layout-w600dp-land/activity_view.xml b/app/src/main/res/layout-w600dp-land/activity_view.xml index c49c2b9004..e1c6e9ffb2 100644 --- a/app/src/main/res/layout-w600dp-land/activity_view.xml +++ b/app/src/main/res/layout-w600dp-land/activity_view.xml @@ -43,13 +43,22 @@ app:constraint_referenced_ids="content_separator,content_pane" /> - + android:background="?attr/colorDrawerBackground"> + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_setup.xml b/app/src/main/res/layout/activity_setup.xml index 2f16046eca..b1141b381c 100644 --- a/app/src/main/res/layout/activity_setup.xml +++ b/app/src/main/res/layout/activity_setup.xml @@ -1,4 +1,5 @@ - + android:background="?attr/colorDrawerBackground"> + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_view.xml b/app/src/main/res/layout/activity_view.xml index b3c57ae15b..ec2d972a5a 100644 --- a/app/src/main/res/layout/activity_view.xml +++ b/app/src/main/res/layout/activity_view.xml @@ -1,4 +1,5 @@ - + android:background="?attr/colorDrawerBackground"> + + + \ No newline at end of file