Linjiajia
2023-12-29 590c1cff46b105d774271f950caa9f65523f05c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.application.zhangshi_app_android.adapter;
 
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;
import android.widget.FrameLayout;
 
import androidx.recyclerview.widget.GridLayoutManager;
 
import com.android.app_base.base.adapter.BaseRVAdapter;
import com.android.app_base.manager.AppManager;
import com.android.app_base.utils.Utils;
import com.application.zhangshi_app_android.R;
import com.application.zhangshi_app_android.bean.PropertyBean;
import com.application.zhangshi_app_android.bean.TourismBean;
import com.application.zhangshi_app_android.databinding.ItemCleanStorageBinding;
import com.application.zhangshi_app_android.databinding.ItemPropertyBinding;
import com.application.zhangshi_app_android.ui.function.CleanStorageDetailActivity;
import com.application.zhangshi_app_android.ui.function.FamilyAssetsDetailActivity;
import com.application.zhangshi_app_android.ui.function.PropertyDetailActivity;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author Ljj
 * @date 2023.04.21. 19:26
 * @desc 个人财产 Adapter
 */
public class PropertyRvAdapter extends BaseRVAdapter<PropertyBean, ItemPropertyBinding, PropertyRvAdapter.ViewHolder> {
    private final Map<PropertyBean, Boolean> expendMap = new HashMap<>();
 
    public PropertyRvAdapter(Context context) {
        super(context);
    }
 
    @Override
    protected int getLayoutId() {
        return R.layout.item_property;
    }
 
    @Override
    protected ViewHolder getViewHolder(ItemPropertyBinding itemBind, int viewType) {
        return new ViewHolder(itemBind);
    }
 
    @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(typedValue1.data);
        }else {
            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(unfoldIcon.resourceId);
            holder.getBinding().cardView.post(() -> {
                holder.getBinding().cardView.getLayoutParams().height = FrameLayout.LayoutParams.WRAP_CONTENT;
                holder.getBinding().cardView.requestLayout();
            });
        }else{
            holder.getBinding().ivFold.setBackgroundResource(foldIcon.resourceId);
            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 (Boolean.TRUE.equals(expendMap.get(getItem(position)))){
                    int initialHeight = holder.getBinding().cardView.getMeasuredHeight();
                    int collapsedHeight = holder.getBinding().layoutTitle.getMeasuredHeight();
                    Utils.pullCollapse(holder.getBinding().cardView,initialHeight,collapsedHeight);
                    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(unfoldIcon.resourceId);
                    expendMap.put(getItem(position),true);
                }
            }
        });
        holder.getBinding().layoutContent.setOnClickListener(v -> {
            AppManager.getAppManager().startActivity(
                    new Intent(getRecyclerView().getContext(), PropertyDetailActivity.class)
                            .putExtra("bean",mDataList.get(position)));
        });
        ElectronicFileAdapter adapter = new ElectronicFileAdapter(mContext);
        holder.getBinding().rvImage.setLayoutManager(new GridLayoutManager(mContext,3));
        holder.getBinding().rvImage.setAdapter(adapter);
        adapter.setData(Utils.splitString2List(mDataList.get(position).getUrl(),","));
 
    }
 
    public static class ViewHolder extends BaseRVAdapter.BaseViewHolder<ItemPropertyBinding> {
        private boolean isExpended;
 
        public ViewHolder(ItemPropertyBinding binding) {
            super(binding);
        }
    }
}