Allow collapsing part of main navigation menu

pull/156/head
M66B 5 years ago
parent 27af5265f0
commit b0cfb2f1e7

@ -85,8 +85,9 @@ import javax.crypto.spec.PBEKeySpec;
public class ActivitySetup extends ActivityBilling implements FragmentManager.OnBackStackChangedListener {
private View view;
private DrawerLayout drawerLayout;
private ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
private ListView drawerList;
private DrawerAdapter drawerArray;
private boolean hasAccount;
private String password;
@ -132,7 +133,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
drawerList = findViewById(R.id.drawer_list);
final DrawerAdapter drawerArray = new DrawerAdapter(this);
drawerArray = new DrawerAdapter(this, false);
drawerList.setAdapter(drawerArray);
drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@ -99,10 +99,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private String startup;
private View view;
private DrawerLayout drawerLayout;
private Group grpPane;
private ListView drawerList;
private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle;
private ListView drawerList;
private DrawerAdapter drawerArray;
private long message = -1;
private long attachment = -1;
@ -157,11 +158,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
grpPane = findViewById(R.id.grpPane);
drawerLayout = findViewById(R.id.drawer_layout);
drawerLayout.setScrimColor(Helper.resolveColor(this, R.attr.colorDrawerScrim));
grpPane = findViewById(R.id.grpPane);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.app_name, R.string.app_name) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
@ -177,7 +178,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
drawerList = findViewById(R.id.drawer_list);
final DrawerAdapter drawerArray = new DrawerAdapter(ActivityView.this);
boolean minimal = prefs.getBoolean("minimal", false);
drawerArray = new DrawerAdapter(this, minimal);
drawerList.setAdapter(drawerArray);
drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@ -198,6 +201,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
case R.string.menu_setup:
onMenuSetup();
break;
case R.string.title_legend_expander:
onMenuCollapse();
return;
case R.string.menu_legend:
onMenuLegend();
break;
@ -351,18 +357,19 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
items.add(new DrawerItem(-5, R.drawable.baseline_settings_applications_24, R.string.menu_setup));
items.add(new DrawerItem(-6));
items.add(new DrawerItem(-7, R.drawable.baseline_help_24, R.string.menu_legend));
items.add(new DrawerItem(-7, R.string.title_legend_expander));
items.add(new DrawerItem(-8, R.drawable.baseline_help_24, R.string.menu_legend).setCollapsible());
if (Helper.getIntentFAQ().resolveActivity(getPackageManager()) != null)
items.add(new DrawerItem(-8, R.drawable.baseline_question_answer_24, R.string.menu_faq));
items.add(new DrawerItem(-9, R.drawable.baseline_question_answer_24, R.string.menu_faq).setCollapsible());
if (BuildConfig.BETA_RELEASE)
items.add(new DrawerItem(-9, R.drawable.baseline_report_problem_24, R.string.menu_issue));
items.add(new DrawerItem(-10, R.drawable.baseline_report_problem_24, R.string.menu_issue).setCollapsible());
if (Helper.getIntentPrivacy().resolveActivity(getPackageManager()) != null)
items.add(new DrawerItem(-10, R.drawable.baseline_account_box_24, R.string.menu_privacy));
items.add(new DrawerItem(-11, R.drawable.baseline_account_box_24, R.string.menu_privacy).setCollapsible());
items.add(new DrawerItem(-11, R.drawable.baseline_info_24, R.string.menu_about));
items.add(new DrawerItem(-12, R.drawable.baseline_info_24, R.string.menu_about).setCollapsible());
boolean pro = (getIntentPro() == null || getIntentPro().resolveActivity(getPackageManager()) != null);
boolean invite = (getIntentInvite().resolveActivity(getPackageManager()) != null);
@ -370,19 +377,19 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
boolean other = (getIntentOtherApps().resolveActivity(getPackageManager()) != null);
if (pro || invite || rate || other)
items.add(new DrawerItem(-12));
items.add(new DrawerItem(-13).setCollapsible());
if (pro)
items.add(new DrawerItem(-13, R.drawable.baseline_monetization_on_24, R.string.menu_pro));
items.add(new DrawerItem(-14, R.drawable.baseline_monetization_on_24, R.string.menu_pro).setCollapsible());
if (invite)
items.add(new DrawerItem(-14, R.drawable.baseline_people_24, R.string.menu_invite));
items.add(new DrawerItem(-15, R.drawable.baseline_people_24, R.string.menu_invite).setCollapsible());
if (rate)
items.add(new DrawerItem(-15, R.drawable.baseline_star_24, R.string.menu_rate));
items.add(new DrawerItem(-16, R.drawable.baseline_star_24, R.string.menu_rate).setCollapsible());
if (other)
items.add(new DrawerItem(-16, R.drawable.baseline_get_app_24, R.string.menu_other));
items.add(new DrawerItem(-17, R.drawable.baseline_get_app_24, R.string.menu_other).setCollapsible());
drawerArray.set(items);
}
@ -954,6 +961,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
startActivity(new Intent(ActivityView.this, ActivitySetup.class));
}
private void onMenuCollapse() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean minimal = !prefs.getBoolean("minimal", false);
prefs.edit().putBoolean("minimal", minimal).apply();
drawerArray.set(minimal);
drawerArray.notifyDataSetChanged();
}
private void onMenuLegend() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getSupportFragmentManager().popBackStack("legend", FragmentManager.POP_BACK_STACK_INCLUSIVE);

@ -15,10 +15,12 @@ import java.util.ArrayList;
import java.util.List;
public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
private boolean collapsed = false;
private List<DrawerItem> items = new ArrayList<>();
DrawerAdapter(@NonNull Context context) {
DrawerAdapter(@NonNull Context context, boolean collapsed) {
super(context, -1);
this.collapsed = collapsed;
}
@NonNull
@ -28,6 +30,7 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
ImageView iv = row.findViewById(R.id.ivItem);
TextView tv = row.findViewById(R.id.tvItem);
ImageView expander = row.findViewById(R.id.ivExpander);
if (iv != null) {
iv.setImageResource(item.getIcon());
@ -42,9 +45,19 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
item.getHighlight() ? R.attr.colorUnread : android.R.attr.textColorSecondary));
}
if (expander != null)
expander.setImageLevel(collapsed ? 1 /* more */ : 0 /* less */);
row.setVisibility(item.isCollapsible() && collapsed ? View.GONE : View.VISIBLE);
return row;
}
void set(boolean collapsed) {
this.collapsed = collapsed;
notifyDataSetChanged();
}
void set(List<DrawerItem> items) {
this.items = items;
notifyDataSetChanged();
@ -74,10 +87,4 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
DrawerItem item = getItem(position);
return (item == null ? 0 : item.getId());
}
@Override
public boolean isEnabled(int position) {
DrawerItem item = getItem(position);
return (item != null && item.isEnabled());
}
}

@ -11,12 +11,19 @@ public class DrawerItem {
private int resid;
private String title;
private boolean highlight;
private boolean collapsible = false;
DrawerItem(long id) {
this.id = id;
this.layout = R.layout.item_drawer_separator;
}
DrawerItem(long id, int resid) {
this.id = id;
this.menu = resid;
this.layout = R.layout.item_drawer_expander;
}
DrawerItem(long id, int icon, int resid) {
this.id = id;
this.menu = resid;
@ -43,6 +50,11 @@ public class DrawerItem {
this.highlight = highlight;
}
DrawerItem setCollapsible() {
this.collapsible = true;
return this;
}
int getLayout() {
return this.layout;
}
@ -76,4 +88,8 @@ public class DrawerItem {
boolean getHighlight() {
return this.highlight;
}
boolean isCollapsible() {
return this.collapsible;
}
}

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivExpander"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:contentDescription="@string/title_legend_expander"
android:src="@drawable/expander"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save