From 3a8346b9a5299502e496f1b8047db9cc36bee171 Mon Sep 17 00:00:00 2001 From: Cedric Staniewski Date: Sun, 3 Jul 2016 20:48:24 +0200 Subject: [PATCH] Sort folders by label If the label is empty or unset, use the folder ID in comparision. --- .../syncthingandroid/fragments/FolderListFragment.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java index a6e91e07..c5236562 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java @@ -29,10 +29,16 @@ import java.util.TimerTask; public class FolderListFragment extends ListFragment implements SyncthingService.OnApiChangeListener, AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener { + /** + * Compares folders by labels, uses the folder ID as fallback if the label is empty + */ private final static Comparator FOLDERS_COMPARATOR = new Comparator() { @Override public int compare(RestApi.Folder lhs, RestApi.Folder rhs) { - return lhs.id.compareTo(rhs.id); + String lhsLabel = lhs.label != null && !lhs.label.isEmpty() ? lhs.label : lhs.id; + String rhsLabel = rhs.label != null && !rhs.label.isEmpty() ? rhs.label : rhs.id; + + return lhsLabel.compareTo(rhsLabel); } };