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;
|
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.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;
|
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
|
* @desc 家大事记 Activity
|
*/
|
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() {
|
return R.layout.activity_family_memorabilia;
|
}
|
|
@Override
|
public int getVariableId() {
|
return BR.viewModel;
|
}
|
|
@Override
|
public void initParam() {
|
|
}
|
|
@Override
|
public void initView() {
|
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 -> {
|
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();
|
}
|
});
|
|
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);
|
}
|
});
|
}
|
|
|
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点击返回按钮会退出当前Activity,如果pop中有Editor的话,focusable必须要为true
|
popupWindow.setFocusable(true);
|
// 设置pop可点击,为false点击事件无效,默认为true
|
popupWindow.setTouchable(true);
|
// 设置点击pop外侧消失,默认为false;在focusable为true时点击外侧始终消失
|
popupWindow.setOutsideTouchable(true);
|
return popupWindow;
|
}
|
|
@Override
|
protected void dataNull() {
|
super.dataNull();
|
binding.layoutDataNull.setVisibility(View.VISIBLE);
|
binding.recyclerView.setVisibility(View.GONE);
|
}
|
|
@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("按“地点”搜索");
|
}
|
}
|
}
|