Linjiajia
2024-01-29 b17b9aa59bae6d03055f14d937821655dfaffa1f
app/src/main/java/com/application/zhangshi_app_android/adapter/PropertyRvAdapter.java
@@ -2,6 +2,7 @@
import android.content.Context;
import android.content.Intent;
import android.util.TypedValue;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
@@ -52,22 +53,32 @@
    @Override
    protected void onBind(ViewHolder holder, int position) {
        holder.getBinding().setBean(mDataList.get(position));
        //根据主题选择对应卡片背景色
        TypedValue typedValue1 = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.cardBackgroundColorFirst, typedValue1, true);
        TypedValue typedValue2 = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.cardBackgroundColorSecond, typedValue2, true);
        if (position % 2 != 0){
            holder.getBinding().cardView.setCardBackgroundColor(mContext.getColor(R.color.color_card_blue));
            holder.getBinding().cardView.setCardBackgroundColor(typedValue1.data);
        }else {
            holder.getBinding().cardView.setCardBackgroundColor(mContext.getColor(R.color.color_card_pink));
            holder.getBinding().cardView.setCardBackgroundColor(typedValue2.data);
        }
        if (!expendMap.containsKey(getItem(position))){
            expendMap.put(getItem(position),false);
        }
        //根据主题选择对应图标
        TypedValue unfoldIcon = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.icUnfold, unfoldIcon, true);
        TypedValue foldIcon = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.icFold, foldIcon, true);
        if (Boolean.TRUE.equals(expendMap.get(getItem(position)))){
            holder.getBinding().ivFold.setBackgroundResource(R.drawable.ic_unfold);
            holder.getBinding().ivFold.setBackgroundResource(unfoldIcon.resourceId);
            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().ivFold.setBackgroundResource(foldIcon.resourceId);
            holder.getBinding().cardView.post(() -> {
                holder.getBinding().cardView.getLayoutParams().height = holder.getBinding().layoutTitle.getMeasuredHeight();
                holder.getBinding().cardView.requestLayout();
@@ -80,14 +91,14 @@
                    int initialHeight = holder.getBinding().cardView.getMeasuredHeight();
                    int collapsedHeight = holder.getBinding().layoutTitle.getMeasuredHeight();
                    Utils.pullCollapse(holder.getBinding().cardView,initialHeight,collapsedHeight);
                    holder.getBinding().ivFold.setBackgroundResource(R.drawable.ic_fold);
                    holder.getBinding().ivFold.setBackgroundResource(foldIcon.resourceId);
                    expendMap.put(getItem(position),false);
                }else{
                    final int initialHeight = holder.getBinding().cardView.getMeasuredHeight();
                    holder.getBinding().cardView.measure(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
                    int targetHeight = holder.getBinding().cardView.getMeasuredHeight();
                    Utils.dropExpand(holder.getBinding().cardView,initialHeight,targetHeight);
                    holder.getBinding().ivFold.setBackgroundResource(R.drawable.ic_unfold);
                    holder.getBinding().ivFold.setBackgroundResource(unfoldIcon.resourceId);
                    expendMap.put(getItem(position),true);
                }
            }