Search in sources :

Example 26 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ContactDeleteDialogFragment method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    if (which == Dialog.BUTTON_POSITIVE) {
        MessageManager.getInstance().closeChat(account, user);
        try {
            // discard subscription
            PresenceManager.getInstance().discardSubscription(account, user);
        } catch (NetworkException e) {
            Application.getInstance().onError(R.string.CONNECTION_FAILED);
        }
        // delete chat
        AbstractChat chat = MessageManager.getInstance().getChat(account, user);
        if (chat != null)
            MessageManager.getInstance().removeChat(chat);
        // remove roster contact
        RosterManager.getInstance().removeContact(account, user);
        if (getActivity() instanceof ContactActivity) {
            startActivity(ContactListActivity.createIntent(getActivity()));
        }
    }
}
Also used : ContactActivity(com.xabber.android.ui.activity.ContactActivity) AbstractChat(com.xabber.android.data.message.AbstractChat) NetworkException(com.xabber.android.data.NetworkException)

Example 27 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatFragment method showJoinButtonIfNeed.

public void showJoinButtonIfNeed() {
    AbstractChat chat = getChat();
    if (chat != null && chat instanceof RoomChat) {
        RoomState chatState = ((RoomChat) chat).getState();
        if (chatState == RoomState.unavailable) {
            if (joinLayout == null)
                inflateJoinLayout();
            joinLayout.setVisibility(View.VISIBLE);
            inputView.setVisibility(View.GONE);
        } else {
            if (joinLayout != null)
                joinLayout.setVisibility(View.GONE);
            inputView.setVisibility(View.VISIBLE);
        }
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) RoomChat(com.xabber.android.data.extension.muc.RoomChat) RoomState(com.xabber.android.data.extension.muc.RoomState)

Example 28 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatFragment method setChat.

public void setChat(AccountJid accountJid, UserJid userJid) {
    this.account = accountJid;
    this.user = userJid;
    AbstractChat abstractChat = getChat();
    if (!(abstractChat instanceof RegularChat)) {
        securityButton.setVisibility(View.GONE);
    }
    if (abstractChat != null) {
        messageItems = abstractChat.getMessages();
        syncInfoResults = abstractChat.getSyncInfo();
    }
    chatMessageAdapter = new ChatMessageAdapter(getActivity(), messageItems, abstractChat, this);
    realmRecyclerView.setAdapter(chatMessageAdapter);
    layoutManager.scrollToPosition(chatMessageAdapter.getItemCount() - 1);
    restoreInputState();
    updateContact();
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) ChatMessageAdapter(com.xabber.android.ui.adapter.ChatMessageAdapter) RegularChat(com.xabber.android.data.message.RegularChat)

Example 29 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_chat, container, false);
    sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
    sendButton.setColorFilter(ColorManager.getInstance().getAccountPainter().getGreyMain());
    attachButton = (ImageButton) view.findViewById(R.id.button_attach);
    attachButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onAttachButtonPressed();
        }
    });
    lastHistoryProgressBar = view.findViewById(R.id.chat_last_history_progress_bar);
    previousHistoryProgressBar = view.findViewById(R.id.chat_previous_history_progress_bar);
    securityButton = (ImageButton) view.findViewById(R.id.button_security);
    securityButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showSecurityMenu();
        }
    });
    // to avoid strange bug on some 4.x androids
    inputLayout = (LinearLayout) view.findViewById(R.id.input_layout);
    inputLayout.setBackgroundColor(ColorManager.getInstance().getChatInputBackgroundColor());
    view.findViewById(R.id.button_send_message).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            sendMessage();
        }
    });
    setUpInputView(view);
    setUpEmoji(view);
    realmRecyclerView = (RecyclerView) view.findViewById(R.id.chat_messages_recycler_view);
    layoutManager = new LinearLayoutManager(getActivity());
    realmRecyclerView.setLayoutManager(layoutManager);
    layoutManager.setStackFromEnd(true);
    realmRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (dy < 0) {
                loadHistoryIfNeeded();
            }
            if (dy >= 0) {
                toBeScrolled = false;
            }
        }
    });
    swipeContainer = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
    swipeContainer.setColorSchemeColors(ColorManager.getInstance().getAccountPainter().getAccountMainColor(account));
    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            swipeContainer.setRefreshing(false);
            AbstractChat chat = getChat();
            if (chat != null) {
                if (chat.isRemotePreviousHistoryCompletelyLoaded())
                    Toast.makeText(getActivity(), R.string.toast_no_history, Toast.LENGTH_SHORT).show();
                else
                    requestRemoteHistoryLoad();
            }
        }
    });
    stubNotify = (ViewStub) view.findViewById(R.id.stubNotify);
    stubJoin = (ViewStub) view.findViewById(R.id.stubJoin);
    setChat(account, user);
    if (SettingsManager.chatsShowBackground()) {
        if (SettingsManager.interfaceTheme() == SettingsManager.InterfaceTheme.dark) {
            view.setBackgroundResource(R.drawable.chat_background_repeat_dark);
        } else {
            view.setBackgroundResource(R.drawable.chat_background_repeat);
        }
    } else {
        view.setBackgroundColor(ColorManager.getInstance().getChatBackgroundColor());
    }
    placeholder = view.findViewById(R.id.placeholder);
    placeholder.setOnClickListener(this);
    return view;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) EmojiconGridView(github.ankushsachdeva.emojicon.EmojiconGridView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 30 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class AttentionManager method sendAttention.

public void sendAttention(AccountJid account, UserJid user) throws NetworkException {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
    if (!(chat instanceof RegularChat)) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
    }
    Jid to = chat.getTo();
    if (to.getResourceOrNull() == null || to.getResourceOrNull().equals(Resourcepart.EMPTY)) {
        final Presence presence = RosterManager.getInstance().getPresence(account, user);
        if (presence == null) {
            to = null;
        } else {
            to = presence.getFrom();
        }
    }
    if (to == null) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
    }
    if (!CapabilitiesManager.getInstance().isFeatureSupported(to, AttentionExtension.NAMESPACE)) {
        throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
    }
    Message message = new Message();
    message.setTo(to);
    message.setType(Message.Type.headline);
    message.addExtension(new AttentionExtension());
    StanzaSender.sendStanza(account, message);
    chat.newAction(null, null, ChatAction.attention_called);
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) Presence(org.jivesoftware.smack.packet.Presence) NetworkException(com.xabber.android.data.NetworkException) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension) RegularChat(com.xabber.android.data.message.RegularChat)

Aggregations

AbstractChat (com.xabber.android.data.message.AbstractChat)55 UserJid (com.xabber.android.data.entity.UserJid)10 RoomChat (com.xabber.android.data.extension.muc.RoomChat)10 NetworkException (com.xabber.android.data.NetworkException)9 RegularChat (com.xabber.android.data.message.RegularChat)9 ArrayList (java.util.ArrayList)8 AccountJid (com.xabber.android.data.entity.AccountJid)7 RoomContact (com.xabber.android.data.extension.muc.RoomContact)6 ChatContact (com.xabber.android.data.message.ChatContact)6 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 RosterContact (com.xabber.android.data.roster.RosterContact)6 NotificationState (com.xabber.android.data.message.NotificationState)5 Message (org.jivesoftware.smack.packet.Message)5 GroupConfiguration (com.xabber.android.ui.adapter.contactlist.GroupConfiguration)4 View (android.view.View)3 MessageManager (com.xabber.android.data.message.MessageManager)3 Map (java.util.Map)3 Intent (android.content.Intent)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2