From ba86adbc78fcc69cda6ebeca72635aa279bffe49 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Sun, 26 May 2019 18:23:40 +0400 Subject: [PATCH] [FIXME] Removed adding users to user list in ChatEntity. Added toast when send message if network error --- .../github/chronosx88/influence/helpers/NetworkHandler.java | 5 +---- .../github/chronosx88/influence/presenters/ChatPresenter.kt | 4 +++- .../chronosx88/influence/presenters/DialogListPresenter.java | 5 +---- .../github/chronosx88/influence/presenters/MainPresenter.kt | 5 +---- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/influence/helpers/NetworkHandler.java b/app/src/main/java/io/github/chronosx88/influence/helpers/NetworkHandler.java index 1edd164..d4a9b46 100644 --- a/app/src/main/java/io/github/chronosx88/influence/helpers/NetworkHandler.java +++ b/app/src/main/java/io/github/chronosx88/influence/helpers/NetworkHandler.java @@ -71,10 +71,7 @@ public class NetworkHandler implements IncomingChatMessageListener, PresenceEven public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) { String chatID = chat.getXmppAddressOfChatPartner().asUnescapedString(); if(LocalDBWrapper.getChatByChatID(from.asEntityBareJidString()) == null) { - ArrayList users = new ArrayList<>(); - users.add(new GenericUser(AppHelper.getJid(), AppHelper.getJid().split("@")[0], AppHelper.getJid())); - users.add(new GenericUser(chat.getXmppAddressOfChatPartner().asBareJid().asUnescapedString(), chat.getXmppAddressOfChatPartner().asBareJid().asUnescapedString().split("@")[0], chat.getXmppAddressOfChatPartner().asBareJid().asUnescapedString())); - LocalDBWrapper.createChatEntry(chatID, chat.getXmppAddressOfChatPartner().asBareJid().asUnescapedString().split("@")[0], users); + LocalDBWrapper.createChatEntry(chatID, chat.getXmppAddressOfChatPartner().asBareJid().asUnescapedString().split("@")[0], new ArrayList<>()); } long messageID = LocalDBWrapper.createMessageEntry(chatID, message.getStanzaId(), from.asUnescapedString(), TrueTime.now().getTime(), message.getBody(), true, false); int newUnreadMessagesCount = LocalDBWrapper.getChatByChatID(chatID).unreadMessagesCount + 1; diff --git a/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.kt b/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.kt index fcbebb3..4ed58bc 100644 --- a/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.kt +++ b/app/src/main/java/io/github/chronosx88/influence/presenters/ChatPresenter.kt @@ -17,6 +17,7 @@ package io.github.chronosx88.influence.presenters import android.view.MenuItem +import android.widget.Toast import com.google.gson.Gson import com.stfalcon.chatkit.messages.MessageHolders import com.stfalcon.chatkit.messages.MessagesListAdapter @@ -56,7 +57,7 @@ class ChatPresenter(private val view: CoreContracts.IChatViewContract, private v val holdersConfig = MessageHolders() holdersConfig.setIncomingTextLayout(R.layout.item_incoming_text_message_custom) chatAdapter = MessagesListAdapter(AppHelper.getJid(), holdersConfig, AvatarImageLoader(view.getActivityObject())) - chatAdapter.setLoadMoreListener { page, _ -> loadMoreMessages() } + chatAdapter.setLoadMoreListener { _, _ -> loadMoreMessages() } view.setAdapter(chatAdapter) getUserStatus() EventBus.getDefault().register(this) @@ -71,6 +72,7 @@ class ChatPresenter(private val view: CoreContracts.IChatViewContract, private v EventBus.getDefault().post(LastMessageEvent(chatEntity!!.jid, message)) return true } + Toast.makeText(view.getActivityObject(), "Network error!", Toast.LENGTH_SHORT).show() return false } diff --git a/app/src/main/java/io/github/chronosx88/influence/presenters/DialogListPresenter.java b/app/src/main/java/io/github/chronosx88/influence/presenters/DialogListPresenter.java index 1beff5e..a516562 100644 --- a/app/src/main/java/io/github/chronosx88/influence/presenters/DialogListPresenter.java +++ b/app/src/main/java/io/github/chronosx88/influence/presenters/DialogListPresenter.java @@ -148,10 +148,7 @@ public class DialogListPresenter implements CoreContracts.IDialogListPresenterCo if(contacts != null) { StreamSupport.stream(contacts).forEach(contact -> { String chatID = contact.getJid().asUnescapedString(); - ArrayList users = new ArrayList<>(); - users.add(new GenericUser(AppHelper.getJid(), AppHelper.getJid().split("@")[0], AppHelper.getJid())); - users.add(new GenericUser(chatID, contact.getName() == null ? contact.getJid().asUnescapedString().split("@")[0] : contact.getName(), chatID)); - LocalDBWrapper.createChatEntry(chatID, contact.getName() == null ? contact.getJid().asUnescapedString().split("@")[0] : contact.getName(), users); + LocalDBWrapper.createChatEntry(chatID, contact.getName() == null ? contact.getJid().asUnescapedString().split("@")[0] : contact.getName(), new ArrayList<>()); GenericDialog dialog = new GenericDialog(LocalDBWrapper.getChatByChatID(chatID)); MessageEntity messageEntity = LocalDBWrapper.getLastMessage(chatID); if(messageEntity != null) { diff --git a/app/src/main/java/io/github/chronosx88/influence/presenters/MainPresenter.kt b/app/src/main/java/io/github/chronosx88/influence/presenters/MainPresenter.kt index b5f254f..963b480 100644 --- a/app/src/main/java/io/github/chronosx88/influence/presenters/MainPresenter.kt +++ b/app/src/main/java/io/github/chronosx88/influence/presenters/MainPresenter.kt @@ -48,10 +48,7 @@ class MainPresenter(private val view: CoreContracts.IMainViewContract) : CoreCon view.showSnackbar(AppHelper.getContext().getString(R.string.invalid_jid_error)) return } - val users = ArrayList() - users.add(GenericUser(AppHelper.getJid(), AppHelper.getJid().split("@")[0], AppHelper.getJid())) - users.add(GenericUser(username, username.split("@")[0], AppHelper.getJid())) - LocalDBWrapper.createChatEntry(username, username.split("@")[0], users) + LocalDBWrapper.createChatEntry(username, username.split("@")[0], ArrayList()) EventBus.getDefault().post(NewChatEvent(username)) }