Search in sources :

Example 1 with VCardToggleEvent

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();
}
Also used : VCardToggleEvent(com.owncloud.android.ui.events.VCardToggleEvent)

Example 2 with VCardToggleEvent

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;
}
Also used : IntentFilter(android.content.IntentFilter) ContactsPreferenceActivity(com.owncloud.android.ui.activity.ContactsPreferenceActivity) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckedTextView(android.widget.CheckedTextView) VCardToggleEvent(com.owncloud.android.ui.events.VCardToggleEvent) ActionBar(android.support.v7.app.ActionBar) HashSet(java.util.HashSet)

Example 3 with VCardToggleEvent

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));
                    }
                }
            }
        });
    }
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Photo(ezvcard.property.Photo) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckedTextView(android.widget.CheckedTextView) IOException(java.io.IOException) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) VCardToggleEvent(com.owncloud.android.ui.events.VCardToggleEvent) ImageView(android.widget.ImageView) VCard(ezvcard.VCard)

Aggregations

VCardToggleEvent (com.owncloud.android.ui.events.VCardToggleEvent)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 CheckedTextView (android.widget.CheckedTextView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)1 ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 TextDrawable (com.owncloud.android.ui.TextDrawable)1 ContactsPreferenceActivity (com.owncloud.android.ui.activity.ContactsPreferenceActivity)1 VCard (ezvcard.VCard)1 Photo (ezvcard.property.Photo)1