use of com.nightonke.saver.ui.SwipeableItemOnClickListener in project CoCoin by Nightonke.
the class MySwipeableItemAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
// set listeners
// (if the item is *not pinned*, click event comes to the itemView)
holder.itemView.setOnClickListener(new SwipeableItemOnClickListener(position) {
@Override
public void onClick(View v) {
onItemViewClick(v);
}
});
// (if the item is *pinned*, click event comes to the mContainer)
holder.mContainer.setOnClickListener(new SwipeableItemOnClickListener(position) {
@Override
public void onClick(View v) {
onSwipeableViewContainerClick(v);
onItemClickListener.onItemClick(position);
}
});
// set text
int tPosition = records.size() - 1 - position;
CoCoinRecord record = records.get(tPosition);
holder.tagImage.setImageResource(CoCoinUtil.GetTagIcon(record.getTag()));
holder.date.setText(record.getCalendarString());
holder.money.setText(String.valueOf((int) record.getMoney()));
holder.date.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.money.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.money.setTextColor(ContextCompat.getColor(CoCoinApplication.getAppContext(), R.color.my_blue));
holder.index.setText((position + 1) + "");
holder.index.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.remark.setText(record.getRemark());
holder.remark.setTypeface(CoCoinUtil.typefaceLatoLight);
// set background resource (target view ID: container)
final int swipeState = holder.getSwipeStateFlags();
if ((swipeState & Swipeable.STATE_FLAG_IS_UPDATED) != 0) {
int bgResId;
if ((swipeState & Swipeable.STATE_FLAG_IS_ACTIVE) != 0) {
bgResId = R.drawable.bg_item_swiping_active_state;
} else if ((swipeState & Swipeable.STATE_FLAG_SWIPING) != 0) {
bgResId = R.drawable.bg_item_swiping_state;
} else {
bgResId = R.drawable.bg_item_normal_state;
}
holder.mContainer.setBackgroundResource(bgResId);
}
holder.setSwipeItemHorizontalSlideAmount(pinned.get((int) records.get(records.size() - 1 - position).getId()) ? Swipeable.OUTSIDE_OF_THE_WINDOW_LEFT : 0);
}
Aggregations