Preference: Change nav drawer

Preference
This commit is contained in:
Martin Fietz 2015-04-17 11:12:54 +02:00
parent 85ace6fb01
commit 158821c0e1
5 changed files with 86 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.preferences;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -190,6 +191,15 @@ public class PreferenceController {
}
}
);
ui.findPreference(UserPreferences.PREF_HIDDEN_DRAWER_ITEMS)
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showDrawerPreferencesDialog();
return true;
}
});
ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL)
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
@ -561,6 +571,43 @@ public class PreferenceController {
}
}
private void showDrawerPreferencesDialog() {
final Context context = ui.getActivity();
final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems();
final String[] navTitles = context.getResources().getStringArray(R.array.nav_drawer_titles);
final String[] NAV_DRAWER_TAGS = MainActivity.NAV_DRAWER_TAGS;
boolean[] checked = new boolean[MainActivity.NAV_DRAWER_TAGS.length];
for(int i=0; i < NAV_DRAWER_TAGS.length; i++) {
String tag = NAV_DRAWER_TAGS[i];
if(!hiddenDrawerItems.contains(tag)) {
checked[i] = true;
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.drawer_preferences);
builder.setMultiChoiceItems(navTitles, 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(context, hiddenDrawerItems);
}
});
builder.setNegativeButton(R.string.cancel_label, null);
builder.create().show();
}
public static interface PreferenceUI {

View File

@ -9,6 +9,10 @@
android:key="prefTheme"
android:summary="@string/pref_set_theme_sum"
android:defaultValue="0"/>
<Preference
android:key="prefHiddenDrawerItems"
android:summary="@string/pref_nav_drawer_items_sum"
android:title="@string/pref_nav_drawer_items_title" />
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"

View File

@ -16,6 +16,8 @@ import org.json.JSONException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -63,6 +65,7 @@ public class UserPreferences implements
private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
public static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
public static final String PREF_HIDDEN_DRAWER_ITEMS = "prefHiddenDrawerItems";
// TODO: Make this value configurable
private static final float PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT = 0.8f;
@ -99,6 +102,7 @@ public class UserPreferences implements
private boolean isFreshInstall;
private int notifyPriority;
private boolean persistNotify;
private List<String> hiddenDrawerItems;
private UserPreferences(Context context) {
this.context = context;
@ -167,6 +171,7 @@ public class UserPreferences implements
notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
}
persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
hiddenDrawerItems = Arrays.asList(StringUtils.split(sp.getString(PREF_HIDDEN_DRAWER_ITEMS, ""), ','));
}
private int readThemeValue(String valueFromPrefs) {
@ -355,6 +360,11 @@ public class UserPreferences implements
return instance.rewindSecs;
}
public static List<String> getHiddenDrawerItems() {
instanceAvailable();
return new ArrayList<String>(instance.hiddenDrawerItems);
}
/**
* Returns the capacity of the episode cache. This method will return the
* negative integer EPISODE_CACHE_SIZE_UNLIMITED if the cache size is set to
@ -456,6 +466,8 @@ public class UserPreferences implements
}
} else if (key.equals(PREF_PERSISTENT_NOTIFICATION)) {
persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
} else if (key.equals(PREF_HIDDEN_DRAWER_ITEMS)) {
hiddenDrawerItems = Arrays.asList(StringUtils.split(sp.getString(PREF_HIDDEN_DRAWER_ITEMS, ""), ','));
}
}
@ -532,6 +544,17 @@ public class UserPreferences implements
instance.autoFlattrPlayedDurationThreshold = autoFlattrThreshold;
}
public static void setHiddenDrawerItems(Context context, List<String> items) {
instanceAvailable();
String str = StringUtils.join(items, ',');
PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
.edit()
.putString(PREF_HIDDEN_DRAWER_ITEMS, str)
.commit();
instance.hiddenDrawerItems = items;
}
/**
* Return the folder where the app stores all of its data. This method will
* return the standard data folder if none has been set by the user.

View File

@ -126,4 +126,14 @@
<item>0</item>
<item>1</item>
</string-array>
<string-array name="nav_drawer_titles">
<item>@string/queue_label</item>
<item>@string/new_episodes_label</item>
<item>@string/all_episodes_label</item>
<item>@string/downloads_label</item>
<item>@string/playback_history_label</item>
<item>@string/add_feed_label</item>
</string-array>
</resources>

View File

@ -245,6 +245,8 @@
<string name="pref_auto_flattr_sum">Configure automatic flattring</string>
<string name="user_interface_label">User Interface</string>
<string name="pref_set_theme_title">Select theme</string>
<string name="pref_nav_drawer_items_title">Change navigation drawer</string>
<string name="pref_nav_drawer_items_sum">Change which items appear in the navigation drawer.</string>
<string name="pref_set_theme_sum">Change the appearance of AntennaPod.</string>
<string name="pref_automatic_download_title">Automatic download</string>
<string name="pref_automatic_download_sum">Configure the automatic download of episodes.</string>