use of com.romainpiel.lib.utils.CacheManager in project meatspace-android by RomainPiel.
the class ChatService method onCreate.
@Override
public void onCreate() {
super.onCreate();
cacheManager = new CacheManager(this, false);
apiManager = ApiManager.get();
busManager = BusManager.get();
handler = new Handler();
ioState = IOState.IDLE;
chatList = new ChatList();
mutedUsers = new HashSet<String>();
BackgroundExecutor.execute(new Runnable() {
@Override
public void run() {
final HashSet<String> cachedMutedUsers = (HashSet<String>) cacheManager.readFile(Constants.CACHE_MUTED_USERS, null);
if (cachedMutedUsers != null) {
handler.post(new Runnable() {
@Override
public void run() {
mutedUsers = cachedMutedUsers;
if (chatList.get() != null && !chatList.get().isEmpty()) {
syncChatList(chatList);
post();
}
}
});
}
}
}, API_GET_CACHED_MUTED_REQ_ID, null);
busManager.getChatBus().register(this);
busManager.getUiBus().register(this);
closeChatReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ioState = IOState.DISCONNECTED;
post();
context.stopService(new Intent(context, ChatService.class));
}
};
registerReceiver(closeChatReceiver, new IntentFilter(Constants.FILTER_CHAT_CLOSE));
}
Aggregations