fix:修复通用公屏异常(FastJson解析DataClass问题)

feat:增加trycatch避免直接崩溃
This commit is contained in:
Max
2024-03-25 14:52:02 +08:00
parent ed6e247de7
commit 9d8118e331
3 changed files with 46 additions and 41 deletions

View File

@@ -1461,21 +1461,25 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
String contentStr = broadcastMessage.getContent();
Logger.i(ResUtil.getString(R.string.avroom_activity_avroomactivity_014) + contentStr);
if (TextUtils.isEmpty(contentStr)) return;
AVRoomActivity activity = mReference.get();
if (activity == null) return;
if (activity.isValid()) {
JSONObject jsonObject;
try {
jsonObject = JSON.parseObject(contentStr);
} catch (Exception e) {
jsonObject = null;
}
if (jsonObject == null) return;
if (jsonObject.containsKey("body")) {
String body = jsonObject.getString("body");
if (TextUtils.isEmpty(body)) return;
activity.onReceivedGiftBroadcastMessage(body);
try {
AVRoomActivity activity = mReference.get();
if (activity == null) return;
if (activity.isValid()) {
JSONObject jsonObject;
try {
jsonObject = JSON.parseObject(contentStr);
} catch (Exception e) {
jsonObject = null;
}
if (jsonObject == null) return;
if (jsonObject.containsKey("body")) {
String body = jsonObject.getString("body");
if (TextUtils.isEmpty(body)) return;
activity.onReceivedGiftBroadcastMessage(body);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1503,14 +1503,15 @@ public abstract class BaseActivity extends RxAppCompatActivity
JSONObject jsonObject;
try {
jsonObject = JSON.parseObject(contentStr);
if (jsonObject == null) return;
if (jsonObject.containsKey("body")) {
String body = jsonObject.getString("body");
if (TextUtils.isEmpty(body)) return;
baseMvpActivity.onReceivedNimBroadcastMessage(body);
}
} catch (Exception e) {
jsonObject = null;
}
if (jsonObject == null) return;
if (jsonObject.containsKey("body")) {
String body = jsonObject.getString("body");
if (TextUtils.isEmpty(body)) return;
baseMvpActivity.onReceivedNimBroadcastMessage(body);
e.printStackTrace();
}
}
}

View File

@@ -73,29 +73,29 @@ open class TemplateMessage : Serializable {
return list
}
data class Content(
/**
* 公共字段
*/
val key: String? = null,
// TEXT,IMAGE
val type: String? = null,
val skipType: Int? = null,
val skipContent: String? = null,
class Content : Serializable, IRouterData {
/**
* 公共字段
*/
val key: String? = null
/**
* 文本相关字段(type=TEXT)
*/
val text: I18N? = null,
var textColor: String? = null,
// TEXT,IMAGE
val type: String? = null
val skipType: Int? = null
val skipContent: String? = null
/**
* 图片相关字段(type=IMAGE)
*/
val image: String? = null,
val width: Int? = null,
val height: Int? = null
) : Serializable, IRouterData {
/**
* 文本相关字段(type=TEXT)
*/
val text: I18N? = null
var textColor: String? = null
/**
* 图片相关字段(type=IMAGE)
*/
val image: String? = null
val width: Int? = null
val height: Int? = null
override fun getSkipType(): Int {
return skipType ?: 0