| | |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.EditText; |
| | | 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.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.databinding.ActivityIncomeAndExpensesDetailBinding; |
| | | import com.application.zhangshi_app_android.databinding.ActivityLittleDoctorDetailBinding; |
| | | import com.application.zhangshi_app_android.ui.DLBaseActivity; |
| | | import com.github.gzuliyujiang.wheelpicker.DatePicker; |
| | | import com.github.gzuliyujiang.wheelpicker.OptionPicker; |
| | | import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener; |
| | | import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener; |
| | | 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.Arrays; |
| | | import java.util.List; |
| | | import java.util.function.Consumer; |
| | | |
| | | /** |
| | | * @author Ljj |
| | |
| | | */ |
| | | public class IncomeAndExpensesDetailActivity extends DLBaseActivity<ActivityIncomeAndExpensesDetailBinding, IncomeAndExpensesDetailActivityViewModel> { |
| | | |
| | | private int type;// 0 查看可修改删除 1 新增 2 直接修改 |
| | | private PopupWindow popupWindow; |
| | | private ImageRvAdapter adapter; |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void initParam() { |
| | | if (getIntent().hasExtra("bean")){ |
| | | viewModel.getBeanLiveData().setValue((IncomeAndExpensesBean) getIntent().getSerializableExtra("bean")); |
| | | type = getIntent().getIntExtra(BaseConfig.EXTRA_TYPE,0); |
| | | if (type == 0 || type == 2){ |
| | | IncomeAndExpensesBean bean = (IncomeAndExpensesBean) getIntent().getSerializableExtra("bean"); |
| | | if (bean !=null){ |
| | | viewModel.getBeanLiveData().setValue(bean); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3); |
| | | binding.rvImage.setLayoutManager(gridLayoutManager); |
| | | binding.rvImage.setNestedScrollingEnabled(false); |
| | | setIsEdited(false); |
| | | View footerView = View.inflate(this,R.layout.item_image_footer,null); |
| | | binding.rvImage.addFooterView(footerView); |
| | | binding.rvImage.requestLayout(); |
| | | footerView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | UserManager.getInstance().selectImage(getSelfActivity(), 9, new OnResultCallbackListener<LocalMedia>() { |
| | | @Override |
| | | public void onResult(ArrayList<LocalMedia> result) { |
| | | if (result.size() == 0) return; |
| | | for (LocalMedia media : result) { |
| | | String path = media.getRealPath(); |
| | | File file = new File(path); |
| | | if (file.exists()) { |
| | | viewModel.uploadFile(file); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | adapter.setOnChildClickListener(R.id.iv_delete, new BaseRVAdapter.OnChildClickListener() { |
| | | @Override |
| | | public void onChildClick(RecyclerView recyclerView, View childView, int position) { |
| | | IncomeAndExpensesBean bean = viewModel.getBeanLiveData().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.getBeanLiveData().setValue(bean); |
| | | } |
| | | }); |
| | | binding.rvImage.setAdapter(adapter); |
| | | |
| | | if (type == 1){ |
| | | viewModel.getTypeLiveData().postValue(true); |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | viewModel.add(); |
| | | }); |
| | | }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(true); |
| | | 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(); |
| | | } |
| | | }); |
| | | viewModel.getTypeLiveData().postValue(false); |
| | | }else if (type == 2){ |
| | | viewModel.getTypeLiveData().postValue(true); |
| | | } |
| | | binding.etTime.setOnClickListener(v -> { |
| | | DatePicker picker = getDatePicker(); |
| | | picker.setTitle("选择时间"); |
| | | picker.setOnDatePickedListener(new OnDatePickedListener() { |
| | | @Override |
| | | public void onDatePicked(int year, int month, int day) { |
| | | binding.etTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | } |
| | | }); |
| | | picker.show(); |
| | | }); |
| | | binding.etPrice.setOnClickListener(v -> { |
| | | List<String> list = Arrays.asList("收入","支出"); |
| | | OptionPicker picker = getOptionPicker(list); |
| | | picker.setTitle("选择收支类型"); |
| | | picker.setDefaultValue(binding.etPrice.getText().toString()); |
| | | picker.setOnOptionPickedListener(new OnOptionPickedListener() { |
| | | @Override |
| | | public void onOptionPicked(int position, Object item) { |
| | | binding.etPrice.setText((String) item); |
| | | } |
| | | }); |
| | | picker.show(); |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void initLiveDataObserve() { |
| | | viewModel.getBeanLiveData().observe(this,bean -> { |
| | | if (bean!=null){ |
| | | String url = bean.getUrl(); |
| | | if (url == null||url.isEmpty()){ |
| | | return; |
| | | } |
| | | List<String> list; |
| | | if (url.contains(",")){ |
| | | String[] split = url.split(","); |
| | | list = new ArrayList<>(Arrays.asList(split)); |
| | | adapter.setData(Utils.splitString2List(bean.getUrl(),",")); |
| | | } |
| | | }); |
| | | viewModel.getTypeLiveData().observe(this,operateType -> { |
| | | if (operateType){ |
| | | if (type == 1) { |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | viewModel.add(); |
| | | }); |
| | | }else { |
| | | list = new ArrayList<>(); |
| | | list.add(url); |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | viewModel.update(); |
| | | }); |
| | | } |
| | | adapter.setData(list); |
| | | binding.rvImage.getFooterViews().forEach(new Consumer<View>() { |
| | | @Override |
| | | public void accept(View view) { |
| | | view.setVisibility(View.VISIBLE); |
| | | } |
| | | }); |
| | | adapter.setIsEdited(true); |
| | | }else { |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | popupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0); |
| | | }); |
| | | binding.rvImage.getFooterViews().forEach(new Consumer<View>() { |
| | | @Override |
| | | public void accept(View view) { |
| | | view.setVisibility(View.GONE); |
| | | } |
| | | }); |
| | | adapter.setIsEdited(false); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |