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(); String contentStr = broadcastMessage.getContent();
Logger.i(ResUtil.getString(R.string.avroom_activity_avroomactivity_014) + contentStr); Logger.i(ResUtil.getString(R.string.avroom_activity_avroomactivity_014) + contentStr);
if (TextUtils.isEmpty(contentStr)) return; if (TextUtils.isEmpty(contentStr)) return;
AVRoomActivity activity = mReference.get(); try {
if (activity == null) return; AVRoomActivity activity = mReference.get();
if (activity.isValid()) { if (activity == null) return;
JSONObject jsonObject; if (activity.isValid()) {
try { JSONObject jsonObject;
jsonObject = JSON.parseObject(contentStr); try {
} catch (Exception e) { jsonObject = JSON.parseObject(contentStr);
jsonObject = null; } catch (Exception e) {
} jsonObject = null;
if (jsonObject == null) return; }
if (jsonObject.containsKey("body")) { if (jsonObject == null) return;
String body = jsonObject.getString("body"); if (jsonObject.containsKey("body")) {
if (TextUtils.isEmpty(body)) return; String body = jsonObject.getString("body");
activity.onReceivedGiftBroadcastMessage(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; JSONObject jsonObject;
try { try {
jsonObject = JSON.parseObject(contentStr); 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) { } catch (Exception e) {
jsonObject = null; jsonObject = null;
} e.printStackTrace();
if (jsonObject == null) return;
if (jsonObject.containsKey("body")) {
String body = jsonObject.getString("body");
if (TextUtils.isEmpty(body)) return;
baseMvpActivity.onReceivedNimBroadcastMessage(body);
} }
} }
} }

View File

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