Merge branch 'branch_new_dev' into branch_new
This commit is contained in:
@@ -449,9 +449,9 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
|
||||
// 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.mqttClient();
|
||||
// mqttConnect.mqttClient();
|
||||
|
||||
// 每次启动应用时重置状态
|
||||
SpUtil.getInstance().setBooleanValue("youth_model_shown", false);
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.blankj.utilcode.util.ActivityUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.google.android.gms.common.api.Api;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
@@ -33,10 +34,10 @@ public class MqttConnect {
|
||||
public static String update_app = "";
|
||||
public static String qx_hour_ranking = "";
|
||||
|
||||
public static String qx_redpacket_arrive="";//红包飘屏的主题
|
||||
public static String qx_redpacket_arrive = "";//红包飘屏的主题
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
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;
|
||||
|
||||
public MqttConnect(Context context, String host, String clientId) {
|
||||
@@ -49,7 +50,7 @@ public class MqttConnect {
|
||||
update_app = "qx_xunlehui"; // 发送更新APP
|
||||
// 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<>();
|
||||
topicList.add(shutdown);
|
||||
@@ -61,6 +62,7 @@ public class MqttConnect {
|
||||
|
||||
/**
|
||||
* 单列模式,只能实例化一次
|
||||
*
|
||||
* @param context
|
||||
* @param host
|
||||
* @param clientId
|
||||
@@ -76,51 +78,44 @@ public class MqttConnect {
|
||||
/**
|
||||
* 客户端connect连接mqtt服务器
|
||||
**/
|
||||
public void mqttClient()
|
||||
{
|
||||
// close();
|
||||
// handler.postDelayed(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
public void mqttClient() {
|
||||
close();
|
||||
|
||||
// 使用线程或线程池
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// uiTip("MQTT开始连接");
|
||||
MqttConnectOptions options = mqttConnectOptions();
|
||||
mqttClient.setCallback(new MqttInitCallback(context, HOST, clientId));
|
||||
// 在子线程连接(不会阻塞UI)
|
||||
mqttClient.connect(options);
|
||||
// sub(topic,qos);
|
||||
// 订阅也在子线程
|
||||
// sub(topic, qos);
|
||||
sub(shutdown);
|
||||
sub(update_app);
|
||||
sub(qx_hour_ranking);
|
||||
sub(qx_redpacket_arrive);
|
||||
// uiTip("MQTT连接成功");
|
||||
}catch (MqttException e){
|
||||
// uiTip("MQTT连接失败,准备重连。。。:"+e.getMessage());
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LogUtils.e(Tag,"开始重连。。。");
|
||||
mqttClient();
|
||||
|
||||
// UI操作回到主线程
|
||||
ActivityUtils.getTopActivity().runOnUiThread(() -> uiTip("MQTT连接成功"));
|
||||
|
||||
} catch (Exception e) {
|
||||
ActivityUtils.getTopActivity().runOnUiThread(() -> {
|
||||
uiTip("MQTT连接失败,准备重连: " + e.getMessage());
|
||||
});
|
||||
// 延迟重连
|
||||
handler.postDelayed(() -> mqttClient(), 3000);
|
||||
}
|
||||
},3000);
|
||||
}
|
||||
// }
|
||||
// },200);
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 在主线程弹出消息
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
private void uiTip(String 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);
|
||||
}
|
||||
});
|
||||
private void uiTip(String msg) {
|
||||
LogUtils.d(Tag, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +126,6 @@ public class MqttConnect {
|
||||
mqttClient = new MqttClient(HOST, clientId, new MemoryPersistence());
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName("public");
|
||||
options.setConnectionTimeout(10);
|
||||
options.setCleanSession(true);
|
||||
options.setConnectionTimeout(10);
|
||||
options.setKeepAliveInterval(10);
|
||||
@@ -143,18 +137,18 @@ public class MqttConnect {
|
||||
/**
|
||||
* 关闭MQTT连接
|
||||
*/
|
||||
public void close(){
|
||||
if(mqttClient != null && mqttClient.isConnected()){
|
||||
public void close() {
|
||||
if (mqttClient != null && mqttClient.isConnected()) {
|
||||
try {
|
||||
mqttClient.close();
|
||||
mqttClient.disconnect();
|
||||
mqttClient = null;
|
||||
} catch (MqttException e) {
|
||||
LogUtils.e(Tag,"关闭MQTT连接报错:"+e.getMessage());
|
||||
LogUtils.e(Tag, "关闭MQTT连接报错:" + e.getMessage());
|
||||
// ToastUtils.show("关闭MQTT连接报错");
|
||||
}
|
||||
}else {
|
||||
LogUtils.d(Tag,"Mqtt已关闭");
|
||||
} else {
|
||||
LogUtils.d(Tag, "Mqtt已关闭");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,11 +184,11 @@ public class MqttConnect {
|
||||
*
|
||||
* @param topic 主题
|
||||
*/
|
||||
public void sub(String topic){
|
||||
public void sub(String topic) {
|
||||
try {
|
||||
mqttClient.subscribe(topic);
|
||||
} catch (MqttException e) {
|
||||
LogUtils.e(Tag,"MQTT主题订阅失败:" + e.getMessage());
|
||||
LogUtils.e(Tag, "MQTT主题订阅失败:" + e.getMessage());
|
||||
// uiTip("MQTT主题订阅失败");
|
||||
}
|
||||
}
|
||||
@@ -203,16 +197,15 @@ public class MqttConnect {
|
||||
* 订阅某一个主题,可携带Qos
|
||||
*
|
||||
* @param topic 所要订阅的主题
|
||||
* @param qos
|
||||
* 消息质量:0最多发送一次,不保证消息能够到达接收端,也不负责重发
|
||||
* @param qos 消息质量:0最多发送一次,不保证消息能够到达接收端,也不负责重发
|
||||
* 1至少发送一次,确保消息能够到达接收端,但可能会导致消息重复
|
||||
* 2确保消息恰好被接收一次
|
||||
*/
|
||||
public void sub(String[] topic, int[] qos){
|
||||
public void sub(String[] topic, int[] qos) {
|
||||
try {
|
||||
mqttClient.subscribe(topic, qos);
|
||||
}catch (MqttException e){
|
||||
LogUtils.e(Tag,"订阅主题失败:"+e.getMessage());
|
||||
} catch (MqttException e) {
|
||||
LogUtils.e(Tag, "订阅主题失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ public class DataLoggingInterceptor implements Interceptor {
|
||||
private final Logger logger;
|
||||
|
||||
@NotNull
|
||||
@Override public Response intercept(@NonNull Chain chain) throws IOException {
|
||||
@Override
|
||||
public Response intercept(@NonNull Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
|
||||
logger.reset();
|
||||
@@ -135,8 +136,11 @@ public class DataLoggingInterceptor implements Interceptor {
|
||||
if (responseBody != null) {
|
||||
long contentLength = responseBody.contentLength();
|
||||
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() + " "
|
||||
+ response.request().url() + " (" + tookMs + "ms)");
|
||||
+ response.request().url() + " → " + response.networkResponse().request().url() + " (" + tookMs + "ms)");
|
||||
|
||||
Headers headers = response.headers();
|
||||
for (int i = 0, count = headers.size(); i < count; i++) {
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -34,7 +36,7 @@ public class LogInterceptor implements Interceptor {
|
||||
|
||||
private boolean logResponseBody = true;
|
||||
// 最大日志长度(避免过大的响应体导致日志刷屏)
|
||||
private int maxLogLength = 2048;
|
||||
private int maxLogLength = 2048 * 2;
|
||||
|
||||
public LogInterceptor() {
|
||||
}
|
||||
@@ -136,9 +138,18 @@ public class LogInterceptor implements Interceptor {
|
||||
}
|
||||
|
||||
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) {
|
||||
Log.e(TAG, "打印请求日志失败: " + e.getMessage());
|
||||
LogUtils.e(TAG, "打印请求日志失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +197,18 @@ public class LogInterceptor implements Interceptor {
|
||||
}
|
||||
|
||||
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) {
|
||||
Log.e(TAG, "打印响应日志失败: " + e.getMessage());
|
||||
LogUtils.e(TAG, "打印响应日志失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1158,17 +1158,19 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
|
||||
private fun startGiftProgressTime() {
|
||||
giftProgress = 0
|
||||
if (giftCountTimer != null) {
|
||||
giftCountTimer!!.cancel()
|
||||
giftCountTimer?.cancel()
|
||||
}
|
||||
LogUtils.e("xj2", "onSubscribe")
|
||||
giftCountTimer = object : CountDownTimer((1000 * 10).toLong(), 50) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
LogUtils.e("startGiftProgressTime onTick:${(!isFinishing)}")
|
||||
if (!isFinishing) {
|
||||
circularProgress!!.progress = 1000 - (millisUntilFinished / 10).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
LogUtils.e("startGiftProgressTime onFinish")
|
||||
circularProgress!!.progress = 1000
|
||||
hideGiftGiveProgress()
|
||||
}
|
||||
@@ -1177,6 +1179,7 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
|
||||
}
|
||||
|
||||
private fun showGiftGiveProgress() {
|
||||
LogUtils.e("showGiftGiveProgress")
|
||||
ImageUtils.loadImageView(
|
||||
giftGiveEvent!!.roonGiftModel.base_image,
|
||||
mBinding!!.giftShowProgressImg
|
||||
@@ -1187,6 +1190,7 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
|
||||
}
|
||||
|
||||
private fun hideGiftGiveProgress() {
|
||||
LogUtils.e("hideGiftGiveProgress")
|
||||
mBinding!!.giftShowLayout.visibility = View.GONE
|
||||
if (giftCountTimer != null) {
|
||||
giftCountTimer!!.cancel()
|
||||
|
||||
@@ -345,8 +345,8 @@ public class ChatRoomFragment extends BaseMvpFragment<ChatRoomPresenter, RoomFra
|
||||
mBinding.tvTabAll.setTextSize(12);
|
||||
mBinding.tvTabUser.setTextSize(12);
|
||||
} else if (view_id == R.id.tv_count) {
|
||||
mBinding.recycleViewPublic.scrollToPosition(easeChatAdapter.getItemCount() - 1);
|
||||
isBottom = true;
|
||||
scrollToBottomIfNeed();
|
||||
mBinding.tvCount.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@@ -688,8 +688,13 @@ public class ChatRoomFragment extends BaseMvpFragment<ChatRoomPresenter, RoomFra
|
||||
if (isBottom && easeChatAdapter != null) {
|
||||
int itemCount = easeChatAdapter.getItemCount();
|
||||
if (itemCount > 0) {
|
||||
mBinding.recycleViewPublic.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mBinding.recycleViewPublic.scrollToPosition(itemCount - 1);
|
||||
}
|
||||
},100);
|
||||
}
|
||||
} else {
|
||||
count++;
|
||||
mBinding.tvCount.setText(count + "条新消息");
|
||||
|
||||
Reference in New Issue
Block a user