From bf4e40cdf60c2a2fd8a486051a1ddac2daefef62 Mon Sep 17 00:00:00 2001
From: Linjiajia <319408893@qq.com>
Date: 星期二, 28 三月 2023 19:00:24 +0800
Subject: [PATCH] 家大事记完善

---
 app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivity.java |  192 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 186 insertions(+), 6 deletions(-)

diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivity.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivity.java
index f073c3f..bfff5ec 100644
--- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivity.java
+++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivity.java
@@ -1,12 +1,35 @@
 package com.application.zhangshi_app_android.ui.function;
 
+import android.content.DialogInterface;
+import android.graphics.drawable.ColorDrawable;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.inputmethod.EditorInfo;
+import android.widget.Button;
+import android.widget.PopupWindow;
+import android.widget.TextView;
+
+import androidx.annotation.IdRes;
+import androidx.annotation.LayoutRes;
+import androidx.appcompat.app.AlertDialog;
+import androidx.drawerlayout.widget.DrawerLayout;
+import androidx.lifecycle.Observer;
+
+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.utils.ScreenSizeUtils;
 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.FamilyMemorabiliaRvAdapter;
 import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean;
 import com.application.zhangshi_app_android.databinding.ActivityFamilyMemorabiliaBinding;
+
+import java.util.List;
+
 /**
  * @author Ljj
  * @date 2023.03.18. 10:00
@@ -15,6 +38,10 @@
 public class FamilyMemorabiliaActivity extends BaseActivity<ActivityFamilyMemorabiliaBinding,FamilyMemorabiliaActivityViewModel> {
 
     FamilyMemorabiliaRvAdapter adapter;
+    private PopupWindow mOperatePopupWindow;
+    private PopupWindow mSearchPopupWindow;
+    private int operateType = 0;
+    private int searchType = 0;
 
     @Override
     public int getLayoutId() {
@@ -33,26 +60,179 @@
 
     @Override
     public void initView() {
-        adapter = new FamilyMemorabiliaRvAdapter(this);
+        adapter = new FamilyMemorabiliaRvAdapter(this,viewModel);
         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(R.layout.pop_operate);
+        mOperatePopupWindow.getContentView().findViewById(R.id.tv_add).setOnClickListener(v -> {
+            //TODO 璺宠浆 鏂板缓
+        });
+        mOperatePopupWindow.getContentView().findViewById(R.id.tv_select).setOnClickListener(v -> {
+            binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish);
+            operateType = 1;
+            adapter.setCheckable(true);
+            mOperatePopupWindow.dismiss();
+        });
+        mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_new_to_old).setOnClickListener(v -> {
+            viewModel.changeOrder(true);
+            mOperatePopupWindow.dismiss();
+        });
+        mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_old_to_new).setOnClickListener(v -> {
+            viewModel.changeOrder(false);
+            mOperatePopupWindow.dismiss();
+        });
+        binding.ivOperate.setOnClickListener(v -> {
+            if (operateType == 0){
+                mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0);
+            } else if (operateType == 1) {
+                binding.ivOperate.setBackgroundResource(R.drawable.ic_operate);
+                operateType = 0;
+                adapter.setCheckable(false);
+            } else {
+                new UIDialog.Builder(this)
+                        .setTitle("鎮ㄧ‘瀹氳鍒犻櫎椤圭洰鍚�")
+                        .setContent("椤圭洰鍒犻櫎鍚庡皢鏃犳硶鎭㈠")
+                        .setConfirm("纭畾")
+                        .setCancel("鍙栨秷")
+                        .setListener(new UIDialog.OnListener() {
+                            @Override
+                            public void onConfirm(BaseDialog dialog) {
+                                viewModel.delete();
+                            }
+                        })
+                        .show();
+            }
+        });
+
+        mSearchPopupWindow = initPopUpWindow(R.layout.pop_search);
+        binding.ivSearchType.setOnClickListener(v -> {
+            mSearchPopupWindow.showAsDropDown(binding.etSearch,0,0);
+        });
+        binding.ivSearchDefault.setOnClickListener(v -> {
+            binding.layoutSearch.setVisibility(View.VISIBLE);
+            binding.layoutDefault.setVisibility(View.GONE);
+        });
+        binding.fabAdd.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+
+            }
+        });
+        setOnClickListener(
+                mSearchPopupWindow.getContentView().findViewById(R.id.tv_global_search),
+                mSearchPopupWindow.getContentView().findViewById(R.id.tv_search_in_family_memorabilia),
+                mSearchPopupWindow.getContentView().findViewById(R.id.tv_search_by_title),
+                mSearchPopupWindow.getContentView().findViewById(R.id.tv_search_by_people),
+                mSearchPopupWindow.getContentView().findViewById(R.id.tv_search_by_time),
+                mSearchPopupWindow.getContentView().findViewById(R.id.tv_search_by_place));
+
+
+        binding.etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
+            @Override
+            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+                if ((actionId == EditorInfo.IME_ACTION_UNSPECIFIED || actionId == EditorInfo.IME_ACTION_SEARCH)
+                        && event != null) {
+                    viewModel.getFamilyMemorabilia(searchType);
+                    hideSoftKeyboard();
+                    return true;
+                }
+                return false;
+            }
+        });
+
+        binding.drawerLayout.setScrimColor(getResources().getColor(R.color.color_shadow));
     }
 
     @Override
     public void initData() {
-        adapter.addItem(new FamilyMemorabiliaBean());
-        adapter.addItem(new FamilyMemorabiliaBean());
-        adapter.addItem(new FamilyMemorabiliaBean());
-        adapter.addItem(new FamilyMemorabiliaBean());
-        adapter.addItem(new FamilyMemorabiliaBean());
+        viewModel.getFamilyMemorabilia(0);
     }
 
     @Override
     public void initLiveDataObserve() {
+        viewModel.getCheckListLiveData().observe(this, new Observer<List<FamilyMemorabiliaBean>>() {
+            @Override
+            public void onChanged(List<FamilyMemorabiliaBean> familyMemorabiliaBeans) {
+                if (operateType == 0){
+                    return;
+                }
+                if (familyMemorabiliaBeans.isEmpty()){
+                    binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish);
+                    operateType = 1;
+                }else{
+                    binding.ivOperate.setBackgroundResource(R.drawable.ic_delete_white);
+                    operateType = 2;
+                }
+            }
+        });
+        viewModel.getDataListLiveData().observe(this, new Observer<List<FamilyMemorabiliaBean>>() {
+            @Override
+            public void onChanged(List<FamilyMemorabiliaBean> familyMemorabiliaBeans) {
+                adapter.setData(familyMemorabiliaBeans);
+            }
+        });
+    }
 
+
+    private PopupWindow initPopUpWindow(@LayoutRes int layoutId){
+        PopupWindow popupWindow = new PopupWindow(this);
+        // 璁剧疆甯冨眬鏂囦欢
+        popupWindow.setContentView(LayoutInflater.from(this).inflate(layoutId, 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_add);
+        // 璁剧疆pop鑾峰彇鐒︾偣锛屽鏋滀负false鐐瑰嚮杩斿洖鎸夐挳浼氶��鍑哄綋鍓岮ctivity锛屽鏋減op涓湁Editor鐨勮瘽锛宖ocusable蹇呴』瑕佷负true
+        popupWindow.setFocusable(true);
+        // 璁剧疆pop鍙偣鍑伙紝涓篺alse鐐瑰嚮浜嬩欢鏃犳晥锛岄粯璁や负true
+        popupWindow.setTouchable(true);
+        // 璁剧疆鐐瑰嚮pop澶栦晶娑堝け锛岄粯璁や负false锛涘湪focusable涓簍rue鏃剁偣鍑诲渚у缁堟秷澶�
+        popupWindow.setOutsideTouchable(true);
+        return popupWindow;
+    }
+
+    @Override
+    protected void dataNull() {
+        super.dataNull();
+
+    }
+
+    @Override
+    public void onClick(View v) {
+        int id = v.getId();
+        if (id == R.id.tv_global_search){
+            searchType = 0;
+            binding.etSearch.setHint("鍏ㄥ眬鎼滅储");
+            mSearchPopupWindow.dismiss();
+        }else if (id == R.id.tv_search_in_family_memorabilia) {
+            searchType = 1;
+            mSearchPopupWindow.dismiss();
+            binding.etSearch.setHint("鍦ㄢ�滃澶т簨璁扳�濆唴鎼滅储");
+        }else if (id == R.id.tv_search_by_title) {
+            searchType = 2;
+            mSearchPopupWindow.dismiss();
+            binding.etSearch.setHint("鎸夆�滃ぇ浜嬭鏍囬鈥濇悳绱�");
+        }else if (id == R.id.tv_search_by_people) {
+            searchType = 3;
+            mSearchPopupWindow.dismiss();
+            binding.etSearch.setHint("鎸夆�滀汉鐗┾�濇悳绱�");
+        }else if (id == R.id.tv_search_by_time) {
+            searchType = 4;
+            mSearchPopupWindow.dismiss();
+            binding.etSearch.setHint("鎸夆�滄椂闂粹�濇悳绱�");
+        }else if (id == R.id.tv_search_by_place) {
+            searchType = 5;
+            mSearchPopupWindow.dismiss();
+            binding.etSearch.setHint("鎸夆�滃湴鐐光�濇悳绱�");
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1