aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/AccountUtils.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-11-15 20:44:00 +0100
committerChristian Schneppe <christian@pix-art.de>2018-11-15 20:50:54 +0100
commitba3e6ffba2d27470c448be3c3e28c06b8932b8ee (patch)
tree623156f1dffea277483362499ec6cf3509445a39 /src/main/java/de/pixart/messenger/utils/AccountUtils.java
parentb81313d1db8261ba76ecbe0c2bc16ac26edac311 (diff)
refactored some ManageAccount, WelcomeActivity and a few other things
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/utils/AccountUtils.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/AccountUtils.java b/src/main/java/de/pixart/messenger/utils/AccountUtils.java
new file mode 100644
index 000000000..430ebb573
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/utils/AccountUtils.java
@@ -0,0 +1,59 @@
+package de.pixart.messenger.utils;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.widget.Toast;
+
+import java.util.List;
+
+import de.pixart.messenger.R;
+import de.pixart.messenger.entities.Account;
+import de.pixart.messenger.services.XmppConnectionService;
+
+public class AccountUtils {
+
+ public static final Class MANAGE_ACCOUNT_ACTIVITY;
+
+ static {
+ MANAGE_ACCOUNT_ACTIVITY = getManageAccountActivityClass();
+ }
+
+
+ public static Account getFirstEnabled(XmppConnectionService service) {
+ final List<Account> accounts = service.getAccounts();
+ for (Account account : accounts) {
+ if (!account.isOptionSet(Account.OPTION_DISABLED)) {
+ return account;
+ }
+ }
+ return null;
+ }
+
+ public static Account getPendingAccount(XmppConnectionService service) {
+ Account pending = null;
+ for (Account account : service.getAccounts()) {
+ if (!account.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY)) {
+ pending = account;
+ } else {
+ return null;
+ }
+ }
+ return pending;
+ }
+
+ public static void launchManageAccounts(Activity activity) {
+ if (MANAGE_ACCOUNT_ACTIVITY != null) {
+ activity.startActivity(new Intent(activity, MANAGE_ACCOUNT_ACTIVITY));
+ } else {
+ Toast.makeText(activity, R.string.feature_not_implemented, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ private static Class getManageAccountActivityClass() {
+ try {
+ return Class.forName("de.pixart.messenger.ui.ManageAccountActivity");
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
+ }
+} \ No newline at end of file