| | |
| | | package com.application.zhangshi_app_android.ui.function; |
| | | |
| | | import android.text.Editable; |
| | | import android.text.TextUtils; |
| | | import android.text.TextWatcher; |
| | | import android.view.MotionEvent; |
| | | import android.view.View; |
| | | import android.widget.PopupWindow; |
| | | |
| | | import com.android.app_base.utils.ScreenSizeUtils; |
| | | import com.android.app_base.utils.Utils; |
| | | 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.CleanStorageRvAdapter; |
| | | import com.application.zhangshi_app_android.adapter.PetMemoRvAdapter; |
| | | import com.application.zhangshi_app_android.bean.PetBean; |
| | | import com.application.zhangshi_app_android.databinding.ActivityCleanStorageBinding; |
| | | import com.application.zhangshi_app_android.databinding.ActivityPetMemoBinding; |
| | | import com.application.zhangshi_app_android.ui.DLBaseActivity; |
| | | import com.github.gzuliyujiang.wheelpicker.DatePicker; |
| | | import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener; |
| | | import com.hjq.bar.TitleBar; |
| | | |
| | | /** |
| | |
| | | public class PetMemoActivity extends DLBaseActivity<ActivityPetMemoBinding, PetMemoActivityViewModel> { |
| | | |
| | | private PetMemoRvAdapter adapter; |
| | | |
| | | private PopupWindow mOperatePopupWindow; |
| | | private boolean isSearchLayoutVisible; |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.activity_pet_memo; |
| | |
| | | |
| | | @Override |
| | | public void initParam() { |
| | | |
| | | if (getIntent().hasExtra("bean")){ |
| | | viewModel.getBeanLiveData().setValue((PetBean) getIntent().getSerializableExtra("bean")); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void initView() { |
| | | //下拉刷新布局 |
| | | binding.refreshLayout.setEnableRefresh(false); |
| | | binding.refreshLayout.setEnableLoadMore(true); |
| | | binding.refreshLayout.setEnableOverScrollDrag(true); |
| | | binding.refreshLayout.setOnLoadMoreListener(refreshLayout -> { |
| | | viewModel.getMorePetMemo(); |
| | | }); |
| | | //recyclerView适配器 |
| | | adapter = new PetMemoRvAdapter(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_20)); |
| | | binding.recyclerView.addItemDecoration(itemDecoration); |
| | | binding.recyclerView.setAdapter(adapter); |
| | | //右上角操作弹窗 |
| | | mOperatePopupWindow = initPopUpWindow(View.inflate(this,R.layout.pop_operate,null)); |
| | | mOperatePopupWindow.getContentView().findViewById(R.id.layout_add).setVisibility(View.GONE); |
| | | mOperatePopupWindow.getContentView().findViewById(R.id.layout_select).setVisibility(View.GONE); |
| | | mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_new_to_old).setOnClickListener(v -> { |
| | | viewModel.sortDataList(0); |
| | | mOperatePopupWindow.dismiss(); |
| | | }); |
| | | mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_old_to_new).setOnClickListener(v -> { |
| | | viewModel.sortDataList(1); |
| | | mOperatePopupWindow.dismiss(); |
| | | }); |
| | | //点击弹出操作弹窗 |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0); |
| | | }); |
| | | //点击放大镜按钮显示出搜索框 |
| | | binding.ivSearchDefault.setOnClickListener(v -> { |
| | | binding.layoutSearch.setVisibility(View.VISIBLE); |
| | | binding.layoutDefault.setVisibility(View.GONE); |
| | | }); |
| | | //点击搜索框菜单下拉出 搜索参数 |
| | | binding.ivSearchType.setOnClickListener(v -> { |
| | | if (!isSearchLayoutVisible){ |
| | | binding.layoutSearchParameter.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); |
| | | int targetHeight = binding.layoutSearchParameter.getMeasuredHeight(); |
| | | Utils.pullCollapse(binding.containerSearchParameter,0,targetHeight); |
| | | isSearchLayoutVisible = true; |
| | | } |
| | | }); |
| | | //搜索参数layout添加空点击事件,防止点击它内部view时它后面的recycler还能响应点击事件 |
| | | binding.layoutSearchParameter.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | } |
| | | }); |
| | | //点击搜索按钮进行搜索 |
| | | binding.ivSearch.setOnClickListener(v -> { |
| | | viewModel.getPetMemo(); |
| | | binding.layoutSearch.setVisibility(View.GONE); |
| | | binding.layoutDefault.setVisibility(View.VISIBLE); |
| | | binding.tvTitle.setText("搜索结果"); |
| | | hideSoftKeyboard(); |
| | | }); |
| | | binding.etStartTime.addTextChangedListener(new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | if (!TextUtils.isEmpty(s)) { |
| | | binding.ivTimeClear.setVisibility(View.VISIBLE); |
| | | } else { |
| | | if (TextUtils.isEmpty(binding.etEndTime.getText().toString())) { |
| | | binding.ivTimeClear.setVisibility(View.INVISIBLE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | |
| | | } |
| | | }); |
| | | binding.etEndTime.addTextChangedListener(new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | if (!TextUtils.isEmpty(s)) { |
| | | binding.ivTimeClear.setVisibility(View.VISIBLE); |
| | | } else { |
| | | if (TextUtils.isEmpty(binding.etStartTime.getText().toString())) { |
| | | binding.ivTimeClear.setVisibility(View.INVISIBLE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | |
| | | } |
| | | }); |
| | | binding.etStartTime.setOnClickListener(v -> { |
| | | hideSoftKeyboard(); |
| | | DatePicker datePicker = getDatePicker(); |
| | | datePicker.setTitle("请选择开始时间"); |
| | | datePicker.setOnDatePickedListener(new OnDatePickedListener() { |
| | | @Override |
| | | public void onDatePicked(int year, int month, int day) { |
| | | //以yyyy-MM-dd的格式显示,月日小于10时前面补0 |
| | | binding.etStartTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | if (binding.etEndTime.getText().toString().isEmpty()){ |
| | | binding.etEndTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | }else { |
| | | //比较开始时间和结束时间的大小 |
| | | String startTime = binding.etStartTime.getText().toString(); |
| | | String endTime = binding.etEndTime.getText().toString(); |
| | | if (Utils.compareDate(startTime,endTime) > 0){ |
| | | //交换 |
| | | binding.etStartTime.setText(endTime); |
| | | binding.etEndTime.setText(startTime); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | datePicker.show(); |
| | | }); |
| | | binding.etEndTime.setOnClickListener(v -> { |
| | | hideSoftKeyboard(); |
| | | DatePicker datePicker = getDatePicker(); |
| | | datePicker.setTitle("请选择结束时间"); |
| | | datePicker.setOnDatePickedListener(new OnDatePickedListener() { |
| | | @Override |
| | | public void onDatePicked(int year, int month, int day) { |
| | | binding.etEndTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | if (binding.etStartTime.getText().toString().isEmpty()){ |
| | | binding.etStartTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | }else { |
| | | //比较开始时间和结束时间的大小 |
| | | String startTime = binding.etStartTime.getText().toString(); |
| | | String endTime = binding.etEndTime.getText().toString(); |
| | | if (Utils.compareDate(startTime,endTime) > 0){ |
| | | //交换 |
| | | binding.etStartTime.setText(endTime); |
| | | binding.etEndTime.setText(startTime); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | datePicker.show(); |
| | | }); |
| | | binding.ivTimeClear.setOnClickListener(v -> { |
| | | binding.etStartTime.setText(""); |
| | | binding.etEndTime.setText(""); |
| | | }); |
| | | |
| | | binding.etRemindStartTime.addTextChangedListener(new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | if (!TextUtils.isEmpty(s)) { |
| | | binding.ivRemindTimeClear.setVisibility(View.VISIBLE); |
| | | } else { |
| | | if (TextUtils.isEmpty(binding.etRemindEndTime.getText().toString())) { |
| | | binding.ivRemindTimeClear.setVisibility(View.INVISIBLE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | |
| | | } |
| | | }); |
| | | binding.etRemindEndTime.addTextChangedListener(new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | if (!TextUtils.isEmpty(s)) { |
| | | binding.ivRemindTimeClear.setVisibility(View.VISIBLE); |
| | | } else { |
| | | if (TextUtils.isEmpty(binding.etRemindStartTime.getText().toString())) { |
| | | binding.ivRemindTimeClear.setVisibility(View.INVISIBLE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | |
| | | } |
| | | }); |
| | | binding.etRemindStartTime.setOnClickListener(v -> { |
| | | hideSoftKeyboard(); |
| | | DatePicker datePicker = getDatePicker(); |
| | | datePicker.setTitle("请选择开始时间"); |
| | | datePicker.setOnDatePickedListener(new OnDatePickedListener() { |
| | | @Override |
| | | public void onDatePicked(int year, int month, int day) { |
| | | //以yyyy-MM-dd的格式显示,月日小于10时前面补0 |
| | | binding.etRemindStartTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | if (binding.etRemindEndTime.getText().toString().isEmpty()){ |
| | | binding.etRemindEndTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | }else { |
| | | //比较开始时间和结束时间的大小 |
| | | String startTime = binding.etRemindStartTime.getText().toString(); |
| | | String endTime = binding.etRemindEndTime.getText().toString(); |
| | | if (Utils.compareDate(startTime,endTime) > 0){ |
| | | //交换 |
| | | binding.etRemindStartTime.setText(endTime); |
| | | binding.etRemindEndTime.setText(startTime); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | datePicker.show(); |
| | | }); |
| | | binding.etRemindEndTime.setOnClickListener(v -> { |
| | | hideSoftKeyboard(); |
| | | DatePicker datePicker = getDatePicker(); |
| | | datePicker.setTitle("请选择结束时间"); |
| | | datePicker.setOnDatePickedListener(new OnDatePickedListener() { |
| | | @Override |
| | | public void onDatePicked(int year, int month, int day) { |
| | | binding.etRemindEndTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | if (binding.etRemindStartTime.getText().toString().isEmpty()){ |
| | | binding.etRemindStartTime.setText(String.format("%d-%02d-%02d", year, month, day)); |
| | | }else { |
| | | //比较开始时间和结束时间的大小 |
| | | String startTime = binding.etRemindStartTime.getText().toString(); |
| | | String endTime = binding.etRemindEndTime.getText().toString(); |
| | | if (Utils.compareDate(startTime,endTime) > 0){ |
| | | //交换 |
| | | binding.etRemindStartTime.setText(endTime); |
| | | binding.etRemindEndTime.setText(startTime); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | datePicker.show(); |
| | | }); |
| | | binding.ivRemindTimeClear.setOnClickListener(v -> { |
| | | binding.etRemindStartTime.setText(""); |
| | | binding.etRemindEndTime.setText(""); |
| | | }); |
| | | } |
| | | @Override |
| | | public boolean dispatchTouchEvent(MotionEvent event) { |
| | | float x = event.getX(); |
| | | float y = event.getY(); |
| | | if (isSearchLayoutVisible){ |
| | | if (!Utils.isPointInsideView(x, y, binding.layoutSearchParameter)) { |
| | | Utils.pullCollapse(binding.containerSearchParameter, binding.layoutSearchParameter.getMeasuredHeight(),0); |
| | | isSearchLayoutVisible = false; |
| | | return true; |
| | | } |
| | | } |
| | | return super.dispatchTouchEvent(event); |
| | | } |
| | | |
| | | @Override |
| | |
| | | viewModel.getDataListLiveData().observe(this, dataList -> { |
| | | adapter.setData(dataList); |
| | | }); |
| | | viewModel.getMoreListLiveData().observe(this, list -> { |
| | | adapter.addData(list); |
| | | }); |
| | | } |
| | | @Override |
| | | protected void dataNull() { |
| | | super.dataNull(); |
| | | binding.layoutDataNull.setVisibility(View.VISIBLE); |
| | | binding.refreshLayout.setVisibility(View.GONE); |
| | | } |
| | | |
| | | @Override |
| | | protected void dataFinish() { |
| | | super.dataFinish(); |
| | | binding.refreshLayout.finishLoadMore(); |
| | | } |
| | | |
| | | @Override |
| | | protected void hide() { |
| | | super.hide(); |
| | | binding.layoutDataNull.setVisibility(View.GONE); |
| | | binding.refreshLayout.setVisibility(View.VISIBLE); |
| | | binding.refreshLayout.finishLoadMore(); |
| | | } |
| | | |
| | | @Override |