Refactoring

This commit is contained in:
M66B 2019-04-28 20:48:45 +02:00
parent 259be35c00
commit 681b0bfb48
5 changed files with 73 additions and 38 deletions

View File

@ -43,6 +43,7 @@ import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.documentfile.provider.DocumentFile; import androidx.documentfile.provider.DocumentFile;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -86,7 +87,8 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
private View view; private View view;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;
private ListView drawerList; private ConstraintLayout drawerContainer;
private ListView drawerMenu;
private DrawerAdapter drawerArray; private DrawerAdapter drawerArray;
private boolean hasAccount; private boolean hasAccount;
@ -131,12 +133,13 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
}; };
drawerLayout.addDrawerListener(drawerToggle); 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); drawerArray = new DrawerAdapter(this, false);
drawerList.setAdapter(drawerArray); drawerMenu.setAdapter(drawerArray);
drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { drawerMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position); DrawerItem item = drawerArray.getItem(position);
@ -176,7 +179,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
break; break;
} }
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(drawerContainer);
} }
}); });
@ -264,8 +267,8 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (drawerLayout.isDrawerOpen(drawerList)) if (drawerLayout.isDrawerOpen(drawerContainer))
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(drawerContainer);
else else
super.onBackPressed(); super.onBackPressed();
} }
@ -278,8 +281,8 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
startActivity(new Intent(this, ActivityView.class)); startActivity(new Intent(this, ActivityView.class));
finish(); finish();
} else { } else {
if (drawerLayout.isDrawerOpen(drawerList)) if (drawerLayout.isDrawerOpen(drawerContainer))
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(drawerContainer);
drawerToggle.setDrawerIndicatorEnabled(count == 1); drawerToggle.setDrawerIndicatorEnabled(count == 1);
} }
} }

View File

@ -50,6 +50,7 @@ import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.documentfile.provider.DocumentFile; import androidx.documentfile.provider.DocumentFile;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
@ -101,7 +102,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private Group grpPane; private Group grpPane;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;
private ListView drawerList; private ConstraintLayout drawerContainer;
private ListView drawerMenu;
private DrawerAdapter drawerArray; private DrawerAdapter drawerArray;
private long message = -1; private long message = -1;
@ -175,14 +177,15 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}; };
drawerLayout.addDrawerListener(drawerToggle); 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); boolean minimal = prefs.getBoolean("minimal", false);
drawerArray = new DrawerAdapter(this, minimal); drawerArray = new DrawerAdapter(this, minimal);
drawerList.setAdapter(drawerArray); drawerMenu.setAdapter(drawerArray);
drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { drawerMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position); DrawerItem item = drawerArray.getItem(position);
@ -235,11 +238,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
onMenuOutbox(); onMenuOutbox();
} }
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(drawerContainer);
} }
}); });
drawerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { drawerMenu.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position); DrawerItem item = drawerArray.getItem(position);
@ -272,7 +275,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
onMenuInbox(account); onMenuInbox(account);
} }
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(drawerContainer);
return true; return true;
} }
}); });
@ -603,8 +606,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (drawerLayout.isDrawerOpen(drawerList)) if (drawerLayout.isDrawerOpen(drawerContainer))
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(drawerContainer);
else else
super.onBackPressed(); super.onBackPressed();
} }
@ -615,8 +618,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if (count == 0) if (count == 0)
finish(); finish();
else { else {
if (drawerLayout.isDrawerOpen(drawerList)) if (drawerLayout.isDrawerOpen(drawerContainer))
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(drawerContainer);
drawerToggle.setDrawerIndicatorEnabled(count == 1); drawerToggle.setDrawerIndicatorEnabled(count == 1);
if (grpPane != null) { if (grpPane != null) {

View File

@ -43,13 +43,22 @@
app:constraint_referenced_ids="content_separator,content_pane" /> app:constraint_referenced_ids="content_separator,content_pane" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<ListView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/drawer_list" android:id="@+id/drawer_container"
android:layout_width="270dp" android:layout_width="270dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"
android:background="?attr/colorDrawerBackground" android:background="?attr/colorDrawerBackground">
android:choiceMode="singleChoice"
android:divider="@android:color/transparent" <ListView
android:dividerHeight="0dp" /> android:id="@+id/drawer_menu"
android:layout_width="match_parent"
android:layout_height="0dp"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout> </androidx.drawerlayout.widget.DrawerLayout>

View File

@ -1,4 +1,5 @@
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -10,13 +11,22 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<ListView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/drawer_list" android:id="@+id/drawer_container"
android:layout_width="270dp" android:layout_width="270dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"
android:background="?attr/colorDrawerBackground" android:background="?attr/colorDrawerBackground">
android:choiceMode="singleChoice"
android:divider="@android:color/transparent" <ListView
android:dividerHeight="0dp" /> android:id="@+id/drawer_menu"
android:layout_width="match_parent"
android:layout_height="0dp"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout> </androidx.drawerlayout.widget.DrawerLayout>

View File

@ -1,4 +1,5 @@
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -10,13 +11,22 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<ListView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/drawer_list" android:id="@+id/drawer_container"
android:layout_width="270dp" android:layout_width="270dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"
android:background="?attr/colorDrawerBackground" android:background="?attr/colorDrawerBackground">
android:choiceMode="singleChoice"
android:divider="@android:color/transparent" <ListView
android:dividerHeight="0dp" /> android:id="@+id/drawer_menu"
android:layout_width="match_parent"
android:layout_height="0dp"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout> </androidx.drawerlayout.widget.DrawerLayout>