diff --git a/src/main/java/com/nutomic/syncthingandroid/util/DevicesAdapter.java b/src/main/java/com/nutomic/syncthingandroid/util/DevicesAdapter.java index 0162a49b..56dac978 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/DevicesAdapter.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/DevicesAdapter.java @@ -12,6 +12,7 @@ import android.widget.TextView; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.syncthing.RestApi; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,6 +26,13 @@ public class DevicesAdapter extends ArrayAdapter private Map mConnections = new HashMap<>(); + private final static Comparator COMPARATOR = new Comparator() { + @Override + public int compare(RestApi.Device lhs, RestApi.Device rhs) { + return lhs.name.compareTo(rhs.name); + } + }; + public DevicesAdapter(Context context) { super(context, R.layout.device_list_item); } @@ -78,6 +86,15 @@ public class DevicesAdapter extends ArrayAdapter } } + /** + * Sorts adapter after insert. + */ + @Override + public void add(RestApi.Device device) { + super.add(device); + sort(COMPARATOR); + } + /** * Requests new connection info for all devices visible in listView. */ diff --git a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java index 6ee2a414..39128536 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java @@ -11,6 +11,7 @@ import android.widget.TextView; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.syncthing.RestApi; +import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -22,6 +23,13 @@ public class FoldersAdapter extends ArrayAdapter private HashMap mModels = new HashMap<>(); + private final static Comparator COMPARATOR = new Comparator() { + @Override + public int compare(RestApi.Folder lhs, RestApi.Folder rhs) { + return lhs.id.compareTo(rhs.id); + } + }; + public FoldersAdapter(Context context) { super(context, R.layout.folder_list_item); } @@ -78,6 +86,15 @@ public class FoldersAdapter extends ArrayAdapter } } + /** + * Sorts adapter after insert. + */ + @Override + public void add(RestApi.Folder object) { + super.add(object); + sort(COMPARATOR); + } + /** * Requests updated model info from the api for all visible items. */