Changes due to feedback in pull request #3315

This commit is contained in:
damoasda 2019-08-11 14:07:45 +02:00
parent fe9f0c8e7e
commit c4399de8cb
4 changed files with 23 additions and 24 deletions

View File

@ -378,9 +378,11 @@ public class QueueFragment extends Fragment {
if (keepSortedNew) {
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
QueueSorter.sort(sortOrder, true);
recyclerAdapter.setLocked(true);
} else {
recyclerAdapter.setLocked(UserPreferences.isQueueLocked());
}
// Update sort menu items and list lock elements
getActivity().recreate();
getActivity().invalidateOptionsMenu();
return true;
default:
return false;
@ -393,16 +395,10 @@ public class QueueFragment extends Fragment {
/**
* This method is called if the user clicks on a sort order menu item.
*
* If the queue is in keep sorted mode, the new sort order is stored in the preferences and
* the queue is sorted. Otherwise the queue is just sorted.
*
* @param sortOrder New sort order.
*/
private void setSortOrder(SortOrder sortOrder) {
boolean keepSorted = UserPreferences.isQueueKeepSorted();
if (keepSorted) {
UserPreferences.setQueueKeepSortedOrder(sortOrder);
}
UserPreferences.setQueueKeepSortedOrder(sortOrder);
QueueSorter.sort(sortOrder, true);
}

View File

@ -899,7 +899,7 @@ public class UserPreferences {
*/
public static SortOrder getQueueKeepSortedOrder() {
String sortOrderStr = prefs.getString(PREF_QUEUE_KEEP_SORTED_ORDER, "use-default");
return parseSortOrder(sortOrderStr);
return SortOrder.parseWithDefault(sortOrderStr, SortOrder.DATE_NEW_OLD);
}
/**
@ -915,17 +915,4 @@ public class UserPreferences {
.putString(PREF_QUEUE_KEEP_SORTED_ORDER, sortOrder.name())
.apply();
}
/**
* Converts the string representation to its enum value. If the string value is unknown,
* a default value is retuned.
*/
private static SortOrder parseSortOrder(String value) {
try {
return SortOrder.valueOf(value);
} catch (IllegalArgumentException e) {
// default value
return SortOrder.DATE_NEW_OLD;
}
}
}

View File

@ -416,6 +416,10 @@ public class DBWriter {
// Sort queue by configured sort order
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
if (sortOrder == SortOrder.RANDOM) {
// do not shuffle the list on every change
return;
}
Permutor<FeedItem> permutor = QueueSorter.getPermutor(sortOrder);
permutor.reorder(queue);

View File

@ -14,5 +14,17 @@ public enum SortOrder {
FEED_TITLE_Z_A,
RANDOM,
SMART_SHUFFLE_OLD_NEW,
SMART_SHUFFLE_NEW_OLD
SMART_SHUFFLE_NEW_OLD;
/**
* Converts the string representation to its enum value. If the string value is unknown,
* the given default value is returned.
*/
public static SortOrder parseWithDefault(String value, SortOrder defaultValue) {
try {
return valueOf(value);
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
}