Merge branch 'branch_new_dev' into branch_new

This commit is contained in:
2025-12-02 11:42:12 +08:00
6 changed files with 98 additions and 72 deletions

View File

@@ -449,9 +449,9 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
// startService(mqttServiceIntent); // startService(mqttServiceIntent);
// } // }
mqttConnect=MqttConnect.getInstance(this, currentEnvironment.getMqttUrl(),"android-"+ MqttClient.generateClientId()); // mqttConnect=MqttConnect.getInstance(this, currentEnvironment.getMqttUrl(),"android-"+ MqttClient.generateClientId());
// mqttConnect=MqttConnect.getInstance(this,"tcp://1.13.101.98","android-"+ MqttClient.generateClientId()); // mqttConnect=MqttConnect.getInstance(this,"tcp://1.13.101.98","android-"+ MqttClient.generateClientId());
mqttConnect.mqttClient(); // mqttConnect.mqttClient();
// 每次启动应用时重置状态 // 每次启动应用时重置状态
SpUtil.getInstance().setBooleanValue("youth_model_shown", false); SpUtil.getInstance().setBooleanValue("youth_model_shown", false);

View File

@@ -6,6 +6,7 @@ import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.LogUtils;
import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.Api;
import com.hjq.toast.ToastUtils; import com.hjq.toast.ToastUtils;
@@ -33,10 +34,10 @@ public class MqttConnect {
public static String update_app = ""; public static String update_app = "";
public static String qx_hour_ranking = ""; public static String qx_hour_ranking = "";
public static String qx_redpacket_arrive="";//红包飘屏的主题 public static String qx_redpacket_arrive = "";//红包飘屏的主题
Handler handler = new Handler(Looper.getMainLooper()); Handler handler = new Handler(Looper.getMainLooper());
String[] topic; String[] topic;
int[] qos = {1,2,3,0,0,0,0,0,0,0,0,0,0}; // 消息质量 int[] qos = {1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // 消息质量
private static MqttConnect instance; private static MqttConnect instance;
public MqttConnect(Context context, String host, String clientId) { public MqttConnect(Context context, String host, String clientId) {
@@ -49,7 +50,7 @@ public class MqttConnect {
update_app = "qx_xunlehui"; // 发送更新APP update_app = "qx_xunlehui"; // 发送更新APP
// qx_hour_ranking = "qx_hour_ranking"; // qx_hour_ranking = "qx_hour_ranking";
qx_hour_ranking = "qx_hour_ranking"; qx_hour_ranking = "qx_hour_ranking";
qx_redpacket_arrive="qx_redpacket_arrive"; qx_redpacket_arrive = "qx_redpacket_arrive";
ArrayList<String> topicList = new ArrayList<>(); ArrayList<String> topicList = new ArrayList<>();
topicList.add(shutdown); topicList.add(shutdown);
@@ -61,12 +62,13 @@ public class MqttConnect {
/** /**
* 单列模式,只能实例化一次 * 单列模式,只能实例化一次
*
* @param context * @param context
* @param host * @param host
* @param clientId * @param clientId
* @return * @return
*/ */
public static synchronized MqttConnect getInstance(Context context, String host, String clientId) { public static synchronized MqttConnect getInstance(Context context, String host, String clientId) {
if (instance == null) { if (instance == null) {
instance = new MqttConnect(context, host, clientId); instance = new MqttConnect(context, host, clientId);
} }
@@ -76,51 +78,44 @@ public class MqttConnect {
/** /**
* 客户端connect连接mqtt服务器 * 客户端connect连接mqtt服务器
**/ **/
public void mqttClient() public void mqttClient() {
{ close();
// close();
// handler.postDelayed(new Runnable() { // 使用线程或线程池
// @Override new Thread(() -> {
// public void run() { try {
try { MqttConnectOptions options = mqttConnectOptions();
// uiTip("MQTT开始连接"); mqttClient.setCallback(new MqttInitCallback(context, HOST, clientId));
MqttConnectOptions options = mqttConnectOptions(); // 在子线程连接不会阻塞UI
mqttClient.setCallback(new MqttInitCallback(context, HOST, clientId)); mqttClient.connect(options);
mqttClient.connect(options); // 订阅也在子线程
// sub(topic,qos); // sub(topic, qos);
sub(shutdown); sub(shutdown);
sub(update_app); sub(update_app);
sub(qx_hour_ranking); sub(qx_hour_ranking);
sub(qx_redpacket_arrive); sub(qx_redpacket_arrive);
// uiTip("MQTT连接成功");
}catch (MqttException e){ // UI操作回到主线程
// uiTip("MQTT连接失败,准备重连。。。:"+e.getMessage()); ActivityUtils.getTopActivity().runOnUiThread(() -> uiTip("MQTT连接成功"));
handler.postDelayed(new Runnable() {
@Override } catch (Exception e) {
public void run() { ActivityUtils.getTopActivity().runOnUiThread(() -> {
LogUtils.e(Tag,"开始重连。。。"); uiTip("MQTT连接失败,准备重连: " + e.getMessage());
mqttClient(); });
} // 延迟重连
},3000); handler.postDelayed(() -> mqttClient(), 3000);
} }
// } }).start();
// },200);
} }
/** /**
* 在主线程弹出消息 * 在主线程弹出消息
*
* @param msg * @param msg
*/ */
private void uiTip(String msg){ private void uiTip(String msg) {
LogUtils.d(Tag,msg); LogUtils.d(Tag, msg);
handler.post(new Runnable() {
@Override
public void run() {
// Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
LogUtils.e("mqtt","连接成功");
ToastUtils.show(msg);
}
});
} }
/** /**
@@ -131,7 +126,6 @@ public class MqttConnect {
mqttClient = new MqttClient(HOST, clientId, new MemoryPersistence()); mqttClient = new MqttClient(HOST, clientId, new MemoryPersistence());
MqttConnectOptions options = new MqttConnectOptions(); MqttConnectOptions options = new MqttConnectOptions();
options.setUserName("public"); options.setUserName("public");
options.setConnectionTimeout(10);
options.setCleanSession(true); options.setCleanSession(true);
options.setConnectionTimeout(10); options.setConnectionTimeout(10);
options.setKeepAliveInterval(10); options.setKeepAliveInterval(10);
@@ -143,18 +137,18 @@ public class MqttConnect {
/** /**
* 关闭MQTT连接 * 关闭MQTT连接
*/ */
public void close(){ public void close() {
if(mqttClient != null && mqttClient.isConnected()){ if (mqttClient != null && mqttClient.isConnected()) {
try { try {
mqttClient.close(); mqttClient.close();
mqttClient.disconnect(); mqttClient.disconnect();
mqttClient = null; mqttClient = null;
} catch (MqttException e) { } catch (MqttException e) {
LogUtils.e(Tag,"关闭MQTT连接报错"+e.getMessage()); LogUtils.e(Tag, "关闭MQTT连接报错" + e.getMessage());
// ToastUtils.show("关闭MQTT连接报错"); // ToastUtils.show("关闭MQTT连接报错");
} }
}else { } else {
LogUtils.d(Tag,"Mqtt已关闭"); LogUtils.d(Tag, "Mqtt已关闭");
} }
} }
@@ -173,8 +167,8 @@ public class MqttConnect {
* 向某个主题发布消息 * 向某个主题发布消息
* *
* @param topic: 发布的主题 * @param topic: 发布的主题
* @param msg: 发布的消息 * @param msg: 发布的消息
* @param qos: 消息质量 Qos0、1、2 * @param qos: 消息质量 Qos0、1、2
*/ */
public void pub(String topic, String msg, int qos) throws MqttException { public void pub(String topic, String msg, int qos) throws MqttException {
MqttMessage mqttMessage = new MqttMessage(); MqttMessage mqttMessage = new MqttMessage();
@@ -190,11 +184,11 @@ public class MqttConnect {
* *
* @param topic 主题 * @param topic 主题
*/ */
public void sub(String topic){ public void sub(String topic) {
try { try {
mqttClient.subscribe(topic); mqttClient.subscribe(topic);
} catch (MqttException e) { } catch (MqttException e) {
LogUtils.e(Tag,"MQTT主题订阅失败" + e.getMessage()); LogUtils.e(Tag, "MQTT主题订阅失败" + e.getMessage());
// uiTip("MQTT主题订阅失败"); // uiTip("MQTT主题订阅失败");
} }
} }
@@ -203,16 +197,15 @@ public class MqttConnect {
* 订阅某一个主题可携带Qos * 订阅某一个主题可携带Qos
* *
* @param topic 所要订阅的主题 * @param topic 所要订阅的主题
* @param qos * @param qos 消息质量0最多发送一次不保证消息能够到达接收端也不负责重发
* 消息质量0最多发送一次,不保证消息能够到达接收端,也不负责重发 * 1至少发送一次,确保消息能够到达接收端,但可能会导致消息重复
* 1至少发送一次确保消息能够到达接收端但可能会导致消息重复 * 2确保消息恰好被接收一次
* 2确保消息恰好被接收一次
*/ */
public void sub(String[] topic, int[] qos){ public void sub(String[] topic, int[] qos) {
try { try {
mqttClient.subscribe(topic, qos); mqttClient.subscribe(topic, qos);
}catch (MqttException e){ } catch (MqttException e) {
LogUtils.e(Tag,"订阅主题失败:"+e.getMessage()); LogUtils.e(Tag, "订阅主题失败:" + e.getMessage());
} }
} }

View File

@@ -48,7 +48,8 @@ public class DataLoggingInterceptor implements Interceptor {
private final Logger logger; private final Logger logger;
@NotNull @NotNull
@Override public Response intercept(@NonNull Chain chain) throws IOException { @Override
public Response intercept(@NonNull Chain chain) throws IOException {
Request request = chain.request(); Request request = chain.request();
logger.reset(); logger.reset();
@@ -135,8 +136,11 @@ public class DataLoggingInterceptor implements Interceptor {
if (responseBody != null) { if (responseBody != null) {
long contentLength = responseBody.contentLength(); long contentLength = responseBody.contentLength();
String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length"; String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
// logger.log(response.code() + " " + response.message() + " "
// + response.request().url() + " (" + tookMs + "ms)");
logger.log(response.code() + " " + response.message() + " " logger.log(response.code() + " " + response.message() + " "
+ response.request().url() + " (" + tookMs + "ms)"); + response.request().url() + "" + response.networkResponse().request().url() + " (" + tookMs + "ms)");
Headers headers = response.headers(); Headers headers = response.headers();
for (int i = 0, count = headers.size(); i < count; i++) { for (int i = 0, count = headers.size(); i < count; i++) {

View File

@@ -4,6 +4,8 @@ import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.blankj.utilcode.util.LogUtils;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -34,7 +36,7 @@ public class LogInterceptor implements Interceptor {
private boolean logResponseBody = true; private boolean logResponseBody = true;
// 最大日志长度(避免过大的响应体导致日志刷屏) // 最大日志长度(避免过大的响应体导致日志刷屏)
private int maxLogLength = 2048; private int maxLogLength = 2048 * 2;
public LogInterceptor() { public LogInterceptor() {
} }
@@ -136,9 +138,18 @@ public class LogInterceptor implements Interceptor {
} }
log.append("==================== 请求结束 ====================\n"); log.append("==================== 请求结束 ====================\n");
Log.d(TAG, log.toString()); // LogUtils.d(TAG, log.toString());
if (log.toString().contains("Xintiao/keep_xintiao"))
return;
try {
LogUtils.d(log.toString());
} catch (StringIndexOutOfBoundsException e) {
// 处理异常,记录日志或使用默认值
LogUtils.e("打印 JSON 数据时出错:" + e.getMessage());
}
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "打印请求日志失败: " + e.getMessage()); LogUtils.e(TAG, "打印请求日志失败: " + e.getMessage());
} }
} }
@@ -186,9 +197,18 @@ public class LogInterceptor implements Interceptor {
} }
log.append("==================== 响应结束 ====================\n"); log.append("==================== 响应结束 ====================\n");
Log.d(TAG, log.toString()); // LogUtils.d(TAG, log.toString());
if (log.toString().contains("Xintiao/keep_xintiao"))
return;
try {
LogUtils.d(log.toString());
} catch (StringIndexOutOfBoundsException e) {
// 处理异常,记录日志或使用默认值
LogUtils.e("打印 JSON 数据时出错:" + e.getMessage());
}
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "打印响应日志失败: " + e.getMessage()); LogUtils.e(TAG, "打印响应日志失败: " + e.getMessage());
} }
} }

View File

@@ -1158,17 +1158,19 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
private fun startGiftProgressTime() { private fun startGiftProgressTime() {
giftProgress = 0 giftProgress = 0
if (giftCountTimer != null) { if (giftCountTimer != null) {
giftCountTimer!!.cancel() giftCountTimer?.cancel()
} }
LogUtils.e("xj2", "onSubscribe") LogUtils.e("xj2", "onSubscribe")
giftCountTimer = object : CountDownTimer((1000 * 10).toLong(), 50) { giftCountTimer = object : CountDownTimer((1000 * 10).toLong(), 50) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
LogUtils.e("startGiftProgressTime onTick:${(!isFinishing)}")
if (!isFinishing) { if (!isFinishing) {
circularProgress!!.progress = 1000 - (millisUntilFinished / 10).toInt() circularProgress!!.progress = 1000 - (millisUntilFinished / 10).toInt()
} }
} }
override fun onFinish() { override fun onFinish() {
LogUtils.e("startGiftProgressTime onFinish")
circularProgress!!.progress = 1000 circularProgress!!.progress = 1000
hideGiftGiveProgress() hideGiftGiveProgress()
} }
@@ -1177,6 +1179,7 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
} }
private fun showGiftGiveProgress() { private fun showGiftGiveProgress() {
LogUtils.e("showGiftGiveProgress")
ImageUtils.loadImageView( ImageUtils.loadImageView(
giftGiveEvent!!.roonGiftModel.base_image, giftGiveEvent!!.roonGiftModel.base_image,
mBinding!!.giftShowProgressImg mBinding!!.giftShowProgressImg
@@ -1187,6 +1190,7 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
} }
private fun hideGiftGiveProgress() { private fun hideGiftGiveProgress() {
LogUtils.e("hideGiftGiveProgress")
mBinding!!.giftShowLayout.visibility = View.GONE mBinding!!.giftShowLayout.visibility = View.GONE
if (giftCountTimer != null) { if (giftCountTimer != null) {
giftCountTimer!!.cancel() giftCountTimer!!.cancel()

View File

@@ -345,8 +345,8 @@ public class ChatRoomFragment extends BaseMvpFragment<ChatRoomPresenter, RoomFra
mBinding.tvTabAll.setTextSize(12); mBinding.tvTabAll.setTextSize(12);
mBinding.tvTabUser.setTextSize(12); mBinding.tvTabUser.setTextSize(12);
} else if (view_id == R.id.tv_count) { } else if (view_id == R.id.tv_count) {
mBinding.recycleViewPublic.scrollToPosition(easeChatAdapter.getItemCount() - 1);
isBottom = true; isBottom = true;
scrollToBottomIfNeed();
mBinding.tvCount.setVisibility(View.GONE); mBinding.tvCount.setVisibility(View.GONE);
} }
@@ -688,7 +688,12 @@ public class ChatRoomFragment extends BaseMvpFragment<ChatRoomPresenter, RoomFra
if (isBottom && easeChatAdapter != null) { if (isBottom && easeChatAdapter != null) {
int itemCount = easeChatAdapter.getItemCount(); int itemCount = easeChatAdapter.getItemCount();
if (itemCount > 0) { if (itemCount > 0) {
mBinding.recycleViewPublic.scrollToPosition(itemCount - 1); mBinding.recycleViewPublic.postDelayed(new Runnable() {
@Override
public void run() {
mBinding.recycleViewPublic.scrollToPosition(itemCount - 1);
}
},100);
} }
} else { } else {
count++; count++;