use of com.xabber.android.data.message.NewMessageEvent in project xabber-android by redsolution.
the class CrowdfundingManager method startUpdateTimer.
public void startUpdateTimer(final int delay, final int step) {
if (timer != null)
timer.cancel();
if (!CrowdfundingManager.getInstance().haveDelayedMessages()) {
CrowdfundingMessage lastMessage = getLastMessageFromRealm();
if (lastMessage != null && isCacheExpired())
requestFeed(lastMessage.getTimestamp());
return;
}
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
CrowdfundingManager.getInstance().removeDelay(delay + step);
EventBus.getDefault().post(new NewMessageEvent());
startUpdateTimer(delay + step, step);
}
}, step * 1000);
}
use of com.xabber.android.data.message.NewMessageEvent in project xabber-android by redsolution.
the class CrowdfundingManager method requestLeader.
private void requestLeader() {
compositeSubscription.add(CrowdfundingClient.getLeader().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<CrowdfundingMessage>>() {
@Override
public void call(List<CrowdfundingMessage> crowdfundingMessages) {
Log.d("crowd", "ok");
SettingsManager.setLastLeaderCrowdfundingLoadTimestamp(getCurrentTime());
EventBus.getDefault().post(new NewMessageEvent());
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Log.d("crowd", throwable.toString());
}
}));
}
use of com.xabber.android.data.message.NewMessageEvent in project xabber-android by redsolution.
the class CrowdfundingManager method requestFeed.
private void requestFeed(int timestamp) {
compositeSubscription.add(CrowdfundingClient.getFeed(timestamp).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<CrowdfundingMessage>>() {
@Override
public void call(List<CrowdfundingMessage> crowdfundingMessages) {
Log.d("crowd", "ok");
SettingsManager.setLastCrowdfundingLoadTimestamp(getCurrentTime());
EventBus.getDefault().post(new NewMessageEvent());
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Log.d("crowd", throwable.toString());
}
}));
}
use of com.xabber.android.data.message.NewMessageEvent in project xabber-android by redsolution.
the class NextMamManager method saveOrUpdateMessages.
private List<MessageItem> saveOrUpdateMessages(Realm realm, final Collection<MessageItem> messages, boolean ui) {
List<MessageItem> messagesToSave = new ArrayList<>();
if (messages != null && !messages.isEmpty()) {
Iterator<MessageItem> iterator = messages.iterator();
while (iterator.hasNext()) {
MessageItem newMessage = determineSaveOrUpdate(realm, iterator.next(), ui);
if (newMessage != null)
messagesToSave.add(newMessage);
}
}
realm.beginTransaction();
realm.copyToRealmOrUpdate(messagesToSave);
realm.commitTransaction();
SyncManager.getInstance().onMessageSaved();
EventBus.getDefault().post(new NewMessageEvent());
return messagesToSave;
}
Aggregations