| | |
| | | import android.widget.FrameLayout; |
| | | |
| | | import com.android.app_base.base.adapter.BaseRVAdapter; |
| | | import com.android.app_base.utils.Utils; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.bean.ContactsBean; |
| | | import com.application.zhangshi_app_android.bean.ContactsDetailBean; |
| | | import com.application.zhangshi_app_android.bean.TourismBean; |
| | | import com.application.zhangshi_app_android.databinding.ItemContactsBinding; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author Gss |
| | |
| | | * @desc 通讯录 recyclerView 的 adapter |
| | | */ |
| | | public class ContactsRvAdapter extends BaseRVAdapter<ContactsBean, ItemContactsBinding, ContactsRvAdapter.ViewHolder> { |
| | | |
| | | private final Map<ContactsBean, Boolean> expendMap = new HashMap<>(); |
| | | |
| | | public ContactsRvAdapter(Context context) { |
| | | super(context); |
| | |
| | | }else { |
| | | holder.getBinding().cardView.setCardBackgroundColor(mContext.getColor(R.color.color_card_pink)); |
| | | } |
| | | if (!expendMap.containsKey(getItem(position))){ |
| | | expendMap.put(getItem(position),false); |
| | | } |
| | | if (Boolean.TRUE.equals(expendMap.get(getItem(position)))){ |
| | | holder.getBinding().ivFold.setBackgroundResource(R.drawable.ic_unfold); |
| | | holder.getBinding().cardView.post(() -> { |
| | | holder.getBinding().cardView.getLayoutParams().height = FrameLayout.LayoutParams.WRAP_CONTENT; |
| | | holder.getBinding().cardView.requestLayout(); |
| | | }); |
| | | }else{ |
| | | holder.getBinding().ivFold.setBackgroundResource(R.drawable.ic_fold); |
| | | holder.getBinding().cardView.post(() -> { |
| | | holder.getBinding().cardView.getLayoutParams().height = holder.getBinding().layoutTitle.getMeasuredHeight(); |
| | | holder.getBinding().cardView.requestLayout(); |
| | | }); |
| | | } |
| | | holder.getBinding().layoutTitle.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | if (holder.isExpended){ |
| | | if (Boolean.TRUE.equals(expendMap.get(getItem(position)))){ |
| | | int initialHeight = holder.getBinding().cardView.getMeasuredHeight(); |
| | | int collapsedHeight = holder.getBinding().layoutTitle.getMeasuredHeight(); |
| | | int distanceToCollapse = (int) (initialHeight - collapsedHeight); |
| | | |
| | | Animation a = new Animation() { |
| | | @Override |
| | | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| | | if (interpolatedTime == 1){ |
| | | } |
| | | holder.getBinding().cardView.getLayoutParams().height = (int) (initialHeight - (distanceToCollapse * interpolatedTime)); |
| | | holder.getBinding().cardView.requestLayout(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean willChangeBounds() { |
| | | return true; |
| | | } |
| | | }; |
| | | a.setDuration(500); |
| | | holder.getBinding().cardView.startAnimation(a); |
| | | holder.isExpended = false; |
| | | Utils.pullCollapse(holder.getBinding().cardView,initialHeight,collapsedHeight); |
| | | expendMap.put(getItem(position),false); |
| | | }else{ |
| | | final int initialHeight = holder.getBinding().cardView.getMeasuredHeight(); |
| | | holder.getBinding().cardView.measure(View.MeasureSpec.UNSPECIFIED,View.MeasureSpec.UNSPECIFIED); |
| | | holder.getBinding().cardView.measure(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); |
| | | int targetHeight = holder.getBinding().cardView.getMeasuredHeight(); |
| | | int distanceToExpand = targetHeight - initialHeight; |
| | | Animation a = new Animation() { |
| | | @Override |
| | | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| | | if (interpolatedTime == 1){ |
| | | } |
| | | holder.getBinding().cardView.getLayoutParams().height = (int) (initialHeight + (distanceToExpand * interpolatedTime)); |
| | | holder.getBinding().cardView.requestLayout(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean willChangeBounds() { |
| | | return true; |
| | | } |
| | | }; |
| | | a.setDuration(500); |
| | | holder.getBinding().cardView.startAnimation(a); |
| | | holder.isExpended = true; |
| | | Utils.dropExpand(holder.getBinding().cardView,initialHeight,targetHeight); |
| | | expendMap.put(getItem(position),true); |
| | | } |
| | | } |
| | | }); |
| | |
| | | |
| | | |
| | | public static class ViewHolder extends BaseViewHolder<ItemContactsBinding>{ |
| | | private boolean isExpended; |
| | | |
| | | public ViewHolder(ItemContactsBinding binding) { |
| | | super(binding); |
| | | } |