mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Removed unneeded compatibility functions, moved sorting into fragments.
This commit is contained in:
parent
494f98ee5c
commit
deda1582df
4 changed files with 28 additions and 59 deletions
|
@ -13,9 +13,13 @@ import android.widget.ListView;
|
|||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
||||
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||
import com.nutomic.syncthingandroid.util.DevicesAdapter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -25,6 +29,13 @@ import java.util.TimerTask;
|
|||
public class DeviceListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
|
||||
ListView.OnItemClickListener {
|
||||
|
||||
private final static Comparator<RestApi.Device> DEVICES_COMPARATOR = new Comparator<RestApi.Device>() {
|
||||
@Override
|
||||
public int compare(RestApi.Device lhs, RestApi.Device rhs) {
|
||||
return lhs.name.compareTo(rhs.name);
|
||||
}
|
||||
};
|
||||
|
||||
private DevicesAdapter mAdapter;
|
||||
|
||||
private Timer mTimer;
|
||||
|
@ -94,7 +105,9 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
|
|||
}
|
||||
|
||||
mAdapter.clear();
|
||||
mAdapter.add(activity.getApi().getDevices(false));
|
||||
List<RestApi.Device> devices = activity.getApi().getDevices(false);
|
||||
Collections.sort(devices, DEVICES_COMPARATOR);
|
||||
mAdapter.addAll(devices);
|
||||
mAdapter.updateConnections(activity.getApi());
|
||||
setListShown(true);
|
||||
}
|
||||
|
|
|
@ -13,9 +13,13 @@ import android.widget.AdapterView;
|
|||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
||||
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||
import com.nutomic.syncthingandroid.util.FoldersAdapter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -25,6 +29,13 @@ import java.util.TimerTask;
|
|||
public class FolderListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
|
||||
AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
|
||||
|
||||
private final static Comparator<RestApi.Folder> FOLDERS_COMPARATOR = new Comparator<RestApi.Folder>() {
|
||||
@Override
|
||||
public int compare(RestApi.Folder lhs, RestApi.Folder rhs) {
|
||||
return lhs.id.compareTo(rhs.id);
|
||||
}
|
||||
};
|
||||
|
||||
private FoldersAdapter mAdapter;
|
||||
|
||||
private Timer mTimer;
|
||||
|
@ -95,7 +106,9 @@ public class FolderListFragment extends ListFragment implements SyncthingService
|
|||
}
|
||||
|
||||
mAdapter.clear();
|
||||
mAdapter.add(activity.getApi().getFolders());
|
||||
List<RestApi.Folder> folders = activity.getApi().getFolders();
|
||||
Collections.sort(folders, FOLDERS_COMPARATOR);
|
||||
mAdapter.addAll(folders);
|
||||
mAdapter.updateModel(activity.getApi());
|
||||
setListShown(true);
|
||||
}
|
||||
|
|
|
@ -6,15 +6,12 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -26,13 +23,6 @@ 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.item_device_list);
|
||||
}
|
||||
|
@ -77,24 +67,6 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
|
|||
return convertView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replacement for addAll, which is not implemented on lower API levels.
|
||||
*/
|
||||
public void add(List<RestApi.Device> devices) {
|
||||
for (RestApi.Device n : devices) {
|
||||
add(n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
|
|
@ -2,21 +2,17 @@ package com.nutomic.syncthingandroid.util;
|
|||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nutomic.syncthingandroid.BuildConfig;
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
@ -31,13 +27,6 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
|||
private HashMap<String, RestApi.Model> mModels = new HashMap<>();
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
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.item_folder_list);
|
||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
@ -101,24 +90,6 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
|||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Replacement for addAll, which is not implemented on lower API levels.
|
||||
*/
|
||||
public void add(List<RestApi.Folder> devices) {
|
||||
for (RestApi.Folder r : devices) {
|
||||
add(r);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue