diff --git a/app/build.gradle b/app/build.gradle
index b077fac..4dee1f6 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -116,7 +116,7 @@ android {
}
kotlinOptions {
- jvmTarget = '17'
+ jvmTarget = '11'
}
dexOptions {
dexInProcess true
@@ -144,13 +144,9 @@ dependencies {
implementation files('libs/logger-2.2.2-release.aar')
implementation files('libs/main-2.2.3-release.aar')
- implementation files('libs/WbCloudFaceLiveSdk-face-v6.6.2-8e4718fc.aar')
- implementation files('libs/WbCloudNormal-v5.1.10-4e3e198.aar')
- implementation(libs.arouter.api.v150)
- //annotationProcessor
- annotationProcessor libs.arouter.compiler
+
implementation project(':modulevocal') // 必须
annotationProcessor project(':modulevocal') // 关键!
@@ -158,6 +154,10 @@ dependencies {
api project(":moduleLogin")
implementation project(':modulemain')
+ implementation(libs.arouter.api.v150)
+ //annotationProcessor
+ annotationProcessor libs.arouter.compiler
+
//aar的名称,例如:WbCloudFaceLiveSdk-v6.0.0-1234567.aar,填入'WbCloudFaceLiveSdk-v6.0.0-1234567'
// implementation(name: 'WbCloudFaceLiveSdk-face-v6.6.2-8e4718fc', ext: 'aar')
////2. 云normal SDK,
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e8660f2..c964307 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -200,7 +200,7 @@
android:launchMode="singleTask">
implement
}
public void ysxl() {
- ARouter.getInstance().build(ARouteConstants.H5).withString("url",CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=4").withString("title", "隐私协议").navigation();
+ Intent intent = new Intent(com.blankj.utilcode.util.ActivityUtils.getTopActivity(), WebViewActivity.class);
+ intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=4");
+ intent.putExtra("title", "隐私协议");
+ com.blankj.utilcode.util.ActivityUtils.startActivity(intent);
+
+// ARouter.getInstance().build(ARouteConstants.H5).withString("url",CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=4").withString("title", "隐私协议").navigation();
}
public void yhxy() {
- ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=6").withString("title", "用户协议").navigation();
+ Intent intent = new Intent(com.blankj.utilcode.util.ActivityUtils.getTopActivity(), WebViewActivity.class);
+ intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=6");
+ intent.putExtra("title", "用户协议");
+ com.blankj.utilcode.util.ActivityUtils.startActivity(intent);
+
+// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=6").withString("title", "用户协议").navigation();
}
}
diff --git a/moduleUtil/build.gradle b/moduleUtil/build.gradle
index f91a807..b5410c1 100644
--- a/moduleUtil/build.gradle
+++ b/moduleUtil/build.gradle
@@ -2,7 +2,7 @@ plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
}
-
+//apply plugin: 'kotlin-kapt' // 关键:Kotlin 注解处理器
android {
namespace 'com.xscm.moduleutil'
compileSdk 35
@@ -35,14 +35,14 @@ android {
}
}
compileOptions {
- sourceCompatibility JavaVersion.VERSION_17
- targetCompatibility JavaVersion.VERSION_17
+ sourceCompatibility JavaVersion.VERSION_11
+ targetCompatibility JavaVersion.VERSION_11
}
dataBinding {
enabled = true
}
kotlinOptions {
- jvmTarget = '17'
+ jvmTarget = '11'
}
packagingOptions {
@@ -50,6 +50,13 @@ android {
}
}
+// Kotlin 注解处理器参数(针对 Kotlin 代码)
+//kapt {
+// arguments {
+// arg("AROUTER_MODULE_NAME", project.getName())
+// }
+//}
+
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
@@ -139,8 +146,9 @@ dependencies {
api(libs.alipay.alipaysdk.android)
api(libs.arouter.api.v150)
- annotationProcessor libs.arouter.annotation
annotationProcessor libs.arouter.compiler
+// implementation 'com.alibaba:arouter-api:1.5.2'
+// kapt 'com.alibaba:arouter-compiler:1.5.2'/**/
api(libs.easypermissions)
api(libs.xbanner)
@@ -221,4 +229,4 @@ dependencies {
//aar的名称,例如:WbCloudNormal-v5.1.10-123456789.aar,填入 'WbCloudNormal-v5.1.10-123456789.aar'
}
-apply plugin: 'com.alibaba.arouter' // ⚠️ 添加这一行
\ No newline at end of file
+//apply plugin: 'com.alibaba.arouter' // ⚠️ 添加这一行
\ No newline at end of file
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/activity/BaseAppCompatActivity.java b/moduleUtil/src/main/java/com/xscm/moduleutil/activity/BaseAppCompatActivity.java
index f82b030..b8397ab 100644
--- a/moduleUtil/src/main/java/com/xscm/moduleutil/activity/BaseAppCompatActivity.java
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/activity/BaseAppCompatActivity.java
@@ -766,7 +766,10 @@ public abstract class BaseAppCompatActivity extends
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(ChatInfo event) {
String id = event.getId().replace("g", "");
- ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/union/setGroup?id=" + SpUtil.getToken() + "&guildId=" + id).navigation();
+ Intent intent = new Intent(this, WebViewActivity.class);
+ intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/union/setGroup?id=" + SpUtil.getToken() + "&guildId=" + id);
+ startActivity( intent);
+// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/union/setGroup?id=" + SpUtil.getToken() + "&guildId=" + id).navigation();
}
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/activity/news/OfficialNoticeActivity.java b/moduleUtil/src/main/java/com/xscm/moduleutil/activity/news/OfficialNoticeActivity.java
index 23254b1..f075499 100644
--- a/moduleUtil/src/main/java/com/xscm/moduleutil/activity/news/OfficialNoticeActivity.java
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/activity/news/OfficialNoticeActivity.java
@@ -3,6 +3,7 @@ package com.xscm.moduleutil.activity.news;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
+import android.content.Intent;
import android.text.Html;
import android.view.View;
@@ -14,6 +15,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.activity.WebViewActivity;
import com.xscm.moduleutil.base.RoomManager;
import com.xscm.moduleutil.bean.NewsMessageList;
import com.xscm.moduleutil.databinding.ActivityOfficialNoticeBinding;
@@ -79,7 +81,10 @@ public class OfficialNoticeActivity extends BaseMvpActivity {
// } else {
// ARouter.getInstance().build(ARouteConstants.SET_YOUTH_PWD_ACTIVITY).withInt("type", SetYouthPasswordActivity.SET_TYPE).navigation();
// }
- ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/feedback/teenage?id=" + SpUtil.getToken()).navigation();
+
+ Intent intent = new Intent(getContext(), WebViewActivity.class);
+ intent.putExtra("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/feedback/teenage?id=" + SpUtil.getToken());
+ getContext().startActivity(intent);
+// ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/feedback/teenage?id=" + SpUtil.getToken()).navigation();
dismiss();
});
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryPresenter.java b/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryPresenter.java
index 84b58e8..6a2c49d 100644
--- a/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryPresenter.java
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/dialog/giftLottery/GiftLotteryPresenter.java
@@ -122,6 +122,9 @@ public class GiftLotteryPresenter extends BasePresenter(mView);
+ }
MvpRef.get().wallet(walletBean);
}
});
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/http/ApiResponseCallback.java b/moduleUtil/src/main/java/com/xscm/moduleutil/http/ApiResponseCallback.java
new file mode 100644
index 0000000..4bb637e
--- /dev/null
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/http/ApiResponseCallback.java
@@ -0,0 +1,134 @@
+package com.xscm.moduleutil.http;
+
+import android.content.Context;
+import android.widget.Toast;
+
+import com.blankj.utilcode.util.LogUtils;
+import com.blankj.utilcode.util.ToastUtils;
+import com.xscm.moduleutil.base.CommonAppContext;
+
+import org.greenrobot.eventbus.EventBus;
+
+import java.io.IOException;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+
+/**
+ * 通用的API响应处理回调类
+ * 统一处理所有接口的响应和错误情况
+ */
+public abstract class ApiResponseCallback implements Callback> {
+ private Context mContext;
+
+ // 构造方法,传入上下文用于显示提示
+ public ApiResponseCallback(Context context) {
+ this.mContext = context;
+ }
+
+ @Override
+ public void onResponse(Call> call, Response> response) {
+ // 统一处理HTTP响应
+ if (response.isSuccessful()) {
+ // 处理200-299范围内的HTTP状态码
+ BaseModel body = response.body();
+
+ if (body != null) {
+ // 根据code值进行不同处理
+ switch (body.getCode()) {
+ case 1: // 接口返回成功
+ // 业务成功,回调给具体实现
+ // 即使data为null也调用onSuccess,由具体实现决定如何处理null值
+ onSuccess(body.getData());
+ break;
+ case 0: // 接口请求成功但数据错误
+ // 显示错误信息
+// String errorMsg = body.getMsg() != null ? body.getMsg() : "操作失败,请重试";
+// showToast(errorMsg);
+ onFailure(new Exception(body.getMsg()));
+ break;
+ case 301: // 登录失效
+ // 显示错误信息并退出应用
+// String loginErrorMsg = body.getMsg() != null ? body.getMsg() : "登录已失效,请重新登录";
+ showToast(body.getMsg());
+
+ try {
+ // 发送退出登录事件
+// EventBus.getDefault().post(new com.xscm.moduleutil.event.LogOutEvent());
+
+ // 清除登录信息
+ CommonAppContext.getInstance().clearLoginInfo();
+
+ // 跳转到登录页面
+// android.content.Intent intent = new android.content.Intent(CommonAppContext.getInstance(), Class.forName("com.xscm.midi.LaunchPageActivity"));
+// intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK | android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK);
+// CommonAppContext.getInstance().startActivity(intent);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ onFailure(new Exception(body.getMsg()));
+ break;
+ default:
+ // 其他错误情况
+ String defaultErrorMsg = body.getMsg() != null ? body.getMsg() : "未知错误";
+ showToast(defaultErrorMsg);
+ onFailure(new Exception(defaultErrorMsg));
+ break;
+ }
+ } else {
+ // 响应体为空的情况
+ String errorMsg = "获取数据失败,请重试";
+ showToast(errorMsg);
+ onFailure(new Exception(errorMsg));
+ }
+ } else {
+ // 处理HTTP错误状态码
+ String errorInfo;
+ try {
+ if (response.errorBody() != null) {
+ errorInfo = response.errorBody().string();
+ // 可以在这里统一解析错误响应体
+ } else {
+ errorInfo = "请求失败,状态码:" + response.code();
+ }
+ } catch (IOException e) {
+ errorInfo = "请求失败,状态码:" + response.code();
+ e.printStackTrace();
+ }
+ showToast("");
+ onFailure(new Exception(errorInfo));
+ }
+ }
+
+ @Override
+ public void onFailure(Call> call, Throwable t) {
+ // 统一处理网络异常
+ String errorMsg;
+ if (t instanceof IOException) {
+// errorMsg = "网络异常,请检查网络连接";
+ } else {
+// errorMsg = "请求处理失败,请重试";
+ }
+ showToast("");
+ // 回调给具体实现处理
+ onFailure(t);
+ }
+
+ // 显示提示信息
+ private void showToast(String message) {
+ if (mContext != null) {
+ Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ // 业务成功时的回调,由具体接口实现
+ public abstract void onSuccess(T data);
+
+ // 错误时的回调,可选实现
+ public void onFailure(Throwable t) {
+ // 可以留空,由子类选择性实现
+ LogUtils.e("接口错误:",t);
+ }
+}
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/http/BusinessAwareConverterFactory.java b/moduleUtil/src/main/java/com/xscm/moduleutil/http/BusinessAwareConverterFactory.java
new file mode 100644
index 0000000..f41332d
--- /dev/null
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/http/BusinessAwareConverterFactory.java
@@ -0,0 +1,74 @@
+package com.xscm.moduleutil.http;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+
+import com.blankj.utilcode.util.ToastUtils;
+import com.xscm.moduleutil.base.CommonAppContext;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import okhttp3.ResponseBody;
+import retrofit2.Converter;
+import retrofit2.Retrofit;
+import retrofit2.converter.gson.GsonConverterFactory;
+
+public class BusinessAwareConverterFactory extends Converter.Factory {
+ private final GsonConverterFactory originalFactory;
+ private final Context context;
+
+ public BusinessAwareConverterFactory(Context context) {
+ this.context = context;
+ this.originalFactory = GsonConverterFactory.create();
+ }
+
+ @Override
+ public Converter responseBodyConverter(Type type,
+ Annotation[] annotations,
+ Retrofit retrofit) {
+ final Converter delegate =
+ originalFactory.responseBodyConverter(type, annotations, retrofit);
+
+ return new Converter() {
+ @Override
+ public Object convert(ResponseBody value) throws IOException {
+ // 先读取响应字符串检查业务状态码
+ String responseString = value.string();
+ try {
+ JSONObject jsonObject = new JSONObject(responseString);
+ int code = jsonObject.getInt("code");
+ String msg = jsonObject.getString("msg");
+
+ if (code == 301) {
+ handleForceLogout();
+ ToastUtils.showShort(msg);
+ }
+
+ // 重新构建 ResponseBody 供原始转换器使用
+ ResponseBody newValue = ResponseBody.create(value.contentType(), responseString);
+ return delegate.convert(newValue);
+
+ } catch (JSONException e) {
+ throw new IOException("");
+ }
+ }
+
+ private void handleForceLogout() {
+ new Handler(Looper.getMainLooper()).post(() -> {
+ try {
+ CommonAppContext.getInstance().clearLoginInfo();
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+
+ });
+ }
+ };
+ }
+}
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/http/RetrofitClient.java b/moduleUtil/src/main/java/com/xscm/moduleutil/http/RetrofitClient.java
index 45b8c0f..b044e51 100644
--- a/moduleUtil/src/main/java/com/xscm/moduleutil/http/RetrofitClient.java
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/http/RetrofitClient.java
@@ -193,6 +193,7 @@ public class RetrofitClient {
private Retrofit provideRetrofit(OkHttpClient client) {
return new Retrofit.Builder()
+ .addConverterFactory(new BusinessAwareConverterFactory(CommonAppContext.getInstance()))
.addConverterFactory(MyConverterFactory.create())/**/
// .addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
@@ -234,7 +235,29 @@ public class RetrofitClient {
}
return INSTANCE;
}
+ /**
+ * 检查网络连接状态
+ * @return true表示网络可用,false表示网络不可用
+ */
+ private boolean isNetworkAvailable() {
+ ConnectivityManager connectivityManager = (ConnectivityManager) CommonAppContext.getInstance()
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivityManager != null) {
+ NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
+ return activeNetworkInfo != null && activeNetworkInfo.isConnected();
+ }
+ return false;
+ }
+ /**
+ * 网络不可用时的统一处理方法
+ * @param observer BaseObserver对象
+ * @param 泛型类型
+ */
+ private void handleNetworkUnavailable(BaseObserver observer) {
+ ToastUtils.showShort("网络不可用,请检查网络设置");
+ observer.onError(new Throwable("网络不可用,请检查网络设置"));
+ }
public T createApiClient(Class apiClientClass) {
return mRetrofit.create(apiClientClass);
}
@@ -258,6 +281,7 @@ public class RetrofitClient {
public void onResponse(Call> call, Response> response) {
if (response.code() == 200) {
BaseModel body = response.body();
+
observer.onNext(body.getMsg());
}
@@ -367,6 +391,7 @@ public class RetrofitClient {
sApiServer.exchangeCoin(earnings_num).enqueue(new Callback>() {
@Override
public void onResponse(Call> call, Response> response) {
+
onNextRetu(response, observer);
}
@@ -400,7 +425,7 @@ public class RetrofitClient {
public void onResponse(Call> call, Response> response) {
if (response.code() == 200) {
BaseModel baseModel = response.body();
- if (baseModel != null) {
+ if (baseModel.getCode()==1){
observer.onNext(baseModel.getData());
} else {
ToastUtils.showShort("获取数据失败");
@@ -1301,7 +1326,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call>> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("获取房间列表失败", t);
}
});
}
@@ -1345,7 +1371,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call>> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("getTopRooms", t);
}
});
}
@@ -1748,6 +1775,11 @@ public class RetrofitClient {
}
public void roomGetIn(String roomId, String password, BaseObserver observer) {
+ if (!isNetworkAvailable()) {
+ handleNetworkUnavailable(observer);
+ CommonAppContext.getInstance().isRoomJoininj=false;
+ return;
+ }
sApiServer.roomGetIn(roomId, password).enqueue(new Callback>() {
@Override
@@ -1827,7 +1859,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call>> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("myCpRoom", t);
}
});
}
@@ -2026,8 +2059,7 @@ public class RetrofitClient {
}
// TODO: 2025/3/15 获取主持人列表
- public void getHostList(String roomId, String
- type, BaseObserver> observer) {
+ public void getHostList(String roomId, String type, BaseObserver> observer) {
sApiServer.getHostList(roomId, type).enqueue(new Callback>>() {
@Override
public void onResponse(Call>> call, Response>> response) {
@@ -2046,8 +2078,7 @@ public class RetrofitClient {
});
}
- public void getSearch(String keyWord, String
- type, BaseObserver> observer) {
+ public void getSearch(String keyWord, String type, BaseObserver> observer) {
sApiServer.getSearch(keyWord, type).enqueue(new Callback>>() {
@Override
public void onResponse(Call>> call, Response>> response) {
@@ -2086,8 +2117,7 @@ public class RetrofitClient {
});
}
- public void getCharmList(String roomId, String stime, String etime, String
- p, BaseObserver observer) {
+ public void getCharmList(String roomId, String stime, String etime, String p, BaseObserver observer) {
sApiServer.getCharmList(roomId, stime, etime, p).enqueue(new Callback>() {
@Override
public void onResponse(Call> call, Response> response) {
@@ -2146,26 +2176,22 @@ public class RetrofitClient {
});
}
- public void roomAuctionJoin(String auctionId, String userId, String giftId, String
- num, String type, BaseObserver observer) {
- sApiServer.roomAuctionJoin(auctionId, userId, giftId, num, type).enqueue(new Callback>() {
-
- @Override
- public void onResponse(Call> call, Response> response) {
- if (response.code() == 200) {
- BaseModel baseModel = response.body();
-
- if (baseModel.getCode() == 1) {
- observer.onNext(baseModel.getData());
- } else {
- ToastUtils.showShort(baseModel.getMsg());
+ public void roomAuctionJoin(String auctionId, String userId, String giftId, String num, String type, BaseObserver observer) {
+ sApiServer.roomAuctionJoin(auctionId, userId, giftId, num, type).enqueue(new ApiResponseCallback(CommonAppContext.getInstance()) {
+ @Override
+ public void onSuccess(RoomAuction.AuctionListBean data) {
+ // 确保即使data为null也能够正确传递给observer
+ if (data == null){
+ data = new RoomAuction.AuctionListBean();
+ }
+ observer.onNext(data);
}
- }
- }
@Override
- public void onFailure(Call> call, Throwable t) {
- t.printStackTrace();
+ public void onFailure(Throwable t) {
+ super.onFailure(t);
+ RoomAuction.AuctionListBean yy=new RoomAuction.AuctionListBean();
+ observer.onNext(yy);
}
});
}
@@ -2180,6 +2206,7 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
ToastUtils.showShort(t.toString());
+ LogUtils.e("auction",t);
}
});
}
@@ -2197,7 +2224,7 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
}
});
}
@@ -2211,7 +2238,7 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
}
});
}
@@ -2225,7 +2252,7 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
}
});
}
@@ -2241,7 +2268,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("editRoom",t);
}
});
}
@@ -2256,7 +2284,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("setPresidedRatio",t);
}
});
}
@@ -2272,7 +2301,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("postHostAdd",t);
}
});
}
@@ -2287,7 +2317,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("reward_zone",t);
}
});
}
@@ -2301,7 +2332,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("upSong",t);
}
});
}
@@ -2315,7 +2347,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("clearApply",t);
}
});
}
@@ -2356,7 +2389,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("helpApply",t);
}
});
}
@@ -2371,7 +2405,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("setRoomApply",t);
}
});
}
@@ -2386,13 +2421,13 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("giveGift",t);
}
});
}
- public void roomGift(String room_id, String gift_id, String gift_num, String to_uid, String
- type, String pit_number, String heart_id, BaseObserver observer) {
+ public void roomGift(String room_id, String gift_id, String gift_num, String to_uid, String type, String pit_number, String heart_id, BaseObserver observer) {
sApiServer.roomGift(room_id, gift_id, gift_num, to_uid, type, pit_number, heart_id).enqueue(new Callback>() {
@Override
public void onResponse(Call> call, Response> response) {
@@ -2401,7 +2436,9 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("解析失败:roomGift", t.toString());
+ observer.onNext( "");
}
});
}
@@ -2579,8 +2616,7 @@ public class RetrofitClient {
});
}
- public void setMutePit(String roomId, String user_id, String
- isMute, BaseObserver observer) {
+ public void setMutePit(String roomId, String user_id, String isMute, BaseObserver observer) {
sApiServer.setMutePit(roomId, user_id, isMute).enqueue(new Callback>() {
@Override
public void onResponse(Call> call, Response> response) {
@@ -2589,7 +2625,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("setMutePit", t.toString());
}
});
}
@@ -2604,7 +2641,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("setLockPit", t.toString());
}
});
}
@@ -2618,7 +2656,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("downPit", t.toString());
}
});
}
@@ -2632,7 +2671,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("kickOutRoom", t.toString());
}
});
}
@@ -2646,7 +2686,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("applySong", t.toString());
}
});
}
@@ -2660,7 +2701,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("agreeSong", t.toString());
}
});
}
@@ -2674,7 +2716,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("endSong", t.toString());
}
});
}
@@ -2769,6 +2812,7 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
ToastUtils.showShort(t.toString());
+ LogUtils.e("changeSong", t.toString());
}
});
}
@@ -2783,7 +2827,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("hostUserPit", t.toString());
}
});
}
@@ -2836,7 +2881,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("topRelationCard", t.toString());
}
});
}
@@ -2850,7 +2896,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("deleteRelationCard", t.toString());
}
});
}
@@ -2906,7 +2953,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("setUserDecorate", t.toString());
}
});
}
@@ -2938,7 +2986,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("publishZone", t.toString());
}
});
}
@@ -2952,7 +3001,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("likeZone", t.toString());
}
});
}
@@ -2966,7 +3016,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("deleteComment", t.toString());
}
});
@@ -2982,7 +3033,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("deleteZone", t.toString());
}
});
}
@@ -2997,7 +3049,9 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("commentZone", t.toString());
+
}
});
}
@@ -3012,7 +3066,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("clearLoginInfo", t.toString());
}
});
}
@@ -3027,13 +3082,13 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("cancel", t.toString());
}
});
}
- public void getPostData(String new_password, String mobile, String code, String
- userId, BaseObserver observer) {
+ public void getPostData(String new_password, String mobile, String code, String userId, BaseObserver observer) {
sApiServer.getPostData(new_password, mobile, code, userId).enqueue(new Callback>() {
@Override
public void onResponse(Call> call, Response> response) {
@@ -3066,7 +3121,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("forgotPassword", t.toString());
}
});
}
@@ -3081,7 +3137,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("createAlbum", t.toString());
}
});
}
@@ -3096,7 +3153,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("editAlbum", t.toString());
}
});
}
@@ -3113,7 +3171,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("editUserInfo", t.toString());
}
});
} else {
@@ -3126,7 +3185,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("editUserBg", t.toString());
}
});
}
@@ -3141,7 +3201,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("userGuanz", t.toString());
}
});
}
@@ -3155,7 +3216,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ t.printStackTrace();
}
});
}
@@ -3170,7 +3232,7 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
t.printStackTrace();
}
});
@@ -3220,7 +3282,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("removeBlackList", t.toString());
}
});
}
@@ -3235,7 +3298,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("upAddAlbum", t.toString());
}
});
}
@@ -3249,7 +3313,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("moveAlbum", t.toString());
}
});
}
@@ -3278,7 +3343,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("deleteAlbum", t.toString());
}
});
} else {
@@ -3290,7 +3356,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("deleteAlbum", t.toString());
}
});
}
@@ -3306,7 +3373,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("likeAlbum", t.toString());
}
});
}
@@ -3320,7 +3388,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("getRealNameResult", t.toString());
}
});
}
@@ -3334,7 +3403,8 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("changeRoom", t.toString());
}
});
}
@@ -3348,13 +3418,13 @@ public class RetrofitClient {
@Override
public void onFailure(Call> call, Throwable t) {
- ToastUtils.showShort(t.toString());
+// ToastUtils.showShort(t.toString());
+ LogUtils.e("changeRoomType", t.toString());
}
});
}
- public void onNextRetu
- (Response> response, BaseObserver observer) {
+ public void onNextRetu(Response> response, BaseObserver observer) {
if (response.code() == 200) {
BaseModel string = response.body();
if (string != null) {
@@ -3380,8 +3450,7 @@ public class RetrofitClient {
}
/// 获取活动礼物列表
- public void getBoxGiftList(String giftBagId, String
- roomId, BaseObserver observer) {
+ public void getBoxGiftList(String giftBagId, String roomId, BaseObserver observer) {
sApiServer.getBoxGiftList(giftBagId, roomId).enqueue(new Callback>() {
@Override
public void onResponse(Call> call, Response> response) {
@@ -3512,8 +3581,7 @@ public class RetrofitClient {
});
}
- public void xlhMyRecord(String roomId, String page, String
- pageSize, BaseObserver> observer) {
+ public void xlhMyRecord(String roomId, String page, String pageSize, BaseObserver> observer) {
sApiServer.xlhMyRecord(roomId, page, pageSize).enqueue(new Callback>>() {
@Override
public void onResponse(Call>> call, Response>> response) {
@@ -3532,8 +3600,7 @@ public class RetrofitClient {
});
}
- public void getAllRecord(String giftBagId, String page, String
- pageSize, BaseObserver> observer) {
+ public void getAllRecord(String giftBagId, String page, String pageSize, BaseObserver> observer) {
sApiServer.getAllRecord(giftBagId, page, pageSize).enqueue(new Callback>>() {
@Override
public void onResponse(Call>> call, Response>> response) {
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/utils/ARouteConstants.java b/moduleUtil/src/main/java/com/xscm/moduleutil/utils/ARouteConstants.java
index 66b90ba..5f76355 100644
--- a/moduleUtil/src/main/java/com/xscm/moduleutil/utils/ARouteConstants.java
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/utils/ARouteConstants.java
@@ -21,9 +21,9 @@ public class ARouteConstants {
public static final String CREATED_ROOM = "/modulevocal/CreatedRoomActivity"; //创建房间
public static final String WITHDRAWAL_ACTIVITY = "/modulevocal/WithdrawalActivity"; //提现
public static final String REAL_NAME_ACTIVITY ="/modulevocal/RealNameActivity"; //实名认证
- public static final String REAL_NAME_ACTIVITY2 ="/app/RealNameActivity"; //实名认证
- public static final String H5 ="/moduleutil/WebViewActivity"; //网页
- public static final String GIFT_WALL ="/moduleroom/UserGiftWallFragment"; //实名认证
+ public static final String REAL_NAME_ACTIVITY2 ="/modulevocal/RealNameActivity"; //实名认证
+ public static final String H5 ="/moduleUtil/WebViewActivity"; //网页
+// public static final String GIFT_WALL ="/moduleroom/UserGiftWallFragment"; //实名认证
public static final String RECHARGE_ACTIVITY ="/modulevocal/RechargeActivity"; //实名认证
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/BaseViewModel.kt b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/BaseViewModel.kt
new file mode 100644
index 0000000..ac28857
--- /dev/null
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/BaseViewModel.kt
@@ -0,0 +1,38 @@
+package com.xscm.moduleutil.widget.room
+
+import androidx.lifecycle.LifecycleObserver
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.Observer
+import androidx.lifecycle.ViewModel
+import com.xscm.moduleutil.bean.room.RoomInfoResp
+import com.xscm.moduleutil.http.RetrofitClient
+import kotlinx.coroutines.CoroutineScope
+
+open class BaseViewModel : ViewModel(),LifecycleObserver {
+
+ val roomInfoData=MutableLiveData()
+ private val passRoom by lazy { MutableLiveData() }
+
+ private val error by lazy { MutableLiveData() }
+
+ private val finally by lazy { MutableLiveData() }
+ //加入房间
+ fun jiaoRoom(roomId:String, password:String){
+
+ }
+
+ /**
+ * 请求失败,出现异常
+ */
+ fun getError(): LiveData {
+ return error
+ }
+
+ /**
+ * 请求完成,在此处做一些关闭操作
+ */
+ fun getFinally(): LiveData {
+ return finally
+ }
+}
diff --git a/moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/PassRoomException.kt b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/PassRoomException.kt
new file mode 100644
index 0000000..cea4259
--- /dev/null
+++ b/moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/PassRoomException.kt
@@ -0,0 +1,8 @@
+package com.xscm.moduleutil.widget.room
+
+import java.io.IOException
+
+/**
+ * 自定义异常信息显示
+ */
+data class PassRoomException(var msg: String,var code: Int) : IOException()
\ No newline at end of file
diff --git a/modulecircle/src/main/java/com/example/modulecircle/fragment/CircleCategoryFragment.java b/modulecircle/src/main/java/com/example/modulecircle/fragment/CircleCategoryFragment.java
index 8440a1e..8f251ca 100644
--- a/modulecircle/src/main/java/com/example/modulecircle/fragment/CircleCategoryFragment.java
+++ b/modulecircle/src/main/java/com/example/modulecircle/fragment/CircleCategoryFragment.java
@@ -244,7 +244,9 @@ public class CircleCategoryFragment extends BaseMvpFragment
+
+
+
+
\ No newline at end of file
diff --git a/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.java b/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.java
deleted file mode 100644
index 0641a09..0000000
--- a/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.java
+++ /dev/null
@@ -1,4369 +0,0 @@
-package com.example.moduleroom.activity;
-
-import static android.view.View.GONE;
-import static android.view.View.INVISIBLE;
-import static android.view.View.VISIBLE;
-
-import static com.liulishuo.okdownload.OkDownloadProvider.context;
-
-import android.Manifest;
-import android.annotation.SuppressLint;
-import android.app.ActivityManager;
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.ActivityInfo;
-import android.content.res.Configuration;
-import android.graphics.Color;
-import android.graphics.drawable.ColorDrawable;
-import android.os.Bundle;
-import android.os.CountDownTimer;
-import android.os.Handler;
-import android.os.Looper;
-import android.text.Spannable;
-import android.text.SpannableStringBuilder;
-import android.text.TextUtils;
-import android.text.style.ForegroundColorSpan;
-import android.util.Log;
-import android.view.GestureDetector;
-import android.view.Gravity;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewParent;
-import android.view.Window;
-import android.view.WindowManager;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.RelativeLayout;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.constraintlayout.widget.ConstraintLayout;
-import androidx.core.content.ContextCompat;
-import androidx.fragment.app.DialogFragment;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
-import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
-
-import com.alibaba.android.arouter.facade.annotation.Autowired;
-import com.alibaba.android.arouter.facade.annotation.Route;
-import com.alibaba.android.arouter.launcher.ARouter;
-import com.blankj.utilcode.util.GsonUtils;
-import com.blankj.utilcode.util.LogUtils;
-import com.blankj.utilcode.util.ThreadUtils;
-import com.blankj.utilcode.util.TimeUtils;
-import com.blankj.utilcode.util.ToastUtils;
-import com.chad.library.adapter.base.BaseQuickAdapter;
-import com.example.moduleroom.R;
-import com.example.moduleroom.contacts.RoomContacts;
-import com.example.moduleroom.databinding.ActivityRoomBinding;
-import com.example.moduleroom.dialog.ExitRoomBottomSheet;
-import com.example.moduleroom.dialog.FriendsDialogFragment;
-import com.example.moduleroom.dialog.PublishCommentDialogFragment;
-import com.example.moduleroom.dialog.RequestDialogFragment;
-import com.example.moduleroom.dialog.RoomGiftDialogFragment;
-import com.example.moduleroom.dialog.RoomMessageDialogFragment;
-import com.example.moduleroom.dialog.RoomOnlineDialogFragment;
-import com.example.moduleroom.dialog.RoomPkDialogFragment;
-import com.example.moduleroom.dialog.RoomSettingFragment;
-import com.example.moduleroom.dialog.SoundEffectsDialogFragment;
-import com.example.moduleroom.fragment.PublicScreenEaseChatFragment;
-import com.example.moduleroom.fragment.RoomCabinFragment;
-import com.example.moduleroom.fragment.RoomChartsFragment;
-import com.example.moduleroom.fragment.RoomNoticeDialogFragment;
-import com.orhanobut.logger.Logger;
-import com.petterp.floatingx.assist.helper.FxScopeHelper;
-import com.petterp.floatingx.listener.control.IFxControl;
-import com.tencent.imsdk.v2.V2TIMValueCallback;
-import com.xscm.moduleutil.base.AppStateListener;
-import com.xscm.moduleutil.base.AppStateManager;
-import com.xscm.moduleutil.base.CommonAppContext;
-import com.xscm.moduleutil.base.RoomManager;
-import com.xscm.moduleutil.bean.GiftBean;
-import com.xscm.moduleutil.bean.HeadlineBean;
-import com.xscm.moduleutil.bean.RoomInputEvent;
-import com.xscm.moduleutil.bean.RoomSingleton;
-import com.xscm.moduleutil.bean.UserInfo;
-import com.xscm.moduleutil.bean.UserOnlineStatusBean;
-import com.xscm.moduleutil.bean.room.FriendInfo;
-import com.xscm.moduleutil.bean.room.FriendUserBean;
-import com.xscm.moduleutil.bean.room.RoomAuction;
-import com.xscm.moduleutil.bean.room.RoomOnline;
-import com.xscm.moduleutil.color.ThemeableDrawableUtils;
-import com.xscm.moduleutil.dialog.RechargeDialogFragment;
-import com.xscm.moduleutil.dialog.giftLottery.GiftLotteryDialog;
-import com.xscm.moduleutil.dialog.giftLottery.TourClubDialogFragment;
-import com.xscm.moduleutil.event.ColoseCardEvent;
-import com.xscm.moduleutil.event.EffectEvent;
-import com.xscm.moduleutil.event.MusicEvent;
-import com.xscm.moduleutil.event.QXRoomSeatViewType;
-import com.xscm.moduleutil.event.RoomGiftGiveEvent;
-import com.xscm.moduleutil.event.RoomInputHideEvent;
-import com.xscm.moduleutil.event.RoomOutEvent;
-import com.xscm.moduleutil.event.RoomTaskEvent;
-import com.xscm.moduleutil.event.RoomWheatEvent;
-import com.xscm.moduleutil.event.SurfaceEvent;
-import com.xscm.moduleutil.event.UnreadCountEvent;
-import com.xscm.moduleutil.http.BaseObserver;
-import com.xscm.moduleutil.http.RetrofitClient;
-import com.xscm.moduleutil.interfaces.OnMusicItemClickListener;
-import com.xscm.moduleutil.listener.MessageListenerSingleton;
-import com.xscm.moduleutil.adapter.LikeUserAdapter;
-import com.xscm.moduleutil.bean.RoomCharmRankBean;
-import com.xscm.moduleutil.bean.RoomMessageEvent;
-import com.xscm.moduleutil.bean.RoomSettingEvent;
-import com.xscm.moduleutil.bean.room.RoomOnlineBean;
-import com.example.moduleroom.fragment.RoomFragment;
-import com.example.moduleroom.fragment.RoomPasswordSetDialogFragment;
-import com.example.moduleroom.presenter.RoomPresenter;
-import com.xscm.moduleutil.activity.BaseMvpActivity;
-import com.xscm.moduleutil.adapter.CommonPageAdapter;
-import com.xscm.moduleutil.bean.room.RoomBean;
-import com.xscm.moduleutil.bean.room.RoomInfoResp;
-import com.xscm.moduleutil.bean.room.RoomOwnerBean;
-import com.xscm.moduleutil.bean.room.RoomPitBean;
-import com.xscm.moduleutil.bean.room.RoomUserBean;
-import com.xscm.moduleutil.dialog.ConfirmDialog;
-import com.xscm.moduleutil.event.RoomJoinMountModel;
-import com.xscm.moduleutil.rtc.AgoraManager;
-import com.xscm.moduleutil.rtc.MusicPlayBean;
-import com.xscm.moduleutil.service.MyRoomSingleton;
-import com.xscm.moduleutil.utils.ARouteConstants;
-import com.xscm.moduleutil.utils.ColorManager;
-import com.xscm.moduleutil.utils.ImageUtils;
-import com.xscm.moduleutil.utils.SpUtil;
-import com.xscm.moduleutil.utils.SystemUtils;
-import com.xscm.moduleutil.widget.CircularProgressView;
-import com.xscm.moduleutil.widget.CustomMusicFloatingView;
-import com.xscm.moduleutil.widget.GiftAnimView;
-import com.xscm.moduleutil.widget.QXGiftPlayerManager;
-import com.xscm.moduleutil.widget.SharedViewModel;
-import com.xscm.moduleutil.widget.SilentCountDownTimer;
-import com.xscm.moduleutil.widget.ViewUtils;
-import com.xscm.moduleutil.widget.floatingView.Floa;
-import com.tencent.imsdk.v2.V2TIMManager;
-
-import org.greenrobot.eventbus.EventBus;
-import org.greenrobot.eventbus.Subscribe;
-import org.greenrobot.eventbus.ThreadMode;
-
-import java.lang.ref.WeakReference;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.stream.Collectors;
-
-import io.agora.musiccontentcenter.Music;
-import io.reactivex.disposables.Disposable;
-import pub.devrel.easypermissions.AppSettingsDialog;
-import pub.devrel.easypermissions.EasyPermissions;
-
-@Route(path = ARouteConstants.ROOM_DETAILS)
-public class RoomActivity extends BaseMvpActivity implements RoomContacts.View,
- EasyPermissions.PermissionCallbacks, MessageListenerSingleton.OnMessageReceivedListener {
-
- private RoomFragment roomFragment;
- CommonPageAdapter commonPageAdapter;
- private RoomBean mRoomBean;
- //房主信息
- private RoomOwnerBean mRoomOwnerBean;
- //房间用户信息
- private RoomUserBean mRoomUserBean;
- private List mPitList = new ArrayList<>();
- @Autowired
- public String password;
- @Autowired
- public String roomId;
- @Autowired
- public RoomInfoResp mRoomInfoResp;
-
- @Autowired
- public String taskId;
-
- public static boolean sDestroied = false;
- LikeUserAdapter likeUserAdapter;
- String[] permissions = {Manifest.permission.RECORD_AUDIO};
- private boolean isSave = false;//活动是否将被系统回收
-
- private IFxControl musicWindowControl;
- private CustomMusicFloatingView customMusicFloatingView;
- private int number = 0;
-
- private Floa floatingMagnetView;
- private FrameLayout fullScreenContainer;
- private boolean isFullScreen = false;
- private ImageView ivExitFullscreen;
- ImageView ivQuan;
- private boolean imYc;
-
- @Autowired
- public boolean isOnline;
-
- private SilentCountDownTimer silentCountDownTimer;
- private CircularProgressView circularProgress;
- private PublicScreenEaseChatFragment publicScreenFragment; // 添加成员变量
- // 添加成员变量
- private boolean isLayoutAdjusted = false;
- // private ViewStub stub;
- private static WeakReference sActivityRef;
- // 存储当前显示的弹框引用
- private List activeDialogs = new ArrayList<>();
- private List activeDialogFragments = new ArrayList<>();
-
- private boolean isMinimized = false;
- private static final String PREF_MINIMIZED_ROOM = "minimized_room_id";
- private static final String PREF_MINIMIZED_TIME = "minimized_time";
- private AppStateListener appStateListener;
-
- // 添加弹框到管理列表
- public void addActiveDialog(DialogInterface dialog) {
- activeDialogs.add(dialog);
- }
-
- public void addActiveDialogFragment(Fragment dialogFragment) {
- activeDialogFragments.add(dialogFragment);
- }
-
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- // 必须调用 setIntent 来更新 Activity 的 Intent
- setIntent(intent);
- isOnline = intent.getBooleanExtra("isOnline", false);
- password = intent.getStringExtra("password");
- String mRoomId = intent.getStringExtra("roomId");
-// mRoomInfoResp = (RoomInfoResp) getIntent().getSerializableExtra("roomInfo");
- if (roomId.equals(mRoomId) || TextUtils.isEmpty(mRoomId)) {
- sDestroied = false;
- if (mRoomInfoResp == null) {
- mRoomInfoResp = AppStateManager.getInstance().getRoomInfo();
- }
- if (!isOnline) {
- releaseRoom();
- startActivity(intent);
- finish();
- } else {
- MvpPre.postRoomInfo(roomId);
- }
-
-// updateSharedViewModelData(mRoomInfoResp);
-// resetFragment();
-// postRoomInfo(mRoomInfoResp);
- } else {
- releaseRoom();
- startActivity(intent);
- finish();
- }
- }
-
-// private void updateSharedViewModelData(RoomInfoResp newData) {
-// if (newData != null) {
-// // 清除旧数据
-// sharedViewModel.clearChildFragmentData();
-// // 设置新数据
-// sharedViewModel.setChildFragmentData(newData);
-//
-// // 如果需要更新主Fragment数据也一并更新
-// sharedViewModel.clearFragmentData();
-// sharedViewModel.setDataForFragment(newData);
-// }
-// }
-
- private void handleRestoreFromMinimize(Intent intent) {
- // 如果是从桌面启动且之前有最小化的房间
-// if (Intent.ACTION_MAIN.equals(intent.getAction())
-// && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
-//
-// SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
-// boolean isMinimized = prefs.getBoolean("is_minimized", false);
-//
-// if (isMinimized) {
-// // 恢复到最小化的房间
-// String minimizedRoomId = prefs.getString(PREF_MINIMIZED_ROOM, null);
-// if (minimizedRoomId != null && minimizedRoomId.equals(roomId)) {
-// // 当前就是最小化的房间,直接恢复
-// resumeRoomFromMinimize();
-// return;
-// }
-// }
-// }
-
- // 其他情况按正常流程处理
- String newRoomId = intent.getStringExtra("roomId");
- String newPassword = intent.getStringExtra("password");
-
- if (!TextUtils.isEmpty(newRoomId) && !newRoomId.equals(roomId)) {
-// switchToRoom(newRoomId, newPassword);
- releaseRoom();
- startActivity(intent);
- finish();
- }
- }
-
- private void resumeRoomFromMinimize() {
- // 从最小化状态恢复房间
- isMinimized = false;
- clearMinimizeState();
-
- // 恢复房间状态
- resumeRoomState();
-
- // 确保UI正确显示
- if (mBinding != null) {
- // 恢复UI状态
- }
- }
-
- private View bgEffectView;
-
- private void setupEffectView() {
- bgEffectView = null;
- if (bgEffectView == null) {
- // 获取单例管理器
- QXGiftPlayerManager manager = QXGiftPlayerManager.getInstance(getApplicationContext());
-
- // 获取背景特效视图并添加到布局中
- bgEffectView = manager.getDefaultBgEffectView();
- // 找到 mBinding.svgaGift 的父容器
- ViewParent parent = mBinding.svgaGift.getParent();
- if (parent instanceof ViewGroup) {
- ViewGroup parentViewGroup = (ViewGroup) parent;
- // 检查 bgEffectView 是否已经有父视图
- ViewParent currentParent = bgEffectView.getParent();
- if (currentParent != null && currentParent instanceof ViewGroup) {
- // 如果已经有父视图,先从父视图中移除
- ((ViewGroup) currentParent).removeView(bgEffectView);
- }
-
- // 确保 bgEffectView 不为 null 并且没有父视图后再添加
- if (bgEffectView != null) {
- // 将 bgEffectView 添加为 mBinding.svgaGift 的兄弟视图
- // 添加到 mBinding.svgaGift 的父容器中,位置在 mBinding.svgaGift 之前
- parentViewGroup.addView(bgEffectView, parentViewGroup.indexOfChild(mBinding.svgaGift));
- }
-
- // 设置布局参数 - 填满父视图
- FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
- FrameLayout.LayoutParams.MATCH_PARENT,
- FrameLayout.LayoutParams.MATCH_PARENT
- );
- bgEffectView.setLayoutParams(params);
- } else {
- LogUtils.e("mBinding.svgaGift 没有有效的父容器");
- return;
- }
- // 获取全屏特效视图
- GiftAnimView fullEffectView = manager.getDefaultFullEffectView();
-
- // 设置全屏特效视图的布局参数 - 居中并设置尺寸
- FrameLayout.LayoutParams fullParams = new FrameLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT
- );
- fullParams.gravity = Gravity.CENTER;
- fullEffectView.setLayoutParams(fullParams);
-
- // 获取聊天特效视图
- GiftAnimView chatEffectView = manager.getDefaultChatEffectView();
-
- // 设置聊天特效视图的布局参数 - 底部居中并设置尺寸
- FrameLayout.LayoutParams chatParams = new FrameLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT
- );
- chatParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
- chatEffectView.setLayoutParams(chatParams);
- }
-
- // 从SharedPreferences获取是否关闭特效的设置
- boolean isClose = SpUtil.getOpenEffect() != 1;
- QXGiftPlayerManager.getInstance(getApplicationContext()).openOrCloseEffectViewWith(!isClose);
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
- // 拦截返回键,显示退出对话框而不是直接退出
- showExitRoomDialog();
- return true;
- }
- return false;
- }
-
- // 添加一个标记,用于判断用户是否主动离开应用
- private boolean userLeaving = false;
-
- @Override
- protected void onUserLeaveHint() {
- super.onUserLeaveHint();
- // 当用户主动离开应用时(例如按下Home键),设置标记
- userLeaving = true;
- }
-
- @Override
- protected void onPause() {
- super.onPause();
-
-// // 当RoomActivity进入后台时,不finish而是最小化
-// if (appStateListener!= null && appStateListener.isAppInBackground()) {
-// // 保持Activity alive,不调用finish()
-// minimizeToBackground();
-// }
- if (mRoomInfoResp != null) {
- if (!mRoomInfoResp.getRoom_info().getType_id().equals("6")) {
- // 只有在用户主动离开应用时才执行最小化操作
- if (!userLeaving) {
- // 保持Activity alive,不调用finish()
-
- minimizeToBackground();
- userLeaving = false; // 重置标记
- }
- }
- userLeaving = true;
- }
-
- }
-
- public void tob() {
- LinearLayout stub = mBinding.roomTop.stubButtons2;
- stub.setVisibility(VISIBLE);
- ImageView imActionJs = mBinding.roomTop.imActionJs.findViewById(R.id.im_action_js);
- ImageView imActionYs = mBinding.roomTop.imActionYs.findViewById(R.id.im_action_ys);
- if (imActionJs != null && imActionYs != null) {
- imActionJs.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dialogEnd();
- }
- });
- imActionYs.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- MvpPre.auctionDelay(SpUtil.getauctionId());
- }
- });
- }
-
- }
-
- public void upTop() {
- mBinding.roomTop.stubButtons2.setVisibility(GONE);
- }
-
- private void dialogEnd() {
- // 创建并显示确认对话框
- new ConfirmDialog(this,
- "提示",
- "您确定要结束本次拍卖吗?",
- "确认",
- "取消",
- v -> {
- // 点击“确认”按钮时执行删除操作
- MvpPre.auctionEnd(SpUtil.getauctionId(), roomId);
- },
- v -> {
- // 点击“取消”按钮时什么都不做
- }, false, 0).show();
- }
-
- public void upVisibility(boolean visible) {
- mBinding.roomTop.imActionJs.setVisibility(visible ? VISIBLE : INVISIBLE);
- mBinding.roomTop.imActionYs.setVisibility(visible ? VISIBLE : INVISIBLE);
- }
-
- public void upJs(boolean visible) {
- mBinding.roomTop.imActionJs.setVisibility(visible ? VISIBLE : INVISIBLE);
- }
-
- public void upYs(boolean visible) {
- mBinding.roomTop.imActionYs.setVisibility(visible ? VISIBLE : INVISIBLE);
- }
-
- /// 最小化
- private void showExitRoomDialog() {
- ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
- bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() {
- @Override
- public void onMinimize() {
- // 处理最小化逻辑,比如不销毁 Activity,仅移至后台
-// CommonAppContext.getInstance().isShow = false;
-// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
-// moveTaskToBack(true);
-
-// CommonAppContext.getInstance().isShow = false;
-// ARouter.getInstance().build(ARouteConstants.ME)
-// .navigation();
-// moveTaskToBack(true);
-
- // 处理最小化逻辑
- minimizeToBackground();
- }
-
- @Override
- public void onExitRoom() {
- // 调用退出房间方法
-// MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
-
- // 真正退出房间
- performExitRoom(1);
- }
-
- @Override
- public void onCancel() {
- // 用户点击取消,不做任何事
- }
- });
- bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
- addActiveDialogFragment(bottomSheet);
- }
-
- @Override
- public void onConfigurationChanged(@NonNull Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.vp_room_pager); // 替换为你实际的容器 ID
- if (currentFragment instanceof RoomCabinFragment) {
- ((RoomCabinFragment) currentFragment).onConfigurationChanged(newConfig);
- }
- }
-
- public void clearData() {
- publicScreenFragment.someMethod();
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void roomInfoEvent(SurfaceEvent surfaceView) {
- if (mRoomInfoResp.getRoom_info().getType_id().equals("6")) {//判断是否是电影房
- floatingMagnetView = findViewById(R.id.flaoat);//电影房
- if (mRoomInfoResp.getUser_info().getIs_room_owner() != 1) { //判断是不是房主,1:是 如何是,不展示 0不是,展示布局
- if (surfaceView.getType() != 1) {
-
- FrameLayout container = floatingMagnetView.findViewById(R.id.fl_screenshare);
-// mBinding.flaoat.setVisibility(GONE);//展示或不展示
- if (surfaceView == null) {
- runOnUiThread(() -> {
- mBinding.flaoat.setVisibility(GONE);
- container.removeAllViews();
- });
- } else {
- runOnUiThread(() -> {
- mBinding.flaoat.setVisibility(VISIBLE);
- container.removeAllViews();
- container.addView(surfaceView.getSurfaceView());
-// mBinding.flaoat.setVisibility(VISIBLE);
-// mBinding.flScreenshare.removeAllViews();
-// mBinding.flScreenshare.addView(surfaceView);
- });
- }
- } else {
- floatingMagnetView.setVisibility(GONE);
- }
- }
- }
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void hideInput(RoomInputHideEvent event) {
- if (event.hide) {
- mBinding.vpRoomPager.setScrollContainer(false);
- } else {
- mBinding.vpRoomPager.setScrollContainer(true);
- }
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void roomInfoEvent(ColoseCardEvent messageEvent) {
- mBinding.flaoat.setVisibility(GONE);
- }
-
- /**
- * 释放当前房间
- */
- private void releaseRoom() {
- AgoraManager.getInstance(this).cleanup();
-// RtcManager.getInstance().leaveChannel(roomId);
-// RtcManager.getInstance().setAudioUrl(null);
-// EMqttService.cleanSubscribeRoom(roomId);
- CommonAppContext.getInstance().isPlaying = false;
- CommonAppContext.getInstance().isShow = false;
- QXGiftPlayerManager.getInstance(getApplicationContext()).destroyEffectSvga();
- cleanupResources();
-// MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
- }
-
-// private SharedViewModel sharedViewModel;
- // 添加这个成员变量来跟踪房间数据是否已处理
-// private boolean isRoomDataProcessed = false;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- // 在super.onCreate之前设置主题以避免闪白屏
- setTheme(com.xscm.moduleutil.R.style.BaseAppTheme); // 设置你的主主题
- super.onCreate(savedInstanceState);
-// // 进入房间10s后检查是否显示提示上麦对话框
-
-// if (SpUtil.getMyRoomId() != null && !SpUtil.getMyRoomId().equals(roomId)) {
-//
-// MvpPre.quitRoom(SpUtil.getMyRoomId(), SpUtil.getUserId() + "");
-// QXGiftPlayerManager.getInstance(this).destroyEffectSvga();
-// }
-
- // 初始化数据库
-
- isSave = false;
- sDestroied = false;
- isMinimized = false;
- overridePendingTransition(0, 0); // 关闭转场动画
-
-
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
- sActivityRef = new WeakReference<>(this);
-
-
-// MessageListenerSingleton.getInstance().joinGroup(roomId);
- // 检查是否有保存的最小化状态
- checkAndRestoreMinimizeState();
- // 获取传递的房间数据
-// RoomInfoResp newRoomInfo = (RoomInfoResp) getIntent().getSerializableExtra("roomInfo");
-//
-// // 检查是否是重新创建的Activity且已经有房间数据
-// if (mRoomInfoResp != null && newRoomInfo != null &&
-// mRoomInfoResp.getRoom_info().getRoom_id().equals(newRoomInfo.getRoom_info().getRoom_id())) {
-// // 如果是同一个房间且已有数据,标记为数据已处理
-// isRoomDataProcessed = true;
-// } else if (newRoomInfo != null) {
-// // 更新房间数据
-// mRoomInfoResp = newRoomInfo;
-// isRoomDataProcessed = false;
-// }
-
-
- // 在子线程中执行网络请求
- performNetworkRequestsAsync();
- roomFragment = RoomFragment.newInstance();
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.vp_room_pager, roomFragment)
- .commitAllowingStateLoss();
- // 使用新的 OnBackPressedDispatcher API 来处理返回事件
- if (getOnBackPressedDispatcher() != null) {
- getOnBackPressedDispatcher().addCallback(this, new androidx.activity.OnBackPressedCallback(true) {
- @Override
- public void handleOnBackPressed() {
- // 拦截返回键,显示退出对话框而不是直接退出
- showExitRoomDialog();
- }
- });
- }
-
- // 获取Application实例并设置监听器
- CommonAppContext app = (CommonAppContext) getApplication();
- appStateListener = AppStateManager.getInstance();
- app.setAppStateListener(appStateListener);
-
- // 通知RoomActivity已创建
- if (appStateListener != null) {
- appStateListener.onRoomActivityCreated(this);
- }
-
- // 获取 ViewModel
-// sharedViewModel = new ViewModelProvider(this).get(SharedViewModel.class);
-
- // 处理房间数据
-// handleRoomData();
- SpUtil.saveMyRoomId(roomId);
- // 检查是否从最小化状态恢复
- if (isMinimized) {
- // 恢复房间状态
- resumeRoomState();
- }
-
- // 在子线程中执行网络请求
-// performNetworkRequestsAsync();
-// roomFragment = RoomFragment.newInstance();
-//// roomFragment.setqxRoomSeatViewType(QXRoomSeatViewType.NONE);
-// getSupportFragmentManager()
-// .beginTransaction()
-// .replace(R.id.vp_room_pager, roomFragment)
-// .commitAllowingStateLoss();
-// // 使用新的 OnBackPressedDispatcher API 来处理返回事件
-// if (getOnBackPressedDispatcher() != null) {
-// getOnBackPressedDispatcher().addCallback(this, new androidx.activity.OnBackPressedCallback(true) {
-// @Override
-// public void handleOnBackPressed() {
-// // 拦截返回键,显示退出对话框而不是直接退出
-// showExitRoomDialog();
-// }
-// });
-// }
-//
-// // 获取Application实例并设置监听器
-// CommonAppContext app = (CommonAppContext) getApplication();
-// appStateListener = AppStateManager.getInstance();
-// app.setAppStateListener(appStateListener);
-//
-// // 通知RoomActivity已创建
-// if (appStateListener != null) {
-// appStateListener.onRoomActivityCreated(this);
-// }
-// // 获取传递的房间数据
-// RoomInfoResp newRoomInfo = (RoomInfoResp) getIntent().getSerializableExtra("roomInfo");
-//
-// // 检查是否是重新创建的Activity且已经有房间数据
-// if (mRoomInfoResp != null && newRoomInfo != null &&
-// mRoomInfoResp.getRoom_info().getRoom_id().equals(newRoomInfo.getRoom_info().getRoom_id())) {
-// // 如果是同一个房间且已有数据,标记为数据已处理
-// isRoomDataProcessed = true;
-// } else if (newRoomInfo != null) {
-// // 更新房间数据
-// mRoomInfoResp = newRoomInfo;
-// isRoomDataProcessed = false;
-// }
-//// if (mRoomInfoResp != null){
-//// setview(mRoomInfoResp);
-//// }
-//
-// // 获取 ViewModel
-// sharedViewModel = new ViewModelProvider(this).get(SharedViewModel.class);
-// // 只有在数据未处理时才观察Fragment状态
-// if (!isRoomDataProcessed) {
-// sharedViewModel.getFragmentReady().observe(this, isReady -> {
-// if (Boolean.TRUE.equals(isReady) && mRoomInfoResp != null) {
-// // Fragment 已就绪且有等待中的数据,发送数据
-// sharedViewModel.setDataForFragment(mRoomInfoResp);
-// setview(mRoomInfoResp);
-// isRoomDataProcessed = true; // 标记为已处理
-// }
-// });
-// } else if (mRoomInfoResp != null) {
-// // 如果数据已经处理过,直接设置视图
-//// setview(mRoomInfoResp);
-// MvpPre.postRoomInfo(roomId);
-// }
-// SpUtil.saveMyRoomId(roomId);
- }
-
- /**
- * 处理房间数据,避免重复初始化
- */
- private void handleRoomData() {
- // 确保sharedViewModel不为null
-// if (sharedViewModel == null) {
-// sharedViewModel = new ViewModelProvider(this).get(SharedViewModel.class);
-// }
-// if (!isRoomDataProcessed) {
-// sharedViewModel.getFragmentReady().observe(this, isReady -> {
-// if (Boolean.TRUE.equals(isReady) && mRoomInfoResp != null) {
-// // Fragment 已就绪且有等待中的数据,发送数据
-// sharedViewModel.setDataForFragment(mRoomInfoResp);
-// setview(mRoomInfoResp);
-// isRoomDataProcessed = true; // 标记为已处理
-// }
-// });
-// } else if (mRoomInfoResp != null) {
-// // 如果数据已经处理过,直接更新视图而不是重新初始化
-// MvpPre.postRoomInfo(roomId);
-// }
- }
-
- private void setview(RoomInfoResp resp) {
- this.mRoomInfoResp = resp;
- RoomBean roomBean = resp.getRoom_info();
- this.mRoomBean = roomBean;
- this.mRoomUserBean = resp.getUser_info();
- this.mRoomOwnerBean = resp.getRoom_owner();
- this.mPitList = mRoomBean.getPit_list();
-
- CommonAppContext.getInstance().isPlaying = true;
- CommonAppContext.getInstance().playId = roomId;
- CommonAppContext.getInstance().playName = mRoomBean.getRoom_name();
-
- CommonAppContext.getInstance().playCover = resp.getRoom_info().getRoom_cover();
- CommonAppContext.getInstance().showSelf = resp.getIs_show_self() == 1;
-
- ImageUtils.loadHeadCC(resp.getRoom_info().getRoom_cover(), mBinding.roomTop.avatar);
- mBinding.roomTop.name.setText(roomBean.getRoom_name());
- mBinding.roomTop.idVal.setText("ID:" + roomBean.getRoom_number());
- if (mRoomUserBean.getIs_room_owner() == 1) {
- mBinding.roomTop.btnFollow.setVisibility(GONE);
- } else {
- mBinding.roomTop.btnFollow.setVisibility(VISIBLE);
- if (resp.isCollect()) {
- mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.collected));
- mBinding.roomTop.btnFollow.setText("");
- }
- }
- number = roomBean.getOnline_number();
- mBinding.roomTop.tvNum.setText(number + "");
-
- StringBuilder userIds = new StringBuilder();
- for (int i = 0; i < mRoomInfoResp.getRoom_info().getPit_list().size(); i++) {
- String userId = mRoomInfoResp.getRoom_info().getPit_list().get(i).getUser_id();
- if (userId != null && !userId.equals("0") && !userId.isEmpty()) {
- if (userIds.length() > 0) {
- userIds.append(",");
- }
- userIds.append(userId);
- }
- }
- initPublicScreenFragment();
- // 确保Fragment已完全初始化后再调用getUpRoomInfo
- if (publicScreenFragment != null && publicScreenFragment.isAdded() && publicScreenFragment.getView() != null) {
- publicScreenFragment.getUpRoomInfo(resp);
- }
- if (!isFinishing() && !isDestroyed()) {
- resetFragment();
- upHeight();
- } else {
- Log.e("Fragment", "Fragment transaction skipped due to state loss.");
- }
-
- if (mRoomUserBean.getIs_collect() == 1) {
- mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.yishouc));
- mBinding.roomTop.btnFollow.setText("");
- } else {
- ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.roomTop.btnFollow, ColorManager.getInstance().getPrimaryColorInt(), 53);
- mBinding.roomTop.btnFollow.setTextColor(ColorManager.getInstance().getButtonColorInt());
- mBinding.roomTop.btnFollow.setText("收藏");
- }
- if ((roomBean.getType_id().equals("3") || roomBean.getType_id().equals("1") || roomBean.getType_id().equals("4")) && roomBean.getLabel_id().equals("2")) {
- AgoraManager.getInstance(this).setBjMusic(false);
- } else {
- AgoraManager.getInstance(this).setBjMusic(true);
- }
-
- AgoraManager.getInstance(this).stopMuisc();
- initializeAudio();
-
-
- toutiao();
- upRoomInfo(resp);
-
-
- if (userIds.length() > 0 && roomId != null) {
-// MvpPre.userOnlineStatus(userIds.toString(), roomId);
- }
-//
-// // 延迟调用getUpRoomInfo,确保Fragment视图已创建
-// mBinding.getRoot().post(new Runnable() {
-// @Override
-// public void run() {
-// if (publicScreenFragment != null) {
-// publicScreenFragment.getUpRoomInfo(resp);
-// }
-// }
-// });
-
- instView();
-
- if (mRoomInfoResp.getUser_info().getPit_number() == 9 && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId() + "")) {
- mBinding.roomTop.rl.setVisibility(View.VISIBLE);
- ivSoundEffects(true);
- } else {
- mBinding.roomTop.rl.setVisibility(View.GONE);
- ivSoundEffects(false);
- }
-
- if (mRoomInfoResp.getRoom_info().getType_id().equals("7") || mRoomInfoResp.getRoom_info().getType_id().equals("2")) {
- mBinding.rlMore.setVisibility(GONE);
- mBinding.rlMisc.setVisibility(GONE);
- }
- setupEffectView();
-
- // 使用Handler延迟执行,确保Fragment视图已完全创建
- new Handler(Looper.getMainLooper()).post(new Runnable() {
- @Override
- public void run() {
- if (publicScreenFragment != null && publicScreenFragment.isAdded() && publicScreenFragment.getView() != null) {
- publicScreenFragment.getUpRoomInfo(resp);
- }
- }
- });
- }
-
- private void checkAndRestoreMinimizeState() {
- SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
- boolean isMinimized = prefs.getBoolean("is_minimized", false);
-
- if (isMinimized) {
- isMinimized = true;
- // 检查最小化时间,如果太久可能需要重新登录
- long minimizeTime = prefs.getLong(PREF_MINIMIZED_TIME, 0);
- long currentTime = System.currentTimeMillis();
-
- // 如果最小化超过一定时间(如30分钟),可能需要重新验证
- if (currentTime - minimizeTime > 30 * 60 * 1000) {
- // 清理过期的最小化状态
- clearMinimizeState();
- isMinimized = false;
- }
- } else {
- isMinimized = false;
- }
- }
-
- /**
- * 在子线程中执行网络请求,避免阻塞主线程
- */
- private void performNetworkRequestsAsync() {
- ThreadUtils.executeByIo(new ThreadUtils.SimpleTask() {
- @Override
- public Void doInBackground() throws Throwable {
- // 在后台线程执行网络请求前的准备工作
- // 例如:检查缓存、预处理数据等
-// prepareNetworkRequest();
- return null;
- }
-
- @Override
- public void onSuccess(Void result) {
- // 切换到主线程执行实际的网络请求
- runOnUiThread(() -> {
- // 使用Handler确保在主线程中调用
-// MvpPre.getRoomIn(roomId, password);
- if (mRoomInfoResp == null) {
- // 使用Handler确保在主线程中调用
- MvpPre.getRoomIn(roomId, password);
- }
- MvpPre.getRoomOnline(roomId, "1", "10");
- });
- }
-
- @Override
- public void onFail(Throwable e) {
- LogUtils.e("Network request preparation failed: " + e.getMessage());
- // 即使准备失败,也尝试执行网络请求
- runOnUiThread(() -> {
-// MvpPre.getRoomIn(roomId, password);
- // 检查是否已经有房间信息,如果有则不需要再次获取
- if (mRoomInfoResp == null) {
- MvpPre.getRoomIn(roomId, password);
- }
- MvpPre.getRoomOnline(roomId, "1", "10");
- });
- }
- });
- }
-
-
- // 提供安全的访问方法
- public static RoomActivity getCurrentActivity() {
- return sActivityRef != null ? sActivityRef.get() : null;
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onRoomTaskEvent(RoomTaskEvent event) {
- if (taskId != null && !taskId.equals("9")) {//这是每日任务完成发送私聊信息的事件
- RetrofitClient.getInstance().dailyTasksComplete(taskId, new BaseObserver() {
- @Override
- public void onSubscribe(Disposable d) {
- }
-
- @Override
- public void onNext(RoomSingleton roomSingleton) {
- number++;
- // 这里处理请求结果
- if (roomSingleton.getIs_completed() == 1) {
- // 任务完成,可以做一些后续操作
- taskId = null;
- }
- }
- });
- }
- }
-
- @Override
- protected void initView() {
- super.initView();
- floatingMagnetView = findViewById(R.id.flaoat);
- ivQuan = findViewById(R.id.iv_quan);
- fullScreenContainer = findViewById(R.id.fullscreen_container); // 自定义全屏容器
- ivExitFullscreen = findViewById(R.id.iv_exit_fullscreen);
- ivQuan.setOnClickListener(v -> toggleFullScreen());
- ivExitFullscreen.setOnClickListener(v -> exitFullScreen());
-
- LogUtils.e("lxj", "开始时间:" + TimeUtils.date2String(new Date()));
-
- if (taskId != null) {
- if (taskId.equals("9")) {
- MyRoomSingleton.getInstance().onEnterRoom(taskId);
- }
- }
- circularProgress = mBinding.giftShowProgress;
- circularProgress.setProgress(0);
- mBinding.giftShowLayout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onGiftGiveProgressClcik();
- LogUtils.e("xj", "onSubscribe2222");
- }
- });
-
- ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.roomTop.btnFollow, ColorManager.getInstance().getPrimaryColorInt(), 53);
- mBinding.roomTop.btnFollow.setTextColor(ColorManager.getInstance().getButtonColorInt());
- initPublicScreenFragment();
-// stub = mBinding.roomTop.stubButtons.getViewStub();
-
- // 为透明 View 设置触摸监听
- mBinding.roomTop.rlTop.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- // 将触摸事件透传给下层的 View
- return false; // 返回 false,表示不拦截事件
- }
- });
-
- ViewGroup.LayoutParams layoutParams = mBinding.roomTop.getRoot().getLayoutParams();
- layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; // 使用你定义的getWidth方法
- layoutParams.height = SystemUtils.getWidth(74); // 示例高度
- mBinding.roomTop.getRoot().setLayoutParams(layoutParams);
-// MP4PlaybackCallback mp4PlaybackCallback=MP4PlaybackCallback.getInstance();
-// mp4PlaybackCallback.setAvatarFrameView(mBinding.svgaGift);
-// mBinding.svgaGift.setAnimListener(mp4PlaybackCallback);
-
- mBinding.xlhIm.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- FragmentManager fm = getSupportFragmentManager();
- if (fm != null && !fm.isDestroyed()) {
- TourClubDialogFragment newDialog = TourClubDialogFragment.newInstance(
- roomId);
- newDialog.show(fm, "TourClubDialogFragment");
- }
- }
- });
- }
-
- private void onGiftGiveProgressClcik() {
- if (giftGiveEvent == null || giftGiveEvent.roonGiftModel == null) {
- return;
- }
-
- if (giftGiveEvent.auction_id != null && !giftGiveEvent.auction_id.isEmpty()) {
- RetrofitClient.getInstance().roomAuctionJoin(giftGiveEvent.getAuction_id(), giftGiveEvent.getUserId(), giftGiveEvent.getRoonGiftModel().getGift_id(), giftGiveEvent.getNum(), "1", new BaseObserver() {
- @Override
- public void onSubscribe(Disposable d) {
-// showGiftGiveProgress();
- }
-
- @Override
- public void onNext(RoomAuction.AuctionListBean auctionListBean) {
- showGiftGiveProgress();
- }
-
- @Override
- public void onError(Throwable e) {
- super.onError(e);
- String msg = e.getMessage();
- if (!TextUtils.isEmpty(msg) && msg.contains("当前余额不足")) {
- com.hjq.toast.ToastUtils.show("当前余额不足,请充值");
- ThreadUtils.runOnUiThreadDelayed(() -> {
- RechargeDialogFragment fragment = RechargeDialogFragment.show(roomId, null, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- }, 1400);
- }
- hideGiftGiveProgress();
- }
-
-
- });
- } else {
-
- RetrofitClient.getInstance().roomGift(giftGiveEvent.getRoom_id(), giftGiveEvent.getRoonGiftModel().getGift_id(), giftGiveEvent.getNum(), giftGiveEvent.getUserId(), "1", giftGiveEvent.getPit(), giftGiveEvent.heart_id, new BaseObserver() {
- @Override
- public void onSubscribe(Disposable d) {
-// showGiftGiveProgress();
-// LogUtils.e("xj", "onSubscribe");
-
- }
-
- @Override
- public void onNext(String s) {
- showGiftGiveProgress();
- }
-
- @Override
- public void onError(Throwable e) {
- super.onError(e);
- String msg = e.getMessage();
- if (!TextUtils.isEmpty(msg) && msg.contains("当前余额不足")) {
- com.hjq.toast.ToastUtils.show("当前余额不足,请充值");
- ThreadUtils.runOnUiThreadDelayed(() -> {
- RechargeDialogFragment fragment = RechargeDialogFragment.show(roomId, null, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- }, 1400);
- }
- hideGiftGiveProgress();
- }
- });
- }
- }
-
- private RoomGiftGiveEvent giftGiveEvent;
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void roomGiveGiftEvent(RoomGiftGiveEvent event) {
- if (isFinishing() || event == null || event.roonGiftModel == null) {
- return;
- }
- giftGiveEvent = event;
- showGiftGiveProgress();
- }
-
- private int giftProgress = 0;
- private CountDownTimer giftCountTimer;
-
- private void startGiftProgressTime() {
- giftProgress = 0;
- if (giftCountTimer != null) {
- giftCountTimer.cancel();
- }
- LogUtils.e("xj2", "onSubscribe");
- giftCountTimer = new CountDownTimer(1000 * 10, 50) {
-
- @Override
- public void onTick(long millisUntilFinished) {
- if (!isFinishing()) {
- circularProgress.setProgress(1000 - (int) (millisUntilFinished / 10));
- }
- }
-
- @Override
- public void onFinish() {
- circularProgress.setProgress(1000);
- hideGiftGiveProgress();
- }
- };
- giftCountTimer.start();
- }
-
- private void showGiftGiveProgress() {
- ImageUtils.loadImageView(giftGiveEvent.roonGiftModel.getBase_image(), mBinding.giftShowProgressImg);
- circularProgress.setProgress(1000);// 显示进度条,2025年7月19日11:23:37将这个从下面的方法提起到这里,
- startGiftProgressTime();
- mBinding.giftShowLayout.setVisibility(View.VISIBLE);
- }
-
- private void hideGiftGiveProgress() {
- mBinding.giftShowLayout.setVisibility(View.GONE);
- if (giftCountTimer != null) {
- giftCountTimer.cancel();
- giftCountTimer = null;
- }
- }
-
- private void toggleFullScreen() {
- if (isFullScreen) {
- exitFullScreen();
- } else {
-// enterFullScreen();
-
- // 修改为横屏展示模式而不是全屏模式
- enterLandscapeMode();
- }
- }
-
- private void enterLandscapeMode() {
- isFullScreen = true;
-
- // 设置横屏
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
-
- if (floatingMagnetView != null) {
- // 修改Floa组件的布局参数,使其在横屏时占据更大区域
- ViewGroup.LayoutParams layoutParams = floatingMagnetView.getLayoutParams();
- if (layoutParams instanceof ConstraintLayout.LayoutParams) {
- ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) layoutParams;
- params.width = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT;
- params.height = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT;
- params.horizontalBias = 0.5f;
- params.verticalBias = 0.5f;
- floatingMagnetView.setLayoutParams(params);
- } else {
- // 如果不是ConstraintLayout.LayoutParams,创建新的
- ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(
- ConstraintLayout.LayoutParams.MATCH_CONSTRAINT,
- ConstraintLayout.LayoutParams.MATCH_CONSTRAINT
- );
- params.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
- params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
- params.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
- params.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
- floatingMagnetView.setLayoutParams(params);
- }
-
- // 可以调整内部fl_screenshare的布局参数
- FrameLayout flScreenshare = floatingMagnetView.findViewById(R.id.fl_screenshare);
- ViewGroup.LayoutParams screenParams = flScreenshare.getLayoutParams();
- if (!(screenParams instanceof FrameLayout.LayoutParams)) {
- // 如果不是FrameLayout.LayoutParams,创建新的
- FrameLayout.LayoutParams newScreenParams = new FrameLayout.LayoutParams(
- FrameLayout.LayoutParams.MATCH_PARENT,
- FrameLayout.LayoutParams.MATCH_PARENT
- );
- flScreenshare.setLayoutParams(newScreenParams);
- } else {
- FrameLayout.LayoutParams newScreenParams = (FrameLayout.LayoutParams) screenParams;
- newScreenParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
- newScreenParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
- flScreenshare.setLayoutParams(newScreenParams);
- }
-
- // 显示退出按钮
- ivQuan.setVisibility(View.VISIBLE);
- }
- }
-
- private void enterFullScreen() {
- isFullScreen = true;
-
-
- // 隐藏系统UI
- View decorView = getWindow().getDecorView();
- decorView.setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_FULLSCREEN
- | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
- );
-
- // 设置横屏
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- // 找到 fl_screenshare 并移到全屏容器中
- FrameLayout fl_screenshare = findViewById(R.id.fl_screenshare);
- if (fl_screenshare != null) {
-// // 先从当前父容器中移除
-// ViewParent parent = fl_screenshare.getParent();
-// if (parent != null && parent instanceof ViewGroup) {
-// ((ViewGroup) parent).removeView(fl_screenshare);
-// }
-//
-// // 添加到全屏容器
-// fullScreenContainer.addView(fl_screenshare);
-
- safelyMoveViewToParent(fl_screenshare, floatingMagnetView);
- // 显示全屏容器
- fullScreenContainer.setVisibility(View.VISIBLE);
- floatingMagnetView.setVisibility(View.GONE);
- ivExitFullscreen.setVisibility(View.VISIBLE); // 显示退出按钮
- }
- }
-
- private void exitFullScreen() {
-
- isFullScreen = false;
-
- // 设置回竖屏
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
-
- if (floatingMagnetView != null) {
- // 恢复原始尺寸
- ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(
- getResources().getDimensionPixelSize(com.xscm.moduleutil.R.dimen.dp_240),
- getResources().getDimensionPixelSize(com.xscm.moduleutil.R.dimen.dp_135)
- );
- params.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
- params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
- params.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
- params.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
- floatingMagnetView.setLayoutParams(params);
-
- // 恢复内部fl_screenshare的布局参数
- FrameLayout flScreenshare = floatingMagnetView.findViewById(R.id.fl_screenshare);
- FrameLayout.LayoutParams screenParams = new FrameLayout.LayoutParams(
- FrameLayout.LayoutParams.MATCH_PARENT,
- FrameLayout.LayoutParams.MATCH_PARENT
- );
- flScreenshare.setLayoutParams(screenParams);
- }
-
- // 隐藏退出按钮
- ivExitFullscreen.setVisibility(View.GONE);
-
-
-// isFullScreen = false;
-// // 恢复系统UI
-// View decorView = getWindow().getDecorView();
-//// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
-// decorView.setSystemUiVisibility(
-// View.SYSTEM_UI_FLAG_FULLSCREEN
-// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
-// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
-// );
-// // 设置回竖屏
-// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
-// // 找到 fl_screenshare 并移回原父容器
-// FrameLayout fl_screenshare = findViewById(R.id.fl_screenshare);
-// if (fl_screenshare != null) {
-// safelyMoveViewToParent(fl_screenshare, fullScreenContainer);
-//// ViewParent parent = fl_screenshare.getParent();
-//// if (parent instanceof ViewGroup) {
-//// ((ViewGroup) parent).removeView(fl_screenshare);
-//// }
-//// // 添加到全屏容器
-//// fullScreenContainer.addView(fl_screenshare);
-// // 找到原始父容器并重新添加
-//// FrameLayout originalParent = findViewById(R.id.fullscreen_container); // 或者你实际的容器
-//// if (originalParent != null) {
-//// originalParent.removeView(fl_screenshare); // 防止重复添加
-//// }
-//
-//// floatingMagnetView.addView(fl_screenshare);
-// }
-// // 恢复界面
-// fullScreenContainer.setVisibility(View.GONE);
-// floatingMagnetView.setVisibility(View.VISIBLE);
-// ivQuan.setVisibility(View.VISIBLE);
-// ivExitFullscreen.setVisibility(View.GONE); // 隐藏退出按钮
- }
-
- @Override
- protected void initData() {
-
-
- if (!EasyPermissions.hasPermissions(this, permissions)) {
- EasyPermissions.requestPermissions(this, "请开启录音使用权限",
- 1, permissions);
- }
-
- mBinding.roomTop.btnFollow.setOnClickListener(this::onClick);
- mBinding.roomTop.btnNotice.setOnClickListener(this::onClick);
- mBinding.roomTop.btnRanking.setOnClickListener(this::onClick);
- mBinding.roomTop.btnCloseLive.setOnClickListener(this::onClick);
- mBinding.roomTop.tvNum.setOnClickListener(this::onClick);
- mBinding.roomTop.rl.setOnClickListener(this::onClick);
- mBinding.ivSoundEffects.setOnClickListener(this::onClick);
- mBinding.ivWheatFeeding.setOnClickListener(this::onClick);
- mBinding.clFirstCharge.setOnClickListener(this::onClick);
- mBinding.roomTop.userRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
- likeUserAdapter = new LikeUserAdapter<>();
- mBinding.roomTop.userRecyclerView.setAdapter(likeUserAdapter);
- likeUserAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
- @Override
- public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
-// RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
- RoomOnlineDialogFragment fragment = RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- }
- });
-
-// PublicScreenEaseChatFragment fragment = PublicScreenEaseChatFragment.newInstance();
-// getSupportFragmentManager().beginTransaction().replace(R.id.ease_container, fragment).commitAllowingStateLoss();
-
-
- mBinding.ivChat.setOnClickListener(this::onClick);
- mBinding.llInput.setOnClickListener(this::onClick);
- mBinding.rlMisc.setOnClickListener(this::onClick);
- mBinding.rlGift.setOnClickListener(this::onClick);
- mBinding.rlMic.setOnClickListener(this::onClick);
- mBinding.rlSett.setOnClickListener(this::onClick);
- mBinding.rlVoive.setOnClickListener(this::onClick);
- mBinding.rlMore.setOnClickListener(this::onClick);
- mBinding.rlMessage.setOnClickListener(this::onClick);
-
-// SpUtil.saveMyRoomId(roomId);
-// MvpPre.getRoomIn(roomId, password);
-// MvpPre.getRoomOnline(roomId, "1", "10");
- mBinding.inputMenu1.performClick();
-
- V2TIMManager.getConversationManager().getTotalUnreadMessageCount(new V2TIMValueCallback() {
- @Override
- public void onSuccess(Long aLong) {
- if (aLong == 0) {
- mBinding.ivMessageDot.setVisibility(View.GONE);
- mBinding.ivMessageDot.setText("0");
- } else {
- mBinding.ivMessageDot.setVisibility(View.VISIBLE);
- }
- mBinding.ivMessageDot.setText(String.valueOf(aLong));
- }
-
- @Override
- public void onError(int code, String desc) {
-
- }
- });
-
- mBinding.roomTop.getRoot().setClickable(false);
- mBinding.roomTop.getRoot().setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-// ToastUtils.showShort("点击了房间,事件穿透");
-
- }
- });
-// if (mRoomInfoResp!=null){
-// setview(mRoomInfoResp);
-// }
- }
-
-
- private void initPublicScreenFragment() {
- // 检查是否已经存在 Fragment 实例(例如在配置更改后)
- publicScreenFragment = (PublicScreenEaseChatFragment) getSupportFragmentManager()
- .findFragmentById(R.id.ease_container);
-
- // 如果不存在,则创建新的实例
- if (publicScreenFragment == null) {
- publicScreenFragment = PublicScreenEaseChatFragment.newInstance(roomId);
- getSupportFragmentManager().beginTransaction()
- .replace(R.id.ease_container, publicScreenFragment)
- .commitAllowingStateLoss();
- }
- }
-
- // 在类成员变量中添加
- private android.os.Handler roomSwitchHandler = new android.os.Handler(Looper.getMainLooper());
- private Runnable roomSwitchRunnable;
- private String pendingRoomId;
- private String lastSwitchedRoomId = "";
-
- public void roomInfoEvent(RoomMessageEvent messageEvent) {
- if (messageEvent == null) return;
- if (roomFragment == null) {
- roomFragment = RoomFragment.newInstance();
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.vp_room_pager, roomFragment)
- .commitAllowingStateLoss();
- }
-
- int msgType = messageEvent.getMsgType();
- RoomMessageEvent.T text = messageEvent.getText();
-
- if (msgType == 1005) {
- LogUtils.e("@@@@" + "EventBusnujm2" + "playQueue.size()====" + messageEvent.getText().getGiftInfo());
- List playQueue = Arrays.asList(messageEvent.getText().getGiftInfo().getPlay_image().split(","));
- QXGiftPlayerManager.getInstance(this).displayFullEffectView1(playQueue);
-
- hand1005(messageEvent, text);
- } else if (msgType == 123) {
- EventBus.getDefault().post(new RoomSettingEvent());
- } else if (msgType == 1014) {
- handleMsgType1014(messageEvent, text);
- } else if (msgType == 1013) {
- handleMsgType1013(messageEvent, text);
- } else if (msgType == 1012) {
- handleMsgType1012();
- } else if (msgType == 124) {
- handleMsgType124(messageEvent, text);
- } else if (msgType == 1003) {
- handleMsgType1003(messageEvent, text);
- } else if (msgType == 1004) {
- handleMsgType1004(messageEvent, text);
- } else if (msgType == 1022) {
- handleMsgType1022(messageEvent, text);
- } else if (msgType == 1023) {
- handleMsgType1023(messageEvent, text);
- } else if (msgType == 1024) {
- handleMsgType1024(messageEvent, text);
- } else if (msgType == 1025) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if (msgType == 1026) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if (msgType == 1027) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if (msgType == 1020) {
- handleMsgType1020(messageEvent, text);
- } else if (msgType == 1011) {
- handleMsgType1011(messageEvent, text);
- } else if (msgType == 1001) {
- handleMsgType1001();
- } else if (msgType == 1002) {
- handleMsgType1002();
- } else if (msgType == 1029) {
- handleMsgType1029(messageEvent, text);
- } else if (msgType == 1021) {
- handleMsgType1021(messageEvent, text);
- } else if (msgType == 1036) {
- handleMsgType1036(messageEvent, text);
- } else if (msgType == 1049) {
- handleMsgType1049(messageEvent, text);
- } else if (msgType == 1050) {
- handleMsgType1050(messageEvent, text);
- } else if (msgType == 1051) {
- handleMsgType1051(messageEvent, text);
- } else if (msgType == 1052) {
- roomFragment.upCabinFragment(text.getTime_day());
- } else if (msgType == 1053) {
- handleMsgType1053(messageEvent, text);
- } else if (msgType == 1054) {
- handleMsgType1054(messageEvent, text);
- } else if (msgType == 1055) {
- handleMsgType1055(messageEvent);
- } else if (msgType == 1035) {
- handleMsgType1035(messageEvent, text);
- } else if (msgType == 1030 || msgType == 1031 || msgType == 1032 || msgType == 1033 || msgType == 1015 || msgType == 1037) {
-
- roomFragment.SingSongEvent(messageEvent);
- if (msgType == 1032 || msgType == 1033) {
- setRoleType(3, -11);
- }
- } else if (msgType == 125) {
- handleMsgType125(messageEvent, text);
- }else if (msgType==1006){
- handleMsgType1006();
- } else if (msgType == 1007) {
- handleMsgType1007();
- }else if (msgType == 1017){
- handleMsgType1017();
- }
- else if (msgType == 1018) {
- handleMsgType1018();
- } else if (msgType == 126) {
- handleMsgType126(messageEvent, text);
- } else if (msgType == 1034) {
- handleMsgType1034(messageEvent, text);
- } else if (msgType == 1016) {
- handleMsgType1016(messageEvent, text);
- } else if (msgType == 1039) {
- handleMsgType1039(messageEvent, text);
- } else if (msgType == 1028) {
- roomFragment.handleMsgType1028(messageEvent);
- } else if (msgType == 1058) {
- if (mRoomInfoResp != null && mRoomInfoResp.getRoom_info() != null) {
- if (mRoomInfoResp.getRoom_info().getType_id().equals("1") || mRoomInfoResp.getRoom_info().getType_id().equals("3") ||
- mRoomInfoResp.getRoom_info().getType_id().equals("4") || mRoomInfoResp.getRoom_info().getType_id().equals("8")) {
- if (mRoomInfoResp.getRoom_info().getLabel_id().equals("1")) {
- roomFragment.SingSongEvent(messageEvent);
- } else {
- roomFragment.KtvFragmentEvent(messageEvent);
- }
- } else if (mRoomInfoResp.getRoom_info().getType_id().equals("2")) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if (mRoomInfoResp.getRoom_info().getType_id().equals("7")) {
- roomFragment.friendshipRoomFragmentEvent(messageEvent);
- }
- }
- } else if (msgType == 1059) {// 1059清除个人魅力 1058在离线
- if (mRoomInfoResp != null && mRoomInfoResp.getRoom_info() != null) {
- if (mRoomInfoResp.getRoom_info().getType_id().equals("1") || mRoomInfoResp.getRoom_info().getType_id().equals("3") ||
- mRoomInfoResp.getRoom_info().getType_id().equals("4") || mRoomInfoResp.getRoom_info().getType_id().equals("8")) {
- if (mRoomInfoResp.getRoom_info().getLabel_id().equals("1")) {
- roomFragment.SingSongEvent(messageEvent);
- } else {
- roomFragment.KtvFragmentEvent(messageEvent);
- }
- } else if (mRoomInfoResp.getRoom_info().getType_id().equals("2")) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if (mRoomInfoResp.getRoom_info().getType_id().equals("7")) {
- roomFragment.friendshipRoomFragmentEvent(messageEvent);
- }
- }
- } else if (msgType == 1056) {// 1056 抽奖结果
- GiftLotteryDialog dialog = (GiftLotteryDialog) getSupportFragmentManager()
- .findFragmentByTag("GiftLotteryDialog");
- if (dialog != null && dialog.isVisible()) {
- dialog.UpView(messageEvent.getText().getXlh_data());
- } else {
- EventBus.getDefault().post(messageEvent.getText().getXlh_data());
- }
-
- if (messageEvent.getText().getXlh_data() != null) {
- if (messageEvent.getText().getXlh_data().getStatus() == 1) {
- mBinding.xlhRk.setVisibility(View.VISIBLE);
- xlhDjs(messageEvent.getText().getXlh_data().getEnd_time());
- } else {
- mBinding.xlhRk.setVisibility(INVISIBLE);
- releaseCountDownTimer1();
- }
- }
-
- } else if (msgType == 1057) {
- TourClubDialogFragment existingFragment = (TourClubDialogFragment) getSupportFragmentManager().findFragmentByTag("TourClubDialogFragment");
- if (existingFragment != null && existingFragment.isVisible()) {
- existingFragment.onMusicPlay(messageEvent);
- } else {
- LogUtils.e("TourClubDialogFragment", "巡乐会界面未打开");
- EventBus.getDefault().post(messageEvent);
- }
- xlhDjs(messageEvent.getText().getEnd_time());
-// if (messageEvent.getText().getXlh_data() != null) {
-// if (messageEvent.getText().getXlh_data().getStatus() == 1) {
-// mBinding.xlhRk.setVisibility(View.VISIBLE);
-// xlhDjs(messageEvent.getText().getEnd_time());
-// } else {
-// mBinding.xlhRk.setVisibility(View.GONE);
-// releaseCountDownTimer1();
-// }
-// }
-
- }
- }
-
- private long endTime;
-
- private void xlhDjs(String endTimeStr) {
- // 获取结束时间并启动倒计时
- if (endTimeStr != null && !endTimeStr.isEmpty()) {
- try {
- // 假设 end_time 是时间戳字符串
- endTime = Long.parseLong(endTimeStr);
- countDownTime(endTime);
- } catch (NumberFormatException e) {
- // 如果不是时间戳,可能是日期字符串,需要相应解析
- // 例如:2025-08-26 19:10:47
- // 可以使用 SimpleDateFormat 解析
- e.printStackTrace();
- }
- }
- }
-
- public void countDownTime(long time) {
- try {
- if (time <= 0) {
- setTime(0);
-
- releaseCountDownTimer1();
- return;
- }
- releaseCountDownTimer1();
- // 获取当前时间的毫秒值
- long currentTime = System.currentTimeMillis() / 1000L;
- // 计算倒计时的总秒数
- long countDownTime = (time - currentTime);
- Logger.d("@@@", "countDownTime = " + countDownTime);
- if (countDownTime <= 0) {
- setTime(0);
- releaseCountDownTimer1();
- return;
- }
- mCountDownTimer2 = new CountDownTimer(countDownTime * 1000L, 1000L) {
- @Override
- public void onTick(long millisUntilFinished) {
- int time1 = (int) (millisUntilFinished / 1000);
- setTime(time1);
-// mBinding.tvDjs.setText(time1 + "");
- if (time1 == 0) {
- mBinding.xlhRk.setVisibility(INVISIBLE);
- }
- }
-
- @Override
- public void onFinish() {
- setTime(0);
- }
- };
- mCountDownTimer2.start();
- } catch (Exception e) {
- Logger.e("countDownTime", e);
- }
- }
-
- private String formatTime(int totalSeconds) {
- int minutes = (totalSeconds % 3600) / 60;
- int seconds = totalSeconds % 60;
-
- return String.format("%02d:%02d", minutes, seconds);
- }
-
- @SuppressLint("DefaultLocale")
- public void setTime(int seconds) {
- if (seconds == 0) {
- mBinding.xlhRk.setVisibility(INVISIBLE);
- return;
- }
- String formattedTime = formatTime(seconds);
- mBinding.tvDjs.setText("倒计时" + formattedTime);
-
- }
-
- // TODO: 2025/3/19 释放倒计时器
- private void releaseCountDownTimer1() {
- if (mCountDownTimer2 != null) {
- mCountDownTimer2.cancel();
- mCountDownTimer2 = null;
- }
- }
-
- private Map pitMap = new HashMap<>();
-
- public void handleMsgType1039(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) {
- return;
- }
-
- List pitList = mRoomInfoResp.getRoom_info().getPit_list();
- if (pitList != null && !pitList.isEmpty()) {
- pitMap.clear(); // 避免数据累积
- for (RoomPitBean roomPitBean : pitList) {
- pitMap.put(roomPitBean.getPit_number(), roomPitBean);
- }
-
- if (text == null) {
- return;
- }
-
- String fromPitNumber = text.getFrom_pit_number();
- String toPitNumber = text.getTo_pit_number();
-
- if (!TextUtils.isEmpty(fromPitNumber) && !TextUtils.isEmpty(toPitNumber)) {
- performSwitchMic(fromPitNumber, toPitNumber, messageEvent);
- }
- // 执行换麦逻辑
- }
-
- }
-
- private void performSwitchMic(String fromPitNumber, String toPitNumber, RoomMessageEvent messageEvent) {
- if (TextUtils.isEmpty(fromPitNumber) || TextUtils.isEmpty(toPitNumber)) {
- return;
- }
-
- if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) {
- LogUtils.e("Room info is null");
- return;
- }
-
- List pitList = mRoomInfoResp.getRoom_info().getPit_list();
- if (pitList == null || pitList.isEmpty()) {
- LogUtils.e("pit_list is null or empty");
- return;
- }
-
- RoomPitBean fromBean = null;
- RoomPitBean toBean = null;
- List pitListCopy = new ArrayList<>();
-
- for (RoomPitBean bean : pitList) {
- if (bean == null) continue;
- if (fromPitNumber.equals(bean.getPit_number())) {
- fromBean = bean;
- pitListCopy.add(bean);
- } else if (toPitNumber.equals(bean.getPit_number())) {
- toBean = bean;
- pitListCopy.add(bean);
- }
- }
-
- if (fromBean == null || toBean == null) {
- LogUtils.e("Cannot find pit number: from=" + fromPitNumber + ", to=" + toPitNumber);
- return;
- }
-
- // 交换 pit_number
- String temp = fromBean.getPit_number();
- fromBean.setPit_number(toBean.getPit_number());
- toBean.setPit_number(temp);
-
- // 构造新的 pitList
- List newPitList = new ArrayList<>();
- for (RoomPitBean bean : pitList) {
- if (!pitListCopy.contains(bean)) {
- newPitList.add(bean);
- }
- }
- newPitList.add(fromBean);
- newPitList.add(toBean);
-
- // 排序
- newPitList.sort((a, b) -> {
- try {
- return Integer.compare(Integer.parseInt(a.getPit_number()), Integer.parseInt(b.getPit_number()));
- } catch (NumberFormatException e) {
- return a.getPit_number().compareTo(b.getPit_number());
- }
- });
-
- mRoomInfoResp.getRoom_info().setPit_list(newPitList);
-
- // 更新当前用户 pit_number
- if (mRoomInfoResp.getUser_info() != null) {
- String currentUserId = String.valueOf(SpUtil.getUserId());
- String fromUserId = fromBean.getUser_id();
- String toUserId = toBean.getUser_id();
-
- if (fromUserId != null && fromUserId.equals(currentUserId)) {
- try {
- mRoomInfoResp.getUser_info().setPit_number(Integer.parseInt(fromBean.getPit_number()));
- } catch (NumberFormatException e) {
- LogUtils.e("Invalid pit number: " + toBean.getPit_number());
- }
- } else if (toUserId != null && toUserId.equals(currentUserId)) {
- try {
- mRoomInfoResp.getUser_info().setPit_number(Integer.parseInt(fromBean.getPit_number()));
- } catch (NumberFormatException e) {
- LogUtils.e("Invalid pit number: " + toBean.getPit_number());
- }
- }
- }
-
- dispatchRoomEvent(messageEvent);
- }
-
- private void dispatchRoomEvent(RoomMessageEvent messageEvent) {
- if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
-
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- if ("2".equals(typeId)) {
- roomFragment.upRoomInfoData(mRoomInfoResp);
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if ("3".equals(typeId) || "4".equals(typeId) || "1".equals(typeId) || "8".equals(typeId)) {
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- if ("2".equals(labelId)) {
- roomFragment.KtvFragmentEvent(messageEvent);
- } else if ("1".equals(labelId)) {
- roomFragment.SingSongEvent(messageEvent);
- }
- } else if ("7".equals(typeId)) {
- roomFragment.friendshipRoomFragmentEvent(messageEvent);
- }
- if (mRoomInfoResp.getUser_info().getPit_number() == 9) {
- mBinding.roomTop.rl.setVisibility(View.VISIBLE);
- ivSoundEffects(true);
- }
- }
-
-
- private void hand1005(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
-
- GiftBean giftInfo = text.getGiftInfo();
- UserInfo toUserInfo = text.getToUserInfo();
-// if (giftInfo == null || toUserInfo == null) return;
- List pitList = mRoomInfoResp.getRoom_info().getPit_list();
- if (pitList == null) return;
-
-
-// roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
-
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- if ("2".equals(typeId)) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- return;
- } else if ("1".equals(typeId) || "4".equals(typeId) || "3".equals(typeId) || "8".equals(typeId)) {
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- if ("2".equals(labelId)) {
- roomFragment.KtvFragmentEvent(messageEvent);
- return;
- } else if ("1".equals(labelId)) {
- roomFragment.SingSongEvent(messageEvent);
- return;
- }
- } else if ("7".equals(typeId)) {//交友房
- roomFragment.friendshipRoomFragmentEvent(messageEvent);
- return;
- }
- }
-
-
- private void handleMsgType1014(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- RoomSettingEvent roomSettingEvent = new RoomSettingEvent();
- roomSettingEvent.setRoomId(messageEvent.getRoomId());
- roomSettingEvent.setRoom_up_pit_type(text.getRoom_up_pit_type());
- roomSettingEvent.setType(messageEvent.getMsgType());
-
- if (mRoomBean != null) {
- mRoomBean.setRoom_up_pit_type(text.getRoom_up_pit_type() + "");
- EventBus.getDefault().post(mRoomBean);
- }
-
- EventBus.getDefault().post(roomSettingEvent);
- }
-
- private void handleMsgType1013(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomUserBean == null) return;
-
- int userId2 = SpUtil.getUserId();
-
- if (text.getAction() == 1 && mRoomUserBean.getUser_id().equals(userId2 + "") && mRoomUserBean.getPit_number() == 9) {
- queren(text.getFromUserInfo().getNickname());
- } else if (text.getAction() == 4 && text.getFromUserInfo().getUser_id() == userId2) {
- queren1(text.getFromUserInfo().getNickname());
- } else {
- roomFragment.KtvFragmentEvent(messageEvent);
- }
- }
-
- private void handleMsgType1012() {
- if (customMusicFloatingView != null) {
- customMusicFloatingView.destroy();
- }
- AgoraManager.getInstance(RoomActivity.this).desMusic();
-// stub.setVisibility(View.GONE);
-
- if ((mRoomInfoResp.getRoom_info().getType_id().equals("1") || mRoomInfoResp.getRoom_info().getType_id().equals("4") ||
- mRoomInfoResp.getRoom_info().getType_id().equals("3") || mRoomInfoResp.getRoom_info().getType_id().equals("8")) &&
- mRoomInfoResp.getRoom_info().getLabel_id().equals("2")) {
- for (RoomPitBean roomPitBean : mRoomInfoResp.getSong_pit_list()) {
- AgoraManager.getInstance(RoomActivity.this).ClientRole(false);
- ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding);
- mBinding.rlMic.setVisibility(View.GONE);
- }
- if (mRoomInfoResp.getSong_user_info() != null && mRoomInfoResp.getSong_user_info().getUser_id() != null) {
- if (mRoomInfoResp.getSong_user_info().getUser_id().equals(SpUtil.getUserId() + "")) {
- AgoraManager.getInstance(RoomActivity.this).ClientRole(false);
- ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding);
- mBinding.rlMic.setVisibility(View.GONE);
- }
- }
- }
-
- MvpPre.postRoomInfo(roomId);
- }
-
- private void handleMsgType124(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- try {
- RoomMessageEvent.text parsedText = GsonUtils.fromJson(text.getText(), RoomMessageEvent.text.class);
- MusicPlayBean musicPlayBean = new MusicPlayBean();
- musicPlayBean.setPosition(parsedText.getPosition());
- EventBus.getDefault().post(musicPlayBean);
- } catch (Exception e) {
- // Handle exception
- }
- }
-
- private void handleMsgType1003(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
- if (roomFragment == null) {
- roomFragment = RoomFragment.newInstance();
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.vp_room_pager, roomFragment)
- .commitAllowingStateLoss();
- }
-
- UserInfo fromUserInfo = text.getFromUserInfo();
- if (fromUserInfo == null) return;
-
- String pitNumber = text.getPit_number();
- int userId = fromUserInfo.getUser_id();
- int currentUserId = SpUtil.getUserId();
-
- if ("9".equals(pitNumber) && userId == currentUserId) {
- mBinding.roomTop.rl.setVisibility(View.VISIBLE);
- ivSoundEffects(true);
- }
-
- if (userId == currentUserId) {
- aBoolean = false;
- ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding_up);
- setBoolean(aBoolean);
- if (mRoomInfoResp.getUser_info() != null) {
- mRoomInfoResp.getUser_info().setPit_number(pitNumber != null ? Integer.parseInt(pitNumber) : -1);
- }
- setRoleType(3, Integer.parseInt(pitNumber));
- switchMic(2);
- }
-
-
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- if ("2".equals(typeId)) {
- if ("9".equals(pitNumber)) {
- mRoomInfoResp.getRoom_info().getPit_list().set(0, getPitBean(messageEvent));
- if (mRoomInfoResp.getUser_info() != null) {
- mRoomInfoResp.getUser_info().setPit_number(Integer.parseInt(pitNumber));
- }
- }
- roomFragment.upRoomInfoData(mRoomInfoResp);
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if ("3".equals(typeId) || "4".equals(typeId) || "1".equals(typeId) || "8".equals(typeId)) {
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- if ("2".equals(labelId)) {
- roomFragment.KtvFragmentEvent(messageEvent);
- } else if ("1".equals(labelId)) {
- roomFragment.SingSongEvent(messageEvent);
-
- }
- } else if ("7".equals(typeId)) {
- mBinding.rlMore.setVisibility(GONE);
- mBinding.rlMisc.setVisibility(GONE);
-
- roomFragment.friendshipRoomFragmentEvent(messageEvent);
- } else {
- roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
- }
-
-// if (pitNumber.equals("9") && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId()+"")) {
-// ivSoundEffects(true);
-// } else {
-// ivSoundEffects(false);
-// }
- }
-
- private void handleMsgType1004(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
-
- UserInfo fromUserInfo = text.getFromUserInfo();
- if (fromUserInfo == null) return;
-
- String pitNumber = text.getPit_number();
- int userId = fromUserInfo.getUser_id();
- int currentUserId = SpUtil.getUserId();
-
- if (userId == currentUserId) {
- aBoolean = true;
- ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding);
- setBoolean(aBoolean);
- if (mRoomInfoResp.getUser_info() != null) {
- mRoomInfoResp.getUser_info().setPit_number(0);
- }
- setRoleType(0, 0);
- switchMic(2);
- }
-
- if (pitNumber.equals("9")) {
- ivSoundEffects(false);
- }
-
- if (userId == currentUserId && "9".equals(pitNumber)) {
- if (customMusicFloatingView != null) {
- customMusicFloatingView.destroy();
- AgoraManager.getInstance(RoomActivity.this).desMusic();
- isMusic = false;
- }
- mBinding.roomTop.rl.setVisibility(GONE);
- ivSoundEffects(false);
- }
-
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- if ("2".equals(typeId)) {
- if ("9".equals(pitNumber)) {
- if (userId == currentUserId) {
- mRoomInfoResp.getRoom_info().getPit_list().set(0, getPitBean2(messageEvent, "9"));
- if (mRoomInfoResp.getUser_info() != null) {
- mRoomInfoResp.getUser_info().setPit_number(0);
- }
- }
- } else if ("888".equals(pitNumber)) {
- mRoomInfoResp.setRoom_auction(null);
- if (userId == currentUserId) {
- setRoleType(0, 0);
- switchMic(2);
- }
- }
- roomFragment.upRoomInfoData(mRoomInfoResp);
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if ("3".equals(typeId) || "4".equals(typeId) || "1".equals(typeId) || "8".equals(typeId)) {
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- if ("2".equals(labelId)) {
- roomFragment.KtvFragmentEvent(messageEvent);
- } else if ("1".equals(labelId)) {
- roomFragment.SingSongEvent(messageEvent);
- if (mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId() + "")) {
- ivSoundEffects(false);
- }
- }
- } else {
-
- roomFragment.friendshipRoomFragmentEvent(messageEvent);
- }
- }
-
- private void handleMsgType1022(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
-
- String pitNumber = text.getPit_number();
- int userId = text.getFromUserInfo().getUser_id();
- int currentUserId = SpUtil.getUserId();
-
- if (text.getType() == 1) {
- if ("888".equals(pitNumber)) {
- int type = -1;
- if ("2".equals(mRoomInfoResp.getRoom_info().getType_id())) {
- type = "1".equals(mRoomInfoResp.getRoom_info().getLabel_id()) ? 1 : 2;
- }
- if (userId == currentUserId) {
- setRoleType(3, 888);
- switchMic(2);
- }
- }
- } else if (text.getType() == 2) {
- if ("9".equals(pitNumber)) {
- setRoleType(0, 0);
- switchMic(2);
- } else if ("888".equals(pitNumber)) {
- mRoomInfoResp.setRoom_auction(new RoomAuction());
- if (userId == currentUserId) {
- setRoleType(0, 0);
- switchMic(2);
- }
- }
- }
-
- roomFragment.upRoomInfoData(mRoomInfoResp);
- roomFragment.handleAuctionMessageEvent(messageEvent);
- }
-
- private void handleMsgType1023(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_auction() == null)
- return;
-
- mRoomInfoResp.getRoom_auction().setAuction_user(text.getAuction_user());
- SpUtil.setAuctionId(text.getAuction_user().getAuction_id());
- roomFragment.upRoomInfoData(mRoomInfoResp);
- roomFragment.handleAuctionMessageEvent(messageEvent);
-// roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
- }
-
- private void handleMsgType1024(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_auction() == null)
- return;
- if (mRoomInfoResp.getRoom_auction().getAuction_list() != null) {
- mRoomInfoResp.getRoom_auction().getAuction_list().clear();
- }
- if (mRoomInfoResp.getRoom_auction().getAuction_list() != null) {
- mRoomInfoResp.getRoom_auction().getAuction_list().addAll(text.getAuction_list());
- } else {
- mRoomInfoResp.getRoom_auction().setAuction_list(new ArrayList<>());
-// mRoomInfoResp.getRoom_auction().getAuction_list().addAll(text.getAuction_list());
- }
- roomFragment.upRoomInfoData(mRoomInfoResp);
- roomFragment.handleAuctionMessageEvent(messageEvent);
-// roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
- }
-
- private void handleMsgType1020(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- mRoomBean = text.getRoomInfo();
- EventBus.getDefault().post(mRoomBean);
- changeBackgroundColor(mRoomBean.getRoom_background());
- }
-
- private void handleMsgType1011(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || text.getFromUserInfo() == null) return;
-
- if (text.getFromUserInfo().getUser_id() == SpUtil.getUserId()) {
- MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
- }
- }
-
- private void handleMsgType1001() {
- number++;
- mBinding.roomTop.tvNum.setText(number + "");
- }
-
- private void handleMsgType1002() {
- number--;
- if (number<0){
- number=0;
- }
- mBinding.roomTop.tvNum.setText(number + "");
- }
-
- private void handleMsgType1029(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getUser_info() == null) return;
-
- if (mRoomInfoResp.getUser_info().getPit_number() == 9 && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId() + "")) {
- querenPk(text.getText(), text.getPkId());
- }
- }
-
- private void handleMsgType1021(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
-
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- if ("2".equals(typeId)) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if ("1".equals(typeId) || "4".equals(typeId) || "3".equals(typeId) || "8".equals(typeId)) {
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- if ("2".equals(labelId)) {
- roomFragment.KtvFragmentEvent(messageEvent);
- } else {
- updateCharmForAllPitBeans("");
- roomFragment.upRoomInfoData(mRoomInfoResp);
- roomFragment.SingSongEvent(messageEvent);
- }
- } else {
- updateCharmForAllPitBeans("");
- roomFragment.upFriendList(mRoomInfoResp.getRoom_info().getPit_list());
- }
-
-
- }
-
- private void updateCharmForAllPitBeans(String charm) {
- if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
-
- List pitList = mRoomInfoResp.getRoom_info().getPit_list();
- if (pitList == null) return;
-
- for (RoomPitBean roomPitBean : pitList) {
- roomPitBean.setCharm(charm);
- try {
- pitList.set(Integer.parseInt(roomPitBean.getPit_number()) - 1, roomPitBean);
- } catch (NumberFormatException e) {
- // Handle exception
- }
- }
- }
-
- private void handleMsgType1036(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- if (text.getRoom_id().equals(roomId)) {
- String onlineNumber = text.getOnline_number() + "";
- if (!mBinding.roomTop.tvNum.getText().toString().equals(onlineNumber)) {
- mBinding.roomTop.tvNum.setText(onlineNumber);
- }
- }
- }
-
- private void handleMsgType1049(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- long endTime = text.getEnd_time() != null ? Long.parseLong(text.getEnd_time()) : 0;
- if (text.getStep() != 3) {
- roomFragment.updateFriendshipState(text.getStep(), text.getFriend_id(), endTime, null);
- } else {
- roomFragment.updateFriendshipState(text.getStep(), text.getFriend_id(), 0, text.getFriend_user());
- }
- }
-
- private void handleMsgType1050(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- roomFragment.friendTimeDelayWithTime(Long.parseLong(text.getEnd_time()));
- }
-
- private void handleMsgType1051(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- if (text.getUser1_id() == null || text.getUser2_id() == null) {
- return;
- }
- if (roomFragment != null) {
- roomFragment.clearDialog();
- }
- FriendUserBean friend_user = getFriendUserBean(messageEvent);
- FriendsDialogFragment.show(friend_user, getSupportFragmentManager());
-
-
- if (text.getUser1_id().equals(SpUtil.getUserId() + "") || text.getUser2_id().equals(SpUtil.getUserId() + "")) {
- if (roomSwitchRunnable != null) {
- roomSwitchHandler.removeCallbacks(roomSwitchRunnable);
- }
-
- pendingRoomId = text.getRoom_id();
- if (pendingRoomId == null) {
- return;
- }
- LogUtils.e("需要加入的房间id:pendingRoomId: " + pendingRoomId);
- roomSwitchRunnable = () -> {
- if (!isFinishing() && !isDestroyed()) {
- if (!pendingRoomId.equals(lastSwitchedRoomId)) {
-
- MvpPre.quitRoom2(messageEvent.getRoomId(), SpUtil.getUserId() + "");
- quit();
- MessageListenerSingleton.getInstance().quitGroup(messageEvent.getRoomId());
- MessageListenerSingleton.getInstance().joinGroup(pendingRoomId);
- MvpPre.getRoomIn(pendingRoomId, "");
- lastSwitchedRoomId = pendingRoomId;
- AgoraManager.getInstance(context).setLastRoomId(messageEvent.getRoomId());
- }
- }
- pendingRoomId = null;
- };
-
- roomSwitchHandler.postDelayed(roomSwitchRunnable, 3000);
- }
- }
-
- //退出房间
- public void quitRoomAll(String roomId) {
- MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
- }
-
- private void handleMsgType1053(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || text.getList() == null || text.getList().isEmpty()) return;
- List pitArr = new ArrayList<>();
- for (int j = 0; j < text.getList().size(); j++) {
- RoomPitBean roomPitBean = getRoomPitBean(messageEvent, j);
- pitArr.add(roomPitBean);
- }
-
- roomFragment.friendSeatDidChanged(pitArr);
- pitArr.clear();
- }
-
- private void handleMsgType1054(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || text.getList() == null) return;
-
- List heartList = text.getList().stream()
- .map(item -> {
- FriendInfo.HeartList heartList1 = new FriendInfo.HeartList();
- heartList1.setHeartId(item.getHeartId());
- heartList1.setHeartNum(item.getHeartNum());
- return heartList1;
- })
- .collect(Collectors.toList());
-
- roomFragment.friendHeartNumberDidChanged(heartList);
- }
-
- private void handleMsgType1055(RoomMessageEvent messageEvent) {
- if (!isFinishing() && !isDestroyed()) {
- MvpPre.quitRoom2(messageEvent.getRoomId(), SpUtil.getUserId() + "");
- quit();
- jiaR();
- }
- }
-
- private void handleMsgType1035(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
-
- UserInfo fromUserInfo = text.getFromUserInfo();
- if (fromUserInfo == null) return;
-
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- if ("2".equals(typeId)) {
- roomFragment.handleAuctionMessageEvent(messageEvent);
- } else if ("1".equals(typeId) || "3".equals(typeId) || "4".equals(typeId) || "8".equals(typeId)) {
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- if ("2".equals(labelId)) {
- roomFragment.KtvFragmentEvent(messageEvent);
- } else {
-// updatePitBeanForUser(fromUserInfo);
- roomFragment.upRoomInfoData(updatePitBeanForUser(fromUserInfo));
- roomFragment.SingSongEvent(messageEvent);
- }
- } else {
- roomFragment.upRoomInfoData(updatePitBeanForUser(fromUserInfo));
- roomFragment.friendshipRoomFragmentEvent(messageEvent);
- }
-
-
- }
-
- private RoomInfoResp updatePitBeanForUser(UserInfo fromUserInfo) {
- if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return mRoomInfoResp;
-
- List pitList = mRoomInfoResp.getRoom_info().getPit_list();
- if (pitList == null) return mRoomInfoResp;
-
- for (RoomPitBean pitBean : pitList) {
- if (pitBean.getUser_id().equals(fromUserInfo.getUser_id() + "")) {
- pitBean.setCharm(fromUserInfo.getCharm());
- pitBean.setAvatar(fromUserInfo.getAvatar());
- pitBean.setNickname(fromUserInfo.getNickname());
- pitBean.setSex(fromUserInfo.getSex() + "");
- pitBean.setDress(fromUserInfo.getDress());
- }
- }
- return mRoomInfoResp;
- }
-
- private void handleMsgType125(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- try {
- RoomMessageEvent.text parsedText = com.blankj.utilcode.util.GsonUtils.fromJson(text.getText(), RoomMessageEvent.text.class);
- if (parsedText.getIs_mute() == 1) {
- AgoraManager.getInstance(this).ClientRole(false);
- AgoraManager.getInstance(this).muteLocalAudioStreamEx(false, SpUtil.getUserId());
- } else {
- AgoraManager.getInstance(this).ClientRole(true);
- AgoraManager.getInstance(this).muteLocalAudioStreamEx(true, SpUtil.getUserId());
- }
- } catch (Exception e) {
- // Handle exception
- }
- }
-
- private void handleMsgType1007() {
- if (mRoomInfoResp != null && mRoomInfoResp.getUser_info() != null) {
- mRoomInfoResp.getUser_info().setIs_host(1);
- roomFragment.upRoomInfoData(mRoomInfoResp);
-// roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
- }
- }
-
- private void handleMsgType1006(){
- if (mRoomInfoResp!=null && mRoomInfoResp.getUser_info() != null){
- mRoomInfoResp.getUser_info().setIs_management(1);
- roomFragment.upRoomInfoData(mRoomInfoResp);
- }
- }
-
- private void handleMsgType1018() {
- if (mRoomInfoResp != null && mRoomInfoResp.getUser_info() != null) {
- mRoomInfoResp.getUser_info().setIs_host(0);
- roomFragment.upRoomInfoData(mRoomInfoResp);
-// roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
- }
- }
-
- private void handleMsgType1017(){
- if (mRoomInfoResp!=null && mRoomInfoResp.getUser_info() != null){
- mRoomInfoResp.getUser_info().setIs_management(0);
- roomFragment.upRoomInfoData(mRoomInfoResp);
- }
- }
-
- private void handleMsgType126(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- AgoraManager.getInstance(this).setLocalAudioEnabled(false, text.getFromUserInfo().getUser_id() + "");
- }
-
- private void handleMsgType1034(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null) return;
-
- int count = text.getCount();
- if (count == 0) {
- tvFirst(new SpannableStringBuilder("0人排队"));
- return;
- }
-
- String countText = String.valueOf(count);
- String fullText = countText + "人排队";
-
- SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(fullText);
- spannableStringBuilder.setSpan(
- new ForegroundColorSpan(ContextCompat.getColor(this, com.xscm.moduleutil.R.color.color_C7BF62)),
- 0,
- countText.length(),
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
- );
- tvFirst(spannableStringBuilder);
- }
-
- private void handleMsgType1016(RoomMessageEvent messageEvent, RoomMessageEvent.T text) {
- if (text == null || mRoomInfoResp == null || mRoomInfoResp.getUser_info() == null) return;
-
- if (text.getFromUserInfo().getUser_id() == SpUtil.getUserId()) {
- if (text.getIs_mute_pit() == 1) {
- switchMic(2);
- }
- mRoomInfoResp.getUser_info().setIs_mute_pit(String.valueOf(text.getIs_mute_pit()));
- mRoomInfoResp.getUser_info().setIs_mute(String.valueOf(text.getIs_mute()));
- }
- }
-
- // TODO: 2025/6/30 上麦,麦位变化
- private RoomPitBean getPitBean(RoomMessageEvent messageEvent) {
- RoomPitBean pitBean = new RoomPitBean();
- pitBean.setPit_number(messageEvent.getText().getPit_number());
- pitBean.setUser_id(messageEvent.getText().getFromUserInfo().getUser_id() + "");
- pitBean.setAvatar(messageEvent.getText().getFromUserInfo().getAvatar());
- pitBean.setNickname(messageEvent.getText().getFromUserInfo().getNickname());
- pitBean.setSex(messageEvent.getText().getFromUserInfo().getSex() + "");
- pitBean.setCharm(messageEvent.getText().getFromUserInfo().getCharm());
-
- return pitBean;
- }
-
- // TODO: 2025/6/30 下麦麦位变化
- private RoomPitBean getPitBean2(RoomMessageEvent messageEvent, String number) {
- RoomPitBean pitBean = new RoomPitBean();
- pitBean.setPit_number(messageEvent != null ? messageEvent.getText().getPit_number() : number);
- pitBean.setUser_id("");
- pitBean.setAvatar("");
- pitBean.setNickname("");
- pitBean.setSex("");
- pitBean.setCharm("");
- pitBean.setIs_pm(1);
- return pitBean;
- }
-
- // TODO: 2025/8/29 排麦位上麦
- private RoomAuction.AuctionUserBean getPitBean3(RoomMessageEvent messageEvent) {
- RoomAuction.AuctionUserBean roomAuction = new RoomAuction.AuctionUserBean();
- roomAuction.setUser_id(messageEvent.getText().getFromUserInfo().getUser_id() + "");
- roomAuction.setAvatar(messageEvent.getText().getFromUserInfo().getAvatar());
- roomAuction.setNickname(messageEvent.getText().getFromUserInfo().getNickname());
- roomAuction.setSex(messageEvent.getText().getFromUserInfo().getSex() + "");
- roomAuction.setCharm(messageEvent.getText().getFromUserInfo().getCharm());
-
- return roomAuction;
- }
-
- public void mus() {
- if (mRoomInfoResp.getUser_info().getIs_mute().equals("1")) {
- com.hjq.toast.ToastUtils.show("您已经被禁言");
- } else {
- switchMic(1);
- }
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onMessageEvent(UnreadCountEvent messageEvent) {
- if (messageEvent.getALong() == 0) {
- mBinding.ivMessageDot.setVisibility(View.GONE);
- } else {
- mBinding.ivMessageDot.setVisibility(View.VISIBLE);
- mBinding.ivMessageDot.setText(String.valueOf(messageEvent.getALong()));
- }
-
- }
-
- @NonNull
- private static FriendUserBean getFriendUserBean(RoomMessageEvent messageEvent) {
- FriendUserBean friend_user = new FriendUserBean();
- friend_user.setUser2_id(messageEvent.getText().getUser2_id());
- friend_user.setUser1_id(messageEvent.getText().getUser1_id());
- friend_user.setUser1_avatar(messageEvent.getText().getUser1_avatar());
- friend_user.setUser1_nickname(messageEvent.getText().getUser1_nickname());
- friend_user.setUser2_avatar(messageEvent.getText().getUser2_avatar());
- friend_user.setUser2_nickname(messageEvent.getText().getUser2_nickname());
- friend_user.setRelation_name(messageEvent.getText().getRelation_name());
- return friend_user;
- }
-
- @NonNull
- private static RoomPitBean getRoomPitBean(RoomMessageEvent messageEvent, int j) {
- RoomPitBean roomPitBean = new RoomPitBean();
- roomPitBean.setPit_number(messageEvent.getText().getList().get(j).getPit_number());
- roomPitBean.setUser_id(messageEvent.getText().getList().get(j).getUser_id() + "");
- roomPitBean.setAvatar(messageEvent.getText().getList().get(j).getAvatar());
- roomPitBean.setNickname(messageEvent.getText().getList().get(j).getNickname());
- roomPitBean.setSex(messageEvent.getText().getList().get(j).getSex() + "");
- roomPitBean.setDress(messageEvent.getText().getList().get(j).getDress());
- roomPitBean.setCharm(messageEvent.getText().getList().get(j).getCharm());
- return roomPitBean;
- }
-
-
- private void querenPk(String text, String pk_id) {
- // 创建并显示确认对话框
- ConfirmDialog dialog = new ConfirmDialog(this,
- "温馨提示",
- text,
- "确认",
- "拒绝",
- v -> {
- // 点击“确认”按钮时执行删除操作
- MvpPre.acceptPk(pk_id, "1");
- },
- v -> {
- MvpPre.acceptPk(pk_id, "2");
- // 点击“取消”按钮时什么都不做
- }, true, 10);
- dialog.show();
- addActiveDialog(dialog);
- }
-
- /**
- * 修改背景图
- *
- * @param bjId
- */
-
- public void changeBackgroundColor(String bjId) {
- // 假设你的Activity有一个根布局,例如 ConstraintLayout
- ImageUtils.loadImageWithCache(this, bjId, mBinding.ivBg);
- }
-
- public void changeBackground(int bjId) {
- mBinding.ivBg.setImageDrawable(getResources().getDrawable(bjId));
- }
-
- public void setvisibTop(boolean is) {
- mBinding.roomTop.getRoot().setVisibility(is ? VISIBLE : GONE);
- }
-
- public void setDiany(boolean is) {
-// mBinding.flaoat.setVisibility(is? VISIBLE : GONE);
- }
-
- public void setOnlineNumber(int number) {
- mBinding.roomTop.tvNum.setText(number + "");
- }
-
- /**
- * 特效设置
- */
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void setEffectSwitch(EffectEvent event) {
- if (event.isEffectOn()) {//特效开启
- QXGiftPlayerManager.getInstance(this).openOrCloseEffectViewWith(true);
- mBinding.svgaGift.setVisibility(View.VISIBLE);
- } else {
-// mBinding.svgaGift.closeEffect();
-// mBinding.svgaGift.closeEffect();
- QXGiftPlayerManager.getInstance(this).openOrCloseEffectViewWith(false);
- mBinding.svgaGift.setVisibility(View.GONE);
- }
- }
-
- /**
- * 坐骑进场特效
- *
- * @param roomJoinMountModel
- */
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void roomJoinMount(RoomJoinMountModel roomJoinMountModel) {
- if (!roomId.equals(roomJoinMountModel.getRoom_id())) {
- return;
- }
- if (roomJoinMountModel.getShow_type() != 1) {
- GiftBean gift = new GiftBean();
- gift.setGift_id("");
- gift.setPlay_image(roomJoinMountModel.getRide_url());
- QXGiftPlayerManager.getInstance(this).displayFullEffectView(roomJoinMountModel.getRide_url());
-// mBinding.svgaZuoji.setSource(roomJoinMountModel.getRide_url(), 2);
- }
- }
-
- private boolean isSwith;
- private boolean voive = false;//声音开关
- private boolean canSend = true;
- private boolean aBoolean = true;//上下麦按钮
- private CountDownTimer mCountDownTimer;
- private CountDownTimer mCountDownTimer2;
-
- private void onClick(View view) {
- int id = view.getId();
- if (id == R.id.btn_follow) {
- MvpPre.userGuanz(mRoomInfoResp.getRoom_info().getRoom_id(), "2");
- } else if (id == R.id.btn_notice) {
-// RoomTipsView.show(this,view,"公告","公告内容");
- RoomNoticeDialogFragment roomNoticeDialogFragment = new RoomNoticeDialogFragment(this);
- roomNoticeDialogFragment.setTitle("公告");
- roomNoticeDialogFragment.setContent(mRoomBean.getRoom_intro());
- roomNoticeDialogFragment.show();
- addActiveDialog(roomNoticeDialogFragment);
- } else if (id == R.id.btn_ranking) {//排行榜
-// RoomChartsFragment.newInstance(roomId).show(getSupportFragmentManager(), "RoomChartsFragment");
- RoomChartsFragment fragment = RoomChartsFragment.newInstance(roomId, mRoomInfoResp);
- fragment.show(getSupportFragmentManager(), "RoomChartsFragment");
- addActiveDialogFragment(fragment);
- } else if (id == R.id.btn_close_live) {//退出房间
- showExitRoomDialog();
-
- } else if (id == R.id.tv_num) {
-// RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
- RoomOnlineDialogFragment fragment = RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- } else if (id == R.id.rl) {
- MvpPre.clearUserCharm(roomId, "");
- } else if (id == R.id.ll_input) {
- mBinding.llInput.setVisibility(View.GONE);
- mBinding.inputMenu1.dismiss();
- } else if (id == R.id.iv_chat) {
- if (mRoomInfoResp.getUser_info().getIs_mute().equals("1")) {
- com.hjq.toast.ToastUtils.show("您已经被禁言");
- } else {
-
-// mBinding.llInput.setVisibility(View.VISIBLE);
-// mBinding.inputMenu1.bringToFront(); // 强制将该 View 置于最上层
-// mBinding.inputMenu1.show();
- dialogDismiss();
-
- }
- } else if (id == R.id.rl_mic) {
- if (mRoomInfoResp.getUser_info().getIs_mute_pit() != null && mRoomInfoResp.getUser_info().getIs_mute_pit().equals("1")) {
- com.hjq.toast.ToastUtils.show("您被禁麦了");
- } else {
- if (isSwith) {
- switchMic(1);
- } else {
- switchMic(2);
- }
- }
- } else if (id == R.id.rl_sett) {//房间设置
-// RoomSettingFragment.show(mRoomInfoResp, getSupportFragmentManager());
- if (mRoomInfoResp==null){
- ToastUtils.showShort("请稍后再试");
- return;
- }
- RoomSettingFragment fragment = RoomSettingFragment.show(mRoomInfoResp, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- } else if (id == R.id.rl_voive) {
- if (voive) {
- mBinding.imVoive.setImageResource(com.xscm.moduleutil.R.mipmap.room_voice_g);
- voive = false;
- } else {
- mBinding.imVoive.setImageResource(com.xscm.moduleutil.R.mipmap.room_voice_kg);
- voive = true;
- }
- AgoraManager.getInstance(this).muteSpeaker(!voive);
- } else if (id == R.id.rl_more) {//点击PK
-// RoomPkDialogFragment.newInstance(roomId, SpUtil.getUserId() + "", mRoomInfoResp.getRoom_info().getIs_pk()).show(getSupportFragmentManager(), "RoomPkDialogFragment");
- RoomPkDialogFragment fragment = RoomPkDialogFragment.newInstance(roomId, SpUtil.getUserId() + "", mRoomInfoResp.getRoom_info().getIs_pk());
- fragment.show(getSupportFragmentManager(), "RoomPkDialogFragment");
- addActiveDialogFragment(fragment); // 添加到管理列表
- } else if (id == R.id.rl_message) {
-// RoomMessageDialogFragment.show(getSupportFragmentManager());
- RoomMessageDialogFragment fragment = RoomMessageDialogFragment.show(getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- } else if (id == R.id.rl_misc) {//设置点歌
- if (mRoomInfoResp.getRoom_info().getLabel_id().equals("1")) {
- queren();
- } else {
-// RequestDialogFragment.show(roomId, mRoomInfoResp, 1, getSupportFragmentManager());
- RequestDialogFragment fragment = RequestDialogFragment.show(roomId, mRoomInfoResp, 1, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- }
- } else if (id == R.id.rl_gift) {//礼物
-// RoomGiftDialogFragment.show(mRoomInfoResp, null, roomId, 0, "", getSupportFragmentManager());
- RoomGiftDialogFragment fragment = RoomGiftDialogFragment.show(mRoomInfoResp, null, roomId, 0, "", getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- } else if (id == R.id.iv_sound_effects) {
-// SoundEffectsDialogFragment.show(roomId, getSupportFragmentManager());
- SoundEffectsDialogFragment fragment = SoundEffectsDialogFragment.show(roomId, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- } else if (id == R.id.cl_first_charge) {
-// showWheatFeedingDialog(roomId, (mRoomInfoResp.getUser_info().getIs_room_owner() == 1 || mRoomInfoResp.getUser_info().getIs_host() == 1 || mRoomInfoResp.getUser_info().getIs_management() == 1) ? 1 : 2);
- roomFragment.showWheatFeedingDialog(roomId, (mRoomInfoResp.getUser_info().getIs_room_owner() == 1 || mRoomInfoResp.getUser_info().getIs_host() == 1 || mRoomInfoResp.getUser_info().getIs_management() == 1) ? 1 : 2);
- } else if (id == R.id.iv_wheat_feeding) {//点击上麦操作
- if (mRoomInfoResp.getRoom_info().getRoom_up_pit_type().equals("1")) {
-// showWheatFeedingDialog(roomId, mRoomInfoResp.getUser_info().getPit_number() == 9 ? 1 : 2);
- if (aBoolean) {
- MvpPre.applyPit(roomId, "");
-// aBoolean = false;
- } else {
- MvpPre.downPit(roomId, "");
-// aBoolean = true;
- }
- } else {
-
- if (aBoolean) {
-// mBinding.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding_up);
- MvpPre.applyPit(roomId, "");
- aBoolean = false;
- } else {
-// mBinding.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding);
- MvpPre.downPit(roomId, "");
- aBoolean = true;
- }
- }
- }
- }
-
- // TODO: 2025/9/18 type==1:退出房间,进入到首页 2:退出当前页,不导航到首页,是从首页点击关闭悬浮退出的
- public void performExitRoom(int type) {
- // 清理最小化状态
- clearMinimizeState();
- isMinimized = false;
-
- // 执行退出房间逻辑
- CommonAppContext.getInstance().isPlaying = false;
- CommonAppContext.getInstance().isShow = false;
- QXGiftPlayerManager.getInstance(this).destroyEffectSvga();
- // 停止屏幕捕获和其他资源
-// AgoraManager.getInstance(this).stopScreenCapture();
-// AgoraManager.getInstance(this).leaveRoom();
-// AgoraManager.getInstance(this).stopMusicPlayer();
- AgoraManager.getInstance(this).cleanup();
-
- MyRoomSingleton.getInstance().onExitRoom();
- MessageListenerSingleton.getInstance().quitGroup(roomId);
- // 清理ViewModel中的数据
-// if (sharedViewModel != null) {
-// sharedViewModel.clearAllData();
-// }
- RoomManager.getInstance().exitRoom(roomId);
- // 清理资源
- cleanupResources();
- if (type == 1) {
- // 导航到首页
- navigateToMainPage();
- } else if (type == 2) {
- // 返回上一个页面
- finish();
- }
-
- finish();
- }
-
- // 添加前后台状态检测
- private boolean isAppInForeground() {
- if (mRoomInfoResp==null){
- return true;
- }
- if (!mRoomInfoResp.getRoom_info().getLabel_id().equals("6")) {
- ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
- List appProcesses = activityManager.getRunningAppProcesses();
- if (appProcesses == null) {
- return false;
- }
-
- final String packageName = getPackageName();
- for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
- if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
- && appProcess.processName.equals(packageName)) {
- return true;
- }
- }
- } else {
- return true;
- }
- return false;
- }
-
- private void navigateToMainPage() {
- ARouter.getInstance()
- .build(ARouteConstants.ME)
- .navigation();
-
- // 添加转场动画
- overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
- }
-
- private void quitUpRoom() {
- // 清理最小化状态
- clearMinimizeState();
- isMinimized = false;
-
- // 执行退出房间逻辑
- CommonAppContext.getInstance().isPlaying = false;
- CommonAppContext.getInstance().isShow = false;
- QXGiftPlayerManager.getInstance(this).destroyEffectSvga();
- // 停止屏幕捕获和其他资源
-// AgoraManager.getInstance(this).stopScreenCapture();
- AgoraManager.getInstance(this).leaveRoom();
-// AgoraManager.getInstance(this).stopMusicPlayer();
- AgoraManager.getInstance(this).cleanup();
-
- MyRoomSingleton.getInstance().onExitRoom();
- MessageListenerSingleton.getInstance().quitGroup(roomId);
- cleanupResources();
- }
-
- private void minimizeToBackground() {
- isMinimized = true;
- // 保存最小化状态和房间ID
- saveMinimizeState();
- // 设置应用状态
- CommonAppContext.getInstance().isShow = false;
- // 通知状态管理器RoomActivity已最小化
- if (appStateListener != null) {
- appStateListener.setAppInBackground(true);
- }
- QXGiftPlayerManager.getInstance(getApplicationContext()).destroyEffectSvga();
-// ARouter.getInstance().build(ARouteConstants.ME)
-// .addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP)
-// .navigation();
-
- // 使用Intent启动主Activity,通过ARouter路径
- // 这样可以避免模块间的直接依赖
- try {
- Intent intent = new Intent();
- intent.setClassName(getPackageName(), "com.xscm.modulemain.activity.MainActivity");
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- startActivity(intent);
- } catch (Exception e) {
- // 如果直接指定类名失败,则使用默认的Launcher Activity
- Intent startMain = new Intent(Intent.ACTION_MAIN);
- startMain.addCategory(Intent.CATEGORY_HOME);
- startMain.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- startActivity(startMain);
- }
-
- // 隐藏Activity而不是销毁它
-// moveTaskToBack(true);
- // 使用 moveTaskToBack 将应用最小化
-// moveTaskToBack(true);
- }
-
- private void saveMinimizeState() {
- SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(PREF_MINIMIZED_ROOM, roomId);
- editor.putLong(PREF_MINIMIZED_TIME, System.currentTimeMillis());
- editor.putBoolean("is_minimized", true);
- editor.apply();
- }
-
- private void clearMinimizeState() {
- SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.remove(PREF_MINIMIZED_ROOM);
- editor.remove(PREF_MINIMIZED_TIME);
- editor.putBoolean("is_minimized", false);
- editor.apply();
- }
-
- private boolean wasMinimized() {
- SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
- return prefs.getBoolean("is_minimized", false);
- }
-
- private void queren() {
- // 创建并显示确认对话框
- ConfirmDialog dialog = new ConfirmDialog(this,
- "提示",
- "您将要发起点歌申请?",
- "确认",
- "取消",
- v -> {
- // 点击“确认”按钮时执行删除操作
- MvpPre.applySong(roomId);
- },
- v -> {
- // 点击“取消”按钮时什么都不做
- }, false, 0);
- dialog.show();
- addActiveDialog(dialog);
- }
-
- /**
- * 设置是否打开麦克风
- *
- * @param type
- */
- // @Override
- public void switchMic(int type) {
- if (type == 1) {
- mBinding.ivMic.setImageResource(com.xscm.moduleutil.R.mipmap.room_microphone);
- AgoraManager.getInstance(this).setLocalAudioEnabled(true, SpUtil.getUserId() + "");
- isSwith = false;
- AgoraManager.getInstance(this).muteLocalAudioStream(false);
- AgoraManager.getInstance(this).ClientRole(true);
- } else {
- mBinding.ivMic.setImageResource(com.xscm.moduleutil.R.mipmap.room_microphone_off);
- AgoraManager.getInstance(this).setLocalAudioEnabled(false, SpUtil.getUserId() + "");
- isSwith = true;
- isMute(1);
-
- }
-
- }
-
- /// 进入小黑屋将所有的底部隐藏
- public void setviewyc(boolean voive) {
- mBinding.rlMore.setVisibility(voive ? GONE : View.GONE);
- mBinding.rlMisc.setVisibility(voive ? GONE : View.GONE);
- mBinding.rlMic.setVisibility(voive ? VISIBLE : View.GONE);
- mBinding.rlSett.setVisibility(voive ? VISIBLE : View.GONE);
- mBinding.rlVoive.setVisibility(voive ? VISIBLE : View.GONE);
- mBinding.rlGift.setVisibility(voive ? VISIBLE : View.GONE);
- mBinding.ivSoundEffects.setVisibility(voive ? VISIBLE : View.GONE);
- mBinding.ivWheatFeeding.setVisibility(voive ? VISIBLE : View.GONE);
- mBinding.clFirstCharge.setVisibility(voive ? VISIBLE : View.GONE);
- }
-
- /// 这里是当进入电影放房的时候,如果是排麦模式,并且不是电影放的时候,就隐藏排麦视图
- public void clFirstCharge(boolean voive) {
- mBinding.clFirstCharge.setVisibility(voive ? View.VISIBLE : View.GONE);
- }
-
- public void ivWheatFeeding(int id) {
- mBinding.ivWheatFeeding.setImageResource(id);
- }
-
- public void setBoolean(boolean voive) {
- this.aBoolean = voive;
- }
-
- public void ivSoundEffects(boolean voive) {
- mBinding.ivSoundEffects.setVisibility(voive ? View.VISIBLE : View.GONE);
- }
-
- public void tvFirst(SpannableStringBuilder s) {
- mBinding.tvFirst.setText(s);
- }
-
- public void setrlMic(boolean voive) {
- mBinding.rlMic.setVisibility(voive ? VISIBLE : View.GONE);
- }
-
- public void rlMore(boolean voive) {
- mBinding.rlMore.setVisibility(voive ? GONE : View.GONE);
- }
-
- public void ivMic(int inIvMic) {
- mBinding.ivMic.setImageResource(inIvMic);
- }
-
- public void setRoleType(int roleType, int pit_number) {
- RelativeLayout rl_voice = mBinding.rlVoive; // 注意:原拼写错误已修正
- RelativeLayout rl_mic = mBinding.rlMic;
- RelativeLayout rl_more = mBinding.rlMore;
- RelativeLayout rl_misc = mBinding.rlMisc;
-
- // 默认隐藏所有按钮
- rl_voice.setVisibility(View.GONE);
- rl_more.setVisibility(View.GONE);
- rl_misc.setVisibility(View.GONE);
- rl_mic.setVisibility(View.GONE);
-
- // 空指针保护
- if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null || mRoomInfoResp.getUser_info() == null) {
- return;
- }
-
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- int userPitNumber = mRoomInfoResp.getUser_info().getPit_number();
-
- // 特殊房间类型处理(优先级最高)
- if ("6".equals(typeId)) {
- mBinding.rlMessage.setVisibility(View.GONE);
- return; // 全部隐藏,无需继续处理
- }
-
-
- // 根据角色类型显示按钮
- switch (roleType) {
- case 1: // 房主
- case 2: // 主持人
- case 3: // 麦上用户
- rl_voice.setVisibility(View.VISIBLE);
- rl_mic.setVisibility(pit_number != 0 ? View.VISIBLE : View.GONE);
- rl_more.setVisibility(pit_number == 9 ? GONE : View.GONE);
- rl_misc.setVisibility(GONE);
- break;
- case 0: // 观众
- rl_voice.setVisibility(View.VISIBLE);
- rl_mic.setVisibility(pit_number != 0 ? View.VISIBLE : View.GONE);
- rl_misc.setVisibility(GONE);
- break;
- case 5: // 房间管理员
- rl_voice.setVisibility(View.VISIBLE);
- rl_more.setVisibility(View.GONE);
- rl_misc.setVisibility(View.GONE);
- break;
- default:
- break;
- }
- if (roleType != 5) {
- rl_misc.setVisibility(GONE);
- if (userPitNumber == 9) {
- rl_more.setVisibility(GONE);
- }
- }
-
-
- // label_id 和 type_id 联合判断
- if (Arrays.asList("1", "3", "4", "8").contains(typeId) && "2".equals(labelId)) {
- rl_more.setVisibility(View.GONE);
- }
-
- // mic 显示逻辑
- if (userPitNumber > 0) {
- rl_mic.setVisibility(View.VISIBLE);
- switchMic(2);
- } else {
- if (pit_number == 888) {
- rl_mic.setVisibility(View.VISIBLE);
- switchMic(2);
- } else if (pit_number == -1) {
- rl_mic.setVisibility(View.VISIBLE); // 原代码此处缺少 View. 前缀,已补全
- switchMic(1);
- } else {
- rl_mic.setVisibility(View.GONE);
- switchMic(2);
- }
- }
-
- if ("7".equals(typeId) || "2".equals(typeId)) {
- rl_more.setVisibility(View.GONE);
- rl_misc.setVisibility(View.GONE);
- }
- }
-
-
- public void isMute(int is_mute) {
- RoomMessageEvent.text text = new RoomMessageEvent.text();
- text.setIs_mute(is_mute);
- String s = com.blankj.utilcode.util.GsonUtils.toJson(text);
- RoomMessageEvent.T t = new RoomMessageEvent.T();
- t.setFromUserInfo(SpUtil.getUserInfo());
- t.setText(s);
- RoomMessageEvent roomMessageEvent = new RoomMessageEvent(126, mRoomInfoResp.getRoom_info().getRoom_id(), t);
- String json = com.blankj.utilcode.util.GsonUtils.toJson(roomMessageEvent);
- // 转换为 byte[]
- byte[] binaryData = json.getBytes(StandardCharsets.UTF_8);
- // 创建自定义消息
- MessageListenerSingleton.getInstance().sendCustomRoomMessage(
- roomId + "",
- binaryData
- );
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void roomInfoEvent(RoomWheatEvent messageEvent) {
- if (messageEvent.getRoomId().equals(roomId)) {
- if (messageEvent.isOccupied()) {
- mBinding.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding_up);
- aBoolean = false;
- } else {
- mBinding.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding);
- aBoolean = true;
- }
- }
- }
-
- @SuppressLint("MissingInflatedId")
- public void dialogDismiss() {
-
-// // 使用 AlertDialog.Builder
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- LayoutInflater inflater = getLayoutInflater();
- View dialogView = inflater.inflate(com.xscm.moduleutil.R.layout.room_message_input_menu, null);
- builder.setView(dialogView);
- EditText etContent = dialogView.findViewById(com.xscm.moduleutil.R.id.et_content);
- Button tvSend = dialogView.findViewById(com.xscm.moduleutil.R.id.tv_send);
- // 创建 AlertDialog
- final AlertDialog dialog = builder.create();
- // 设置对话框在底部显示
- // 设置对话框在底部显示
- Window window = dialog.getWindow();
- if (window != null) {
- window.setGravity(Gravity.BOTTOM);
- // 修复宽度问题
- window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
- WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
- window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
-
- // 添加额外的窗口属性设置
- WindowManager.LayoutParams params = window.getAttributes();
- params.width = WindowManager.LayoutParams.MATCH_PARENT;
- params.height = WindowManager.LayoutParams.WRAP_CONTENT;
- params.horizontalMargin = 0;
- window.setAttributes(params);
- }
- dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
- tvSend.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (!canSend) {
- com.hjq.toast.ToastUtils.show("消息发送较频繁~");
- return;
- }
- String text = etContent.getText().toString();
- if (TextUtils.isEmpty(text)) {
- com.hjq.toast.ToastUtils.show("发送消息不哪呢过为空");
- return;
- }
- EventBus.getDefault().post(new RoomInputEvent(text));
- if (publicScreenFragment != null) {
- publicScreenFragment.fasong(new RoomInputEvent(text));
- }
- etContent.setText("");
- countDownTimer();
- dialog.dismiss();
- }
- });
-
- dialog.setOnShowListener(new DialogInterface.OnShowListener() {
- @Override
- public void onShow(DialogInterface dialogInterface) {
- etContent.requestFocus();
- InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(etContent, InputMethodManager.SHOW_IMPLICIT);
- }
- });
- if (inputSting != null) {
- etContent.setText(inputSting);
- }
- dialog.show();
- addActiveDialog(dialog); // 添加到管理列表
- inputSting = "";
- }
-
- private void countDownTimer() {
- releaseCountDownTimer();
- mCountDownTimer = new CountDownTimer(3 * 1000L, 1000L) {
- @Override
- public void onTick(long millisUntilFinished) {
- canSend = false;
- }
-
- @Override
- public void onFinish() {
- canSend = true;
- }
- };
- mCountDownTimer.start();
- }
-
- private void releaseCountDownTimer() {
- if (mCountDownTimer != null) {
- mCountDownTimer.cancel();
- mCountDownTimer = null;
- }
- }
-
- String inputSting;
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void roomInfoEvent(UserInfo messageEvent) {
-// mBinding.llInput.setVisibility(View.VISIBLE);
-// mBinding.inputMenu1.bringToFront(); // 强制将该 View 置于最上层
-// mBinding.inputMenu1.show();
-// mBinding.inputMenu1.setText("@" + messageEvent.getNickname());
- inputSting = "@" + messageEvent.getNickname();
- dialogDismiss();
- }
-
- @Override
- protected int getLayoutId() {
- return R.layout.activity_room;
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void roomOut(RoomOutEvent roomOutEvent) {
-// MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
- performExitRoom(2);
- }
-
- @Override
- protected RoomPresenter bindPresenter() {
- return new RoomPresenter(this, this);
- }
-
- public void upRoomInfo(RoomInfoResp resp) {
- this.mRoomInfoResp = resp;
- if (mRoomInfoResp.getUser_info().getPit_number() == 9 && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId() + "")) {
- mBinding.roomTop.rl.setVisibility(View.VISIBLE);
- ivSoundEffects(true);
- } else {
- mBinding.roomTop.rl.setVisibility(View.GONE);
- ivSoundEffects(false);
- }
- }
-
- // TODO: 2025/8/26 加入房间
- @Override
- public void roomInfo(RoomInfoResp resp) {
- AppStateManager.getInstance().setRoomInfo(resp);
- this.mRoomInfoResp = resp;
- RoomBean roomBean = resp.getRoom_info();
- this.mRoomBean = roomBean;
- this.mRoomUserBean = resp.getUser_info();
- this.mRoomOwnerBean = resp.getRoom_owner();
- this.mPitList = mRoomBean.getPit_list();
- this.roomId = roomBean.getRoom_id();
- MessageListenerSingleton.getInstance().joinGroup(roomId);//加入房间im
- ImageUtils.loadHeadCC(resp.getRoom_info().getRoom_cover(), mBinding.roomTop.avatar);
- mBinding.roomTop.name.setText(roomBean.getRoom_name());
- mBinding.roomTop.idVal.setText("ID:" + roomBean.getRoom_number());
- if (mRoomUserBean.getIs_room_owner() == 1) {
- mBinding.roomTop.btnFollow.setVisibility(GONE);
- } else {
- mBinding.roomTop.btnFollow.setVisibility(VISIBLE);
- if (resp.isCollect()) {
- mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.collected));
- mBinding.roomTop.btnFollow.setText("");
- }
- }
- number = roomBean.getOnline_number();
- mBinding.roomTop.tvNum.setText(number + "");
-
- StringBuilder userIds = new StringBuilder();
- for (int i = 0; i < mRoomInfoResp.getRoom_info().getPit_list().size(); i++) {
- String userId = mRoomInfoResp.getRoom_info().getPit_list().get(i).getUser_id();
- if (userId != null && !userId.equals("0") && !userId.isEmpty()) {
- if (userIds.length() > 0) {
- userIds.append(",");
- }
- userIds.append(userId);
- }
- }
- initPublicScreenFragment();
- if (!isFinishing() && !isDestroyed()) {
- resetFragment();
- upHeight();
-
- } else {
- Log.e("Fragment", "Fragment transaction skipped due to state loss.");
- }
- LogUtils.e("加入", roomId);
-
- CommonAppContext.getInstance().isPlaying = true;
- CommonAppContext.getInstance().playId = roomId;
- CommonAppContext.getInstance().playName = mRoomBean.getRoom_name();
-
- CommonAppContext.getInstance().playCover = resp.getRoom_info().getRoom_cover();
- CommonAppContext.getInstance().showSelf = resp.getIs_show_self() == 1;
-
- if (mRoomUserBean.getIs_collect() == 1) {
- mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.yishouc));
- mBinding.roomTop.btnFollow.setText("");
- } else {
- ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.roomTop.btnFollow, ColorManager.getInstance().getPrimaryColorInt(), 53);
- mBinding.roomTop.btnFollow.setTextColor(ColorManager.getInstance().getButtonColorInt());
- mBinding.roomTop.btnFollow.setText("收藏");
-// mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.collect));
- }
- if ((roomBean.getType_id().equals("3") || roomBean.getType_id().equals("1") || roomBean.getType_id().equals("4")) && roomBean.getLabel_id().equals("2")) {
- AgoraManager.getInstance(this).setBjMusic(false);
- } else {
- AgoraManager.getInstance(this).setBjMusic(true);
- }
-
- AgoraManager.getInstance(this).stopMuisc();
- initializeAudio();
-
-
- toutiao();
- upRoomInfo(resp);
-
-
- if (userIds.length() > 0 && roomId != null) {
-// MvpPre.userOnlineStatus(userIds.toString(), roomId);
- }
- if (publicScreenFragment != null) {
- publicScreenFragment.getUpRoomInfo(resp);
- }
- instView();
-
- if (mRoomInfoResp.getUser_info().getPit_number() == 9 && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId() + "")) {
- mBinding.roomTop.rl.setVisibility(View.VISIBLE);
- ivSoundEffects(true);
- } else {
- mBinding.roomTop.rl.setVisibility(View.GONE);
- ivSoundEffects(false);
- }
-
- if (resp.getRoom_info().getType_id().equals("7") || resp.getRoom_info().getType_id().equals("2")) {
- mBinding.rlMore.setVisibility(GONE);
- mBinding.rlMisc.setVisibility(GONE);
- }
- setupEffectView();
-
- if (mRoomInfoResp.getGift_cycle()!=null && mRoomInfoResp.getGift_cycle().getXlh_info()!=null && mRoomInfoResp.getGift_cycle().getXlh_info().getXlh_status()!=null && mRoomInfoResp.getGift_cycle().getXlh_info().getXlh_status().equals("1")){
- mBinding.xlhRk.setVisibility(View.VISIBLE);
- xlhDjs(mRoomInfoResp.getGift_cycle().getXlh_info().getEnd_time());
- } else {
- mBinding.xlhRk.setVisibility(INVISIBLE);
- releaseCountDownTimer1();
- }
-
-// sharedViewModel.setDataForFragment(mRoomInfoResp);
-//
- }
-
- private void instView() {//隐藏视图
-
- if (mRoomInfoResp.getUser_info().getPit_number() != 0) {
- aBoolean = false;
- ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding_up);
- setrlMic(true);
- setBoolean(aBoolean);
- } else {
- aBoolean = true;
- ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding);
- setrlMic(false);
- setBoolean(aBoolean);
- }
- int pitNumber = mRoomInfoResp.getUser_info().getPit_number();
- int roleType;
-
- if (pitNumber == 9) {
- roleType = mRoomInfoResp.getUser_info().getIs_room_owner() != 0 ? 1 :
- mRoomInfoResp.getUser_info().getIs_host() != 0 ? 2 : 0;
- } else if (pitNumber != 0 && pitNumber != 9) {
- roleType = 3;
- } else {
- roleType = 0;
- }
- if (mRoomInfoResp.getUser_info().getPit_number() == 9) {
- ivSoundEffects(true);
- } else {
- ivSoundEffects(false);
- }
-// }
- if (mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId() + "") && mRoomInfoResp.getUser_info().getPit_number() == 9
- && !mRoomInfoResp.getRoom_info().getType_id().equals("2") && !mRoomInfoResp.getRoom_info().getType_id().equals("6")) {
- rlMore(true);
-
- } else {
- rlMore(false);
- }
- String countText = String.valueOf(mRoomInfoResp.getRoom_info().getQueue_number());
- String fullText = countText + "人排队";
-
- SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(fullText);
- spannableStringBuilder.setSpan(
- new ForegroundColorSpan(ContextCompat.getColor(this, com.xscm.moduleutil.R.color.colorPrimary)), // 设置颜色为红色
- 0, // 起始位置
- countText.length(), // 结束位置
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
- );
-
- tvFirst(spannableStringBuilder);
- setRoleType(roleType, pitNumber);
- }
-
- private static final long CLICK_DELAY = 500; // 延迟时间,单位毫秒
- private boolean isClick = false;
- private boolean isIntercepted = false;
- private long downTime;
-
- /// 头条
- public void toutiao() {
- if (mRoomInfoResp.getRoom_info().getHead_line() != null) {
- mBinding.flaoatZuoji.setVisibility(VISIBLE);
-
- ImageUtils.loadHeadCC(mRoomInfoResp.getRoom_info().getHead_line().getAvatar(), mBinding.headAvate);
- mBinding.headName.setText(mRoomInfoResp.getRoom_info().getHead_line().getNickname());
- mBinding.headCone.setText(mRoomInfoResp.getRoom_info().getHead_line().getContent());
-
- mBinding.ivQuanQiang.setOnClickListener(v -> {
- PublishCommentDialogFragment fragment = PublishCommentDialogFragment.show(roomId, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- });
- mBinding.ivQuanC.setOnClickListener(v -> ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS)
- .withString("from", "我的界面")
- .withString("roomId", mRoomInfoResp.getRoom_info().getHead_line().getRoom_id())
- .navigation());
-
- mBinding.imYc.setOnClickListener(v -> {
- if (imYc) {
- mBinding.cl.setVisibility(VISIBLE);
- imYc = false;
- } else {
- mBinding.cl.setVisibility(GONE);
- imYc = true;
- }
- });
-
- mBinding.imHq.setOnClickListener(v -> {
- if (!imYc) {
- mBinding.cl.setVisibility(VISIBLE);
- imYc = true;
- } else {
- mBinding.cl.setVisibility(GONE);
- imYc = false;
- }
- });
-
- final GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
- @Override
- public boolean onDown(MotionEvent e) {
- return true;
- }
-
- @Override
- public boolean onSingleTapUp(MotionEvent e) {
- if (!imYc) {
- mBinding.cl.setVisibility(VISIBLE);
- imYc = true;
- } else {
- mBinding.cl.setVisibility(GONE);
- imYc = false;
- }
- return true;
- }
-
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
- mBinding.flaoatZuoji.onTouchEvent(e2);
- return true;
- }
- });
-
- mBinding.imHq.setOnTouchListener((v, event) -> gestureDetector.onTouchEvent(event));
-
- silentCountDownTimer = new SilentCountDownTimer();
- silentCountDownTimer.setOnCountDownFinishListener(() -> {
- Log.d("CountDown", "倒计时结束,执行清理或通知操作");
- hideSomeViewOrDoSomething();
- });
-
- silentCountDownTimer.start(Long.parseLong(mRoomInfoResp.getRoom_info().getHead_line().getEnd_time()));
- } else {
- mBinding.flaoatZuoji.setVisibility(GONE);
- }
- }
-
- private void hideSomeViewOrDoSomething() {
- runOnUiThread(() -> {
- // 执行你需要的操作,比如隐藏某个控件
-// mBinding.someView.setVisibility(View.GONE);
- mBinding.flaoatZuoji.setVisibility(GONE);
- });
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onHeadlineEvent(HeadlineBean event) {
- mRoomInfoResp.getRoom_info().setHead_line(event);
- toutiao();
- }
-
- /**
- * @author qx
- * @data 2025/6/27
- * @description: 初始化音频,初始的时候,当是在麦上,将用户设置为主持,在麦下,设置为观众, 默认关闭麦克风
- */
- public void initializeAudio() {
- if (mRoomUserBean.getPit_number() != 0) {
- AgoraManager.getInstance(this).ClientRole(true);
- AgoraManager.getInstance(this).muteLocalAudioStream(false);
- } else {
- AgoraManager.getInstance(this).ClientRole(false);
- AgoraManager.getInstance(this).muteLocalAudioStream(true);
- }
- AgoraManager.getInstance(this).setLocalAudioEnabled(false, SpUtil.getUserId() + "");
- }
-
- @Override
- public void showPasswordDialog() {
- RoomPasswordSetDialogFragment roomPasswordSetDialogFragment = RoomPasswordSetDialogFragment.newInstance(true, roomId);
- roomPasswordSetDialogFragment.show(getSupportFragmentManager());
- addActiveDialogFragment(roomPasswordSetDialogFragment);
- }
-
- @Override
- public void enterFail() {
- releaseRoom();
- finish();
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void logOutEvent(MusicEvent musicEvent) {
-// mBinding.musicView.setVisibility(VISIBLE);
-// musicWindowControl.show(); // <<< 添加这行代码
- if (!isMusic) {
- xunf();
- isMusic = true;
- }
-// RequestDialogFragment.show(roomId, mRoomInfoResp, 2, getSupportFragmentManager());
- RequestDialogFragment fragment = RequestDialogFragment.show(roomId, mRoomInfoResp, 2, getSupportFragmentManager());
- if (fragment != null) {
- addActiveDialogFragment(fragment); // 添加到管理列表
- }
- }
-
- /**
- * 背景音乐
- */
- private boolean isMusic = false;
-
- /// 悬浮框
- private void xunf() {
- musicWindowControl = FxScopeHelper.builder()
- .setLayout(com.xscm.moduleutil.R.layout.room_dialog_music_window_open)
- .build()
- .toControl(this);
- // 创建自定义悬浮窗包装类
- customMusicFloatingView = new CustomMusicFloatingView(this, musicWindowControl);
-
- customMusicFloatingView.setOnItemClickListener(new OnMusicItemClickListener() {
- @Override
- public void onMinimize() {
- customMusicFloatingView.destroy();
- AgoraManager.getInstance(RoomActivity.this).desMusic();
- isMusic = false;
- }
-
- @Override
- public void onOpenList() {
- // 打开音乐列表
-// ToastUtils.showShort("打开音乐列表");
- RequestDialogFragment.show(roomId, mRoomInfoResp, 2, getSupportFragmentManager());
- }
-
- @Override
- public void onPause() {
-// ToastUtils.showShort("暂停播放");
- // 调用播放器或通知 MusicView
- AgoraManager.getInstance(RoomActivity.this).pauseMusic();
- }
-
- @Override
- public void onResume() {
-// ToastUtils.showShort("恢复播放");
- // 调用播放器或通知 MusicView
- AgoraManager.getInstance(RoomActivity.this).resumeMusic();
- }
-
- @Override
- public void onNext() {
-// ToastUtils.showShort("下一首");
- // 切换歌曲
-// List musicSongBeans = AgoraManager.getInstance(RoomActivity.this).getMusicList();
- AgoraManager.getInstance(RoomActivity.this).nextSong();
- }
- });
-// customMusicFloatingView.initView();
- customMusicFloatingView.show();
- // 等待 View 创建完成后才绑定点击事件
- ViewUtils.waitUntilViewReady(musicWindowControl, view -> {
- customMusicFloatingView.initView(); // 这里 fxControl.getView() 不再为 null
- customMusicFloatingView.updatePlayState(false);
- });
-
-
- }
-
- // 添加成员变量来跟踪前后台状态
- private boolean isInBackground = false;
-
- @Override
- protected void onResume() {
- super.onResume();
- CommonAppContext.getInstance().isShow = true;
- CommonAppContext.getInstance().isPlaying = true;
- CommonAppContext.getInstance().isRoomJoininj=false;
- // 当Activity恢复时,重置标记
- userLeaving = true;
-// // 正常启动或从后台恢复
-// if (isInBackground) {
-// isInBackground = false;
-// // 从后台回到前台时调用
-// if (MvpPre != null && roomId != null) {
-// if (mRoomInfoResp != null && mRoomInfoResp.getRoom_info() != null) {
-// if (mRoomInfoResp.getRoom_info().getType_id().equals("1")
-// || mRoomInfoResp.getRoom_info().getType_id().equals("3") ||
-// mRoomInfoResp.getRoom_info().getType_id().equals("4")||
-// mRoomInfoResp.getRoom_info().getType_id().equals("8")) {
-// if (mRoomInfoResp.getRoom_info().getLabel_id().equals("2")) {
-//
-// } else {
-// MvpPre.postRoomInfo(roomId);
-// }
-// }
-// } else {
-// MvpPre.postRoomInfo(roomId);
-// }
-// } else {
-// ToastUtils.showLong("您已经掉线,需要重新进入房间!");
-// ARouter.getInstance().build(ARouteConstants.ME)
-// .navigation();
-// cleanupResources();
-// finish();
-// }
-// }
-// if (appStateListener != null && appStateListener.isAppInBackground()) {
-// MvpPre.postRoomInfo(roomId);
-// }
-
-
- // 检查是否从最小化状态恢复
- if (isMinimized) {
- isMinimized = false;
- clearMinimizeState();
- // 恢复房间状态
- resumeRoomState();
- setupEffectView();
- resetFragment();
- }
-
- // 延迟调整布局,确保视图已经完全加载
- mBinding.mainContentContainer.post(this::adjustLayoutHeights);
- }
-
- // 添加检查房间连接状态的方法
- private void resumeRoomState() {
- // 恢复房间相关状态
- if (MvpPre != null && roomId != null) {
- MvpPre.postRoomInfo(roomId);
- }
-
- // 重新连接房间相关服务
- if (MessageListenerSingleton.getInstance() != null) {
- MessageListenerSingleton.getInstance().joinGroup(roomId);
- }
-
- // 恢复音频状态
- if (AgoraManager.getInstance(this) != null) {
- AgoraManager.getInstance(this).resumeMusic();
- }
-
- // 清除最小化状态标志
- isMinimized = false;
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- // 只有在真正进入后台时才标记
- if (!isAppInForeground()) {
- isInBackground = true;
- }
- }
-
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- super.onWindowFocusChanged(hasFocus);
- if (hasFocus && !isLayoutAdjusted) {
- adjustLayoutHeights();
- isLayoutAdjusted = true;
- }
- }
-
- int maxHeightDp = 333;
-
- /**
- * 动态调整布局高度以适配不同设备
- */
- private void adjustLayoutHeights() {
- if (mBinding == null) return;
-
- try {
- // 获取主容器
- ConstraintLayout mainContainer = mBinding.mainContentContainer;
- View pager = mBinding.vpRoomPager;
- View easeContainer = mBinding.easeContainer;
-
- if (mainContainer != null && pager != null && easeContainer != null) {
- // 强制测量主容器
- int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
- int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
- mainContainer.measure(widthSpec, heightSpec);
-
- int containerHeight = mainContainer.getMeasuredHeight();
- if (containerHeight <= 0) {
- // 如果测量不到高度,使用布局参数中的高度
- ConstraintLayout.LayoutParams containerParams = (ConstraintLayout.LayoutParams) mainContainer.getLayoutParams();
- containerHeight = getResources().getDisplayMetrics().heightPixels
- - getStatusBarHeight()
- - getResources().getDimensionPixelSize(com.xscm.moduleutil.R.dimen.dp_50) // room_top 高度
- - getResources().getDimensionPixelSize(com.xscm.moduleutil.R.dimen.dp_15) * 3; // 底部控件高度
- }
-
- // 确保最小高度
- if (containerHeight > 0) {
- // 设置 vp_room_pager 占用 70% 空间
- ConstraintLayout.LayoutParams pagerParams = (ConstraintLayout.LayoutParams) pager.getLayoutParams();
- pagerParams.height = SystemUtils.getWidth(maxHeightDp);
- pager.setLayoutParams(pagerParams);
-
- // 设置 ease_container 占用 30% 空间
- ConstraintLayout.LayoutParams easeParams = (ConstraintLayout.LayoutParams) easeContainer.getLayoutParams();
- easeParams.height = 0;
- easeContainer.setLayoutParams(easeParams);
-
- // 请求重新布局
- mainContainer.requestLayout();
- }
- }
- } catch (Exception e) {
- LogUtils.e("adjustLayoutHeights error: " + e.getMessage());
- }
- }
-
- /**
- * 获取状态栏高度
- */
- private int getStatusBarHeight() {
- int result = 0;
- int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
- if (resourceId > 0) {
- result = getResources().getDimensionPixelSize(resourceId);
- }
- return result;
- }
-
-
- @Override
- public void getRoomOnline(RoomOnline onlineBean) {
- if (onlineBean != null) {
- List onlineBeans = new ArrayList<>();
- if (onlineBean.getOn_pit().size() > 0) {
- onlineBeans.addAll(onlineBean.getOn_pit());
- }
- if (onlineBean.getOff_pit().size() > 0) {
- onlineBeans.addAll(onlineBean.getOff_pit());
- }
- likeUserAdapter.setNewData(onlineBeans.subList(0, onlineBeans.size() > 3 ? 3 : onlineBeans.size()));
- }
- }
-
- @Override
- public void applyPit() {
-
- }
-
- @Override
- public void downPit() {
-
- }
-
- @Override
- public void applySong() {
-
- }
-
- @Override
- public void agreeSong() {
-
- }
-
- @Override
- public void onBackPressed() {
-
- if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
- if (isFullScreen) {
- exitFullScreen();
- }
- getSupportFragmentManager().popBackStack();
- } else {
- super.onBackPressed();
- }
- }
-
- @Override
- public void postRoomInfo(RoomInfoResp resp) {
- if (resp == null) {
-// CommonAppContext.getInstance().isShow = false;
-// CommonAppContext.getInstance().isPlaying = false;
-// ToastUtils.showShort("您已经掉线,需要重新进入房间!");
-// ARouter.getInstance().build(ARouteConstants.ME)
-// .navigation();
- // 只有在没有房间信息时才重新获取
- if (mRoomInfoResp == null) {
- cleanupResources();
- MvpPre.getRoomIn(roomId, password);
- }
- return;
- }
- this.mRoomInfoResp = resp;
-
-
- RoomBean roomBean = resp.getRoom_info();
- this.mRoomBean = roomBean;
- this.mRoomUserBean = resp.getUser_info();
- this.mRoomOwnerBean = resp.getRoom_owner();
- this.mPitList = mRoomBean.getPit_list();
-
- ImageUtils.loadHeadCC(resp.getRoom_info().getRoom_cover(), mBinding.roomTop.avatar);
- mBinding.roomTop.name.setText(roomBean.getRoom_name());
- mBinding.roomTop.idVal.setText(roomBean.getRoom_number());
- if (mRoomUserBean.getIs_room_owner() == 1) {
- mBinding.roomTop.btnFollow.setVisibility(GONE);
- } else {
- mBinding.roomTop.btnFollow.setVisibility(VISIBLE);
- if (resp.isCollect()) {
- mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.collected));
- mBinding.roomTop.btnFollow.setText("");
- }
- }
- initPublicScreenFragment();
- if (!isFinishing() && !isDestroyed()) {
- resetFragment();
- upHeight();
- } else {
- Log.e("Fragment", "Fragment transaction skipped due to state loss.");
- }
-
- if (mRoomUserBean.getIs_collect() == 1) {
- mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.yishouc));
- mBinding.roomTop.btnFollow.setText("");
- } else {
-// mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.collect));
- ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.roomTop.btnFollow, ColorManager.getInstance().getPrimaryColorInt(), 53);
- mBinding.roomTop.btnFollow.setTextColor(ColorManager.getInstance().getButtonColorInt());
- mBinding.roomTop.btnFollow.setText("收藏");
- }
- if ((resp.getRoom_info().getType_id().equals("3") || resp.getRoom_info().getType_id().equals("1") || resp.getRoom_info().getType_id().equals("4")) && resp.getRoom_info().getLabel_id().equals("2")) {
- AgoraManager.getInstance(this).setBjMusic(false);
- } else {
- AgoraManager.getInstance(this).setBjMusic(true);
- }
-
-
- AgoraManager.getInstance(this).stopMuisc();
- initializeAudio();
-
- if (mRoomInfoResp.getRoom_info().getLabel_id().equals("2") || mRoomInfoResp.getRoom_info().getType_id().equals("7")) {
- mBinding.rlMore.setVisibility(GONE);
-// mBinding.rlMisc.setVisibility(GONE);
- } else if (mRoomInfoResp.getRoom_info().getLabel_id().equals("1") || mRoomInfoResp.getRoom_info().getType_id().equals("3") || mRoomInfoResp.getRoom_info().getType_id().equals("4") ||
- mRoomInfoResp.getRoom_info().getType_id().equals("8")) {
- mBinding.rlMore.setVisibility(GONE);
- mBinding.rlMisc.setVisibility(GONE);
- }
-
- if (resp.getRoom_info().getType_id().equals("7") || resp.getRoom_info().getType_id().equals("2")) {
- mBinding.rlMore.setVisibility(GONE);
- mBinding.rlMisc.setVisibility(GONE);
- }
-
- }
-
-
- public void upHeight() {
- if (mRoomInfoResp.getRoom_info().getType_id().equals("1") || mRoomInfoResp.getRoom_info().getType_id().equals("3") || mRoomInfoResp.getRoom_info().getType_id().equals("4")
- || mRoomInfoResp.getRoom_info().getType_id().equals("8")) {
- if (mRoomInfoResp.getRoom_info().getLabel_id().equals("1")) {
- maxHeightDp = 333;
- } else {
- maxHeightDp = 287;
- }
-
- } else if (mRoomInfoResp.getRoom_info().getType_id().equals("2")) {
- maxHeightDp = 297;
- }
- if (mRoomInfoResp.getRoom_info().getType_id().equals("6")) {
- maxHeightDp = 453;
- } else if (mRoomInfoResp.getRoom_info().getType_id().equals("7")) {
- maxHeightDp = 373;
-
- }
- adjustLayoutHeights();
- }
-
-
- private void resetFragment() {
- String typeId = mRoomInfoResp.getRoom_info().getType_id();
- String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
- CommonAppContext.getInstance().lable_id = typeId;
- if (roomFragment == null) {
- roomFragment = RoomFragment.newInstance();
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.vp_room_pager, roomFragment)
- .commitAllowingStateLoss();
- }
-
- if ("7".equals(typeId)) {
- if (mRoomInfoResp.getRoom_info().getRoom_background() == null || mRoomInfoResp.getRoom_info().getRoom_background().equals("")) {
- changeBackground(com.xscm.moduleutil.R.mipmap.jiaoy_bj);
- } else {
- changeBackgroundColor(mRoomInfoResp.getRoom_info().getRoom_background());
- }
- setvisibTop(true);
- // 当需要传递数据给子Fragment时
-// sharedViewModel.setSeatViewType(QXRoomSeatViewType.FRIEND);
-// sharedViewModel.setDataForFragment(mRoomInfoResp);
- roomFragment.refreshData(mRoomInfoResp, QXRoomSeatViewType.FRIEND);
- } else if ("2".equals(typeId)) {
- changeBackgroundColor(mRoomInfoResp.getRoom_info().getRoom_background());
- setvisibTop(true);
-// sharedViewModel.setSeatViewType(QXRoomSeatViewType.AUCTION);
-// sharedViewModel.setDataForFragment(mRoomInfoResp);
- roomFragment.refreshData(mRoomInfoResp, QXRoomSeatViewType.AUCTION);
- } else if ("1".equals(typeId) || "3".equals(typeId) || "4".equals(typeId) || "8".equals(typeId)) {
- if ("2".equals(labelId)) {
- changeBackgroundColor(mRoomInfoResp.getRoom_info().getRoom_background());
- setvisibTop(true);
-// sharedViewModel.setSeatViewType(QXRoomSeatViewType.KTV);
- roomFragment.refreshData(mRoomInfoResp, QXRoomSeatViewType.KTV);
- } else if ("1".equals(labelId)) {
- changeBackgroundColor(mRoomInfoResp.getRoom_info().getRoom_background());
- setvisibTop(true);
-// sharedViewModel.setSeatViewType(QXRoomSeatViewType.NORMAL);
- roomFragment.refreshData(mRoomInfoResp, QXRoomSeatViewType.NORMAL);
- }
- } else if ("6".equals(typeId)) {
- changeBackground(com.xscm.moduleutil.R.mipmap.cabin_bj);
- setvisibTop(false);
-
-// sharedViewModel.setSeatViewType(QXRoomSeatViewType.CABIN);
- roomFragment.refreshData(mRoomInfoResp, QXRoomSeatViewType.CABIN);
- }
-
-// if (isMinimized) {
-// // 如果是从最小化状态恢复,使用轻量级方式更新数据
-// sharedViewModel.clearChildFragmentData();
-// // 只传递必要的信息,而不是整个RoomInfoResp对象
-// sharedViewModel.setChildFragmentData(mRoomInfoResp);
-// } else {
-// // 正常进入房间
-// sharedViewModel.clearChildFragmentData();
-// sharedViewModel.setChildFragmentData(mRoomInfoResp);
-// }
-
- // 先清除旧数据再设置新数据,确保更新
-// sharedViewModel.clearChildFragmentData();
-// sharedViewModel.setChildFragmentData(mRoomInfoResp);
- }
-
-
- @Override
- public void getCharmRank(List list) {
-
- }
-
- @Override
- public void changeSong() {
-
- }
-
- @Override
- public void hostUserPit() {
-
- }
-
- @Override
- public void quitRoom() {
- }
-
- //退出房间进行销毁
- public void quit() {
- CommonAppContext.getInstance().isPlaying = false;
- CommonAppContext.getInstance().isShow = false;
-// AgoraManager.getInstance(this).stopScreenCapture();
-// AgoraManager.getInstance(this).leaveRoom();
- AgoraManager.getInstance(this).cleanup();
- MyRoomSingleton.getInstance().onExitRoom();
- }
-
- @Override
- public void quitRoom2(String roomId) {
-
- }
-
- /// 小黑屋退出房间后调用这个加入房间
- public void jiaR() {
- LogUtils.e("@@@", "上一个房间的roonid" + AgoraManager.getInstance(context).getLastRoomId());
-// MvpPre.getRoomIn(AgoraManager.getInstance(context).getLastRoomId(), "");
- ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "电影房").withString("roomId", AgoraManager.getInstance(context).getLastRoomId()).navigation();
- AgoraManager.getInstance(context).setLastRoomId("");
-// setviewyc(true);
- }
-
- @Override
- public void userGuanzSuccess(String s) {
- if (mRoomUserBean.getIs_collect() == 1) {
- mRoomUserBean.setIs_collect(0);
-// mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.collect));
- ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.roomTop.btnFollow, ColorManager.getInstance().getPrimaryColorInt(), 53);
- mBinding.roomTop.btnFollow.setTextColor(ColorManager.getInstance().getButtonColorInt());
- mBinding.roomTop.btnFollow.setText("收藏");
- } else {
- mRoomUserBean.setIs_collect(1);
- mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.yishouc));
- mBinding.roomTop.btnFollow.setText("");
- }
- }
-
- @Override
- public void acceptPk() {
-
- }
-
- @Override
- public void clearUserCharm() {
-
- }
-
- @Override
- public void userOnlineStatus(List list) {
-// SpUtil.setUserOnline(GsonUtils.toJson(list));
- if (!list.isEmpty()) {
- for (int i = 0; i < list.size(); i++) {
- UserOnlineStatusBean userOnlineStatusBean = list.get(i);
- EventBus.getDefault().post(userOnlineStatusBean);
- }
- }
-
- }
-
- @Override
- public void findRoom() {
-
- }
-
- private void queren1(String nickname) {
- // 创建并显示确认对话框
- new ConfirmDialog(this,
- "温馨提示",
- "您申请点歌模式被主持人拒绝",
- "确认",
- "取消",
- v -> {
- // 点击“确认”按钮时执行删除操作
-
- },
- v -> {
- // 点击“取消”按钮时什么都不做
-
- }, false, 0).show();
- }
-
- private void queren(String nickname) {
- // 创建并显示确认对话框
- new ConfirmDialog(this,
- "温馨提示",
- "亲爱的主持,您好!\n\n " + "\t" + nickname + "正在发起点唱申请,进入点唱模式后背景音乐将自动停止播放",
- "确认",
- "拒绝",
- v -> {
- // 点击“确认”按钮时执行
- MvpPre.agreeSong(roomId, "1");
- },
- v -> {
- // 点击“取消”按钮时什么都不做
- MvpPre.agreeSong(roomId, "2");
- }, true, 10).show();
- }
-
- @Override
- protected void onDestroy() {
- // 只有在真正退出房间时才清理最小化状态
- if (!isMinimized) {
- clearMinimizeState();
- cleanupResources();
-
- }
- // 取消注册礼物播放完成监听器
-// unregisterGiftPlaybackListener();
-
- // 清理队列
-// giftQueue.clear();
-// giftUrlViewModel.deleteAllGiftUrls();
- // 清理所有可能的内存泄漏点
-// cleanupResources();
-
- // 确保父类的 onDestroy 被调用
- super.onDestroy();
-
-// // 通知RoomActivity已销毁
-// if (appStateListener != null) {
-// appStateListener.onRoomActivityDestroyed();
-// }
-//
-// // 如果Activity是被销毁而不是进入后台,隐藏悬浮窗
-// if (!isChangingConfigurations() && appStateListener != null) {
-// appStateListener.setFloatingWindowVisible(false);
-// }
-
- }
-
- public void cleanupResources() {
- sDestroied = true;
- overridePendingTransition(0, 0);
- try {
- // 1. 清理 EventBus 注册
- if (EventBus.getDefault().isRegistered(this)) {
- EventBus.getDefault().unregister(this);
- }
-
- // 2. 清理 Handler 回调
- if (roomSwitchHandler != null) {
- roomSwitchHandler.removeCallbacksAndMessages(null);
- }
-
- // 3. 清理 CountDownTimer
- releaseCountDownTimer();
- releaseCountDownTimer1();
- if (giftCountTimer != null) {
- giftCountTimer.cancel();
- giftCountTimer = null;
- }
-
- // 4. 清理 SVGA 资源
- clearSVGAResources();
-
- // 5. 清理自定义悬浮窗
- if (customMusicFloatingView != null) {
- customMusicFloatingView.destroy();
- customMusicFloatingView = null;
- }
-
- // 6. 清理 Agora 资源
-// if (AgoraManager.getInstance(this) != null) {
-// AgoraManager.getInstance(this).cleanup();
-// }
-// 清理所有弹框
- dismissAllDialogs();
- // 7. 清理 Fragment
- cleanupFragments();
-
- // 8. 清理监听器
- if (mBinding != null) {
- // 移除所有 OnClickListener 防止内存泄漏
- clearClickListeners();
- }
- ThreadUtils.cancel();
- QXGiftPlayerManager.getInstance(getApplicationContext()).destroyEffectSvga();
-
- } catch (Exception e) {
- LogUtils.e("cleanupResources error: " + e.getMessage());
- }
- }
-
- /**
- * 安全地将视图从当前父容器移动到新的父容器
- *
- * @param view 要移动的视图
- * @param newParent 新的父容器
- */
- private void safelyMoveViewToParent(View view, ViewGroup newParent) {
- if (view == null || newParent == null) {
- return;
- }
-
- // 如果视图已经在目标容器中,则不需要移动
- if (view.getParent() == newParent) {
- return;
- }
-
- // 先从当前父容器中移除
- ViewParent currentParent = view.getParent();
- if (currentParent != null && currentParent instanceof ViewGroup) {
- ((ViewGroup) currentParent).removeView(view);
- }
-
- // 添加到新的父容器
- newParent.addView(view);
- }
-
- // 清理所有弹框
- private void dismissAllDialogs() {
- // 关闭 AlertDialog 实例
- for (DialogInterface dialog : activeDialogs) {
- if (dialog != null) {
- try {
- dialog.dismiss();
- } catch (Exception e) {
- LogUtils.e("dismiss dialog error: " + e.getMessage());
- }
- }
- }
- activeDialogs.clear();
-
- // 移除 DialogFragment
- for (Fragment fragment : activeDialogFragments) {
- if (fragment != null && fragment.isAdded()) {
- try {
- if (fragment instanceof DialogFragment) {
- ((DialogFragment) fragment).dismissAllowingStateLoss();
- }
- } catch (Exception e) {
- LogUtils.e("dismiss dialog fragment error: " + e.getMessage());
- }
- }
- }
- activeDialogFragments.clear();
- }
-
- private void clearSVGAResources() {
- try {
- if (mBinding != null) {
- if (mBinding.svgaGift != null) {
-// mBinding.svgaGift.release();
- }
-// if (mBinding.svgaZuoji != null) {
-// mBinding.svgaZuoji.release();
-// }
- }
- } catch (Exception e) {
- LogUtils.e("clearSVGAResources error: " + e.getMessage());
- }
- }
-
- private void cleanupFragments() {
- try {
- // 清理Fragment
- if (publicScreenFragment != null || roomFragment != null) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- if (publicScreenFragment != null) {
- publicScreenFragment.onFragmentShowDestroy();
- transaction.remove(publicScreenFragment);
- publicScreenFragment = null;
- }
- if (roomFragment != null) {
- roomFragment.onFragmentShowDestroy();
- transaction.remove(roomFragment);
- roomFragment = null;
- }
- transaction.commitAllowingStateLoss();
- }
- } catch (Exception e) {
- LogUtils.e("cleanupFragments error: " + e.getMessage());
- }
- }
-
- private void clearClickListeners() {
- if (mBinding != null) {
- mBinding.roomTop.btnFollow.setOnClickListener(null);
- mBinding.roomTop.btnNotice.setOnClickListener(null);
- mBinding.roomTop.btnRanking.setOnClickListener(null);
- mBinding.roomTop.btnCloseLive.setOnClickListener(null);
- mBinding.roomTop.tvNum.setOnClickListener(null);
- mBinding.roomTop.rl.setOnClickListener(null);
- mBinding.ivSoundEffects.setOnClickListener(null);
- mBinding.ivWheatFeeding.setOnClickListener(null);
- mBinding.clFirstCharge.setOnClickListener(null);
- mBinding.ivChat.setOnClickListener(null);
- mBinding.llInput.setOnClickListener(null);
- mBinding.rlMisc.setOnClickListener(null);
- mBinding.rlGift.setOnClickListener(null);
- mBinding.rlMic.setOnClickListener(null);
- mBinding.rlSett.setOnClickListener(null);
- mBinding.rlVoive.setOnClickListener(null);
- mBinding.rlMore.setOnClickListener(null);
- mBinding.rlMessage.setOnClickListener(null);
- }
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- isSave = true;
- }
-
- private static final String[] AUDIO_PERMISSIONS = {Manifest.permission.RECORD_AUDIO};
-
- private void requestAudioPermission() {
- if (!EasyPermissions.hasPermissions(getApplicationContext(), AUDIO_PERMISSIONS)) {
- EasyPermissions.requestPermissions(
- this,
- "需要录音权限以使用语音功能",
- 1001,
- AUDIO_PERMISSIONS
- );
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
- @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
- }
-
- @Override
- public void onPermissionsGranted(int requestCode, @NonNull List perms) {
- if (perms.contains(Manifest.permission.RECORD_AUDIO)) {
- Log.d("Permission", "录音权限已授权");
- }
- }
-
- @Override
- public void onPermissionsDenied(int requestCode, @NonNull List perms) {
- if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
- new AppSettingsDialog.Builder(this).build().show();
- } else {
- ToastUtils.showShort("需要录音权限才能继续");
- }
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onMusicEvent(Music event) {
- if (customMusicFloatingView != null) {
- customMusicFloatingView.onMusicEvent(event);
- }
- }
-
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onMusicPlay(MusicPlayBean musicPlayBean) {
- if (customMusicFloatingView != null) {
- customMusicFloatingView.updateProgress(Math.toIntExact(musicPlayBean.getPosition()));
- }
- }
-
- @Override
- public void onMessageReceived(RoomMessageEvent message) {
- EventBus.getDefault().post(message);
- }
-}
\ No newline at end of file
diff --git a/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.kt b/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.kt
new file mode 100644
index 0000000..782c664
--- /dev/null
+++ b/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.kt
@@ -0,0 +1,4381 @@
+package com.example.moduleroom.activity
+
+import android.Manifest
+import android.annotation.SuppressLint
+import android.app.ActivityManager
+import android.app.AlertDialog
+import android.content.Context
+import android.content.DialogInterface
+import android.content.Intent
+import android.content.pm.ActivityInfo
+import android.content.res.Configuration
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Build
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.os.Handler
+import android.os.Looper
+import android.text.Spannable
+import android.text.SpannableStringBuilder
+import android.text.TextUtils
+import android.text.style.ForegroundColorSpan
+import android.util.Log
+import android.view.GestureDetector
+import android.view.Gravity
+import android.view.KeyEvent
+import android.view.MotionEvent
+import android.view.View
+import android.view.ViewGroup
+import android.view.WindowManager
+import android.view.inputmethod.InputMethodManager
+import android.widget.Button
+import android.widget.EditText
+import android.widget.FrameLayout
+import android.widget.ImageView
+import androidx.activity.OnBackPressedCallback
+import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.core.content.ContextCompat
+import androidx.fragment.app.DialogFragment
+import androidx.fragment.app.Fragment
+import androidx.recyclerview.widget.LinearLayoutManager
+import com.alibaba.android.arouter.facade.annotation.Autowired
+import com.alibaba.android.arouter.facade.annotation.Route
+import com.alibaba.android.arouter.launcher.ARouter
+import com.blankj.utilcode.util.GsonUtils
+import com.blankj.utilcode.util.LogUtils
+import com.blankj.utilcode.util.ThreadUtils
+import com.blankj.utilcode.util.TimeUtils
+import com.chad.library.adapter.base.BaseQuickAdapter
+import com.example.moduleroom.R
+import com.example.moduleroom.contacts.RoomContacts
+import com.example.moduleroom.databinding.ActivityRoomBinding
+import com.example.moduleroom.dialog.ExitRoomBottomSheet
+import com.example.moduleroom.dialog.ExitRoomBottomSheet.OnOptionSelectedListener
+import com.example.moduleroom.dialog.FriendsDialogFragment
+import com.example.moduleroom.dialog.PublishCommentDialogFragment
+import com.example.moduleroom.dialog.RequestDialogFragment
+import com.example.moduleroom.dialog.RoomGiftDialogFragment
+import com.example.moduleroom.dialog.RoomMessageDialogFragment
+import com.example.moduleroom.dialog.RoomOnlineDialogFragment
+import com.example.moduleroom.dialog.RoomPkDialogFragment
+import com.example.moduleroom.dialog.RoomSettingFragment
+import com.example.moduleroom.dialog.SoundEffectsDialogFragment
+import com.example.moduleroom.fragment.PublicScreenEaseChatFragment
+import com.example.moduleroom.fragment.RoomCabinFragment
+import com.example.moduleroom.fragment.RoomChartsFragment
+import com.example.moduleroom.fragment.RoomFragment
+import com.example.moduleroom.fragment.RoomNoticeDialogFragment
+import com.example.moduleroom.fragment.RoomPasswordSetDialogFragment
+import com.example.moduleroom.presenter.RoomPresenter
+import com.example.moduleroom.service.ForegroundService
+import com.example.moduleroom.service.RoomPlayService
+import com.hjq.toast.ToastUtils
+import com.liulishuo.okdownload.OkDownloadProvider
+import com.orhanobut.logger.Logger
+import com.petterp.floatingx.assist.helper.FxScopeHelper
+import com.petterp.floatingx.listener.control.IFxControl
+import com.tencent.imsdk.v2.V2TIMManager
+import com.tencent.imsdk.v2.V2TIMValueCallback
+import com.xscm.moduleutil.activity.BaseMvpActivity
+import com.xscm.moduleutil.adapter.CommonPageAdapter
+import com.xscm.moduleutil.adapter.LikeUserAdapter
+import com.xscm.moduleutil.base.AppStateListener
+import com.xscm.moduleutil.base.AppStateManager
+import com.xscm.moduleutil.base.CommonAppContext
+import com.xscm.moduleutil.base.RoomManager
+import com.xscm.moduleutil.bean.GiftBean
+import com.xscm.moduleutil.bean.HeadlineBean
+import com.xscm.moduleutil.bean.RoomCharmRankBean
+import com.xscm.moduleutil.bean.RoomInputEvent
+import com.xscm.moduleutil.bean.RoomMessageEvent
+import com.xscm.moduleutil.bean.RoomMessageEvent.T
+import com.xscm.moduleutil.bean.RoomMessageEvent.text
+import com.xscm.moduleutil.bean.RoomSettingEvent
+import com.xscm.moduleutil.bean.RoomSingleton
+import com.xscm.moduleutil.bean.UserInfo
+import com.xscm.moduleutil.bean.UserOnlineStatusBean
+import com.xscm.moduleutil.bean.room.FriendInfo.HeartList
+import com.xscm.moduleutil.bean.room.FriendUserBean
+import com.xscm.moduleutil.bean.room.RoomAuction
+import com.xscm.moduleutil.bean.room.RoomAuction.AuctionListBean
+import com.xscm.moduleutil.bean.room.RoomAuction.AuctionUserBean
+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.room.RoomOnlineBean
+import com.xscm.moduleutil.bean.room.RoomOwnerBean
+import com.xscm.moduleutil.bean.room.RoomPitBean
+import com.xscm.moduleutil.bean.room.RoomUserBean
+import com.xscm.moduleutil.color.ThemeableDrawableUtils
+import com.xscm.moduleutil.dialog.ConfirmDialog
+import com.xscm.moduleutil.dialog.RechargeDialogFragment
+import com.xscm.moduleutil.dialog.giftLottery.GiftLotteryDialog
+import com.xscm.moduleutil.dialog.giftLottery.TourClubDialogFragment
+import com.xscm.moduleutil.event.ColoseCardEvent
+import com.xscm.moduleutil.event.EffectEvent
+import com.xscm.moduleutil.event.MusicEvent
+import com.xscm.moduleutil.event.QXRoomSeatViewType
+import com.xscm.moduleutil.event.RoomGiftGiveEvent
+import com.xscm.moduleutil.event.RoomInputHideEvent
+import com.xscm.moduleutil.event.RoomJoinMountModel
+import com.xscm.moduleutil.event.RoomOutEvent
+import com.xscm.moduleutil.event.RoomTaskEvent
+import com.xscm.moduleutil.event.RoomWheatEvent
+import com.xscm.moduleutil.event.SurfaceEvent
+import com.xscm.moduleutil.event.UnreadCountEvent
+import com.xscm.moduleutil.http.BaseObserver
+import com.xscm.moduleutil.http.RetrofitClient
+import com.xscm.moduleutil.interfaces.OnMusicItemClickListener
+import com.xscm.moduleutil.listener.MessageListenerSingleton
+import com.xscm.moduleutil.listener.MessageListenerSingleton.OnMessageReceivedListener
+import com.xscm.moduleutil.rtc.AgoraManager
+import com.xscm.moduleutil.rtc.MusicPlayBean
+import com.xscm.moduleutil.service.MyRoomSingleton
+import com.xscm.moduleutil.utils.ARouteConstants
+import com.xscm.moduleutil.utils.ColorManager
+import com.xscm.moduleutil.utils.ImageUtils
+import com.xscm.moduleutil.utils.SpUtil
+import com.xscm.moduleutil.utils.SystemUtils
+import com.xscm.moduleutil.widget.CircularProgressView
+import com.xscm.moduleutil.widget.CustomMusicFloatingView
+import com.xscm.moduleutil.widget.QXGiftPlayerManager
+import com.xscm.moduleutil.widget.SilentCountDownTimer
+import com.xscm.moduleutil.widget.ViewUtils
+import com.xscm.moduleutil.widget.ViewUtils.OnViewCreatedListener
+import com.xscm.moduleutil.widget.floatingView.Floa
+import io.agora.musiccontentcenter.Music
+import io.reactivex.disposables.Disposable
+import org.greenrobot.eventbus.EventBus
+import org.greenrobot.eventbus.Subscribe
+import org.greenrobot.eventbus.ThreadMode
+import pub.devrel.easypermissions.AppSettingsDialog
+import pub.devrel.easypermissions.EasyPermissions
+import pub.devrel.easypermissions.EasyPermissions.PermissionCallbacks
+import java.lang.ref.WeakReference
+import java.nio.charset.StandardCharsets
+import java.util.Arrays
+import java.util.Date
+import java.util.stream.Collectors
+
+@Route(path = ARouteConstants.ROOM_DETAILS )
+class RoomActivity : BaseMvpActivity(),
+ RoomContacts.View, PermissionCallbacks, OnMessageReceivedListener {
+ private var roomFragment: RoomFragment? = null
+ var commonPageAdapter: CommonPageAdapter? = null
+ private var mRoomBean: RoomBean? = null
+
+ //房主信息
+ private var mRoomOwnerBean: RoomOwnerBean? = null
+
+ //房间用户信息
+ private var mRoomUserBean: RoomUserBean? = null
+ private var mPitList: List = ArrayList()
+
+ @JvmField
+ @Autowired
+ var password: String? = null
+
+ @JvmField
+ @Autowired
+ var roomId: String? = null
+
+ @JvmField
+ @Autowired
+ var mRoomInfoResp: RoomInfoResp? = null
+
+ @JvmField
+ @Autowired
+ var taskId: String? = null
+
+ var likeUserAdapter: LikeUserAdapter? = null
+ var permissions: Array = arrayOf(Manifest.permission.RECORD_AUDIO)
+ private var isSave = false //活动是否将被系统回收
+
+ private var musicWindowControl: IFxControl? = null
+ private var customMusicFloatingView: CustomMusicFloatingView? = null
+ private var number = 0
+
+ private var floatingMagnetView: Floa? = null
+ private var fullScreenContainer: FrameLayout? = null
+ private var isFullScreen = false
+ private var ivExitFullscreen: ImageView? = null
+ var ivQuan: ImageView? = null
+ private var imYc = false
+
+ @JvmField
+ @Autowired
+ var isOnline: Boolean = false
+
+ private var silentCountDownTimer: SilentCountDownTimer? = null
+ private var circularProgress: CircularProgressView? = null
+ private var publicScreenFragment: PublicScreenEaseChatFragment? = null // 添加成员变量
+
+ // 添加成员变量
+ private var isLayoutAdjusted = false
+
+ // 存储当前显示的弹框引用
+ private val activeDialogs: MutableList = ArrayList()
+ private val activeDialogFragments: MutableList = ArrayList()
+
+ private var isMinimized = false
+ private var appStateListener: AppStateListener? = null
+
+ // 添加弹框到管理列表
+ fun addActiveDialog(dialog: DialogInterface) {
+ activeDialogs.add(dialog)
+ }
+
+ fun addActiveDialogFragment(dialogFragment: Fragment) {
+ activeDialogFragments.add(dialogFragment)
+ }
+
+// override fun onNewIntent(intent: Intent) {
+// super.onNewIntent(intent)
+//
+// // 必须调用 setIntent 来更新 Activity 的 Intent
+// setIntent(intent)
+// isOnline = intent.getBooleanExtra("isOnline", false)
+// password = intent.getStringExtra("password")
+// val mRoomId = intent.getStringExtra("roomId")
+// // mRoomInfoResp = (RoomInfoResp) getIntent().getSerializableExtra("roomInfo");
+// if (roomId == mRoomId || TextUtils.isEmpty(mRoomId)) {
+// sDestroied = false
+// if (mRoomInfoResp == null) {
+// mRoomInfoResp = AppStateManager.getInstance().roomInfo
+// }
+// if (!isOnline) {
+// releaseRoom()
+// startActivity(intent)
+// finish()
+// } else {
+// MvpPre!!.postRoomInfo(roomId)
+// }
+//
+// // updateSharedViewModelData(mRoomInfoResp);
+//// resetFragment();
+//// postRoomInfo(mRoomInfoResp);
+// } else {
+// releaseRoom()
+// startActivity(intent)
+// finish()
+// }
+// }
+
+ private fun handleRestoreFromMinimize(intent: Intent) {
+ // 如果是从桌面启动且之前有最小化的房间
+// if (Intent.ACTION_MAIN.equals(intent.getAction())
+// && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
+//
+// SharedPreferences prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE);
+// boolean isMinimized = prefs.getBoolean("is_minimized", false);
+//
+// if (isMinimized) {
+// // 恢复到最小化的房间
+// String minimizedRoomId = prefs.getString(PREF_MINIMIZED_ROOM, null);
+// if (minimizedRoomId != null && minimizedRoomId.equals(roomId)) {
+// // 当前就是最小化的房间,直接恢复
+// resumeRoomFromMinimize();
+// return;
+// }
+// }
+// }
+
+ // 其他情况按正常流程处理
+
+ val newRoomId = intent.getStringExtra("roomId")
+ val newPassword = intent.getStringExtra("password")
+
+ if (!TextUtils.isEmpty(newRoomId) && newRoomId != roomId) {
+// switchToRoom(newRoomId, newPassword);
+ releaseRoom()
+ startActivity(intent)
+ finish()
+ }
+ }
+
+ private fun resumeRoomFromMinimize() {
+ // 从最小化状态恢复房间
+ isMinimized = false
+ clearMinimizeState()
+
+ // 恢复房间状态
+ resumeRoomState()
+
+ // 确保UI正确显示
+ if (mBinding != null) {
+ // 恢复UI状态
+ }
+ }
+
+ private var bgEffectView: View? = null
+
+ private fun setupEffectView() {
+ bgEffectView = null
+ if (bgEffectView == null) {
+ // 获取单例管理器
+ val manager = QXGiftPlayerManager.getInstance(applicationContext)
+
+ // 获取背景特效视图并添加到布局中
+ bgEffectView = manager.defaultBgEffectView
+ // 找到 mBinding.svgaGift 的父容器
+ val parent = mBinding!!.svgaGift.parent
+ if (parent is ViewGroup) {
+ val parentViewGroup = parent
+ // 检查 bgEffectView 是否已经有父视图
+ val currentParent = bgEffectView?.getParent()
+ if (currentParent != null && currentParent is ViewGroup) {
+ // 如果已经有父视图,先从父视图中移除
+ currentParent.removeView(bgEffectView)
+ }
+
+ // 确保 bgEffectView 不为 null 并且没有父视图后再添加
+ if (bgEffectView != null) {
+ // 将 bgEffectView 添加为 mBinding.svgaGift 的兄弟视图
+ // 添加到 mBinding.svgaGift 的父容器中,位置在 mBinding.svgaGift 之前
+ parentViewGroup.addView(
+ bgEffectView,
+ parentViewGroup.indexOfChild(mBinding!!.svgaGift)
+ )
+ }
+
+ // 设置布局参数 - 填满父视图
+ val params = FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT
+ )
+ bgEffectView?.setLayoutParams(params)
+ } else {
+ LogUtils.e("mBinding.svgaGift 没有有效的父容器")
+ return
+ }
+ // 获取全屏特效视图
+ val fullEffectView = manager.defaultFullEffectView
+
+ // 设置全屏特效视图的布局参数 - 居中并设置尺寸
+ val fullParams = FrameLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT
+ )
+ fullParams.gravity = Gravity.CENTER
+ fullEffectView.layoutParams = fullParams
+
+ // 获取聊天特效视图
+ val chatEffectView = manager.defaultChatEffectView
+
+ // 设置聊天特效视图的布局参数 - 底部居中并设置尺寸
+ val chatParams = FrameLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT
+ )
+ chatParams.gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
+ chatEffectView.layoutParams = chatParams
+ }
+
+ // 从SharedPreferences获取是否关闭特效的设置
+ val isClose = SpUtil.getOpenEffect() != 1
+ QXGiftPlayerManager.getInstance(applicationContext).openOrCloseEffectViewWith(!isClose)
+ }
+
+ override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
+ if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
+ // 拦截返回键,显示退出对话框而不是直接退出
+ showExitRoomDialog()
+ return true
+ }
+ return false
+ }
+
+ // 添加一个标记,用于判断用户是否主动离开应用
+ private var userLeaving = false
+
+ override fun onUserLeaveHint() {
+ super.onUserLeaveHint()
+ LogUtils.e("RoomActivity", "onUserLeaveHint")
+ // 当用户主动离开应用时(例如按下Home键),设置标记
+ userLeaving = true
+ }
+
+ override fun onPause() {
+ super.onPause()
+ LogUtils.e("RoomActivity", "onPause")
+ if (mRoomInfoResp != null) {
+ if (mRoomInfoResp!!.room_info.type_id != "6") {
+ // 只有在用户主动离开应用时才执行最小化操作
+ if (!userLeaving) {
+ // 保持Activity alive,不调用finish()
+
+ minimizeToBackground()
+ userLeaving = false // 重置标记
+ }
+ }
+ userLeaving = true
+ }
+ }
+
+ fun tob() {
+ val stub = mBinding!!.roomTop.stubButtons2
+ stub.visibility = View.VISIBLE
+ val imActionJs = mBinding!!.roomTop.imActionJs.findViewById(R.id.im_action_js)
+ val imActionYs = mBinding!!.roomTop.imActionYs.findViewById(R.id.im_action_ys)
+ if (imActionJs != null && imActionYs != null) {
+ imActionJs.setOnClickListener { dialogEnd() }
+ imActionYs.setOnClickListener {
+ MvpPre!!.auctionDelay(
+ SpUtil.getauctionId()
+ )
+ }
+ }
+ }
+
+ fun upTop() {
+ mBinding!!.roomTop.stubButtons2.visibility = View.GONE
+ }
+
+ private fun dialogEnd() {
+ // 创建并显示确认对话框
+ ConfirmDialog(
+ this,
+ "提示",
+ "您确定要结束本次拍卖吗?",
+ "确认",
+ "取消",
+ { v: View? ->
+ // 点击“确认”按钮时执行删除操作
+ MvpPre!!.auctionEnd(SpUtil.getauctionId(), roomId)
+ },
+ { v: View? -> }, false, 0
+ ).show()
+ }
+
+ fun upVisibility(visible: Boolean) {
+ mBinding!!.roomTop.imActionJs.visibility =
+ if (visible) View.VISIBLE else View.INVISIBLE
+ mBinding!!.roomTop.imActionYs.visibility =
+ if (visible) View.VISIBLE else View.INVISIBLE
+ }
+
+ fun upJs(visible: Boolean) {
+ mBinding!!.roomTop.imActionJs.visibility =
+ if (visible) View.VISIBLE else View.INVISIBLE
+ }
+
+ fun upYs(visible: Boolean) {
+ mBinding!!.roomTop.imActionYs.visibility =
+ if (visible) View.VISIBLE else View.INVISIBLE
+ }
+
+ /** 最小化 */
+ private fun showExitRoomDialog() {
+ val bottomSheet = ExitRoomBottomSheet.newInstance()
+ bottomSheet.setOnOptionSelectedListener(object : OnOptionSelectedListener {
+ override fun onMinimize() {
+ // 处理最小化逻辑,比如不销毁 Activity,仅移至后台
+// CommonAppContext.getInstance().isShow = false;
+// ARouter.getInstance().build(ARouteConstants.ME).navigation();//栈顶复用
+// moveTaskToBack(true);
+
+// CommonAppContext.getInstance().isShow = false;
+// ARouter.getInstance().build(ARouteConstants.ME)
+// .navigation();
+// moveTaskToBack(true);
+
+ // 处理最小化逻辑
+
+ minimizeToBackground()
+ }
+
+ override fun onExitRoom() {
+ // 调用退出房间方法
+// MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
+
+ // 真正退出房间
+
+ performExitRoom(1)
+ }
+
+ override fun onCancel() {
+ // 用户点击取消,不做任何事
+ }
+ })
+ bottomSheet.show(supportFragmentManager, "ExitRoomBottomSheet")
+ addActiveDialogFragment(bottomSheet)
+ }
+
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
+ val currentFragment =
+ supportFragmentManager.findFragmentById(R.id.vp_room_pager) // 替换为你实际的容器 ID
+ if (currentFragment is RoomCabinFragment) {
+ currentFragment.onConfigurationChanged(newConfig)
+ }
+ }
+
+ fun clearData() {
+ publicScreenFragment!!.someMethod()
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun roomInfoEvent(surfaceView: SurfaceEvent) {
+ if (mRoomInfoResp!!.room_info.type_id == "6") { //判断是否是电影房
+ floatingMagnetView = findViewById(R.id.flaoat) //电影房
+ if (mRoomInfoResp!!.user_info.is_room_owner != 1) { //判断是不是房主,1:是 如何是,不展示 0不是,展示布局
+ if (surfaceView.type != 1) {
+ val container =
+ floatingMagnetView?.findViewById(R.id.fl_screenshare)
+ // mBinding.flaoat.setVisibility(GONE);//展示或不展示
+ if (surfaceView == null) {
+ runOnUiThread {
+ mBinding!!.flaoat.visibility = View.GONE
+ container?.removeAllViews()
+ }
+ } else {
+ runOnUiThread {
+ mBinding!!.flaoat.visibility = View.VISIBLE
+ container?.removeAllViews()
+ container?.addView(surfaceView.surfaceView)
+ }
+ }
+ } else {
+ floatingMagnetView?.setVisibility(View.GONE)
+ }
+ }
+ }
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun hideInput(event: RoomInputHideEvent) {
+ if (event.hide) {
+ mBinding!!.vpRoomPager.isScrollContainer = false
+ } else {
+ mBinding!!.vpRoomPager.isScrollContainer = true
+ }
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun roomInfoEvent(messageEvent: ColoseCardEvent?) {
+ mBinding!!.flaoat.visibility = View.GONE
+ }
+
+ /**
+ * 释放当前房间
+ */
+ private fun releaseRoom() {
+ AgoraManager.getInstance(this).cleanup()
+ // RtcManager.getInstance().leaveChannel(roomId);
+// RtcManager.getInstance().setAudioUrl(null);
+// EMqttService.cleanSubscribeRoom(roomId);
+ CommonAppContext.getInstance().isPlaying = false
+ CommonAppContext.getInstance().isShow = false
+ QXGiftPlayerManager.getInstance(applicationContext).destroyEffectSvga()
+ cleanupResources()
+ // MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
+ }
+
+ // private SharedViewModel sharedViewModel;
+ // 添加这个成员变量来跟踪房间数据是否已处理
+ // private boolean isRoomDataProcessed = false;
+ override fun onCreate(savedInstanceState: Bundle?) {
+ // 在super.onCreate之前设置主题以避免闪白屏
+ setTheme(com.xscm.moduleutil.R.style.BaseAppTheme) // 设置你的主主题
+ super.onCreate(savedInstanceState)
+ // // 进入房间10s后检查是否显示提示上麦对话框
+ LogUtils.e("RoomActivity", "onCreate")
+
+ isSave = false
+ sDestroied = false
+ isMinimized = false
+ overridePendingTransition(0, 0) // 关闭转场动画
+ startKeepLiveService() //保活
+
+ window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
+ sActivityRef = WeakReference(this)
+
+
+ // 检查是否有保存的最小化状态
+ checkAndRestoreMinimizeState()
+ // 获取传递的房间数据
+ // 在子线程中执行网络请求
+ performNetworkRequestsAsync()
+ roomFragment = RoomFragment.newInstance()
+ supportFragmentManager
+ .beginTransaction()
+ .replace(R.id.vp_room_pager, roomFragment!!)
+ .commitAllowingStateLoss()
+ // 使用新的 OnBackPressedDispatcher API 来处理返回事件
+ if (onBackPressedDispatcher != null) {
+ onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
+ override fun handleOnBackPressed() {
+ // 拦截返回键,显示退出对话框而不是直接退出
+ showExitRoomDialog()
+ }
+ })
+ }
+
+ // 获取Application实例并设置监听器
+ val app = application as CommonAppContext
+ appStateListener = AppStateManager.getInstance()
+ app.setAppStateListener(appStateListener)
+
+ // 通知RoomActivity已创建
+ if (appStateListener != null) {
+ appStateListener?.onRoomActivityCreated(this)
+ }
+
+
+ // 处理房间数据
+// handleRoomData();
+ SpUtil.saveMyRoomId(roomId)
+ // 检查是否从最小化状态恢复
+ if (isMinimized) {
+ // 恢复房间状态
+ resumeRoomState()
+ }
+ }
+
+ private fun setview(resp: RoomInfoResp) {
+ this.mRoomInfoResp = resp
+ val roomBean = resp.room_info
+ this.mRoomBean = roomBean
+ this.mRoomUserBean = resp.user_info
+ this.mRoomOwnerBean = resp.room_owner
+ this.mPitList = mRoomBean!!.pit_list
+
+ CommonAppContext.getInstance().isPlaying = true
+ CommonAppContext.getInstance().playId = roomId
+ CommonAppContext.getInstance().playName = mRoomBean!!.room_name
+
+ CommonAppContext.getInstance().playCover = resp.room_info.room_cover
+ CommonAppContext.getInstance().showSelf = resp.is_show_self == 1
+
+ ImageUtils.loadHeadCC(resp.room_info.room_cover, mBinding!!.roomTop.avatar)
+ mBinding!!.roomTop.name.text = roomBean.room_name
+ mBinding!!.roomTop.idVal.text = "ID:" + roomBean.room_number
+ if (mRoomUserBean?.getIs_room_owner() == 1) {
+ mBinding!!.roomTop.btnFollow.visibility = View.GONE
+ } else {
+ mBinding!!.roomTop.btnFollow.visibility = View.VISIBLE
+ if (resp.isCollect) {
+ mBinding!!.roomTop.btnFollow.background =
+ resources.getDrawable(com.xscm.moduleutil.R.mipmap.collected)
+ mBinding!!.roomTop.btnFollow.text = ""
+ }
+ }
+ number = roomBean.online_number
+ mBinding!!.roomTop.tvNum.text = number.toString() + ""
+
+ val userIds = StringBuilder()
+ for (i in mRoomInfoResp!!.room_info.pit_list.indices) {
+ val userId = mRoomInfoResp!!.room_info.pit_list[i].user_id
+ if (userId != null && userId != "0" && !userId.isEmpty()) {
+ if (userIds.length > 0) {
+ userIds.append(",")
+ }
+ userIds.append(userId)
+ }
+ }
+ initPublicScreenFragment()
+ // 确保Fragment已完全初始化后再调用getUpRoomInfo
+ if (publicScreenFragment != null && publicScreenFragment!!.isAdded && publicScreenFragment!!.view != null) {
+ publicScreenFragment!!.getUpRoomInfo(resp)
+ }
+ if (!isFinishing && !isDestroyed) {
+ resetFragment()
+ upHeight()
+ } else {
+ Log.e("Fragment", "Fragment transaction skipped due to state loss.")
+ }
+
+ if (mRoomUserBean?.getIs_collect() == 1) {
+ mBinding!!.roomTop.btnFollow.background =
+ resources.getDrawable(com.xscm.moduleutil.R.mipmap.yishouc)
+ mBinding!!.roomTop.btnFollow.text = ""
+ } else {
+ ThemeableDrawableUtils.setThemeableRoundedBackground(
+ mBinding!!.roomTop.btnFollow,
+ ColorManager.getInstance().primaryColorInt,
+ 53
+ )
+ mBinding!!.roomTop.btnFollow.setTextColor(ColorManager.getInstance().buttonColorInt)
+ mBinding!!.roomTop.btnFollow.text = "收藏"
+ }
+ if ((roomBean.type_id == "3" || roomBean.type_id == "1" || roomBean.type_id == "4") && roomBean.label_id == "2") {
+ AgoraManager.getInstance(this).isBjMusic = false
+ } else {
+ AgoraManager.getInstance(this).isBjMusic = true
+ }
+
+ AgoraManager.stopMuisc()
+ initializeAudio()
+
+
+ toutiao()
+ upRoomInfo(resp)
+
+
+ if (userIds.length > 0 && roomId != null) {
+// MvpPre.userOnlineStatus(userIds.toString(), roomId);
+ }
+
+ //
+// // 延迟调用getUpRoomInfo,确保Fragment视图已创建
+// mBinding.getRoot().post(new Runnable() {
+// @Override
+// public void run() {
+// if (publicScreenFragment != null) {
+// publicScreenFragment.getUpRoomInfo(resp);
+// }
+// }
+// });
+ instView()
+
+ if (mRoomInfoResp!!.user_info.pit_number == 9 && mRoomInfoResp!!.user_info.user_id == SpUtil.getUserId()
+ .toString() + ""
+ ) {
+ mBinding!!.roomTop.rl.visibility = View.VISIBLE
+ ivSoundEffects(true)
+ } else {
+ mBinding!!.roomTop.rl.visibility = View.GONE
+ ivSoundEffects(false)
+ }
+
+ if (mRoomInfoResp!!.room_info.type_id == "7" || mRoomInfoResp!!.room_info.type_id == "2") {
+ mBinding!!.rlMore.visibility = View.GONE
+ mBinding!!.rlMisc.visibility = View.GONE
+ }
+ setupEffectView()
+
+ // 使用Handler延迟执行,确保Fragment视图已完全创建
+ Handler(Looper.getMainLooper()).post {
+ if (publicScreenFragment != null && publicScreenFragment!!.isAdded && publicScreenFragment!!.view != null) {
+ publicScreenFragment!!.getUpRoomInfo(resp)
+ }
+ }
+ }
+
+ private fun checkAndRestoreMinimizeState() {
+ val prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE)
+ var isMinimized = prefs.getBoolean("is_minimized", false)
+
+ if (isMinimized) {
+ isMinimized = true
+ // 检查最小化时间,如果太久可能需要重新登录
+ val minimizeTime = prefs.getLong(PREF_MINIMIZED_TIME, 0)
+ val currentTime = System.currentTimeMillis()
+
+ // 如果最小化超过一定时间(如30分钟),可能需要重新验证
+ if (currentTime - minimizeTime > 30 * 60 * 1000) {
+ // 清理过期的最小化状态
+ clearMinimizeState()
+ isMinimized = false
+ }
+ } else {
+ isMinimized = false
+ }
+ }
+
+ /**
+ * 在子线程中执行网络请求,避免阻塞主线程
+ */
+ private fun performNetworkRequestsAsync() {
+ ThreadUtils.executeByIo(object : ThreadUtils.SimpleTask() {
+ @Throws(Throwable::class)
+ override fun doInBackground(): Void? {
+ // 在后台线程执行网络请求前的准备工作
+ // 例如:检查缓存、预处理数据等
+// prepareNetworkRequest();
+ return null
+ }
+
+ override fun onSuccess(result: Void?) {
+ runOnUiThread {
+ // 使用Handler确保在主线程中调用
+// MvpPre.getRoomIn(roomId, password);
+ if (mRoomInfoResp == null) {
+ // 使用Handler确保在主线程中调用
+ MvpPre!!.getRoomIn(roomId, password)
+ }
+ MvpPre!!.getRoomOnline(roomId, "1", "10")
+ }
+ }
+
+
+
+ override fun onFail(e: Throwable) {
+ LogUtils.e("Network request preparation failed: " + e.message)
+ // 即使准备失败,也尝试执行网络请求
+ runOnUiThread {
+ // MvpPre.getRoomIn(roomId, password);
+ // 检查是否已经有房间信息,如果有则不需要再次获取
+ if (mRoomInfoResp == null) {
+ MvpPre!!.getRoomIn(roomId, password)
+ }
+ MvpPre!!.getRoomOnline(roomId, "1", "10")
+ }
+ }
+ })
+ }
+
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun onRoomTaskEvent(event: RoomTaskEvent?) {
+ if (taskId != null && taskId != "9") { //这是每日任务完成发送私聊信息的事件
+ RetrofitClient.getInstance()
+ .dailyTasksComplete(taskId, object : BaseObserver() {
+ override fun onSubscribe(d: Disposable) {
+ }
+
+ override fun onNext(roomSingleton: RoomSingleton) {
+ number++
+ // 这里处理请求结果
+ if (roomSingleton.is_completed == 1) {
+ // 任务完成,可以做一些后续操作
+ taskId = null
+ }
+ }
+ })
+ }
+ }
+
+ override fun initView() {
+ super.initView()
+ floatingMagnetView = findViewById(R.id.flaoat)
+ ivQuan = findViewById(R.id.iv_quan)
+ fullScreenContainer = findViewById(R.id.fullscreen_container) // 自定义全屏容器
+ ivExitFullscreen = findViewById(R.id.iv_exit_fullscreen)
+ ivQuan?.setOnClickListener(View.OnClickListener { v: View? -> toggleFullScreen() })
+ ivExitFullscreen?.setOnClickListener(View.OnClickListener { v: View? -> exitFullScreen() })
+
+ LogUtils.e("lxj", "开始时间:" + TimeUtils.date2String(Date()))
+
+ if (taskId != null) {
+ if (taskId == "9") {
+ MyRoomSingleton.getInstance().onEnterRoom(taskId)
+ }
+ }
+ circularProgress = mBinding!!.giftShowProgress
+ circularProgress!!.progress = 0
+ mBinding!!.giftShowLayout.setOnClickListener {
+ onGiftGiveProgressClcik()
+ LogUtils.e("xj", "onSubscribe2222")
+ }
+
+ ThemeableDrawableUtils.setThemeableRoundedBackground(
+ mBinding!!.roomTop.btnFollow,
+ ColorManager.getInstance().primaryColorInt,
+ 53
+ )
+ mBinding!!.roomTop.btnFollow.setTextColor(ColorManager.getInstance().buttonColorInt)
+ initPublicScreenFragment()
+
+ // stub = mBinding.roomTop.stubButtons.getViewStub();
+
+ // 为透明 View 设置触摸监听
+ mBinding!!.roomTop.rlTop.setOnTouchListener { v, event ->
+ // 将触摸事件透传给下层的 View
+ false // 返回 false,表示不拦截事件
+ }
+
+ val layoutParams = mBinding!!.roomTop.root.layoutParams
+ layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT // 使用你定义的getWidth方法
+ layoutParams.height = SystemUtils.getWidth(74) // 示例高度
+ mBinding!!.roomTop.root.layoutParams = layoutParams
+
+ // MP4PlaybackCallback mp4PlaybackCallback=MP4PlaybackCallback.getInstance();
+// mp4PlaybackCallback.setAvatarFrameView(mBinding.svgaGift);
+// mBinding.svgaGift.setAnimListener(mp4PlaybackCallback);
+ mBinding!!.xlhIm.setOnClickListener {
+ val fm = supportFragmentManager
+ if (fm != null && !fm.isDestroyed) {
+ val newDialog = TourClubDialogFragment.newInstance(
+ roomId
+ )
+ newDialog.show(fm, "TourClubDialogFragment")
+ }
+ }
+ }
+
+ private fun onGiftGiveProgressClcik() {
+ if (giftGiveEvent == null || giftGiveEvent!!.roonGiftModel == null) {
+ return
+ }
+
+ if (giftGiveEvent!!.auction_id != null && !giftGiveEvent!!.auction_id.isEmpty()) {
+ RetrofitClient.getInstance().roomAuctionJoin(
+ giftGiveEvent!!.getAuction_id(),
+ giftGiveEvent!!.getUserId(),
+ giftGiveEvent!!.getRoonGiftModel().gift_id,
+ giftGiveEvent!!.getNum(),
+ "1",
+ object : BaseObserver() {
+ override fun onSubscribe(d: Disposable) {
+// showGiftGiveProgress();
+ }
+
+ override fun onNext(auctionListBean: AuctionListBean) {
+ showGiftGiveProgress()
+ }
+
+ override fun onError(e: Throwable) {
+ super.onError(e)
+ val msg = e.message
+ if (!TextUtils.isEmpty(msg) && msg!!.contains("当前余额不足")) {
+ ToastUtils.show("当前余额不足,请充值")
+ ThreadUtils.runOnUiThreadDelayed({
+ val fragment = RechargeDialogFragment.show(
+ roomId, null,
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ }, 1400)
+ }
+ hideGiftGiveProgress()
+ }
+ })
+ } else {
+ RetrofitClient.getInstance().roomGift(
+ giftGiveEvent!!.getRoom_id(),
+ giftGiveEvent!!.getRoonGiftModel().gift_id,
+ giftGiveEvent!!.getNum(),
+ giftGiveEvent!!.getUserId(),
+ "1",
+ giftGiveEvent!!.getPit(),
+ giftGiveEvent!!.heart_id,
+ object : BaseObserver() {
+ override fun onSubscribe(d: Disposable) {
+// showGiftGiveProgress();
+// LogUtils.e("xj", "onSubscribe");
+ }
+
+ override fun onNext(s: String) {
+ showGiftGiveProgress()
+ }
+
+ override fun onError(e: Throwable) {
+ super.onError(e)
+ val msg = e.message
+ if (!TextUtils.isEmpty(msg) && msg!!.contains("当前余额不足")) {
+ ToastUtils.show("当前余额不足,请充值")
+ ThreadUtils.runOnUiThreadDelayed({
+ val fragment = RechargeDialogFragment.show(
+ roomId, null,
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ }, 1400)
+ }
+ hideGiftGiveProgress()
+ }
+ })
+ }
+ }
+
+ private var giftGiveEvent: RoomGiftGiveEvent? = null
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun roomGiveGiftEvent(event: RoomGiftGiveEvent?) {
+ if (isFinishing || event == null || event.roonGiftModel == null) {
+ return
+ }
+ giftGiveEvent = event
+ showGiftGiveProgress()
+ }
+
+ private var giftProgress = 0
+ private var giftCountTimer: CountDownTimer? = null
+
+ private fun startGiftProgressTime() {
+ giftProgress = 0
+ if (giftCountTimer != null) {
+ giftCountTimer!!.cancel()
+ }
+ LogUtils.e("xj2", "onSubscribe")
+ giftCountTimer = object : CountDownTimer((1000 * 10).toLong(), 50) {
+ override fun onTick(millisUntilFinished: Long) {
+ if (!isFinishing) {
+ circularProgress!!.progress = 1000 - (millisUntilFinished / 10).toInt()
+ }
+ }
+
+ override fun onFinish() {
+ circularProgress!!.progress = 1000
+ hideGiftGiveProgress()
+ }
+ }
+ giftCountTimer?.start()
+ }
+
+ private fun showGiftGiveProgress() {
+ ImageUtils.loadImageView(
+ giftGiveEvent!!.roonGiftModel.base_image,
+ mBinding!!.giftShowProgressImg
+ )
+ circularProgress!!.progress = 1000 // 显示进度条,2025年7月19日11:23:37将这个从下面的方法提起到这里,
+ startGiftProgressTime()
+ mBinding!!.giftShowLayout.visibility = View.VISIBLE
+ }
+
+ private fun hideGiftGiveProgress() {
+ mBinding!!.giftShowLayout.visibility = View.GONE
+ if (giftCountTimer != null) {
+ giftCountTimer!!.cancel()
+ giftCountTimer = null
+ }
+ }
+
+ private fun toggleFullScreen() {
+ if (isFullScreen) {
+ exitFullScreen()
+ } else {
+// enterFullScreen();
+
+ // 修改为横屏展示模式而不是全屏模式
+
+ enterLandscapeMode()
+ }
+ }
+
+ private fun enterLandscapeMode() {
+ isFullScreen = true
+
+ // 设置横屏
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+
+ if (floatingMagnetView != null) {
+ // 修改Floa组件的布局参数,使其在横屏时占据更大区域
+ val layoutParams = floatingMagnetView!!.layoutParams
+ if (layoutParams is ConstraintLayout.LayoutParams) {
+ val params = layoutParams
+ params.width = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT
+ params.height = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT
+ params.horizontalBias = 0.5f
+ params.verticalBias = 0.5f
+ floatingMagnetView!!.layoutParams = params
+ } else {
+ // 如果不是ConstraintLayout.LayoutParams,创建新的
+ val params = ConstraintLayout.LayoutParams(
+ ConstraintLayout.LayoutParams.MATCH_CONSTRAINT,
+ ConstraintLayout.LayoutParams.MATCH_CONSTRAINT
+ )
+ params.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
+ params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
+ params.startToStart = ConstraintLayout.LayoutParams.PARENT_ID
+ params.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID
+ floatingMagnetView!!.layoutParams = params
+ }
+
+ // 可以调整内部fl_screenshare的布局参数
+ val flScreenshare = floatingMagnetView!!.findViewById(R.id.fl_screenshare)
+ val screenParams = flScreenshare.layoutParams
+ if (screenParams !is FrameLayout.LayoutParams) {
+ // 如果不是FrameLayout.LayoutParams,创建新的
+ val newScreenParams = FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT
+ )
+ flScreenshare.layoutParams = newScreenParams
+ } else {
+ val newScreenParams = screenParams
+ newScreenParams.width = FrameLayout.LayoutParams.MATCH_PARENT
+ newScreenParams.height = FrameLayout.LayoutParams.MATCH_PARENT
+ flScreenshare.layoutParams = newScreenParams
+ }
+
+ // 显示退出按钮
+ ivQuan!!.visibility = View.VISIBLE
+ }
+ }
+
+ private fun enterFullScreen() {
+ isFullScreen = true
+
+
+ // 隐藏系统UI
+ val decorView = window.decorView
+ decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_FULLSCREEN
+ or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
+
+ // 设置横屏
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+ // 找到 fl_screenshare 并移到全屏容器中
+ val fl_screenshare = findViewById(R.id.fl_screenshare)
+ if (fl_screenshare != null) {
+// // 先从当前父容器中移除
+// ViewParent parent = fl_screenshare.getParent();
+// if (parent != null && parent instanceof ViewGroup) {
+// ((ViewGroup) parent).removeView(fl_screenshare);
+// }
+//
+// // 添加到全屏容器
+// fullScreenContainer.addView(fl_screenshare);
+
+ safelyMoveViewToParent(fl_screenshare, floatingMagnetView)
+ // 显示全屏容器
+ fullScreenContainer!!.visibility = View.VISIBLE
+ floatingMagnetView!!.visibility = View.GONE
+ ivExitFullscreen!!.visibility = View.VISIBLE // 显示退出按钮
+ }
+ }
+
+ private fun exitFullScreen() {
+ isFullScreen = false
+
+ // 设置回竖屏
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
+
+ if (floatingMagnetView != null) {
+ // 恢复原始尺寸
+ val params = ConstraintLayout.LayoutParams(
+ resources.getDimensionPixelSize(com.xscm.moduleutil.R.dimen.dp_240),
+ resources.getDimensionPixelSize(com.xscm.moduleutil.R.dimen.dp_135)
+ )
+ params.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
+ params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
+ params.startToStart = ConstraintLayout.LayoutParams.PARENT_ID
+ params.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID
+ floatingMagnetView!!.layoutParams = params
+
+ // 恢复内部fl_screenshare的布局参数
+ val flScreenshare = floatingMagnetView!!.findViewById(R.id.fl_screenshare)
+ val screenParams = FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT
+ )
+ flScreenshare.layoutParams = screenParams
+ }
+
+ // 隐藏退出按钮
+ ivExitFullscreen!!.visibility = View.GONE
+
+
+ // isFullScreen = false;
+// // 恢复系统UI
+// View decorView = getWindow().getDecorView();
+//// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
+// decorView.setSystemUiVisibility(
+// View.SYSTEM_UI_FLAG_FULLSCREEN
+// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
+// );
+// // 设置回竖屏
+// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+// // 找到 fl_screenshare 并移回原父容器
+// FrameLayout fl_screenshare = findViewById(R.id.fl_screenshare);
+// if (fl_screenshare != null) {
+// safelyMoveViewToParent(fl_screenshare, fullScreenContainer);
+//// ViewParent parent = fl_screenshare.getParent();
+//// if (parent instanceof ViewGroup) {
+//// ((ViewGroup) parent).removeView(fl_screenshare);
+//// }
+//// // 添加到全屏容器
+//// fullScreenContainer.addView(fl_screenshare);
+// // 找到原始父容器并重新添加
+//// FrameLayout originalParent = findViewById(R.id.fullscreen_container); // 或者你实际的容器
+//// if (originalParent != null) {
+//// originalParent.removeView(fl_screenshare); // 防止重复添加
+//// }
+//
+//// floatingMagnetView.addView(fl_screenshare);
+// }
+// // 恢复界面
+// fullScreenContainer.setVisibility(View.GONE);
+// floatingMagnetView.setVisibility(View.VISIBLE);
+// ivQuan.setVisibility(View.VISIBLE);
+// ivExitFullscreen.setVisibility(View.GONE); // 隐藏退出按钮
+ }
+
+ override fun initData() {
+ if (!EasyPermissions.hasPermissions(this, *permissions)) {
+ EasyPermissions.requestPermissions(
+ this, "请开启录音使用权限",
+ 1, *permissions
+ )
+ }
+
+ mBinding!!.roomTop.btnFollow.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.roomTop.btnNotice.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.roomTop.btnRanking.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.roomTop.btnCloseLive.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.roomTop.tvNum.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.roomTop.rl.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.ivSoundEffects.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.ivWheatFeeding.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.clFirstCharge.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.roomTop.userRecyclerView.layoutManager = LinearLayoutManager(
+ this, LinearLayoutManager.HORIZONTAL, false
+ )
+ likeUserAdapter = LikeUserAdapter()
+ mBinding!!.roomTop.userRecyclerView.adapter = likeUserAdapter
+ likeUserAdapter!!.onItemClickListener =
+ BaseQuickAdapter.OnItemClickListener { adapter, view, position ->
+ // RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
+ val fragment = RoomOnlineDialogFragment.show(
+ roomId, "", mRoomUserBean, mRoomInfoResp,
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ }
+
+
+ // PublicScreenEaseChatFragment fragment = PublicScreenEaseChatFragment.newInstance();
+// getSupportFragmentManager().beginTransaction().replace(R.id.ease_container, fragment).commitAllowingStateLoss();
+ mBinding!!.ivChat.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.llInput.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.rlMisc.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.rlGift.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.rlMic.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.rlSett.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.rlVoive.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.rlMore.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+ mBinding!!.rlMessage.setOnClickListener { view: View ->
+ this.onClick(
+ view
+ )
+ }
+
+ // SpUtil.saveMyRoomId(roomId);
+// MvpPre.getRoomIn(roomId, password);
+// MvpPre.getRoomOnline(roomId, "1", "10");
+ mBinding!!.inputMenu1.performClick()
+
+ V2TIMManager.getConversationManager()
+ .getTotalUnreadMessageCount(object : V2TIMValueCallback {
+ override fun onSuccess(aLong: Long) {
+ if (aLong == 0L) {
+ mBinding!!.ivMessageDot.visibility = View.GONE
+ mBinding!!.ivMessageDot.text = "0"
+ } else {
+ mBinding!!.ivMessageDot.visibility = View.VISIBLE
+ }
+ mBinding!!.ivMessageDot.text = aLong.toString()
+ }
+
+ override fun onError(code: Int, desc: String) {
+ }
+ })
+
+ mBinding!!.roomTop.root.isClickable = false
+ mBinding!!.roomTop.root.setOnClickListener {
+ // ToastUtils.showShort("点击了房间,事件穿透");
+ }
+ // if (mRoomInfoResp!=null){
+// setview(mRoomInfoResp);
+// }
+ }
+
+
+ private fun initPublicScreenFragment() {
+ // 检查是否已经存在 Fragment 实例(例如在配置更改后)
+ publicScreenFragment = supportFragmentManager
+ .findFragmentById(R.id.ease_container) as PublicScreenEaseChatFragment?
+
+ // 如果不存在,则创建新的实例
+ if (publicScreenFragment == null) {
+ publicScreenFragment = PublicScreenEaseChatFragment.newInstance(roomId)
+ supportFragmentManager.beginTransaction()
+ .replace(R.id.ease_container, publicScreenFragment!!)
+ .commitAllowingStateLoss()
+ }
+ }
+
+ // 在类成员变量中添加
+ private val roomSwitchHandler = Handler(Looper.getMainLooper())
+ private var roomSwitchRunnable: Runnable? = null
+ private var pendingRoomId: String? = null
+ private var lastSwitchedRoomId = ""
+
+ fun roomInfoEvent(messageEvent: RoomMessageEvent?) {
+ if (messageEvent == null) return
+ if (roomFragment == null) {
+ roomFragment = RoomFragment.newInstance()
+ supportFragmentManager
+ .beginTransaction()
+ .replace(R.id.vp_room_pager, roomFragment!!)
+ .commitAllowingStateLoss()
+ }
+
+ val msgType = messageEvent.msgType
+ val text = messageEvent.text
+
+ if (msgType == 1005) {
+ LogUtils.e("@@@@" + "EventBusnujm2" + "playQueue.size()====" + messageEvent.text.giftInfo)
+ val playQueue = Arrays.asList(
+ *messageEvent.text.giftInfo.play_image.split(",".toRegex())
+ .dropLastWhile { it.isEmpty() }.toTypedArray()
+ )
+ QXGiftPlayerManager.getInstance(this).displayFullEffectView1(playQueue)
+
+ hand1005(messageEvent, text)
+ } else if (msgType == 123) {
+ EventBus.getDefault().post(RoomSettingEvent())
+ } else if (msgType == 1014) {
+ handleMsgType1014(messageEvent, text)
+ } else if (msgType == 1013) {
+ handleMsgType1013(messageEvent, text)
+ } else if (msgType == 1012) {
+ handleMsgType1012()
+ } else if (msgType == 124) {
+ handleMsgType124(messageEvent, text)
+ } else if (msgType == 1003) {
+ handleMsgType1003(messageEvent, text)
+ } else if (msgType == 1004) {
+ handleMsgType1004(messageEvent, text)
+ } else if (msgType == 1022) {
+ handleMsgType1022(messageEvent, text)
+ } else if (msgType == 1023) {
+ handleMsgType1023(messageEvent, text)
+ } else if (msgType == 1024) {
+ handleMsgType1024(messageEvent, text)
+ } else if (msgType == 1025) {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if (msgType == 1026) {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if (msgType == 1027) {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if (msgType == 1020) {
+ handleMsgType1020(messageEvent, text)
+ } else if (msgType == 1011) {
+ handleMsgType1011(messageEvent, text)
+ } else if (msgType == 1001) {
+ handleMsgType1001()
+ } else if (msgType == 1002) {
+ handleMsgType1002()
+ } else if (msgType == 1029) {
+ handleMsgType1029(messageEvent, text)
+ } else if (msgType == 1021) {
+ handleMsgType1021(messageEvent, text)
+ } else if (msgType == 1036) {
+ handleMsgType1036(messageEvent, text)
+ } else if (msgType == 1049) {
+ handleMsgType1049(messageEvent, text)
+ } else if (msgType == 1050) {
+ handleMsgType1050(messageEvent, text)
+ } else if (msgType == 1051) {
+ handleMsgType1051(messageEvent, text)
+ } else if (msgType == 1052) {
+ roomFragment!!.upCabinFragment(text.time_day)
+ } else if (msgType == 1053) {
+ handleMsgType1053(messageEvent, text)
+ } else if (msgType == 1054) {
+ handleMsgType1054(messageEvent, text)
+ } else if (msgType == 1055) {
+ handleMsgType1055(messageEvent)
+ } else if (msgType == 1035) {
+ handleMsgType1035(messageEvent, text)
+ } else if (msgType == 1030 || msgType == 1031 || msgType == 1032 || msgType == 1033 || msgType == 1015 || msgType == 1037) {
+ roomFragment!!.SingSongEvent(messageEvent)
+ if (msgType == 1032 || msgType == 1033) {
+ setRoleType(3, -11)
+ }
+ } else if (msgType == 125) {
+ handleMsgType125(messageEvent, text)
+ } else if (msgType == 1006) {
+ handleMsgType1006()
+ } else if (msgType == 1007) {
+ handleMsgType1007()
+ } else if (msgType == 1017) {
+ handleMsgType1017()
+ } else if (msgType == 1018) {
+ handleMsgType1018()
+ } else if (msgType == 126) {
+ handleMsgType126(messageEvent, text)
+ } else if (msgType == 1034) {
+ handleMsgType1034(messageEvent, text)
+ } else if (msgType == 1016) {
+ handleMsgType1016(messageEvent, text)
+ } else if (msgType == 1039) {
+ handleMsgType1039(messageEvent, text)
+ } else if (msgType == 1028) {
+ roomFragment!!.handleMsgType1028(messageEvent)
+ } else if (msgType == 1058) {
+ if (mRoomInfoResp != null && mRoomInfoResp!!.room_info != null) {
+ if (mRoomInfoResp!!.room_info.type_id == "1" || mRoomInfoResp!!.room_info.type_id == "3" ||
+ mRoomInfoResp!!.room_info.type_id == "4" || mRoomInfoResp!!.room_info.type_id == "8"
+ ) {
+ if (mRoomInfoResp!!.room_info.label_id == "1") {
+ roomFragment!!.SingSongEvent(messageEvent)
+ } else {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ }
+ } else if (mRoomInfoResp!!.room_info.type_id == "2") {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if (mRoomInfoResp!!.room_info.type_id == "7") {
+ roomFragment!!.friendshipRoomFragmentEvent(messageEvent)
+ }
+ }
+ } else if (msgType == 1059) { // 1059清除个人魅力 1058在离线
+ if (mRoomInfoResp != null && mRoomInfoResp!!.room_info != null) {
+ if (mRoomInfoResp!!.room_info.type_id == "1" || mRoomInfoResp!!.room_info.type_id == "3" ||
+ mRoomInfoResp!!.room_info.type_id == "4" || mRoomInfoResp!!.room_info.type_id == "8"
+ ) {
+ if (mRoomInfoResp!!.room_info.label_id == "1") {
+ roomFragment!!.SingSongEvent(messageEvent)
+ } else {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ }
+ } else if (mRoomInfoResp!!.room_info.type_id == "2") {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if (mRoomInfoResp!!.room_info.type_id == "7") {
+ roomFragment!!.friendshipRoomFragmentEvent(messageEvent)
+ }
+ }
+ } else if (msgType == 1056) { // 1056 抽奖结果
+ val dialog = supportFragmentManager
+ .findFragmentByTag("GiftLotteryDialog") as GiftLotteryDialog?
+ if (dialog != null && dialog.isVisible) {
+ dialog.UpView(messageEvent.text.xlh_data)
+ } else {
+ EventBus.getDefault().post(messageEvent.text.xlh_data)
+ }
+
+ if (messageEvent.text.xlh_data != null) {
+ if (messageEvent.text.xlh_data.status == 1) {
+ mBinding!!.xlhRk.visibility = View.VISIBLE
+ xlhDjs(messageEvent.text.xlh_data.end_time)
+ } else {
+ mBinding!!.xlhRk.visibility = View.INVISIBLE
+ releaseCountDownTimer1()
+ }
+ }
+ } else if (msgType == 1057) {
+ val existingFragment =
+ supportFragmentManager.findFragmentByTag("TourClubDialogFragment") as TourClubDialogFragment?
+ if (existingFragment != null && existingFragment.isVisible) {
+ existingFragment.onMusicPlay(messageEvent)
+ } else {
+ LogUtils.e("TourClubDialogFragment", "巡乐会界面未打开")
+ EventBus.getDefault().post(messageEvent)
+ }
+ xlhDjs(messageEvent.text.end_time)
+
+ // if (messageEvent.getText().getXlh_data() != null) {
+// if (messageEvent.getText().getXlh_data().getStatus() == 1) {
+// mBinding.xlhRk.setVisibility(View.VISIBLE);
+// xlhDjs(messageEvent.getText().getEnd_time());
+// } else {
+// mBinding.xlhRk.setVisibility(View.GONE);
+// releaseCountDownTimer1();
+// }
+// }
+ }
+ }
+
+ private var endTime: Long = 0
+
+ private fun xlhDjs(endTimeStr: String?) {
+ // 获取结束时间并启动倒计时
+ if (endTimeStr != null && !endTimeStr.isEmpty()) {
+ try {
+ // 假设 end_time 是时间戳字符串
+ endTime = endTimeStr.toLong()
+ countDownTime(endTime)
+ } catch (e: NumberFormatException) {
+ // 如果不是时间戳,可能是日期字符串,需要相应解析
+ // 例如:2025-08-26 19:10:47
+ // 可以使用 SimpleDateFormat 解析
+ e.printStackTrace()
+ }
+ }
+ }
+
+ fun countDownTime(time: Long) {
+ try {
+ if (time <= 0) {
+ setTime(0)
+
+ releaseCountDownTimer1()
+ return
+ }
+ releaseCountDownTimer1()
+ // 获取当前时间的毫秒值
+ val currentTime = System.currentTimeMillis() / 1000L
+ // 计算倒计时的总秒数
+ val countDownTime = (time - currentTime)
+ Logger.d("@@@", "countDownTime = $countDownTime")
+ if (countDownTime <= 0) {
+ setTime(0)
+ releaseCountDownTimer1()
+ return
+ }
+ mCountDownTimer2 = object : CountDownTimer(countDownTime * 1000L, 1000L) {
+ override fun onTick(millisUntilFinished: Long) {
+ val time1 = (millisUntilFinished / 1000).toInt()
+ setTime(time1)
+ // mBinding.tvDjs.setText(time1 + "");
+ if (time1 == 0) {
+ mBinding!!.xlhRk.visibility = View.INVISIBLE
+ }
+ }
+
+ override fun onFinish() {
+ setTime(0)
+ }
+ }
+ mCountDownTimer2?.start()
+ } catch (e: Exception) {
+ Logger.e("countDownTime", e)
+ }
+ }
+
+ private fun formatTime(totalSeconds: Int): String {
+ val minutes = (totalSeconds % 3600) / 60
+ val seconds = totalSeconds % 60
+
+ return String.format("%02d:%02d", minutes, seconds)
+ }
+
+ @SuppressLint("DefaultLocale")
+ fun setTime(seconds: Int) {
+ if (seconds == 0) {
+ mBinding!!.xlhRk.visibility = View.INVISIBLE
+ return
+ }
+ val formattedTime = formatTime(seconds)
+ mBinding!!.tvDjs.text = "倒计时$formattedTime"
+ }
+
+ // TODO: 2025/3/19 释放倒计时器
+ private fun releaseCountDownTimer1() {
+ if (mCountDownTimer2 != null) {
+ mCountDownTimer2!!.cancel()
+ mCountDownTimer2 = null
+ }
+ }
+
+ private val pitMap: MutableMap = HashMap()
+
+ fun handleMsgType1039(messageEvent: RoomMessageEvent, text: T?) {
+ if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) {
+ return
+ }
+
+ val pitList = mRoomInfoResp!!.room_info.pit_list
+ if (pitList != null && !pitList.isEmpty()) {
+ pitMap.clear() // 避免数据累积
+ for (roomPitBean in pitList) {
+ pitMap[roomPitBean.pit_number] = roomPitBean
+ }
+
+ if (text == null) {
+ return
+ }
+
+ val fromPitNumber = text.from_pit_number
+ val toPitNumber = text.to_pit_number
+
+ if (!TextUtils.isEmpty(fromPitNumber) && !TextUtils.isEmpty(toPitNumber)) {
+ performSwitchMic(fromPitNumber, toPitNumber, messageEvent)
+ }
+ // 执行换麦逻辑
+ }
+ }
+
+ private fun performSwitchMic(
+ fromPitNumber: String,
+ toPitNumber: String,
+ messageEvent: RoomMessageEvent
+ ) {
+ if (TextUtils.isEmpty(fromPitNumber) || TextUtils.isEmpty(toPitNumber)) {
+ return
+ }
+
+ if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) {
+ LogUtils.e("Room info is null")
+ return
+ }
+
+ val pitList = mRoomInfoResp!!.room_info.pit_list
+ if (pitList == null || pitList.isEmpty()) {
+ LogUtils.e("pit_list is null or empty")
+ return
+ }
+
+ var fromBean: RoomPitBean? = null
+ var toBean: RoomPitBean? = null
+ val pitListCopy: MutableList = ArrayList()
+
+ for (bean in pitList) {
+ if (bean == null) continue
+ if (fromPitNumber == bean.pit_number) {
+ fromBean = bean
+ pitListCopy.add(bean)
+ } else if (toPitNumber == bean.pit_number) {
+ toBean = bean
+ pitListCopy.add(bean)
+ }
+ }
+
+ if (fromBean == null || toBean == null) {
+ LogUtils.e("Cannot find pit number: from=$fromPitNumber, to=$toPitNumber")
+ return
+ }
+
+ // 交换 pit_number
+ val temp = fromBean.pit_number
+ fromBean.pit_number = toBean.pit_number
+ toBean.pit_number = temp
+
+ // 构造新的 pitList
+ val newPitList: MutableList = ArrayList()
+ for (bean in pitList) {
+ if (!pitListCopy.contains(bean)) {
+ newPitList.add(bean)
+ }
+ }
+ newPitList.add(fromBean)
+ newPitList.add(toBean)
+// 排序 - 更简洁的 Kotlin 写法
+ newPitList.sortWith(compareBy {
+ try {
+ it.pit_number.toInt()
+ } catch (e: NumberFormatException) {
+ it.pit_number
+ }
+ })
+// // 排序
+// newPitList.sort(java.util.Comparator { a: RoomPitBean, b: RoomPitBean ->
+// try {
+// return@sort Integer.compare(a.pit_number.toInt(), b.pit_number.toInt())
+// } catch (e: NumberFormatException) {
+// return@sort a.pit_number.compareTo(b.pit_number)
+// }
+// })
+
+ mRoomInfoResp!!.room_info.pit_list = newPitList
+
+ // 更新当前用户 pit_number
+ if (mRoomInfoResp!!.user_info != null) {
+ val currentUserId = SpUtil.getUserId().toString()
+ val fromUserId = fromBean.user_id
+ val toUserId = toBean.user_id
+
+ if (fromUserId != null && fromUserId == currentUserId) {
+ try {
+ mRoomInfoResp!!.user_info.pit_number = fromBean.pit_number.toInt()
+ } catch (e: NumberFormatException) {
+ LogUtils.e("Invalid pit number: " + toBean.pit_number)
+ }
+ } else if (toUserId != null && toUserId == currentUserId) {
+ try {
+ mRoomInfoResp!!.user_info.pit_number = fromBean.pit_number.toInt()
+ } catch (e: NumberFormatException) {
+ LogUtils.e("Invalid pit number: " + toBean.pit_number)
+ }
+ }
+ }
+
+ dispatchRoomEvent(messageEvent)
+ }
+
+ private fun dispatchRoomEvent(messageEvent: RoomMessageEvent) {
+ if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+
+ val typeId = mRoomInfoResp!!.room_info.type_id
+ if ("2" == typeId) {
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if ("3" == typeId || "4" == typeId || "1" == typeId || "8" == typeId) {
+ val labelId = mRoomInfoResp!!.room_info.label_id
+ if ("2" == labelId) {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ } else if ("1" == labelId) {
+ roomFragment!!.SingSongEvent(messageEvent)
+ }
+ } else if ("7" == typeId) {
+ roomFragment!!.friendshipRoomFragmentEvent(messageEvent)
+ }
+ if (mRoomInfoResp!!.user_info.pit_number == 9) {
+ mBinding!!.roomTop.rl.visibility = View.VISIBLE
+ ivSoundEffects(true)
+ }
+ }
+
+ private fun hand1005(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+
+ val giftInfo = text.giftInfo
+ val toUserInfo = text.toUserInfo
+ // if (giftInfo == null || toUserInfo == null) return;
+ val pitList = mRoomInfoResp!!.room_info.pit_list ?: return
+
+
+ // roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
+ val typeId = mRoomInfoResp!!.room_info.type_id
+ if ("2" == typeId) {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ return
+ } else if ("1" == typeId || "4" == typeId || "3" == typeId || "8" == typeId) {
+ val labelId = mRoomInfoResp!!.room_info.label_id
+ if ("2" == labelId) {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ return
+ } else if ("1" == labelId) {
+ roomFragment!!.SingSongEvent(messageEvent)
+ return
+ }
+ } else if ("7" == typeId) { //交友房
+ roomFragment!!.friendshipRoomFragmentEvent(messageEvent)
+ return
+ }
+ }
+
+ private fun handleMsgType1014(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ val roomSettingEvent = RoomSettingEvent()
+ roomSettingEvent.roomId = messageEvent.roomId
+ roomSettingEvent.room_up_pit_type = text.room_up_pit_type
+ roomSettingEvent.type = messageEvent.msgType
+
+ if (mRoomBean != null) {
+ mRoomBean!!.room_up_pit_type = text.room_up_pit_type.toString() + ""
+ EventBus.getDefault().post(mRoomBean)
+ }
+
+ EventBus.getDefault().post(roomSettingEvent)
+ }
+
+ private fun handleMsgType1013(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomUserBean == null) return
+
+ val userId2 = SpUtil.getUserId()
+
+ if (text.action == 1 && mRoomUserBean!!.user_id == userId2.toString() + "" && mRoomUserBean!!.pit_number == 9) {
+ queren(text.fromUserInfo.nickname)
+ } else if (text.action == 4 && text.fromUserInfo.user_id == userId2) {
+ queren1(text.fromUserInfo.nickname)
+ } else {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ }
+ }
+
+ private fun handleMsgType1012() {
+ if (customMusicFloatingView != null) {
+ customMusicFloatingView!!.destroy()
+ }
+ AgoraManager.getInstance(this@RoomActivity).desMusic()
+
+ // stub.setVisibility(View.GONE);
+ if ((mRoomInfoResp!!.room_info.type_id == "1" || mRoomInfoResp!!.room_info.type_id == "4" ||
+ mRoomInfoResp!!.room_info.type_id == "3" || mRoomInfoResp!!.room_info.type_id == "8") &&
+ mRoomInfoResp!!.room_info.label_id == "2"
+ ) {
+ for (roomPitBean in mRoomInfoResp!!.song_pit_list) {
+ AgoraManager.getInstance(this@RoomActivity).ClientRole(false)
+ ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding)
+ mBinding!!.rlMic.visibility = View.GONE
+ }
+ if (mRoomInfoResp!!.song_user_info != null && mRoomInfoResp!!.song_user_info.user_id != null) {
+ if (mRoomInfoResp!!.song_user_info.user_id == SpUtil.getUserId().toString() + "") {
+ AgoraManager.getInstance(this@RoomActivity).ClientRole(false)
+ ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding)
+ mBinding!!.rlMic.visibility = View.GONE
+ }
+ }
+ }
+
+ MvpPre!!.postRoomInfo(roomId)
+ }
+
+ private fun handleMsgType124(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ try {
+ val parsedText = GsonUtils.fromJson(
+ text.text,
+ text::class.java
+ )
+ val musicPlayBean = MusicPlayBean()
+ musicPlayBean.position = parsedText.position
+ EventBus.getDefault().post(musicPlayBean)
+ } catch (e: Exception) {
+ // Handle exception
+ }
+ }
+
+ private fun handleMsgType1003(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+ if (roomFragment == null) {
+ roomFragment = RoomFragment.newInstance()
+ supportFragmentManager
+ .beginTransaction()
+ .replace(R.id.vp_room_pager, roomFragment!!)
+ .commitAllowingStateLoss()
+ }
+
+ val fromUserInfo = text.fromUserInfo ?: return
+
+ val pitNumber = text.pit_number
+ val userId = fromUserInfo.user_id
+ val currentUserId = SpUtil.getUserId()
+
+ if ("9" == pitNumber && userId == currentUserId) {
+ mBinding!!.roomTop.rl.visibility = View.VISIBLE
+ ivSoundEffects(true)
+ }
+
+ if (userId == currentUserId) {
+ aBoolean = false
+ ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding_up)
+ setBoolean(aBoolean)
+ if (mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.pit_number =
+ pitNumber?.toInt() ?: -1
+ }
+ setRoleType(3, pitNumber!!.toInt())
+ switchMic(2)
+ }
+
+
+ val typeId = mRoomInfoResp!!.room_info.type_id
+ if ("2" == typeId) {
+ if ("9" == pitNumber) {
+ mRoomInfoResp!!.room_info.pit_list[0] = getPitBean(messageEvent)
+ if (mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.pit_number = pitNumber.toInt()
+ }
+ }
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if ("3" == typeId || "4" == typeId || "1" == typeId || "8" == typeId) {
+ val labelId = mRoomInfoResp!!.room_info.label_id
+ if ("2" == labelId) {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ } else if ("1" == labelId) {
+ roomFragment!!.SingSongEvent(messageEvent)
+ }
+ } else if ("7" == typeId) {
+ mBinding!!.rlMore.visibility = View.GONE
+ mBinding!!.rlMisc.visibility = View.GONE
+
+ roomFragment!!.friendshipRoomFragmentEvent(messageEvent)
+ } else {
+ roomFragment!!.updateSeatViewExchangedWithPitArray(mRoomInfoResp)
+ }
+
+ // if (pitNumber.equals("9") && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId()+"")) {
+// ivSoundEffects(true);
+// } else {
+// ivSoundEffects(false);
+// }
+ }
+
+ private fun handleMsgType1004(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+
+ val fromUserInfo = text.fromUserInfo ?: return
+
+ val pitNumber = text.pit_number
+ val userId = fromUserInfo.user_id
+ val currentUserId = SpUtil.getUserId()
+
+ if (userId == currentUserId) {
+ aBoolean = true
+ ivWheatFeeding(com.xscm.moduleutil.R.mipmap.room_wheat_feeding)
+ setBoolean(aBoolean)
+ if (mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.pit_number = 0
+ }
+ setRoleType(0, 0)
+ switchMic(2)
+ }
+
+ if (pitNumber == "9") {
+ ivSoundEffects(false)
+ }
+
+ if (userId == currentUserId && "9" == pitNumber) {
+ if (customMusicFloatingView != null) {
+ customMusicFloatingView!!.destroy()
+ AgoraManager.getInstance(this@RoomActivity).desMusic()
+ isMusic = false
+ }
+ mBinding!!.roomTop.rl.visibility = View.GONE
+ ivSoundEffects(false)
+ }
+
+ val typeId = mRoomInfoResp!!.room_info.type_id
+ if ("2" == typeId) {
+ if ("9" == pitNumber) {
+ if (userId == currentUserId) {
+ mRoomInfoResp!!.room_info.pit_list[0] = getPitBean2(messageEvent, "9")
+ if (mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.pit_number = 0
+ }
+ }
+ } else if ("888" == pitNumber) {
+ mRoomInfoResp!!.room_auction = null
+ if (userId == currentUserId) {
+ setRoleType(0, 0)
+ switchMic(2)
+ }
+ }
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if ("3" == typeId || "4" == typeId || "1" == typeId || "8" == typeId) {
+ val labelId = mRoomInfoResp!!.room_info.label_id
+ if ("2" == labelId) {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ } else if ("1" == labelId) {
+ roomFragment!!.SingSongEvent(messageEvent)
+ if (mRoomInfoResp!!.user_info.user_id == SpUtil.getUserId().toString() + "") {
+ ivSoundEffects(false)
+ }
+ }
+ } else {
+ roomFragment!!.friendshipRoomFragmentEvent(messageEvent)
+ }
+ }
+
+ private fun handleMsgType1022(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+
+ val pitNumber = text.pit_number
+ val userId = text.fromUserInfo.user_id
+ val currentUserId = SpUtil.getUserId()
+
+ if (text.type == 1) {
+ if ("888" == pitNumber) {
+ var type = -1
+ if ("2" == mRoomInfoResp!!.room_info.type_id) {
+ type = if ("1" == mRoomInfoResp!!.room_info.label_id) 1 else 2
+ }
+ if (userId == currentUserId) {
+ setRoleType(3, 888)
+ switchMic(2)
+ }
+ }
+ } else if (text.type == 2) {
+ if ("9" == pitNumber) {
+ setRoleType(0, 0)
+ switchMic(2)
+ } else if ("888" == pitNumber) {
+ mRoomInfoResp!!.room_auction = RoomAuction()
+ if (userId == currentUserId) {
+ setRoleType(0, 0)
+ switchMic(2)
+ }
+ }
+ }
+
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ }
+
+ private fun handleMsgType1023(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_auction == null) return
+
+ mRoomInfoResp!!.room_auction.auction_user = text.auction_user
+ SpUtil.setAuctionId(text.auction_user.auction_id)
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ // roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
+ }
+
+ private fun handleMsgType1024(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_auction == null) return
+ if (mRoomInfoResp!!.room_auction.auction_list != null) {
+ mRoomInfoResp!!.room_auction.auction_list.clear()
+ }
+ if (mRoomInfoResp!!.room_auction.auction_list != null) {
+ mRoomInfoResp!!.room_auction.auction_list.addAll(text.auction_list)
+ } else {
+ mRoomInfoResp!!.room_auction.auction_list = ArrayList()
+ // mRoomInfoResp.getRoom_auction().getAuction_list().addAll(text.getAuction_list());
+ }
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ // roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
+ }
+
+ private fun handleMsgType1020(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ mRoomBean = text.roomInfo
+ EventBus.getDefault().post(mRoomBean)
+ changeBackgroundColor(mRoomBean?.getRoom_background())
+ }
+
+ private fun handleMsgType1011(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || text.fromUserInfo == null) return
+
+ if (text.fromUserInfo.user_id == SpUtil.getUserId()) {
+ MvpPre!!.quitRoom(roomId, SpUtil.getUserId().toString() + "")
+ }
+ }
+
+ private fun handleMsgType1001() {
+ number++
+ mBinding!!.roomTop.tvNum.text = number.toString() + ""
+ }
+
+ private fun handleMsgType1002() {
+ number--
+ if (number < 0) {
+ number = 0
+ }
+ mBinding!!.roomTop.tvNum.text = number.toString() + ""
+ }
+
+ private fun handleMsgType1029(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.user_info == null) return
+
+ if (mRoomInfoResp!!.user_info.pit_number == 9 && mRoomInfoResp!!.user_info.user_id == SpUtil.getUserId()
+ .toString() + ""
+ ) {
+ querenPk(text.text, text.pkId)
+ }
+ }
+
+ private fun handleMsgType1021(messageEvent: RoomMessageEvent, text: T) {
+ if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+
+ val typeId = mRoomInfoResp!!.room_info.type_id
+ if ("2" == typeId) {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if ("1" == typeId || "4" == typeId || "3" == typeId || "8" == typeId) {
+ val labelId = mRoomInfoResp!!.room_info.label_id
+ if ("2" == labelId) {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ } else {
+ updateCharmForAllPitBeans("")
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ roomFragment!!.SingSongEvent(messageEvent)
+ }
+ } else {
+ updateCharmForAllPitBeans("")
+ roomFragment!!.upFriendList(mRoomInfoResp!!.room_info.pit_list)
+ }
+ }
+
+ private fun updateCharmForAllPitBeans(charm: String) {
+ if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+
+ val pitList = mRoomInfoResp!!.room_info.pit_list ?: return
+
+ for (roomPitBean in pitList) {
+ roomPitBean.charm = charm
+ try {
+ pitList[roomPitBean.pit_number.toInt() - 1] = roomPitBean
+ } catch (e: NumberFormatException) {
+ // Handle exception
+ }
+ }
+ }
+
+ private fun handleMsgType1036(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ if (text.room_id == roomId) {
+ val onlineNumber = text.online_number.toString() + ""
+ if (mBinding!!.roomTop.tvNum.text.toString() != onlineNumber) {
+ mBinding!!.roomTop.tvNum.text = onlineNumber
+ }
+ }
+ }
+
+ private fun handleMsgType1049(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ val endTime = if (text.end_time != null) text.end_time.toLong() else 0
+ if (text.step != 3) {
+ roomFragment!!.updateFriendshipState(text.step, text.friend_id, endTime, null)
+ } else {
+ roomFragment!!.updateFriendshipState(text.step, text.friend_id, 0, text.friend_user)
+ }
+ }
+
+ private fun handleMsgType1050(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ roomFragment!!.friendTimeDelayWithTime(text.end_time.toLong())
+ }
+
+ private fun handleMsgType1051(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ if (text.user1_id == null || text.user2_id == null) {
+ return
+ }
+ if (roomFragment != null) {
+ roomFragment!!.clearDialog()
+ }
+ val friend_user = getFriendUserBean(messageEvent)
+ FriendsDialogFragment.show(friend_user, supportFragmentManager)
+
+
+ if (text.user1_id == SpUtil.getUserId()
+ .toString() + "" || text.user2_id == SpUtil.getUserId().toString() + ""
+ ) {
+ if (roomSwitchRunnable != null) {
+ roomSwitchHandler.removeCallbacks(roomSwitchRunnable!!)
+ }
+
+ pendingRoomId = text.room_id
+ if (pendingRoomId == null) {
+ return
+ }
+ LogUtils.e("需要加入的房间id:pendingRoomId: $pendingRoomId")
+ roomSwitchRunnable = Runnable {
+ if (!isFinishing && !isDestroyed) {
+ if (pendingRoomId != lastSwitchedRoomId) {
+ MvpPre!!.quitRoom2(messageEvent.roomId, SpUtil.getUserId().toString() + "")
+ quit()
+ MessageListenerSingleton.quitGroup(messageEvent.roomId)
+ MessageListenerSingleton.getInstance().joinGroup(pendingRoomId)
+ MvpPre!!.getRoomIn(pendingRoomId, "")
+ lastSwitchedRoomId = pendingRoomId!!
+ AgoraManager.getInstance(OkDownloadProvider.context).lastRoomId =
+ messageEvent.roomId
+ }
+ }
+ pendingRoomId = null
+ }
+
+ roomSwitchHandler.postDelayed(roomSwitchRunnable!!, 3000)
+ }
+ }
+
+ //退出房间
+ fun quitRoomAll(roomId: String?) {
+ MvpPre!!.quitRoom(roomId, SpUtil.getUserId().toString() + "")
+ }
+
+ private fun handleMsgType1053(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || text.list == null || text.list.isEmpty()) return
+ val pitArr: MutableList = ArrayList()
+ for (j in text.list.indices) {
+ val roomPitBean = getRoomPitBean(messageEvent, j)
+ pitArr.add(roomPitBean)
+ }
+
+ roomFragment!!.friendSeatDidChanged(pitArr)
+ pitArr.clear()
+ }
+
+ private fun handleMsgType1054(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || text.list == null) return
+
+ val heartList = text.list.stream()
+ .map { item: UserInfo ->
+ val heartList1 = HeartList()
+ heartList1.heartId = item.heartId
+ heartList1.heartNum = item.heartNum
+ heartList1
+ }
+ .collect(Collectors.toList())
+
+ roomFragment!!.friendHeartNumberDidChanged(heartList)
+ }
+
+ private fun handleMsgType1055(messageEvent: RoomMessageEvent) {
+ if (!isFinishing && !isDestroyed) {
+ MvpPre!!.quitRoom2(messageEvent.roomId, SpUtil.getUserId().toString() + "")
+ quit()
+ jiaR()
+ }
+ }
+
+ private fun handleMsgType1035(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return
+
+ val fromUserInfo = text.fromUserInfo ?: return
+
+ val typeId = mRoomInfoResp!!.room_info.type_id
+ if ("2" == typeId) {
+ roomFragment!!.handleAuctionMessageEvent(messageEvent)
+ } else if ("1" == typeId || "3" == typeId || "4" == typeId || "8" == typeId) {
+ val labelId = mRoomInfoResp!!.room_info.label_id
+ if ("2" == labelId) {
+ roomFragment!!.KtvFragmentEvent(messageEvent)
+ } else {
+// updatePitBeanForUser(fromUserInfo);
+ roomFragment!!.upRoomInfoData(updatePitBeanForUser(fromUserInfo))
+ roomFragment!!.SingSongEvent(messageEvent)
+ }
+ } else {
+ roomFragment!!.upRoomInfoData(updatePitBeanForUser(fromUserInfo))
+ roomFragment!!.friendshipRoomFragmentEvent(messageEvent)
+ }
+ }
+
+ private fun updatePitBeanForUser(fromUserInfo: UserInfo): RoomInfoResp? {
+ if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return mRoomInfoResp
+
+ val pitList = mRoomInfoResp!!.room_info.pit_list ?: return mRoomInfoResp
+
+ for (pitBean in pitList) {
+ if (pitBean.user_id == fromUserInfo.user_id.toString() + "") {
+ pitBean.charm = fromUserInfo.charm
+ pitBean.avatar = fromUserInfo.avatar
+ pitBean.nickname = fromUserInfo.nickname
+ pitBean.sex = fromUserInfo.sex.toString() + ""
+ pitBean.dress = fromUserInfo.dress
+ }
+ }
+ return mRoomInfoResp
+ }
+
+ private fun handleMsgType125(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ try {
+ val parsedText = GsonUtils.fromJson(
+ text.text,
+ text::class.java
+ )
+ if (parsedText.is_mute == 1) {
+ AgoraManager.getInstance(this).ClientRole(false)
+ AgoraManager.getInstance(this).muteLocalAudioStreamEx(false, SpUtil.getUserId())
+ } else {
+ AgoraManager.getInstance(this).ClientRole(true)
+ AgoraManager.getInstance(this).muteLocalAudioStreamEx(true, SpUtil.getUserId())
+ }
+ } catch (e: Exception) {
+ // Handle exception
+ }
+ }
+
+ private fun handleMsgType1007() {
+ if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.is_host = 1
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ // roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
+ }
+ }
+
+ private fun handleMsgType1006() {
+ if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.is_management = 1
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ }
+ }
+
+ private fun handleMsgType1018() {
+ if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.is_host = 0
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ // roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp);
+ }
+ }
+
+ private fun handleMsgType1017() {
+ if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) {
+ mRoomInfoResp!!.user_info.is_management = 0
+ roomFragment!!.upRoomInfoData(mRoomInfoResp)
+ }
+ }
+
+ private fun handleMsgType126(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ AgoraManager.getInstance(this)
+ .setLocalAudioEnabled(false, text.fromUserInfo.user_id.toString() + "")
+ }
+
+ private fun handleMsgType1034(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null) return
+
+ val count = text.count
+ if (count == 0) {
+ tvFirst(SpannableStringBuilder("0人排队"))
+ return
+ }
+
+ val countText = count.toString()
+ val fullText = countText + "人排队"
+
+ val spannableStringBuilder = SpannableStringBuilder(fullText)
+ spannableStringBuilder.setSpan(
+ ForegroundColorSpan(
+ ContextCompat.getColor(
+ this,
+ com.xscm.moduleutil.R.color.color_C7BF62
+ )
+ ),
+ 0,
+ countText.length,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
+ )
+ tvFirst(spannableStringBuilder)
+ }
+
+ private fun handleMsgType1016(messageEvent: RoomMessageEvent, text: T?) {
+ if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.user_info == null) return
+
+ if (text.fromUserInfo.user_id == SpUtil.getUserId()) {
+ if (text.is_mute_pit == 1) {
+ switchMic(2)
+ }
+ mRoomInfoResp!!.user_info.is_mute_pit = text.is_mute_pit.toString()
+ mRoomInfoResp!!.user_info.is_mute = text.is_mute.toString()
+ }
+ }
+
+ // TODO: 2025/6/30 上麦,麦位变化
+ private fun getPitBean(messageEvent: RoomMessageEvent): RoomPitBean {
+ val pitBean = RoomPitBean()
+ pitBean.pit_number = messageEvent.text.pit_number
+ pitBean.user_id = messageEvent.text.fromUserInfo.user_id.toString() + ""
+ pitBean.avatar = messageEvent.text.fromUserInfo.avatar
+ pitBean.nickname = messageEvent.text.fromUserInfo.nickname
+ pitBean.sex = messageEvent.text.fromUserInfo.sex.toString() + ""
+ pitBean.charm = messageEvent.text.fromUserInfo.charm
+
+ return pitBean
+ }
+
+ // TODO: 2025/6/30 下麦麦位变化
+ private fun getPitBean2(messageEvent: RoomMessageEvent?, number: String): RoomPitBean {
+ val pitBean = RoomPitBean()
+ pitBean.pit_number = if (messageEvent != null) messageEvent.text.pit_number else number
+ pitBean.user_id = ""
+ pitBean.avatar = ""
+ pitBean.nickname = ""
+ pitBean.sex = ""
+ pitBean.charm = ""
+ pitBean.is_pm = 1
+ return pitBean
+ }
+
+ // TODO: 2025/8/29 排麦位上麦
+ private fun getPitBean3(messageEvent: RoomMessageEvent): AuctionUserBean {
+ val roomAuction = AuctionUserBean()
+ roomAuction.user_id = messageEvent.text.fromUserInfo.user_id.toString() + ""
+ roomAuction.avatar = messageEvent.text.fromUserInfo.avatar
+ roomAuction.nickname = messageEvent.text.fromUserInfo.nickname
+ roomAuction.sex = messageEvent.text.fromUserInfo.sex.toString() + ""
+ roomAuction.charm = messageEvent.text.fromUserInfo.charm
+
+ return roomAuction
+ }
+
+ fun mus() {
+ if (mRoomInfoResp!!.user_info.is_mute == "1") {
+ ToastUtils.show("您已经被禁言")
+ } else {
+ switchMic(1)
+ }
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun onMessageEvent(messageEvent: UnreadCountEvent) {
+ if (messageEvent.aLong == 0L) {
+ mBinding!!.ivMessageDot.visibility = View.GONE
+ } else {
+ mBinding!!.ivMessageDot.visibility = View.VISIBLE
+ mBinding!!.ivMessageDot.text = messageEvent.aLong.toString()
+ }
+ }
+
+ private fun querenPk(text: String, pk_id: String) {
+ // 创建并显示确认对话框
+ val dialog = ConfirmDialog(
+ this,
+ "温馨提示",
+ text,
+ "确认",
+ "拒绝",
+ { v: View? ->
+ // 点击“确认”按钮时执行删除操作
+ MvpPre!!.acceptPk(pk_id, "1")
+ },
+ { v: View? ->
+ MvpPre!!.acceptPk(pk_id, "2")
+ }, true, 10
+ )
+ dialog.show()
+ addActiveDialog(dialog)
+ }
+
+ /**
+ * 修改背景图
+ *
+ * @param bjId
+ */
+ fun changeBackgroundColor(bjId: String?) {
+ // 假设你的Activity有一个根布局,例如 ConstraintLayout
+ ImageUtils.loadImageWithCache(this, bjId, mBinding!!.ivBg)
+ }
+
+ fun changeBackground(bjId: Int) {
+ mBinding!!.ivBg.setImageDrawable(resources.getDrawable(bjId))
+ }
+
+ fun setvisibTop(`is`: Boolean) {
+ mBinding!!.roomTop.root.visibility =
+ if (`is`) View.VISIBLE else View.GONE
+ }
+
+ fun setDiany(`is`: Boolean) {
+// mBinding.flaoat.setVisibility(is? VISIBLE : GONE);
+ }
+
+ fun setOnlineNumber(number: Int) {
+ mBinding!!.roomTop.tvNum.text = number.toString() + ""
+ }
+
+ /**
+ * 特效设置
+ */
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun setEffectSwitch(event: EffectEvent) {
+ if (event.isEffectOn) { //特效开启
+ QXGiftPlayerManager.getInstance(this).openOrCloseEffectViewWith(true)
+ mBinding!!.svgaGift.visibility = View.VISIBLE
+ } else {
+// mBinding.svgaGift.closeEffect();
+// mBinding.svgaGift.closeEffect();
+ QXGiftPlayerManager.getInstance(this).openOrCloseEffectViewWith(false)
+ mBinding!!.svgaGift.visibility = View.GONE
+ }
+ }
+
+ /**
+ * 坐骑进场特效
+ *
+ * @param roomJoinMountModel
+ */
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun roomJoinMount(roomJoinMountModel: RoomJoinMountModel) {
+ if (roomId != roomJoinMountModel.room_id) {
+ return
+ }
+ if (roomJoinMountModel.show_type != 1) {
+ val gift = GiftBean()
+ gift.gift_id = ""
+ gift.play_image = roomJoinMountModel.ride_url
+ QXGiftPlayerManager.getInstance(this).displayFullEffectView(roomJoinMountModel.ride_url)
+ // mBinding.svgaZuoji.setSource(roomJoinMountModel.getRide_url(), 2);
+ }
+ }
+
+ private var isSwith = false
+ private var voive = false //声音开关
+ private var canSend = true
+ private var aBoolean = true //上下麦按钮
+ private var mCountDownTimer: CountDownTimer? = null
+ private var mCountDownTimer2: CountDownTimer? = null
+
+ private fun onClick(view: View) {
+ val id = view.id
+ if (id == R.id.btn_follow) {
+ MvpPre!!.userGuanz(mRoomInfoResp!!.room_info.room_id, "2")
+ } else if (id == R.id.btn_notice) {
+// RoomTipsView.show(this,view,"公告","公告内容");
+ val roomNoticeDialogFragment = RoomNoticeDialogFragment(this)
+ roomNoticeDialogFragment.setTitle("公告")
+ roomNoticeDialogFragment.setContent(mRoomBean!!.room_intro)
+ roomNoticeDialogFragment.show()
+ addActiveDialog(roomNoticeDialogFragment)
+ } else if (id == R.id.btn_ranking) { //排行榜
+// RoomChartsFragment.newInstance(roomId).show(getSupportFragmentManager(), "RoomChartsFragment");
+ val fragment = RoomChartsFragment.newInstance(roomId, mRoomInfoResp)
+ fragment.show(supportFragmentManager, "RoomChartsFragment")
+ addActiveDialogFragment(fragment)
+ } else if (id == R.id.btn_close_live) { //退出房间
+ showExitRoomDialog()
+ } else if (id == R.id.tv_num) {
+// RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
+ val fragment = RoomOnlineDialogFragment.show(
+ roomId, "", mRoomUserBean, mRoomInfoResp,
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ } else if (id == R.id.rl) {
+ MvpPre!!.clearUserCharm(roomId, "")
+ } else if (id == R.id.ll_input) {
+ mBinding!!.llInput.visibility = View.GONE
+ mBinding!!.inputMenu1.dismiss()
+ } else if (id == R.id.iv_chat) {
+ if (mRoomInfoResp!!.user_info.is_mute == "1") {
+ ToastUtils.show("您已经被禁言")
+ } else {
+ // mBinding.llInput.setVisibility(View.VISIBLE);
+// mBinding.inputMenu1.bringToFront(); // 强制将该 View 置于最上层
+// mBinding.inputMenu1.show();
+
+ dialogDismiss()
+ }
+ } else if (id == R.id.rl_mic) {
+ if (mRoomInfoResp!!.user_info.is_mute_pit != null && mRoomInfoResp!!.user_info.is_mute_pit == "1") {
+ ToastUtils.show("您被禁麦了")
+ } else {
+ if (isSwith) {
+ switchMic(1)
+ } else {
+ switchMic(2)
+ }
+ }
+ } else if (id == R.id.rl_sett) { //房间设置
+// RoomSettingFragment.show(mRoomInfoResp, getSupportFragmentManager());
+ if (mRoomInfoResp == null) {
+ com.blankj.utilcode.util.ToastUtils.showShort("请稍后再试")
+ return
+ }
+ val fragment = RoomSettingFragment.show(
+ mRoomInfoResp,
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ } else if (id == R.id.rl_voive) {
+ if (voive) {
+ mBinding!!.imVoive.setImageResource(com.xscm.moduleutil.R.mipmap.room_voice_g)
+ voive = false
+ } else {
+ mBinding!!.imVoive.setImageResource(com.xscm.moduleutil.R.mipmap.room_voice_kg)
+ voive = true
+ }
+ AgoraManager.getInstance(this).muteSpeaker(!voive)
+ } else if (id == R.id.rl_more) { //点击PK
+// RoomPkDialogFragment.newInstance(roomId, SpUtil.getUserId() + "", mRoomInfoResp.getRoom_info().getIs_pk()).show(getSupportFragmentManager(), "RoomPkDialogFragment");
+ val fragment = RoomPkDialogFragment.newInstance(
+ roomId,
+ SpUtil.getUserId().toString() + "",
+ mRoomInfoResp!!.room_info.is_pk
+ )
+ fragment.show(supportFragmentManager, "RoomPkDialogFragment")
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ } else if (id == R.id.rl_message) {
+// RoomMessageDialogFragment.show(getSupportFragmentManager());
+ val fragment = RoomMessageDialogFragment.show(
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ } else if (id == R.id.rl_misc) { //设置点歌
+ if (mRoomInfoResp!!.room_info.label_id == "1") {
+ queren()
+ } else {
+// RequestDialogFragment.show(roomId, mRoomInfoResp, 1, getSupportFragmentManager());
+ val fragment = RequestDialogFragment.show(
+ roomId, mRoomInfoResp, 1,
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ }
+ } else if (id == R.id.rl_gift) { //礼物
+// RoomGiftDialogFragment.show(mRoomInfoResp, null, roomId, 0, "", getSupportFragmentManager());
+ val fragment = RoomGiftDialogFragment.show(
+ mRoomInfoResp, null, roomId, 0, "",
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ } else if (id == R.id.iv_sound_effects) {
+// SoundEffectsDialogFragment.show(roomId, getSupportFragmentManager());
+ val fragment = SoundEffectsDialogFragment.show(
+ roomId,
+ supportFragmentManager
+ )
+ if (fragment != null) {
+ addActiveDialogFragment(fragment) // 添加到管理列表
+ }
+ } else if (id == R.id.cl_first_charge) {
+// showWheatFeedingDialog(roomId, (mRoomInfoResp.getUser_info().getIs_room_owner() == 1 || mRoomInfoResp.getUser_info().getIs_host() == 1 || mRoomInfoResp.getUser_info().getIs_management() == 1) ? 1 : 2);
+ roomFragment!!.showWheatFeedingDialog(
+ roomId,
+ if ((mRoomInfoResp!!.user_info.is_room_owner == 1 || mRoomInfoResp!!.user_info.is_host == 1 || mRoomInfoResp!!.user_info.is_management == 1)) 1 else 2
+ )
+ } else if (id == R.id.iv_wheat_feeding) { //点击上麦操作
+ if (mRoomInfoResp!!.room_info.room_up_pit_type == "1") {
+// showWheatFeedingDialog(roomId, mRoomInfoResp.getUser_info().getPit_number() == 9 ? 1 : 2);
+ if (aBoolean) {
+ MvpPre!!.applyPit(roomId, "")
+ // aBoolean = false;
+ } else {
+ MvpPre!!.downPit(roomId, "")
+ // aBoolean = true;
+ }
+ } else {
+ if (aBoolean) {
+// mBinding.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding_up);
+ MvpPre!!.applyPit(roomId, "")
+ aBoolean = false
+ } else {
+// mBinding.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding);
+ MvpPre!!.downPit(roomId, "")
+ aBoolean = true
+ }
+ }
+ }
+ }
+
+ // TODO: 2025/9/18 type==1:退出房间,进入到首页 2:退出当前页,不导航到首页,是从首页点击关闭悬浮退出的
+ fun performExitRoom(type: Int) {
+ // 清理最小化状态
+ clearMinimizeState()
+ isMinimized = false
+
+ // 执行退出房间逻辑
+ CommonAppContext.getInstance().isPlaying = false
+ CommonAppContext.getInstance().isShow = false
+ QXGiftPlayerManager.getInstance(this).destroyEffectSvga()
+ // 停止屏幕捕获和其他资源
+// AgoraManager.getInstance(this).stopScreenCapture();
+// AgoraManager.getInstance(this).leaveRoom();
+// AgoraManager.getInstance(this).stopMusicPlayer();
+ AgoraManager.getInstance(this).cleanup()
+
+ MyRoomSingleton.getInstance().onExitRoom()
+ MessageListenerSingleton.quitGroup(roomId)
+ // 清理ViewModel中的数据
+// if (sharedViewModel != null) {
+// sharedViewModel.clearAllData();
+// }
+ RoomManager.getInstance().exitRoom(roomId)
+ // 清理资源
+ cleanupResources()
+ if (type == 1) {
+ // 导航到首页
+ navigateToMainPage()
+ } else if (type == 2) {
+ // 返回上一个页面
+ finish()
+ }
+
+ finish()
+ }
+
+ private val isAppInForeground: Boolean
+ // 添加前后台状态检测
+ get() {
+ if (mRoomInfoResp == null) {
+ return true
+ }
+ if (mRoomInfoResp!!.room_info.label_id != "6") {
+ val activityManager =
+ getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
+ val appProcesses =
+ activityManager.runningAppProcesses ?: return false
+
+ val packageName = packageName
+ for (appProcess in appProcesses) {
+ if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
+ && appProcess.processName == packageName
+ ) {
+ return true
+ }
+ }
+ } else {
+ return true
+ }
+ return false
+ }
+
+ private fun navigateToMainPage() {
+ ARouter.getInstance()
+ .build(ARouteConstants.ME)
+ .navigation()
+
+ // 添加转场动画
+ overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
+ }
+
+ private fun quitUpRoom() {
+ // 清理最小化状态
+ clearMinimizeState()
+ isMinimized = false
+
+ // 执行退出房间逻辑
+ CommonAppContext.getInstance().isPlaying = false
+ CommonAppContext.getInstance().isShow = false
+ QXGiftPlayerManager.getInstance(this).destroyEffectSvga()
+ // 停止屏幕捕获和其他资源
+// AgoraManager.getInstance(this).stopScreenCapture();
+ AgoraManager.getInstance(this).leaveRoom()
+ // AgoraManager.getInstance(this).stopMusicPlayer();
+ AgoraManager.getInstance(this).cleanup()
+
+ MyRoomSingleton.getInstance().onExitRoom()
+ MessageListenerSingleton.quitGroup(roomId)
+ cleanupResources()
+ }
+
+ private fun minimizeToBackground() {
+ isMinimized = true
+ // 保存最小化状态和房间ID
+ saveMinimizeState()
+ // 设置应用状态
+ CommonAppContext.getInstance().isShow = false
+ // 通知状态管理器RoomActivity已最小化
+ if (appStateListener != null) {
+ appStateListener!!.isAppInBackground = true
+ }
+ QXGiftPlayerManager.getInstance(applicationContext).destroyEffectSvga()
+
+ ARouter.getInstance()
+ .build(ARouteConstants.ME)
+ .navigation()
+
+ // ARouter.getInstance().build(ARouteConstants.ME)
+// .addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP)
+// .navigation();
+
+ // 使用Intent启动主Activity,通过ARouter路径
+ // 这样可以避免模块间的直接依赖
+// try {
+// val intent = Intent()
+// intent.setClassName(packageName, "com.xscm.modulemain.activity.MainActivity")
+// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
+// startActivity(intent)
+// } catch (e: Exception) {
+// // 如果直接指定类名失败,则使用默认的Launcher Activity
+// val startMain = Intent(Intent.ACTION_MAIN)
+// startMain.addCategory(Intent.CATEGORY_HOME)
+// startMain.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
+// startActivity(startMain)
+// }
+
+ // 隐藏Activity而不是销毁它
+// moveTaskToBack(true);
+ // 使用 moveTaskToBack 将应用最小化
+// moveTaskToBack(true);
+ }
+
+ private fun saveMinimizeState() {
+ val prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE)
+ val editor = prefs.edit()
+ editor.putString(PREF_MINIMIZED_ROOM, roomId)
+ editor.putLong(PREF_MINIMIZED_TIME, System.currentTimeMillis())
+ editor.putBoolean("is_minimized", true)
+ editor.apply()
+ }
+
+ private fun clearMinimizeState() {
+ val prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE)
+ val editor = prefs.edit()
+ editor.remove(PREF_MINIMIZED_ROOM)
+ editor.remove(PREF_MINIMIZED_TIME)
+ editor.putBoolean("is_minimized", false)
+ editor.apply()
+ }
+
+ private fun wasMinimized(): Boolean {
+ val prefs = getSharedPreferences("room_minimize_state", Context.MODE_PRIVATE)
+ return prefs.getBoolean("is_minimized", false)
+ }
+
+ private fun queren() {
+ // 创建并显示确认对话框
+ val dialog = ConfirmDialog(
+ this,
+ "提示",
+ "您将要发起点歌申请?",
+ "确认",
+ "取消",
+ { v: View? ->
+ // 点击“确认”按钮时执行删除操作
+ MvpPre!!.applySong(roomId)
+ },
+ { v: View? -> }, false, 0
+ )
+ dialog.show()
+ addActiveDialog(dialog)
+ }
+
+ /**
+ * 设置是否打开麦克风
+ *
+ * @param type
+ */
+ // @Override
+ fun switchMic(type: Int) {
+ if (type == 1) {
+ mBinding!!.ivMic.setImageResource(com.xscm.moduleutil.R.mipmap.room_microphone)
+ AgoraManager.getInstance(this)
+ .setLocalAudioEnabled(true, SpUtil.getUserId().toString() + "")
+ isSwith = false
+ AgoraManager.getInstance(this).muteLocalAudioStream(false)
+ AgoraManager.getInstance(this).ClientRole(true)
+ } else {
+ mBinding!!.ivMic.setImageResource(com.xscm.moduleutil.R.mipmap.room_microphone_off)
+ AgoraManager.getInstance(this)
+ .setLocalAudioEnabled(false, SpUtil.getUserId().toString() + "")
+ isSwith = true
+ isMute(1)
+ }
+ }
+
+ /** 进入小黑屋将所有的底部隐藏 */
+ fun setviewyc(voive: Boolean) {
+ mBinding!!.rlMore.visibility =
+ if (voive) View.GONE else View.GONE
+ mBinding!!.rlMisc.visibility =
+ if (voive) View.GONE else View.GONE
+ mBinding!!.rlMic.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ mBinding!!.rlSett.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ mBinding!!.rlVoive.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ mBinding!!.rlGift.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ mBinding!!.ivSoundEffects.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ mBinding!!.ivWheatFeeding.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ mBinding!!.clFirstCharge.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ }
+
+ /** 这里是当进入电影放房的时候,如果是排麦模式,并且不是电影放的时候,就隐藏排麦视图 */
+ fun clFirstCharge(voive: Boolean) {
+ mBinding!!.clFirstCharge.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ }
+
+ fun ivWheatFeeding(id: Int) {
+ mBinding!!.ivWheatFeeding.setImageResource(id)
+ }
+
+ fun setBoolean(voive: Boolean) {
+ this.aBoolean = voive
+ }
+
+ fun ivSoundEffects(voive: Boolean) {
+ mBinding!!.ivSoundEffects.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ }
+
+ fun tvFirst(s: SpannableStringBuilder?) {
+ mBinding!!.tvFirst.text = s
+ }
+
+ fun setrlMic(voive: Boolean) {
+ mBinding!!.rlMic.visibility =
+ if (voive) View.VISIBLE else View.GONE
+ }
+
+ fun rlMore(voive: Boolean) {
+ mBinding!!.rlMore.visibility = if (voive) View.GONE else View.GONE
+ }
+
+ fun ivMic(inIvMic: Int) {
+ mBinding!!.ivMic.setImageResource(inIvMic)
+ }
+
+ fun setRoleType(roleType: Int, pit_number: Int) {
+ val rl_voice = mBinding!!.rlVoive // 注意:原拼写错误已修正
+ val rl_mic = mBinding!!.rlMic
+ val rl_more = mBinding!!.rlMore
+ val rl_misc = mBinding!!.rlMisc
+
+ // 默认隐藏所有按钮
+ rl_voice.visibility = View.GONE
+ rl_more.visibility = View.GONE
+ rl_misc.visibility = View.GONE
+ rl_mic.visibility = View.GONE
+
+ // 空指针保护
+ if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null || mRoomInfoResp!!.user_info == null) {
+ return
+ }
+
+ val typeId = mRoomInfoResp!!.room_info.type_id
+ val labelId = mRoomInfoResp!!.room_info.label_id
+ val userPitNumber = mRoomInfoResp!!.user_info.pit_number
+
+ // 特殊房间类型处理(优先级最高)
+ if ("6" == typeId) {
+ mBinding!!.rlMessage.visibility = View.GONE
+ return // 全部隐藏,无需继续处理
+ }
+
+
+ // 根据角色类型显示按钮
+ when (roleType) {
+ 1, 2, 3 -> {
+ rl_voice.visibility = View.VISIBLE
+ rl_mic.visibility =
+ if (pit_number != 0) View.VISIBLE else View.GONE
+ rl_more.visibility =
+ if (pit_number == 9) View.GONE else View.GONE
+ rl_misc.visibility = View.GONE
+ }
+
+ 0 -> {
+ rl_voice.visibility = View.VISIBLE
+ rl_mic.visibility =
+ if (pit_number != 0) View.VISIBLE else View.GONE
+ rl_misc.visibility = View.GONE
+ }
+
+ 5 -> {
+ rl_voice.visibility = View.VISIBLE
+ rl_more.visibility = View.GONE
+ rl_misc.visibility = View.GONE
+ }
+
+ else -> {}
+ }
+ if (roleType != 5) {
+ rl_misc.visibility = View.GONE
+ if (userPitNumber == 9) {
+ rl_more.visibility = View.GONE
+ }
+ }
+
+
+ // label_id 和 type_id 联合判断
+ if (mutableListOf("1", "3", "4", "8").contains(typeId) && "2" == labelId) {
+ rl_more.visibility = View.GONE
+ }
+
+ // mic 显示逻辑
+ if (userPitNumber > 0) {
+ rl_mic.visibility = View.VISIBLE
+ switchMic(2)
+ } else {
+ if (pit_number == 888) {
+ rl_mic.visibility = View.VISIBLE
+ switchMic(2)
+ } else if (pit_number == -1) {
+ rl_mic.visibility = View.VISIBLE // 原代码此处缺少 View. 前缀,已补全
+ switchMic(1)
+ } else {
+ rl_mic.visibility = View.GONE
+ switchMic(2)
+ }
+ }
+
+ if ("7" == typeId || "2" == typeId) {
+ rl_more.visibility = View.GONE
+ rl_misc.visibility = View.GONE
+ }
+ }
+
+ fun isMute(is_mute: Int) {
+ val text = text()
+ text.is_mute = is_mute
+ val s = GsonUtils.toJson(text)
+ val t = T()
+ t.fromUserInfo = SpUtil.getUserInfo()
+ t.text = s
+ val roomMessageEvent = RoomMessageEvent(126, mRoomInfoResp!!.room_info.room_id, t)
+ val json = GsonUtils.toJson(roomMessageEvent)
+ // 转换为 byte[]
+ val binaryData = json.toByteArray(StandardCharsets.UTF_8)
+ // 创建自定义消息
+ MessageListenerSingleton.getInstance().sendCustomRoomMessage(
+ roomId + "",
+ binaryData
+ )
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ fun roomInfoEvent(messageEvent: RoomWheatEvent) {
+ if (messageEvent.roomId == roomId) {
+ if (messageEvent.isOccupied) {
+ mBinding!!.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding_up)
+ aBoolean = false
+ } else {
+ mBinding!!.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding)
+ aBoolean = true
+ }
+ }
+ }
+
+ @SuppressLint("MissingInflatedId")
+ fun dialogDismiss() {
+ // // 使用 AlertDialog.Builder
+
+ val builder = AlertDialog.Builder(this)
+ val inflater = layoutInflater
+ val dialogView =
+ inflater.inflate(com.xscm.moduleutil.R.layout.room_message_input_menu, null)
+ builder.setView(dialogView)
+ val etContent = dialogView.findViewById(com.xscm.moduleutil.R.id.et_content)
+ val tvSend = dialogView.findViewById