use of com.owncloud.android.ui.events.VCardToggleEvent in project android by nextcloud.
the class ContactListAdapter method selectAllFiles.
public void selectAllFiles(boolean select) {
checkedVCards = new HashSet<>();
if (select) {
for (int i = 0; i < vCards.size(); i++) {
checkedVCards.add(i);
}
}
if (checkedVCards.size() > 0) {
EventBus.getDefault().post(new VCardToggleEvent(true));
} else {
EventBus.getDefault().post(new VCardToggleEvent(false));
}
notifyDataSetChanged();
}
use of com.owncloud.android.ui.events.VCardToggleEvent in project android by nextcloud.
the class ContactListAdapter method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.contactlist_fragment, container, false);
ButterKnife.bind(this, view);
setHasOptionsMenu(true);
ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
ActionBar actionBar = contactsPreferenceActivity.getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(R.string.actionbar_contacts_restore);
actionBar.setDisplayHomeAsUpEnabled(true);
}
contactsPreferenceActivity.setDrawerIndicatorEnabled(false);
recyclerView = (RecyclerView) view.findViewById(R.id.contactlist_recyclerview);
if (savedInstanceState == null) {
contactListAdapter = new ContactListAdapter(getContext(), vCards);
} 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 (checkedItems.size() > 0) {
onMessageEvent(new VCardToggleEvent(true));
}
contactListAdapter = new ContactListAdapter(getContext(), vCards, checkedItems);
}
recyclerView.setAdapter(contactListAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ocFile = getArguments().getParcelable(FILE_NAME);
setFile(ocFile);
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);
// Listen for download messages
IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage());
downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
DownloadFinishReceiver mDownloadFinishReceiver = new DownloadFinishReceiver();
getContext().registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
} else {
loadContactsTask.execute();
}
restoreContacts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkAndAskForContactsWritePermission()) {
getAccountForImport();
}
}
});
restoreContacts.setTextColor(ThemeUtils.primaryAccentColor());
return view;
}
use of com.owncloud.android.ui.events.VCardToggleEvent in project android by nextcloud.
the class ContactListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ContactListFragment.ContactItemViewHolder holder, final int position) {
final int verifiedPosition = holder.getAdapterPosition();
final VCard vcard = vCards.get(verifiedPosition);
if (vcard != null) {
if (checkedVCards.contains(position)) {
holder.getName().setChecked(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
}
} else {
holder.getName().setChecked(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().clearColorFilter();
}
}
holder.getName().setText(getDisplayName(vcard));
// photo
if (vcard.getPhotos().size() > 0) {
Photo firstPhoto = vcard.getPhotos().get(0);
String url = firstPhoto.getUrl();
byte[] data = firstPhoto.getData();
if (data != null && data.length > 0) {
Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
RoundedBitmapDrawable drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.getResources(), thumbnail);
holder.getBadge().setImageDrawable(drawable);
} else if (url != null) {
ImageView badge = holder.getBadge();
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
holder.getBadge().setImageDrawable(resource);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
holder.getBadge().setImageDrawable(errorDrawable);
}
};
DisplayUtils.downloadIcon(context, url, target, R.drawable.ic_user, badge.getWidth(), badge.getHeight());
}
} else {
try {
holder.getBadge().setImageDrawable(TextDrawable.createNamedAvatar(holder.getName().getText().toString(), context.getResources().getDimension(R.dimen.list_item_avatar_icon_radius)));
} catch (Exception e) {
holder.getBadge().setImageResource(R.drawable.ic_user);
}
}
// Checkbox
holder.setVCardListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.getName().setChecked(!holder.getName().isChecked());
if (holder.getName().isChecked()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
}
if (!checkedVCards.contains(verifiedPosition)) {
checkedVCards.add(verifiedPosition);
}
if (checkedVCards.size() == 1) {
EventBus.getDefault().post(new VCardToggleEvent(true));
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().clearColorFilter();
}
if (checkedVCards.contains(verifiedPosition)) {
checkedVCards.remove(verifiedPosition);
}
if (checkedVCards.size() == 0) {
EventBus.getDefault().post(new VCardToggleEvent(false));
}
}
}
});
}
}
Aggregations