| | |
| | | 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; |
| | | |
| | |
| | | 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; |
| | | |
| | |
| | | * @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() { |
| | |
| | | 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.ivOperate.setBackgroundResource(R.drawable.ic_operate); |
| | | operateType = 0; |
| | | adapter.setCheckable(false); |
| | | 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); |
| | | 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); |
| | | new UIDialog.Builder(this) |
| | | .setTitle("您确定要删除项目吗") |
| | | .setContent("项目删除后将无法恢复") |
| | |
| | | } |
| | | }) |
| | | .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); |
| | |
| | | // 设置pop可点击,为false点击事件无效,默认为true |
| | | popupWindow.setTouchable(true); |
| | | // 设置点击pop外侧消失,默认为false;在focusable为true时点击外侧始终消失 |
| | | popupWindow.setOutsideTouchable(true); |
| | | popupWindow.setOutsideTouchable(false); |
| | | return popupWindow; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @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(); |
| | | } |
| | | } |
| | | } |