| | |
| | | package com.application.zhangshi_app_android.ui.function; |
| | | |
| | | |
| | | import android.graphics.drawable.ColorDrawable; |
| | | import android.os.Bundle; |
| | | import android.view.LayoutInflater; |
| | | 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.LinearLayout; |
| | | import android.widget.PopupWindow; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.android.app_base.base.BaseConfig; |
| | | import com.android.app_base.base.dialog.BaseDialog; |
| | | import com.android.app_base.base.dialog.UIDialog; |
| | | import com.android.app_base.base.view.BaseActivity; |
| | | import androidx.constraintlayout.widget.ConstraintLayout; |
| | | import androidx.lifecycle.Observer; |
| | | |
| | | import com.android.app_base.manager.AppManager; |
| | | import com.android.app_base.utils.ScreenSizeUtils; |
| | | import com.android.app_base.utils.ToastUtils; |
| | | import com.android.app_base.widget.LinearItemDecoration; |
| | | import com.application.zhangshi_app_android.BR; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean; |
| | | import com.application.zhangshi_app_android.databinding.ItemFamilyCreateBinding; |
| | | import com.application.zhangshi_app_android.adapter.GrowthExperienceAbroadConditionRvAdapter; |
| | | import com.application.zhangshi_app_android.adapter.GrowthExperienceHolderConditionRvAdapter; |
| | | import com.application.zhangshi_app_android.adapter.GrowthExperiencePrimaryRvAdapter; |
| | | import com.application.zhangshi_app_android.adapter.GrowthExperienceRelationshipRvAdapter; |
| | | import com.application.zhangshi_app_android.bean.GrowthExperienceAbroadConditionBean; |
| | | import com.application.zhangshi_app_android.bean.GrowthExperienceAutobiographyBean; |
| | | import com.application.zhangshi_app_android.bean.GrowthExperienceBean; |
| | | import com.application.zhangshi_app_android.bean.GrowthExperienceHolderConditionBean; |
| | | import com.application.zhangshi_app_android.bean.GrowthExperienceRelationshipBean; |
| | | import com.application.zhangshi_app_android.databinding.ActivityGrowthExperienceBinding; |
| | | import com.application.zhangshi_app_android.ui.DLBaseActivity; |
| | | import com.google.android.material.tabs.TabLayout; |
| | | import com.hjq.bar.TitleBar; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author Gss |
| | | * @date 2023.03.31. 16:00 |
| | | * @desc 成长经历 GrowthExperienceActivity |
| | | */ |
| | | public class GrowthExperienceActivity { |
| | | public class GrowthExperienceActivity extends BaseActivity<GrowthExperienceActivityBinding,GrowthExperienceActivityViewModel> { |
| | | private int type; |
| | | private int operateType; |
| | | private PopupWindow popupWindow; |
| | | public class GrowthExperienceActivity extends DLBaseActivity<ActivityGrowthExperienceBinding,GrowthExperienceActivityViewModel> { |
| | | private GrowthExperiencePrimaryRvAdapter primaryRvAdapter; |
| | | private GrowthExperienceRelationshipRvAdapter relationshipRvAdapter; |
| | | private GrowthExperienceHolderConditionRvAdapter holderConditionRvAdapter; |
| | | private GrowthExperienceAbroadConditionRvAdapter abroadConditionRvAdapter; |
| | | |
| | | private PopupWindow mOperatePopupWindow; |
| | | |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.activity_growth_experience; |
| | | } |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.activity_growth_experience; |
| | | } |
| | | @Override |
| | | public int getVariableId() { |
| | | return BR.viewModel; |
| | | } |
| | | |
| | | @Override |
| | | public int getVariableId() { |
| | | return BR.viewModel; |
| | | } |
| | | @Override |
| | | public void initParam() { |
| | | |
| | | @Override |
| | | public void initParam() { |
| | | type = getIntent().getIntExtra(BaseConfig.EXTRA_TYPE,0); |
| | | if (type == 0){ |
| | | GrowthExperienceBean bean = (GrowthExperienceBean) getIntent().getSerializableExtra("bean"); |
| | | if (bean!=null){ |
| | | viewModel.getBeanMutableLiveData().postValue(bean); |
| | | } |
| | | |
| | | @Override |
| | | public void initView() { |
| | | primaryRvAdapter = new GrowthExperiencePrimaryRvAdapter(this); |
| | | relationshipRvAdapter = new GrowthExperienceRelationshipRvAdapter(this); |
| | | holderConditionRvAdapter = new GrowthExperienceHolderConditionRvAdapter(this ); |
| | | abroadConditionRvAdapter = new GrowthExperienceAbroadConditionRvAdapter(this); |
| | | |
| | | LinearItemDecoration itemDecoration = new LinearItemDecoration(); |
| | | itemDecoration.setBottomSpace((int) getResources().getDimension(com.android.app_base.R.dimen.dp_12)); |
| | | |
| | | binding.rvPrimary.addItemDecoration(itemDecoration); |
| | | binding.rvPrimary.setNestedScrollingEnabled(false); |
| | | binding.rvPrimary.setAdapter(primaryRvAdapter); |
| | | binding.rvRelationship.addItemDecoration(itemDecoration); |
| | | binding.rvRelationship.setNestedScrollingEnabled(false); |
| | | binding.rvRelationship.setAdapter(relationshipRvAdapter); |
| | | binding.rvCertificates.addItemDecoration(itemDecoration); |
| | | binding.rvCertificates.setNestedScrollingEnabled(false); |
| | | binding.rvCertificates.setAdapter(holderConditionRvAdapter); |
| | | binding.rvAbroad.addItemDecoration(itemDecoration); |
| | | binding.rvAbroad.setNestedScrollingEnabled(false); |
| | | binding.rvAbroad.setAdapter(abroadConditionRvAdapter); |
| | | |
| | | mOperatePopupWindow = initPopUpWindow(View.inflate(this,R.layout.pop_personal_notepad,null)); |
| | | mOperatePopupWindow.getContentView().findViewById(R.id.layout_personal_notepad).setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | mOperatePopupWindow.dismiss(); |
| | | AppManager.getAppManager().startActivity(PersonalNotepadActivity.class); |
| | | } |
| | | }); |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0); |
| | | }); |
| | | |
| | | 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 initView() { |
| | | if (type == 1){ |
| | | binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish); |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | viewModel.add(); |
| | | @Override |
| | | public void initData() { |
| | | viewModel.getInfo(); |
| | | viewModel.getGrowthExperience(); |
| | | viewModel.getRelation(); |
| | | viewModel.getHolder(); |
| | | viewModel.getAbroad(); |
| | | viewModel.getGrowthExperienceAutobiography(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void initLiveDataObserve() { |
| | | viewModel.getIsExperienceExpendedLiveData().observe(this, aBoolean -> { |
| | | if (aBoolean){ |
| | | binding.layoutExperienceTitle.setOnClickListener(view -> { |
| | | collapseView(binding.layoutExperience,binding.layoutExperienceTitle); |
| | | viewModel.getIsExperienceExpendedLiveData().setValue(false); |
| | | }); |
| | | }else { |
| | | binding.ivOperate.setBackgroundResource(R.drawable.ic_operate); |
| | | popupWindow = new PopupWindow(this); |
| | | // 设置布局文件 |
| | | popupWindow.setContentView(LayoutInflater.from(this).inflate(R.layout.pop_operate_delete, null)); |
| | | // 为了避免部分机型不显示,需要重新设置一下宽高 |
| | | popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | // 设置pop透明效果 |
| | | popupWindow.setBackgroundDrawable(new ColorDrawable(0x0000)); |
| | | // 设置pop出入动画 |
| | | popupWindow.setAnimationStyle(com.android.app_base.R.style.pop_add); |
| | | // 设置pop获取焦点,如果为false点击返回按钮会退出当前Activity,如果pop中有Editor的话,focusable必须要为true |
| | | popupWindow.setFocusable(true); |
| | | // 设置pop可点击,为false点击事件无效,默认为true |
| | | popupWindow.setTouchable(true); |
| | | // 设置点击pop外侧消失,默认为false;在focusable为true时点击外侧始终消失 |
| | | popupWindow.setOutsideTouchable(true); |
| | | binding.layoutExperienceTitle.setOnClickListener(view -> { |
| | | expendView(binding.layoutExperience); |
| | | viewModel.getIsExperienceExpendedLiveData().setValue(true); |
| | | }); |
| | | } |
| | | }); |
| | | viewModel.getIsRelationExpendedLiveData().observe(this, aBoolean -> { |
| | | if (aBoolean){ |
| | | binding.layoutRelationTitle.setOnClickListener(view -> { |
| | | collapseView(binding.layoutRelation,binding.layoutRelationTitle); |
| | | viewModel.getIsRelationExpendedLiveData().setValue(false); |
| | | }); |
| | | }else { |
| | | binding.layoutRelationTitle.setOnClickListener(view -> { |
| | | expendView(binding.layoutRelation); |
| | | viewModel.getIsRelationExpendedLiveData().setValue(true); |
| | | }); |
| | | } |
| | | }); |
| | | viewModel.getIsHolderExpendedLiveData().observe(this, aBoolean -> { |
| | | if (aBoolean){ |
| | | binding.layoutHolderTitle.setOnClickListener(view -> { |
| | | collapseView(binding.layoutHolder,binding.layoutHolderTitle); |
| | | viewModel.getIsHolderExpendedLiveData().setValue(false); |
| | | }); |
| | | }else { |
| | | binding.layoutHolderTitle.setOnClickListener(view -> { |
| | | expendView(binding.layoutHolder); |
| | | viewModel.getIsHolderExpendedLiveData().setValue(true); |
| | | }); |
| | | } |
| | | }); |
| | | viewModel.getIsAbroadExpendedLiveData().observe(this, aBoolean -> { |
| | | if (aBoolean){ |
| | | binding.layoutAbroadTitle.setOnClickListener(view -> { |
| | | collapseView(binding.layoutAbroad,binding.layoutAbroadTitle); |
| | | viewModel.getIsAbroadExpendedLiveData().setValue(false); |
| | | }); |
| | | }else { |
| | | binding.layoutAbroadTitle.setOnClickListener(view -> { |
| | | expendView(binding.layoutAbroad); |
| | | viewModel.getIsAbroadExpendedLiveData().setValue(true); |
| | | }); |
| | | } |
| | | }); |
| | | viewModel.getExperienceListLiveData().observe(this, new Observer<List<GrowthExperienceBean>>() { |
| | | @Override |
| | | public void onChanged(List<GrowthExperienceBean> growthExperienceBeans) { |
| | | primaryRvAdapter.setData(growthExperienceBeans); |
| | | } |
| | | }); |
| | | viewModel.getRelationLiveData().observe(this, new Observer<List<GrowthExperienceRelationshipBean>>() { |
| | | @Override |
| | | public void onChanged(List<GrowthExperienceRelationshipBean> growthExperienceRelationshipBeans) { |
| | | relationshipRvAdapter.setData(growthExperienceRelationshipBeans); |
| | | } |
| | | }); |
| | | viewModel.getHolderLiveData().observe(this, new Observer<List<GrowthExperienceHolderConditionBean>>() { |
| | | @Override |
| | | public void onChanged(List<GrowthExperienceHolderConditionBean> growthExperienceHolderConditionBeans) { |
| | | holderConditionRvAdapter.setData(growthExperienceHolderConditionBeans); |
| | | } |
| | | }); |
| | | viewModel.getAbroadLiveData().observe(this, new Observer<List<GrowthExperienceAbroadConditionBean>>() { |
| | | @Override |
| | | public void onChanged(List<GrowthExperienceAbroadConditionBean> growthExperienceAbroadConditionBeans) { |
| | | abroadConditionRvAdapter.setData(growthExperienceAbroadConditionBeans); |
| | | } |
| | | }); |
| | | viewModel.getAutobiographyLiveData().observe(this, new Observer<List<GrowthExperienceAutobiographyBean>>() { |
| | | @Override |
| | | public void onChanged(List<GrowthExperienceAutobiographyBean> beans) { |
| | | if (beans==null||beans.size() == 0 ){ |
| | | binding.tvFill.setVisibility(View.GONE); |
| | | return; |
| | | }else { |
| | | binding.tvFill.setVisibility(View.VISIBLE); |
| | | } |
| | | binding.tabLayout.removeAllTabs(); |
| | | for (int i = 0; i < beans.size(); i++) { |
| | | GrowthExperienceAutobiographyBean bean = beans.get(i); |
| | | String tabText = bean.getAgeBegin()+"-"+bean.getAgeEnd()+"岁("+bean.getTerm()+")"; |
| | | TabLayout.Tab tab = binding.tabLayout.newTab().setText(tabText); |
| | | if (i % 2 == 0){ |
| | | tab.view.setBackgroundResource(R.drawable.selector_tab_background_pink); |
| | | }else { |
| | | tab.view.setBackgroundResource(R.drawable.selector_tab_background_blue); |
| | | } |
| | | //取消tab的长按显示文本 |
| | | tab.view.setOnLongClickListener(new View.OnLongClickListener() { |
| | | @Override |
| | | public boolean onLongClick(View v) { |
| | | return true; |
| | | } |
| | | }); |
| | | binding.tabLayout.addTab(tab); |
| | | } |
| | | binding.tvFill.setText(beans.get(0).getContent()); |
| | | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { |
| | | @Override |
| | | public void onTabSelected(TabLayout.Tab tab) { |
| | | binding.tvFill.setText(beans.get(tab.getPosition()).getContent()); |
| | | } |
| | | |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | if (operateType == 0){ |
| | | popupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0); |
| | | }else{ |
| | | viewModel.update(); |
| | | } |
| | | }); |
| | | popupWindow.getContentView().findViewById(R.id.tv_modify).setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish); |
| | | operateType = 1; |
| | | popupWindow.dismiss(); |
| | | public void onTabUnselected(TabLayout.Tab tab) { |
| | | |
| | | } |
| | | }); |
| | | popupWindow.getContentView().findViewById(R.id.tv_delete).setOnClickListener(new View.OnClickListener() { |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | popupWindow.dismiss(); |
| | | new UIDialog.Builder(getSelfActivity()) |
| | | .setTitle("您确定要删除项目吗") |
| | | .setContent("项目删除后将无法恢复") |
| | | .setConfirm("确定") |
| | | .setCancel("取消") |
| | | .setListener(new UIDialog.OnListener() { |
| | | @Override |
| | | public void onConfirm(BaseDialog dialog) { |
| | | viewModel.delete(); |
| | | } |
| | | }) |
| | | .show(); |
| | | public void onTabReselected(TabLayout.Tab tab) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | public void initData() { |
| | | } |
| | | 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(); |
| | | } |
| | | |
| | | @Override |
| | | public void initLiveDataObserve() { |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onLeftClick(TitleBar titleBar) { |
| | | finish(); |
| | | } |
| | | |
| | | } |