use of com.xabber.android.data.database.realm.CrowdfundingMessage in project xabber-android by redsolution.
the class CrowdfundingChatAdapter method getItemViewType.
@Override
public int getItemViewType(int position) {
final CrowdfundingMessage message = getMessage(position);
if (message == null)
return 0;
String text = message.getMessageForCurrentLocale();
if (FileManager.isImageUrl(text))
return VIEW_TYPE_MESSAGE_NOFLEX;
else
return VIEW_TYPE_MESSAGE;
}
use of com.xabber.android.data.database.realm.CrowdfundingMessage 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.database.realm.CrowdfundingMessage in project xabber-android by redsolution.
the class CrowdfundingManager method haveDelayedMessages.
public boolean haveDelayedMessages() {
Realm realm = RealmManager.getInstance().getNewRealm();
CrowdfundingMessage message = realm.where(CrowdfundingMessage.class).notEqualTo(CrowdfundingMessage.Fields.DELAY, 0).findFirst();
return message != null;
}
use of com.xabber.android.data.database.realm.CrowdfundingMessage in project xabber-android by redsolution.
the class CrowdfundingManager method messageToRealm.
private CrowdfundingMessage messageToRealm(CrowdfundingClient.Message message) {
CrowdfundingMessage realmMessage = new CrowdfundingMessage(message.getUuid());
realmMessage.setRead(false);
realmMessage.setDelay(message.getDelay());
realmMessage.setLeader(message.isLeader());
if (message.isLeader())
realmMessage.setTimestamp(getCurrentTime());
else
realmMessage.setTimestamp(message.getTimestamp());
realmMessage.setAuthorAvatar(message.getAuthor().getAvatar());
realmMessage.setAuthorJid(message.getAuthor().getJabberId());
for (CrowdfundingClient.LocalizedMessage locale : message.getFeed()) {
if ("en".equals(locale.getLocale()))
realmMessage.setMessageEn(locale.getMessage());
if ("ru".equals(locale.getLocale()))
realmMessage.setMessageRu(locale.getMessage());
}
for (CrowdfundingClient.LocalizedName name : message.getAuthor().getName()) {
if ("en".equals(name.getLocale()))
realmMessage.setAuthorNameEn(name.getName());
if ("ru".equals(name.getLocale()))
realmMessage.setAuthorNameRu(name.getName());
}
return realmMessage;
}
use of com.xabber.android.data.database.realm.CrowdfundingMessage 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());
}
}));
}
Aggregations