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.HundredWishRvAdapter;
|
import com.application.zhangshi_app_android.databinding.ActivityHundredWishBinding;
|
import com.application.zhangshi_app_android.ui.DLBaseActivity;
|
import com.github.gzuliyujiang.wheelpicker.DatePicker;
|
import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener;
|
|
/**
|
* @author Ljj
|
* @date 2023.04.23. 14:15
|
* @desc 百年心愿
|
*/
|
public class HundredWishActivity extends DLBaseActivity<ActivityHundredWishBinding, HundredWishActivityViewModel> {
|
|
private HundredWishRvAdapter adapter;
|
private PopupWindow mOperatePopupWindow;
|
private boolean isSearchLayoutVisible;
|
@Override
|
public int getLayoutId() {
|
return R.layout.activity_hundred_wish;
|
}
|
|
@Override
|
public int getVariableId() {
|
return BR.viewModel;
|
}
|
|
@Override
|
public void initParam() {
|
|
}
|
|
@Override
|
public void initView() {
|
//下拉刷新布局
|
binding.refreshLayout.setEnableRefresh(false);
|
binding.refreshLayout.setEnableLoadMore(true);
|
binding.refreshLayout.setEnableOverScrollDrag(true);
|
binding.refreshLayout.setOnLoadMoreListener(refreshLayout -> {
|
viewModel.getMoreProperty();
|
});
|
//recyclerView适配器
|
adapter = new HundredWishRvAdapter(this);
|
LinearItemDecoration itemDecoration = new LinearItemDecoration();
|
itemDecoration.setBottomSpace((int) getResources().getDimension(com.android.app_base.R.dimen.dp_12));
|
itemDecoration.setHorizontalSpace((int) getResources().getDimension(com.android.app_base.R.dimen.dp_20));
|
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.getProperty();
|
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("");
|
});
|
}
|
@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
|
public void initData() {
|
viewModel.getProperty();
|
}
|
|
@Override
|
public void initLiveDataObserve() {
|
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();
|
}
|
}
|