|
@@ -23,9 +23,11 @@ package com.owncloud.android.ui.fragment.contactsbackup;
|
|
|
|
|
|
import android.Manifest;
|
|
import android.Manifest;
|
|
import android.accounts.Account;
|
|
import android.accounts.Account;
|
|
|
|
+import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
|
+import android.content.IntentFilter;
|
|
import android.database.Cursor;
|
|
import android.database.Cursor;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.BitmapFactory;
|
|
@@ -53,6 +55,7 @@ import android.widget.LinearLayout;
|
|
import com.evernote.android.job.JobRequest;
|
|
import com.evernote.android.job.JobRequest;
|
|
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
|
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.R;
|
|
|
|
+import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.files.services.FileDownloader;
|
|
import com.owncloud.android.files.services.FileDownloader;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
@@ -104,6 +107,7 @@ public class ContactListFragment extends FileFragment {
|
|
public Button restoreContacts;
|
|
public Button restoreContacts;
|
|
|
|
|
|
private ContactListAdapter contactListAdapter;
|
|
private ContactListAdapter contactListAdapter;
|
|
|
|
+ private Account account;
|
|
|
|
|
|
public static ContactListFragment newInstance(OCFile file, Account account) {
|
|
public static ContactListFragment newInstance(OCFile file, Account account) {
|
|
ContactListFragment frag = new ContactListFragment();
|
|
ContactListFragment frag = new ContactListFragment();
|
|
@@ -142,13 +146,19 @@ public class ContactListFragment extends FileFragment {
|
|
try {
|
|
try {
|
|
OCFile ocFile = getArguments().getParcelable(FILE_NAME);
|
|
OCFile ocFile = getArguments().getParcelable(FILE_NAME);
|
|
setFile(ocFile);
|
|
setFile(ocFile);
|
|
- Account account = getArguments().getParcelable(ACCOUNT);
|
|
|
|
|
|
+ account = getArguments().getParcelable(ACCOUNT);
|
|
|
|
|
|
if (!ocFile.isDown()) {
|
|
if (!ocFile.isDown()) {
|
|
Intent i = new Intent(getContext(), FileDownloader.class);
|
|
Intent i = new Intent(getContext(), FileDownloader.class);
|
|
i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
|
|
i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
|
|
i.putExtra(FileDownloader.EXTRA_FILE, ocFile);
|
|
i.putExtra(FileDownloader.EXTRA_FILE, ocFile);
|
|
getContext().startService(i);
|
|
getContext().startService(i);
|
|
|
|
+
|
|
|
|
+ // Listen for download messages
|
|
|
|
+ IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage());
|
|
|
|
+ downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
|
|
|
|
+ DownloadFinishReceiver mDownloadFinishReceiver = new DownloadFinishReceiver();
|
|
|
|
+ getContext().registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
|
|
} else {
|
|
} else {
|
|
File file = new File(ocFile.getStoragePath());
|
|
File file = new File(ocFile.getStoragePath());
|
|
vCards.addAll(Ezvcard.parse(file).all());
|
|
vCards.addAll(Ezvcard.parse(file).all());
|
|
@@ -446,6 +456,27 @@ public class ContactListFragment extends FileFragment {
|
|
return displayName;
|
|
return displayName;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private class DownloadFinishReceiver extends BroadcastReceiver {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
|
+ if (intent.getAction().equalsIgnoreCase(FileDownloader.getDownloadFinishMessage())){
|
|
|
|
+ String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
|
|
|
|
+
|
|
|
|
+ FileDataStorageManager storageManager = new FileDataStorageManager(account,
|
|
|
|
+ getContext().getContentResolver());
|
|
|
|
+ OCFile ocFile = storageManager.getFileByPath(downloadedRemotePath);
|
|
|
|
+ File file = new File(ocFile.getStoragePath());
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ contactListAdapter.replaceVCards(Ezvcard.parse(file).all());
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.ContactItemViewHolder> {
|
|
class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.ContactItemViewHolder> {
|
|
@@ -475,6 +506,11 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void replaceVCards(List<VCard> vCards) {
|
|
|
|
+ this.vCards = vCards;
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
+ }
|
|
|
|
+
|
|
public int[] getCheckedIntArray() {
|
|
public int[] getCheckedIntArray() {
|
|
int[] intArray;
|
|
int[] intArray;
|
|
if (checkedVCards != null && checkedVCards.size() > 0) {
|
|
if (checkedVCards != null && checkedVCards.size() > 0) {
|