Linjiajia
2023-04-24 fcdddf8b9b34f9930bec454b5fffe41c0e33ba3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.application.zhangshi_app_android.ui.function;
 
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
 
import androidx.databinding.library.baseAdapters.BR;
 
import com.android.app_base.utils.ScreenSizeUtils;
import com.android.app_base.widget.LinearItemDecoration;
import com.application.zhangshi_app_android.R;
import com.application.zhangshi_app_android.adapter.FamilyAssetsRvAdapter;
import com.application.zhangshi_app_android.databinding.ActivityFamilyAssetsBinding;
import com.application.zhangshi_app_android.ui.DLBaseActivity;
 
/**
 * @author Ljj
 * @date 2023.04.03. 19:40
 * @desc
 */
public class FamilyAssetsActivity extends DLBaseActivity<ActivityFamilyAssetsBinding,FamilyAssetsActivityViewModel> {
 
 
    private FamilyAssetsRvAdapter adapter;
    private PopupWindow mOperatePopupWindow;
 
 
    @Override
    public int getLayoutId() {
        return R.layout.activity_family_assets;
    }
 
    @Override
    public int getVariableId() {
        return BR.viewModel;
    }
 
    @Override
    public void initParam() {
 
    }
 
    @Override
    public void initView() {
        binding.refreshLayout.setEnableRefresh(false);
        binding.refreshLayout.setEnableLoadMore(true);
        binding.refreshLayout.setEnableOverScrollDrag(true);
        binding.refreshLayout.setOnLoadMoreListener(refreshLayout -> {
//            viewModel.getMoreFamilyMemorabilia();
        });
 
        adapter = new FamilyAssetsRvAdapter(this);
        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(View.inflate(this,R.layout.pop_operate,null));
        mOperatePopupWindow.getContentView().findViewById(R.id.layout_add).setVisibility(View.GONE);
        mOperatePopupWindow.getContentView().findViewById(R.id.layout_select).setVisibility(View.GONE);
        mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_new_to_old).setOnClickListener(v -> {
            viewModel.sortDataList(0);
            mOperatePopupWindow.dismiss();
        });
        mOperatePopupWindow.getContentView().findViewById(R.id.tv_from_old_to_new).setOnClickListener(v -> {
            viewModel.sortDataList(1);
            mOperatePopupWindow.dismiss();
        });
        binding.ivOperate.setOnClickListener(v -> {
            mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(this,85) +binding.ivOperate.getWidth(),0);
        });
    }
 
    @Override
    public void initData() {
        viewModel.getFamilyAssets();
    }
 
    @Override
    public void initLiveDataObserve() {
        viewModel.getDataListLiveData().observe(this, familyAssetsBeans -> {
            adapter.setData(familyAssetsBeans);
        });
    }
    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;
    }
}