1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Sort folders and devices lists (fixes #424).

This commit is contained in:
Felix Ableitner 2015-07-09 22:47:50 +02:00
parent 8a74770fa0
commit 74dd373f87
2 changed files with 34 additions and 0 deletions

View file

@ -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<RestApi.Device>
private Map<String, RestApi.Connection> mConnections =
new HashMap<>();
private final static Comparator<RestApi.Device> COMPARATOR = new Comparator<RestApi.Device>() {
@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<RestApi.Device>
}
}
/**
* 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.
*/

View file

@ -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<RestApi.Folder>
private HashMap<String, RestApi.Model> mModels = new HashMap<>();
private final static Comparator<RestApi.Folder> COMPARATOR = new Comparator<RestApi.Folder>() {
@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<RestApi.Folder>
}
}
/**
* 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.
*/