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;
@@ -61,6 +62,7 @@ public class MqttConnect {
/** /**
* 单列模式,只能实例化一次 * 单列模式,只能实例化一次
*
* @param context * @param context
* @param host * @param host
* @param clientId * @param 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 {
// uiTip("MQTT开始连接");
MqttConnectOptions options = mqttConnectOptions(); MqttConnectOptions options = mqttConnectOptions();
mqttClient.setCallback(new MqttInitCallback(context, HOST, clientId)); mqttClient.setCallback(new MqttInitCallback(context, HOST, clientId));
// 在子线程连接不会阻塞UI
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(); });
// 延迟重连
handler.postDelayed(() -> mqttClient(), 3000);
} }
},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);
@@ -203,8 +197,7 @@ public class MqttConnect {
* 订阅某一个主题可携带Qos * 订阅某一个主题可携带Qos
* *
* @param topic 所要订阅的主题 * @param topic 所要订阅的主题
* @param qos * @param qos 消息质量0最多发送一次不保证消息能够到达接收端也不负责重发
* 消息质量0最多发送一次不保证消息能够到达接收端也不负责重发
* 1至少发送一次确保消息能够到达接收端但可能会导致消息重复 * 1至少发送一次确保消息能够到达接收端但可能会导致消息重复
* 2确保消息恰好被接收一次 * 2确保消息恰好被接收一次
*/ */

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,8 +688,13 @@ 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.postDelayed(new Runnable() {
@Override
public void run() {
mBinding.recycleViewPublic.scrollToPosition(itemCount - 1); mBinding.recycleViewPublic.scrollToPosition(itemCount - 1);
} }
},100);
}
} else { } else {
count++; count++;
mBinding.tvCount.setText(count + "条新消息"); mBinding.tvCount.setText(count + "条新消息");