1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Always sort folders (fixes #902)

This commit is contained in:
Felix Ableitner 2017-06-07 17:14:44 +09:00
parent 755e581eb3
commit 941f9aa0c8
2 changed files with 15 additions and 14 deletions

View file

@ -16,8 +16,6 @@ import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.service.SyncthingService; import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.views.FoldersAdapter; import com.nutomic.syncthingandroid.views.FoldersAdapter;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@ -28,16 +26,6 @@ import java.util.TimerTask;
public class FolderListFragment extends ListFragment implements SyncthingService.OnApiChangeListener, public class FolderListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
AdapterView.OnItemClickListener { AdapterView.OnItemClickListener {
/**
* Compares folders by labels, uses the folder ID as fallback if the label is empty
*/
private final static Comparator<Folder> FOLDERS_COMPARATOR = (lhs, rhs) -> {
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);
};
private FoldersAdapter mAdapter; private FoldersAdapter mAdapter;
private Timer mTimer; private Timer mTimer;
@ -96,7 +84,6 @@ public class FolderListFragment extends ListFragment implements SyncthingService
mAdapter.setNotifyOnChange(false); mAdapter.setNotifyOnChange(false);
mAdapter.clear(); mAdapter.clear();
List<Folder> folders = activity.getApi().getFolders(); List<Folder> folders = activity.getApi().getFolders();
Collections.sort(folders, FOLDERS_COMPARATOR);
mAdapter.addAll(folders); mAdapter.addAll(folders);
mAdapter.updateModel(activity.getApi()); mAdapter.updateModel(activity.getApi());
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();

View file

@ -34,6 +34,8 @@ import com.nutomic.syncthingandroid.util.FolderObserver;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URL; import java.net.URL;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -48,6 +50,16 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
private static final String TAG = "RestApi"; private static final String TAG = "RestApi";
/**
* Compares folders by labels, uses the folder ID as fallback if the label is empty
*/
private final static Comparator<Folder> FOLDERS_COMPARATOR = (lhs, rhs) -> {
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);
};
public interface OnConfigChangedListener { public interface OnConfigChangedListener {
void onConfigChanged(); void onConfigChanged();
} }
@ -200,7 +212,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
} }
public List<Folder> getFolders() { public List<Folder> getFolders() {
return deepCopy(mConfig.folders, new TypeToken<List<Folder>>(){}.getType()); List<Folder> folders = deepCopy(mConfig.folders, new TypeToken<List<Folder>>(){}.getType());
Collections.sort(folders, FOLDERS_COMPARATOR);
return folders;
} }
public void addFolder(Folder folder) { public void addFolder(Folder folder) {