add feed sort menu item

This commit is contained in:
asdoi 2020-09-03 13:16:48 +02:00
parent d9814d2563
commit bd0d0b5008
5 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,40 @@
package de.danoeh.antennapod.dialog;
import android.content.Context;
import androidx.appcompat.app.AlertDialog;
import org.greenrobot.eventbus.EventBus;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.core.preferences.UserPreferences;
public class FeedSortDialog {
public static void showDialog(Context context) {
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(context.getString(R.string.pref_nav_drawer_feed_order_title));
dialog.setNegativeButton(android.R.string.cancel, (d, listener) -> d.dismiss());
int selectedIndexTemp = 0;
int selected = UserPreferences.getFeedOrder();
String[] entryValues = context.getResources().getStringArray(R.array.nav_drawer_feed_order_values);
for (int i = 0; i < entryValues.length; i++) {
if (Integer.parseInt(entryValues[i]) == selected) {
selectedIndexTemp = i;
}
}
final int selectedIndex = selectedIndexTemp;
String[] items = context.getResources().getStringArray(R.array.nav_drawer_feed_order_options);
dialog.setSingleChoiceItems(items, selectedIndex, (d, which) -> {
if (selectedIndex != which) {
UserPreferences.setFeedOrder(entryValues[which]);
//Update subscriptions
EventBus.getDefault().post(new UnreadItemsUpdateEvent());
}
d.dismiss();
});
dialog.show();
}
}

View File

@ -46,6 +46,7 @@ import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
import de.danoeh.antennapod.dialog.FeedFilterDialog;
import de.danoeh.antennapod.dialog.FeedSortDialog;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.view.EmptyViewHandler;
@ -131,6 +132,8 @@ public class SubscriptionFragment extends Fragment {
case R.id.subscriptions_filter:
FeedFilterDialog.showDialog(requireContext());
return true;
case R.id.subscriptions_sort:
FeedSortDialog.showDialog(requireContext());
case R.id.subscription_num_columns_2:
setColumnNumber(2);
return true;

View File

@ -14,6 +14,10 @@
android:id="@+id/subscriptions_filter"
android:title="@string/filter"
custom:showAsAction="never" />
<item
android:id="@+id/subscriptions_sort"
android:title="@string/sort_order"
custom:showAsAction="never" />
<item
android:id="@+id/subscription_num_columns"
android:title="@string/subscription_num_columns"

View File

@ -246,6 +246,12 @@ public class UserPreferences {
return Integer.parseInt(value);
}
public static void setFeedOrder(String selected) {
prefs.edit()
.putString(PREF_DRAWER_FEED_ORDER, selected)
.commit();
}
public static int getFeedCounterSetting() {
String value = prefs.getString(PREF_DRAWER_FEED_COUNTER, "" + FEED_COUNTER_SHOW_NEW);
return Integer.parseInt(value);

View File

@ -723,6 +723,7 @@
<string name="search_powered_by">Search powered by %1$s</string>
<string name="filter">Filter</string>
<string name="sort_order">Sort order</string>
<!-- Episodes apply actions -->
<string name="all_label">All</string>