Add servers sorting.

Change-Id: Idd3d39fcf91fba6d5f7b0615d241f6ad9f46bd5f
This commit is contained in:
Artur Dryomov
2013-08-02 00:08:08 +03:00
parent 43dbc8088b
commit d3cef7ed75

View File

@@ -9,6 +9,8 @@
package org.libreoffice.impressremote.communication;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
@@ -19,7 +21,7 @@ import android.content.Context;
import org.libreoffice.impressremote.util.Preferences;
class ServersManager {
class ServersManager implements Comparator<Server> {
private final Context mContext;
private final ServersFinder mBluetoothServersFinder;
@@ -53,7 +55,11 @@ class ServersManager {
aServers.addAll(mTcpServersFinder.getServers());
aServers.addAll(getManualAddedTcpServers());
return filterBlacklistedServers(aServers);
aServers = filterBlacklistedServers(aServers);
Collections.sort(aServers, this);
return aServers;
}
private List<Server> getManualAddedTcpServers() {
@@ -89,6 +95,14 @@ class ServersManager {
return aFilteredServers;
}
@Override
public int compare(Server aFirstServer, Server aSecondServer) {
String aFirstServerName = aFirstServer.getName();
String aSecondServerName = aSecondServer.getName();
return aFirstServerName.compareToIgnoreCase(aSecondServerName);
}
public void addTcpServer(String aAddress, String aName) {
Preferences.set(mContext, Preferences.Locations.STORED_SERVERS,
aAddress, aName);