1:修改BUG
This commit is contained in:
@@ -4,25 +4,25 @@ import static androidx.core.content.ContextCompat.getSystemService;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
@@ -44,15 +44,14 @@ 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.MqttBean;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.BackgroundManager;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.DialogUtils;
|
||||
import com.xscm.moduleutil.utils.DisplayUtil;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
import com.xscm.moduleutil.utils.LanguageUtil;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@@ -67,10 +66,6 @@ import java.util.Map;
|
||||
public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends AppCompatActivity
|
||||
implements BackgroundManager.BackgroundUpdateListener, ColorManager.ColorChangeListener {
|
||||
|
||||
// @Override
|
||||
// protected void attachBaseContext(Context newBase) {
|
||||
// super.attachBaseContext(LanguageUtil.attachBaseContext(newBase));
|
||||
// }
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
// 设置字体缩放比例为1.0f,即不跟随系统字体大小变化
|
||||
@@ -398,11 +393,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
return false;
|
||||
}
|
||||
|
||||
// 在类中添加以下成员变量
|
||||
private final List<MqttBean> messageQueue = new ArrayList<>(); // 消息队列
|
||||
private boolean isPlaying = false; // 播放状态标志
|
||||
private boolean isPlaying2 = false; // 播放状态标志
|
||||
private final Object queueLock = new Object(); // 队列同步锁
|
||||
|
||||
/// 礼物特效
|
||||
// 在类中添加以下成员变量
|
||||
@@ -420,14 +410,17 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
public void onMessageReceived(MqttBean mqttBean) {
|
||||
LogUtils.e("收到MQTT", mqttBean);
|
||||
if (mqttBean == null) return;
|
||||
if (SpUtil.getFloatingScreen() == 1) {
|
||||
synchronized (mqttQueueLock) {
|
||||
|
||||
synchronized (mqttQueueLock) {
|
||||
|
||||
mqttMessageQueue.addAll(mqttBean.getList());
|
||||
if (!isMqttPlaying) {
|
||||
isMqttPlaying = true;
|
||||
processNextMqttMessage();
|
||||
mqttMessageQueue.addAll(mqttBean.getList());
|
||||
if (!isMqttPlaying) {
|
||||
isMqttPlaying = true;
|
||||
processNextMqttMessage();
|
||||
}
|
||||
}
|
||||
}else {
|
||||
mqttMessageQueue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,13 +429,16 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
public void onEvent(XLHBean event) {
|
||||
LogUtils.e("收到XLH", event);
|
||||
if (event == null) return;
|
||||
|
||||
synchronized (xlhQueueLock) {
|
||||
xlhMessageQueue.add(event);
|
||||
if (!isXlhPlaying) {
|
||||
isXlhPlaying = true;
|
||||
processNextXlhMessage();
|
||||
if (SpUtil.getFloatingScreen() == 1) {
|
||||
synchronized (xlhQueueLock) {
|
||||
xlhMessageQueue.add(event);
|
||||
if (!isXlhPlaying) {
|
||||
isXlhPlaying = true;
|
||||
processNextXlhMessage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
xlhMessageQueue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,11 +562,15 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAndStartMqttAnimation(View view, Runnable onAnimationEnd) {
|
||||
try {
|
||||
view.setTranslationX(view.getWidth());
|
||||
int screenWidth = getScreenWidth();
|
||||
// 设置初始位置:在屏幕右侧外部(完全不可见)
|
||||
view.setTranslationX(screenWidth);
|
||||
|
||||
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
|
||||
// ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", getScreenWidth(), (getScreenWidth() - view.getMeasuredWidth()) / 2f);
|
||||
animator1.setDuration(1500);
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator1.start();
|
||||
@@ -578,6 +578,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
view.postDelayed(() -> {
|
||||
try {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
|
||||
// ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", (getScreenWidth() - view.getMeasuredWidth()) / 2f, -view.getMeasuredWidth());
|
||||
animator2.setDuration(1500);
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@@ -602,7 +603,15 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
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());
|
||||
@@ -680,8 +689,9 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
private void handleItemClick(XLHBean xlhBean) {
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
|
||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
// 使用缓存数据进入房间
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), xlhBean.getRoom_id(), "");
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
@@ -11,9 +12,18 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
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.bean.UserBean;
|
||||
import com.xscm.moduleutil.bean.UserInfo;
|
||||
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;
|
||||
@@ -28,12 +38,12 @@ 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> , LocationProvider.LocationCallback
|
||||
{
|
||||
IView<Activity>, LocationProvider.LocationCallback {
|
||||
|
||||
protected P MvpPre;
|
||||
|
||||
protected abstract P bindPresenter();
|
||||
|
||||
private String city1;
|
||||
|
||||
@Override
|
||||
@@ -77,36 +87,53 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
|
||||
@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() {
|
||||
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);
|
||||
LogUtils.e("@@@1", code, "描述:", desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
LogUtils.e("@@@","成功");
|
||||
// V2TIMUserFullInfo userFullInfo = new V2TIMUserFullInfo();
|
||||
// userFullInfo.setNickname(userBean.getNickname());
|
||||
// userFullInfo.setFaceUrl(userBean.getAvatar());
|
||||
// userFullInfo.setAllowType(userBean.getSex());
|
||||
// V2TIMManager.getInstance().setSelfInfo(userFullInfo, new V2TIMCallback() {
|
||||
// @Override
|
||||
// public void onSuccess() {
|
||||
// LogUtils.e("@@@", "成功");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(int code, String desc) {
|
||||
// LogUtils.e("@@@", "描述"+desc);
|
||||
// }
|
||||
// });
|
||||
LogUtils.e("@@@", "成功");
|
||||
initLocation();
|
||||
}
|
||||
});
|
||||
|
||||
V2TIMManager.getInstance().addIMSDKListener(imSdkListener);
|
||||
|
||||
}
|
||||
|
||||
private final V2TIMSDKListener imSdkListener = new V2TIMSDKListener() {
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectSuccess() {//重连成功
|
||||
if (CommonAppContext.getInstance().playId!=null){
|
||||
RetrofitClient.getInstance().roomUserReconnect(CommonAppContext.getInstance().playId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectFailed(int code, String error) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKickedOffline() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserSigExpired() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
|
||||
}
|
||||
};
|
||||
|
||||
private SystemLocationProvider locationProvider;
|
||||
|
||||
private void initLocation() {
|
||||
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
@@ -126,24 +153,24 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
|
||||
locationProvider.getLastKnownLocation(this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationReceived(double latitude, double longitude, String city) {
|
||||
LogUtils.e("当前位置:" + city);
|
||||
city1=city;
|
||||
EventBus.getDefault().post(city1);
|
||||
}
|
||||
@Override
|
||||
public void onLocationReceived(double latitude, double longitude, String city) {
|
||||
LogUtils.e("当前位置:" + city);
|
||||
city1 = city;
|
||||
EventBus.getDefault().post(city1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(String errorMessage) {
|
||||
LogUtils.e("定位失败");
|
||||
}
|
||||
@Override
|
||||
public void onFailed(String errorMessage) {
|
||||
LogUtils.e("定位失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
if (requestCode == 1001) {
|
||||
if (locationProvider==null) {
|
||||
if (locationProvider == null) {
|
||||
locationProvider = new SystemLocationProvider();
|
||||
}
|
||||
locationProvider.getLastKnownLocation(this, this);
|
||||
@@ -169,10 +196,10 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
|
||||
// }
|
||||
// });
|
||||
}
|
||||
/**
|
||||
* 显示全局飘屏消息(支持任意位置飘过)
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 显示全局飘屏消息(支持任意位置飘过)
|
||||
*
|
||||
*/
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void showPiaoPingMessage(MqttBean mqttBean) {
|
||||
// WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||
|
||||
@@ -33,6 +33,7 @@ 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;
|
||||
@@ -389,7 +390,9 @@ public class WebViewActivity extends BaseAppCompatActivity<ActivityWebViewBindin
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), room_id,"");
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@@ -402,14 +405,16 @@ public class WebViewActivity extends BaseAppCompatActivity<ActivityWebViewBindin
|
||||
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, TUIC2CChatActivity.class);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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.base.RoomManager;
|
||||
import com.xscm.moduleutil.bean.NewsMessageList;
|
||||
import com.xscm.moduleutil.databinding.ActivityOfficialNoticeBinding;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
@@ -75,7 +76,8 @@ public class OfficialNoticeActivity extends BaseMvpActivity<NewsPresenter, Activ
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (item.getRoom_id()>0){
|
||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("roomId", item.getRoom_id() + "").navigation();
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), item.getRoom_id()+"","");
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("roomId", item.getRoom_id() + "").navigation();
|
||||
}else if (item.getRoom_id() == 0 && item.getUrl() != null && !item.getUrl().isEmpty()){
|
||||
ARouter.getInstance().build(ARouteConstants.H5).withString("url", item.getUrl()).navigation();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.xscm.moduleutil.base;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/9/20
|
||||
*@description: 模块之间的通讯接口
|
||||
*/
|
||||
public interface AppStateListener {
|
||||
void onAppForeground();
|
||||
void onAppBackground();
|
||||
void onRoomActivityCreated(Activity roomActivity);
|
||||
void onRoomActivityDestroyed();
|
||||
boolean isRoomActivityActive();
|
||||
void setFloatingWindowVisible(boolean visible);
|
||||
boolean isFloatingWindowVisible();
|
||||
|
||||
// 新增方法
|
||||
boolean shouldShowSplash();
|
||||
void setShouldShowSplash(boolean shouldShow);
|
||||
boolean isAppInBackground();
|
||||
void setAppInBackground(boolean inBackground);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.xscm.moduleutil.base;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.xscm.moduleutil.bean.room.RoomInfoResp;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/9/20
|
||||
*@description: 应用状态管理的单例类
|
||||
*/
|
||||
// 在 common 模块中
|
||||
public class AppStateManager implements AppStateListener {
|
||||
private static AppStateManager instance;
|
||||
private boolean isAppInBackground = true;
|
||||
private boolean shouldShowSplash = true;
|
||||
private WeakReference<Activity> roomActivityRef;
|
||||
private boolean isFloatingWindowVisible = false;
|
||||
private boolean isRoomActivityMinimized = false;
|
||||
private AppStateManager() {
|
||||
// 私有构造函数
|
||||
}
|
||||
|
||||
public static synchronized AppStateManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new AppStateManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldShowSplash() {
|
||||
return shouldShowSplash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShouldShowSplash(boolean shouldShow) {
|
||||
this.shouldShowSplash = shouldShow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAppInBackground() {
|
||||
return isAppInBackground;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppInBackground(boolean inBackground) {
|
||||
this.isAppInBackground = inBackground;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomActivityCreated(Activity roomActivity) {
|
||||
roomActivityRef = new WeakReference<>(roomActivity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomActivityDestroyed() {
|
||||
roomActivityRef = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoomActivityActive() {
|
||||
Activity activity = getRoomActivity();
|
||||
return activity != null && !activity.isFinishing();
|
||||
}
|
||||
|
||||
private Activity getRoomActivity() {
|
||||
return roomActivityRef != null ? roomActivityRef.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFloatingWindowVisible(boolean visible) {
|
||||
this.isFloatingWindowVisible = visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFloatingWindowVisible() {
|
||||
return isFloatingWindowVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppForeground() {
|
||||
// 应用进入前台时的处理
|
||||
setAppInBackground(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppBackground() {
|
||||
// 应用进入后台时的处理
|
||||
setAppInBackground(true);
|
||||
}
|
||||
|
||||
// 新增方法:设置RoomActivity为最小化状态
|
||||
public void setRoomActivityMinimized(boolean minimized) {
|
||||
this.isRoomActivityMinimized = minimized;
|
||||
}
|
||||
|
||||
// 新增方法:检查RoomActivity是否处于最小化状态
|
||||
public boolean isRoomActivityMinimized() {
|
||||
return isRoomActivityMinimized;
|
||||
}
|
||||
private RoomInfoResp roomInfoResp;
|
||||
public void setRoomInfo(RoomInfoResp roomInfoResp) {
|
||||
// 处理RoomInfoResp对象
|
||||
this.roomInfoResp = roomInfoResp;
|
||||
}
|
||||
|
||||
public RoomInfoResp getRoomInfo() {
|
||||
return roomInfoResp;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.xscm.moduleutil.base;
|
||||
|
||||
import static androidx.core.app.ActivityCompat.startActivityForResult;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Application;
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -19,6 +19,8 @@ import android.provider.Settings;
|
||||
import android.util.Base64;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.multidex.MultiDex;
|
||||
import androidx.multidex.MultiDexApplication;
|
||||
|
||||
@@ -27,16 +29,23 @@ import com.blankj.utilcode.util.AppUtils;
|
||||
import com.blankj.utilcode.util.FileUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ProcessUtils;
|
||||
import com.blankj.utilcode.util.ServiceUtils;
|
||||
import com.lahm.library.EasyProtectorLib;
|
||||
import com.lahm.library.EmulatorCheckCallback;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.tencent.imsdk.v2.V2TIMAdvancedMsgListener;
|
||||
import com.tencent.imsdk.v2.V2TIMManager;
|
||||
import com.tencent.imsdk.v2.V2TIMMessage;
|
||||
import com.tencent.imsdk.v2.V2TIMMessageManager;
|
||||
import com.tencent.imsdk.v2.V2TIMMessageReceipt;
|
||||
import com.tencent.imsdk.v2.V2TIMValueCallback;
|
||||
import com.xscm.moduleutil.bean.UserBean;
|
||||
import com.xscm.moduleutil.bean.UserInfo;
|
||||
import com.xscm.moduleutil.event.AppLifecycleEvent;
|
||||
import com.xscm.moduleutil.event.UnreadCountEvent;
|
||||
import com.xscm.moduleutil.interfaces.AppLifecycleUtil;
|
||||
import com.xscm.moduleutil.listener.MessageListenerSingleton;
|
||||
import com.xscm.moduleutil.rtc.AgoraManager;
|
||||
import com.xscm.moduleutil.service.MqttConnect;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.utils.UtilConfig;
|
||||
import com.xscm.moduleutil.utils.config.EnvironmentEnum;
|
||||
@@ -59,8 +68,7 @@ import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -69,7 +77,7 @@ import lombok.Getter;
|
||||
* Created by cxf on 2017/8/3.
|
||||
*/
|
||||
|
||||
public class CommonAppContext extends MultiDexApplication {
|
||||
public class CommonAppContext extends MultiDexApplication implements Application.ActivityLifecycleCallbacks {
|
||||
|
||||
private static CommonAppContext sInstance;
|
||||
private static Handler sMainThreadHandler;
|
||||
@@ -87,8 +95,6 @@ public class CommonAppContext extends MultiDexApplication {
|
||||
public String playCover;
|
||||
public boolean showSelf;//盲盒是否能送自己
|
||||
public String playName;
|
||||
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
||||
private ScheduledExecutorService scheduledExecutorServiceRoom = null;
|
||||
private MqttConnect mqttConnect=null;
|
||||
|
||||
// 添加后台状态标记
|
||||
@@ -106,22 +112,230 @@ public class CommonAppContext extends MultiDexApplication {
|
||||
return wasInBackground;
|
||||
}
|
||||
|
||||
private int activityCount = 0;
|
||||
|
||||
private Long masageCount;
|
||||
private int announcement_read_count;
|
||||
|
||||
public int getAnnouncement_read_count() {
|
||||
return announcement_read_count;
|
||||
}
|
||||
|
||||
public void setAnnouncement_read_count(int announcement_read_count) {
|
||||
this.announcement_read_count = announcement_read_count;
|
||||
}
|
||||
|
||||
public Long getMasageCount() {
|
||||
return masageCount;
|
||||
}
|
||||
|
||||
public void setMasageCount(Long masageCount) {
|
||||
this.masageCount = masageCount;
|
||||
}
|
||||
|
||||
private AppStateListener appStateListener;
|
||||
private boolean isListeningUnreadCount = false;
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
sInstance = this;
|
||||
sMainThreadHandler = new Handler();
|
||||
EnvironmentPrefs prefs = new EnvironmentPrefs(this);
|
||||
// 添加内存优化配置
|
||||
optimizeMemorySettings();
|
||||
currentEnvironment = prefs.getSelectedEnvironment();
|
||||
initialization();
|
||||
registerActivityLifecycleCallbacks(this);
|
||||
appStateListener = AppStateManager.getInstance();
|
||||
startListeningUnreadMessageCount();
|
||||
}
|
||||
// 在适当的位置(如onCreate或onResume)添加实时监听
|
||||
protected void startListeningUnreadMessageCount() {
|
||||
if (!isListeningUnreadCount) {
|
||||
// 添加未读消息数变化监听器
|
||||
V2TIMMessageManager messageManager = V2TIMManager.getMessageManager();
|
||||
messageManager.addAdvancedMsgListener(new V2TIMAdvancedMsgListener() {
|
||||
@Override
|
||||
public void onRecvNewMessage(V2TIMMessage msg) {
|
||||
// 收到新消息时更新未读数
|
||||
updateUnreadMessageCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecvC2CReadReceipt(List<V2TIMMessageReceipt> receiptList) {
|
||||
// 收到C2C消息已读回执时更新未读数
|
||||
updateUnreadMessageCount();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
isListeningUnreadCount = true;
|
||||
// 首次获取未读数
|
||||
updateUnreadMessageCount();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新未读消息数的方法
|
||||
private void updateUnreadMessageCount() {
|
||||
V2TIMManager.getConversationManager().getTotalUnreadMessageCount(new V2TIMValueCallback<Long>() {
|
||||
@Override
|
||||
public void onSuccess(Long aLong) {
|
||||
CommonAppContext.getInstance().setMasageCount(aLong != null ? aLong : 0L);
|
||||
// 通知未读数变化
|
||||
notifyUnreadCountChanged(aLong != null ? aLong : 0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String desc) {
|
||||
// 错误处理
|
||||
CommonAppContext.getInstance().setMasageCount(0L);
|
||||
notifyUnreadCountChanged(0L);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 通知未读数变化的方法(可以发送广播或EventBus事件)
|
||||
private void notifyUnreadCountChanged(long unreadCount) {
|
||||
// 使用EventBus通知
|
||||
EventBus.getDefault().post(new UnreadCountEvent(unreadCount,0));
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 优化内存设置
|
||||
*/
|
||||
private void optimizeMemorySettings() {
|
||||
try {
|
||||
// 请求降低内存负载
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// 启用自动内存管理优化
|
||||
registerComponentCallbacks(new ComponentCallbacks2() {
|
||||
@Override
|
||||
public void onTrimMemory(int level) {
|
||||
handleMemoryTrim(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
// 内存极低时的处理
|
||||
releaseNonEssentialResources();
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Memory optimization setup failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理内存削减事件
|
||||
* @param level 削减级别
|
||||
*/
|
||||
private void handleMemoryTrim(int level) {
|
||||
switch (level) {
|
||||
case TRIM_MEMORY_RUNNING_MODERATE:
|
||||
// 应用正在运行,内存开始紧张
|
||||
LogUtils.d("Memory trim: moderate");
|
||||
break;
|
||||
case TRIM_MEMORY_RUNNING_LOW:
|
||||
// 应用正在运行,内存更加紧张
|
||||
LogUtils.d("Memory trim: low");
|
||||
releaseNonEssentialResources();
|
||||
break;
|
||||
case TRIM_MEMORY_RUNNING_CRITICAL:
|
||||
// 应用仍在运行,但系统已开始杀死后台进程
|
||||
LogUtils.d("Memory trim: critical");
|
||||
releaseAllNonEssentialResources();
|
||||
break;
|
||||
case TRIM_MEMORY_UI_HIDDEN:
|
||||
// 应用UI已隐藏,可以释放UI相关资源
|
||||
LogUtils.d("Memory trim: UI hidden");
|
||||
releaseUIResources();
|
||||
break;
|
||||
case TRIM_MEMORY_BACKGROUND:
|
||||
// 应用处于LRU列表中较远位置
|
||||
LogUtils.d("Memory trim: background");
|
||||
break;
|
||||
case TRIM_MEMORY_MODERATE:
|
||||
// 应用处于LRU列表中间位置
|
||||
LogUtils.d("Memory trim: moderate background");
|
||||
releaseAllNonEssentialResources();
|
||||
break;
|
||||
case TRIM_MEMORY_COMPLETE:
|
||||
// 应用处于LRU列表中最远位置,即将被杀死
|
||||
LogUtils.d("Memory trim: complete");
|
||||
releaseAllResources();
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 释放非必要资源
|
||||
*/
|
||||
private void releaseNonEssentialResources() {
|
||||
try {
|
||||
// 清理图片缓存
|
||||
// Glide.get(this).clearMemory();
|
||||
|
||||
// 释放MQTT资源
|
||||
if (mqttConnect != null) {
|
||||
mqttConnect.close();
|
||||
}
|
||||
|
||||
// 通知各个组件释放资源
|
||||
// EventBus.getDefault().post(new MemoryTrimEvent());
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Error releasing non-essential resources: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放所有非必要资源
|
||||
*/
|
||||
private void releaseAllNonEssentialResources() {
|
||||
try {
|
||||
releaseNonEssentialResources();
|
||||
|
||||
// 进行垃圾回收
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Error releasing all non-essential resources: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放UI相关资源
|
||||
*/
|
||||
private void releaseUIResources() {
|
||||
try {
|
||||
// 可以在这里通知UI组件释放资源
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Error releasing UI resources: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放所有资源
|
||||
*/
|
||||
private void releaseAllResources() {
|
||||
try {
|
||||
releaseAllNonEssentialResources();
|
||||
releaseUIResources();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Error releasing all resources: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setAppStateListener(AppStateListener listener) {
|
||||
this.appStateListener = listener;
|
||||
}
|
||||
public void initialization(){
|
||||
UtilConfig.init(this);
|
||||
registerActivityLifecycleCallbacks();
|
||||
// registerActivityLifecycleCallbacks();
|
||||
initWebView();
|
||||
if (ProcessUtils.isMainProcess()) {
|
||||
initARouter();
|
||||
@@ -156,7 +370,7 @@ public class CommonAppContext extends MultiDexApplication {
|
||||
}
|
||||
}
|
||||
|
||||
requestBatteryOptimizationExemption();
|
||||
// requestBatteryOptimizationExemption();
|
||||
}
|
||||
private void requestBatteryOptimizationExemption() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
@@ -414,6 +628,11 @@ public class CommonAppContext extends MultiDexApplication {
|
||||
return mUserBean;
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo() {
|
||||
UserInfo userInfo = SpUtil.getUserInfo();
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public void setUserBean(UserBean bean) {
|
||||
mUserBean = bean;
|
||||
}
|
||||
@@ -480,4 +699,109 @@ public class CommonAppContext extends MultiDexApplication {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(@NonNull Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(@NonNull Activity activity) {
|
||||
if (activityCount == 0) {
|
||||
// 应用从后台回到前台
|
||||
if (appStateListener != null) {
|
||||
appStateListener.onAppForeground();
|
||||
}
|
||||
// handleAppForeground(activity);
|
||||
// AppStateManager.setRoomActivityMinimized(false);
|
||||
}
|
||||
activityCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(@NonNull Activity activity) {
|
||||
activityCount--;
|
||||
if (activityCount == 0) {
|
||||
// 应用切换到后台
|
||||
if (appStateListener != null) {
|
||||
appStateListener.onAppBackground();
|
||||
}
|
||||
// handleAppBackground(activity);
|
||||
// AppStateManager.setRoomActivityMinimized( true);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleAppBackground(Activity activity) {
|
||||
String className = activity.getClass().getName();
|
||||
if (className.contains("RoomActivity") && appStateListener != null) {
|
||||
// RoomActivity进入后台时显示悬浮窗
|
||||
appStateListener.setFloatingWindowVisible(true);
|
||||
}
|
||||
}
|
||||
private void handleAppForeground(Activity activity) {
|
||||
// 获取当前Activity的类名,避免直接引用类
|
||||
String className = activity.getClass().getName();
|
||||
|
||||
if (className.contains("LaunchPageActivity")) {
|
||||
// 对于启动页,我们需要检查是否应该跳转到主页面
|
||||
if (appStateListener != null && appStateListener.isFloatingWindowVisible()) {
|
||||
// 有悬浮窗,直接回到首页
|
||||
ARouter.getInstance().build(ARouteConstants.ME).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP).navigation();
|
||||
} else if (appStateListener != null && appStateListener.shouldShowSplash()) {
|
||||
// 需要显示启动页,但已经在启动页了,不需要额外操作
|
||||
return;
|
||||
} else {
|
||||
// 默认情况下,跳转到主页面
|
||||
ARouter.getInstance().build(ARouteConstants.ME).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP).navigation();
|
||||
}
|
||||
return; // 启动页或引导页不需要特殊处理
|
||||
}
|
||||
|
||||
if (appStateListener != null && appStateListener.isFloatingWindowVisible()) {
|
||||
// 有悬浮窗,直接回到首页
|
||||
// if (!className.contains("MainActivity")) {
|
||||
ARouter.getInstance().build(ARouteConstants.ME).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP).navigation();
|
||||
// }
|
||||
} else if (appStateListener != null && appStateListener.shouldShowSplash()) {
|
||||
// 需要显示启动页
|
||||
try {
|
||||
Class<?> splashActivityClass = Class.forName("com.xscm.modulemain.activity.LaunchPageActivity");
|
||||
Intent intent = new Intent(activity, splashActivityClass);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.startActivity(intent);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showFloatingWindow(Activity activity) {
|
||||
// 这里实现显示悬浮窗的逻辑
|
||||
AppStateManager.getInstance().setFloatingWindowVisible(true);
|
||||
// 实际显示悬浮窗的代码,已实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(@NonNull Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(@NonNull Activity activity) {
|
||||
// String className = activity.getClass().getName();
|
||||
// if (className.contains("RoomActivity") && appStateListener != null) {
|
||||
// appStateListener.onRoomActivityDestroyed();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,497 @@
|
||||
package com.xscm.moduleutil.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 房间管理器
|
||||
* 统一处理房间数据获取、进入房间和退出房间的逻辑
|
||||
*/
|
||||
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);
|
||||
} else {
|
||||
// 获取房间数据后进入房间
|
||||
fetchRoomDataAndEnter(context, roomId, password);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取房间数据并进入房间
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
*/
|
||||
public void fetchRoomDataAndEnter(Context context, String roomId, String password) {
|
||||
// 显示加载提示
|
||||
// 这里可以根据需要添加加载对话框
|
||||
|
||||
// 检查是否有有效的缓存数据
|
||||
// RoomInfoResp roomInfo = getCachedRoomData(roomId);
|
||||
// 检查是否是当前房间且用户在线
|
||||
// boolean isCurrentRoom = isCurrentRoom(roomId);
|
||||
if (CommonAppContext.getInstance().playId==null){
|
||||
fetchAndJoinRoom(context, roomId, password);
|
||||
}else {
|
||||
isUserOnline(context, roomId, password, null);
|
||||
}
|
||||
|
||||
// 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){
|
||||
|
||||
|
||||
if (isOnline){
|
||||
navigateToRoom(context, roomId, password, roomInfo,isOnline);
|
||||
}else {
|
||||
// CommonAppContext.getInstance().isShow = false;
|
||||
// CommonAppContext.getInstance().isPlaying = false;
|
||||
// EventBus.getDefault().post(new RoomOutEvent());
|
||||
// try {
|
||||
// Thread.sleep(300);
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
fetchAndJoinRoom(context, roomId, password);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if (isCurrentRoom&& isOnline) {
|
||||
// if (roomInfo != null) {
|
||||
// navigateToRoom(context, roomId, password, roomInfo);
|
||||
// } else {
|
||||
// // 即使在线,如果没有缓存数据,也需要获取数据
|
||||
// fetchAndJoinRoom(context, roomId, password);
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
// 如果有缓存数据且用户在线,使用缓存数据进入房间
|
||||
// if (roomInfo != null && isOnline) {
|
||||
// RetrofitClient.getInstance().postRoomInfo(roomId, new BaseObserver<RoomInfoResp>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onSubscribe(Disposable d) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(RoomInfoResp roomInfoResp) {
|
||||
//// cacheRoomData(roomId, roomInfo);
|
||||
// navigateToRoom(context, roomId, password, roomInfoResp);
|
||||
// }
|
||||
// });
|
||||
|
||||
// cacheRoomData(roomId, roomInfo);
|
||||
// navigateToRoom(context, roomId, password, roomInfo);
|
||||
return;
|
||||
// }
|
||||
|
||||
// 其他情况,获取新的房间数据并加入房间
|
||||
// fetchAndJoinRoom(context, roomId, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新的房间数据并加入房间
|
||||
* @param context 上下文
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
*/
|
||||
private void fetchAndJoinRoom(Context context, String roomId, String password) {
|
||||
// 获取房间数据
|
||||
MessageListenerSingleton.getInstance().joinGroup(roomId);
|
||||
// 等待一段时间确保退出完成
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} 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);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否是当前房间
|
||||
* @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) {
|
||||
try {
|
||||
// 构建跳转参数
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("roomId", roomId);
|
||||
bundle.putBoolean("isOnline", isOnline);
|
||||
|
||||
if (!TextUtils.isEmpty(password)) {
|
||||
bundle.putString("password", password);
|
||||
}
|
||||
|
||||
if (roomInfo != null) {
|
||||
// bundle.putSerializable("roomInfo", roomInfo);
|
||||
}
|
||||
|
||||
// 使用ARouter跳转到房间页面
|
||||
ARouter.getInstance()
|
||||
.build(ARouteConstants.ROOM_DETAILS)
|
||||
.with(bundle)
|
||||
.withFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
||||
.navigation(context);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "跳转房间页面失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存房间数据
|
||||
* @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) {
|
||||
// 这里应该实现检查用户是否在线的逻辑
|
||||
// 可以通过检查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);
|
||||
} else {
|
||||
isOnline[0] = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 捕获所有可能的异常,避免崩溃
|
||||
e.printStackTrace();
|
||||
isOnline[0] = false;
|
||||
// 即使出现异常也继续执行
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
return isOnline[0];
|
||||
}
|
||||
/**
|
||||
* 清除指定房间的缓存数据
|
||||
* @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);
|
||||
|
||||
// 可以在这里添加其他退出房间的逻辑
|
||||
// 例如:通知服务器用户已退出、清理房间相关资源等
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ public class RoomMessageEvent {
|
||||
private UserInfo ToUserInfo;
|
||||
private List<UserInfo> ToUserInfos;
|
||||
private GiftBean GiftInfo;
|
||||
private List<GiftBean> GiftInfos;
|
||||
private int room_up_pit_type;
|
||||
private MusicSongBean songInfo;
|
||||
private MusicSongBean nextInfo;
|
||||
|
||||
@@ -19,6 +19,8 @@ public class UserBean implements Serializable {
|
||||
private String mobile;
|
||||
private int sex;
|
||||
private int auth;
|
||||
private int is_can_chat;//是否可以私聊,1:可以,0:不可以
|
||||
private int can_chat_money;//需要充值的金额
|
||||
|
||||
private List<MultiUserBean> multi_user;
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@ public class UserInfo implements Serializable {
|
||||
private String red_status;
|
||||
private String gift_num;
|
||||
|
||||
private int is_can_chat;//是否可以私聊,1:可以,0:不可以
|
||||
private int can_chat_money;//需要充值的金额
|
||||
|
||||
private RelationshipBean qinmi;
|
||||
private RelationshipBean zhenai;
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public class RoomSettingBean implements MultiItemEntity {
|
||||
public static final int QXRoomSettingTypeRoomCloseEffects = 25;
|
||||
/// 意见反馈
|
||||
public static final int QXRoomSettingTypeRoomReport = 26;
|
||||
public static final int QXRoomSettingTypeRoomFloatingScreen = 29;
|
||||
|
||||
public static final int ITEM_TYPE_DEFAULT = 0;
|
||||
public static final int ITEM_TYPE_WITH_ICON = 1;
|
||||
|
||||
@@ -22,6 +22,7 @@ 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;
|
||||
@@ -162,7 +163,9 @@ public class WebViewDialog extends BaseDialog<WebViewDialogBinding> {
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"");
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void jumpWebPage(String objects) {
|
||||
|
||||
@@ -22,16 +22,20 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.GsonUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
|
||||
import com.xscm.moduleutil.bean.GiftBean;
|
||||
import com.xscm.moduleutil.bean.MqttXlhEnd;
|
||||
import com.xscm.moduleutil.bean.RoomMessageEvent;
|
||||
import com.xscm.moduleutil.bean.WalletBean;
|
||||
import com.xscm.moduleutil.bean.XLHBean;
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.BlindBoxBean;
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.BlindReslutBean;
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.XlhDrawBean;
|
||||
import com.xscm.moduleutil.databinding.DialogGiftLotteryBinding;
|
||||
import com.xscm.moduleutil.dialog.RechargeDialogFragment;
|
||||
import com.xscm.moduleutil.dialog.WebViewDialog;
|
||||
import com.xscm.moduleutil.event.LotteryEvent;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
@@ -81,8 +85,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
private GiftCardView currentGiftCardView;
|
||||
private boolean isDrawing;//是否正在抽奖
|
||||
private boolean isOpenSound;//是否开启音效
|
||||
private boolean isOpenSpecial;//是否开启特效
|
||||
|
||||
private boolean isOpenSpecial;//是否开启特效
|
||||
private Handler handler;
|
||||
private Runnable timerRunnable;//定时器
|
||||
private int startType;//类型,点击的事抽奖1次还是10次还是100次
|
||||
@@ -145,7 +149,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
mBinding.mirroeSky.swLockYx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean check) {
|
||||
isOpenSound= check;
|
||||
isOpenSound= check;//音效
|
||||
if(!check){
|
||||
stopPlay();
|
||||
}
|
||||
@@ -154,7 +158,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
mBinding.cityTime.swLockYx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean check) {
|
||||
isOpenSound= check;
|
||||
isOpenSound= check;//音效
|
||||
if(!check){
|
||||
stopPlay();
|
||||
}
|
||||
@@ -163,7 +167,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
mBinding.pinnacleTime.swLockYx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean check) {
|
||||
isOpenSound= check;
|
||||
isOpenSound= check;//音效
|
||||
if(!check){
|
||||
stopPlay();
|
||||
}
|
||||
@@ -437,7 +441,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
}
|
||||
}
|
||||
} else if (id == R.id.exchange_layout) {
|
||||
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
|
||||
// ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
|
||||
RechargeDialogFragment.show(roomId, null, getActivity().getSupportFragmentManager());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,13 +576,19 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
mBinding.pinnacleTime.llHundred.setBackground(getResources().getDrawable(R.mipmap.chou_w));
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttXlhEnd event) {
|
||||
BlindBoxBean.XlhData xlhData =new BlindBoxBean.XlhData();
|
||||
xlhData.setCurrent_num(0);
|
||||
xlhData.setCurrent_num(0);
|
||||
xlhData.setStatus(0);
|
||||
UpView(xlhData);
|
||||
XLHBean xlhBean= GsonUtils.fromJson(event.getMessage(), XLHBean.class);
|
||||
// if (xlhBean.getFrom_type()==3) {
|
||||
// dismiss();
|
||||
// }
|
||||
// BlindBoxBean.XlhData xlhData =new BlindBoxBean.XlhData();
|
||||
if (xlhBean.getFrom_type()==3) {
|
||||
xlhData.setCurrent_num(0);
|
||||
xlhData.setStatus(0);
|
||||
UpView(xlhData);
|
||||
}
|
||||
}
|
||||
/// 定时器
|
||||
public void startFastAnimate() {
|
||||
@@ -661,6 +672,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
MvpPre.giftSend(blind_box_turntable_id);
|
||||
MvpPre.wallet();
|
||||
isDrawing = false;
|
||||
playSound("xuanz.mp3");
|
||||
stopFastAnimate();
|
||||
return;
|
||||
}
|
||||
@@ -803,6 +815,11 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(BlindBoxBean.XlhData xlhData) {
|
||||
UpView(xlhData);
|
||||
}
|
||||
|
||||
public void UpView(BlindBoxBean.XlhData xlhData) {
|
||||
if (xlhData != null) {
|
||||
this.xlhData = xlhData;
|
||||
@@ -897,17 +914,22 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
MvpPre = new GiftLotteryPresenter(this, getActivity());
|
||||
}
|
||||
MvpPre.wallet();
|
||||
isDrawing = false;
|
||||
|
||||
MvpPre.giftSend(blind_box_turntable_id);
|
||||
Log.e("isOpenSound===","isOpenSound1222"+isOpenSound);
|
||||
if (isOpenSpecial) {
|
||||
if (isOpenSpecial) {//特效
|
||||
Log.e("isOpenSound===","isOpenSound333"+isOpenSound);
|
||||
startFastAnimate();
|
||||
}else{
|
||||
if(isOpenSound){
|
||||
if(isOpenSound){//音效
|
||||
isDrawing = false;
|
||||
playSound("xuanz.mp3");
|
||||
}else {
|
||||
isDrawing = false;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
isDrawing = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.xscm.moduleutil.bean.blindboxwheel.BlindBoxBean;
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.BlindReslutBean;
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.XlhDrawBean;
|
||||
import com.xscm.moduleutil.databinding.FragmentTourClubDialogBinding;
|
||||
import com.xscm.moduleutil.dialog.RechargeDialogFragment;
|
||||
import com.xscm.moduleutil.dialog.WebViewDialog;
|
||||
import com.xscm.moduleutil.event.MqttBean;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
@@ -75,6 +76,14 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
|
||||
private boolean isDrawing;//是否正在抽奖
|
||||
|
||||
|
||||
// 添加自动滚动相关的成员变量
|
||||
private Handler autoScrollHandler = new Handler();
|
||||
private Runnable autoScrollRunnable;
|
||||
private boolean isAutoScrolling = false;
|
||||
private static final int AUTO_SCROLL_DELAY = 1000; // 1秒滚动一个item
|
||||
private boolean vCheckbox=false;
|
||||
|
||||
@Override
|
||||
protected GiftLotteryPresenter bindPresenter() {
|
||||
return new GiftLotteryPresenter(this, getActivity());
|
||||
@@ -146,8 +155,7 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
mBinding.tvBd.setOnClickListener(this::onClick);
|
||||
mBinding.tvJl.setOnClickListener(this::onClick);
|
||||
mBinding.exchangeLayout.setOnClickListener(this::onClick);
|
||||
|
||||
|
||||
mBinding.vCheckbox.setOnClickListener(this::onClick);
|
||||
giftXlhChouAdapter = new GiftXlhChouAdapter();
|
||||
// 使用 LinearLayoutManager 横向滚动
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
|
||||
@@ -173,10 +181,75 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
mBinding.recycleView.scrollToPosition(middlePosition);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 添加自动滚动相关的方法
|
||||
private void startAutoScroll() {
|
||||
// 如果已经在自动滚动或数据为空,则不启动
|
||||
if (isAutoScrolling || giftLists == null || giftLists.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
isAutoScrolling = true;
|
||||
autoScrollRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isAutoScrolling && mBinding != null && mBinding.recycleView != null) {
|
||||
// 获取当前显示的第一个可见item位置
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.recycleView.getLayoutManager();
|
||||
if (layoutManager != null) {
|
||||
int currentPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
// 如果没有完全可见的item,使用第一个可见item
|
||||
if (currentPosition == RecyclerView.NO_POSITION) {
|
||||
currentPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
}
|
||||
|
||||
// 如果还是没有有效的position,从0开始
|
||||
if (currentPosition == RecyclerView.NO_POSITION) {
|
||||
currentPosition = 0;
|
||||
}
|
||||
// 计算下一个位置
|
||||
int nextPosition = currentPosition + 1;
|
||||
|
||||
// 如果到达末尾,回到开始位置
|
||||
if (nextPosition >= giftXlhChouAdapter.getItemCount()) {
|
||||
nextPosition = 0;
|
||||
}
|
||||
|
||||
// 平滑滚动到下一个位置
|
||||
mBinding.recycleView.smoothScrollToPosition(nextPosition);
|
||||
}
|
||||
|
||||
// 1秒后继续滚动
|
||||
autoScrollHandler.postDelayed(this, AUTO_SCROLL_DELAY);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 开始自动滚动
|
||||
autoScrollHandler.postDelayed(autoScrollRunnable, AUTO_SCROLL_DELAY);
|
||||
}
|
||||
|
||||
private void stopAutoScroll() {
|
||||
isAutoScrolling = false;
|
||||
if (autoScrollRunnable != null) {
|
||||
autoScrollHandler.removeCallbacks(autoScrollRunnable);
|
||||
autoScrollRunnable = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 在抽奖结束后重新启动自动滚动
|
||||
private void resumeAutoScrollAfterLottery() {
|
||||
// 延迟一段时间后再启动自动滚动,让用户看到抽奖结果
|
||||
mBinding.recycleView.postDelayed(() -> {
|
||||
if (isVisible() && !isDrawing) {
|
||||
startAutoScroll();
|
||||
}
|
||||
}, 3000); // 3秒后重新开始自动滚动
|
||||
}
|
||||
|
||||
|
||||
private void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.tv_jc) {
|
||||
@@ -240,7 +313,11 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
xlhRecordDialog = XlhRecordDialog.newInstance(roomId);
|
||||
xlhRecordDialog.show(getChildFragmentManager(), "XlhRecordDialog");
|
||||
} else if (id == R.id.exchange_layout) {//钻石兑换
|
||||
ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
|
||||
// ARouter.getInstance().build(ARouteConstants.CURRENCY).navigation();
|
||||
RechargeDialogFragment.show(roomId, null, getActivity().getSupportFragmentManager());
|
||||
}else if (id==R.id.v_checkbox){
|
||||
mBinding.vCheckbox.setSelected(!mBinding.vCheckbox.isSelected());
|
||||
vCheckbox=mBinding.vCheckbox.isSelected();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,12 +365,24 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
}
|
||||
|
||||
giftXlhChouAdapter.setNewData(giftLists);
|
||||
// // 数据加载完成后启动自动滚动
|
||||
// if (giftLists != null && !giftLists.isEmpty()) {
|
||||
// mBinding.recycleView.post(() -> {
|
||||
// // 确保在UI线程中启动自动滚动
|
||||
// startAutoScroll();
|
||||
// });
|
||||
// }
|
||||
|
||||
}else {
|
||||
isDrawing = false;
|
||||
}
|
||||
}
|
||||
|
||||
int mboxPrice;
|
||||
|
||||
// TODO: 2025/9/4 设置底部按钮文字
|
||||
private void upTitle(int boxPrice) {
|
||||
this.mboxPrice = boxPrice;
|
||||
mBinding.tvOne.setText(boxPrice + "币一次");
|
||||
mBinding.tvTen.setText((boxPrice * 10) + "币十次");
|
||||
mBinding.tvHundred.setText((boxPrice * 100) + "币百次");
|
||||
@@ -309,9 +398,15 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
mBinding.tvGiftCount.setText(message.getText().getGift_num() != null ? message.getText().getGift_num() : "0");
|
||||
mBinding.userName.setText(message.getText().getFromUserInfo().getNickname() != null ? message.getText().getFromUserInfo().getNickname() : "");
|
||||
ImageUtils.loadHeadCC(message.getText().getFromUserInfo().getAvatar(), mBinding.userPic);
|
||||
isDrawing=false;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(RoomMessageEvent event) {
|
||||
onMusicPlay( event);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttXlhEnd event) {
|
||||
dismiss();
|
||||
@@ -429,6 +524,9 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
if (xlhObtainDialog != null && xlhObtainDialog.isShowing()) {
|
||||
xlhObtainDialog.dismiss();
|
||||
}
|
||||
|
||||
stopAutoScroll();
|
||||
autoScrollHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -452,10 +550,37 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
|
||||
}
|
||||
|
||||
private int icon;
|
||||
|
||||
@Override
|
||||
public void wallet(WalletBean walletBean) {
|
||||
if (walletBean != null) {
|
||||
mBinding.tvIcon.setText(walletBean.getCoin());
|
||||
icon = (int) Double.parseDouble(
|
||||
(walletBean.getCoin() != null && !walletBean.getCoin().isEmpty())
|
||||
? walletBean.getCoin()
|
||||
: "0"
|
||||
);
|
||||
mBinding.tvIcon.setText(walletBean.getCoin()!=null && !walletBean.getCoin().isEmpty() ?walletBean.getCoin():"0");
|
||||
showView();
|
||||
}
|
||||
}
|
||||
|
||||
private void showView() {
|
||||
if (icon>=mboxPrice){
|
||||
mBinding.llOne.setClickable( true);
|
||||
}else {
|
||||
mBinding.llOne.setClickable( false);
|
||||
}
|
||||
|
||||
if (icon>=mboxPrice*10){
|
||||
mBinding.llTen.setClickable( true);
|
||||
}else {
|
||||
mBinding.llTen.setClickable( false);
|
||||
}
|
||||
if (icon>=mboxPrice*100){
|
||||
mBinding.llHundred.setClickable( true);
|
||||
}else {
|
||||
mBinding.llHundred.setClickable( false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,74 +590,85 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
@Override
|
||||
public void xlhChouSuccess(List<XlhDrawBean> data) {
|
||||
if (data != null) {
|
||||
if (vCheckbox){
|
||||
showResultDialog(data);
|
||||
}else {
|
||||
// showResultDialog(data);
|
||||
|
||||
showResultDialog(data);
|
||||
// 取消之前可能存在的任务
|
||||
clearPendingTasks();
|
||||
// 抽奖完成后执行动画滚动
|
||||
pendingLotteryRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 清理之前的状态
|
||||
if (giftXlhChouAdapter != null) {
|
||||
giftXlhChouAdapter.clearSelection();
|
||||
}
|
||||
int winningPosition = findHighestValueWinningPosition(data);//这是获取到的中奖位置下标
|
||||
if (winningPosition != -1) {
|
||||
if (scrollHelper == null) {
|
||||
scrollHelper = new CenterScrollHelper(mBinding.recycleView);
|
||||
}
|
||||
|
||||
// 取消之前可能存在的任务
|
||||
// clearPendingTasks();
|
||||
// // 抽奖完成后执行动画滚动
|
||||
// pendingLotteryRunnable = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// // 清理之前的状态
|
||||
// if (giftXlhChouAdapter != null) {
|
||||
// giftXlhChouAdapter.clearSelection();
|
||||
// }
|
||||
// int winningPosition = findHighestValueWinningPosition(data);//这是获取到的中奖位置下标
|
||||
// if (winningPosition != -1) {
|
||||
// if (scrollHelper == null) {
|
||||
// scrollHelper = new CenterScrollHelper(mBinding.recycleView);
|
||||
// }
|
||||
//
|
||||
// // 计算在循环列表中的目标位置(滚动几圈后停在目标位置)
|
||||
// int loopCount = 4; // 滚动4圈
|
||||
// int originalSize = giftLists.size();///这是列表的总大小
|
||||
// // 计算目标在循环列表中的位置(确保在中间区域)
|
||||
// ///这是计算总圈数的大小
|
||||
// int middleBaseIndex = (loopCount * originalSize);
|
||||
// ///这里是展示在中奖的位置,加上总圈数的大小,
|
||||
// int targetLoopIndex = middleBaseIndex + (winningPosition % originalSize);
|
||||
//
|
||||
// // 使用scrollWithCircles方法执行带动画的滚动(带完成回调)
|
||||
// scrollHelper.scrollWithCircles(
|
||||
// targetLoopIndex, // 在循环列表中的位置
|
||||
// loopCount, // 滚动圈数
|
||||
// 200, // 每个item滚动时间200ms(控制速度)
|
||||
// originalSize, // 原始数据大小
|
||||
// () -> { // 滚动完成回调
|
||||
// // 滚动完成后更新选中状态(使用原始位置)
|
||||
// if (giftXlhChouAdapter != null) {
|
||||
// giftXlhChouAdapter.setSelectedPosition(winningPosition);
|
||||
// }
|
||||
// // 滚动完成后延迟一小段时间再居中,确保UI更新完成
|
||||
// pendingCenteringRunnable = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// // 手动将选中项居中
|
||||
// centerSelectedItem(winningPosition, originalSize);
|
||||
//
|
||||
// // 显示结果对话框
|
||||
// getActivity().runOnUiThread(() -> {
|
||||
// scrollHelper = null;
|
||||
// showResultDialog(data);
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
// mBinding.recycleView.postDelayed(pendingCenteringRunnable, 100);
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// } else {
|
||||
// // 如果没有找到中奖位置,直接显示对话框
|
||||
// showResultDialog(data);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// mBinding.recycleView.postDelayed(pendingLotteryRunnable, 300);
|
||||
// 计算在循环列表中的目标位置(滚动几圈后停在目标位置)
|
||||
int loopCount = 4; // 滚动4圈
|
||||
int originalSize = giftLists.size();///这是列表的总大小
|
||||
// 计算目标在循环列表中的位置(确保在中间区域)
|
||||
///这是计算总圈数的大小
|
||||
int middleBaseIndex = (loopCount * originalSize);
|
||||
///这里是展示在中奖的位置,加上总圈数的大小,
|
||||
int targetLoopIndex = middleBaseIndex + (winningPosition % originalSize);
|
||||
|
||||
// 使用scrollWithCircles方法执行带动画的滚动(带完成回调)
|
||||
scrollHelper.scrollWithCircles(
|
||||
targetLoopIndex, // 在循环列表中的位置
|
||||
loopCount, // 滚动圈数
|
||||
1000, // 每个item滚动时间200ms(控制速度)
|
||||
originalSize, // 原始数据大小
|
||||
() -> { // 滚动完成回调
|
||||
// 滚动完成后更新选中状态(使用原始位置)
|
||||
if (giftXlhChouAdapter != null) {
|
||||
giftXlhChouAdapter.setSelectedPosition(winningPosition);
|
||||
}
|
||||
// 滚动完成后延迟一小段时间再居中,确保UI更新完成
|
||||
pendingCenteringRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 手动将选中项居中
|
||||
centerSelectedItem(winningPosition, originalSize);
|
||||
|
||||
// 显示结果对话框
|
||||
getActivity().runOnUiThread(() -> {
|
||||
scrollHelper = null;
|
||||
showResultDialog(data);
|
||||
// 抽奖结束后重新启动自动滚动
|
||||
// resumeAutoScrollAfterLottery();
|
||||
});
|
||||
}
|
||||
};
|
||||
mBinding.recycleView.postDelayed(pendingCenteringRunnable, 1000);
|
||||
}
|
||||
);
|
||||
|
||||
} else {
|
||||
// 如果没有找到中奖位置,直接显示对话框
|
||||
showResultDialog(data);
|
||||
// 抽奖结束后重新启动自动滚动
|
||||
// resumeAutoScrollAfterLottery();
|
||||
}
|
||||
}
|
||||
};
|
||||
mBinding.recycleView.postDelayed(pendingLotteryRunnable, 1000);
|
||||
|
||||
}
|
||||
}else {
|
||||
isDrawing=false;
|
||||
// 抽奖失败也重新启动自动滚动
|
||||
// resumeAutoScrollAfterLottery();
|
||||
}
|
||||
MvpPre.wallet();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -540,6 +676,10 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
* 为新的抽奖做准备,清理之前的状态
|
||||
*/
|
||||
private void prepareForNewLottery() {
|
||||
|
||||
// 停止自动滚动
|
||||
stopAutoScroll();
|
||||
|
||||
// 取消之前可能存在的任务
|
||||
clearPendingTasks();
|
||||
|
||||
@@ -843,6 +983,7 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
public void onCloseClick() {
|
||||
// 处理关闭点击事件
|
||||
if (xlhObtainDialog != null && xlhObtainDialog.isShowing()) {
|
||||
isDrawing = false;
|
||||
xlhObtainDialog.dismiss();
|
||||
}
|
||||
xlhObtainDialog = null;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xscm.moduleutil.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/9/22
|
||||
*@description: 关闭飘屏
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FloatingScreenEvent {
|
||||
private boolean floatingScreen;
|
||||
}
|
||||
@@ -9,8 +9,10 @@ import lombok.Data;
|
||||
@Data
|
||||
public class UnreadCountEvent {
|
||||
private long aLong;
|
||||
private long bLong;
|
||||
|
||||
public UnreadCountEvent(long aLong) {
|
||||
public UnreadCountEvent(long aLong, long bLong) {
|
||||
this.aLong = aLong;
|
||||
this.bLong = bLong;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ public interface ApiServer {
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.JOIN_ROOM)
|
||||
Observable<BaseModel<RoomInfoResp>> roomGetIn(@Field("room_id") String roomId, @Field("password") String password);
|
||||
Call<BaseModel<RoomInfoResp>> roomGetIn(@Field("room_id") String roomId, @Field("password") String password);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.DELETE_ALBUM_IMAGE)
|
||||
@@ -777,4 +777,8 @@ public interface ApiServer {
|
||||
@GET(Constants.GET_GIFT_PACK_LIST_COUNT)
|
||||
Call<BaseModel<GiftPackListCount>> getGiftPackListCount();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.ROOM_USER_RECONNECT)
|
||||
Observable<BaseModel<String>> roomUserReconnect(@Field("room_id") String room_id);
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ResponseBodyConverter<T> implements Converter<ResponseBody, T> {
|
||||
return adapter.fromJson(json);
|
||||
} else {
|
||||
if(!info.contains("更新失败")) {
|
||||
ToastUtils.showShort(info);
|
||||
// ToastUtils.showShort(info);
|
||||
}
|
||||
// throw new APIException(obj.getCode(), info);
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ import com.xscm.moduleutil.bean.room.RoomBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomInfoResp;
|
||||
import com.xscm.moduleutil.bean.room.RoomOnline;
|
||||
import com.xscm.moduleutil.bean.zhuangb.ZhuangBanShangChengBean;
|
||||
import com.xscm.moduleutil.listener.MessageListenerSingleton;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.utils.SystemUtils;
|
||||
import com.xscm.moduleutil.utils.logger.DataLogger;
|
||||
@@ -101,6 +102,7 @@ import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EventListener;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -518,6 +520,10 @@ public class RetrofitClient {
|
||||
});
|
||||
}
|
||||
|
||||
public void roomUserReconnect(String roomId){
|
||||
sApiServer.roomUserReconnect(roomId).compose(new DefaultTransformer<>()).subscribe();
|
||||
}
|
||||
|
||||
public void tasksLihen(BaseObserver<GiftBoxBean> observer) {
|
||||
sApiServer.tasksLihen().enqueue(new Callback<ResponseBody>() {
|
||||
@Override
|
||||
@@ -1096,7 +1102,25 @@ public class RetrofitClient {
|
||||
}
|
||||
|
||||
public void roomGetIn(String roomId, String password, BaseObserver<RoomInfoResp> observer) {
|
||||
sApiServer.roomGetIn(roomId, password).compose(new DefaultTransformer<>()).subscribe(observer);
|
||||
sApiServer.roomGetIn(roomId, password).enqueue(new Callback<BaseModel<RoomInfoResp>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<BaseModel<RoomInfoResp>> call, Response<BaseModel<RoomInfoResp>> response) {
|
||||
if (response.code() == 200){
|
||||
BaseModel<RoomInfoResp> roomInfoRespBaseModel = response.body();
|
||||
if (roomInfoRespBaseModel.getCode()==1){
|
||||
observer.onNext(roomInfoRespBaseModel.getData());
|
||||
}else {
|
||||
MessageListenerSingleton.getInstance().quitGroup(roomId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<BaseModel<RoomInfoResp>> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updatePassword(String roomId, String password, BaseObserver<String> observer) {
|
||||
@@ -1231,7 +1255,12 @@ public class RetrofitClient {
|
||||
public void onResponse(Call<BaseModel<RoomAuction.AuctionListBean>> call, Response<BaseModel<RoomAuction.AuctionListBean>> response) {
|
||||
if (response.code() == 200){
|
||||
BaseModel<RoomAuction.AuctionListBean> baseModel = response.body();
|
||||
observer.onNext(baseModel.getData());
|
||||
|
||||
if (baseModel.getCode()==1) {
|
||||
observer.onNext(baseModel.getData());
|
||||
}else {
|
||||
ToastUtils.showShort(baseModel.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1550,7 +1579,7 @@ public class RetrofitClient {
|
||||
if (response.code() == 200) {
|
||||
BaseModel<String> baseModel = response.body();
|
||||
if (baseModel.getCode() != 1) {
|
||||
// com.hjq.toast.ToastUtils.show(baseModel.getMsg());
|
||||
com.hjq.toast.ToastUtils.show(baseModel.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2333,12 +2362,15 @@ public class RetrofitClient {
|
||||
|
||||
} else if (code == 301) {
|
||||
try {
|
||||
com.blankj.utilcode.util.ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
|
||||
// com.blankj.utilcode.util.ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
|
||||
ToastUtils.showShort(string.getMsg());
|
||||
CommonAppContext.getInstance().clearLoginInfo();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ToastUtils.showShort(string.getMsg());
|
||||
}else {
|
||||
ToastUtils.showShort(string.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2351,7 +2383,11 @@ public class RetrofitClient {
|
||||
public void onResponse(Call<BaseModel<BlindBoxBean>> call, Response<BaseModel<BlindBoxBean>> response) {
|
||||
if (response.code() == 200) {
|
||||
BaseModel<BlindBoxBean> baseModel = response.body();
|
||||
observer.onNext(baseModel.getData());
|
||||
if (baseModel.getCode()==1) {
|
||||
observer.onNext(baseModel.getData());
|
||||
}else {
|
||||
observer.onNext(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2392,6 +2428,7 @@ public class RetrofitClient {
|
||||
}
|
||||
}else {
|
||||
observer.onNext(null);
|
||||
ToastUtils.showShort(baseModel.getMsg());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2412,7 +2449,12 @@ public class RetrofitClient {
|
||||
public void onResponse(Call<BaseModel<BlindReslutBean>> call, Response<BaseModel<BlindReslutBean>> response) {
|
||||
if (response.code() == 200) {
|
||||
BaseModel<BlindReslutBean> baseModel = response.body();
|
||||
observer.onNext(baseModel.getData());
|
||||
if (baseModel.getCode()==1) {
|
||||
observer.onNext(baseModel.getData());
|
||||
}else {
|
||||
observer.onNext(null);
|
||||
ToastUtils.showShort(baseModel.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.xscm.moduleutil.listener;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.blankj.utilcode.util.GsonUtils;
|
||||
@@ -29,6 +32,10 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* @author qx
|
||||
@@ -46,6 +53,16 @@ public class MessageListenerSingleton {
|
||||
private V2TIMGroupListener groupListener;
|
||||
private V2TIMConversationListener conversationListener; // 需要保存引用
|
||||
|
||||
// 添加操作状态标记
|
||||
private volatile boolean isGroupOperationInProgress = false;
|
||||
private final Object groupOperationLock = new Object();
|
||||
private Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
// 添加消息缓存机制
|
||||
private static final int MAX_CACHED_MESSAGES = 20;
|
||||
private final Map<String, List<RoomMessageEvent>> cachedMessages = new ConcurrentHashMap<>();
|
||||
private final Set<String> joinedRooms = ConcurrentHashMap.newKeySet();
|
||||
|
||||
// private boolean listenersAdded = false; // 标记监听器是否已添加
|
||||
// 1. 添加新的监听器接口
|
||||
public interface PublicScreenMessageListener {
|
||||
@@ -79,44 +96,293 @@ public class MessageListenerSingleton {
|
||||
return instance;
|
||||
}
|
||||
|
||||
// 修改 joinGroup 方法
|
||||
public void joinGroup(String roomId) {
|
||||
|
||||
LogUtils.e("@@@", "加入房间的"+roomId);
|
||||
|
||||
if (groupId!=null){
|
||||
quitGroup(groupId);
|
||||
/**
|
||||
* 缓存消息(用于在Fragment未准备好时存储消息)
|
||||
*/
|
||||
private void cacheMessage(String roomId, RoomMessageEvent message) {
|
||||
if (TextUtils.isEmpty(roomId) || message == null) {
|
||||
return;
|
||||
}
|
||||
// 确保监听器已初始化并添加
|
||||
ensureListenersAdded();
|
||||
// RoomMessageEvent.T t = new RoomMessageEvent.T();
|
||||
// t.setText("羽声严禁未成年人进行直播或打赏,官方将24小时在线巡查。我们提倡绿色直播,直播间严禁出现涉政、涉恐、涉黄、涉赌等违法违规内容,严禁宣传封建迷信、宗教极端思想、出现低俗色情、吸烟酗酒等内容,严禁违反社会主义核心价值观、践踏社会道德底线、诱导打赏、低俗 PK 、买卖金币等行为,请大家共同遵守、监督并及时举报。请勿相信各类刷钻、购买礼包、游戏币及电商贩卖等非官方广告信息,谨防网络诈骗。");
|
||||
// notifyMessageReceived(new RoomMessageEvent(1000, mRoomId, t));
|
||||
V2TIMManager.getInstance().joinGroup("room" + roomId, "申请加入", new V2TIMCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Log.d("@@@", "加入im群组成功:");
|
||||
groupId = roomId;
|
||||
}
|
||||
// 标记该房间有待处理的消息
|
||||
List<RoomMessageEvent> roomMessages = cachedMessages.computeIfAbsent(roomId, k -> new ArrayList<>());
|
||||
|
||||
@Override
|
||||
public void onError(int code, String desc) {
|
||||
Log.d("@@@", "加入群组失败:" + code + "=" + desc);
|
||||
}
|
||||
});
|
||||
// 限制每个房间的缓存消息数量
|
||||
if (roomMessages.size() >= MAX_CACHED_MESSAGES) {
|
||||
roomMessages.remove(0); // 移除最旧的消息
|
||||
}
|
||||
|
||||
if (tempGroupJoinListener == null) {
|
||||
tempGroupJoinListener = new OnMessageReceivedListener() {
|
||||
@Override
|
||||
public void onMessageReceived(RoomMessageEvent message) {
|
||||
// 处理消息
|
||||
roomMessages.add(message);
|
||||
LogUtils.d("MessageListener", "缓存消息: roomId=" + roomId + ", msgType=" + message.getMsgType());
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
addOnMessageReceivedListener(tempGroupJoinListener);
|
||||
/**
|
||||
* 获取并清除指定房间的缓存消息
|
||||
*/
|
||||
public List<RoomMessageEvent> getAndClearCachedMessages(String roomId) {
|
||||
if (TextUtils.isEmpty(roomId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<RoomMessageEvent> messages = cachedMessages.remove(roomId);
|
||||
if (messages == null) {
|
||||
messages = new ArrayList<>();
|
||||
}
|
||||
|
||||
LogUtils.d("MessageListener", "获取并清除缓存消息: roomId=" + roomId + ", count=" + messages.size());
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记房间已加入
|
||||
*/
|
||||
public void markRoomJoined(String roomId) {
|
||||
if (!TextUtils.isEmpty(roomId)) {
|
||||
joinedRooms.add(roomId);
|
||||
LogUtils.d("MessageListener", "标记房间已加入: " + roomId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查房间是否已加入
|
||||
*/
|
||||
public boolean isRoomJoined(String roomId) {
|
||||
return !TextUtils.isEmpty(roomId) && joinedRooms.contains(roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除房间加入标记
|
||||
*/
|
||||
public void clearRoomJoined(String roomId) {
|
||||
if (!TextUtils.isEmpty(roomId)) {
|
||||
joinedRooms.remove(roomId);
|
||||
LogUtils.d("MessageListener", "清除房间加入标记: " + roomId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 修改 joinGroup 方法
|
||||
// public void joinGroup(String roomId) {
|
||||
// if (TextUtils.isEmpty(roomId)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 使用同步块确保操作的原子性
|
||||
// synchronized (groupOperationLock) {
|
||||
// if (isGroupOperationInProgress) {
|
||||
// // 如果有操作正在进行,延迟执行
|
||||
// mainHandler.removeCallbacksAndMessages(null);
|
||||
// mainHandler.postDelayed(() -> joinGroup(roomId), 100);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// isGroupOperationInProgress = true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 在新线程中执行操作
|
||||
// new Thread(() -> {
|
||||
// try {
|
||||
// // 先退出当前群组
|
||||
// if (groupId != null && !groupId.equals(roomId)) {
|
||||
// try {
|
||||
// quitGroup(groupId);
|
||||
// // 执行退出操作
|
||||
// // TIMGroupManager.getInstance().quitGroup(groupId);
|
||||
// LogUtils.d("MessageListener", "退出群组: " + groupId);
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e("MessageListener", "退出群组失败: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 等待一小段时间确保退出完成
|
||||
// Thread.sleep(500);
|
||||
//
|
||||
// // 加入新群组
|
||||
// try {
|
||||
// // 执行加入操作
|
||||
//
|
||||
// ensureListenersAdded();
|
||||
// V2TIMManager.getInstance().joinGroup("room" + roomId, "申请加入", new V2TIMCallback() {
|
||||
// @Override
|
||||
// public void onSuccess() {
|
||||
// Log.d("@@@", "加入im群组成功:");
|
||||
//
|
||||
// groupId = roomId;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(int code, String desc) {
|
||||
// Log.d("@@@", "加入群组失败:" + code + "=" + desc);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// groupId = roomId;
|
||||
// LogUtils.d("MessageListener", "加入群组: " + roomId);
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e("MessageListener", "加入群组失败: " + e.getMessage());
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// } finally {
|
||||
// synchronized (groupOperationLock) {
|
||||
// isGroupOperationInProgress = false;
|
||||
// }
|
||||
// }
|
||||
// }).start();
|
||||
//
|
||||
//
|
||||
//// LogUtils.e("@@@", "加入房间的"+roomId);
|
||||
//// if (groupId!=null){
|
||||
//// quitGroup(groupId);
|
||||
//// }
|
||||
////
|
||||
//// // 确保监听器已初始化并添加
|
||||
//// ensureListenersAdded();
|
||||
//// V2TIMManager.getInstance().joinGroup("room" + roomId, "申请加入", new V2TIMCallback() {
|
||||
//// @Override
|
||||
//// public void onSuccess() {
|
||||
//// Log.d("@@@", "加入im群组成功:");
|
||||
////
|
||||
//// groupId = roomId;
|
||||
//// }
|
||||
////
|
||||
//// @Override
|
||||
//// public void onError(int code, String desc) {
|
||||
//// Log.d("@@@", "加入群组失败:" + code + "=" + desc);
|
||||
//// }
|
||||
//// });
|
||||
//
|
||||
// if (tempGroupJoinListener == null) {
|
||||
// tempGroupJoinListener = new OnMessageReceivedListener() {
|
||||
// @Override
|
||||
// public void onMessageReceived(RoomMessageEvent message) {
|
||||
// // 处理消息
|
||||
//
|
||||
// }
|
||||
// };
|
||||
// addOnMessageReceivedListener(tempGroupJoinListener);
|
||||
// }
|
||||
// }
|
||||
|
||||
// 修改 joinGroup 方法,确保先退出再加入
|
||||
public void joinGroup(String roomId) {
|
||||
if (TextUtils.isEmpty(roomId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (groupOperationLock) {
|
||||
if (isGroupOperationInProgress) {
|
||||
// 如果有操作正在进行,延迟执行
|
||||
mainHandler.removeCallbacksAndMessages(null);
|
||||
mainHandler.postDelayed(() -> joinGroup(roomId), 100);
|
||||
return;
|
||||
}
|
||||
|
||||
isGroupOperationInProgress = true;
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// 先退出当前群组(如果需要)
|
||||
if (groupId != null && !groupId.equals(roomId)) {
|
||||
LogUtils.d("MessageListener", "开始退出群组: " + groupId);
|
||||
CountDownLatch quitLatch = new CountDownLatch(1);
|
||||
boolean[] quitSuccess = {false};
|
||||
|
||||
try {
|
||||
V2TIMManager.getInstance().quitGroup("room" + groupId, new V2TIMCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
LogUtils.d("MessageListener", "退出群组成功: " + groupId);
|
||||
quitSuccess[0] = true;
|
||||
quitLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String desc) {
|
||||
LogUtils.e("MessageListener", "退出群组失败: " + groupId + ", code=" + code + ", desc=" + desc);
|
||||
quitSuccess[0] = false;
|
||||
quitLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// 等待退出操作完成,最多等待3秒
|
||||
try {
|
||||
quitLatch.await(3, java.util.concurrent.TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("MessageListener", "退出群组异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 等待一段时间确保退出完成
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
// 加入新群组
|
||||
LogUtils.d("MessageListener", "开始加入群组: " + roomId);
|
||||
CountDownLatch joinLatch = new CountDownLatch(1);
|
||||
boolean[] joinSuccess = {false};
|
||||
|
||||
try {
|
||||
// 确保监听器已添加
|
||||
ensureListenersAdded();
|
||||
|
||||
V2TIMManager.getInstance().joinGroup("room" + roomId, "申请加入", new V2TIMCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
LogUtils.d("MessageListener", "加入im群组成功: " + roomId);
|
||||
joinSuccess[0] = true;
|
||||
groupId = roomId;
|
||||
joinLatch.countDown();
|
||||
// 标记房间已加入
|
||||
markRoomJoined(roomId);
|
||||
|
||||
|
||||
|
||||
// // 发送加入成功的事件
|
||||
// mainHandler.post(() -> {
|
||||
// RoomMessageEvent.T t = new RoomMessageEvent.T();
|
||||
// t.setText("成功加入房间");
|
||||
// notifyMessageReceived(new RoomMessageEvent(1000, roomId, t));
|
||||
// });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String desc) {
|
||||
LogUtils.e("MessageListener", "加入群组失败: " + roomId + ", code=" + code + ", desc=" + desc);
|
||||
joinSuccess[0] = false;
|
||||
joinLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// 等待加入操作完成,最多等待3秒
|
||||
try {
|
||||
joinLatch.await(3, java.util.concurrent.TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("MessageListener", "加入群组异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
LogUtils.d("MessageListener", "群组操作完成 - 退出成功: " + (groupId == null || !groupId.equals(roomId)) + ", 加入成功: " + joinSuccess[0]);
|
||||
|
||||
} finally {
|
||||
synchronized (groupOperationLock) {
|
||||
isGroupOperationInProgress = false;
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private void initListeners() {
|
||||
// 简单消息监听器
|
||||
if (simpleMsgListener == null) {
|
||||
@@ -246,7 +512,7 @@ public class MessageListenerSingleton {
|
||||
@Override
|
||||
public void onTotalUnreadMessageCountChanged(long totalUnreadCount) {
|
||||
super.onTotalUnreadMessageCountChanged(totalUnreadCount);
|
||||
EventBus.getDefault().post(new UnreadCountEvent(totalUnreadCount));
|
||||
EventBus.getDefault().post(new UnreadCountEvent(totalUnreadCount,0));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -297,28 +563,27 @@ public class MessageListenerSingleton {
|
||||
// 修改 quitGroup 方法
|
||||
public static void quitGroup(String mRoomId) {
|
||||
|
||||
if (instance != null) {
|
||||
instance.listeners.clear();
|
||||
removeAllListeners();
|
||||
isInitialized = false;
|
||||
groupId=null;
|
||||
// instance = null;
|
||||
LogUtils.e("@@@","重置成功");
|
||||
}
|
||||
|
||||
V2TIMManager.getInstance().quitGroup("room" + mRoomId, new V2TIMCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
LogUtils.d("@@@","退出群组成功"+mRoomId);
|
||||
LogUtils.d("@@@", "退出群组成功" + mRoomId);
|
||||
// removeAllListeners(); // 移除所有监听器
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String desc) {
|
||||
LogUtils.d("@@@","退出群组失败"+mRoomId, code, desc);
|
||||
LogUtils.d("@@@", "退出群组失败" + mRoomId, code, desc);
|
||||
// removeAllListeners(); // 即使失败也移除监听器
|
||||
}
|
||||
});
|
||||
|
||||
if (instance != null) {
|
||||
instance.listeners.clear();
|
||||
removeAllListeners();
|
||||
isInitialized = false;
|
||||
groupId = null;
|
||||
LogUtils.e("@@@", "重置成功");
|
||||
}
|
||||
}
|
||||
|
||||
// 修改 reset 方法
|
||||
@@ -327,10 +592,10 @@ public class MessageListenerSingleton {
|
||||
instance.listeners.clear();
|
||||
removeAllListeners();
|
||||
isInitialized = false;
|
||||
groupId=null;
|
||||
groupId = null;
|
||||
// instance = null;
|
||||
quitGroup(roomId);
|
||||
LogUtils.e("@@@","重置成功");
|
||||
LogUtils.e("@@@", "重置成功");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,6 +916,11 @@ public class MessageListenerSingleton {
|
||||
// for (OnMessageReceivedListener listener : listeners) {
|
||||
// listener.onMessageReceived(message);
|
||||
// }
|
||||
|
||||
if (message.getMsgType() == 1001 && publicScreenListeners.isEmpty()) {
|
||||
cacheMessage(message.getRoomId(), message);
|
||||
}
|
||||
|
||||
// 通知原有的监听器
|
||||
for (OnMessageReceivedListener listener : listeners) {
|
||||
listener.onMessageReceived(message);
|
||||
|
||||
@@ -262,6 +262,7 @@ public class AgoraManager {
|
||||
*/
|
||||
public void cleanup() {
|
||||
try {
|
||||
|
||||
if (rtcEngine != null) {
|
||||
// // 离开频道
|
||||
|
||||
|
||||
@@ -85,9 +85,11 @@ public class MqttInitCallback implements MqttCallback {
|
||||
XLHBean xlhBean= GsonUtils.fromJson(message, XLHBean.class);
|
||||
if (xlhBean!=null && xlhBean.getRoom_id()!=null && SpUtil.getMyRoomId()!=null) {
|
||||
if (xlhBean.getRoom_id().equals(SpUtil.getMyRoomId())) {
|
||||
MqttXlhEnd mqttXlhEnd = new MqttXlhEnd();
|
||||
mqttXlhEnd.setMessage(message);
|
||||
EventBus.getDefault().post(mqttXlhEnd);
|
||||
if (xlhBean.getFrom_type()==3) {
|
||||
MqttXlhEnd mqttXlhEnd = new MqttXlhEnd();
|
||||
mqttXlhEnd.setMessage(message);
|
||||
EventBus.getDefault().post(mqttXlhEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,7 @@ package com.xscm.moduleutil.utils;
|
||||
*@description: 防止重复点击的工具类
|
||||
*/
|
||||
public class ClickUtils {
|
||||
private static final long CLICK_INTERVAL = 500; // 500ms内不允许重复点击
|
||||
private static final long CLICK_INTERVAL = 1000; // 1000ms内不允许重复点击
|
||||
private static long lastClickTime = 0;
|
||||
|
||||
public static boolean isFastDoubleClick() {
|
||||
|
||||
@@ -30,4 +30,6 @@ public class SPConstants {
|
||||
public static final String REAL_NAME = "realName";//是否实名认证
|
||||
|
||||
public static final String USER_INFO = "userInfo";
|
||||
|
||||
public static final String FLOATING_SCREEN = "floatingScreen";
|
||||
}
|
||||
|
||||
@@ -369,6 +369,14 @@ public class SpUtil {
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.OPEN_EFFECT, 1);
|
||||
}
|
||||
|
||||
public static void setFloatingScreen(int i){
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.FLOATING_SCREEN, i);
|
||||
}
|
||||
|
||||
public static int getFloatingScreen(){
|
||||
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.FLOATING_SCREEN, 1);
|
||||
}
|
||||
|
||||
//设置耳返
|
||||
public static void setAuricularBack(int i) {
|
||||
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.OPEN_AU_BACK, i);
|
||||
|
||||
@@ -235,10 +235,10 @@ public class AvatarFrameView extends FrameLayout {
|
||||
// }
|
||||
|
||||
// 检查特效是否开启
|
||||
if (SpUtil.getOpenEffect() != 1) {
|
||||
clearQueue();
|
||||
return;
|
||||
}
|
||||
// if (SpUtil.getOpenEffect() != 1) {
|
||||
// clearQueue();
|
||||
// return;
|
||||
// }
|
||||
// 检查是否可以开始新的播放
|
||||
// if (!playbackManager.canStartNewPlayback()) {
|
||||
// Logger.d("AvatarFrameView", "Max concurrent playbacks reached, waiting...");
|
||||
@@ -299,14 +299,21 @@ public class AvatarFrameView extends FrameLayout {
|
||||
mBinding.playView.setVisibility(View.GONE);
|
||||
}
|
||||
loadSVGA(item.url);
|
||||
} );
|
||||
});
|
||||
} else if ("mp4".equalsIgnoreCase(ext)) {
|
||||
mainHandler.post(() -> {
|
||||
renderType = RenderType.MP4;
|
||||
mType = item.type;
|
||||
mBinding.playView.setVisibility(View.VISIBLE);
|
||||
downloadAndPlayMp4(item.url);
|
||||
} );
|
||||
if (mBinding != null && mBinding.playView != null) {
|
||||
mBinding.playView.setVisibility(View.VISIBLE);
|
||||
|
||||
downloadAndPlayMp4(item.url);
|
||||
}else {
|
||||
mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.room_view_svga_anim, this, true);
|
||||
mBinding.playView.setVisibility(View.VISIBLE);
|
||||
downloadAndPlayMp4(item.url);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 不支持的格式,直接完成
|
||||
handlePlaybackComplete();
|
||||
@@ -329,7 +336,7 @@ public class AvatarFrameView extends FrameLayout {
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
if (mBinding!=null && mBinding.playView!=null) {
|
||||
if (mBinding != null && mBinding.playView != null) {
|
||||
return mBinding.playView.isRunning();
|
||||
}
|
||||
return true;
|
||||
@@ -557,7 +564,7 @@ public class AvatarFrameView extends FrameLayout {
|
||||
LogUtils.e("有缓存");
|
||||
mainHandler.post(() -> {
|
||||
// 检查是否已销毁
|
||||
if ( file.exists()) {
|
||||
if (file.exists()) {
|
||||
playMp4File(file);
|
||||
} else {
|
||||
LogUtils.w(TAG, "有缓存2222222222222");
|
||||
@@ -813,18 +820,18 @@ public class AvatarFrameView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
public void stopAll(){
|
||||
if (svgaSurface != null){
|
||||
public void stopAll() {
|
||||
if (svgaSurface != null) {
|
||||
svgaSurface.stopAnimation();
|
||||
svgaSurface.clearAnimation();
|
||||
svgaSurface.setImageDrawable( null);
|
||||
svgaSurface.setImageDrawable(null);
|
||||
}
|
||||
if (svgaSurface2 != null){
|
||||
if (svgaSurface2 != null) {
|
||||
svgaSurface2.stopAnimation();
|
||||
svgaSurface2.clearAnimation();
|
||||
svgaSurface.setImageDrawable( null);
|
||||
svgaSurface.setImageDrawable(null);
|
||||
}
|
||||
if (mBinding.playView!=null){
|
||||
if (mBinding.playView != null) {
|
||||
mBinding.playView.stopPlay();
|
||||
}
|
||||
}
|
||||
@@ -1215,7 +1222,7 @@ public class AvatarFrameView extends FrameLayout {
|
||||
svgaSurface.stopAnimation(true);
|
||||
svgaSurface.clear();
|
||||
svgaSurface.clearAnimation();
|
||||
svgaSurface.setImageDrawable( null);
|
||||
svgaSurface.setImageDrawable(null);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "Error releasing SVGA resources: " + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -48,19 +48,25 @@ public class CenterScrollHelper {
|
||||
|
||||
// 使用LinearSmoothScroller进行平滑滚动
|
||||
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
|
||||
private static final float ACCELERATION = 0.5f; // 加速度
|
||||
private static final float DECELERATION = 0.8f; // 减速度
|
||||
|
||||
@Override
|
||||
protected int calculateTimeForScrolling(int dx) {
|
||||
// 使用缓动函数计算时间,实现从慢到快再到慢的效果
|
||||
// return calculateEasingTime(dx, durationPerItem);
|
||||
|
||||
// 简单线性时间计算,确保滚动速度一致
|
||||
int screenWidth = recyclerView.getWidth();
|
||||
if (screenWidth <= 0) {
|
||||
return durationPerItem * 3;
|
||||
}
|
||||
int itemWidth = screenWidth / 3;
|
||||
int items = Math.max(1, dx / itemWidth);
|
||||
return durationPerItem * items;
|
||||
// // 简单线性时间计算,确保滚动速度一致
|
||||
// int screenWidth = recyclerView.getWidth();
|
||||
// if (screenWidth <= 0) {
|
||||
// return durationPerItem * 3;
|
||||
// }
|
||||
// int itemWidth = screenWidth / 3;
|
||||
// int items = Math.max(1, dx / itemWidth);
|
||||
// return durationPerItem * items;
|
||||
|
||||
// 使用缓动函数计算时间,实现从慢到快再到慢的效果
|
||||
return calculateEasingTime(dx, durationPerItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,8 +126,8 @@ public class CenterScrollHelper {
|
||||
}
|
||||
|
||||
// 计算时间:开始慢(500ms),后来快(50ms)
|
||||
int minDuration = 50; // 最快速度
|
||||
int maxDuration = 500; // 最慢速度
|
||||
int minDuration = 1000; // 最快速度
|
||||
int maxDuration = 2000; // 最慢速度
|
||||
int calculatedTime = (int) (maxDuration - (maxDuration - minDuration) * easeProgress);
|
||||
|
||||
return Math.max(minDuration, calculatedTime);
|
||||
|
||||
@@ -380,13 +380,14 @@ public class Constants {
|
||||
public static final String GET_ALL_RECORD = "/api/BlindBoxTurntable/get_all_record";//获取全服抽奖记录
|
||||
public static final String GIFT_SEND = "/api/BlindBoxTurntable/gift_send";//礼物发放
|
||||
|
||||
public static final String GET_BOX_GIFT_LIST_XLH = "/api/BlindBoxTurntable/xlh";///巡乐会
|
||||
public static final String POST_DRAW_GIFT_LIST_XLH = "/api/BlindBoxTurntable/xlh_draw_gift";///巡乐会抽奖
|
||||
public static final String POST_XLH_ALL_RECORD = "/api/BlindBoxTurntable/get_xlh_all_record";///巡乐会榜单
|
||||
public static final String GET_XLH_MY_RECORD = "/api/BlindBoxTurntable/get_xlh_my_record";///巡乐会记录
|
||||
public static final String POST_GIFT_ALL_CLEAR = "/api/Room/room_gift_all_clear";///背包礼物全清
|
||||
public static final String POST_ROOM_USER_CHARM_LIST = "/api/Room/room_user_charm_list";///房间用户当前魅力值列表
|
||||
public static final String GET_GIFT_PACK_LIST_COUNT = "/api/UserGiftPack/get_gift_pack_list_count";///背包礼物总价值
|
||||
public static final String GET_BOX_GIFT_LIST_XLH = "/api/BlindBoxTurntable/xlh";//巡乐会
|
||||
public static final String POST_DRAW_GIFT_LIST_XLH = "/api/BlindBoxTurntable/xlh_draw_gift";//巡乐会抽奖
|
||||
public static final String POST_XLH_ALL_RECORD = "/api/BlindBoxTurntable/get_xlh_all_record";//巡乐会榜单
|
||||
public static final String GET_XLH_MY_RECORD = "/api/BlindBoxTurntable/get_xlh_my_record";//巡乐会记录
|
||||
public static final String POST_GIFT_ALL_CLEAR = "/api/Room/room_gift_all_clear";//背包礼物全清
|
||||
public static final String POST_ROOM_USER_CHARM_LIST = "/api/Room/room_user_charm_list";//房间用户当前魅力值列表
|
||||
public static final String GET_GIFT_PACK_LIST_COUNT = "/api/UserGiftPack/get_gift_pack_list_count";//背包礼物总价值
|
||||
public static final String ROOM_USER_RECONNECT = "/api/Room/user_reconnect";//用户重连
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -256,6 +256,10 @@ public class PKProgressBar extends View {
|
||||
getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
// 添加视图是否已附加到窗口的检查
|
||||
if (getWindowToken() == null) {
|
||||
return true; // 视图尚未附加到窗口,稍后再试
|
||||
}
|
||||
getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
// 是否需要渐变器
|
||||
if (isGradient) {
|
||||
|
||||
@@ -93,7 +93,7 @@ public class RoomFriendshipWheatView extends BaseWheatView {
|
||||
mIvRipple.stopAnimation(true);
|
||||
mIvRipple.setVisibility(VISIBLE);
|
||||
mTvName.setText(bean.getNickname());
|
||||
ImageUtils.loadCenterCrop(bean.getAvatar(), mRiv);
|
||||
ImageUtils.loadHeadCC(bean.getAvatar(), mRiv);
|
||||
if (TextUtils.isEmpty(pitBean.getDress())) {
|
||||
mIvFrame.stopAll();
|
||||
mIvFrame.setVisibility(INVISIBLE);
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.xscm.moduleutil.widget;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.xscm.moduleutil.bean.room.RoomInfoResp;
|
||||
import com.xscm.moduleutil.event.QXRoomSeatViewType;
|
||||
|
||||
// 在 common 模块中或相应模块中
|
||||
public class SharedViewModel extends ViewModel {
|
||||
// 给roomFragment传递数据
|
||||
private final MutableLiveData<RoomInfoResp> dataForFragment = new MutableLiveData<>();
|
||||
private final MutableLiveData<Boolean> fragmentReady = new MutableLiveData<>(false);
|
||||
private MutableLiveData<QXRoomSeatViewType> seatViewTypeData = new MutableLiveData<>();
|
||||
//给子fragment传递数据
|
||||
private MutableLiveData<RoomInfoResp> childFragmentData = new MutableLiveData<>();
|
||||
|
||||
// 为子Fragment设置数据的方法
|
||||
public void setChildFragmentData(RoomInfoResp data) {
|
||||
childFragmentData.setValue(data);
|
||||
}
|
||||
|
||||
// 获取子Fragment数据的LiveData
|
||||
public LiveData<RoomInfoResp> getChildFragmentData() {
|
||||
return childFragmentData;
|
||||
}
|
||||
public void setSeatViewType(QXRoomSeatViewType type) {
|
||||
seatViewTypeData.setValue(type);
|
||||
}
|
||||
|
||||
public LiveData<QXRoomSeatViewType> getSeatViewType() {
|
||||
return seatViewTypeData;
|
||||
}
|
||||
public LiveData<RoomInfoResp> getDataForFragment() {
|
||||
return dataForFragment;
|
||||
}
|
||||
|
||||
public void setDataForFragment(RoomInfoResp data) {
|
||||
dataForFragment.setValue(data);
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getFragmentReady() {
|
||||
return fragmentReady;
|
||||
}
|
||||
|
||||
public void setFragmentReady(boolean ready) {
|
||||
fragmentReady.setValue(ready);
|
||||
}
|
||||
|
||||
// 清除数据,避免重复接收
|
||||
|
||||
// 清理所有数据的方法
|
||||
public void clearAllData() {
|
||||
dataForFragment.setValue(null);
|
||||
childFragmentData.setValue(null);
|
||||
seatViewTypeData.setValue(null);
|
||||
fragmentReady.setValue(false);
|
||||
}
|
||||
|
||||
// 清理子Fragment数据
|
||||
public void clearChildFragmentData() {
|
||||
childFragmentData.setValue(null);
|
||||
}
|
||||
|
||||
// 清理主Fragment数据
|
||||
public void clearFragmentData() {
|
||||
dataForFragment.setValue(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user