mirror of
https://gitee.com/farsunset/cim.git
synced 2025-07-16 13:06:15 +08:00
android sdk 监听器容器修改为CopyOnWriteArrayList
This commit is contained in:
parent
40a4353d21
commit
11f40a0f51
@ -53,6 +53,11 @@ class CIMCacheManager {
|
||||
|
||||
public static final String CONTENT_URI = "content://%s.cim.provider";
|
||||
|
||||
static final String COLUMN_KEY = "key";
|
||||
|
||||
static final String COLUMN_VALUE = "value";
|
||||
|
||||
|
||||
|
||||
public static void remove(Context context, String key) {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
@ -63,8 +68,8 @@ class CIMCacheManager {
|
||||
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("value", value);
|
||||
values.put("key", key);
|
||||
values.put(COLUMN_KEY, key);
|
||||
values.put(COLUMN_VALUE, value);
|
||||
resolver.insert(Uri.parse(String.format(CONTENT_URI, context.getPackageName())), values);
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class CIMCacheProvider extends ContentProvider {
|
||||
|
||||
@Override
|
||||
public int delete(Uri arg0, String key, String[] arg2) {
|
||||
getContext().getSharedPreferences(MODEL_KEY, Context.MODE_PRIVATE).edit().remove(key).apply();
|
||||
getContext().getSharedPreferences(MODEL_KEY, Context.MODE_PRIVATE).edit().remove(key).commit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -44,9 +44,9 @@ public class CIMCacheProvider extends ContentProvider {
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri arg0, ContentValues values) {
|
||||
String key = values.getAsString("key");
|
||||
String value = values.getAsString("value");
|
||||
getContext().getSharedPreferences(MODEL_KEY, Context.MODE_PRIVATE).edit().putString(key, value).apply();
|
||||
String key = values.getAsString(CIMCacheManager.COLUMN_KEY);
|
||||
String value = values.getAsString(CIMCacheManager.COLUMN_VALUE);
|
||||
getContext().getSharedPreferences(MODEL_KEY, Context.MODE_PRIVATE).edit().putString(key, value).commit();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public class CIMCacheProvider extends ContentProvider {
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri arg0, String[] arg1, String key, String[] arg3, String arg4) {
|
||||
MatrixCursor cursor = new MatrixCursor(new String[]{"value"});
|
||||
MatrixCursor cursor = new MatrixCursor(new String[]{CIMCacheManager.COLUMN_VALUE});
|
||||
String value = getContext().getSharedPreferences(MODEL_KEY, Context.MODE_PRIVATE).getString(arg1[0], null);
|
||||
cursor.addRow(new Object[]{value});
|
||||
return cursor;
|
||||
|
@ -27,16 +27,16 @@ import com.farsunset.cim.sdk.android.model.Message;
|
||||
import com.farsunset.cim.sdk.android.model.ReplyBody;
|
||||
import com.farsunset.cim.sdk.android.model.SentBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* CIM 消息监听器管理
|
||||
*/
|
||||
public class CIMListenerManager {
|
||||
|
||||
private static final ArrayList<CIMEventListener> cimListeners = new ArrayList<>();
|
||||
private static final List<CIMEventListener> cimListeners = new CopyOnWriteArrayList<>();
|
||||
private static final ReceiveComparator comparator = new ReceiveComparator();
|
||||
|
||||
private CIMListenerManager() {
|
||||
@ -47,7 +47,7 @@ public class CIMListenerManager {
|
||||
|
||||
if (!cimListeners.contains(listener)) {
|
||||
cimListeners.add(listener);
|
||||
Collections.sort(cimListeners,comparator);
|
||||
cimListeners.sort(comparator);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,9 +118,7 @@ public class CIMPushService extends Service {
|
||||
|
||||
String action = newIntent.getAction();
|
||||
|
||||
if (!persistHolder.get()) {
|
||||
createTransientNotification();
|
||||
}
|
||||
createTransientNotification(newIntent);
|
||||
|
||||
if (ServiceAction.ACTION_CREATE_CIM_CONNECTION.equals(action)) {
|
||||
this.prepareConnect(newIntent.getLongExtra(BundleKey.KEY_DELAYED_TIME, 0));
|
||||
@ -221,10 +219,6 @@ public class CIMPushService extends Service {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
release();
|
||||
}
|
||||
|
||||
private void release() {
|
||||
|
||||
connectHandler.removeMessages(0);
|
||||
|
||||
@ -246,13 +240,18 @@ public class CIMPushService extends Service {
|
||||
|
||||
}
|
||||
|
||||
private void createTransientNotification() {
|
||||
private void createTransientNotification(Intent intent) {
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || persistHolder.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (ServiceAction.ACTION_SHOW_PERSIST_NOTIFICATION.equals(intent.getAction())
|
||||
|| ServiceAction.ACTION_HIDE_PERSIST_NOTIFICATION.equals(intent.getAction())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (notificationManager.getNotificationChannel(PERSIST_NTC_CHANNEL_ID) != null) {
|
||||
|
||||
int icon = CIMCacheManager.getInt(this,CIMCacheManager.KEY_NTC_CHANNEL_ICON);
|
||||
@ -272,11 +271,13 @@ public class CIMPushService extends Service {
|
||||
channel.enableVibration(false);
|
||||
channel.setSound(null, null);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
|
||||
Notification notification = makeNotification(TRANSIENT_NTC_CHANNEL_ID,0,CIMPushService.class.getSimpleName(),null);
|
||||
|
||||
startForeground(NOTIFICATION_ID, notification);
|
||||
|
||||
}
|
||||
|
||||
Notification notification = makeNotification(TRANSIENT_NTC_CHANNEL_ID,0,CIMPushService.class.getSimpleName(),null);
|
||||
|
||||
startForeground(NOTIFICATION_ID, notification);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user