|
@@ -1,4 +1,4 @@
|
|
|
-/**
|
|
|
+/*
|
|
|
* Nextcloud Android client application
|
|
|
*
|
|
|
* @author Tobias Kaminsky
|
|
@@ -37,6 +37,7 @@ import android.provider.ContactsContract;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.design.widget.Snackbar;
|
|
|
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
|
|
|
+import android.support.v7.app.ActionBar;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
@@ -51,6 +52,7 @@ import android.widget.Button;
|
|
|
import android.widget.CheckedTextView;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.evernote.android.job.JobRequest;
|
|
|
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
|
@@ -131,14 +133,18 @@ public class ContactListFragment extends FileFragment {
|
|
|
@Override
|
|
|
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
- View view = inflater.inflate(R.layout.contactlist_fragment, null);
|
|
|
+ View view = inflater.inflate(R.layout.contactlist_fragment, container, false);
|
|
|
ButterKnife.bind(this, view);
|
|
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
|
|
|
- contactsPreferenceActivity.getSupportActionBar().setTitle(R.string.actionbar_contacts_restore);
|
|
|
- contactsPreferenceActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
+
|
|
|
+ ActionBar actionBar = contactsPreferenceActivity.getSupportActionBar();
|
|
|
+ if (actionBar != null) {
|
|
|
+ actionBar.setTitle(R.string.actionbar_contacts_restore);
|
|
|
+ actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
+ }
|
|
|
contactsPreferenceActivity.setDrawerIndicatorEnabled(false);
|
|
|
|
|
|
ArrayList<VCard> vCards = new ArrayList<>();
|
|
@@ -161,7 +167,7 @@ public class ContactListFragment extends FileFragment {
|
|
|
getContext().registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
|
|
|
} 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) {
|
|
@@ -177,6 +183,8 @@ public class ContactListFragment extends FileFragment {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ vCards.addAll(Ezvcard.parse(file).all());
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
Log_OC.e(TAG, "Error processing contacts file!", e);
|
|
@@ -199,8 +207,10 @@ public class ContactListFragment extends FileFragment {
|
|
|
} else {
|
|
|
Set<Integer> checkedItems = new HashSet<>();
|
|
|
int[] itemsArray = savedInstanceState.getIntArray(CHECKED_ITEMS_ARRAY_KEY);
|
|
|
- for (int i = 0; i < itemsArray.length; i++) {
|
|
|
- checkedItems.add(itemsArray[i]);
|
|
|
+ if (itemsArray != null) {
|
|
|
+ for (int item : itemsArray) {
|
|
|
+ checkedItems.add(item);
|
|
|
+ }
|
|
|
}
|
|
|
if (checkedItems.size() > 0) {
|
|
|
onMessageEvent(new VCardToggleEvent(true));
|
|
@@ -422,7 +432,12 @@ public class ContactListFragment extends FileFragment {
|
|
|
if (grantResults[index] >= 0) {
|
|
|
getAccountForImport();
|
|
|
} else {
|
|
|
- Snackbar.make(getView(), R.string.contactlist_no_permission, Snackbar.LENGTH_LONG).show();
|
|
|
+ if (getView() != null) {
|
|
|
+ Snackbar.make(getView(), R.string.contactlist_no_permission, Snackbar.LENGTH_LONG)
|
|
|
+ .show();
|
|
|
+ } else {
|
|
|
+ Toast.makeText(getContext(), R.string.contactlist_no_permission, Toast.LENGTH_LONG).show();
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -536,7 +551,8 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
|
|
|
|
|
@Override
|
|
|
public void onBindViewHolder(final ContactListFragment.ContactItemViewHolder holder, final int position) {
|
|
|
- final VCard vcard = vCards.get(position);
|
|
|
+ final int verifiedPosition = holder.getAdapterPosition();
|
|
|
+ final VCard vcard = vCards.get(verifiedPosition);
|
|
|
|
|
|
if (vcard != null) {
|
|
|
|
|
@@ -550,7 +566,7 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
|
|
if (name != null) {
|
|
|
String first = (name.getGiven() == null) ? "" : name.getGiven() + " ";
|
|
|
String last = (name.getFamily() == null) ? "" : name.getFamily();
|
|
|
- holder.getName().setText(first + last);
|
|
|
+ holder.getName().setText(String.format("%s%s", first, last));
|
|
|
} else {
|
|
|
holder.getName().setText("");
|
|
|
}
|
|
@@ -584,15 +600,15 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
|
|
holder.getName().setChecked(!holder.getName().isChecked());
|
|
|
|
|
|
if (holder.getName().isChecked()) {
|
|
|
- if (!checkedVCards.contains(position)) {
|
|
|
- checkedVCards.add(position);
|
|
|
+ if (!checkedVCards.contains(verifiedPosition)) {
|
|
|
+ checkedVCards.add(verifiedPosition);
|
|
|
}
|
|
|
if (checkedVCards.size() == 1) {
|
|
|
EventBus.getDefault().post(new VCardToggleEvent(true));
|
|
|
}
|
|
|
} else {
|
|
|
- if (checkedVCards.contains(position)) {
|
|
|
- checkedVCards.remove(position);
|
|
|
+ if (checkedVCards.contains(verifiedPosition)) {
|
|
|
+ checkedVCards.remove(verifiedPosition);
|
|
|
}
|
|
|
|
|
|
if (checkedVCards.size() == 0) {
|