| | |
| | | package com.application.zhangshi_app_android.ui.function; |
| | | |
| | | |
| | | import android.graphics.drawable.ColorDrawable; |
| | | import android.os.Bundle; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | 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 com.android.app_base.utils.ScreenSizeUtils; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.viewpager.widget.ViewPager; |
| | | |
| | | 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 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; |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.activity_growth_experience; |
| | | } |
| | | |
| | | @Override |
| | | public int getVariableId() { |
| | | return BR.viewModel; |
| | | } |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.activity_growth_experience; |
| | | } |
| | | |
| | | @Override |
| | | public int getVariableId() { |
| | | return BR.viewModel; |
| | | } |
| | | |
| | | @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() { |
| | | if (type == 1){ |
| | | binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish); |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | viewModel.add(); |
| | | }); |
| | | }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.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(); |
| | | } |
| | | }); |
| | | 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(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void initData() { |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void initLiveDataObserve() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void initParam() { |
| | | |
| | | } |
| | | |
| | | // 设置选中效果 |
| | | |
| | | |
| | | @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)); |
| | | itemDecoration.setFirstTop((int) getResources().getDimension(com.android.app_base.R.dimen.dp_16)); |
| | | |
| | | binding.rvPrimary.addItemDecoration(itemDecoration); |
| | | binding.rvPrimary.setAdapter(primaryRvAdapter); |
| | | binding.rvRelationship.addItemDecoration(itemDecoration); |
| | | binding.rvRelationship.setAdapter(relationshipRvAdapter); |
| | | binding.rvCertificates.addItemDecoration(itemDecoration); |
| | | binding.rvCertificates.setAdapter(holderConditionRvAdapter); |
| | | binding.rvAbroad.addItemDecoration(itemDecoration); |
| | | binding.rvAbroad.setAdapter(abroadConditionRvAdapter); |
| | | |
| | | //这里的tab数量就是后台返回的数据量,tab的标题也是后台返回的,但是{"id":1,"userId":110,"type":1,"content":"婴儿时期我很快乐"}后台的返回数据没有这个时间段,你就得问一下,看不懂吗?? |
| | | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("0-3岁(婴儿期)")); |
| | | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("3-6岁(幼儿期)")); |
| | | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("6-9岁(青年期) ")); |
| | | |
| | | //就不知道脑子在想什么 |
| | | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { |
| | | @Override |
| | | public void onTabSelected(TabLayout.Tab tab) { |
| | | // 当用户选中一个 Tab 时回调 |
| | | // 这里可以根据 Tab 的位置来切换相应的页面 |
| | | switch (tab.getPosition()) { |
| | | case 0: |
| | | // 切换到 0-3 岁页面 |
| | | break; |
| | | case 1: |
| | | // 切换到 3-6 岁页面 |
| | | break; |
| | | case 2: |
| | | // 切换到 6-9 岁页面 |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | @Override |
| | | public void onTabUnselected(TabLayout.Tab tab) { |
| | | // 当用户取消选中一个 Tab 时回调 |
| | | } |
| | | |
| | | @Override |
| | | public void onTabReselected(TabLayout.Tab tab) { |
| | | // 当用户再次选中一个已经选中的 Tab 时回调 |
| | | } |
| | | }); |
| | | // 创建 ViewPager 并设置 Adapter |
| | | ViewPager viewPager = binding.viewPager; |
| | | // 将 TabLayout 与 ViewPager 关联起来 |
| | | binding.tabLayout.setupWithViewPager(viewPager); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void initData() { |
| | | viewModel.getInfo(); |
| | | viewModel.getGrowthExperience(); |
| | | viewModel.getRelation(); |
| | | viewModel.getHolder(); |
| | | viewModel.getAbroad(); |
| | | viewModel.getGrowthExperienceAutobiography(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void initLiveDataObserve() { |
| | | viewModel.getPrimaryLiveData().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); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | private PopupWindow initPopUpWindow(View view){ |
| | | PopupWindow popupWindow = new PopupWindow(this); |
| | | // 设置布局文件 |
| | | popupWindow.setContentView(view); |
| | | // 为了避免部分机型不显示,需要重新设置一下宽高 |
| | | 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(false); |
| | | return popupWindow; |
| | | } |
| | | } |