| | |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.util.TypedValue; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | |
| | | |
| | | 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.GrowthExperienceBean; |
| | | import com.application.zhangshi_app_android.bean.TourismBean; |
| | | import com.application.zhangshi_app_android.databinding.ItemGrowthExperiencePrimaryBinding; |
| | | import com.application.zhangshi_app_android.ui.function.GrowthExperienceActivity; |
| | | import com.application.zhangshi_app_android.ui.function.GrowthExperienceActivityViewModel; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author Gss |
| | |
| | | * @desc 成长经历(主要学习及工作经历) recyclerView 的 adapter |
| | | */ |
| | | public class GrowthExperiencePrimaryRvAdapter extends BaseRVAdapter<GrowthExperienceBean, ItemGrowthExperiencePrimaryBinding, GrowthExperiencePrimaryRvAdapter.ViewHolder> { |
| | | |
| | | private GrowthExperienceActivityViewModel viewModel; |
| | | private final Map<GrowthExperienceBean, Boolean> expendMap = new HashMap<>(); |
| | | |
| | | public GrowthExperiencePrimaryRvAdapter(Context context) { |
| | | super(context); |
| | | } |
| | | |
| | | public GrowthExperiencePrimaryRvAdapter(Context context, GrowthExperienceActivityViewModel viewModel) { |
| | | super(context); |
| | | this.viewModel = viewModel; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | 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(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 (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(); |
| | | 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); |
| | | expendMap.put(getItem(position),false); |
| | | holder.getBinding().ivFold.setBackgroundResource(foldIcon.resourceId); |
| | | }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); |
| | | expendMap.put(getItem(position),true); |
| | | holder.getBinding().ivFold.setBackgroundResource(unfoldIcon.resourceId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean willChangeBounds() { |
| | | return true; |
| | | } |
| | | }; |
| | | a.setDuration(500); |
| | | holder.getBinding().cardView.startAnimation(a); |
| | | holder.isExpended = false; |
| | | }else{ |
| | | int recyclerviewHeight = mRecyclerView.getMeasuredHeight(); |
| | | final int initialHeight = holder.getBinding().cardView.getMeasuredHeight(); |
| | | holder.getBinding().cardView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); |
| | | 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; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |