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;
}
});
}
}
Aggregations