Search in sources :

Example 1 with CrowdfundingMessage

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;
}
Also used : CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Example 2 with CrowdfundingMessage

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);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) NewMessageEvent(com.xabber.android.data.message.NewMessageEvent) CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Example 3 with CrowdfundingMessage

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;
}
Also used : Realm(io.realm.Realm) CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Example 4 with CrowdfundingMessage

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;
}
Also used : CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Example 5 with CrowdfundingMessage

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());
        }
    }));
}
Also used : Action1(rx.functions.Action1) RealmList(io.realm.RealmList) List(java.util.List) NewMessageEvent(com.xabber.android.data.message.NewMessageEvent) CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Aggregations

CrowdfundingMessage (com.xabber.android.data.database.realm.CrowdfundingMessage)16 Realm (io.realm.Realm)7 AbstractChat (com.xabber.android.data.message.AbstractChat)3 NewMessageEvent (com.xabber.android.data.message.NewMessageEvent)3 CrowdfundingContact (com.xabber.android.data.roster.CrowdfundingContact)3 RealmList (io.realm.RealmList)3 ArrayList (java.util.ArrayList)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 CrowdfundingChat (com.xabber.android.data.message.CrowdfundingChat)2 AbstractContact (com.xabber.android.data.roster.AbstractContact)2 GroupConfiguration (com.xabber.android.ui.adapter.contactlist.GroupConfiguration)2 List (java.util.List)2 Action1 (rx.functions.Action1)2 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 DrawableImageViewTarget (com.bumptech.glide.request.target.DrawableImageViewTarget)1