合并module base
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package com.xscm.moduleutil.activity;
|
||||
|
||||
import static androidx.core.content.ContextCompat.getSystemService;
|
||||
|
||||
import static com.xscm.moduleutil.base.CommonAppContext.postDelayed;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -54,12 +52,10 @@ import com.hjq.toast.ToastUtils;
|
||||
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.base.RoomManager;
|
||||
import com.xscm.moduleutil.bean.XLHBean;
|
||||
import com.xscm.moduleutil.event.HourlyBean;
|
||||
import com.xscm.moduleutil.event.MqttBean;
|
||||
import com.xscm.moduleutil.event.RedBean;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.BackgroundManager;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.DisplayUtil;
|
||||
@@ -88,8 +84,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
}
|
||||
|
||||
protected VDB mBinding;
|
||||
private static final List<BaseMvpActivity> activityList = new ArrayList<>();
|
||||
|
||||
|
||||
// private LoadingDialog mLoadingDialog;
|
||||
// 添加广播接收器成员变量
|
||||
@@ -115,6 +109,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
|
||||
QXGiftDriftView qxGiftDriftView;
|
||||
protected void doDone(){}
|
||||
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -198,14 +193,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
}
|
||||
}
|
||||
|
||||
public static void finishAll() {
|
||||
for (BaseMvpActivity activity : activityList) {
|
||||
if (!activity.isFinishing()) {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorChanged() {
|
||||
// 在主线程中更新UI
|
||||
@@ -235,20 +222,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
timerHandler.postDelayed(timerRunnable, 10000);
|
||||
}
|
||||
|
||||
// 你需要定期执行的方法
|
||||
private void executePeriodicTask() {
|
||||
// 在这里实现你的业务逻辑
|
||||
LogUtils.d("定时任务执行中...");
|
||||
List<HourlyBean> hourlyBeans = new ArrayList<>();
|
||||
HourlyBean hourlyBean = new HourlyBean();
|
||||
hourlyBean.setText("nihao");
|
||||
hourlyBean.setRank_number("1");
|
||||
hourlyBean.setRoom_name("夏末");
|
||||
hourlyBean.setRoom_id("1");
|
||||
hourlyBeans.add(hourlyBean);
|
||||
onMessageReceived(hourlyBeans);
|
||||
}
|
||||
|
||||
protected void loadNetworkBackground() {
|
||||
// 只有当已经有背景URL时才加载
|
||||
String backgroundUrl = BackgroundManager.getInstance().getBackgroundUrl();
|
||||
@@ -327,36 +300,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
||||
// 清理MQTT相关资源
|
||||
synchronized (mqttQueueLock) {
|
||||
mqttMessageQueue.clear();
|
||||
isMqttPlaying = false;
|
||||
}
|
||||
|
||||
// 清理XLH相关资源
|
||||
synchronized (xlhQueueLock) {
|
||||
xlhMessageQueue.clear();
|
||||
isXlhPlaying = false;
|
||||
}
|
||||
|
||||
// 移除当前显示的视图
|
||||
try {
|
||||
if (currentMqttView != null && currentMqttView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
|
||||
parent.removeView(currentMqttView);
|
||||
}
|
||||
currentMqttView = null;
|
||||
|
||||
if (currentXlhView != null && currentXlhView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
|
||||
parent.removeView(currentXlhView);
|
||||
}
|
||||
currentXlhView = null;
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("清理飘屏视图失败", e);
|
||||
}
|
||||
|
||||
// 移除背景更新监听器
|
||||
BackgroundManager.getInstance().removeListener(this);
|
||||
// 移除颜色变化监听器
|
||||
@@ -445,741 +388,5 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
}
|
||||
|
||||
|
||||
/// 礼物特效
|
||||
// 在类中添加以下成员变量
|
||||
private final List<MqttBean.ListBean> mqttMessageQueue = new ArrayList<>(); // MQTT消息队列
|
||||
private final List<XLHBean> xlhMessageQueue = new ArrayList<>(); // XLH消息队列
|
||||
private final List<RedBean> redMessageQueue = new ArrayList<>(); // 红包队列
|
||||
private boolean isMqttPlaying = false; // MQTT播放状态标志
|
||||
private boolean isXlhPlaying = false; // XLH播放状态标志
|
||||
private boolean isRedPlaying = false; // XLH播放状态标志
|
||||
private final Object mqttQueueLock = new Object(); // MQTT队列同步锁
|
||||
private final Object xlhQueueLock = new Object(); // XLH队列同步锁
|
||||
private final Object RedQueueLock = new Object(); // XLH队列同步锁
|
||||
private View currentMqttView = null; // 当前正在播放的MQTT视图
|
||||
private View currentXlhView = null; // 当前正在播放的XLH视图
|
||||
private View currentRedView = null; // 当前正在播放的XLH视图
|
||||
|
||||
private final List<HourlyBean> hourlyMessageQueue = new ArrayList<>(); // 小时榜消息队列
|
||||
private final Map<Integer, View> currentHourlyViews = new HashMap<>(); // 当前显示的小时榜视图
|
||||
private final Object hourlyQueueLock = new Object(); // 小时榜队列同步锁
|
||||
private boolean isHourlyProcessing = false; // 小时榜处理状态标志
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(List<HourlyBean> hourlyBean) {
|
||||
LogUtils.e("收到小时榜", hourlyBean);
|
||||
if (hourlyBean == null) return;
|
||||
if (SpUtil.getFloatingScreen() == 1) {
|
||||
synchronized (hourlyQueueLock) {
|
||||
hourlyMessageQueue.addAll(hourlyBean);
|
||||
if (!isHourlyProcessing) {
|
||||
isHourlyProcessing = true;
|
||||
processHourlyMessages();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hourlyMessageQueue.clear();
|
||||
clearAllHourlyViews();
|
||||
}
|
||||
}
|
||||
|
||||
private void processHourlyMessages() {
|
||||
List<HourlyBean> messagesToProcess;
|
||||
synchronized (hourlyQueueLock) {
|
||||
if (hourlyMessageQueue.isEmpty()) {
|
||||
isHourlyProcessing = false;
|
||||
return;
|
||||
}
|
||||
// 每次只处理1条数据
|
||||
messagesToProcess = new ArrayList<>();
|
||||
messagesToProcess.add(hourlyMessageQueue.remove(0));
|
||||
}
|
||||
|
||||
// 只展示一条数据
|
||||
HourlyBean bean = messagesToProcess.get(0);
|
||||
showHourlyFloatingMessage(bean, 0);
|
||||
}
|
||||
|
||||
private void showHourlyFloatingMessage(HourlyBean hourlyBean, int positionIndex) {
|
||||
try {
|
||||
ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
|
||||
|
||||
// 创建新的视图
|
||||
View hourlyView = LayoutInflater.from(this).inflate(R.layout.item_hourly_floating, null);
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
// 设置固定的垂直位置
|
||||
int baseMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 70);
|
||||
layoutParams.topMargin = baseMargin;
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
||||
hourlyView.setLayoutParams(layoutParams);
|
||||
|
||||
decorView.addView(hourlyView);
|
||||
|
||||
// 保存视图引用
|
||||
currentHourlyViews.put(positionIndex, hourlyView);
|
||||
|
||||
// 更新视图数据
|
||||
updateHourlyFloatingViewData(hourlyView, hourlyBean);
|
||||
|
||||
// 根据类型获取展示时间
|
||||
long displayDuration = getDisplayDurationByType(Integer.parseInt(hourlyBean.getRank_number()));
|
||||
|
||||
// 启动动画
|
||||
resetAndStartHourlyAnimation(hourlyView, displayDuration, () -> {
|
||||
// 动画结束后清理视图
|
||||
if (hourlyView.getParent() != null) {
|
||||
decorView.removeView(hourlyView);
|
||||
}
|
||||
currentHourlyViews.remove(positionIndex);
|
||||
|
||||
// 检查是否还有更多消息需要处理
|
||||
synchronized (hourlyQueueLock) {
|
||||
if (hourlyMessageQueue.isEmpty()) {
|
||||
isHourlyProcessing = false;
|
||||
} else {
|
||||
// 当前视图消失后处理下一条消息
|
||||
processHourlyMessages();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("显示小时榜飘屏失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private long getDisplayDurationByType(int type) {
|
||||
// 根据不同类型设置不同的展示时间(毫秒)
|
||||
switch (type) {
|
||||
case 1: // 第一名
|
||||
return 5000; // 5秒
|
||||
case 2: // 第二名
|
||||
return 4000; // 4秒
|
||||
case 3: // 第三名
|
||||
return 3000; // 3秒
|
||||
default:
|
||||
return 3000; // 默认3秒
|
||||
}
|
||||
}
|
||||
|
||||
private void updateHourlyFloatingViewData(View view, HourlyBean hourlyBean) {
|
||||
TextView tvName = view.findViewById(R.id.tv_name);
|
||||
ImageView ivAvatar = view.findViewById(R.id.im_h_t);
|
||||
|
||||
if (hourlyBean != null) {
|
||||
// 根据排名设置不同的显示
|
||||
switch (hourlyBean.getRank_number()) {
|
||||
case "1":
|
||||
// tvName.setText("新科状元! ["+hourlyBean.getRoom_name()+"] 独占鳌头!");
|
||||
setColoredText(tvName, "新科状元! [", hourlyBean.getRoom_name(), "] 独占鳌头!", R.color.color_FFFA63);
|
||||
ivAvatar.setImageResource(R.mipmap.hourl_top1);
|
||||
break;
|
||||
case "2":
|
||||
// tvName.setText("金榜榜眼! ["+hourlyBean.getRoom_name()+"] 才气逼人!");
|
||||
setColoredText(tvName, "金榜榜眼! [", hourlyBean.getRoom_name(), "] 才气逼人!", R.color.color_FFFA63);
|
||||
|
||||
ivAvatar.setImageResource(R.mipmap.hourl_top2);
|
||||
break;
|
||||
case "3":
|
||||
setColoredText(tvName, "风采探花! [", hourlyBean.getRoom_name(), "] 实力绽放!", R.color.color_1FFFE5);
|
||||
// tvName.setText("风采探花! ["+hourlyBean.getRoom_name()+"] 实力绽放!");
|
||||
|
||||
ivAvatar.setImageResource(R.mipmap.hourl_top3);
|
||||
break;
|
||||
default:
|
||||
tvName.setVisibility(View.GONE);
|
||||
ivAvatar.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 设置带颜色的文本
|
||||
// 设置带颜色的文本
|
||||
private void setColoredText(TextView textView, String prefix, String roomName, String suffix, int colorRes) {
|
||||
String fullText = prefix + roomName + suffix;
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(fullText);
|
||||
|
||||
// 先为整个文本设置白色
|
||||
builder.setSpan(
|
||||
new ForegroundColorSpan(ContextCompat.getColor(this, R.color.white)),
|
||||
0,
|
||||
fullText.length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
);
|
||||
|
||||
// 查找房间名在文本中的位置
|
||||
int start = fullText.indexOf("[");
|
||||
int end = fullText.indexOf("]") + 1;
|
||||
|
||||
if (start >= 0 && end > start) {
|
||||
// 为房间名部分设置指定颜色
|
||||
builder.setSpan(
|
||||
new ForegroundColorSpan(ContextCompat.getColor(this, colorRes)),
|
||||
start,
|
||||
end,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
);
|
||||
}
|
||||
|
||||
textView.setText(builder);
|
||||
}
|
||||
|
||||
private void resetAndStartHourlyAnimation(View view, long displayDuration, Runnable onAnimationEnd) {
|
||||
try {
|
||||
int screenWidth = getScreenWidth();
|
||||
// 设置初始位置:在屏幕右侧外部
|
||||
view.setTranslationX(screenWidth);
|
||||
|
||||
// 进入动画
|
||||
ObjectAnimator enterAnimator = ObjectAnimator.ofFloat(view, "translationX", screenWidth, 0f);
|
||||
enterAnimator.setDuration(500);
|
||||
enterAnimator.setInterpolator(new DecelerateInterpolator());
|
||||
enterAnimator.start();
|
||||
|
||||
// 停留后退出动画
|
||||
view.postDelayed(() -> {
|
||||
try {
|
||||
ObjectAnimator exitAnimator = ObjectAnimator.ofFloat(view, "translationX", 0f, -screenWidth);
|
||||
exitAnimator.setDuration(500);
|
||||
exitAnimator.setInterpolator(new AccelerateInterpolator());
|
||||
exitAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
});
|
||||
exitAnimator.start();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("小时榜退出动画执行失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}, displayDuration); // 根据类型设置的展示时间
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("小时榜动画启动失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void clearAllHourlyViews() {
|
||||
ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
|
||||
for (View view : currentHourlyViews.values()) {
|
||||
if (view.getParent() != null) {
|
||||
decorView.removeView(view);
|
||||
}
|
||||
}
|
||||
currentHourlyViews.clear();
|
||||
}
|
||||
|
||||
/// 礼物特效 - MQTT消息处理
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttBean mqttBean) {
|
||||
LogUtils.e("收到MQTT", mqttBean);
|
||||
if (mqttBean == null) return;
|
||||
if (SpUtil.getFloatingScreen() == 1) {
|
||||
synchronized (mqttQueueLock) {
|
||||
|
||||
mqttMessageQueue.addAll(mqttBean.getList());
|
||||
// if (!isMqttPlaying) {
|
||||
// isMqttPlaying = true;
|
||||
processNextMqttMessage();
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
mqttMessageQueue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// XLH消息处理
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(XLHBean event) {
|
||||
LogUtils.e("收到XLH", event);
|
||||
if (event == null) return;
|
||||
if (event.getText()==null || event.getText().isEmpty()) return;
|
||||
if (SpUtil.getFloatingScreen() == 1) {
|
||||
synchronized (xlhQueueLock) {
|
||||
xlhMessageQueue.add(event);
|
||||
if (!isXlhPlaying) {
|
||||
isXlhPlaying = true;
|
||||
processNextXlhMessage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
xlhMessageQueue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(RedBean event){
|
||||
LogUtils.e("收到红包", event);
|
||||
if (event==null) return;
|
||||
if (SpUtil.getFloatingScreen()==1){
|
||||
|
||||
synchronized (RedQueueLock) {
|
||||
redMessageQueue.add(event);
|
||||
if (!isRedPlaying) {
|
||||
isRedPlaying = true;
|
||||
processNextRedMessage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
redMessageQueue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void processNextRedMessage() {
|
||||
RedBean redBean;
|
||||
synchronized (RedQueueLock) {
|
||||
if (redMessageQueue.isEmpty()) {
|
||||
isRedPlaying = false;
|
||||
return;
|
||||
}
|
||||
redBean = redMessageQueue.remove(0);
|
||||
}
|
||||
showPiaoPingMessageRed(redBean);
|
||||
}
|
||||
|
||||
private void showPiaoPingMessageRed(RedBean redBean){
|
||||
try {
|
||||
// 清理之前的视图(如果存在)
|
||||
if (currentRedView != null && currentRedView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentRedView.getParent();
|
||||
parent.removeView(currentRedView);
|
||||
}
|
||||
|
||||
if (decorView2 == null) {
|
||||
decorView2 = (ViewGroup) getWindow().getDecorView();
|
||||
}
|
||||
|
||||
currentRedView = LayoutInflater.from(this).inflate(R.layout.item_piaoping_red, null);
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 140);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
||||
currentRedView.setLayoutParams(layoutParams);
|
||||
decorView2.addView(currentRedView);
|
||||
|
||||
updateRedFloatingViewData(currentRedView, redBean);
|
||||
// 播放红包音效
|
||||
playRedPacketSound();
|
||||
resetAndStartXlhAnimation(currentRedView, () -> {
|
||||
// 清理当前视图
|
||||
if (currentRedView != null && currentRedView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentRedView.getParent();
|
||||
parent.removeView(currentRedView);
|
||||
}
|
||||
currentRedView = null;
|
||||
|
||||
// 处理队列中的下一条消息
|
||||
synchronized (RedQueueLock) {
|
||||
isRedPlaying = false;
|
||||
processNextRedMessage();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("显示红包飘屏失败", e);
|
||||
// 出现异常时继续处理队列
|
||||
synchronized (RedQueueLock) {
|
||||
isRedPlaying = false;
|
||||
processNextRedMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
// 在类中添加成员变量
|
||||
private MediaPlayer redPacketMediaPlayer = null;
|
||||
private boolean isRedPacketMediaPrepared = false;
|
||||
// 添加播放红包音效的方法
|
||||
private void playRedPacketSound() {
|
||||
try {
|
||||
if (!isRedPacketMediaPrepared) {
|
||||
// 第一次初始化MediaPlayer
|
||||
if (redPacketMediaPlayer == null) {
|
||||
redPacketMediaPlayer = MediaPlayer.create(this, R.raw.red_packet_come); // 假设音效文件名为red_packet_sound.mp3
|
||||
redPacketMediaPlayer.setOnPreparedListener(mp -> {
|
||||
isRedPacketMediaPrepared = true;
|
||||
mp.start();
|
||||
});
|
||||
redPacketMediaPlayer.setOnCompletionListener(mp -> {
|
||||
// 播放完成后重置,以便下次重新播放
|
||||
try {
|
||||
mp.seekTo(0);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("MediaPlayer重置失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (redPacketMediaPlayer != null) {
|
||||
redPacketMediaPlayer.prepareAsync(); // 异步准备
|
||||
}
|
||||
} else {
|
||||
// 已经准备好了,直接重新播放
|
||||
if (redPacketMediaPlayer != null && !redPacketMediaPlayer.isPlaying()) {
|
||||
redPacketMediaPlayer.seekTo(0);
|
||||
redPacketMediaPlayer.start();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("播放红包音效失败", e);
|
||||
isRedPacketMediaPrepared=false;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRedFloatingViewData(View view, RedBean redBean){
|
||||
TextView textView = view.findViewById(R.id.tv_name);
|
||||
|
||||
if (redBean != null) {
|
||||
String fullText = redBean.getText();
|
||||
if (redBean.getNickname() != null && redBean.getRoom_name() != null) {
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(fullText);
|
||||
|
||||
// 为用户名设置蓝色
|
||||
int userNameStart = fullText.indexOf(redBean.getNickname());
|
||||
if (userNameStart >= 0) {
|
||||
builder.setSpan(
|
||||
new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)),
|
||||
userNameStart,
|
||||
userNameStart + redBean.getNickname().length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
);
|
||||
}
|
||||
|
||||
// 为房间名设置蓝色
|
||||
int roomNameStart = fullText.indexOf(redBean.getRoom_name());
|
||||
if (roomNameStart >= 0) {
|
||||
builder.setSpan(
|
||||
new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)),
|
||||
roomNameStart,
|
||||
roomNameStart + redBean.getRoom_name().length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
);
|
||||
}
|
||||
|
||||
textView.setText(builder);
|
||||
} else {
|
||||
textView.setText(fullText);
|
||||
}
|
||||
} else {
|
||||
textView.setText("");
|
||||
}
|
||||
|
||||
view.setOnClickListener(v -> {
|
||||
// 点击时执行跳转操作
|
||||
handleRedItemClick(redBean);
|
||||
});
|
||||
}
|
||||
|
||||
// 处理下一个MQTT消息
|
||||
private void processNextMqttMessage() {
|
||||
MqttBean.ListBean mqttBean;
|
||||
synchronized (mqttQueueLock) {
|
||||
if (mqttMessageQueue.isEmpty()) {
|
||||
isMqttPlaying = false;
|
||||
return;
|
||||
}
|
||||
mqttBean = mqttMessageQueue.remove(0);
|
||||
}
|
||||
showFloatingMessage(mqttBean);
|
||||
}
|
||||
|
||||
// 处理下一个XLH消息
|
||||
private void processNextXlhMessage() {
|
||||
XLHBean xlhBean;
|
||||
synchronized (xlhQueueLock) {
|
||||
if (xlhMessageQueue.isEmpty()) {
|
||||
isXlhPlaying = false;
|
||||
return;
|
||||
}
|
||||
xlhBean = xlhMessageQueue.remove(0);
|
||||
}
|
||||
showPiaoPingMessageXlh(xlhBean);
|
||||
}
|
||||
|
||||
ViewGroup decorView;//礼物的
|
||||
ViewGroup decorView1;//巡乐会的
|
||||
ViewGroup decorView2;//红包的
|
||||
|
||||
private void showFloatingMessage(MqttBean.ListBean mqttBean) {
|
||||
|
||||
// QXGiftDriftView.getInstance( this).addGiftModel(mqttBean);
|
||||
|
||||
|
||||
try {
|
||||
// 清理之前的视图(如果存在)
|
||||
if (currentMqttView != null && currentMqttView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
|
||||
parent.removeView(currentMqttView);
|
||||
}
|
||||
|
||||
if (decorView == null) {
|
||||
decorView = (ViewGroup) getWindow().getDecorView();
|
||||
}
|
||||
|
||||
currentMqttView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 70);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
||||
currentMqttView.setLayoutParams(layoutParams);
|
||||
decorView.addView(currentMqttView);
|
||||
|
||||
updateFloatingViewData(currentMqttView, mqttBean);
|
||||
resetAndStartMqttAnimation(currentMqttView, () -> {
|
||||
// 清理当前视图
|
||||
if (currentMqttView != null && currentMqttView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
|
||||
parent.removeView(currentMqttView);
|
||||
}
|
||||
currentMqttView = null;
|
||||
|
||||
// 处理队列中的下一条消息
|
||||
synchronized (mqttQueueLock) {
|
||||
isMqttPlaying = false;
|
||||
processNextMqttMessage();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("显示MQTT飘屏失败", e);
|
||||
// 出现异常时继续处理队列
|
||||
synchronized (mqttQueueLock) {
|
||||
isMqttPlaying = false;
|
||||
processNextMqttMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showPiaoPingMessageXlh(XLHBean event) {
|
||||
try {
|
||||
// 清理之前的视图(如果存在)
|
||||
if (currentXlhView != null && currentXlhView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
|
||||
parent.removeView(currentXlhView);
|
||||
}
|
||||
|
||||
if (decorView1 == null) {
|
||||
decorView1 = (ViewGroup) getWindow().getDecorView();
|
||||
}
|
||||
|
||||
currentXlhView = LayoutInflater.from(this).inflate(R.layout.item_piaoping_xlh, null);
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 100);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
||||
currentXlhView.setLayoutParams(layoutParams);
|
||||
decorView1.addView(currentXlhView);
|
||||
|
||||
updateXlhFloatingViewData(currentXlhView, event);
|
||||
resetAndStartXlhAnimation(currentXlhView, () -> {
|
||||
// 清理当前视图
|
||||
if (currentXlhView != null && currentXlhView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
|
||||
parent.removeView(currentXlhView);
|
||||
}
|
||||
currentXlhView = null;
|
||||
|
||||
// 处理队列中的下一条消息
|
||||
synchronized (xlhQueueLock) {
|
||||
isXlhPlaying = false;
|
||||
processNextXlhMessage();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("显示XLH飘屏失败", e);
|
||||
// 出现异常时继续处理队列
|
||||
synchronized (xlhQueueLock) {
|
||||
isXlhPlaying = false;
|
||||
processNextXlhMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAndStartMqttAnimation(View view, Runnable onAnimationEnd) {
|
||||
try {
|
||||
int screenWidth = getScreenWidth();
|
||||
// 设置初始位置:在屏幕右侧外部(完全不可见)
|
||||
view.setTranslationX(screenWidth);
|
||||
|
||||
|
||||
TranslateAnimation enterAnim = new TranslateAnimation(
|
||||
Animation.ABSOLUTE, screenWidth,
|
||||
Animation.ABSOLUTE, (screenWidth - SystemUtils.getWidth(316)) / 2,
|
||||
Animation.ABSOLUTE, 0,
|
||||
Animation.ABSOLUTE, 0
|
||||
);
|
||||
enterAnim.setDuration(1500);
|
||||
enterAnim.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
enterAnim.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
// 停留后退出
|
||||
postDelayed(() -> {
|
||||
TranslateAnimation exitAnim = new TranslateAnimation(
|
||||
Animation.ABSOLUTE, (screenWidth - SystemUtils.getWidth(316)) / 2,
|
||||
Animation.ABSOLUTE, -screenWidth,
|
||||
Animation.ABSOLUTE, 0,
|
||||
Animation.ABSOLUTE, 0
|
||||
);
|
||||
exitAnim.setDuration(3000);
|
||||
exitAnim.setInterpolator(new DecelerateInterpolator(2f));
|
||||
exitAnim.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
// 移除视图并处理下一个
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
});
|
||||
view.startAnimation(exitAnim);
|
||||
}, 5000); // 停留1秒
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
});
|
||||
view.startAnimation(enterAnim);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("MQTT动画启动失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}
|
||||
|
||||
// 添加获取屏幕宽度的方法
|
||||
private int getScreenWidth() {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
if (getWindowManager() != null) {
|
||||
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
return displayMetrics.widthPixels;
|
||||
}
|
||||
return getResources().getDisplayMetrics().widthPixels;
|
||||
}
|
||||
|
||||
private void resetAndStartXlhAnimation(View view, Runnable onAnimationEnd) {
|
||||
try {
|
||||
view.setTranslationX(view.getWidth());
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
|
||||
animator1.setDuration(1500);
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator1.start();
|
||||
|
||||
view.postDelayed(() -> {
|
||||
try {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
|
||||
animator2.setDuration(1500);
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("XLH动画执行失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}, 5000);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("XLH动画启动失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFloatingViewData(View view, MqttBean.ListBean mqttBean) {
|
||||
TextView textView = view.findViewById(R.id.tv_name);
|
||||
TextView textView2 = view.findViewById(R.id.tv_to_name);
|
||||
TextView tv_time = view.findViewById(R.id.tv_num);
|
||||
|
||||
if (mqttBean != null) {
|
||||
textView2.setText("送给" + (mqttBean.getToUserName() != null ? mqttBean.getToUserName() : ""));
|
||||
textView.setText(mqttBean.getFromUserName() != null ? mqttBean.getFromUserName() : "");
|
||||
if (mqttBean.getGift_picture() != null) {
|
||||
ImageUtils.loadHeadCC(mqttBean.getGift_picture(), view.findViewById(R.id.iv_piaoping));
|
||||
}
|
||||
tv_time.setText("x" + (mqttBean.getNumber() != null ? mqttBean.getNumber() : "1"));
|
||||
} else {
|
||||
textView2.setText("送给");
|
||||
textView.setText("");
|
||||
tv_time.setText("x1");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateXlhFloatingViewData(View view, XLHBean xlhBean) {
|
||||
TextView textView = view.findViewById(R.id.tv_name);
|
||||
ImageView xlh_image = view.findViewById(R.id.im_xlh);
|
||||
|
||||
if (xlhBean != null) {
|
||||
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ?
|
||||
getResources().getDrawable(R.mipmap.xlh_jjks) :
|
||||
getResources().getDrawable(R.mipmap.xlh_zsks));
|
||||
textView.setText(xlhBean.getText());
|
||||
} else {
|
||||
textView.setText("");
|
||||
}
|
||||
|
||||
view.setOnClickListener(v -> {
|
||||
// 点击时执行跳转操作
|
||||
handleItemClick(xlhBean);
|
||||
});
|
||||
}
|
||||
|
||||
private void handleItemClick(XLHBean xlhBean) {
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
// 使用缓存数据进入房间
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), xlhBean.getRoom_id(), "",null);
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
|
||||
private void handleRedItemClick(RedBean redBean) {
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
// 使用缓存数据进入房间
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), redBean.getRoom_id(), "",null);
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(ChatInfo event) {
|
||||
String id = event.getId().replace("g", "");
|
||||
Intent intent = new Intent(this, WebViewActivity.class);
|
||||
intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/union/setGroup?id=" + SpUtil.getToken() + "&guildId=" + id);
|
||||
startActivity(intent);
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/union/setGroup?id=" + SpUtil.getToken() + "&guildId=" + id).navigation();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,304 +0,0 @@
|
||||
package com.xscm.moduleutil.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.tencent.imsdk.v2.V2TIMConversationListener;
|
||||
import com.tencent.imsdk.v2.V2TIMConversationManager;
|
||||
import com.tencent.imsdk.v2.V2TIMSDKListener;
|
||||
import com.tencent.imsdk.v2.V2TIMValueCallback;
|
||||
import com.tencent.qcloud.tuicore.TUIConfig;
|
||||
import com.tencent.qcloud.tuicore.TUIConstants;
|
||||
import com.tencent.qcloud.tuicore.TUICore;
|
||||
import com.tencent.qcloud.tuicore.interfaces.TUILoginListener;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.base.RoomManager;
|
||||
import com.xscm.moduleutil.bean.UserBean;
|
||||
import com.xscm.moduleutil.bean.UserInfo;
|
||||
import com.xscm.moduleutil.dialog.ConfirmDialog;
|
||||
import com.xscm.moduleutil.event.UnreadCountEvent;
|
||||
import com.xscm.moduleutil.http.RetrofitClient;
|
||||
import com.xscm.moduleutil.utils.LanguageUtil;
|
||||
import com.xscm.moduleutil.utils.location.LocationProvider;
|
||||
import com.xscm.moduleutil.utils.location.SystemLocationProvider;
|
||||
import com.tencent.imsdk.v2.V2TIMCallback;
|
||||
import com.tencent.imsdk.v2.V2TIMManager;
|
||||
import com.tencent.imsdk.v2.V2TIMUserFullInfo;
|
||||
import com.tencent.qcloud.tuicore.TUILogin;
|
||||
import com.tencent.qcloud.tuicore.interfaces.TUICallback;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewDataBinding> extends BaseAppCompatActivity<VDB> implements
|
||||
IView<Activity> {
|
||||
|
||||
protected P MvpPre;
|
||||
|
||||
protected abstract P bindPresenter();
|
||||
|
||||
@Override
|
||||
protected void doDone() {
|
||||
super.doDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
MvpPre = bindPresenter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoadings() {
|
||||
// showLoading("加载中");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoadings(String content) {
|
||||
// showLoading(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disLoadings() {
|
||||
// disLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (MvpPre != null) {
|
||||
try {
|
||||
MvpPre.detachView();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getSelfActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(LanguageUtil.attachBaseContext(newBase));
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void logOutEvent(UserBean userBean) {
|
||||
// 在用户 UI 点击登录的时候调用
|
||||
TUILogin.login(getBaseContext(), CommonAppContext.getInstance().getCurrentEnvironment().getSdkAppId(), "u" + userBean.getUser_id(), userBean.getTencent_im(), new TUICallback() {
|
||||
@Override
|
||||
public void onError(final int code, final String desc) {
|
||||
LogUtils.e("@@@1", code, "描述:", desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
LogUtils.e("@@@", "成功");
|
||||
V2TIMManager.getConversationManager().getTotalUnreadMessageCount(new V2TIMValueCallback<Long>() {
|
||||
@Override
|
||||
public void onSuccess(Long aLong) {
|
||||
// 通知未读数变化
|
||||
UnreadCountEvent event =CommonAppContext.getInstance().unreadCountEvent;
|
||||
if (event==null){
|
||||
event=new UnreadCountEvent();
|
||||
}
|
||||
event.setALong(aLong);
|
||||
// 使用EventBus通知
|
||||
CommonAppContext.getInstance().setUnreadCountEvent(event);
|
||||
EventBus.getDefault().post(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String desc) {
|
||||
// 错误处理
|
||||
}
|
||||
});
|
||||
//initLocation();
|
||||
}
|
||||
});
|
||||
// V2TIMManager.getInstance().addIMSDKListener(imSdkListener);
|
||||
|
||||
}
|
||||
|
||||
private final V2TIMSDKListener imSdkListener = new V2TIMSDKListener() {
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectSuccess() {//重连成功
|
||||
if (CommonAppContext.getInstance().playId!=null){
|
||||
LogUtils.e("@@@", "重连成功");
|
||||
LogUtils.e("@@@", ""+CommonAppContext.getInstance().playId);
|
||||
RetrofitClient.getInstance().roomUserReconnect(CommonAppContext.getInstance().playId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectFailed(int code, String error) {
|
||||
LogUtils.e("@@@", "断开连接");
|
||||
CommonAppContext.getInstance().onConnectFailed=true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKickedOffline() {
|
||||
// queren1();
|
||||
if (CommonAppContext.getInstance().playId!=null){
|
||||
ToastUtils.showShort("您的账号已被挤下线");
|
||||
try {
|
||||
CommonAppContext.getInstance().clearLoginInfo();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserSigExpired() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
|
||||
}
|
||||
};
|
||||
|
||||
private void queren1() {
|
||||
// 创建并显示确认对话框
|
||||
new ConfirmDialog(this,
|
||||
"温馨提示",
|
||||
"您的账号已在别处登录,请确认密码是否已经泄露",
|
||||
"知道了",
|
||||
"",
|
||||
v -> {
|
||||
// 点击“确认”按钮时执行删除操作
|
||||
|
||||
if (CommonAppContext.getInstance().playId!=null){
|
||||
RoomManager.getInstance().exitRoom(CommonAppContext.getInstance().playId);
|
||||
}
|
||||
try {
|
||||
CommonAppContext.getInstance().clearLoginInfo();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
},
|
||||
v -> {
|
||||
// 点击“取消”按钮时什么都不做
|
||||
|
||||
}, false, 0).show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
Resources resources = super.getResources();
|
||||
if (resources != null) {
|
||||
Configuration configuration = resources.getConfiguration();
|
||||
if (configuration != null) {
|
||||
// 设置字体缩放比例不随系统变化
|
||||
configuration.fontScale = 1.0f; // 1.0f表示默认大小
|
||||
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示全局飘屏消息(支持任意位置飘过)
|
||||
*
|
||||
*/
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void showPiaoPingMessage(MqttBean mqttBean) {
|
||||
// WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||
// if (windowManager == null) return;
|
||||
//
|
||||
// int screenWidth = getResources().getDisplayMetrics().widthPixels;
|
||||
// int screenHeight = getResources().getDisplayMetrics().heightPixels;
|
||||
//
|
||||
// WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||
// WindowManager.LayoutParams.MATCH_PARENT,
|
||||
// WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
|
||||
// WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY :
|
||||
// WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
|
||||
// WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
||||
// WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
|
||||
// WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
|
||||
// PixelFormat.TRANSLUCENT);
|
||||
//
|
||||
// // 设置 Gravity 为左上角
|
||||
// layoutParams.gravity = Gravity.TOP | Gravity.START;
|
||||
//
|
||||
// // Y 轴随机位置
|
||||
//// layoutParams.y = (int) ((Math.random() * (screenHeight - 200)));
|
||||
//
|
||||
// // 初始 X 设为负值,确保 View 在屏幕左侧外
|
||||
// layoutParams.x = -screenWidth;
|
||||
//
|
||||
// View piaoPingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
|
||||
// TextView textView = piaoPingView.findViewById(R.id.tv_name);
|
||||
// TextView textView2 = piaoPingView.findViewById(R.id.tv_to_name);
|
||||
// textView2.setText("送给"+mqttBean.getList().getToUserName());
|
||||
// textView.setText(mqttBean.getList().getFromUserName());
|
||||
// ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), piaoPingView.findViewById(R.id.iv_piaoping));
|
||||
// TextView tv_time = piaoPingView.findViewById(R.id.tv_num);
|
||||
// tv_time.setText(mqttBean.getList().getNumber());
|
||||
// windowManager.addView(piaoPingView, layoutParams);
|
||||
//
|
||||
// piaoPingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
// @Override
|
||||
// public void onGlobalLayout() {
|
||||
// piaoPingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
//
|
||||
// // 设置锚点为左上角,避免偏移干扰
|
||||
// piaoPingView.setPivotX(0);
|
||||
// piaoPingView.setPivotY(0);
|
||||
//
|
||||
// // 启动动画:从左外滑入 -> 右外滑出
|
||||
// ObjectAnimator animator = ObjectAnimator.ofFloat(
|
||||
// piaoPingView,
|
||||
// "translationX",
|
||||
// 0f, // 初始偏移为 0(此时 View 在左侧外)
|
||||
// screenWidth // 向右移动整个屏幕宽度
|
||||
// );
|
||||
// animator.setDuration(2000); // 整个动画的时长为2秒
|
||||
//
|
||||
// // 强制 GPU 渲染
|
||||
// piaoPingView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
//
|
||||
// // 延迟显示2秒后开始滑出屏幕的动画
|
||||
// piaoPingView.postDelayed(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// animator.start();
|
||||
// }
|
||||
// }, 3000);
|
||||
//
|
||||
// animator.addListener(new AnimatorListenerAdapter() {
|
||||
// @Override
|
||||
// public void onAnimationEnd(Animator animation) {
|
||||
// windowManager.removeView(piaoPingView);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,454 +0,0 @@
|
||||
package com.xscm.moduleutil.activity;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.webkit.GeolocationPermissions;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Autowired;
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.base.RoomManager;
|
||||
import com.xscm.moduleutil.databinding.ActivityWebViewBinding;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.tencent.imsdk.v2.V2TIMConversation;
|
||||
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
import com.tencent.qcloud.tuicore.TUIConstants;
|
||||
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity;
|
||||
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIGroupChatActivity;
|
||||
|
||||
/**
|
||||
* @author qx
|
||||
* @data 2025/6/3
|
||||
* @description: webview公共方法
|
||||
*/
|
||||
@Route(path = ARouteConstants.H5)
|
||||
public class WebViewActivity extends BaseAppCompatActivity<ActivityWebViewBinding> {
|
||||
|
||||
public String title;
|
||||
public String url;
|
||||
@Autowired
|
||||
public String type;//type=1:青少年模式
|
||||
private ValueCallback<Uri> mUploadMessage;
|
||||
private ValueCallback<Uri[]> mUploadCallbackAboveL;
|
||||
private final int REQUEST_FILE_PICKER = 1;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
protected void initData() {
|
||||
|
||||
|
||||
WebSettings webSettings = mBinding.webView.getSettings();
|
||||
|
||||
// 禁用水平滚动
|
||||
webSettings.setUseWideViewPort(true);
|
||||
webSettings.setLoadWithOverviewMode(true);
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
|
||||
//增加JSBridge
|
||||
mBinding.webView.addJavascriptInterface(new WebAppInterface(this, type), "Android");
|
||||
|
||||
if (title != null && !title.isEmpty()) {
|
||||
if (title.contains("协议")) {
|
||||
webSettings.setDisplayZoomControls(false); // 隐藏默认缩放控件
|
||||
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); // 使用正常布局算法
|
||||
webSettings.setBuiltInZoomControls(false);
|
||||
webSettings.setSupportZoom(false);
|
||||
|
||||
// 重要:设置布局算法为适应屏幕
|
||||
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
|
||||
// 设置初始缩放
|
||||
mBinding.webView.setInitialScale(100);
|
||||
mBinding.webView.getSettings().setUseWideViewPort(false);
|
||||
} else {
|
||||
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
}
|
||||
} else {
|
||||
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
}
|
||||
|
||||
webSettings.setBuiltInZoomControls(true);
|
||||
webSettings.setSupportZoom(true);
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
webSettings.setBlockNetworkImage(false);//解决图片不显示
|
||||
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
|
||||
mBinding.webView.setHorizontalScrollBarEnabled(false);//水平不显示
|
||||
mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示
|
||||
mBinding.webView.setScrollbarFadingEnabled(false);
|
||||
mBinding.webView.setScrollContainer(true);
|
||||
|
||||
|
||||
mBinding.webView.setWebViewClient(new WebViewClient());
|
||||
mBinding.webView.setBackgroundColor(Color.TRANSPARENT);
|
||||
mBinding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
|
||||
mBinding.webView.requestFocus();
|
||||
mBinding.webView.loadUrl(url);
|
||||
|
||||
mBinding.webView.setWebChromeClient(new WebChromeClient() {
|
||||
|
||||
//配置权限(同样在WebChromeClient中实现)
|
||||
@Override
|
||||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
||||
callback.invoke(origin, true, false);
|
||||
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
if (title != null && !title.isEmpty()) {
|
||||
if (title.contains("协议")) {
|
||||
|
||||
if (newProgress >= 100) {
|
||||
// 页面加载完成后调整文本换行
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 注入CSS确保文字自动换行
|
||||
mBinding.webView.loadUrl("javascript:(function() {" +
|
||||
"var sheets = document.styleSheets;" +
|
||||
"for (var i = 0; i < sheets.length; i++) {" +
|
||||
" try {" +
|
||||
" sheets[i].addRule('*', 'word-wrap: break-word !important; white-space: normal !important; overflow-x: hidden !important;', 0);" +
|
||||
" } catch(e) {" +
|
||||
" try {" +
|
||||
" sheets[i].insertRule('* { word-wrap: break-word !important; white-space: normal !important; overflow-x: hidden !important; }', 0);" +
|
||||
" } catch(e2) {}" +
|
||||
" }" +
|
||||
"}" +
|
||||
"})()");
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For Android < 3.0
|
||||
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
||||
mUploadMessage = uploadMsg;
|
||||
// showFileChooser();
|
||||
|
||||
}
|
||||
|
||||
// For Android > 4.1.1
|
||||
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
|
||||
mUploadMessage = uploadMsg;
|
||||
// showFileChooser();
|
||||
}
|
||||
|
||||
// For Android > 5.0支持多张上传
|
||||
@Override
|
||||
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> uploadMsg, WebChromeClient.FileChooserParams
|
||||
fileChooserParams) {
|
||||
mUploadCallbackAboveL = uploadMsg;
|
||||
showFileChooser();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
// tvTitle.setText(title);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
if (getOnBackPressedDispatcher() != null) {
|
||||
getOnBackPressedDispatcher().addCallback(this, new androidx.activity.OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
// 拦截返回键,显示退出对话框而不是直接退出
|
||||
showExitRoomDialog();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void showExitRoomDialog() {
|
||||
if (type != null) {
|
||||
if (type.equals("1")) {
|
||||
ARouter.getInstance().build(ARouteConstants.UNDERAGE_ACTIVITY).withInt("type", 1).navigation();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void showFileChooser() {
|
||||
// 这里可以扩展为显示对话框让用户选择“拍照”或“从相册选择”
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("image/*");
|
||||
startActivityForResult(Intent.createChooser(intent, "选择图片"), REQUEST_FILE_PICKER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == REQUEST_FILE_PICKER) {
|
||||
if (mUploadMessage != null) {
|
||||
Uri result = data == null || resultCode != RESULT_OK ? null : data.getData();
|
||||
mUploadMessage.onReceiveValue(result);
|
||||
mUploadMessage = null;
|
||||
} else if (mUploadCallbackAboveL != null) {
|
||||
Uri[] results = null;
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
String dataString = data.getDataString();
|
||||
ClipData clipData = data.getClipData();
|
||||
|
||||
if (clipData != null) {
|
||||
results = new Uri[clipData.getItemCount()];
|
||||
for (int i = 0; i < clipData.getItemCount(); i++) {
|
||||
ClipData.Item item = clipData.getItemAt(i);
|
||||
results[i] = item.getUri();
|
||||
}
|
||||
}
|
||||
|
||||
if (dataString != null)
|
||||
results = new Uri[]{Uri.parse(dataString)};
|
||||
}
|
||||
|
||||
mUploadCallbackAboveL.onReceiveValue(results);
|
||||
mUploadCallbackAboveL = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// 当type==1时,禁止返回键和手势返回
|
||||
// 不执行任何操作,禁止返回
|
||||
if (type != null) {
|
||||
if (type.equals("1")) {
|
||||
ARouter.getInstance().build(ARouteConstants.UNDERAGE_ACTIVITY).withInt("type", 1).navigation();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
|
||||
// 正常处理返回键
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
LogUtils.d("MainActivity", "onKeyDown called, keyCode: " + keyCode);
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (type != null) {
|
||||
if (type.equals("1")) {
|
||||
ARouter.getInstance().build(ARouteConstants.UNDERAGE_ACTIVITY).withInt("type", 1).navigation();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
return true; // 消费事件
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
// // 当type==1时,禁止手势滑动返回
|
||||
// if (type.equals("1")) {
|
||||
// // 检查是否是边缘滑动返回手势
|
||||
// if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
// // 如果触摸点在屏幕边缘,拦截事件
|
||||
// if (ev.getX() < 50) { // 左边缘50像素内
|
||||
// return true; // 拦截事件,不传递给子View
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return super.dispatchTouchEvent(ev);
|
||||
// }
|
||||
@Override
|
||||
protected void initView() {
|
||||
getWindow().getDecorView().setBackgroundResource(com.xscm.moduleutil.R.color.white);
|
||||
title = getIntent().getStringExtra("title");
|
||||
url = getIntent().getStringExtra("url");
|
||||
type = getIntent().getStringExtra("type");
|
||||
if (type != null) {
|
||||
// 当type==1时,禁用返回手势滑动
|
||||
if (type.equals("1")) {
|
||||
// 禁用边缘滑动返回
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (title != null) {
|
||||
if (title.equals("举报") || title.equals("等级") || title.equals("公会") || title.equals("邀请") || title.equals("反馈")) {
|
||||
mBinding.topBar.setVisibility(GONE);
|
||||
// mBinding.webView.setPadding(0,20,0,0);
|
||||
} else {
|
||||
mBinding.topBar.setVisibility(VISIBLE);
|
||||
mBinding.topBar.setTitle(title);
|
||||
}
|
||||
} else {
|
||||
if (url.equals(CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=6")) {
|
||||
mBinding.topBar.setVisibility(VISIBLE);
|
||||
mBinding.topBar.setTitle("用户协议");
|
||||
} else if (url.equals(CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=4")) {
|
||||
mBinding.topBar.setVisibility(VISIBLE);
|
||||
mBinding.topBar.setTitle("隐私协议");
|
||||
} else {
|
||||
mBinding.topBar.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_web_view;
|
||||
}
|
||||
|
||||
public class WebAppInterface {
|
||||
Context mContext;
|
||||
String type;
|
||||
|
||||
WebAppInterface(Context c, String type1) {
|
||||
mContext = c;
|
||||
type = type1;
|
||||
}
|
||||
|
||||
// 被 H5 调用的方法
|
||||
@JavascriptInterface
|
||||
public void showToast(String toast) {
|
||||
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void closeWeb() {
|
||||
if (type != null) {
|
||||
if (type.equals("1")) {
|
||||
ARouter.getInstance().build(ARouteConstants.UNDERAGE_ACTIVITY).withInt("type", 1).navigation();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void customerService() {
|
||||
String appId = CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId(); // 填移动应用(App)的 AppId
|
||||
IWXAPI api = WXAPIFactory.createWXAPI(mContext, appId);
|
||||
|
||||
// 判断当前版本是否支持拉起客服会话
|
||||
WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req();
|
||||
req.corpId = "ww1de4300858c0b461"; // 企业ID
|
||||
req.url = "https://work.weixin.qq.com/kfid/kfcb3d23a59c188a0e7"; // 客服URL
|
||||
api.sendReq(req);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), room_id,"",null);
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpWebPage(String objects) {
|
||||
// ARouter.getInstance().build(ARouteConstants.USER_HOME_PAGE).navigation();
|
||||
ARouter.getInstance().build(ARouteConstants.USER_HOME_PAGE).withString("userId", objects).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void enterGroupChat(String group_id, String cover, String guild_name) {
|
||||
Intent intent = new Intent(mContext, TUIGroupChatActivity.class);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_ID, group_id);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_NAME, guild_name);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_GROUP);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void chatWithUser(String user_id, String nickname) {
|
||||
Intent intent = new Intent(mContext, TUIGroupChatActivity.class);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_ID, user_id);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_NAME, nickname);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_C2C);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void exchange() {
|
||||
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void Withdrawal() {
|
||||
ARouter.getInstance().build(ARouteConstants.WITHDRAWAL_ACTIVITY).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void enterAuthent() {//实名认证
|
||||
ARouter.getInstance().build(ARouteConstants.REAL_NAME_ACTIVITY2).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void Recharge() {
|
||||
ARouter.getInstance().build(ARouteConstants.RECHARGE_ACTIVITY).navigation();
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void closeWeb() {
|
||||
//做原生操作
|
||||
// Intent intent = new Intent(mContext, ListActivity.class);
|
||||
// intent.putExtra("menuName", msg);
|
||||
// startActivity(intent);
|
||||
|
||||
|
||||
LogUtils.e("closeWeb");
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.xscm.moduleutil.activity.news;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.xscm.moduleutil.activity.IPresenter;
|
||||
import com.xscm.moduleutil.activity.IView;
|
||||
import com.xscm.moduleutil.bean.NewsMessageList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NewsContacts {
|
||||
public interface View extends IView<Activity> {
|
||||
void showNews(List<NewsMessageList> newsList);
|
||||
void finishRefresh();
|
||||
}
|
||||
public interface IHomePre extends IPresenter {
|
||||
|
||||
void getMessagetitle(String type,String page,String pageLimit);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.xscm.moduleutil.activity.news;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.xscm.moduleutil.bean.NewsMessageList;
|
||||
import com.xscm.moduleutil.http.BaseObserver;
|
||||
import com.xscm.moduleutil.presenter.BasePresenter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
public class NewsPresenter extends BasePresenter<NewsContacts.View> implements NewsContacts.IHomePre {
|
||||
public NewsPresenter(NewsContacts.View view, Context context) {
|
||||
super(view, context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getMessagetitle(String type, String page, String pageLimit) {
|
||||
api.getMessagetitle(type, page, pageLimit, new BaseObserver<List<NewsMessageList>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
addDisposable(d);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(List<NewsMessageList> newsMessageLists) {
|
||||
MvpRef.get().showNews(newsMessageLists);
|
||||
MvpRef.get().finishRefresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package com.xscm.moduleutil.activity.news;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.activity.BaseMvpActivity;
|
||||
import com.xscm.moduleutil.activity.WebViewActivity;
|
||||
import com.xscm.moduleutil.base.RoomManager;
|
||||
import com.xscm.moduleutil.bean.NewsMessageList;
|
||||
import com.xscm.moduleutil.databinding.ActivityOfficialNoticeBinding;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
import com.xscm.moduleutil.utils.TimeUtils;
|
||||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OfficialNoticeActivity extends BaseMvpActivity<NewsPresenter, ActivityOfficialNoticeBinding> implements NewsContacts.View {
|
||||
|
||||
private int page = 1;
|
||||
private BaseQuickAdapter<NewsMessageList, BaseViewHolder> mAdapter;
|
||||
private String type;
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
type = getIntent().getStringExtra("type");
|
||||
if (type.equals("1")) {
|
||||
mBinding.topBar.setTitle("系统消息");
|
||||
} else {
|
||||
mBinding.topBar.setTitle("官方公告");
|
||||
}
|
||||
// mBinding.smartRefreshLayout.autoRefresh();
|
||||
|
||||
|
||||
mBinding.smartRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
|
||||
@Override
|
||||
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
||||
page++;
|
||||
MvpPre.getMessagetitle(type, page + "", "10");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||||
page = 1;
|
||||
MvpPre.getMessagetitle(type, page + "", "10");
|
||||
}
|
||||
});
|
||||
mBinding.recycleView.setLayoutManager(new LinearLayoutManager(this));
|
||||
mAdapter = new BaseQuickAdapter<NewsMessageList, BaseViewHolder>(R.layout.news_rv_item_system_news) {
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, NewsMessageList item) {
|
||||
String time = TimeUtils.getDateToStringNoZ(Long.parseLong(item.getCreatetime()) * 1000L);
|
||||
helper.setText(R.id.tv_sys_time, time);
|
||||
if (item.getImage()==null || item.getImage().isEmpty()){
|
||||
helper.getView(R.id.tv_sys_con).setVisibility(VISIBLE);
|
||||
helper.setText(R.id.tv_sys_con, item.getContent());
|
||||
helper.getView(R.id.ll_system_official).setVisibility(GONE);
|
||||
}else {
|
||||
helper.getView(R.id.tv_sys_con).setVisibility(GONE);
|
||||
helper.getView(R.id.ll_system_official).setVisibility(VISIBLE);
|
||||
ImageUtils.loadHeadCC(item.getImage(), helper.getView(R.id.image));
|
||||
helper.setText(R.id.tv_cont, Html.fromHtml(item.getContent()));
|
||||
}
|
||||
helper.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (item.getRoom_id()>0){
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), item.getRoom_id()+"","",null);
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("roomId", item.getRoom_id() + "").navigation();
|
||||
}else if (item.getRoom_id() == 0 && item.getUrl() != null && !item.getUrl().isEmpty()){
|
||||
Intent intent = new Intent(OfficialNoticeActivity.this, WebViewActivity.class);
|
||||
intent.putExtra("url", item.getUrl());
|
||||
startActivity(intent);
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", item.getUrl()).navigation();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// if (item.getType().equals("1")) {
|
||||
// helper.getView(R.id.ll_system_official).setVisibility(GONE);
|
||||
// } else if (item.getType().equals("2")) {
|
||||
// helper.getView(R.id.tv_sys_con).setVisibility(GONE);
|
||||
// helper.getView(R.id.ll_system_official).setVisibility(VISIBLE);
|
||||
// } else {
|
||||
// helper.getView(R.id.ll_system_official).setVisibility(GONE);
|
||||
// }
|
||||
|
||||
// helper.getView(R.id.image).setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
};
|
||||
mBinding.recycleView.setAdapter(mAdapter);
|
||||
MvpPre.getMessagetitle(type, "1", "10");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_official_notice;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NewsPresenter bindPresenter() {
|
||||
return new NewsPresenter(this, this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void showNews(List<NewsMessageList> newsList) {
|
||||
mAdapter.setNewData(newsList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishRefresh() {
|
||||
mBinding.smartRefreshLayout.finishRefresh();
|
||||
mBinding.smartRefreshLayout.finishLoadMore();
|
||||
}
|
||||
}
|
||||
@@ -1,534 +0,0 @@
|
||||
package com.xscm.moduleutil.base;
|
||||
|
||||
import static android.app.PendingIntent.getActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.core.app.ActivityOptionsCompat;
|
||||
|
||||
import com.alibaba.android.arouter.facade.Postcard;
|
||||
import com.alibaba.android.arouter.facade.callback.NavCallback;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.ActivityUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.room.RoomInfoResp;
|
||||
import com.xscm.moduleutil.bean.room.RoomOnline;
|
||||
import com.xscm.moduleutil.bean.room.RoomOnlineBean;
|
||||
import com.xscm.moduleutil.event.RoomOutEvent;
|
||||
import com.xscm.moduleutil.http.BaseObserver;
|
||||
import com.xscm.moduleutil.http.RetrofitClient;
|
||||
import com.xscm.moduleutil.listener.MessageListenerSingleton;
|
||||
import com.xscm.moduleutil.rtc.AgoraManager;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.utils.logger.Logger;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 房间管理器
|
||||
* 统一处理房间数据获取、进入房间和退出房间的逻辑
|
||||
*/
|
||||
public class RoomManager {
|
||||
private static final String TAG = "RoomManager";
|
||||
|
||||
private static RoomManager instance;
|
||||
|
||||
// 房间数据缓存
|
||||
private Map<String, RoomInfoResp> roomDataCache = new ConcurrentHashMap<>();
|
||||
private Map<String, Long> cacheTimestamps = new ConcurrentHashMap<>();
|
||||
|
||||
// 缓存有效期(5分钟)
|
||||
private static final long CACHE_DURATION = 5 * 60 * 1000;
|
||||
|
||||
private RoomManager() {
|
||||
}
|
||||
|
||||
public static synchronized RoomManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new RoomManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入房间 - 自动获取房间数据
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
*/
|
||||
public void enterRoom(Context context, String roomId) {
|
||||
enterRoom(context, roomId, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入房间 - 使用密码
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
*/
|
||||
public void enterRoom(Context context, String roomId, String password) {
|
||||
enterRoom(context, roomId, password, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入房间 - 使用缓存数据
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
* @param cachedData 缓存的房间数据
|
||||
*/
|
||||
public void enterRoom(Context context, String roomId, String password, RoomInfoResp cachedData) {
|
||||
if (TextUtils.isEmpty(roomId)) {
|
||||
ToastUtils.showShort("房间ID不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否有有效的缓存数据
|
||||
RoomInfoResp roomInfo = cachedData != null ? cachedData : getCachedRoomData(roomId);
|
||||
|
||||
if (roomInfo != null) {
|
||||
// 使用缓存数据直接进入房间
|
||||
navigateToRoom(context, roomId, password, roomInfo, false,null);
|
||||
} else {
|
||||
// 获取房间数据后进入房间
|
||||
fetchRoomDataAndEnter(context, roomId, password,null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取房间数据并进入房间
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
*/
|
||||
public void fetchRoomDataAndEnter(Context context, String roomId, String password,String taskId) {
|
||||
// 显示加载提示
|
||||
// 这里可以根据需要添加加载对话框
|
||||
if (CommonAppContext.getInstance().isRoomJoininj){
|
||||
return;
|
||||
}
|
||||
|
||||
CommonAppContext.getInstance().isRoomJoininj=true;
|
||||
// 检查是否有有效的缓存数据
|
||||
RoomInfoResp roomInfo = getCachedRoomData(roomId);
|
||||
// 检查是否是当前房间且用户在线
|
||||
// boolean isCurrentRoom = isCurrentRoom(roomId);
|
||||
if (CommonAppContext.getInstance().playId == null) {
|
||||
fetchAndJoinRoom(context, roomId, password,taskId);
|
||||
} else {
|
||||
if (!CommonAppContext.getInstance().playId.equals(roomId)) {
|
||||
MessageListenerSingleton.getInstance().joinGroup(roomId);
|
||||
exitRoom(CommonAppContext.getInstance().playId);
|
||||
CommonAppContext.getInstance().isShow = false;
|
||||
CommonAppContext.getInstance().isPlaying = false;
|
||||
CommonAppContext.getInstance().isRoomJoininj=false;
|
||||
EventBus.getDefault().post(new RoomOutEvent());
|
||||
// fetchAndJoinRoom(context, roomId, password);
|
||||
// return;
|
||||
} else if (CommonAppContext.getInstance().lable_id.equals("6")) {
|
||||
upInfo(context, roomId, password, true, roomInfo, true,taskId);
|
||||
return;
|
||||
}
|
||||
isUserOnline(context, roomId, password, roomInfo,taskId);
|
||||
|
||||
}
|
||||
|
||||
// try {
|
||||
// Thread.sleep(1000);
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
|
||||
// 如果是当前房间且用户在线,直接跳转到房间页面,仅更新数据
|
||||
|
||||
|
||||
// // 获取房间数据
|
||||
// MessageListenerSingleton.getInstance().joinGroup(roomId);
|
||||
// // 等待一段时间确保退出完成
|
||||
// try {
|
||||
// Thread.sleep(500);
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
// RetrofitClient.getInstance().roomGetIn(roomId, password, new BaseObserver<RoomInfoResp>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onSubscribe(Disposable d) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(RoomInfoResp resp) {
|
||||
// String appId = CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId();
|
||||
// String token = resp.getUser_info().getAgora_token(); // 如果启用了鉴权才需要
|
||||
// String roomId = resp.getRoom_info().getRoom_id(); // 房间 ID
|
||||
// String rtm_token=resp.getUser_info().getAgora_rtm_token();
|
||||
// SpUtil.setRtmToken(rtm_token);
|
||||
// int uid = SpUtil.getUserId(); // 0 表示由 Agora 自动生成 UID
|
||||
// boolean enableMic = false; // 是否开启麦克风
|
||||
// boolean enableJs=false; // 是否开启角色
|
||||
// if (resp.getUser_info().getPit_number()!=0){
|
||||
// enableJs=true;
|
||||
// }
|
||||
// LogUtils.e("token",token);
|
||||
// LogUtils.e("roomId:",roomId);
|
||||
//// 初始化 Agora 并加入房间
|
||||
// AgoraManager.getInstance(context)
|
||||
// .joinRoom(token, roomId, uid, enableMic,enableJs);
|
||||
// cacheRoomData(roomId, resp);
|
||||
// navigateToRoom(context, roomId, password, resp);
|
||||
// }
|
||||
// });
|
||||
|
||||
// 临时实现 - 直接跳转(因为缺少具体的网络请求代码)
|
||||
// navigateToRoom(context, roomId, password, null);
|
||||
}
|
||||
|
||||
private void upInfo(Context context, String roomId, String password, boolean isOnline, RoomInfoResp roomInfo, boolean isCurrentRoom,String taskId) {
|
||||
|
||||
|
||||
if (isOnline) {
|
||||
RetrofitClient.getInstance().postRoomInfo(roomId, new BaseObserver<RoomInfoResp>() {
|
||||
|
||||
@Override
|
||||
public void onSubscribe(@NotNull Disposable disposable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NotNull RoomInfoResp roomInfoResp) {
|
||||
navigateToRoom(context, roomId, password, roomInfoResp, false,taskId);
|
||||
}
|
||||
});
|
||||
// navigateToRoom(context, roomId, password, roomInfo, isOnline);
|
||||
} else {
|
||||
fetchAndJoinRoom(context, roomId, password,taskId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新的房间数据并加入房间
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
*/
|
||||
private void fetchAndJoinRoom(Context context, String roomId, String password,String taskId) {
|
||||
// 获取房间数据
|
||||
|
||||
// 等待一段时间确保退出完成
|
||||
// try {
|
||||
// Thread.sleep(50);
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
// navigateToRoom(context, roomId, password, null, false);
|
||||
RetrofitClient.getInstance().roomGetIn(roomId, password, new BaseObserver<RoomInfoResp>() {
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(RoomInfoResp resp) {
|
||||
String appId = CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId();
|
||||
String token = resp.getUser_info().getAgora_token(); // 如果启用了鉴权才需要
|
||||
String roomId = resp.getRoom_info().getRoom_id(); // 房间 ID
|
||||
String rtm_token = resp.getUser_info().getAgora_rtm_token();
|
||||
SpUtil.setRtmToken(rtm_token);
|
||||
int uid = SpUtil.getUserId(); // 0 表示由 Agora 自动生成 UID
|
||||
boolean enableMic = false; // 是否开启麦克风
|
||||
boolean enableJs = false; // 是否开启角色
|
||||
if (resp.getUser_info().getPit_number() != 0) {
|
||||
enableJs = true;
|
||||
}
|
||||
LogUtils.e("token", token);
|
||||
LogUtils.e("roomId:", roomId);
|
||||
// 初始化 Agora 并加入房间
|
||||
AgoraManager.getInstance(context)
|
||||
.joinRoom(token, roomId, uid, enableMic, enableJs);
|
||||
cacheRoomData(roomId, resp);
|
||||
navigateToRoom(context, roomId, password, resp, false,taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否是当前房间
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @return true表示是当前房间,false表示不是
|
||||
*/
|
||||
private boolean isCurrentRoom(String roomId) {
|
||||
// 这里应该实现检查是否是当前房间的逻辑
|
||||
// 可以通过检查当前Activity或者通过全局变量等方式实现
|
||||
// 目前返回false,需要根据实际需求实现具体逻辑
|
||||
|
||||
RoomInfoResp roomInfo = getCachedRoomData(roomId);
|
||||
if (roomInfo != null) {
|
||||
if (roomInfo.getRoom_info().getRoom_id().equals(roomId)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到房间页面
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
* @param roomInfo 房间信息
|
||||
*/
|
||||
private void navigateToRoom(Context context, String roomId, String password, RoomInfoResp roomInfo, boolean isOnline,String taskId) {
|
||||
|
||||
try {
|
||||
// 构建跳转参数
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("roomId", roomId);
|
||||
bundle.putBoolean("isOnline", isOnline);
|
||||
bundle.putSerializable("roomInfo", roomInfo);
|
||||
if (!TextUtils.isEmpty(password)) {
|
||||
bundle.putString("password", password);
|
||||
}
|
||||
if (taskId != null){
|
||||
bundle.putString("taskId", taskId);
|
||||
}
|
||||
|
||||
if (roomInfo == null){
|
||||
LogUtils.dTag("RoomActivity", "navigateToRoom:房间信息获取存在问题");
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用ARouter跳转到房间页面
|
||||
ARouter.getInstance()
|
||||
.build(ARouteConstants.ROOM_DETAILS)
|
||||
.with(bundle)
|
||||
.navigation(context);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "跳转房间页面失败: " + e.getMessage());
|
||||
}finally {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存房间数据
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @param roomInfo 房间信息
|
||||
*/
|
||||
public void cacheRoomData(String roomId, RoomInfoResp roomInfo) {
|
||||
|
||||
if (TextUtils.isEmpty(roomId) || roomInfo == null) {
|
||||
return;
|
||||
}
|
||||
// 清除所有现有的缓存数据
|
||||
roomDataCache.clear();
|
||||
cacheTimestamps.clear();
|
||||
roomDataCache.put(roomId, roomInfo);
|
||||
cacheTimestamps.put(roomId, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的房间数据
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @return 房间信息,如果缓存无效则返回null
|
||||
*/
|
||||
public RoomInfoResp getCachedRoomData(String roomId) {
|
||||
if (TextUtils.isEmpty(roomId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long timestamp = cacheTimestamps.get(roomId);
|
||||
if (timestamp == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查缓存是否过期
|
||||
if (System.currentTimeMillis() - timestamp > CACHE_DURATION) {
|
||||
// 缓存过期,清除数据
|
||||
roomDataCache.remove(roomId);
|
||||
cacheTimestamps.remove(roomId);
|
||||
return null;
|
||||
}
|
||||
|
||||
return roomDataCache.get(roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否在线
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @return true表示用户在线,false表示不在线
|
||||
*/
|
||||
private boolean isUserOnline(Context context, String roomId, String password, RoomInfoResp roomInfo,String taskId) {
|
||||
// 这里应该实现检查用户是否在线的逻辑
|
||||
// 可以通过检查Agora是否还在房间中,或者通过服务端接口查询用户状态等方式实现
|
||||
// 目前返回false,需要根据实际需求实现具体逻辑
|
||||
// boolean isCurrentRoom=isCurrentRoom(roomId);
|
||||
// try {
|
||||
// Thread.sleep(300);
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
final boolean[] isOnline = {false};
|
||||
RetrofitClient.getInstance().getRoomOnline(roomId, "1", "50", new BaseObserver<RoomOnline>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(RoomOnline roomOnline) {
|
||||
try {
|
||||
if (roomOnline != null) {
|
||||
if (roomOnline.getOn_pit() != null) {
|
||||
for (RoomOnlineBean roomOnlineBean : roomOnline.getOn_pit()) {
|
||||
if (roomOnlineBean.getUser_id() == SpUtil.getUserId()) {
|
||||
isOnline[0] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (roomOnline.getOff_pit() != null) {
|
||||
for (RoomOnlineBean roomOnlineBean : roomOnline.getOff_pit()) {
|
||||
if (roomOnlineBean.getUser_id() == SpUtil.getUserId()) {
|
||||
isOnline[0] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
|
||||
} else {
|
||||
isOnline[0] = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 捕获所有可能的异常,避免崩溃
|
||||
e.printStackTrace();
|
||||
isOnline[0] = false;
|
||||
// 即使出现异常也继续执行
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定房间的缓存数据
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
*/
|
||||
public void clearRoomCache(String roomId) {
|
||||
if (!TextUtils.isEmpty(roomId)) {
|
||||
roomDataCache.remove(roomId);
|
||||
cacheTimestamps.remove(roomId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有房间缓存数据
|
||||
*/
|
||||
public void clearAllRoomCache() {
|
||||
roomDataCache.clear();
|
||||
cacheTimestamps.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出房间
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
*/
|
||||
public void exitRoom(String roomId) {
|
||||
// 清除该房间的缓存数据
|
||||
clearRoomCache(roomId);
|
||||
|
||||
// 可以在这里添加其他退出房间的逻辑
|
||||
// 例如:通知服务器用户已退出、清理房间相关资源等
|
||||
|
||||
RetrofitClient.getInstance().quitRoom(roomId, SpUtil.getUserId() + "", new BaseObserver<String>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String s) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Logger.d(TAG, "退出房间: " + roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量退出房间
|
||||
*
|
||||
* @param roomIds 房间ID列表
|
||||
*/
|
||||
public void exitRooms(String... roomIds) {
|
||||
if (roomIds != null) {
|
||||
for (String roomId : roomIds) {
|
||||
exitRoom(roomId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取房间缓存状态
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @return 缓存状态信息
|
||||
*/
|
||||
public String getRoomCacheStatus(String roomId) {
|
||||
if (TextUtils.isEmpty(roomId)) {
|
||||
return "无效的房间ID";
|
||||
}
|
||||
|
||||
Long timestamp = cacheTimestamps.get(roomId);
|
||||
if (timestamp == null) {
|
||||
return "未缓存";
|
||||
}
|
||||
|
||||
long elapsed = System.currentTimeMillis() - timestamp;
|
||||
if (elapsed > CACHE_DURATION) {
|
||||
return "缓存已过期";
|
||||
}
|
||||
|
||||
RoomInfoResp data = roomDataCache.get(roomId);
|
||||
if (data == null) {
|
||||
return "缓存数据为空";
|
||||
}
|
||||
|
||||
return String.format("已缓存 (%d秒前)", elapsed / 1000);
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import static com.blankj.utilcode.util.ActivityUtils.startActivity;
|
||||
import static com.tencent.qcloud.network.sonar.utils.Utils.isNetworkAvailable;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.text.TextPaint;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.SpanUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.activity.WebViewActivity;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.databinding.DialogPolicBinding;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
|
||||
/**
|
||||
* 隐私协议
|
||||
*/
|
||||
public class PolicyDialog extends Dialog {
|
||||
private final DialogPolicBinding policBinding;
|
||||
private PolicyClickListener mPolicyClickListener;
|
||||
|
||||
public PolicyDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
policBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_polic, null, false);
|
||||
policBinding.setClick(new PolicyClickProxy());
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
setContentView(policBinding.getRoot());
|
||||
setCanceledOnTouchOutside(false);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
SpanUtils spanUtils = new SpanUtils();
|
||||
ClickableSpan clickSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
// Intent intent = new Intent(getContext(), WebViewActivity.class);
|
||||
// intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl()+"/api/Page/page_show?id=6");
|
||||
// intent.putExtra("title", "用户协议");
|
||||
// startActivity(intent);
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", "file:///android_asset/page_yongh.html").withString("title", "用户协议").navigation();
|
||||
|
||||
// 检查网络连接状态
|
||||
if (isNetworkAvailable(getContext())) {
|
||||
// 有网络时加载网络资源
|
||||
Intent intent = new Intent(getContext(), WebViewActivity.class);
|
||||
intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl()+"/api/Page/page_show?id=6");
|
||||
intent.putExtra("title", "用户协议");
|
||||
startActivity(intent);
|
||||
} else {
|
||||
// 无网络时加载本地资源
|
||||
ARouter.getInstance().build(ARouteConstants.H5)
|
||||
.withString("url", "file:///android_asset/page_yongh.html")
|
||||
.withString("title", "用户协议")
|
||||
.navigation();
|
||||
}
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl()+"/api/Page/page_show?id=6" ).withString("title", "用户协议").navigation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
ds.setColor(Color.parseColor("#FFFFD6A2"));
|
||||
ds.setUnderlineText(true);
|
||||
}
|
||||
};
|
||||
ClickableSpan ysClickSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
// Intent intent = new Intent(getContext(), WebViewActivity.class);
|
||||
// intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl()+"/api/Page/page_show?id=4");
|
||||
// intent.putExtra("title", "隐私协议");
|
||||
// startActivity(intent);
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", "file:///android_asset/page_show.html").withString("title", "隐私协议").navigation();
|
||||
if (isNetworkAvailable(getContext())) {
|
||||
Intent intent = new Intent(getContext(), WebViewActivity.class);
|
||||
intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl()+"/api/Page/page_show?id=4");
|
||||
intent.putExtra("title", "隐私协议");
|
||||
startActivity(intent);
|
||||
}else {
|
||||
ARouter.getInstance().build(ARouteConstants.H5).withString("url", "file:///android_asset/page_show.html").withString("title", "隐私协议").navigation();
|
||||
|
||||
}
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl()+"/api/Page/page_show?id=4").withString("title", "隐私协议").navigation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
ds.setColor(Color.parseColor("#FFFFD6A2"));
|
||||
ds.setUnderlineText(true);
|
||||
}
|
||||
};
|
||||
spanUtils.append("欢迎使用羽声语音!\n").append("在使用我们的产品和服务之前,请您先阅读并了解").append("《用户协议》").setClickSpan(clickSpan).append("和").append("《隐私协议》").setClickSpan(ysClickSpan).append("。我们将严格按照上述协议为" +
|
||||
"您提供服务,保护您的信息安全,点" +
|
||||
"击“同意”即表示您已阅读并同意全部" +
|
||||
"条款,可以继续使用我们的产品和服" +
|
||||
"务。");
|
||||
policBinding.tvText.setText(spanUtils.create());
|
||||
policBinding.tvText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public void setPolicyClickListener(PolicyClickListener policyClickListener) {
|
||||
this.mPolicyClickListener = policyClickListener;
|
||||
}
|
||||
|
||||
public class PolicyClickProxy {
|
||||
public void onAgreeClick() {
|
||||
if (mPolicyClickListener != null) {
|
||||
mPolicyClickListener.policyAgree();
|
||||
}
|
||||
}
|
||||
|
||||
public void onExit() {
|
||||
if (mPolicyClickListener != null) {
|
||||
mPolicyClickListener.policyExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface PolicyClickListener {
|
||||
void policyAgree();
|
||||
|
||||
void policyExit();
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.tencent.imsdk.v2.V2TIMConversation;
|
||||
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
import com.tencent.qcloud.tuicore.TUIConstants;
|
||||
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity;
|
||||
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIGroupChatActivity;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.base.RoomManager;
|
||||
import com.xscm.moduleutil.databinding.DialogRoomAuctionWebviewBinding;
|
||||
import com.xscm.moduleutil.databinding.WebViewDialogBinding;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.widget.dialog.BaseDialog;
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/9/24
|
||||
*@description: 这是拍卖房的规则界面
|
||||
*/
|
||||
public class RoomAuctionWebViewDialog extends BaseDialog<DialogRoomAuctionWebviewBinding> {
|
||||
|
||||
String mUrl;
|
||||
int type;//10:天空之境 11:岁月之城 12:时空之巅
|
||||
|
||||
public RoomAuctionWebViewDialog(@NonNull Context context, Bundle args) {
|
||||
super(context, R.style.BaseDialogStyleH);
|
||||
this.mUrl = args.getString("url");
|
||||
this.type = args.getInt("type");
|
||||
initData1();
|
||||
}
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (getWindow() != null) {
|
||||
// 获取屏幕尺寸
|
||||
android.util.DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
|
||||
// 设置高度为屏幕高度的80%
|
||||
android.view.WindowManager.LayoutParams params = getWindow().getAttributes();
|
||||
params.height = (int) (displayMetrics.heightPixels * 0.9);
|
||||
params.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
getWindow().setAttributes(params);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_room_auction_webview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(true);
|
||||
setCanceledOnTouchOutside(true);
|
||||
Window window = getWindow();
|
||||
assert window != null;
|
||||
window.setGravity(Gravity.BOTTOM);
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 320.f / 375), WindowManager.LayoutParams.MATCH_PARENT);
|
||||
mBinding.topBar.setTitle("规则");
|
||||
mBinding.topBar.getIvBack().setOnClickListener(v -> dismiss());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void initData1() {
|
||||
// WebSettings webSettings = mBinding.webView.getSettings();
|
||||
// webSettings.setUseWideViewPort(true);
|
||||
// webSettings.setLoadWithOverviewMode(true);
|
||||
// webSettings.setJavaScriptEnabled(true);
|
||||
// webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
|
||||
// //增加JSBridge
|
||||
// mBinding.webView.addJavascriptInterface(new WebAppInterface(getContext()), "Android");
|
||||
//// mBinding.webView.addJavascriptInterface(new WebViewBridgeConfig(title), WebViewBridgeConfig.NAME);
|
||||
// webSettings.setBuiltInZoomControls(false);
|
||||
// webSettings.setSupportZoom(false);
|
||||
// webSettings.setDomStorageEnabled(true);
|
||||
// webSettings.setBlockNetworkImage(false);//解决图片不显示
|
||||
// // 启用 WebView 内容的滚动
|
||||
// mBinding.webView.setVerticalScrollBarEnabled(true);
|
||||
// mBinding.webView.setScrollbarFadingEnabled(true);
|
||||
// webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
// webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
// mBinding.webView.setHorizontalScrollBarEnabled(false);//水平不显示
|
||||
// mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示
|
||||
// mBinding.webView.setWebViewClient(new WebViewClient());
|
||||
// mBinding.webView.setBackgroundColor(Color.TRANSPARENT);
|
||||
// mBinding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
//
|
||||
// mBinding.webView.requestFocus();
|
||||
// mBinding.webView.loadUrl(mUrl);
|
||||
|
||||
WebSettings webSettings = mBinding.webView.getSettings();
|
||||
webSettings.setUseWideViewPort(true);
|
||||
webSettings.setLoadWithOverviewMode(true);
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
|
||||
//增加JSBridge
|
||||
mBinding.webView.addJavascriptInterface(new WebAppInterface(getContext()), "Android");
|
||||
// mBinding.webView.addJavascriptInterface(new WebViewBridgeConfig(title), WebViewBridgeConfig.NAME);
|
||||
webSettings.setBuiltInZoomControls(false);
|
||||
webSettings.setSupportZoom(false);
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
webSettings.setBlockNetworkImage(false);//解决图片不显示
|
||||
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
// 启用 WebView 内容的滚动,但隐藏滚动条
|
||||
mBinding.webView.setHorizontalScrollBarEnabled(false);//水平不显示
|
||||
mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示滚动条
|
||||
mBinding.webView.setWebViewClient(new WebViewClient());
|
||||
mBinding.webView.setBackgroundColor(Color.TRANSPARENT);
|
||||
mBinding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
|
||||
// 确保内容可以滚动
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
|
||||
mBinding.webView.requestFocus();
|
||||
mBinding.webView.loadUrl(mUrl);
|
||||
}
|
||||
|
||||
private Resources getResources() {
|
||||
return getContext().getResources();
|
||||
}
|
||||
|
||||
public class WebAppInterface {
|
||||
Context mContext;
|
||||
|
||||
WebAppInterface(Context c) {
|
||||
mContext = c;
|
||||
}
|
||||
|
||||
// 被 H5 调用的方法
|
||||
@JavascriptInterface
|
||||
public void showToast(String toast) {
|
||||
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void closeWeb() {
|
||||
LogUtils.e("value: ");
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void customerService() {
|
||||
String appId = CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId(); // 填移动应用(App)的 AppId
|
||||
IWXAPI api = WXAPIFactory.createWXAPI(mContext, appId);
|
||||
|
||||
// 判断当前版本是否支持拉起客服会话
|
||||
WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req();
|
||||
req.corpId = "ww1de4300858c0b461"; // 企业ID
|
||||
req.url = "https://work.weixin.qq.com/kfid/kfcb3d23a59c188a0e7"; // 客服URL
|
||||
api.sendReq(req);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"",null);
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void jumpWebPage(String objects) {
|
||||
// ARouter.getInstance().build(ARouteConstants.USER_HOME_PAGE).navigation();
|
||||
ARouter.getInstance().build(ARouteConstants.USER_HOME_PAGE).withString("userId", objects).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void enterGroupChat(String group_id,String cover,String guild_name) {
|
||||
Intent intent = new Intent(mContext, TUIGroupChatActivity.class);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_ID, group_id);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_GROUP);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void chatWithUser(String user_id,String nickname) {
|
||||
Intent intent = new Intent(mContext, TUIC2CChatActivity.class);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_ID, user_id);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_C2C);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void exchange(){
|
||||
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void Withdrawal() {
|
||||
ARouter.getInstance().build(ARouteConstants.WITHDRAWAL_ACTIVITY).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void enterAuthent() {//实名认证
|
||||
ARouter.getInstance().build(ARouteConstants.REAL_NAME_ACTIVITY2).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void Recharge(){
|
||||
ARouter.getInstance().build(ARouteConstants.RECHARGE_ACTIVITY).navigation();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,243 +0,0 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.base.RoomManager;
|
||||
import com.xscm.moduleutil.databinding.WebViewDialogBinding;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.widget.dialog.BaseDialog;
|
||||
import com.tencent.imsdk.v2.V2TIMConversation;
|
||||
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
import com.tencent.qcloud.tuicore.TUIConstants;
|
||||
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity;
|
||||
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIGroupChatActivity;
|
||||
|
||||
/**
|
||||
* @Author lxj$
|
||||
* @Time 2025-8-8 09:20:18$ $
|
||||
* @Description 弹窗webview$
|
||||
*/
|
||||
public class WebViewDialog extends BaseDialog<WebViewDialogBinding> {
|
||||
|
||||
String mUrl;
|
||||
int type;//10:天空之境 11:岁月之城 12:时空之巅
|
||||
|
||||
public WebViewDialog(@NonNull Context context, Bundle args) {
|
||||
super(context, R.style.BaseDialogStyleH);
|
||||
this.mUrl = args.getString("url");
|
||||
this.type = args.getInt("type");
|
||||
initData1();
|
||||
}
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (getWindow() != null) {
|
||||
// 获取屏幕尺寸
|
||||
android.util.DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
|
||||
// 设置高度为屏幕高度的80%
|
||||
android.view.WindowManager.LayoutParams params = getWindow().getAttributes();
|
||||
params.height = (int) (displayMetrics.heightPixels * 0.9);
|
||||
params.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
getWindow().setAttributes(params);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.web_view_dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(true);
|
||||
setCanceledOnTouchOutside(true);
|
||||
Window window = getWindow();
|
||||
assert window != null;
|
||||
window.setGravity(Gravity.BOTTOM);
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 320.f / 375), WindowManager.LayoutParams.MATCH_PARENT);
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
|
||||
if (type==10){
|
||||
mBinding.gzCl.setBackgroundResource(R.mipmap.tkzj);
|
||||
mBinding.imGz.setImageResource(R.mipmap.tkzj_gz);
|
||||
mBinding.webView.setPadding(16, 0, 16, 0);
|
||||
}else if (type==11){
|
||||
mBinding.gzCl.setBackgroundResource(R.mipmap.syzc);
|
||||
mBinding.imGz.setImageResource(R.mipmap.syzc_gz);
|
||||
}else if (type==12){
|
||||
mBinding.gzCl.setBackgroundResource(R.mipmap.skzj);
|
||||
mBinding.imGz.setImageResource(R.mipmap.skzj_gz);
|
||||
}else if (type==13){
|
||||
mBinding.gzCl.setBackgroundResource(R.mipmap.xlh);
|
||||
mBinding.imGz.setImageResource(R.mipmap.xlh_gz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void initData1() {
|
||||
// WebSettings webSettings = mBinding.webView.getSettings();
|
||||
// webSettings.setUseWideViewPort(true);
|
||||
// webSettings.setLoadWithOverviewMode(true);
|
||||
// webSettings.setJavaScriptEnabled(true);
|
||||
// webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
|
||||
// //增加JSBridge
|
||||
// mBinding.webView.addJavascriptInterface(new WebAppInterface(getContext()), "Android");
|
||||
//// mBinding.webView.addJavascriptInterface(new WebViewBridgeConfig(title), WebViewBridgeConfig.NAME);
|
||||
// webSettings.setBuiltInZoomControls(false);
|
||||
// webSettings.setSupportZoom(false);
|
||||
// webSettings.setDomStorageEnabled(true);
|
||||
// webSettings.setBlockNetworkImage(false);//解决图片不显示
|
||||
// // 启用 WebView 内容的滚动
|
||||
// mBinding.webView.setVerticalScrollBarEnabled(true);
|
||||
// mBinding.webView.setScrollbarFadingEnabled(true);
|
||||
// webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
// webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
// mBinding.webView.setHorizontalScrollBarEnabled(false);//水平不显示
|
||||
// mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示
|
||||
// mBinding.webView.setWebViewClient(new WebViewClient());
|
||||
// mBinding.webView.setBackgroundColor(Color.TRANSPARENT);
|
||||
// mBinding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
//
|
||||
// mBinding.webView.requestFocus();
|
||||
// mBinding.webView.loadUrl(mUrl);
|
||||
|
||||
WebSettings webSettings = mBinding.webView.getSettings();
|
||||
webSettings.setUseWideViewPort(true);
|
||||
webSettings.setLoadWithOverviewMode(true);
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
|
||||
//增加JSBridge
|
||||
mBinding.webView.addJavascriptInterface(new WebAppInterface(getContext()), "Android");
|
||||
// mBinding.webView.addJavascriptInterface(new WebViewBridgeConfig(title), WebViewBridgeConfig.NAME);
|
||||
webSettings.setBuiltInZoomControls(false);
|
||||
webSettings.setSupportZoom(false);
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
webSettings.setBlockNetworkImage(false);//解决图片不显示
|
||||
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
// 启用 WebView 内容的滚动,但隐藏滚动条
|
||||
mBinding.webView.setHorizontalScrollBarEnabled(false);//水平不显示
|
||||
mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示滚动条
|
||||
mBinding.webView.setWebViewClient(new WebViewClient());
|
||||
mBinding.webView.setBackgroundColor(Color.TRANSPARENT);
|
||||
mBinding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
|
||||
// 确保内容可以滚动
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
|
||||
mBinding.webView.requestFocus();
|
||||
mBinding.webView.loadUrl(mUrl);
|
||||
}
|
||||
|
||||
private Resources getResources() {
|
||||
return getContext().getResources();
|
||||
}
|
||||
|
||||
public class WebAppInterface {
|
||||
Context mContext;
|
||||
|
||||
WebAppInterface(Context c) {
|
||||
mContext = c;
|
||||
}
|
||||
|
||||
// 被 H5 调用的方法
|
||||
@JavascriptInterface
|
||||
public void showToast(String toast) {
|
||||
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void closeWeb() {
|
||||
LogUtils.e("value: ");
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void customerService() {
|
||||
String appId = CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId(); // 填移动应用(App)的 AppId
|
||||
IWXAPI api = WXAPIFactory.createWXAPI(mContext, appId);
|
||||
|
||||
// 判断当前版本是否支持拉起客服会话
|
||||
WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req();
|
||||
req.corpId = "ww1de4300858c0b461"; // 企业ID
|
||||
req.url = "https://work.weixin.qq.com/kfid/kfcb3d23a59c188a0e7"; // 客服URL
|
||||
api.sendReq(req);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"",null);
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void jumpWebPage(String objects) {
|
||||
// ARouter.getInstance().build(ARouteConstants.USER_HOME_PAGE).navigation();
|
||||
ARouter.getInstance().build(ARouteConstants.USER_HOME_PAGE).withString("userId", objects).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void enterGroupChat(String group_id,String cover,String guild_name) {
|
||||
Intent intent = new Intent(mContext, TUIGroupChatActivity.class);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_ID, group_id);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_GROUP);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void chatWithUser(String user_id,String nickname) {
|
||||
Intent intent = new Intent(mContext, TUIC2CChatActivity.class);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_ID, user_id);
|
||||
intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_C2C);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void exchange(){
|
||||
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void Withdrawal() {
|
||||
ARouter.getInstance().build(ARouteConstants.WITHDRAWAL_ACTIVITY).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void enterAuthent() {//实名认证
|
||||
ARouter.getInstance().build(ARouteConstants.REAL_NAME_ACTIVITY2).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void Recharge(){
|
||||
ARouter.getInstance().build(ARouteConstants.RECHARGE_ACTIVITY).navigation();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.activity.WebViewActivity;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.bean.TeenagerInfo;
|
||||
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
||||
import com.xscm.moduleutil.databinding.IndexDialogYouthModelBinding;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.widget.dialog.BaseDialog;
|
||||
|
||||
/**
|
||||
* 描述 describe 青少年模式弹窗
|
||||
*/
|
||||
public class YouthModelDialog extends BaseDialog<IndexDialogYouthModelBinding> {
|
||||
private TeenagerInfo teenagerInfo;
|
||||
|
||||
public YouthModelDialog(@NonNull Context context, TeenagerInfo teenagerInfo) {
|
||||
super(context);
|
||||
this.teenagerInfo = teenagerInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.index_dialog_youth_model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(false);
|
||||
setCanceledOnTouchOutside(false);
|
||||
Window window = getWindow();
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 315.f / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
mBinding.tvIKnow.setOnClickListener(v -> {
|
||||
|
||||
ARouter.getInstance().build(ARouteConstants.UNDERAGE_ACTIVITY).withInt("type", 0).navigation();
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/feedback/teenage?id=" + SpUtil.getToken()).navigation();
|
||||
// dismiss();
|
||||
});
|
||||
mBinding.tvOpen.setOnClickListener(v -> {
|
||||
// if (teenagerInfo.getHad_password() == 1) {
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.SET_YOUTH_PWD_ACTIVITY).withInt("type", SetYouthPasswordActivity.TYPE_OPEN).navigation();
|
||||
// } else {
|
||||
// ARouter.getInstance().build(ARouteConstants.SET_YOUTH_PWD_ACTIVITY).withInt("type", SetYouthPasswordActivity.SET_TYPE).navigation();
|
||||
// }
|
||||
|
||||
Intent intent = new Intent(getContext(), WebViewActivity.class);
|
||||
intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/feedback/teenage?id=" + SpUtil.getToken());
|
||||
getContext().startActivity(intent);
|
||||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/feedback/teenage?id=" + SpUtil.getToken()).navigation();
|
||||
dismiss();
|
||||
});
|
||||
|
||||
ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.tvIKnow, ColorManager.getInstance().getPrimaryColorInt(), 53);
|
||||
mBinding.tvIKnow.setTextColor(ColorManager.getInstance().getButtonColorInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
public void setTeenagerInfo(TeenagerInfo teenagerInfo) {
|
||||
this.teenagerInfo = teenagerInfo;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -51,11 +51,11 @@ public class EnvironmentPrefs {
|
||||
// }
|
||||
|
||||
// 默认使用生产环境
|
||||
String envName = sharedPreferences.getString(KEY_ENV, EnvironmentEnum.PRODUCTION.name());
|
||||
String envName = sharedPreferences.getString(KEY_ENV, EnvironmentEnum.TEST.name());
|
||||
try {
|
||||
return EnvironmentEnum.valueOf(envName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return EnvironmentEnum.PRODUCTION; // 出错时默认返回生产环境
|
||||
return EnvironmentEnum.TEST; // 出错时默认返回生产环境
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
package com.xscm.moduleutil.widget.dialog;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static com.blankj.utilcode.util.ActivityUtils.startActivity;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.blankj.utilcode.util.ImageUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.activity.WebViewActivity;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.bean.CircleListBean;
|
||||
import com.xscm.moduleutil.databinding.RoomDialogShareBinding;
|
||||
import com.xscm.moduleutil.utils.BaseBottomSheetDialog;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.utils.wx.WeChatShareUtils;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
|
||||
|
||||
|
||||
/**
|
||||
* 房间分享弹窗
|
||||
*/
|
||||
public class ShareDialog extends BaseBottomSheetDialog<RoomDialogShareBinding> {
|
||||
public WeChatShareUtils weChatShareUtils;
|
||||
private Context mContext;
|
||||
private String mcontent;
|
||||
private String murl;
|
||||
private String ids;
|
||||
private int types;//1:用户 2:房间;3:动态
|
||||
private String mUserId;
|
||||
private CircleListBean bean;
|
||||
|
||||
public interface OnShareDataListener {
|
||||
void onShareDataLoaded(String id);
|
||||
}
|
||||
|
||||
private OnShareDataListener listener;
|
||||
|
||||
public void setOnShareDataListener(OnShareDataListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private static final String TAG = "ShareDialog";
|
||||
|
||||
public ShareDialog(Context context, String content, String url, String id, int type,String userId,CircleListBean bean) {
|
||||
super(context);
|
||||
this.mcontent = content;
|
||||
this.murl = url;
|
||||
this.mContext = getContext();
|
||||
this.ids = id;
|
||||
this.types = type;
|
||||
this.mUserId = userId;
|
||||
this.bean = bean;
|
||||
Log.i(TAG, "(Start)启动了===========================ShareDialog");
|
||||
iniv();
|
||||
}
|
||||
|
||||
private void iniv() {
|
||||
if (types == 1) {//1是分享动态
|
||||
|
||||
} else if (types == 2) {//分享相册
|
||||
mBinding.tvQq.setVisibility(GONE);
|
||||
mBinding.tvQqq.setVisibility(GONE);
|
||||
mBinding.rl.setVisibility(GONE);
|
||||
}else if (types == 4){
|
||||
mBinding.tvJub.setVisibility(GONE);
|
||||
mBinding.tvCopy.setVisibility(GONE);
|
||||
}
|
||||
if (mUserId.equals(SpUtil.getUserId()+"")){
|
||||
mBinding.shanc.setVisibility(VISIBLE);
|
||||
}else {
|
||||
mBinding.shanc.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayout() {
|
||||
return R.layout.room_dialog_share;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
Window window = getWindow();
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.dimAmount = 0.4f;
|
||||
window.setAttributes(lp);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||
window.setGravity(Gravity.BOTTOM);
|
||||
mBinding.tvQq.setOnClickListener(this::onClick);
|
||||
mBinding.tvWx.setOnClickListener(this::onClick);
|
||||
mBinding.tvWxq.setOnClickListener(this::onClick);
|
||||
mBinding.tvQqq.setOnClickListener(this::onClick);
|
||||
mBinding.tvClean.setOnClickListener(this::onClick);
|
||||
mBinding.tvCopy.setOnClickListener(this::onClick);
|
||||
mBinding.tvJub.setOnClickListener(this::onClick);
|
||||
mBinding.shanc.setOnClickListener(this::onClick);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
weChatShareUtils = WeChatShareUtils.getInstance(getContext());
|
||||
// if (mUserId.equals(SpUtil.getUserId()+"")){
|
||||
// mBinding.shanc.setVisibility(GONE);
|
||||
// }else {
|
||||
// mBinding.shanc.setVisibility(VISIBLE);
|
||||
// }
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
// String appName = CommonAppContext.getInstance().getResources().getString(R.string.app_name);
|
||||
|
||||
|
||||
if (R.id.tv_qq == id) {
|
||||
// AppLogUtil.reportAppLog(AppLogEvent.D0108, "share_way", "QQ分享");
|
||||
// ShareUtil.shareWeb((Activity) view.getContext(), URLConstants.SHARE, String.format("我在%s玩呢,大家都在玩,快来展示您的精彩", appName)
|
||||
// , appName, "", R.mipmap.ic_launcher_new, SHARE_MEDIA.QQ);
|
||||
} else if (R.id.tv_wx == id) {
|
||||
// AppLogUtil.reportAppLog(AppLogEvent.D0108, "share_way", "微信分享");
|
||||
// ShareUtil.shareWeb((Activity) view.getContext(), URLConstants.SHARE, String.format("我在%s玩呢,大家都在玩,快来展示您的精彩", appName)
|
||||
// , appName, "", R.mipmap.ic_launcher_new, SHARE_MEDIA.WEIXIN);
|
||||
fun_handleShare(SendMessageToWX.Req.WXSceneSession);
|
||||
} else if (R.id.tv_wxq == id) {
|
||||
fun_handleShare1(SendMessageToWX.Req.WXSceneTimeline);
|
||||
} else if (R.id.tv_qqq == id) {
|
||||
|
||||
} else if (R.id.shanc == id) {
|
||||
if (listener != null) {
|
||||
listener.onShareDataLoaded(ids);
|
||||
}
|
||||
} else if (R.id.tv_jub == id) {
|
||||
if (types == 3) {
|
||||
Intent intent = new Intent(getContext(), WebViewActivity.class);
|
||||
intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url()+"/web/index.html#/pages/feedback/report?id=" + SpUtil.getToken() + "&fromType=" + types + "&fromId=" + bean.getId());
|
||||
intent.putExtra("title", "举报");
|
||||
startActivity(intent);
|
||||
}else if (types == 1){
|
||||
Intent intent = new Intent(getContext(), WebViewActivity.class);
|
||||
intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url()+"/web/index.html#/pages/feedback/report?id=" + SpUtil.getToken() + "&fromType=" + types + "&fromId=" + bean.getUser_id());
|
||||
intent.putExtra("title", "举报");
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
} else if (R.id.tv_copy == id) {
|
||||
ClipboardManager clipboard = (ClipboardManager)mContext.getSystemService( Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("链接",bean.getShare_url() );
|
||||
if (clipboard != null) {
|
||||
clipboard.setPrimaryClip(clip);
|
||||
com.hjq.toast.ToastUtils.show("复制成功");
|
||||
} else {
|
||||
com.hjq.toast.ToastUtils.show("复制失败");
|
||||
}
|
||||
}
|
||||
|
||||
dismiss();
|
||||
}
|
||||
|
||||
// todo fun_handleShare 分享小程序类型 (只支持分享给微信好友)
|
||||
private void fun_handleShare(int scene) {
|
||||
if (weChatShareUtils.isSupportWX()) {
|
||||
String appName = mContext.getPackageManager().getApplicationLabel(mContext.getApplicationInfo()).toString();
|
||||
if (types == 2){
|
||||
com.xscm.moduleutil.utils.ImageUtils.loadBitmap(murl, new com.xscm.moduleutil.utils.ImageUtils.onLoadBitmap() {
|
||||
@Override
|
||||
public void onReady(Bitmap resource) {
|
||||
weChatShareUtils.sharePic(resource, scene);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
String shortContent = mcontent.length() > 20 ? mcontent.substring(0, 20) : mcontent;
|
||||
String desc = shortContent;
|
||||
String title = appName;
|
||||
String url = murl;
|
||||
Bitmap bitmap = ImageUtils.drawable2Bitmap(mContext.getResources().getDrawable(R.mipmap.ic_launcher));
|
||||
weChatShareUtils.shareUrl(url, title, bitmap, desc, scene);
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showShort("手机上微信版本不支持分享功能");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void fun_handleShare1(int scene) {
|
||||
if (weChatShareUtils.isSupportWX()) {
|
||||
String appName = mContext.getPackageManager().getApplicationLabel(mContext.getApplicationInfo()).toString();
|
||||
if (types == 2) {
|
||||
com.xscm.moduleutil.utils.ImageUtils.loadBitmap(murl, new com.xscm.moduleutil.utils.ImageUtils.onLoadBitmap() {
|
||||
@Override
|
||||
public void onReady(Bitmap resource) {
|
||||
weChatShareUtils.sharePic(resource, scene);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
String shortContent = mcontent.length() > 20 ? mcontent.substring(0, 20) : mcontent;
|
||||
String desc = shortContent;
|
||||
String title = appName;
|
||||
String url = murl;
|
||||
// Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(),R.mipmap.ic_launcher);
|
||||
Bitmap bitmap = ImageUtils.drawable2Bitmap(mContext.getResources().getDrawable(R.mipmap.ic_launcher));
|
||||
weChatShareUtils.shareUrl(url, title, bitmap, desc, scene);
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showShort("手机上微信版本不支持分享功能");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user