Search in sources :

Example 1 with AlbumItemHolder

use of us.koller.cameraroll.adapter.album.viewHolder.AlbumItemHolder in project Camera-Roll-Android-App by kollerlukas.

the class AlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
    final AlbumItem albumItem = getData().getAlbumItems().get(position);
    if (!albumItem.equals(((AlbumItemHolder) holder).getAlbumItem())) {
        ((AlbumItemHolder) holder).setAlbumItem(albumItem);
    }
    boolean selected = getSelectorManager().isItemSelected(albumItem.getPath());
    ((AlbumItemHolder) holder).setSelected(selected);
    holder.itemView.setTag(albumItem.getPath());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (getSelectorMode()) {
                onItemSelected((AlbumItemHolder) holder);
            } else {
                Log.d("AlbumAdapter", "onClick: " + getData().getPath());
                Context context = holder.itemView.getContext();
                Intent intent = new Intent(context, ItemActivity.class);
                intent.putExtra(ItemActivity.ALBUM_ITEM, albumItem);
                intent.putExtra(ItemActivity.ALBUM_PATH, getData().getPath());
                intent.putExtra(ItemActivity.ITEM_POSITION, getData().getAlbumItems().indexOf(albumItem));
                if (Settings.getInstance(context).showAnimations()) {
                    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context, holder.itemView.findViewById(R.id.image), albumItem.getPath());
                    ActivityCompat.startActivityForResult((Activity) context, intent, ItemActivity.VIEW_IMAGE, options.toBundle());
                } else {
                    ActivityCompat.startActivityForResult((Activity) context, intent, ItemActivity.VIEW_IMAGE, null);
                }
            }
        }
    });
    if (getSelectorManager().callbacksAttached()) {
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                if (!getSelectorMode()) {
                    setSelectorMode(true);
                    clearSelectedItemsList();
                }
                onItemSelected((AlbumItemHolder) holder);
                if (dragSelectEnabled()) {
                    // notify DragSelectTouchListener
                    boolean selected = getSelectorManager().isItemSelected(albumItem.getPath());
                    if (selected) {
                        int position = getData().getAlbumItems().indexOf(albumItem);
                        dragSelectTouchListener.startDragSelection(position);
                    }
                }
                return true;
            }
        });
    }
}
Also used : Context(android.content.Context) AlbumItemHolder(us.koller.cameraroll.adapter.album.viewHolder.AlbumItemHolder) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) ItemActivity(us.koller.cameraroll.ui.ItemActivity) AlbumActivity(us.koller.cameraroll.ui.AlbumActivity) Activity(android.app.Activity) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) ItemActivity(us.koller.cameraroll.ui.ItemActivity)

Aggregations

Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AlbumItemHolder (us.koller.cameraroll.adapter.album.viewHolder.AlbumItemHolder)1 AlbumItem (us.koller.cameraroll.data.models.AlbumItem)1 AlbumActivity (us.koller.cameraroll.ui.AlbumActivity)1 ItemActivity (us.koller.cameraroll.ui.ItemActivity)1