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 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);
}
}

View File

@ -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) {

View File

@ -43,13 +43,22 @@
app:constraint_referenced_ids="content_separator,content_pane" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ListView
android:id="@+id/drawer_list"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/drawer_container"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/colorDrawerBackground"
android:background="?attr/colorDrawerBackground">
<ListView
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" />
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>

View File

@ -1,4 +1,5 @@
<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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
@ -10,13 +11,22 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/drawer_list"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/drawer_container"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/colorDrawerBackground"
android:background="?attr/colorDrawerBackground">
<ListView
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" />
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>

View File

@ -1,4 +1,5 @@
<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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
@ -10,13 +11,22 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/drawer_list"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/drawer_container"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/colorDrawerBackground"
android:background="?attr/colorDrawerBackground">
<ListView
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" />
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>