mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-27 06:41:15 +00:00
Sort folders and devices lists (fixes #424).
This commit is contained in:
parent
8a74770fa0
commit
74dd373f87
2 changed files with 34 additions and 0 deletions
|
@ -12,6 +12,7 @@ import android.widget.TextView;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -25,6 +26,13 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
|
||||||
private Map<String, RestApi.Connection> mConnections =
|
private Map<String, RestApi.Connection> mConnections =
|
||||||
new HashMap<>();
|
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) {
|
public DevicesAdapter(Context context) {
|
||||||
super(context, R.layout.device_list_item);
|
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.
|
* Requests new connection info for all devices visible in listView.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.widget.TextView;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -22,6 +23,13 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
||||||
|
|
||||||
private HashMap<String, RestApi.Model> mModels = new HashMap<>();
|
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) {
|
public FoldersAdapter(Context context) {
|
||||||
super(context, R.layout.folder_list_item);
|
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.
|
* Requests updated model info from the api for all visible items.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue