From 990a35c47500c6a3f4292d41450a5f6cb689c7b1 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Wed, 11 Jan 2017 14:47:25 +0100 Subject: Custom toast view added --- .../utils/ui/ConversationsPlusToast.java | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/ui/ConversationsPlusToast.java (limited to 'src/main/java/de/thedevstack/conversationsplus/utils') diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ui/ConversationsPlusToast.java b/src/main/java/de/thedevstack/conversationsplus/utils/ui/ConversationsPlusToast.java new file mode 100644 index 00000000..3576d1cd --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ui/ConversationsPlusToast.java @@ -0,0 +1,101 @@ +package de.thedevstack.conversationsplus.utils.ui; + +import android.content.Context; +import android.os.Handler; +import android.os.Looper; +import android.support.annotation.StringRes; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.Toast; + +import de.thedevstack.conversationsplus.ConversationsPlusApplication; +import de.thedevstack.conversationsplus.R; + +/** + * Wrapper for custom styled Toasts for Conversations+. + */ +public final class ConversationsPlusToast { + + /** + * Creates an error toast with text and duration + * @param text + * @param duration + */ + public static void makeErrorToast(final CharSequence text, final int duration) { + Handler toastHandler = new Handler(Looper.getMainLooper()); + toastHandler.post(new ConversationsPlusToast.ToastRunnable(text, duration, true)); + } + + /** + * Creates an error toast with text from resource and duration + * @param resId + * @param duration + */ + public static void makeErrorToast(@StringRes int resId, int duration) { + makeErrorToast(ConversationsPlusApplication.getAppContext().getString(resId), duration); + } + + /** + * Creates an toast with text and duration + * @param text + * @param duration + */ + public static void makeToast(final CharSequence text, final int duration) { + Handler toastHandler = new Handler(Looper.getMainLooper()); + toastHandler.post(new ConversationsPlusToast.ToastRunnable(text, duration)); + } + + /** + * Creates an toast with text from resource and duration + * @param resId + * @param duration + */ + public static void makeToast(@StringRes int resId, int duration) { + makeToast(ConversationsPlusApplication.getAppContext().getString(resId), duration); + } + + private ConversationsPlusToast() { + // avoid instantiation - helper class + } + + /** + * Runnable to show the toast in an UI thread. + */ + static class ToastRunnable implements Runnable { + private boolean showErrorToast = false; + private CharSequence text; + private int duration; + + public ToastRunnable(CharSequence text, int duration, boolean isError) { + this.showErrorToast = isError; + this.text = text; + this.duration = duration; + } + + public ToastRunnable(CharSequence text, int duration) { + this.text = text; + this.duration = duration; + } + + @Override + public void run() { + Context applicationContext = ConversationsPlusApplication.getAppContext(); + LayoutInflater inflater = LayoutInflater.from(applicationContext); + View layout = inflater.inflate(R.layout.cplus_toast_container, null); + + TextViewUtil.setText(layout, R.id.cplus_toast_txt, text); + + if (this.showErrorToast) { + // Set image view to error icon + ImageView iv = (ImageView) layout.findViewById(R.id.cplus_toast_icon); + iv.setImageResource(R.drawable.ic_toast_error); + } + + Toast toast = new Toast(applicationContext); + toast.setDuration(duration); + toast.setView(layout); + toast.show(); + } + } +} -- cgit v1.2.3 From 563fcfa77580292a7ff2360eea20553743bd0ae7 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Wed, 11 Jan 2017 14:49:07 +0100 Subject: Generic view util added to change the visibility of subclasses of View --- .../conversationsplus/utils/ui/TextViewUtil.java | 4 +-- .../conversationsplus/utils/ui/ViewUtil.java | 39 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/ui/ViewUtil.java (limited to 'src/main/java/de/thedevstack/conversationsplus/utils') 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 a775dad6..27a269f2 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java @@ -5,9 +5,9 @@ import android.view.View; import android.widget.TextView; /** - * Created by steckbrief on 29.03.2016. + * */ -public final class TextViewUtil { +public final class TextViewUtil extends ViewUtil { public static void setText(View parentView, int textViewId, CharSequence text) { TextView tv = (TextView) parentView.findViewById(textViewId); diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ui/ViewUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ui/ViewUtil.java new file mode 100644 index 00000000..77422587 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ui/ViewUtil.java @@ -0,0 +1,39 @@ +package de.thedevstack.conversationsplus.utils.ui; + +import android.support.annotation.IdRes; +import android.view.View; + +/** + * Created by steckbrief on 11.01.2017. + */ + +public class ViewUtil { + + public static T visible(View parentView, @IdRes int textViewId) { + T tv = (T) parentView.findViewById(textViewId); + if (null != tv) { + tv.setVisibility(View.VISIBLE); + } + + return tv; + } + + public static T invisible(View parentView, @IdRes int textViewId) { + T tv = (T) parentView.findViewById(textViewId); + if (null != tv) { + tv.setVisibility(View.INVISIBLE); + } + + return tv; + } + + public static T gone(View parentView, @IdRes int textViewId) { + T tv = (T) parentView.findViewById(textViewId); + if (null != tv) { + tv.setVisibility(View.GONE); + } + + return tv; + } + +} -- cgit v1.2.3 From 0a9bba28616e594279cd659ec2eb57da2074b3cd Mon Sep 17 00:00:00 2001 From: steckbrief Date: Wed, 11 Jan 2017 14:55:53 +0100 Subject: Improved error handling for filetransfer:http:delete, Check for httpupload feature available extended to include filetransfer:http as well, method to check if http upload is available moved from data class 'Account' to 'AccountUtil' --- .../conversationsplus/utils/AccountUtil.java | 34 ++++++++++++++++++++++ .../thedevstack/conversationsplus/utils/Xmlns.java | 3 -- 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/AccountUtil.java (limited to 'src/main/java/de/thedevstack/conversationsplus/utils') diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/AccountUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/AccountUtil.java new file mode 100644 index 00000000..0ea434f7 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/AccountUtil.java @@ -0,0 +1,34 @@ +package de.thedevstack.conversationsplus.utils; + +import de.thedevstack.conversationsplus.entities.Account; + +/** + * Utility class to work with accounts. + */ +public final class AccountUtil { + + public static boolean isHttpUploadAvailable(Account account, long filesize) { + return null != account + && null != account.getXmppConnection() + && null != account.getXmppConnection().getFeatures() + && account.getXmppConnection().getFeatures().httpUpload(filesize); + } + + public static boolean isHttpUploadAvailable(Account account) { + return null != account + && null != account.getXmppConnection() + && null != account.getXmppConnection().getFeatures() + && account.getXmppConnection().getFeatures().httpUpload(0); + } + + public static boolean isFileTransferHttpAvailable(Account account) { + return null != account + && null != account.getXmppConnection() + && null != account.getXmppConnection().getFeatures() + && account.getXmppConnection().getFeatures().hasFeatureFileTransferHttp(0); + } + + private AccountUtil() { + // avoid instantiation of utility class + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/Xmlns.java b/src/main/java/de/thedevstack/conversationsplus/utils/Xmlns.java index 35adf6ec..80718dec 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/Xmlns.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/Xmlns.java @@ -1,11 +1,8 @@ package de.thedevstack.conversationsplus.utils; -import de.thedevstack.conversationsplus.Config; - public final class Xmlns { public static final String BLOCKING = "urn:xmpp:blocking"; public static final String ROSTER = "jabber:iq:roster"; public static final String REGISTER = "jabber:iq:register"; public static final String BYTE_STREAMS = "http://jabber.org/protocol/bytestreams"; - public static final String HTTP_UPLOAD = "urn:xmpp:http:upload"; } -- cgit v1.2.3