diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils')
3 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java index f8310206..afb8387d 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java @@ -6,8 +6,11 @@ import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; +import de.thedevstack.conversationsplus.ConversationsPlusApplication; + import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.persistance.FileBackend; /** @@ -15,6 +18,17 @@ import eu.siacs.conversations.persistance.FileBackend; */ public final class MessageUtil { + public static void markMessage(Message message, int status) { + if (status == Message.STATUS_SEND_FAILED + && (message.getStatus() == Message.STATUS_SEND_RECEIVED || message + .getStatus() == Message.STATUS_SEND_DISPLAYED)) { + return; + } + message.setStatus(status); + DatabaseBackend.getInstance(ConversationsPlusApplication.getAppContext()).updateMessage(message); + UiUpdateHelper.updateConversationUi(); + } + public static boolean wasHighlightedOrPrivate(final Message message) { final String nick = message.getConversation().getMucOptions().getActualNick(); final Pattern highlight = generateNickHighlightPattern(nick); diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/XmppConnectionServiceAccessor.java b/src/main/java/de/thedevstack/conversationsplus/utils/XmppConnectionServiceAccessor.java new file mode 100644 index 00000000..20cd7361 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/XmppConnectionServiceAccessor.java @@ -0,0 +1,32 @@ +package de.thedevstack.conversationsplus.utils; + +import de.thedevstack.android.logcat.Logging; + +import eu.siacs.conversations.services.XmppConnectionService; + +/** + * Accessor utility to access XmppConnectionService without having to pass the XmppConnectionService every time. + */ +public final class XmppConnectionServiceAccessor { + public static XmppConnectionService xmppConnectionService; + + /** + * Initializes the XmppConnectionService. + * This method needs to be called once in XmppConnectionService#onCreate. + * @param xmppConnectionService + */ + public static void initXmppConnectionService(XmppConnectionService xmppConnectionService) { + if (null == XmppConnectionServiceAccessor.xmppConnectionService) { + XmppConnectionServiceAccessor.xmppConnectionService = xmppConnectionService; + } else { + Logging.e("XmppConnectionServiceAccessor", "XMPP Connection Service already instantiated."); + } + } + + /** + * Avoid instantiation + */ + private XmppConnectionServiceAccessor() { + // avoid instantiation + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java index bb08014b..a775dad6 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java @@ -1,12 +1,28 @@ package de.thedevstack.conversationsplus.utils.ui; import android.support.annotation.StringRes; +import android.view.View; import android.widget.TextView; /** * Created by steckbrief on 29.03.2016. */ public final class TextViewUtil { + + public static void setText(View parentView, int textViewId, CharSequence text) { + TextView tv = (TextView) parentView.findViewById(textViewId); + if (null != tv) { + tv.setText(text); + } + } + + public static void setText(View parentView, int textViewId, int textResId) { + TextView tv = (TextView) parentView.findViewById(textViewId); + if (null != tv) { + tv.setText(textResId); + } + } + public static void enable(TextView tv) { setColorEnabledAndTextResId(tv, null, true, null); } |