瀏覽代碼

Merge pull request #1024 from nextcloud/contactsSort

Sort contact list
Andy Scherzinger 8 年之前
父節點
當前提交
c33a88104d
共有 1 個文件被更改,包括 19 次插入2 次删除
  1. 19 2
      src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java

+ 19 - 2
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java

@@ -71,6 +71,8 @@ import org.greenrobot.eventbus.ThreadMode;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -150,6 +152,21 @@ public class ContactListFragment extends FileFragment {
             } else {
                 File file = new File(ocFile.getStoragePath());
                 vCards.addAll(Ezvcard.parse(file).all());
+                Collections.sort(vCards, new Comparator<VCard>() {
+                    @Override
+                    public int compare(VCard o1, VCard o2) {
+                        if (o1.getFormattedName() != null && o2.getFormattedName() != null) {
+                            return o1.getFormattedName().getValue().compareTo(o2.getFormattedName().getValue());
+                        } else {
+                            if (o1.getFormattedName() == null) {
+                                return 1; // Send the contact to the end of the list
+                            } else {
+                                return -1;
+                            }
+
+                        }
+                    }
+                });
             }
         } catch (IOException e) {
             Log_OC.e(TAG, "Error processing contacts file!", e);
@@ -251,7 +268,7 @@ public class ContactListFragment extends FileFragment {
 
     private void setSelectAllMenuItem(MenuItem selectAll, boolean checked) {
         selectAll.setChecked(checked);
-        if(checked) {
+        if (checked) {
             selectAll.setIcon(R.drawable.ic_select_none);
         } else {
             selectAll.setIcon(R.drawable.ic_select_all);
@@ -463,7 +480,7 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
         if (checkedVCards != null && checkedVCards.size() > 0) {
             intArray = new int[checkedVCards.size()];
             int i = 0;
-            for (int position: checkedVCards) {
+            for (int position : checkedVCards) {
                 intArray[i] = position;
                 i++;
             }