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()));
}
}
}
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);
}
}
}
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();
}
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;
}
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);
}
Aggregations