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.view.animation.Animation;
|
import android.view.animation.Transformation;
|
import android.widget.FrameLayout;
|
import android.widget.PopupWindow;
|
|
import com.android.app_base.manager.AppManager;
|
import com.android.app_base.utils.ScreenSizeUtils;
|
import com.application.zhangshi_app_android.BR;
|
import com.application.zhangshi_app_android.R;
|
import com.application.zhangshi_app_android.databinding.ActivityHealthCareBinding;
|
import com.application.zhangshi_app_android.ui.DLBaseActivity;
|
|
/**
|
* @author Ljj
|
* @date 2023.04.28. 13:51
|
* @desc 健康保健 Activity
|
*/
|
public class HealthCareActivity extends DLBaseActivity<ActivityHealthCareBinding,HealthCareActivityViewModel> {
|
|
private PopupWindow popupWindow;
|
private int popWidth;
|
@Override
|
public int getLayoutId() {
|
return R.layout.activity_health_care;
|
}
|
|
@Override
|
public int getVariableId() {
|
return BR.viewModel;
|
}
|
|
@Override
|
public void initParam() {
|
|
}
|
|
@Override
|
public void initView() {
|
View view = View.inflate(this,R.layout.pop_annual_health_status,null);
|
popupWindow = initPopUpWindow(view);
|
|
view.findViewById(R.id.tv_annual_health_status).setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
popupWindow.dismiss();
|
AppManager.getAppManager().startActivity(AnnualHealthStatusActivity.class);
|
}
|
});
|
|
binding.ivOperate.setOnClickListener(v -> {
|
popupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,118) +binding.ivOperate.getWidth(),0);
|
});
|
|
|
}
|
|
@Override
|
public void initData() {
|
|
}
|
|
@Override
|
public void initLiveDataObserve() {
|
viewModel.getIsLifeHabitsExpendedLiveData().observe(this, aBoolean -> {
|
if (aBoolean){
|
binding.ivLifeHabitsFold.setOnClickListener(view -> {
|
collapseView(binding.cardLifeHabits,binding.layoutTitleLifeHabits);
|
viewModel.getIsLifeHabitsExpendedLiveData().setValue(false);
|
});
|
}else {
|
binding.ivLifeHabitsFold.setOnClickListener(view -> {
|
expendView(binding.cardLifeHabits);
|
viewModel.getIsLifeHabitsExpendedLiveData().setValue(true);
|
});
|
}
|
});
|
viewModel.getIsHealthExpendedLiveData().observe(this, aBoolean -> {
|
if (aBoolean){
|
binding.ivHealthFold.setOnClickListener(view -> {
|
collapseView(binding.cardHealth,binding.layoutTitleHealth);
|
viewModel.getIsHealthExpendedLiveData().setValue(false);
|
});
|
}else {
|
binding.ivHealthFold.setOnClickListener(view -> {
|
expendView(binding.cardHealth);
|
viewModel.getIsHealthExpendedLiveData().setValue(true);
|
});
|
}
|
});
|
viewModel.getIsNursingExpendedLiveData().observe(this, aBoolean -> {
|
if (aBoolean){
|
binding.ivNursingFold.setOnClickListener(view -> {
|
collapseView(binding.cardNursing,binding.layoutTitleNursing);
|
viewModel.getIsNursingExpendedLiveData().setValue(false);
|
});
|
}else {
|
binding.ivNursingFold.setOnClickListener(view -> {
|
expendView(binding.cardNursing);
|
viewModel.getIsNursingExpendedLiveData().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(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();
|
}
|
|
}
|