summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-08-09 00:29:19 +0200
committerArne Schwabe <arne@rfc2549.org>2013-08-09 00:29:19 +0200
commita5949781c2b366f35e4e49243a39952e6c937180 (patch)
tree14f4cda47ec0a1946aea663ccbae6b4ed419a2d3 /src/de
parentc5bd9f110c84f0d3b0a29295337cf724eb2bdbfb (diff)
Fix comparator
--HG-- extra : rebase_source : f8b3fe8b84129962fa51d11d4defb64594719ef3
Diffstat (limited to 'src/de')
-rw-r--r--src/de/blinkt/openvpn/fragments/VPNProfileList.java60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/de/blinkt/openvpn/fragments/VPNProfileList.java b/src/de/blinkt/openvpn/fragments/VPNProfileList.java
index ccd8ef47..2b03048f 100644
--- a/src/de/blinkt/openvpn/fragments/VPNProfileList.java
+++ b/src/de/blinkt/openvpn/fragments/VPNProfileList.java
@@ -1,9 +1,5 @@
package de.blinkt.openvpn.fragments;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.TreeSet;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListFragment;
@@ -15,25 +11,19 @@ import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.text.Html.ImageGetter;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
+import android.view.*;
import android.view.View.OnClickListener;
-import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
-import de.blinkt.openvpn.ConfigConverter;
-import de.blinkt.openvpn.FileSelect;
-import de.blinkt.openvpn.LaunchVPN;
-import de.blinkt.openvpn.R;
-import de.blinkt.openvpn.VPNPreferences;
-import de.blinkt.openvpn.VpnProfile;
+import de.blinkt.openvpn.*;
import de.blinkt.openvpn.core.ProfileManager;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.TreeSet;
+
public class VPNProfileList extends ListFragment {
public final static int RESULT_VPN_DELETED = Activity.RESULT_FIRST_USER;
@@ -126,8 +116,8 @@ public class VPNProfileList extends ListFragment {
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.vpn_profile_list, container,false);
TextView newvpntext = (TextView) v.findViewById(R.id.add_new_vpn_hint);
@@ -150,24 +140,38 @@ public class VPNProfileList extends ListFragment {
setListAdapter();
}
- class VpnProfileNameComperator implements Comparator<VpnProfile> {
+ static class VpnProfileNameComparator implements Comparator<VpnProfile> {
- @Override
- public int compare(VpnProfile lhs, VpnProfile rhs) {
- return lhs.mName.compareTo(rhs.mName);
- }
+ @Override
+ public int compare(VpnProfile lhs, VpnProfile rhs) {
+ if (lhs == rhs)
+ // Catches also both null
+ return 0;
- }
+ if (lhs == null)
+ return -1;
+ if (rhs == null)
+ return 1;
+
+ if (lhs.mName == null)
+ return -1;
+ if (rhs.mName == null)
+ return 1;
+
+ return lhs.mName.compareTo(rhs.mName);
+ }
+
+ }
private void setListAdapter() {
mArrayadapter = new VPNArrayAdapter(getActivity(),R.layout.vpn_list_item,R.id.vpn_item_title);
Collection<VpnProfile> allvpn = getPM().getProfiles();
- TreeSet<VpnProfile> sortedset = new TreeSet<VpnProfile>(new VpnProfileNameComperator());
- sortedset.addAll(allvpn);
- mArrayadapter.addAll(sortedset);
+ TreeSet<VpnProfile> sortedset = new TreeSet<VpnProfile>(new VpnProfileNameComparator());
+ sortedset.addAll(allvpn);
+ mArrayadapter.addAll(sortedset);
- setListAdapter(mArrayadapter);
+ setListAdapter(mArrayadapter);
}