Add longclick Drawer Preference dialog

This commit is contained in:
Martin Fietz 2015-04-17 11:20:58 +02:00
parent ea628037ca
commit ded0006913
2 changed files with 50 additions and 0 deletions

View File

@ -160,6 +160,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
navAdapter = new NavListAdapter(itemAccess, this);
navList.setAdapter(navAdapter);
navList.setOnItemClickListener(navListClickListener);
navList.setOnItemLongClickListener(newListLongClickListener);
findViewById(R.id.nav_settings).setOnClickListener(new View.OnClickListener() {
@Override
@ -200,6 +201,41 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
}
}
public void showDrawerPreferencesDialog() {
final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems();
String[] navLabels = new String[NAV_DRAWER_TAGS.length];
final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length];
for (int i = 0; i < NAV_DRAWER_TAGS.length; i++) {
String tag = NAV_DRAWER_TAGS[i];
navLabels[i] = navAdapter.getLabel(tag);
if (!hiddenDrawerItems.contains(tag)) {
checked[i] = true;
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(R.string.drawer_preferences);
builder.setMultiChoiceItems(navLabels, checked, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]);
} else {
hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]);
}
}
});
builder.setPositiveButton(R.string.confirm_label, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UserPreferences.setHiddenDrawerItems(MainActivity.this, hiddenDrawerItems);
}
});
builder.setNegativeButton(R.string.cancel_label, null);
builder.create().show();
}
public ActionBar getMainActivtyActionBar() {
return getSupportActionBar();
}
@ -314,6 +350,19 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
}
};
private AdapterView.OnItemLongClickListener newListLongClickListener = new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if(position < navAdapter.getTags().size()) {
showDrawerPreferencesDialog();
return true;
} else {
return false;
}
}
};
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);

View File

@ -32,6 +32,7 @@
<!-- Main activity -->
<string name="drawer_open">Open menu</string>
<string name="drawer_close">Close menu</string>
<string name="drawer_preferences">Drawer Preferences</string>
<!-- Webview actions -->
<string name="open_in_browser_label">Open in browser</string>