| | |
| | | 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.LinearLayout; |
| | | import android.widget.PopupWindow; |
| | | |
| | | |
| | | 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.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 |
| | |
| | | * @desc 成长经历 GrowthExperienceActivity |
| | | */ |
| | | 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() { |
| | |
| | | |
| | | @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 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.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()); |
| | | } |
| | | |
| | | @Override |
| | | public void onTabUnselected(TabLayout.Tab tab) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onTabReselected(TabLayout.Tab tab) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | 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 onLeftClick(TitleBar titleBar) { |
| | | finish(); |
| | | } |
| | | |
| | | } |