From 82e57df230ecb744af6c8865f80870ba03c86d89 Mon Sep 17 00:00:00 2001
From: Linjiajia <319408893@qq.com>
Date: 星期二, 25 七月 2023 22:18:27 +0800
Subject: [PATCH] 基本功能完成

---
 app/src/main/java/com/application/zhangshi_app_android/ui/function/PropertyActivity.java |  198 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 197 insertions(+), 1 deletions(-)

diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/PropertyActivity.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/PropertyActivity.java
index 799d3af..953df4c 100644
--- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/PropertyActivity.java
+++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/PropertyActivity.java
@@ -1,11 +1,22 @@
 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.PropertyRvAdapter;
 import com.application.zhangshi_app_android.databinding.ActivityPropertyBinding;
 import com.application.zhangshi_app_android.ui.DLBaseActivity;
+import com.github.gzuliyujiang.wheelpicker.DatePicker;
+import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener;
 
 /**
  * @author Ljj
@@ -15,7 +26,8 @@
 public class PropertyActivity extends DLBaseActivity<ActivityPropertyBinding, PropertyActivityViewModel> {
 
     private PropertyRvAdapter adapter;
-
+    private PopupWindow mOperatePopupWindow;
+    private boolean isSearchLayoutVisible;
     @Override
     public int getLayoutId() {
         return R.layout.activity_property;
@@ -33,6 +45,14 @@
 
     @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 PropertyRvAdapter(this);
         LinearItemDecoration itemDecoration = new LinearItemDecoration();
         itemDecoration.setBottomSpace((int) getResources().getDimension(com.android.app_base.R.dimen.dp_12));
@@ -40,7 +60,160 @@
         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娣诲姞绌虹偣鍑讳簨浠讹紝闃叉鐐瑰嚮瀹冨唴閮╲iew鏃跺畠鍚庨潰鐨剅ecycler杩樿兘鍝嶅簲鐐瑰嚮浜嬩欢
+        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) {
+                    //浠yyy-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() {
@@ -52,5 +225,28 @@
         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();
     }
 }

--
Gitblit v1.9.1