From a5949781c2b366f35e4e49243a39952e6c937180 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 9 Aug 2013 00:29:19 +0200 Subject: Fix comparator --HG-- extra : rebase_source : f8b3fe8b84129962fa51d11d4defb64594719ef3 --- .../blinkt/openvpn/fragments/VPNProfileList.java | 60 ++++++++++++---------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'src/de') 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 { + static class VpnProfileNameComparator implements Comparator { - @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 allvpn = getPM().getProfiles(); - TreeSet sortedset = new TreeSet(new VpnProfileNameComperator()); - sortedset.addAll(allvpn); - mArrayadapter.addAll(sortedset); + TreeSet sortedset = new TreeSet(new VpnProfileNameComparator()); + sortedset.addAll(allvpn); + mArrayadapter.addAll(sortedset); - setListAdapter(mArrayadapter); + setListAdapter(mArrayadapter); } -- cgit v1.2.3