|
@@ -1,7 +1,7 @@
|
|
|
-/**
|
|
|
- * Nextcloud Android client application
|
|
|
- *
|
|
|
- * @author Tobias Kaminsky
|
|
|
+/*
|
|
|
+ Nextcloud Android client application
|
|
|
+
|
|
|
+ @author Tobias Kaminsky
|
|
|
* Copyright (C) 2017 Tobias Kaminsky
|
|
|
* Copyright (C) 2017 Nextcloud GmbH.
|
|
|
* <p>
|
|
@@ -35,6 +35,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;
|
|
@@ -49,6 +50,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;
|
|
@@ -125,14 +127,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) {
|
|
|
+ contactsPreferenceActivity.getSupportActionBar().setTitle(R.string.actionbar_contacts_restore);
|
|
|
+ contactsPreferenceActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
+ }
|
|
|
contactsPreferenceActivity.setDrawerIndicatorEnabled(false);
|
|
|
|
|
|
ArrayList<VCard> vCards = new ArrayList<>();
|
|
@@ -142,14 +148,18 @@ public class ContactListFragment extends FileFragment {
|
|
|
setFile(ocFile);
|
|
|
Account account = getArguments().getParcelable(ACCOUNT);
|
|
|
|
|
|
- if (!ocFile.isDown()) {
|
|
|
- Intent i = new Intent(getContext(), FileDownloader.class);
|
|
|
- i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
|
|
|
- i.putExtra(FileDownloader.EXTRA_FILE, ocFile);
|
|
|
- getContext().startService(i);
|
|
|
+ if (ocFile != null) {
|
|
|
+ if (!ocFile.isDown()) {
|
|
|
+ Intent i = new Intent(getContext(), FileDownloader.class);
|
|
|
+ i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
|
|
|
+ i.putExtra(FileDownloader.EXTRA_FILE, ocFile);
|
|
|
+ getContext().startService(i);
|
|
|
+ } else {
|
|
|
+ File file = new File(ocFile.getStoragePath());
|
|
|
+ vCards.addAll(Ezvcard.parse(file).all());
|
|
|
+ }
|
|
|
} else {
|
|
|
- File file = new File(ocFile.getStoragePath());
|
|
|
- vCards.addAll(Ezvcard.parse(file).all());
|
|
|
+ Toast.makeText(getContext(), R.string.file_not_found, Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
Log_OC.e(TAG, "Error processing contacts file!", e);
|
|
@@ -172,8 +182,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));
|
|
@@ -395,7 +407,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;
|
|
|
}
|
|
@@ -450,14 +467,6 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
|
|
this.checkedVCards = checkedVCards;
|
|
|
}
|
|
|
|
|
|
- public int getCheckedCount() {
|
|
|
- if (checkedVCards != null) {
|
|
|
- return checkedVCards.size();
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public int[] getCheckedIntArray() {
|
|
|
int[] intArray;
|
|
|
if (checkedVCards != null && checkedVCards.size() > 0) {
|
|
@@ -483,7 +492,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) {
|
|
|
|
|
@@ -497,7 +507,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("");
|
|
|
}
|
|
@@ -531,15 +541,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) {
|