Search in sources :

Example 1 with ConversationVM

use of im.actor.core.viewmodel.ConversationVM in project actor-platform by actorapp.

the class ChatFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    findInputBar().setText(messenger().loadDraft(peer), true);
    if (peer.getPeerType() == PeerType.PRIVATE) {
        UserVM userVM = users().get(peer.getPeerId());
        if (userVM.isBot()) {
            ConversationVM conversationVM = messenger().getConversationVM(peer);
            bind(conversationVM.getIsEmpty(), conversationVM.getIsLoaded(), (isEmpty, valueModel, isLoaded, valueModel2) -> {
                if (isEmpty) {
                    inputOverlayText.setText(R.string.chat_empty_bot);
                    inputOverlayText.setTextColor(style.getListActionColor());
                    inputOverlayText.setClickable(true);
                    showView(inputOverlayContainer, false);
                    goneView(inputContainer, false);
                } else {
                    goneView(inputOverlayContainer, false);
                    showView(inputContainer, false);
                }
                if (isEmpty && isLoaded) {
                    showView(emptyContainer, false);
                } else {
                    hideView(emptyContainer, false);
                }
            });
            bind(userVM.getAbout(), (val, valueModel) -> {
                if (val == null) {
                    findEmptyPlaceholder().setText(getString(R.string.chat_empty_bot_about));
                } else {
                    findEmptyPlaceholder().setText(val);
                }
            });
        } else {
            bind(userVM.getIsBlocked(), (val, valueModel) -> {
                if (val) {
                    inputOverlayText.setText(R.string.blocked_unblock);
                    inputOverlayText.setTextColor(style.getListActionColor());
                    inputOverlayText.setClickable(true);
                    showView(inputOverlayContainer, false);
                    goneView(inputContainer, false);
                } else {
                    goneView(inputOverlayContainer, false);
                    showView(inputContainer, false);
                }
            });
        }
    } else if (peer.getPeerType() == PeerType.GROUP) {
        GroupVM groupVM = groups().get(peer.getPeerId());
        bind(groupVM.isMember(), groupVM.getIsCanWriteMessage(), (isMember, valueModel, canWriteMessage, valueModel2) -> {
            if (canWriteMessage) {
                goneView(inputOverlayContainer, false);
                showView(inputContainer, false);
            } else if (isMember) {
                if (messenger().isNotificationsEnabled(peer)) {
                    inputOverlayText.setText(getString(R.string.chat_mute));
                } else {
                    inputOverlayText.setText(getString(R.string.chat_unmute));
                }
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(true);
                inputOverlayText.setEnabled(true);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else if (groupVM.getIsCanJoin().get()) {
                inputOverlayText.setText(getString(R.string.join));
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(true);
                inputOverlayText.setEnabled(true);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else if (groupVM.getIsDeleted().get()) {
                inputOverlayText.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_deleted : R.string.group_deleted);
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(false);
                inputOverlayText.setEnabled(false);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else {
                inputOverlayText.setText(R.string.chat_not_member);
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(false);
                inputOverlayText.setEnabled(false);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            }
        });
    }
}
Also used : BaseFragment(im.actor.sdk.controllers.BaseFragment) ConversationVM(im.actor.core.viewmodel.ConversationVM) InputBarFragment(im.actor.sdk.controllers.conversation.inputbar.InputBarFragment) Bundle(android.os.Bundle) ValueDoubleChangedListener(im.actor.runtime.mvvm.ValueDoubleChangedListener) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) ValueListener(im.actor.runtime.mvvm.ValueListener) GroupVM(im.actor.core.viewmodel.GroupVM) QuoteCallback(im.actor.sdk.controllers.conversation.quote.QuoteCallback) AutocompleteFragment(im.actor.sdk.controllers.conversation.mentions.AutocompleteFragment) AttachFragment(im.actor.sdk.controllers.conversation.attach.AttachFragment) Toast(android.widget.Toast) AbsAttachFragment(im.actor.sdk.controllers.conversation.attach.AbsAttachFragment) View(android.view.View) AutocompleteCallback(im.actor.sdk.controllers.conversation.mentions.AutocompleteCallback) GroupType(im.actor.core.entity.GroupType) PeerType(im.actor.core.entity.PeerType) Sticker(im.actor.core.entity.Sticker) ActorSDK(im.actor.sdk.ActorSDK) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) MessagesDefaultFragment(im.actor.sdk.controllers.conversation.messages.MessagesDefaultFragment) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) InputBarCallback(im.actor.sdk.controllers.conversation.inputbar.InputBarCallback) MessagesFragmentCallback(im.actor.sdk.controllers.conversation.messages.MessagesFragmentCallback) ViewGroup(android.view.ViewGroup) RpcException(im.actor.core.network.RpcException) EmptyChatPlaceholder(im.actor.sdk.controllers.conversation.placeholder.EmptyChatPlaceholder) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) TextView(android.widget.TextView) QuoteFragment(im.actor.sdk.controllers.conversation.quote.QuoteFragment) Configuration(android.content.res.Configuration) Peer(im.actor.core.entity.Peer) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) ValueChangedListener(im.actor.runtime.mvvm.ValueChangedListener) Value(im.actor.runtime.mvvm.Value) ChatToolbarFragment(im.actor.sdk.controllers.conversation.toolbar.ChatToolbarFragment) UserVM(im.actor.core.viewmodel.UserVM) GroupVM(im.actor.core.viewmodel.GroupVM) ConversationVM(im.actor.core.viewmodel.ConversationVM)

Aggregations

Activity (android.app.Activity)1 Configuration (android.content.res.Configuration)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 GroupType (im.actor.core.entity.GroupType)1 Peer (im.actor.core.entity.Peer)1 PeerType (im.actor.core.entity.PeerType)1 Sticker (im.actor.core.entity.Sticker)1 RpcException (im.actor.core.network.RpcException)1 ConversationVM (im.actor.core.viewmodel.ConversationVM)1 GroupVM (im.actor.core.viewmodel.GroupVM)1 UserVM (im.actor.core.viewmodel.UserVM)1 Value (im.actor.runtime.mvvm.Value)1 ValueChangedListener (im.actor.runtime.mvvm.ValueChangedListener)1