CommentHelper.java
4.22 KB
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
package com.people.comment.utils;
import android.app.Activity;
import android.view.View;
import androidx.appcompat.widget.AppCompatTextView;
import com.people.comment.R;
import com.people.comment.bean.CommentClickShowType;
import com.people.comment.listener.CommentClickListener;
import com.people.comment.view.easy_pop.EasyPopup;
import com.people.comment.view.easy_pop.XGravity;
import com.people.comment.view.easy_pop.YGravity;
import com.wd.foundation.wdkit.utils.PDUtils;
import com.wd.common.utils.ProcessUtils;
import com.wd.foundation.wdkitcore.tools.AppContext;
import java.util.Arrays;
/**
* @Author LiuKun
* @date:2023/5/15
* @desc:弹出回复、分享、复制、删除、举报选择
*/
public class CommentHelper {
private String[] cellStr = new String[]{"回复", "分享", "复制", "删除", "举报"};
private AppCompatTextView[] textViews = new AppCompatTextView[4];
private View[] lineViews = new View[3];
private final int[] textIds = new int[]{R.id.comment_popup_cell_1, R.id.comment_popup_cell_2, R.id.comment_popup_cell_3, R.id.comment_popup_cell_4};
private final int[] lineIds = new int[]{R.id.comment_popup_cell_line_1, R.id.comment_popup_cell_line_2, R.id.comment_popup_cell_line_3};
private EasyPopup mCommentPop;
private static class SingletonHolder {
private final static CommentHelper instance = new CommentHelper();
}
public static CommentHelper getInstance() {
return SingletonHolder.instance;
}
private CommentHelper() {
}
/**
* 显示效果
*/
public void showClickDialog(Activity activity, View anchor, final CommentClickListener listener, @CommentClickShowType final int... showTypes) {
// 排序
Arrays.sort(showTypes);
// 在华为P30 Pro 上会跳一下(先在屏幕右边后面又居中),设置一下宽度,后面可以替换为BubbleManager用法
int size = showTypes.length;
final float cellWidth = AppContext.getContext().getResources().getDimension(R.dimen.rmrb_dp45);
final float lintWidth = AppContext.getContext().getResources().getDimension(R.dimen.rmrb_dp30);
int width = (int) (cellWidth * size + lintWidth * (size - 1));
mCommentPop = EasyPopup.create()
.setContentView(activity, R.layout.layout_popup_comment_click_show)
.setAnimationStyle(R.style.RightPopAnim)
.setWidth(width)
.setOnViewListener((view, basePopup) -> {
int length = showTypes.length;
for (int i = 0; i < length; i++) {
final int showType = showTypes[i];
textViews[i] = view.findViewById(textIds[i]);
textViews[i].setText(cellStr[showType]);
textViews[i].setVisibility(View.VISIBLE);
textViews[i].setOnClickListener(v -> {
mCommentPop.dismiss();
if (listener != null) {
if (!PDUtils.isLogin()) {
switch (showType) {
case CommentClickShowType.reply:
case CommentClickShowType.delete:
case CommentClickShowType.report:
ProcessUtils.toOneKeyLoginActivity();
return;
default:
break;
}
}
listener.click(showType);
}
});
}
for (int i = 0; i < length - 1; i++) {
lineViews[i] = view.findViewById(lineIds[i]);
lineViews[i].setVisibility(View.VISIBLE);
}
})
.setOnDismissListener((EasyPopup.OnDismissListener) () -> mCommentPop = null)
.setFocusAndOutsideEnable(true)
.apply();
mCommentPop.showAtAnchorView(anchor, YGravity.CENTER, XGravity.LEFT, 0, 0);
}
}