| | |
| | | package com.application.zhangshi_app_android.ui.function; |
| | | |
| | | import android.animation.Animator; |
| | | import android.animation.AnimatorListenerAdapter; |
| | | import android.animation.ValueAnimator; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | |
| | | import android.widget.LinearLayout; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | |
| | | import com.application.zhangshi_app_android.BR; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.adapter.OldSpouseRvAdapter; |
| | | import com.application.zhangshi_app_android.databinding.ActivityMarriageBinding; |
| | | import com.application.zhangshi_app_android.ui.DLBaseActivity; |
| | | |
| | |
| | | */ |
| | | public class MarriageActivity extends DLBaseActivity<ActivityMarriageBinding,MarriageActivityViewModel> { |
| | | |
| | | private OldSpouseRvAdapter adapter; |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.activity_marriage; |
| | |
| | | public void initParam() { |
| | | |
| | | } |
| | | |
| | | private boolean isExpended = false; |
| | | @Override |
| | | public void initView() { |
| | | adapter = new OldSpouseRvAdapter(this); |
| | | binding.rvPredecessor.setNestedScrollingEnabled(false); |
| | | binding.rvPredecessor.setAdapter(adapter); |
| | | |
| | | final int SCROLL_THRESHOLD = 400; // 滑动阈值,按钮在滑动超过该阈值后开始根据超出阈值距离渐渐显示出来 |
| | | final int SCROLL_DISTANCE = 400; // 按钮从隐藏到全部显示出来需要滑动的距离 |
| | | binding.fabMoveToTop.setAlpha(0f); |
| | | binding.nestedScrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() { |
| | | @Override |
| | | public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { |
| | | // 当滑动距离超过阈值一半时,开始慢慢显示按钮 |
| | | if (scrollY >= SCROLL_THRESHOLD) { |
| | | // 根据滑动距离设置按钮透明度 |
| | | float alpha = Math.min(1.0f, (float) (scrollY - SCROLL_THRESHOLD) / SCROLL_DISTANCE); |
| | | binding.fabMoveToTop.setAlpha(alpha); |
| | | } else { |
| | | binding.fabMoveToTop.setAlpha(0f); |
| | | } |
| | | } |
| | | }); |
| | | binding.fabMoveToTop.setOnClickListener(v -> { |
| | | // 点击按钮返回顶部 |
| | | binding.nestedScrollView.smoothScrollTo(0, 0); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void initData() { |
| | | |
| | | viewModel.getMarriageInfo(); |
| | | } |
| | | |
| | | @Override |
| | | public void initLiveDataObserve() { |
| | | viewModel.getIsSpouseExpendedLiveData().observe(this, aBoolean -> { |
| | | if (aBoolean){ |
| | | binding.ivSpouseFold.setOnClickListener(view -> { |
| | | binding.layoutTitleSpouse.setOnClickListener(view -> { |
| | | collapseView(binding.cardSpouse,binding.layoutTitleSpouse); |
| | | viewModel.getIsSpouseExpendedLiveData().setValue(false); |
| | | }); |
| | | }else { |
| | | binding.ivSpouseFold.setOnClickListener(view -> { |
| | | binding.layoutTitleSpouse.setOnClickListener(view -> { |
| | | expendView(binding.cardSpouse); |
| | | viewModel.getIsSpouseExpendedLiveData().setValue(true); |
| | | }); |
| | |
| | | }); |
| | | viewModel.getIsPredecessorExpendedLiveData().observe(this, aBoolean -> { |
| | | if (aBoolean){ |
| | | binding.ivPredecessorFold.setOnClickListener(view -> { |
| | | binding.layoutTitlePredecessor.setOnClickListener(view -> { |
| | | collapseView(binding.cardPredecessor,binding.layoutTitlePredecessor); |
| | | viewModel.getIsPredecessorExpendedLiveData().setValue(false); |
| | | }); |
| | | }else { |
| | | binding.ivPredecessorFold.setOnClickListener(new View.OnClickListener() { |
| | | binding.layoutTitlePredecessor.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | expendView(binding.cardPredecessor); |
| | |
| | | }); |
| | | viewModel.getIsProcreateExpendedLiveData().observe(this, aBoolean -> { |
| | | if (aBoolean){ |
| | | binding.ivProcreateFold.setOnClickListener(new View.OnClickListener() { |
| | | binding.layoutTitleProcreate.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | collapseView(binding.cardProcreate,binding.layoutTitleProcreate); |
| | |
| | | } |
| | | }); |
| | | }else { |
| | | binding.ivProcreateFold.setOnClickListener(new View.OnClickListener() { |
| | | binding.layoutTitleProcreate.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | expendView(binding.cardProcreate); |
| | |
| | | }); |
| | | } |
| | | }); |
| | | viewModel.getInfoLiveData().observe(this, marriageInfoBean -> { |
| | | if (marriageInfoBean != null){ |
| | | if (marriageInfoBean.getOldSpouseList() == null || marriageInfoBean.getOldSpouseList().size() == 0) { |
| | | binding.cardSpouse.setVisibility(View.GONE); |
| | | }else { |
| | | binding.cardSpouse.setVisibility(View.VISIBLE); |
| | | adapter.setData(marriageInfoBean.getOldSpouseList()); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | protected void dataNull() { |
| | | super.dataNull(); |
| | | binding.layoutDataNull.setVisibility(View.VISIBLE); |
| | | binding.nestedScrollView.setVisibility(View.GONE); |
| | | } |
| | | |
| | | @Override |
| | | protected void hide() { |
| | | super.hide(); |
| | | binding.layoutDataNull.setVisibility(View.GONE); |
| | | binding.nestedScrollView.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | public void collapseView(View initialView,View collapsedView){ |
| | |
| | | } |
| | | public void expendView(View initialView){ |
| | | int initialHeight = initialView.getMeasuredHeight(); |
| | | initialView.measure(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); |
| | | initialView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); |
| | | int targetHeight = initialView.getMeasuredHeight(); |
| | | ValueAnimator animator = ValueAnimator.ofInt(initialHeight,targetHeight); |
| | | animator.addUpdateListener(animation -> { |
| | | initialView.getLayoutParams().height = (int) animation.getAnimatedValue(); |
| | | initialView.requestLayout(); |
| | | }); |
| | | animator.addListener(new AnimatorListenerAdapter() { |
| | | @Override |
| | | public void onAnimationEnd(Animator animation) { |
| | | initialView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; |
| | | initialView.setLayoutParams(initialView.getLayoutParams()); |
| | | } |
| | | }); |
| | | animator.setDuration(500); |
| | | animator.start(); |
| | | } |
| | | |
| | | } |