From a4caa9b07830a77f9971233136b0c2f08bc64e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=B0=8F=E6=B1=9F?= <461355754@qq.com> Date: Fri, 26 Sep 2025 14:32:35 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=9A=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=8D=A2room=E5=8F=98=E6=88=90kotlin?= =?UTF-8?q?=EF=BC=8C=202=EF=BC=9A=E5=9C=A8=E6=89=80=E6=9C=89=E7=9A=84?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E5=88=B0WEBview=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8Intent=E7=9A=84=E6=96=B9=E5=BC=8F=20?= =?UTF-8?q?3=EF=BC=9A=E4=BC=98=E5=8C=96=E7=BD=91=E7=BB=9C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 12 +- app/src/main/AndroidManifest.xml | 2 +- .../com/xscm/midi/LaunchPageActivity.java | 10 +- build.gradle | 11 +- gradle.properties | 18 +- gradle/libs.versions.toml | 2 + .../modulelogin/present/LoginPresenter.java | 15 +- moduleUtil/build.gradle | 20 +- .../activity/BaseAppCompatActivity.java | 5 +- .../activity/news/OfficialNoticeActivity.java | 7 +- .../com/xscm/moduleutil/base/RoomManager.java | 7 +- .../xscm/moduleutil/dialog/PolicyDialog.java | 18 +- .../moduleutil/dialog/YouthModelDialog.java | 8 +- .../giftLottery/GiftLotteryPresenter.java | 3 + .../moduleutil/http/ApiResponseCallback.java | 134 + .../http/BusinessAwareConverterFactory.java | 74 + .../xscm/moduleutil/http/RetrofitClient.java | 245 +- .../moduleutil/utils/ARouteConstants.java | 6 +- .../moduleutil/widget/room/BaseViewModel.kt | 38 + .../widget/room/PassRoomException.kt | 8 + .../fragment/CircleCategoryFragment.java | 4 +- modulemain/build.gradle | 2 +- moduleroom/build.gradle | 17 +- moduleroom/src/main/AndroidManifest.xml | 11 + .../moduleroom/activity/RoomActivity.kt | 5434 +++++++++-------- .../dialog/RoomGiftDialogFragment.java | 11 +- .../dialog/RoomSettingFragment.java | 8 +- .../dialog/RoomUserInfoFragment.java | 14 +- .../fragment/FriendshipRoomFragment.java | 11 +- .../PublicScreenEaseChatFragment.java | 1 - .../fragment/RoomAuctionFragment.java | 13 - .../fragment/RoomCabinFragment.java | 4 - .../moduleroom/fragment/RoomKtvFragment.java | 5 - .../moduleroom/fragment/SingSongFragment.java | 1 - .../moduleroom/service/CancelNoticeService.kt | 43 + .../example/moduleroom/service/Extensions.kt | 63 + .../service/ForegroundNotification.kt | 89 + .../moduleroom/service/ForegroundService.kt | 49 + .../moduleroom/service/RoomPlayService.java | 85 + .../moduleroom/service/ServiceHelper.kt | 6 + modulevocal/build.gradle | 4 + ...bCloudFaceLiveSdk-face-v6.6.2-8e4718fc.aar | Bin 0 -> 3750579 bytes .../libs/WbCloudNormal-v5.1.10-4e3e198.aar | Bin 0 -> 927454 bytes modulevocal/src/main/AndroidManifest.xml | 6 +- .../modulevocal/activity/AboutUsActivity.java | 18 +- .../activity}/RealNameActivity.java | 19 +- .../activity/UnderageActivity.java | 12 +- .../activity/WithdrawalActivity.java | 7 +- .../main/res/layout/activity_real_name.xml | 2 +- modulevoice/build.gradle | 4 +- .../fragment/VoiceCategoryFragment.java | 8 +- 51 files changed, 3692 insertions(+), 2902 deletions(-) create mode 100644 moduleUtil/src/main/java/com/xscm/moduleutil/http/ApiResponseCallback.java create mode 100644 moduleUtil/src/main/java/com/xscm/moduleutil/http/BusinessAwareConverterFactory.java create mode 100644 moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/BaseViewModel.kt create mode 100644 moduleUtil/src/main/java/com/xscm/moduleutil/widget/room/PassRoomException.kt create mode 100644 moduleroom/src/main/java/com/example/moduleroom/service/CancelNoticeService.kt create mode 100644 moduleroom/src/main/java/com/example/moduleroom/service/Extensions.kt create mode 100644 moduleroom/src/main/java/com/example/moduleroom/service/ForegroundNotification.kt create mode 100644 moduleroom/src/main/java/com/example/moduleroom/service/ForegroundService.kt create mode 100644 moduleroom/src/main/java/com/example/moduleroom/service/RoomPlayService.java create mode 100644 moduleroom/src/main/java/com/example/moduleroom/service/ServiceHelper.kt create mode 100644 modulevocal/libs/WbCloudFaceLiveSdk-face-v6.6.2-8e4718fc.aar create mode 100644 modulevocal/libs/WbCloudNormal-v5.1.10-4e3e198.aar rename {app/src/main/java/com/xscm/midi => modulevocal/src/main/java/com/example/modulevocal/activity}/RealNameActivity.java (98%) rename {app => modulevocal}/src/main/res/layout/activity_real_name.xml (99%) 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 5a7e832..daafe6c 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) @@ -219,4 +227,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.kt b/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.kt index 0641a09..782c664 100644 --- a/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.kt +++ b/moduleroom/src/main/java/com/example/moduleroom/activity/RoomActivity.kt @@ -1,292 +1,268 @@ -package com.example.moduleroom.activity; +package com.example.moduleroom.activity -import static android.view.View.GONE; -import static android.view.View.INVISIBLE; -import static android.view.View.VISIBLE; +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 -import static com.liulishuo.okdownload.OkDownloadProvider.context; +@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 -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 var mRoomOwnerBean: RoomOwnerBean? = null + //房间用户信息 - private RoomUserBean mRoomUserBean; - private List mPitList = new ArrayList<>(); + private var mRoomUserBean: RoomUserBean? = null + private var mPitList: List = ArrayList() + + @JvmField @Autowired - public String password; + var password: String? = null + + @JvmField @Autowired - public String roomId; + var roomId: String? = null + + @JvmField @Autowired - public RoomInfoResp mRoomInfoResp; + var mRoomInfoResp: RoomInfoResp? = null + @JvmField @Autowired - public String taskId; + var taskId: String? = null - public static boolean sDestroied = false; - LikeUserAdapter likeUserAdapter; - String[] permissions = {Manifest.permission.RECORD_AUDIO}; - private boolean isSave = false;//活动是否将被系统回收 + var likeUserAdapter: LikeUserAdapter? = null + var permissions: Array = arrayOf(Manifest.permission.RECORD_AUDIO) + private var isSave = false //活动是否将被系统回收 - private IFxControl musicWindowControl; - private CustomMusicFloatingView customMusicFloatingView; - private int number = 0; + private var musicWindowControl: IFxControl? = null + private var customMusicFloatingView: CustomMusicFloatingView? = null + private var number = 0 - private Floa floatingMagnetView; - private FrameLayout fullScreenContainer; - private boolean isFullScreen = false; - private ImageView ivExitFullscreen; - ImageView ivQuan; - private boolean imYc; + 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 - public boolean isOnline; + var isOnline: Boolean = false + + private var silentCountDownTimer: SilentCountDownTimer? = null + private var circularProgress: CircularProgressView? = null + private var publicScreenFragment: PublicScreenEaseChatFragment? = null // 添加成员变量 - 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 var isLayoutAdjusted = false - 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; + // 存储当前显示的弹框引用 + private val activeDialogs: MutableList = ArrayList() + private val activeDialogFragments: MutableList = ArrayList() + + private var isMinimized = false + private var appStateListener: AppStateListener? = null // 添加弹框到管理列表 - public void addActiveDialog(DialogInterface dialog) { - activeDialogs.add(dialog); + fun addActiveDialog(dialog: DialogInterface) { + activeDialogs.add(dialog) } - public void addActiveDialogFragment(Fragment dialogFragment) { - activeDialogFragments.add(dialogFragment); + fun addActiveDialogFragment(dialogFragment: Fragment) { + 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); +// override fun onNewIntent(intent: Intent) { +// super.onNewIntent(intent) // -// // 如果需要更新主Fragment数据也一并更新 -// sharedViewModel.clearFragmentData(); -// sharedViewModel.setDataForFragment(newData); +// // 必须调用 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 void handleRestoreFromMinimize(Intent intent) { + private fun handleRestoreFromMinimize(intent: Intent) { // 如果是从桌面启动且之前有最小化的房间 // if (Intent.ACTION_MAIN.equals(intent.getAction()) // && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) { @@ -306,24 +282,25 @@ public class RoomActivity extends BaseMvpActivity(R.id.im_action_js) + val 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()); - } - }); + imActionJs.setOnClickListener { dialogEnd() } + imActionYs.setOnClickListener { + MvpPre!!.auctionDelay( + SpUtil.getauctionId() + ) + } } - } - public void upTop() { - mBinding.roomTop.stubButtons2.setVisibility(GONE); + fun upTop() { + mBinding!!.roomTop.stubButtons2.visibility = View.GONE } - private void dialogEnd() { + private fun dialogEnd() { // 创建并显示确认对话框 - new ConfirmDialog(this, - "提示", - "您确定要结束本次拍卖吗?", - "确认", - "取消", - v -> { - // 点击“确认”按钮时执行删除操作 - MvpPre.auctionEnd(SpUtil.getauctionId(), roomId); - }, - v -> { - // 点击“取消”按钮时什么都不做 - }, false, 0).show(); + ConfirmDialog( + this, + "提示", + "您确定要结束本次拍卖吗?", + "确认", + "取消", + { v: View? -> + // 点击“确认”按钮时执行删除操作 + MvpPre!!.auctionEnd(SpUtil.getauctionId(), roomId) + }, + { v: View? -> }, false, 0 + ).show() } - public void upVisibility(boolean visible) { - mBinding.roomTop.imActionJs.setVisibility(visible ? VISIBLE : INVISIBLE); - mBinding.roomTop.imActionYs.setVisibility(visible ? VISIBLE : INVISIBLE); + 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 } - public void upJs(boolean visible) { - mBinding.roomTop.imActionJs.setVisibility(visible ? VISIBLE : INVISIBLE); + fun upJs(visible: Boolean) { + mBinding!!.roomTop.imActionJs.visibility = + if (visible) View.VISIBLE else View.INVISIBLE } - public void upYs(boolean visible) { - mBinding.roomTop.imActionYs.setVisibility(visible ? VISIBLE : INVISIBLE); + fun upYs(visible: Boolean) { + mBinding!!.roomTop.imActionYs.visibility = + if (visible) View.VISIBLE else View.INVISIBLE } - /// 最小化 - private void showExitRoomDialog() { - ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance(); - bottomSheet.setOnOptionSelectedListener(new ExitRoomBottomSheet.OnOptionSelectedListener() { - @Override - public void onMinimize() { + /** 最小化 */ + 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();//栈顶复用 @@ -513,353 +481,243 @@ public class RoomActivity extends BaseMvpActivity(R.id.fl_screenshare) + // mBinding.flaoat.setVisibility(GONE);//展示或不展示 if (surfaceView == null) { - runOnUiThread(() -> { - mBinding.flaoat.setVisibility(GONE); - container.removeAllViews(); - }); + runOnUiThread { + mBinding!!.flaoat.visibility = View.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); - }); + runOnUiThread { + mBinding!!.flaoat.visibility = View.VISIBLE + container?.removeAllViews() + container?.addView(surfaceView.surfaceView) + } } } else { - floatingMagnetView.setVisibility(GONE); + floatingMagnetView?.setVisibility(View.GONE) } } } } @Subscribe(threadMode = ThreadMode.MAIN) - public void hideInput(RoomInputHideEvent event) { + fun hideInput(event: RoomInputHideEvent) { if (event.hide) { - mBinding.vpRoomPager.setScrollContainer(false); + mBinding!!.vpRoomPager.isScrollContainer = false } else { - mBinding.vpRoomPager.setScrollContainer(true); + mBinding!!.vpRoomPager.isScrollContainer = true } } @Subscribe(threadMode = ThreadMode.MAIN) - public void roomInfoEvent(ColoseCardEvent messageEvent) { - mBinding.flaoat.setVisibility(GONE); + fun roomInfoEvent(messageEvent: ColoseCardEvent?) { + mBinding!!.flaoat.visibility = View.GONE } /** * 释放当前房间 */ - private void releaseRoom() { - AgoraManager.getInstance(this).cleanup(); -// RtcManager.getInstance().leaveChannel(roomId); + 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(getApplicationContext()).destroyEffectSvga(); - cleanupResources(); -// MvpPre.quitRoom(roomId, SpUtil.getUserId() + ""); + CommonAppContext.getInstance().isPlaying = false + CommonAppContext.getInstance().isShow = false + QXGiftPlayerManager.getInstance(applicationContext).destroyEffectSvga() + cleanupResources() + // MvpPre.quitRoom(roomId, SpUtil.getUserId() + ""); } -// private SharedViewModel sharedViewModel; + // private SharedViewModel sharedViewModel; // 添加这个成员变量来跟踪房间数据是否已处理 -// private boolean isRoomDataProcessed = false; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { + // private boolean isRoomDataProcessed = false; + override fun onCreate(savedInstanceState: Bundle?) { // 在super.onCreate之前设置主题以避免闪白屏 - setTheme(com.xscm.moduleutil.R.style.BaseAppTheme); // 设置你的主主题 - super.onCreate(savedInstanceState); -// // 进入房间10s后检查是否显示提示上麦对话框 + setTheme(com.xscm.moduleutil.R.style.BaseAppTheme) // 设置你的主主题 + super.onCreate(savedInstanceState) + // // 进入房间10s后检查是否显示提示上麦对话框 + LogUtils.e("RoomActivity", "onCreate") -// 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) // 关闭转场动画 + startKeepLiveService() //保活 - // 初始化数据库 - - isSave = false; - sDestroied = false; - isMinimized = false; - overridePendingTransition(0, 0); // 关闭转场动画 + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + sActivityRef = WeakReference(this) - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); - sActivityRef = new WeakReference<>(this); - - -// MessageListenerSingleton.getInstance().joinGroup(roomId); // 检查是否有保存的最小化状态 - checkAndRestoreMinimizeState(); + 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(); + performNetworkRequestsAsync() + roomFragment = RoomFragment.newInstance() + supportFragmentManager + .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() { + if (onBackPressedDispatcher != null) { + onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { // 拦截返回键,显示退出对话框而不是直接退出 - showExitRoomDialog(); + showExitRoomDialog() } - }); + }) } // 获取Application实例并设置监听器 - CommonAppContext app = (CommonAppContext) getApplication(); - appStateListener = AppStateManager.getInstance(); - app.setAppStateListener(appStateListener); + val app = application as CommonAppContext + appStateListener = AppStateManager.getInstance() + app.setAppStateListener(appStateListener) // 通知RoomActivity已创建 if (appStateListener != null) { - appStateListener.onRoomActivityCreated(this); + appStateListener?.onRoomActivityCreated(this) } - // 获取 ViewModel -// sharedViewModel = new ViewModelProvider(this).get(SharedViewModel.class); // 处理房间数据 // handleRoomData(); - SpUtil.saveMyRoomId(roomId); + SpUtil.saveMyRoomId(roomId) // 检查是否从最小化状态恢复 if (isMinimized) { // 恢复房间状态 - resumeRoomState(); + 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 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 - 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!!.room_name - CommonAppContext.getInstance().isPlaying = true; - CommonAppContext.getInstance().playId = roomId; - CommonAppContext.getInstance().playName = mRoomBean.getRoom_name(); + CommonAppContext.getInstance().playCover = resp.room_info.room_cover + CommonAppContext.getInstance().showSelf = resp.is_show_self == 1 - 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); + 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.setVisibility(VISIBLE); - if (resp.isCollect()) { - mBinding.roomTop.btnFollow.setBackground(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.collected)); - mBinding.roomTop.btnFollow.setText(""); + 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.getOnline_number(); - mBinding.roomTop.tvNum.setText(number + ""); + number = roomBean.online_number + mBinding!!.roomTop.tvNum.text = number.toString() + "" - 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(","); + 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); + userIds.append(userId) } } - initPublicScreenFragment(); + initPublicScreenFragment() // 确保Fragment已完全初始化后再调用getUpRoomInfo - if (publicScreenFragment != null && publicScreenFragment.isAdded() && publicScreenFragment.getView() != null) { - publicScreenFragment.getUpRoomInfo(resp); + if (publicScreenFragment != null && publicScreenFragment!!.isAdded && publicScreenFragment!!.view != null) { + publicScreenFragment!!.getUpRoomInfo(resp) } - if (!isFinishing() && !isDestroyed()) { - resetFragment(); - upHeight(); + if (!isFinishing && !isDestroyed) { + resetFragment() + upHeight() } else { - Log.e("Fragment", "Fragment transaction skipped due to state loss."); + 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(""); + 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().getPrimaryColorInt(), 53); - mBinding.roomTop.btnFollow.setTextColor(ColorManager.getInstance().getButtonColorInt()); - mBinding.roomTop.btnFollow.setText("收藏"); + ThemeableDrawableUtils.setThemeableRoundedBackground( + mBinding!!.roomTop.btnFollow, + ColorManager.getInstance().primaryColorInt, + 53 + ) + mBinding!!.roomTop.btnFollow.setTextColor(ColorManager.getInstance().buttonColorInt) + mBinding!!.roomTop.btnFollow.text = "收藏" } - 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); + 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).setBjMusic(true); + AgoraManager.getInstance(this).isBjMusic = true } - AgoraManager.getInstance(this).stopMuisc(); - initializeAudio(); + AgoraManager.stopMuisc() + initializeAudio() - toutiao(); - upRoomInfo(resp); + toutiao() + upRoomInfo(resp) - if (userIds.length() > 0 && roomId != null) { + if (userIds.length > 0 && roomId != null) { // MvpPre.userOnlineStatus(userIds.toString(), roomId); } -// + + // // // 延迟调用getUpRoomInfo,确保Fragment视图已创建 // mBinding.getRoot().post(new Runnable() { // @Override @@ -869,387 +727,383 @@ public class RoomActivity extends BaseMvpActivity 30 * 60 * 1000) { // 清理过期的最小化状态 - clearMinimizeState(); - isMinimized = false; + clearMinimizeState() + isMinimized = false } } else { - isMinimized = false; + isMinimized = false } } /** * 在子线程中执行网络请求,避免阻塞主线程 */ - private void performNetworkRequestsAsync() { - ThreadUtils.executeByIo(new ThreadUtils.SimpleTask() { - @Override - public Void doInBackground() throws Throwable { + private fun performNetworkRequestsAsync() { + ThreadUtils.executeByIo(object : ThreadUtils.SimpleTask() { + @Throws(Throwable::class) + override fun doInBackground(): Void? { // 在后台线程执行网络请求前的准备工作 // 例如:检查缓存、预处理数据等 // prepareNetworkRequest(); - return null; + return null } - @Override - public void onSuccess(Void result) { - // 切换到主线程执行实际的网络请求 - runOnUiThread(() -> { + override fun onSuccess(result: Void?) { + runOnUiThread { // 使用Handler确保在主线程中调用 // MvpPre.getRoomIn(roomId, password); if (mRoomInfoResp == null) { // 使用Handler确保在主线程中调用 - MvpPre.getRoomIn(roomId, password); + MvpPre!!.getRoomIn(roomId, password) } - MvpPre.getRoomOnline(roomId, "1", "10"); - }); + MvpPre!!.getRoomOnline(roomId, "1", "10") + } } - @Override - public void onFail(Throwable e) { - LogUtils.e("Network request preparation failed: " + e.getMessage()); + + + override fun onFail(e: Throwable) { + LogUtils.e("Network request preparation failed: " + e.message) // 即使准备失败,也尝试执行网络请求 - runOnUiThread(() -> { -// MvpPre.getRoomIn(roomId, password); + runOnUiThread { + // MvpPre.getRoomIn(roomId, password); // 检查是否已经有房间信息,如果有则不需要再次获取 if (mRoomInfoResp == null) { - MvpPre.getRoomIn(roomId, password); + MvpPre!!.getRoomIn(roomId, password) } - MvpPre.getRoomOnline(roomId, "1", "10"); - }); + 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; + 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 - 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()); + 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(new Date())); + LogUtils.e("lxj", "开始时间:" + TimeUtils.date2String(Date())) if (taskId != null) { - if (taskId.equals("9")) { - MyRoomSingleton.getInstance().onEnterRoom(taskId); + if (taskId == "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"); - } - }); + circularProgress = mBinding!!.giftShowProgress + circularProgress!!.progress = 0 + mBinding!!.giftShowLayout.setOnClickListener { + 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(); + 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(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - // 将触摸事件透传给下层的 View - return false; // 返回 false,表示不拦截事件 - } - }); + mBinding!!.roomTop.rlTop.setOnTouchListener { v, event -> + // 将触摸事件透传给下层的 View + 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(); + 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(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"); - } + mBinding!!.xlhIm.setOnClickListener { + val fm = supportFragmentManager + if (fm != null && !fm.isDestroyed) { + val newDialog = TourClubDialogFragment.newInstance( + roomId + ) + newDialog.show(fm, "TourClubDialogFragment") } - }); + } } - private void onGiftGiveProgressClcik() { - if (giftGiveEvent == null || giftGiveEvent.roonGiftModel == null) { - return; + 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().getGift_id(), giftGiveEvent.getNum(), "1", new BaseObserver() { - @Override - public void onSubscribe(Disposable d) { + 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 - 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(); - } + 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().getGift_id(), giftGiveEvent.getNum(), giftGiveEvent.getUserId(), "1", giftGiveEvent.getPit(), giftGiveEvent.heart_id, new BaseObserver() { - @Override - public void onSubscribe(Disposable d) { + 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 - 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(); - } - }); + + 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 RoomGiftGiveEvent giftGiveEvent; + private var giftGiveEvent: RoomGiftGiveEvent? = null @Subscribe(threadMode = ThreadMode.MAIN) - public void roomGiveGiftEvent(RoomGiftGiveEvent event) { - if (isFinishing() || event == null || event.roonGiftModel == null) { - return; + fun roomGiveGiftEvent(event: RoomGiftGiveEvent?) { + if (isFinishing || event == null || event.roonGiftModel == null) { + return } - giftGiveEvent = event; - showGiftGiveProgress(); + giftGiveEvent = event + showGiftGiveProgress() } - private int giftProgress = 0; - private CountDownTimer giftCountTimer; + private var giftProgress = 0 + private var giftCountTimer: CountDownTimer? = null - private void startGiftProgressTime() { - giftProgress = 0; + private fun startGiftProgressTime() { + giftProgress = 0 if (giftCountTimer != null) { - giftCountTimer.cancel(); + 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)); + 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 - public void onFinish() { - circularProgress.setProgress(1000); - hideGiftGiveProgress(); + override fun onFinish() { + circularProgress!!.progress = 1000 + hideGiftGiveProgress() } - }; - giftCountTimer.start(); + } + 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 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 void hideGiftGiveProgress() { - mBinding.giftShowLayout.setVisibility(View.GONE); + private fun hideGiftGiveProgress() { + mBinding!!.giftShowLayout.visibility = View.GONE if (giftCountTimer != null) { - giftCountTimer.cancel(); - giftCountTimer = null; + giftCountTimer!!.cancel() + giftCountTimer = null } } - private void toggleFullScreen() { + private fun toggleFullScreen() { if (isFullScreen) { - exitFullScreen(); + exitFullScreen() } else { // enterFullScreen(); // 修改为横屏展示模式而不是全屏模式 - enterLandscapeMode(); + + enterLandscapeMode() } } - private void enterLandscapeMode() { - isFullScreen = true; + private fun enterLandscapeMode() { + isFullScreen = true // 设置横屏 - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + requestedOrientation = 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); + 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,创建新的 - 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); + 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的布局参数 - FrameLayout flScreenshare = floatingMagnetView.findViewById(R.id.fl_screenshare); - ViewGroup.LayoutParams screenParams = flScreenshare.getLayoutParams(); - if (!(screenParams instanceof FrameLayout.LayoutParams)) { + val flScreenshare = floatingMagnetView!!.findViewById(R.id.fl_screenshare) + val screenParams = flScreenshare.layoutParams + if (screenParams !is FrameLayout.LayoutParams) { // 如果不是FrameLayout.LayoutParams,创建新的 - FrameLayout.LayoutParams newScreenParams = new FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, - FrameLayout.LayoutParams.MATCH_PARENT - ); - flScreenshare.setLayoutParams(newScreenParams); + val newScreenParams = FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT + ) + flScreenshare.layoutParams = newScreenParams } else { - FrameLayout.LayoutParams newScreenParams = (FrameLayout.LayoutParams) screenParams; - newScreenParams.width = FrameLayout.LayoutParams.MATCH_PARENT; - newScreenParams.height = FrameLayout.LayoutParams.MATCH_PARENT; - flScreenshare.setLayoutParams(newScreenParams); + val newScreenParams = screenParams + newScreenParams.width = FrameLayout.LayoutParams.MATCH_PARENT + newScreenParams.height = FrameLayout.LayoutParams.MATCH_PARENT + flScreenshare.layoutParams = newScreenParams } // 显示退出按钮 - ivQuan.setVisibility(View.VISIBLE); + ivQuan!!.visibility = View.VISIBLE } } - private void enterFullScreen() { - isFullScreen = true; + private fun 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 - ); + 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) // 设置横屏 - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE // 找到 fl_screenshare 并移到全屏容器中 - FrameLayout fl_screenshare = findViewById(R.id.fl_screenshare); + val fl_screenshare = findViewById(R.id.fl_screenshare) if (fl_screenshare != null) { // // 先从当前父容器中移除 // ViewParent parent = fl_screenshare.getParent(); @@ -1260,47 +1114,46 @@ public class RoomActivity extends BaseMvpActivity(R.id.fl_screenshare) + val screenParams = FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT + ) + flScreenshare.layoutParams = screenParams } // 隐藏退出按钮 - ivExitFullscreen.setVisibility(View.GONE); + ivExitFullscreen!!.visibility = View.GONE -// isFullScreen = false; + // isFullScreen = false; // // 恢复系统UI // View decorView = getWindow().getDecorView(); //// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); @@ -1336,270 +1189,341 @@ public class RoomActivity extends BaseMvpActivity(); - 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()); + 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); // 添加到管理列表 + addActiveDialogFragment(fragment) // 添加到管理列表 } } - }); -// PublicScreenEaseChatFragment fragment = PublicScreenEaseChatFragment.newInstance(); + + // 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 + ) + } - - 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); + // SpUtil.saveMyRoomId(roomId); // MvpPre.getRoomIn(roomId, password); // MvpPre.getRoomOnline(roomId, "1", "10"); - mBinding.inputMenu1.performClick(); + 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); + 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() } - mBinding.ivMessageDot.setText(String.valueOf(aLong)); - } - @Override - public void onError(int code, String desc) { + override fun onError(code: Int, desc: String) { + } + }) - } - }); - - mBinding.roomTop.getRoot().setClickable(false); - mBinding.roomTop.getRoot().setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { -// ToastUtils.showShort("点击了房间,事件穿透"); - - } - }); -// if (mRoomInfoResp!=null){ + mBinding!!.roomTop.root.isClickable = false + mBinding!!.roomTop.root.setOnClickListener { + // ToastUtils.showShort("点击了房间,事件穿透"); + } + // if (mRoomInfoResp!=null){ // setview(mRoomInfoResp); // } } - private void initPublicScreenFragment() { + private fun initPublicScreenFragment() { // 检查是否已经存在 Fragment 实例(例如在配置更改后) - publicScreenFragment = (PublicScreenEaseChatFragment) getSupportFragmentManager() - .findFragmentById(R.id.ease_container); + publicScreenFragment = supportFragmentManager + .findFragmentById(R.id.ease_container) as PublicScreenEaseChatFragment? // 如果不存在,则创建新的实例 if (publicScreenFragment == null) { - publicScreenFragment = PublicScreenEaseChatFragment.newInstance(roomId); - getSupportFragmentManager().beginTransaction() - .replace(R.id.ease_container, publicScreenFragment) - .commitAllowingStateLoss(); + publicScreenFragment = PublicScreenEaseChatFragment.newInstance(roomId) + supportFragmentManager.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 = ""; + private val roomSwitchHandler = Handler(Looper.getMainLooper()) + private var roomSwitchRunnable: Runnable? = null + private var pendingRoomId: String? = null + private var lastSwitchedRoomId = "" - public void roomInfoEvent(RoomMessageEvent messageEvent) { - if (messageEvent == null) return; + fun roomInfoEvent(messageEvent: RoomMessageEvent?) { + if (messageEvent == null) return if (roomFragment == null) { - roomFragment = RoomFragment.newInstance(); - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.vp_room_pager, roomFragment) - .commitAllowingStateLoss(); + roomFragment = RoomFragment.newInstance() + supportFragmentManager + .beginTransaction() + .replace(R.id.vp_room_pager, roomFragment!!) + .commitAllowingStateLoss() } - int msgType = messageEvent.getMsgType(); - RoomMessageEvent.T text = messageEvent.getText(); + val msgType = messageEvent.msgType + val text = messageEvent.text 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); + 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); + hand1005(messageEvent, text) } else if (msgType == 123) { - EventBus.getDefault().post(new RoomSettingEvent()); + EventBus.getDefault().post(RoomSettingEvent()) } else if (msgType == 1014) { - handleMsgType1014(messageEvent, text); + handleMsgType1014(messageEvent, text) } else if (msgType == 1013) { - handleMsgType1013(messageEvent, text); + handleMsgType1013(messageEvent, text) } else if (msgType == 1012) { - handleMsgType1012(); + handleMsgType1012() } else if (msgType == 124) { - handleMsgType124(messageEvent, text); + handleMsgType124(messageEvent, text) } else if (msgType == 1003) { - handleMsgType1003(messageEvent, text); + handleMsgType1003(messageEvent, text) } else if (msgType == 1004) { - handleMsgType1004(messageEvent, text); + handleMsgType1004(messageEvent, text) } else if (msgType == 1022) { - handleMsgType1022(messageEvent, text); + handleMsgType1022(messageEvent, text) } else if (msgType == 1023) { - handleMsgType1023(messageEvent, text); + handleMsgType1023(messageEvent, text) } else if (msgType == 1024) { - handleMsgType1024(messageEvent, text); + handleMsgType1024(messageEvent, text) } else if (msgType == 1025) { - roomFragment.handleAuctionMessageEvent(messageEvent); + roomFragment!!.handleAuctionMessageEvent(messageEvent) } else if (msgType == 1026) { - roomFragment.handleAuctionMessageEvent(messageEvent); + roomFragment!!.handleAuctionMessageEvent(messageEvent) } else if (msgType == 1027) { - roomFragment.handleAuctionMessageEvent(messageEvent); + roomFragment!!.handleAuctionMessageEvent(messageEvent) } else if (msgType == 1020) { - handleMsgType1020(messageEvent, text); + handleMsgType1020(messageEvent, text) } else if (msgType == 1011) { - handleMsgType1011(messageEvent, text); + handleMsgType1011(messageEvent, text) } else if (msgType == 1001) { - handleMsgType1001(); + handleMsgType1001() } else if (msgType == 1002) { - handleMsgType1002(); + handleMsgType1002() } else if (msgType == 1029) { - handleMsgType1029(messageEvent, text); + handleMsgType1029(messageEvent, text) } else if (msgType == 1021) { - handleMsgType1021(messageEvent, text); + handleMsgType1021(messageEvent, text) } else if (msgType == 1036) { - handleMsgType1036(messageEvent, text); + handleMsgType1036(messageEvent, text) } else if (msgType == 1049) { - handleMsgType1049(messageEvent, text); + handleMsgType1049(messageEvent, text) } else if (msgType == 1050) { - handleMsgType1050(messageEvent, text); + handleMsgType1050(messageEvent, text) } else if (msgType == 1051) { - handleMsgType1051(messageEvent, text); + handleMsgType1051(messageEvent, text) } else if (msgType == 1052) { - roomFragment.upCabinFragment(text.getTime_day()); + roomFragment!!.upCabinFragment(text.time_day) } else if (msgType == 1053) { - handleMsgType1053(messageEvent, text); + handleMsgType1053(messageEvent, text) } else if (msgType == 1054) { - handleMsgType1054(messageEvent, text); + handleMsgType1054(messageEvent, text) } else if (msgType == 1055) { - handleMsgType1055(messageEvent); + handleMsgType1055(messageEvent) } else if (msgType == 1035) { - handleMsgType1035(messageEvent, text); + handleMsgType1035(messageEvent, text) } else if (msgType == 1030 || msgType == 1031 || msgType == 1032 || msgType == 1033 || msgType == 1015 || msgType == 1037) { - - roomFragment.SingSongEvent(messageEvent); + roomFragment!!.SingSongEvent(messageEvent) if (msgType == 1032 || msgType == 1033) { - setRoleType(3, -11); + setRoleType(3, -11) } } else if (msgType == 125) { - handleMsgType125(messageEvent, text); - }else if (msgType==1006){ - handleMsgType1006(); + handleMsgType125(messageEvent, text) + } else if (msgType == 1006) { + handleMsgType1006() } else if (msgType == 1007) { - handleMsgType1007(); - }else if (msgType == 1017){ - handleMsgType1017(); - } - else if (msgType == 1018) { - handleMsgType1018(); + handleMsgType1007() + } else if (msgType == 1017) { + handleMsgType1017() + } else if (msgType == 1018) { + handleMsgType1018() } else if (msgType == 126) { - handleMsgType126(messageEvent, text); + handleMsgType126(messageEvent, text) } else if (msgType == 1034) { - handleMsgType1034(messageEvent, text); + handleMsgType1034(messageEvent, text) } else if (msgType == 1016) { - handleMsgType1016(messageEvent, text); + handleMsgType1016(messageEvent, text) } else if (msgType == 1039) { - handleMsgType1039(messageEvent, text); + handleMsgType1039(messageEvent, text) } else if (msgType == 1028) { - roomFragment.handleMsgType1028(messageEvent); + 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); + 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); + 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 (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.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 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); + 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 (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 抽奖结果 - GiftLotteryDialog dialog = (GiftLotteryDialog) getSupportFragmentManager() - .findFragmentByTag("GiftLotteryDialog"); - if (dialog != null && dialog.isVisible()) { - dialog.UpView(messageEvent.getText().getXlh_data()); + } 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.getText().getXlh_data()); + EventBus.getDefault().post(messageEvent.text.xlh_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()); + 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.setVisibility(INVISIBLE); - releaseCountDownTimer1(); + mBinding!!.xlhRk.visibility = View.INVISIBLE + releaseCountDownTimer1() } } - } else if (msgType == 1057) { - TourClubDialogFragment existingFragment = (TourClubDialogFragment) getSupportFragmentManager().findFragmentByTag("TourClubDialogFragment"); - if (existingFragment != null && existingFragment.isVisible()) { - existingFragment.onMusicPlay(messageEvent); + val existingFragment = + supportFragmentManager.findFragmentByTag("TourClubDialogFragment") as TourClubDialogFragment? + if (existingFragment != null && existingFragment.isVisible) { + existingFragment.onMusicPlay(messageEvent) } else { - LogUtils.e("TourClubDialogFragment", "巡乐会界面未打开"); - EventBus.getDefault().post(messageEvent); + LogUtils.e("TourClubDialogFragment", "巡乐会界面未打开") + EventBus.getDefault().post(messageEvent) } - xlhDjs(messageEvent.getText().getEnd_time()); -// if (messageEvent.getText().getXlh_data() != null) { + 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()); @@ -1608,955 +1532,935 @@ public class RoomActivity extends BaseMvpActivity pitMap = new HashMap<>(); + private val pitMap: MutableMap = HashMap() - public void handleMsgType1039(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) { - return; + fun handleMsgType1039(messageEvent: RoomMessageEvent, text: T?) { + if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) { + return } - List pitList = mRoomInfoResp.getRoom_info().getPit_list(); + val pitList = mRoomInfoResp!!.room_info.pit_list if (pitList != null && !pitList.isEmpty()) { - pitMap.clear(); // 避免数据累积 - for (RoomPitBean roomPitBean : pitList) { - pitMap.put(roomPitBean.getPit_number(), roomPitBean); + pitMap.clear() // 避免数据累积 + for (roomPitBean in pitList) { + pitMap[roomPitBean.pit_number] = roomPitBean } if (text == null) { - return; + return } - String fromPitNumber = text.getFrom_pit_number(); - String toPitNumber = text.getTo_pit_number(); + val fromPitNumber = text.from_pit_number + val toPitNumber = text.to_pit_number if (!TextUtils.isEmpty(fromPitNumber) && !TextUtils.isEmpty(toPitNumber)) { - performSwitchMic(fromPitNumber, toPitNumber, messageEvent); + performSwitchMic(fromPitNumber, toPitNumber, messageEvent) } // 执行换麦逻辑 } - } - private void performSwitchMic(String fromPitNumber, String toPitNumber, RoomMessageEvent messageEvent) { + private fun performSwitchMic( + fromPitNumber: String, + toPitNumber: String, + messageEvent: RoomMessageEvent + ) { if (TextUtils.isEmpty(fromPitNumber) || TextUtils.isEmpty(toPitNumber)) { - return; + return } - if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) { - LogUtils.e("Room info is null"); - return; + if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) { + LogUtils.e("Room info is null") + return } - List pitList = mRoomInfoResp.getRoom_info().getPit_list(); + val pitList = mRoomInfoResp!!.room_info.pit_list if (pitList == null || pitList.isEmpty()) { - LogUtils.e("pit_list is null or empty"); - return; + LogUtils.e("pit_list is null or empty") + return } - RoomPitBean fromBean = null; - RoomPitBean toBean = null; - List pitListCopy = new ArrayList<>(); + var fromBean: RoomPitBean? = null + var toBean: RoomPitBean? = null + val pitListCopy: MutableList = 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); + 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; + 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); + val temp = fromBean.pit_number + fromBean.pit_number = toBean.pit_number + toBean.pit_number = temp // 构造新的 pitList - List newPitList = new ArrayList<>(); - for (RoomPitBean bean : pitList) { + val newPitList: MutableList = ArrayList() + for (bean in pitList) { if (!pitListCopy.contains(bean)) { - newPitList.add(bean); + newPitList.add(bean) } } - newPitList.add(fromBean); - newPitList.add(toBean); - - // 排序 - newPitList.sort((a, b) -> { + newPitList.add(fromBean) + newPitList.add(toBean) +// 排序 - 更简洁的 Kotlin 写法 + newPitList.sortWith(compareBy { 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()); + 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.getRoom_info().setPit_list(newPitList); + mRoomInfoResp!!.room_info.pit_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 (mRoomInfoResp!!.user_info != null) { + val currentUserId = SpUtil.getUserId().toString() + val fromUserId = fromBean.user_id + val toUserId = toBean.user_id - if (fromUserId != null && fromUserId.equals(currentUserId)) { + if (fromUserId != null && fromUserId == currentUserId) { try { - mRoomInfoResp.getUser_info().setPit_number(Integer.parseInt(fromBean.getPit_number())); - } catch (NumberFormatException e) { - LogUtils.e("Invalid pit number: " + toBean.getPit_number()); + 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.equals(currentUserId)) { + } else if (toUserId != null && toUserId == currentUserId) { try { - mRoomInfoResp.getUser_info().setPit_number(Integer.parseInt(fromBean.getPit_number())); - } catch (NumberFormatException e) { - LogUtils.e("Invalid pit number: " + toBean.getPit_number()); + mRoomInfoResp!!.user_info.pit_number = fromBean.pit_number.toInt() + } catch (e: NumberFormatException) { + LogUtils.e("Invalid pit number: " + toBean.pit_number) } } } - dispatchRoomEvent(messageEvent); + dispatchRoomEvent(messageEvent) } - private void dispatchRoomEvent(RoomMessageEvent messageEvent) { - if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return; + private fun dispatchRoomEvent(messageEvent: RoomMessageEvent) { + if (mRoomInfoResp == null || mRoomInfoResp!!.room_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); + 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".equals(typeId)) { - roomFragment.friendshipRoomFragmentEvent(messageEvent); + } else if ("7" == typeId) { + roomFragment!!.friendshipRoomFragmentEvent(messageEvent) } - if (mRoomInfoResp.getUser_info().getPit_number() == 9) { - mBinding.roomTop.rl.setVisibility(View.VISIBLE); - ivSoundEffects(true); + 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 - 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; + 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); - - 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; + // 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".equals(typeId)) {//交友房 - roomFragment.friendshipRoomFragmentEvent(messageEvent); - return; + } else if ("7" == typeId) { //交友房 + roomFragment!!.friendshipRoomFragmentEvent(messageEvent) + return } } + private fun handleMsgType1014(messageEvent: RoomMessageEvent, text: T?) { + if (text == null) 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()); + 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.setRoom_up_pit_type(text.getRoom_up_pit_type() + ""); - EventBus.getDefault().post(mRoomBean); + mRoomBean!!.room_up_pit_type = text.room_up_pit_type.toString() + "" + EventBus.getDefault().post(mRoomBean) } - EventBus.getDefault().post(roomSettingEvent); + EventBus.getDefault().post(roomSettingEvent) } - private void handleMsgType1013(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || mRoomUserBean == null) return; + private fun handleMsgType1013(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomUserBean == null) return - int userId2 = SpUtil.getUserId(); + val 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()); + 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); + roomFragment!!.KtvFragmentEvent(messageEvent) } } - private void handleMsgType1012() { + private fun handleMsgType1012() { if (customMusicFloatingView != null) { - customMusicFloatingView.destroy(); + customMusicFloatingView!!.destroy() } - AgoraManager.getInstance(RoomActivity.this).desMusic(); -// stub.setVisibility(View.GONE); + AgoraManager.getInstance(this@RoomActivity).desMusic() - 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); + // 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.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); + 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); + MvpPre!!.postRoomInfo(roomId) } - private void handleMsgType124(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType124(messageEvent: RoomMessageEvent, text: T?) { + 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) { + 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 void handleMsgType1003(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return; + private fun handleMsgType1003(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return if (roomFragment == null) { - roomFragment = RoomFragment.newInstance(); - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.vp_room_pager, roomFragment) - .commitAllowingStateLoss(); + roomFragment = RoomFragment.newInstance() + supportFragmentManager + .beginTransaction() + .replace(R.id.vp_room_pager, roomFragment!!) + .commitAllowingStateLoss() } - UserInfo fromUserInfo = text.getFromUserInfo(); - if (fromUserInfo == null) return; + val fromUserInfo = text.fromUserInfo ?: return - String pitNumber = text.getPit_number(); - int userId = fromUserInfo.getUser_id(); - int currentUserId = SpUtil.getUserId(); + val pitNumber = text.pit_number + val userId = fromUserInfo.user_id + val currentUserId = SpUtil.getUserId() - if ("9".equals(pitNumber) && userId == currentUserId) { - mBinding.roomTop.rl.setVisibility(View.VISIBLE); - ivSoundEffects(true); + 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.getUser_info() != null) { - mRoomInfoResp.getUser_info().setPit_number(pitNumber != null ? Integer.parseInt(pitNumber) : -1); + 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, Integer.parseInt(pitNumber)); - switchMic(2); + setRoleType(3, pitNumber!!.toInt()) + 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)); + 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".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); - + 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".equals(typeId)) { - mBinding.rlMore.setVisibility(GONE); - mBinding.rlMisc.setVisibility(GONE); + } else if ("7" == typeId) { + mBinding!!.rlMore.visibility = View.GONE + mBinding!!.rlMisc.visibility = View.GONE - roomFragment.friendshipRoomFragmentEvent(messageEvent); + roomFragment!!.friendshipRoomFragmentEvent(messageEvent) } else { - roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp); + roomFragment!!.updateSeatViewExchangedWithPitArray(mRoomInfoResp) } -// if (pitNumber.equals("9") && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId()+"")) { + // 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; + private fun handleMsgType1004(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return - UserInfo fromUserInfo = text.getFromUserInfo(); - if (fromUserInfo == null) return; + val fromUserInfo = text.fromUserInfo ?: return - String pitNumber = text.getPit_number(); - int userId = fromUserInfo.getUser_id(); - int currentUserId = SpUtil.getUserId(); + 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.getUser_info() != null) { - mRoomInfoResp.getUser_info().setPit_number(0); + 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); + setRoleType(0, 0) + switchMic(2) } - if (pitNumber.equals("9")) { - ivSoundEffects(false); + if (pitNumber == "9") { + ivSoundEffects(false) } - if (userId == currentUserId && "9".equals(pitNumber)) { + if (userId == currentUserId && "9" == pitNumber) { if (customMusicFloatingView != null) { - customMusicFloatingView.destroy(); - AgoraManager.getInstance(RoomActivity.this).desMusic(); - isMusic = false; + customMusicFloatingView!!.destroy() + AgoraManager.getInstance(this@RoomActivity).desMusic() + isMusic = false } - mBinding.roomTop.rl.setVisibility(GONE); - ivSoundEffects(false); + mBinding!!.roomTop.rl.visibility = View.GONE + ivSoundEffects(false) } - String typeId = mRoomInfoResp.getRoom_info().getType_id(); - if ("2".equals(typeId)) { - if ("9".equals(pitNumber)) { + val typeId = mRoomInfoResp!!.room_info.type_id + if ("2" == typeId) { + if ("9" == 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); + mRoomInfoResp!!.room_info.pit_list[0] = getPitBean2(messageEvent, "9") + if (mRoomInfoResp!!.user_info != null) { + mRoomInfoResp!!.user_info.pit_number = 0 } } - } else if ("888".equals(pitNumber)) { - mRoomInfoResp.setRoom_auction(null); + } else if ("888" == pitNumber) { + mRoomInfoResp!!.room_auction = null if (userId == currentUserId) { - setRoleType(0, 0); - switchMic(2); + 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); + 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); + roomFragment!!.friendshipRoomFragmentEvent(messageEvent) } } - private void handleMsgType1022(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return; + private fun handleMsgType1022(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return - String pitNumber = text.getPit_number(); - int userId = text.getFromUserInfo().getUser_id(); - int currentUserId = SpUtil.getUserId(); + val pitNumber = text.pit_number + val userId = text.fromUserInfo.user_id + val 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 (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); + 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()); + } 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); + setRoleType(0, 0) + switchMic(2) } } } - roomFragment.upRoomInfoData(mRoomInfoResp); - roomFragment.handleAuctionMessageEvent(messageEvent); + roomFragment!!.upRoomInfoData(mRoomInfoResp) + roomFragment!!.handleAuctionMessageEvent(messageEvent) } - private void handleMsgType1023(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_auction() == null) - return; + private fun handleMsgType1023(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_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); + 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 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(); + 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.getRoom_auction().getAuction_list() != null) { - mRoomInfoResp.getRoom_auction().getAuction_list().addAll(text.getAuction_list()); + if (mRoomInfoResp!!.room_auction.auction_list != null) { + mRoomInfoResp!!.room_auction.auction_list.addAll(text.auction_list) } else { - mRoomInfoResp.getRoom_auction().setAuction_list(new ArrayList<>()); -// mRoomInfoResp.getRoom_auction().getAuction_list().addAll(text.getAuction_list()); + mRoomInfoResp!!.room_auction.auction_list = ArrayList() + // mRoomInfoResp.getRoom_auction().getAuction_list().addAll(text.getAuction_list()); } - roomFragment.upRoomInfoData(mRoomInfoResp); - roomFragment.handleAuctionMessageEvent(messageEvent); -// roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp); + roomFragment!!.upRoomInfoData(mRoomInfoResp) + roomFragment!!.handleAuctionMessageEvent(messageEvent) + // roomFragment.updateSeatViewExchangedWithPitArray(mRoomInfoResp); } - private void handleMsgType1020(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType1020(messageEvent: RoomMessageEvent, text: T?) { + if (text == null) return - mRoomBean = text.getRoomInfo(); - EventBus.getDefault().post(mRoomBean); - changeBackgroundColor(mRoomBean.getRoom_background()); + mRoomBean = text.roomInfo + EventBus.getDefault().post(mRoomBean) + changeBackgroundColor(mRoomBean?.getRoom_background()) } - private void handleMsgType1011(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || text.getFromUserInfo() == null) return; + private fun handleMsgType1011(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || text.fromUserInfo == null) return - if (text.getFromUserInfo().getUser_id() == SpUtil.getUserId()) { - MvpPre.quitRoom(roomId, SpUtil.getUserId() + ""); + if (text.fromUserInfo.user_id == SpUtil.getUserId()) { + MvpPre!!.quitRoom(roomId, SpUtil.getUserId().toString() + "") } } - private void handleMsgType1001() { - number++; - mBinding.roomTop.tvNum.setText(number + ""); + private fun handleMsgType1001() { + number++ + mBinding!!.roomTop.tvNum.text = number.toString() + "" } - private void handleMsgType1002() { - number--; - if (number<0){ - number=0; + private fun handleMsgType1002() { + number-- + if (number < 0) { + number = 0 } - mBinding.roomTop.tvNum.setText(number + ""); + mBinding!!.roomTop.tvNum.text = number.toString() + "" } - private void handleMsgType1029(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || mRoomInfoResp == null || mRoomInfoResp.getUser_info() == null) return; + private fun handleMsgType1029(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.user_info == null) return - if (mRoomInfoResp.getUser_info().getPit_number() == 9 && mRoomInfoResp.getUser_info().getUser_id().equals(SpUtil.getUserId() + "")) { - querenPk(text.getText(), text.getPkId()); + if (mRoomInfoResp!!.user_info.pit_number == 9 && mRoomInfoResp!!.user_info.user_id == SpUtil.getUserId() + .toString() + "" + ) { + querenPk(text.text, text.pkId) } } - private void handleMsgType1021(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return; + private fun handleMsgType1021(messageEvent: RoomMessageEvent, text: T) { + if (mRoomInfoResp == null || mRoomInfoResp!!.room_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); + 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); + updateCharmForAllPitBeans("") + roomFragment!!.upRoomInfoData(mRoomInfoResp) + roomFragment!!.SingSongEvent(messageEvent) } } else { - updateCharmForAllPitBeans(""); - roomFragment.upFriendList(mRoomInfoResp.getRoom_info().getPit_list()); + updateCharmForAllPitBeans("") + roomFragment!!.upFriendList(mRoomInfoResp!!.room_info.pit_list) } - - } - private void updateCharmForAllPitBeans(String charm) { - if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return; + private fun updateCharmForAllPitBeans(charm: String) { + if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return - List pitList = mRoomInfoResp.getRoom_info().getPit_list(); - if (pitList == null) return; + val pitList = mRoomInfoResp!!.room_info.pit_list ?: return - for (RoomPitBean roomPitBean : pitList) { - roomPitBean.setCharm(charm); + for (roomPitBean in pitList) { + roomPitBean.charm = charm try { - pitList.set(Integer.parseInt(roomPitBean.getPit_number()) - 1, roomPitBean); - } catch (NumberFormatException e) { + pitList[roomPitBean.pit_number.toInt() - 1] = roomPitBean + } catch (e: NumberFormatException) { // Handle exception } } } - private void handleMsgType1036(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType1036(messageEvent: RoomMessageEvent, text: T?) { + 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); + if (text.room_id == roomId) { + val onlineNumber = text.online_number.toString() + "" + if (mBinding!!.roomTop.tvNum.text.toString() != onlineNumber) { + mBinding!!.roomTop.tvNum.text = onlineNumber } } } - private void handleMsgType1049(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType1049(messageEvent: RoomMessageEvent, text: T?) { + 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); + 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.getStep(), text.getFriend_id(), 0, text.getFriend_user()); + roomFragment!!.updateFriendshipState(text.step, text.friend_id, 0, text.friend_user) } } - private void handleMsgType1050(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType1050(messageEvent: RoomMessageEvent, text: T?) { + if (text == null) return - roomFragment.friendTimeDelayWithTime(Long.parseLong(text.getEnd_time())); + roomFragment!!.friendTimeDelayWithTime(text.end_time.toLong()) } - private void handleMsgType1051(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType1051(messageEvent: RoomMessageEvent, text: T?) { + if (text == null) return - if (text.getUser1_id() == null || text.getUser2_id() == null) { - return; + if (text.user1_id == null || text.user2_id == null) { + return } if (roomFragment != null) { - roomFragment.clearDialog(); + roomFragment!!.clearDialog() } - FriendUserBean friend_user = getFriendUserBean(messageEvent); - FriendsDialogFragment.show(friend_user, getSupportFragmentManager()); + val friend_user = getFriendUserBean(messageEvent) + FriendsDialogFragment.show(friend_user, supportFragmentManager) - if (text.getUser1_id().equals(SpUtil.getUserId() + "") || text.getUser2_id().equals(SpUtil.getUserId() + "")) { + if (text.user1_id == SpUtil.getUserId() + .toString() + "" || text.user2_id == SpUtil.getUserId().toString() + "" + ) { if (roomSwitchRunnable != null) { - roomSwitchHandler.removeCallbacks(roomSwitchRunnable); + roomSwitchHandler.removeCallbacks(roomSwitchRunnable!!) } - pendingRoomId = text.getRoom_id(); + pendingRoomId = text.room_id if (pendingRoomId == null) { - return; + 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()); + 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; - }; + pendingRoomId = null + } - roomSwitchHandler.postDelayed(roomSwitchRunnable, 3000); + roomSwitchHandler.postDelayed(roomSwitchRunnable!!, 3000) } } //退出房间 - public void quitRoomAll(String roomId) { - MvpPre.quitRoom(roomId, SpUtil.getUserId() + ""); + fun quitRoomAll(roomId: String?) { + MvpPre!!.quitRoom(roomId, SpUtil.getUserId().toString() + "") } - 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); + 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(); + roomFragment!!.friendSeatDidChanged(pitArr) + pitArr.clear() } - private void handleMsgType1054(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || text.getList() == null) return; + private fun handleMsgType1054(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || text.list == 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()); + 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); + roomFragment!!.friendHeartNumberDidChanged(heartList) } - private void handleMsgType1055(RoomMessageEvent messageEvent) { - if (!isFinishing() && !isDestroyed()) { - MvpPre.quitRoom2(messageEvent.getRoomId(), SpUtil.getUserId() + ""); - quit(); - jiaR(); + private fun handleMsgType1055(messageEvent: RoomMessageEvent) { + if (!isFinishing && !isDestroyed) { + MvpPre!!.quitRoom2(messageEvent.roomId, SpUtil.getUserId().toString() + "") + quit() + jiaR() } } - private void handleMsgType1035(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null || mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return; + private fun handleMsgType1035(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return - UserInfo fromUserInfo = text.getFromUserInfo(); - if (fromUserInfo == null) return; + val fromUserInfo = text.fromUserInfo ?: 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); + 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); + roomFragment!!.upRoomInfoData(updatePitBeanForUser(fromUserInfo)) + roomFragment!!.SingSongEvent(messageEvent) } } else { - roomFragment.upRoomInfoData(updatePitBeanForUser(fromUserInfo)); - roomFragment.friendshipRoomFragmentEvent(messageEvent); + roomFragment!!.upRoomInfoData(updatePitBeanForUser(fromUserInfo)) + roomFragment!!.friendshipRoomFragmentEvent(messageEvent) } - - } - private RoomInfoResp updatePitBeanForUser(UserInfo fromUserInfo) { - if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return mRoomInfoResp; + private fun updatePitBeanForUser(fromUserInfo: UserInfo): RoomInfoResp? { + if (mRoomInfoResp == null || mRoomInfoResp!!.room_info == null) return mRoomInfoResp - List pitList = mRoomInfoResp.getRoom_info().getPit_list(); - if (pitList == null) return mRoomInfoResp; + val pitList = mRoomInfoResp!!.room_info.pit_list ?: 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()); + 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; + return mRoomInfoResp } - private void handleMsgType125(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType125(messageEvent: RoomMessageEvent, text: T?) { + 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()); + 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()); + AgoraManager.getInstance(this).ClientRole(true) + AgoraManager.getInstance(this).muteLocalAudioStreamEx(true, SpUtil.getUserId()) } - } catch (Exception e) { + } catch (e: Exception) { // 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 fun handleMsgType1007() { + if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) { + mRoomInfoResp!!.user_info.is_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 fun handleMsgType1006() { + if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) { + mRoomInfoResp!!.user_info.is_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 fun handleMsgType1018() { + if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) { + mRoomInfoResp!!.user_info.is_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 fun handleMsgType1017() { + if (mRoomInfoResp != null && mRoomInfoResp!!.user_info != null) { + mRoomInfoResp!!.user_info.is_management = 0 + roomFragment!!.upRoomInfoData(mRoomInfoResp) } } - private void handleMsgType126(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType126(messageEvent: RoomMessageEvent, text: T?) { + if (text == null) return - AgoraManager.getInstance(this).setLocalAudioEnabled(false, text.getFromUserInfo().getUser_id() + ""); + AgoraManager.getInstance(this) + .setLocalAudioEnabled(false, text.fromUserInfo.user_id.toString() + "") } - private void handleMsgType1034(RoomMessageEvent messageEvent, RoomMessageEvent.T text) { - if (text == null) return; + private fun handleMsgType1034(messageEvent: RoomMessageEvent, text: T?) { + if (text == null) return - int count = text.getCount(); + val count = text.count if (count == 0) { - tvFirst(new SpannableStringBuilder("0人排队")); - return; + tvFirst(SpannableStringBuilder("0人排队")) + return } - String countText = String.valueOf(count); - String fullText = countText + "人排队"; + val countText = count.toString() + val fullText = countText + "人排队" - SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(fullText); + val spannableStringBuilder = 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); + 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; + private fun handleMsgType1016(messageEvent: RoomMessageEvent, text: T?) { + if (text == null || mRoomInfoResp == null || mRoomInfoResp!!.user_info == null) return - if (text.getFromUserInfo().getUser_id() == SpUtil.getUserId()) { - if (text.getIs_mute_pit() == 1) { - switchMic(2); + if (text.fromUserInfo.user_id == SpUtil.getUserId()) { + if (text.is_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())); + 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 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()); + 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; + 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; + 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 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()); + 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; + return roomAuction } - public void mus() { - if (mRoomInfoResp.getUser_info().getIs_mute().equals("1")) { - com.hjq.toast.ToastUtils.show("您已经被禁言"); + fun mus() { + if (mRoomInfoResp!!.user_info.is_mute == "1") { + ToastUtils.show("您已经被禁言") } else { - switchMic(1); + switchMic(1) } } @Subscribe(threadMode = ThreadMode.MAIN) - public void onMessageEvent(UnreadCountEvent messageEvent) { - if (messageEvent.getALong() == 0) { - mBinding.ivMessageDot.setVisibility(View.GONE); + fun onMessageEvent(messageEvent: UnreadCountEvent) { + if (messageEvent.aLong == 0L) { + mBinding!!.ivMessageDot.visibility = View.GONE } else { - mBinding.ivMessageDot.setVisibility(View.VISIBLE); - mBinding.ivMessageDot.setText(String.valueOf(messageEvent.getALong())); + mBinding!!.ivMessageDot.visibility = View.VISIBLE + mBinding!!.ivMessageDot.text = messageEvent.aLong.toString() } - } - @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) { + private fun querenPk(text: String, pk_id: String) { // 创建并显示确认对话框 - ConfirmDialog dialog = new ConfirmDialog(this, - "温馨提示", - text, - "确认", - "拒绝", - v -> { - // 点击“确认”按钮时执行删除操作 - MvpPre.acceptPk(pk_id, "1"); - }, - v -> { - MvpPre.acceptPk(pk_id, "2"); - // 点击“取消”按钮时什么都不做 - }, true, 10); - dialog.show(); - addActiveDialog(dialog); + 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) } /** @@ -2564,41 +2468,41 @@ public class RoomActivity extends BaseMvpActivity appProcesses = activityManager.getRunningAppProcesses(); - if (appProcesses == null) { - return false; + 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 - final String packageName = getPackageName(); - for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { - if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND - && appProcess.processName.equals(packageName)) { - return true; + val packageName = packageName + for (appProcess in appProcesses) { + if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND + && appProcess.processName == packageName + ) { + return true + } } + } else { + return true } - } else { - return true; + return false } - return false; - } - private void navigateToMainPage() { + private fun navigateToMainPage() { ARouter.getInstance() - .build(ARouteConstants.ME) - .navigation(); + .build(ARouteConstants.ME) + .navigation() // 添加转场动画 - overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out) } - private void quitUpRoom() { + private fun quitUpRoom() { // 清理最小化状态 - clearMinimizeState(); - isMinimized = false; + clearMinimizeState() + isMinimized = false // 执行退出房间逻辑 - CommonAppContext.getInstance().isPlaying = false; - CommonAppContext.getInstance().isShow = false; - QXGiftPlayerManager.getInstance(this).destroyEffectSvga(); + 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(); + AgoraManager.getInstance(this).leaveRoom() + // AgoraManager.getInstance(this).stopMusicPlayer(); + AgoraManager.getInstance(this).cleanup() - MyRoomSingleton.getInstance().onExitRoom(); - MessageListenerSingleton.getInstance().quitGroup(roomId); - cleanupResources(); + MyRoomSingleton.getInstance().onExitRoom() + MessageListenerSingleton.quitGroup(roomId) + cleanupResources() } - private void minimizeToBackground() { - isMinimized = true; + private fun minimizeToBackground() { + isMinimized = true // 保存最小化状态和房间ID - saveMinimizeState(); + saveMinimizeState() // 设置应用状态 - CommonAppContext.getInstance().isShow = false; + CommonAppContext.getInstance().isShow = false // 通知状态管理器RoomActivity已最小化 if (appStateListener != null) { - appStateListener.setAppInBackground(true); + appStateListener!!.isAppInBackground = true } - QXGiftPlayerManager.getInstance(getApplicationContext()).destroyEffectSvga(); -// ARouter.getInstance().build(ARouteConstants.ME) + 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 { - 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); - } +// 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); @@ -2885,45 +2816,45 @@ public class RoomActivity extends BaseMvpActivity { - // 点击“确认”按钮时执行删除操作 - MvpPre.applySong(roomId); - }, - v -> { - // 点击“取消”按钮时什么都不做 - }, false, 0); - dialog.show(); - addActiveDialog(dialog); + val dialog = ConfirmDialog( + this, + "提示", + "您将要发起点歌申请?", + "确认", + "取消", + { v: View? -> + // 点击“确认”按钮时执行删除操作 + MvpPre!!.applySong(roomId) + }, + { v: View? -> }, false, 0 + ) + dialog.show() + addActiveDialog(dialog) } /** @@ -2932,578 +2863,612 @@ public class RoomActivity extends BaseMvpActivity { + 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.setVisibility(GONE); + rl_misc.visibility = View.GONE if (userPitNumber == 9) { - rl_more.setVisibility(GONE); + rl_more.visibility = View.GONE } } // label_id 和 type_id 联合判断 - if (Arrays.asList("1", "3", "4", "8").contains(typeId) && "2".equals(labelId)) { - rl_more.setVisibility(View.GONE); + if (mutableListOf("1", "3", "4", "8").contains(typeId) && "2" == labelId) { + rl_more.visibility = View.GONE } // mic 显示逻辑 if (userPitNumber > 0) { - rl_mic.setVisibility(View.VISIBLE); - switchMic(2); + rl_mic.visibility = View.VISIBLE + switchMic(2) } else { if (pit_number == 888) { - rl_mic.setVisibility(View.VISIBLE); - switchMic(2); + rl_mic.visibility = View.VISIBLE + switchMic(2) } else if (pit_number == -1) { - rl_mic.setVisibility(View.VISIBLE); // 原代码此处缺少 View. 前缀,已补全 - switchMic(1); + rl_mic.visibility = View.VISIBLE // 原代码此处缺少 View. 前缀,已补全 + switchMic(1) } else { - rl_mic.setVisibility(View.GONE); - switchMic(2); + rl_mic.visibility = View.GONE + switchMic(2) } } - if ("7".equals(typeId) || "2".equals(typeId)) { - rl_more.setVisibility(View.GONE); - rl_misc.setVisibility(View.GONE); + if ("7" == typeId || "2" == typeId) { + rl_more.visibility = View.GONE + rl_misc.visibility = 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); + 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[] - byte[] binaryData = json.getBytes(StandardCharsets.UTF_8); + val binaryData = json.toByteArray(StandardCharsets.UTF_8) // 创建自定义消息 MessageListenerSingleton.getInstance().sendCustomRoomMessage( - roomId + "", - binaryData - ); + 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; + 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; + mBinding!!.ivWheatFeeding.setImageResource(com.xscm.moduleutil.R.mipmap.room_wheat_feeding) + aBoolean = true } } } @SuppressLint("MissingInflatedId") - public void dialogDismiss() { + fun dialogDismiss() { + // // 使用 AlertDialog.Builder -// // 使用 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); + 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