aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java20
-rw-r--r--src/main/java/de/pixart/messenger/services/EventReceiver.java15
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java6
3 files changed, 19 insertions, 22 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
index 07ff600d6..e88db114a 100644
--- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
@@ -4,7 +4,6 @@ import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
-import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
@@ -772,25 +771,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return rows == 1;
}
- public boolean hasEnabledAccounts() {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.rawQuery("select count(" + Account.UUID + ") from "
- + Account.TABLENAME + " where not options & (1 <<1)", null);
- try {
- cursor.moveToFirst();
- int count = cursor.getInt(0);
- return (count > 0);
- } catch (SQLiteCantOpenDatabaseException e) {
- return true; // better safe than sorry
- } catch (RuntimeException e) {
- return true; // better safe than sorry
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- }
-
@Override
public SQLiteDatabase getWritableDatabase() {
SQLiteDatabase db = super.getWritableDatabase();
diff --git a/src/main/java/de/pixart/messenger/services/EventReceiver.java b/src/main/java/de/pixart/messenger/services/EventReceiver.java
index 615bc98b3..cdd1afe19 100644
--- a/src/main/java/de/pixart/messenger/services/EventReceiver.java
+++ b/src/main/java/de/pixart/messenger/services/EventReceiver.java
@@ -3,10 +3,15 @@ package de.pixart.messenger.services;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.preference.PreferenceManager;
+import android.util.Log;
-import de.pixart.messenger.persistance.DatabaseBackend;
+import de.pixart.messenger.Config;
public class EventReceiver extends BroadcastReceiver {
+
+ public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts";
+
@Override
public void onReceive(Context context, Intent intent) {
Intent mIntentForService = new Intent(context, XmppConnectionService.class);
@@ -16,9 +21,15 @@ public class EventReceiver extends BroadcastReceiver {
mIntentForService.setAction("other");
}
final String action = intent.getAction();
- if (action.equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) {
+ if (action.equals("ui") || hasEnabledAccounts(context)) {
context.startService(mIntentForService);
+ } else {
+ Log.d(Config.LOGTAG, "EventReceiver ignored action " + mIntentForService.getAction());
}
}
+ public boolean hasEnabledAccounts(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS, true);
+ }
+
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 519cec043..ae22d205e 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -1922,9 +1922,14 @@ public class XmppConnectionService extends Service {
this.accounts.add(account);
this.reconnectAccountInBackground(account);
updateAccountUi();
+ syncEnabledAccountSetting();
toggleForegroundService();
}
+ private void syncEnabledAccountSetting() {
+ getPreferences().edit().putBoolean(EventReceiver.SETTING_ENABLED_ACCOUNTS, hasEnabledAccounts()).apply();
+ }
+
public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
new Thread(new Runnable() {
@Override
@@ -1997,6 +2002,7 @@ public class XmppConnectionService extends Service {
updateAccountUi();
getNotificationService().updateErrorNotification();
toggleForegroundService();
+ syncEnabledAccountSetting();
return true;
} else {
return false;