| File was renamed from app/src/main/java/com/application/zhangshi_app_android/ui/function/CreateFamilyProjectActivity.java |
| | |
| | | import android.widget.PopupWindow; |
| | | |
| | | import androidx.recyclerview.widget.GridLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.android.app_base.base.BaseConfig; |
| | | import com.android.app_base.base.adapter.BaseRVAdapter; |
| | | 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.manager.UserManager; |
| | | import com.android.app_base.utils.ScreenSizeUtils; |
| | | import com.android.app_base.utils.Utils; |
| | | import com.application.zhangshi_app_android.BR; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.adapter.ImageRvAdapter; |
| | | import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean; |
| | | import com.application.zhangshi_app_android.databinding.ActivityFamilyMemorabiliaCreateBinding; |
| | | import com.application.zhangshi_app_android.bean.LittleDoctorBean; |
| | | import com.application.zhangshi_app_android.databinding.ActivityFamilyMemorabiliaDetailBinding; |
| | | import com.application.zhangshi_app_android.ui.DLBaseActivity; |
| | | import com.github.gzuliyujiang.wheelpicker.DatePicker; |
| | | import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener; |
| | | import com.luck.picture.lib.entity.LocalMedia; |
| | | import com.luck.picture.lib.interfaces.OnResultCallbackListener; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import java.util.function.Consumer; |
| | | |
| | | |
| | | /** |
| | | * @author Gss |
| | | * @date 2023.03.25. 16:00 |
| | | * @desc 家大事记 CreateFamilyProjectActivity |
| | | * @desc 家大事记 FamilyMemorabiliaDetailActivity |
| | | */ |
| | | public class CreateFamilyProjectActivity extends BaseActivity<ActivityFamilyMemorabiliaCreateBinding,CreateFamilyProjectActivityViewModel> { |
| | | private int type; |
| | | public class FamilyMemorabiliaDetailActivity extends DLBaseActivity<ActivityFamilyMemorabiliaDetailBinding, FamilyMemorabiliaDetailActivityViewModel> { |
| | | private int type;// 0 查看可修改删除 1 新增 2 直接修改 |
| | | private PopupWindow popupWindow; |
| | | private FamilyMemorabiliaBean bean; |
| | | private ImageRvAdapter adapter; |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.activity_family_memorabilia_create; |
| | | return R.layout.activity_family_memorabilia_detail; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public void initParam() { |
| | | type = getIntent().getIntExtra(BaseConfig.EXTRA_TYPE,0); |
| | | if (type == 0){ |
| | | bean = (FamilyMemorabiliaBean) getIntent().getSerializableExtra("bean"); |
| | | if (bean!=null){ |
| | | viewModel.getBeanMutableLiveData().postValue(bean); |
| | | if (type == 0 || type == 2){ |
| | | FamilyMemorabiliaBean bean = (FamilyMemorabiliaBean) getIntent().getSerializableExtra("bean"); |
| | | if (bean !=null){ |
| | | viewModel.getBeanMutableLiveData().setValue(bean); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void initView() { |
| | | adapter = new ImageRvAdapter(this,viewModel); |
| | | adapter = new ImageRvAdapter(this); |
| | | GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3); |
| | | binding.rvImage.setLayoutManager(gridLayoutManager); |
| | | binding.rvImage.setNestedScrollingEnabled(false); |
| | |
| | | }); |
| | | } |
| | | }); |
| | | adapter.setOnChildClickListener(R.id.iv_delete, new BaseRVAdapter.OnChildClickListener() { |
| | | @Override |
| | | public void onChildClick(RecyclerView recyclerView, View childView, int position) { |
| | | FamilyMemorabiliaBean bean = viewModel.getBeanMutableLiveData().getValue(); |
| | | if (bean !=null){ |
| | | List<String> urlList = Utils.splitString2List(bean.getUrl(),","); |
| | | urlList.remove(adapter.getItem(position)); |
| | | bean.setUrl(Utils.appendList2String(urlList,",")); |
| | | } |
| | | adapter.removeItem(position); |
| | | viewModel.getBeanMutableLiveData().setValue(bean); |
| | | } |
| | | }); |
| | | binding.rvImage.setAdapter(adapter); |
| | | |
| | | if (type == 1){ |
| | | viewModel.getTypeLiveData().postValue(true); |
| | | viewModel.getTypeLiveData().setValue(true); |
| | | binding.titleBar.setTitle("新增家大事记"); |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | viewModel.add(); |
| | | }); |
| | | }else { |
| | | 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_operate); |
| | | // 设置pop获取焦点,如果为false点击返回按钮会退出当前Activity,如果pop中有Editor的话,focusable必须要为true |
| | | popupWindow.setFocusable(true); |
| | | // 设置pop可点击,为false点击事件无效,默认为true |
| | | popupWindow.setTouchable(true); |
| | | // 设置点击pop外侧消失,默认为false;在focusable为true时点击外侧始终消失 |
| | | popupWindow.setOutsideTouchable(true); |
| | | |
| | | }else if (type == 0){ |
| | | popupWindow = initPopUpWindow(View.inflate(this,R.layout.pop_operate_delete,null)); |
| | | popupWindow.getContentView().findViewById(R.id.tv_modify).setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | } |
| | | }); |
| | | viewModel.getTypeLiveData().postValue(false); |
| | | }else if (type == 2){ |
| | | viewModel.getTypeLiveData().postValue(true); |
| | | |
| | | } |
| | | |
| | | binding.etTime.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | DatePicker picker = getDatePicker(); |
| | | picker.setTitle("选择时间"); |
| | | picker.setOnDatePickedListener(new OnDatePickedListener() { |
| | | @Override |
| | | public void onDatePicked(int year, int month, int day) { |
| | | String date = String.format(Locale.CHINA, "%d-%02d-%02d", year, month, day); |
| | | binding.etTime.setText(date); |
| | | } |
| | | }); |
| | | picker.show(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | |
| | | public void initLiveDataObserve() { |
| | | viewModel.getBeanMutableLiveData().observe(this,bean -> { |
| | | if (bean!=null){ |
| | | bean.setUrl(bean.getUrl()); |
| | | adapter.setData(bean.getUrlList()); |
| | | List<String> urlList = Utils.splitString2List(bean.getUrl(),","); |
| | | adapter.setData(urlList); |
| | | } |
| | | }); |
| | | viewModel.getTypeLiveData().observe(this,operateType -> { |
| | |
| | | } |
| | | |
| | | public void setIsEdited(boolean isEdited){ |
| | | disableAllEditText(getContentView(),isEdited); |
| | | adapter.setIsEdited(isEdited); |
| | | } |
| | | public void disableAllEditText(ViewGroup viewGroup,boolean isEdited) { |
| | | for (int i = 0; i < viewGroup.getChildCount(); i++) { |
| | | View child = viewGroup.getChildAt(i); |
| | | if (child instanceof ViewGroup) { |
| | | disableAllEditText((ViewGroup) child,isEdited); |
| | | } else if (child instanceof EditText) { |
| | | child.setEnabled(isEdited); |
| | | child.setFocusable(isEdited); |
| | | child.setFocusableInTouchMode(isEdited); |
| | | if (!isEdited){ |
| | | child.clearFocus(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |