添加礼物飘屏功能
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.qxcm.moduleutil.event;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.blankj.utilcode.util.GsonUtils;
|
||||
import com.blankj.utilcode.util.ServiceUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.qxcm.moduleutil.base.CommonAppContext;
|
||||
import com.qxcm.moduleutil.service.EMqttService;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author $
|
||||
* @Time $ $
|
||||
* @Description $
|
||||
*/
|
||||
public class RoomGiftRunable implements Runnable {
|
||||
|
||||
private String data;
|
||||
private static final List<MqttBean> mqttCache = new ArrayList<>();
|
||||
private static final int MAX_CACHE_SIZE = 6;
|
||||
private static final Object lock = new Object();
|
||||
public RoomGiftRunable(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
MqttBean mqttBean= GsonUtils.fromJson(data, MqttBean.class);
|
||||
// 线程安全地添加到缓存
|
||||
synchronized (lock) {
|
||||
if (mqttCache.size() >= MAX_CACHE_SIZE) {
|
||||
mqttCache.remove(0); // 移除第一条数据
|
||||
}
|
||||
mqttCache.add(mqttBean); // 添加新数据
|
||||
}
|
||||
EventBus.getDefault().post(mqttBean);
|
||||
|
||||
}
|
||||
|
||||
// 提供方法获取缓存数据
|
||||
public static List<MqttBean> getMqttCache() {
|
||||
synchronized (lock) {
|
||||
return new ArrayList<>(mqttCache);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user