From fcdddf8b9b34f9930bec454b5fffe41c0e33ba3c Mon Sep 17 00:00:00 2001 From: Linjiajia <319408893@qq.com> Date: 星期一, 24 四月 2023 21:17:05 +0800 Subject: [PATCH] 功能模块大部分 --- app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivity.java | 253 +++++++++++++++++++++++++++----------------------- 1 files changed, 137 insertions(+), 116 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 56f247e..ef77b64 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,6 +1,5 @@ package com.application.zhangshi_app_android.ui.function; -import android.content.DialogInterface; import android.content.Intent; import android.graphics.drawable.ColorDrawable; import android.view.KeyEvent; @@ -8,20 +7,15 @@ 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.databinding.DataBindingUtil; import androidx.lifecycle.Observer; import com.android.app_base.base.BaseConfig; 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.manager.AppManager; import com.android.app_base.utils.ScreenSizeUtils; import com.android.app_base.widget.LinearItemDecoration; @@ -30,6 +24,8 @@ 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 com.application.zhangshi_app_android.databinding.PopSearchBinding; +import com.application.zhangshi_app_android.ui.DLBaseActivity; import java.util.List; @@ -38,13 +34,12 @@ * @date 2023.03.18. 10:00 * @desc 瀹跺ぇ浜嬭 Activity */ -public class FamilyMemorabiliaActivity extends BaseActivity<ActivityFamilyMemorabiliaBinding,FamilyMemorabiliaActivityViewModel> { +public class FamilyMemorabiliaActivity extends DLBaseActivity<ActivityFamilyMemorabiliaBinding,FamilyMemorabiliaActivityViewModel> { FamilyMemorabiliaRvAdapter adapter; private PopupWindow mOperatePopupWindow; private PopupWindow mSearchPopupWindow; - private int operateType = 0; - private int searchType = 0; + private PopSearchBinding mSearchPopBinding; @Override public int getLayoutId() { @@ -63,6 +58,13 @@ @Override public void initView() { + binding.refreshLayout.setEnableRefresh(false); + binding.refreshLayout.setEnableLoadMore(true); + binding.refreshLayout.setEnableOverScrollDrag(true); + binding.refreshLayout.setOnLoadMoreListener(refreshLayout -> { + viewModel.getMoreFamilyMemorabilia(); + }); + adapter = new FamilyMemorabiliaRvAdapter(this,viewModel); LinearItemDecoration itemDecoration = new LinearItemDecoration(); itemDecoration.setBottomSpace((int) getResources().getDimension(com.android.app_base.R.dimen.dp_12)); @@ -71,55 +73,45 @@ binding.recyclerView.addItemDecoration(itemDecoration); binding.recyclerView.setAdapter(adapter); + mSearchPopBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.pop_search, null, false); + mSearchPopBinding.setViewModel(viewModel); + mSearchPopupWindow = initPopUpWindow(mSearchPopBinding.getRoot()); - mOperatePopupWindow = initPopUpWindow(R.layout.pop_operate); - mOperatePopupWindow.getContentView().findViewById(R.id.tv_add).setOnClickListener(v -> { - AppManager.getAppManager().startActivity(new Intent(this,CreateFamilyProjectActivity.class).putExtra(BaseConfig.EXTRA_TYPE,1)); - }); - 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(); - } - }); + mOperatePopupWindow = initPopUpWindow(View.inflate(this,R.layout.pop_operate,null)); - 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.ivSearchType.setOnClickListener(v -> { + hideSoftKeyboard(); + mSearchPopupWindow.setWidth(binding.layoutSearch.getMeasuredWidth()); + mSearchPopupWindow.showAsDropDown(binding.layoutSearch,0,0); + }); + + 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(); + binding.layoutSearch.setVisibility(View.GONE); + binding.layoutDefault.setVisibility(View.VISIBLE); + binding.tvTitle.setText("鎼滅储缁撴灉"); + hideSoftKeyboard(); + return true; + } + return false; + } + }); + binding.ivSearch.setOnClickListener(v -> { + viewModel.getFamilyMemorabilia(); + binding.layoutSearch.setVisibility(View.GONE); + binding.layoutDefault.setVisibility(View.VISIBLE); + binding.tvTitle.setText("鎼滅储缁撴灉"); + mSearchPopupWindow.dismiss(); + hideSoftKeyboard(); }); binding.fabAdd.setOnClickListener(new View.OnClickListener() { @Override @@ -129,39 +121,21 @@ }); 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)); + mSearchPopupWindow.getContentView().findViewById(R.id.iv_clear_person), + mSearchPopupWindow.getContentView().findViewById(R.id.iv_clear_place), + mSearchPopupWindow.getContentView().findViewById(R.id.iv_clear_time), + mSearchPopupWindow.getContentView().findViewById(R.id.iv_clear_title), + mOperatePopupWindow.getContentView().findViewById(R.id.tv_add), + mOperatePopupWindow.getContentView().findViewById(R.id.tv_select), + mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_new_to_old), + mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_old_to_new) + ); - - 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.ivMenu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - binding.drawerLayout.open(); - } - }); - binding.drawerLayout.setScrimColor(getResources().getColor(R.color.color_shadow)); } @Override public void initData() { - viewModel.getFamilyMemorabilia(searchType); + viewModel.getFamilyMemorabilia(); } @Override @@ -169,15 +143,13 @@ viewModel.getCheckListLiveData().observe(this, new Observer<List<FamilyMemorabiliaBean>>() { @Override public void onChanged(List<FamilyMemorabiliaBean> familyMemorabiliaBeans) { - if (operateType == 0){ + if (viewModel.getOperateTypeLiveData().getValue() == 0){ return; } if (familyMemorabiliaBeans.isEmpty()){ - binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish); - operateType = 1; + viewModel.getOperateTypeLiveData().setValue(1); }else{ - binding.ivOperate.setBackgroundResource(R.drawable.ic_delete_white); - operateType = 2; + viewModel.getOperateTypeLiveData().setValue(2); } } }); @@ -187,26 +159,63 @@ adapter.setData(familyMemorabiliaBeans); } }); + viewModel.getMoreListLiveData().observe(this, new Observer<List<FamilyMemorabiliaBean>>() { + @Override + public void onChanged(List<FamilyMemorabiliaBean> familyMemorabiliaBeans) { + adapter.addData(familyMemorabiliaBeans); + } + }); + viewModel.getOperateTypeLiveData().observe(this, integer -> { + if (integer == 0){ + binding.ivOperate.setBackgroundResource(R.drawable.ic_operate); + binding.ivOperate.setOnClickListener(v -> { + mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0); + }); + adapter.setCheckable(false); + }else if (integer == 1){ + binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish); + binding.ivOperate.setOnClickListener(v -> { + viewModel.getOperateTypeLiveData().postValue(0); + }); + adapter.setCheckable(true); + }else if (integer == 2){ + binding.ivOperate.setBackgroundResource(R.drawable.ic_delete_white); + binding.ivOperate.setOnClickListener(v -> { + new UIDialog.Builder(this) + .setTitle("鎮ㄧ‘瀹氳鍒犻櫎椤圭洰鍚�") + .setContent("椤圭洰鍒犻櫎鍚庡皢鏃犳硶鎭㈠") + .setConfirm("纭畾") + .setCancel("鍙栨秷") + .setListener(new UIDialog.OnListener() { + @Override + public void onConfirm(BaseDialog dialog) { + viewModel.delete(); + } + }) + .show(); + }); + } + }); } - private PopupWindow initPopUpWindow(@LayoutRes int layoutId){ + private PopupWindow initPopUpWindow(View view){ PopupWindow popupWindow = new PopupWindow(this); // 璁剧疆甯冨眬鏂囦欢 - popupWindow.setContentView(LayoutInflater.from(this).inflate(layoutId, null)); + popupWindow.setContentView(view); // 涓轰簡閬垮厤閮ㄥ垎鏈哄瀷涓嶆樉绀猴紝闇�瑕侀噸鏂拌缃竴涓嬪楂� 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.setAnimationStyle(com.android.app_base.R.style.pop_operate); +// // 璁剧疆pop鑾峰彇鐒︾偣锛屽鏋滀负false鐐瑰嚮杩斿洖鎸夐挳浼氶��鍑哄綋鍓岮ctivity锛屽鏋減op涓湁Editor鐨勮瘽锛宖ocusable蹇呴』瑕佷负true popupWindow.setFocusable(true); - // 璁剧疆pop鍙偣鍑伙紝涓篺alse鐐瑰嚮浜嬩欢鏃犳晥锛岄粯璁や负true +// // 璁剧疆pop鍙偣鍑伙紝涓篺alse鐐瑰嚮浜嬩欢鏃犳晥锛岄粯璁や负true popupWindow.setTouchable(true); // 璁剧疆鐐瑰嚮pop澶栦晶娑堝け锛岄粯璁や负false锛涘湪focusable涓簍rue鏃剁偣鍑诲渚у缁堟秷澶� - popupWindow.setOutsideTouchable(true); + popupWindow.setOutsideTouchable(false); return popupWindow; } @@ -218,32 +227,44 @@ } @Override + protected void dataFinish() { + super.dataFinish(); + binding.refreshLayout.finishLoadMore(); + } + + @Override + protected void hide() { + super.hide(); + binding.layoutDataNull.setVisibility(View.GONE); + binding.recyclerView.setVisibility(View.VISIBLE); + binding.refreshLayout.finishLoadMore(); + } + + @Override public void onClick(View v) { int id = v.getId(); - if (id == R.id.tv_global_search){ - searchType = 0; - binding.etSearch.setHint("鍏ㄥ眬鎼滅储"); + if (id == R.id.tv_add){ + AppManager.getAppManager().startActivity(new Intent(this,CreateFamilyProjectActivity.class).putExtra(BaseConfig.EXTRA_TYPE,1)); + }else if (id == R.id.tv_select){ + viewModel.getOperateTypeLiveData().postValue(1); + mOperatePopupWindow.dismiss(); + } else if (id == R.id.tv_from_new_to_old) { + viewModel.changeOrder(true); + mOperatePopupWindow.dismiss(); + } else if (id == R.id.tv_from_old_to_new) { + viewModel.changeOrder(false); + mOperatePopupWindow.dismiss(); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (mSearchPopupWindow != null){ 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("鎸夆�滃湴鐐光�濇悳绱�"); + } + if (mOperatePopupWindow != null){ + mOperatePopupWindow.dismiss(); } } } \ No newline at end of file -- Gitblit v1.9.1