diff options
author | Martin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de> | 2015-04-17 11:20:58 +0200 |
---|---|---|
committer | Martin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de> | 2015-04-18 22:12:39 +0200 |
commit | ded0006913768fa43390816f4fd0abc214a67718 (patch) | |
tree | 2a653a8cf63f5f4dcc4453cc9d8536b3d6dbc52e /app/src | |
parent | ea628037ca3f9de84744ce0d28d8af7fc06a11dd (diff) | |
download | AntennaPod-ded0006913768fa43390816f4fd0abc214a67718.zip |
Add longclick Drawer Preference dialog
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index c5ad49f6d..6411f0318 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -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); |