From a1d1fb7c44e33c4baeb52964a027932018bc1325 Mon Sep 17 00:00:00 2001 From: Linjiajia <319408893@qq.com> Date: 星期二, 04 四月 2023 16:35:39 +0800 Subject: [PATCH] 家大事记添加接口、家庭资产、家庭设备 --- app/src/main/java/com/application/zhangshi_app_android/ui/function/FamilyMemorabiliaActivity.java | 247 ++++++++++++++++++++++++------------------------- 1 files changed, 122 insertions(+), 125 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..e920c93 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 @@ -15,6 +15,8 @@ import androidx.annotation.IdRes; import androidx.annotation.LayoutRes; import androidx.appcompat.app.AlertDialog; +import androidx.databinding.DataBindingUtil; +import androidx.databinding.ViewDataBinding; import androidx.drawerlayout.widget.DrawerLayout; import androidx.lifecycle.Observer; @@ -30,6 +32,9 @@ 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 com.hjq.bar.TitleBar; import java.util.List; @@ -38,13 +43,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() { @@ -71,33 +75,106 @@ 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 = initPopUpWindow(View.inflate(this,R.layout.pop_operate,null)); + + binding.ivSearchDefault.setOnClickListener(v -> { + binding.layoutSearch.setVisibility(View.VISIBLE); + binding.layoutDefault.setVisibility(View.GONE); }); - mOperatePopupWindow.getContentView().findViewById(R.id.tv_select).setOnClickListener(v -> { - binding.ivOperate.setBackgroundResource(R.drawable.ic_operate_finish); - operateType = 1; - adapter.setCheckable(true); - mOperatePopupWindow.dismiss(); + + binding.ivSearchType.setOnClickListener(v -> { + mSearchPopupWindow.setWidth(binding.layoutSearch.getMeasuredWidth()); + mSearchPopupWindow.showAsDropDown(binding.layoutSearch,0,0); }); - mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_new_to_old).setOnClickListener(v -> { - viewModel.changeOrder(true); - mOperatePopupWindow.dismiss(); + + 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; + } }); - mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_old_to_new).setOnClickListener(v -> { - viewModel.changeOrder(false); - mOperatePopupWindow.dismiss(); + binding.ivSearch.setOnClickListener(v -> { + viewModel.getFamilyMemorabilia(); + binding.layoutSearch.setVisibility(View.GONE); + binding.layoutDefault.setVisibility(View.VISIBLE); + binding.tvTitle.setText("鎼滅储缁撴灉"); + mSearchPopupWindow.dismiss(); + hideSoftKeyboard(); }); - binding.ivOperate.setOnClickListener(v -> { - if (operateType == 0){ - mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0); - } else if (operateType == 1) { + binding.fabAdd.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + AppManager.getAppManager().startActivity(new Intent(getSelfActivity(),CreateFamilyProjectActivity.class).putExtra(BaseConfig.EXTRA_TYPE,1)); + } + }); + + setOnClickListener( + 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) + ); + + } + + @Override + public void initData() { + viewModel.getFamilyMemorabilia(); + } + + @Override + public void initLiveDataObserve() { + viewModel.getCheckListLiveData().observe(this, new Observer<List<FamilyMemorabiliaBean>>() { + @Override + public void onChanged(List<FamilyMemorabiliaBean> familyMemorabiliaBeans) { + if (viewModel.getOperateTypeLiveData().getValue() == 0){ + return; + } + if (familyMemorabiliaBeans.isEmpty()){ + viewModel.getOperateTypeLiveData().postValue(1); + }else{ + viewModel.getOperateTypeLiveData().postValue(2); + } + } + }); + viewModel.getDataListLiveData().observe(this, new Observer<List<FamilyMemorabiliaBean>>() { + @Override + public void onChanged(List<FamilyMemorabiliaBean> familyMemorabiliaBeans) { + adapter.setData(familyMemorabiliaBeans); + } + }); + viewModel.getOperateTypeLiveData().observe(this, integer -> { + if (integer == 0){ binding.ivOperate.setBackgroundResource(R.drawable.ic_operate); - operateType = 0; + binding.ivOperate.setOnClickListener(v -> { + mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0); + }); adapter.setCheckable(false); - } else { + }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); new UIDialog.Builder(this) .setTitle("鎮ㄧ‘瀹氳鍒犻櫎椤圭洰鍚�") .setContent("椤圭洰鍒犻櫎鍚庡皢鏃犳硶鎭㈠") @@ -110,90 +187,16 @@ } }) .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) { - AppManager.getAppManager().startActivity(new Intent(getSelfActivity(),CreateFamilyProjectActivity.class).putExtra(BaseConfig.EXTRA_TYPE,1)); - } - }); - - 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.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); - } - - @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); + adapter.setCheckable(true); } }); } - 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); @@ -206,7 +209,7 @@ // 璁剧疆pop鍙偣鍑伙紝涓篺alse鐐瑰嚮浜嬩欢鏃犳晥锛岄粯璁や负true popupWindow.setTouchable(true); // 璁剧疆鐐瑰嚮pop澶栦晶娑堝け锛岄粯璁や负false锛涘湪focusable涓簍rue鏃剁偣鍑诲渚у缁堟秷澶� - popupWindow.setOutsideTouchable(true); + popupWindow.setOutsideTouchable(false); return popupWindow; } @@ -218,32 +221,26 @@ } @Override + protected void hide() { + super.hide(); + binding.layoutDataNull.setVisibility(View.GONE); + binding.recyclerView.setVisibility(View.VISIBLE); + } + + @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("鎸夆�滃湴鐐光�濇悳绱�"); + 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(); } } } \ No newline at end of file -- Gitblit v1.9.1