| | |
| | | package com.application.zhangshi_app_android.ui.function; |
| | | |
| | | import com.android.app_base.base.view.BaseActivity; |
| | | import android.content.Intent; |
| | | 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.PopupWindow; |
| | | import android.widget.TextView; |
| | | |
| | | 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.manager.AppManager; |
| | | 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 com.application.zhangshi_app_android.databinding.PopSearchBinding; |
| | | import com.application.zhangshi_app_android.ui.DLBaseActivity; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author Ljj |
| | | * @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 PopSearchBinding mSearchPopBinding; |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | |
| | | |
| | | @Override |
| | | public void initView() { |
| | | adapter = new FamilyMemorabiliaRvAdapter(this); |
| | | 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)); |
| | | 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); |
| | | |
| | | mSearchPopBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.pop_search, null, false); |
| | | mSearchPopBinding.setViewModel(viewModel); |
| | | mSearchPopupWindow = initPopUpWindow(mSearchPopBinding.getRoot()); |
| | | |
| | | mOperatePopupWindow = initPopUpWindow(View.inflate(this,R.layout.pop_operate,null)); |
| | | |
| | | 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 |
| | | 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() { |
| | | adapter.addItem(new FamilyMemorabiliaBean()); |
| | | adapter.addItem(new FamilyMemorabiliaBean()); |
| | | adapter.addItem(new FamilyMemorabiliaBean()); |
| | | adapter.addItem(new FamilyMemorabiliaBean()); |
| | | adapter.addItem(new FamilyMemorabiliaBean()); |
| | | 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().setValue(1); |
| | | }else{ |
| | | viewModel.getOperateTypeLiveData().setValue(2); |
| | | } |
| | | } |
| | | }); |
| | | viewModel.getDataListLiveData().observe(this, new Observer<List<FamilyMemorabiliaBean>>() { |
| | | @Override |
| | | public void onChanged(List<FamilyMemorabiliaBean> familyMemorabiliaBeans) { |
| | | 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(View view){ |
| | | PopupWindow popupWindow = new PopupWindow(this); |
| | | // 设置布局文件 |
| | | 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_operate); |
| | | // // 设置pop获取焦点,如果为false点击返回按钮会退出当前Activity,如果pop中有Editor的话,focusable必须要为true |
| | | popupWindow.setFocusable(true); |
| | | // // 设置pop可点击,为false点击事件无效,默认为true |
| | | popupWindow.setTouchable(true); |
| | | // 设置点击pop外侧消失,默认为false;在focusable为true时点击外侧始终消失 |
| | | popupWindow.setOutsideTouchable(false); |
| | | return popupWindow; |
| | | } |
| | | |
| | | @Override |
| | | protected void dataNull() { |
| | | super.dataNull(); |
| | | binding.layoutDataNull.setVisibility(View.VISIBLE); |
| | | binding.recyclerView.setVisibility(View.GONE); |
| | | } |
| | | |
| | | @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_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(); |
| | | } |
| | | if (mOperatePopupWindow != null){ |
| | | mOperatePopupWindow.dismiss(); |
| | | } |
| | | } |
| | | } |