Linjiajia
2023-04-24 fcdddf8b9b34f9930bec454b5fffe41c0e33ba3c
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
126
127
128
129
130
131
package com.application.zhangshi_app_android.adapter;
 
import android.content.Context;
import android.content.Intent;
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.application.zhangshi_app_android.R;
import com.application.zhangshi_app_android.bean.HundredWishBean;
import com.application.zhangshi_app_android.databinding.ItemHundredWishBinding;
import com.application.zhangshi_app_android.ui.function.HundredWishDetailActivity;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
* @author Ljj
* @date 2023.04.23. 20:05
* @desc
*/public class HundredWishRvAdapter extends BaseRVAdapter<HundredWishBean, ItemHundredWishBinding, HundredWishRvAdapter.ViewHolder> {
    public HundredWishRvAdapter(Context context) {
        super(context);
    }
 
    @Override
    protected int getLayoutId() {
        return R.layout.item_hundred_wish;
    }
 
    @Override
    protected ViewHolder getViewHolder(ItemHundredWishBinding itemBind, int viewType) {
        return new ViewHolder(itemBind);
    }
 
    @Override
    protected void onBind(ViewHolder holder, int position) {
        holder.getBinding().setBean(mDataList.get(position));
        if (position % 2 != 0){
            holder.getBinding().cardView.setCardBackgroundColor(mContext.getColor(R.color.color_card_blue));
        }else {
            holder.getBinding().cardView.setCardBackgroundColor(mContext.getColor(R.color.color_card_pink));
        }
        holder.getBinding().layoutTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.isExpended){
                    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;
                }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();
                    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;
                }
            }
        });
        holder.getBinding().layoutContent.setOnClickListener(v -> {
            AppManager.getAppManager().startActivity(
                    new Intent(getRecyclerView().getContext(), HundredWishDetailActivity.class)
                            .putExtra("bean",mDataList.get(position)));
        });
 
        ImageRvAdapter adapter = new ImageRvAdapter(mContext);
        holder.getBinding().rvImage.setLayoutManager(new GridLayoutManager(mContext,3));
        holder.getBinding().rvImage.setAdapter(adapter);
        String url = mDataList.get(position).getUrl();
        if (url == null||url.isEmpty()){
            return;
        }
        List<String> list;
        if (url.contains(",")){
            String[] split = url.split(",");
            list = new ArrayList<>(Arrays.asList(split));
        }else {
            list = new ArrayList<>();
            list.add(url);
        }
        adapter.setData(list);
    }
 
    public static class ViewHolder extends BaseRVAdapter.BaseViewHolder<ItemHundredWishBinding> {
        private boolean isExpended;
 
        public ViewHolder(ItemHundredWishBinding binding) {
            super(binding);
        }
    }
}