package com.application.zhangshi_app_android.ui.function;
|
|
import android.animation.ValueAnimator;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.view.animation.Animation;
|
import android.view.animation.Transformation;
|
import android.widget.FrameLayout;
|
import android.widget.LinearLayout;
|
|
import androidx.annotation.NonNull;
|
|
import com.application.zhangshi_app_android.BR;
|
import com.application.zhangshi_app_android.R;
|
import com.application.zhangshi_app_android.databinding.ActivityMarriageBinding;
|
import com.application.zhangshi_app_android.ui.DLBaseActivity;
|
|
/**
|
* @author Ljj
|
* @date 2023.04.23. 23:23
|
* @desc 婚姻状况 Activity
|
*/
|
public class MarriageActivity extends DLBaseActivity<ActivityMarriageBinding,MarriageActivityViewModel> {
|
|
@Override
|
public int getLayoutId() {
|
return R.layout.activity_marriage;
|
}
|
|
@Override
|
public int getVariableId() {
|
return BR.viewModel;
|
}
|
|
@Override
|
public void initParam() {
|
|
}
|
|
private boolean isExpended = false;
|
@Override
|
public void initView() {
|
}
|
|
@Override
|
public void initData() {
|
|
}
|
|
@Override
|
public void initLiveDataObserve() {
|
viewModel.getIsSpouseExpendedLiveData().observe(this, aBoolean -> {
|
if (aBoolean){
|
binding.ivSpouseFold.setOnClickListener(view -> {
|
collapseView(binding.cardSpouse,binding.layoutTitleSpouse);
|
viewModel.getIsSpouseExpendedLiveData().setValue(false);
|
});
|
}else {
|
binding.ivSpouseFold.setOnClickListener(view -> {
|
expendView(binding.cardSpouse);
|
viewModel.getIsSpouseExpendedLiveData().setValue(true);
|
});
|
}
|
});
|
viewModel.getIsPredecessorExpendedLiveData().observe(this, aBoolean -> {
|
if (aBoolean){
|
binding.ivPredecessorFold.setOnClickListener(view -> {
|
collapseView(binding.cardPredecessor,binding.layoutTitlePredecessor);
|
viewModel.getIsPredecessorExpendedLiveData().setValue(false);
|
});
|
}else {
|
binding.ivPredecessorFold.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
expendView(binding.cardPredecessor);
|
viewModel.getIsPredecessorExpendedLiveData().setValue(true);
|
}
|
});
|
}
|
});
|
viewModel.getIsProcreateExpendedLiveData().observe(this, aBoolean -> {
|
if (aBoolean){
|
binding.ivProcreateFold.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
collapseView(binding.cardProcreate,binding.layoutTitleProcreate);
|
viewModel.getIsProcreateExpendedLiveData().setValue(false);
|
}
|
});
|
}else {
|
binding.ivProcreateFold.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
expendView(binding.cardProcreate);
|
viewModel.getIsProcreateExpendedLiveData().setValue(true);
|
}
|
});
|
}
|
});
|
}
|
|
public void collapseView(View initialView,View collapsedView){
|
int initialHeight = initialView.getMeasuredHeight();
|
int collapsedHeight = collapsedView.getMeasuredHeight();
|
int distanceToCollapse = (int) (initialHeight - collapsedHeight);
|
|
Animation a = new Animation() {
|
@Override
|
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
if (interpolatedTime == 1){
|
}
|
initialView.getLayoutParams().height = (int) (initialHeight - (distanceToCollapse * interpolatedTime));
|
initialView.requestLayout();
|
}
|
|
@Override
|
public boolean willChangeBounds() {
|
return true;
|
}
|
};
|
a.setDuration(500);
|
initialView.startAnimation(a);
|
}
|
public void expendView(View initialView){
|
int initialHeight = initialView.getMeasuredHeight();
|
initialView.measure(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
int targetHeight = initialView.getMeasuredHeight();
|
ValueAnimator animator = ValueAnimator.ofInt(initialHeight,targetHeight);
|
animator.addUpdateListener(animation -> {
|
initialView.getLayoutParams().height = (int) animation.getAnimatedValue();
|
initialView.requestLayout();
|
});
|
animator.setDuration(500);
|
animator.start();
|
}
|
}
|