EventReceiver: use setting to store enabled accounts
This commit is contained in:
parent
a288ad8d6b
commit
50d436fd81
|
@ -760,25 +760,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
return rows == 1;
|
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
|
@Override
|
||||||
public SQLiteDatabase getWritableDatabase() {
|
public SQLiteDatabase getWritableDatabase() {
|
||||||
SQLiteDatabase db = super.getWritableDatabase();
|
SQLiteDatabase db = super.getWritableDatabase();
|
||||||
|
|
|
@ -3,10 +3,17 @@ package eu.siacs.conversations.services;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.persistance.DatabaseBackend;
|
import eu.siacs.conversations.persistance.DatabaseBackend;
|
||||||
|
|
||||||
public class EventReceiver extends BroadcastReceiver {
|
public class EventReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Intent mIntentForService = new Intent(context, XmppConnectionService.class);
|
Intent mIntentForService = new Intent(context, XmppConnectionService.class);
|
||||||
|
@ -16,9 +23,15 @@ public class EventReceiver extends BroadcastReceiver {
|
||||||
mIntentForService.setAction("other");
|
mIntentForService.setAction("other");
|
||||||
}
|
}
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
if (action.equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) {
|
if (action.equals("ui") || hasEnabledAccounts(context)) {
|
||||||
context.startService(mIntentForService);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1748,9 +1748,14 @@ public class XmppConnectionService extends Service {
|
||||||
this.accounts.add(account);
|
this.accounts.add(account);
|
||||||
this.reconnectAccountInBackground(account);
|
this.reconnectAccountInBackground(account);
|
||||||
updateAccountUi();
|
updateAccountUi();
|
||||||
|
syncEnabledAccountSetting();
|
||||||
toggleForegroundService();
|
toggleForegroundService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void syncEnabledAccountSetting() {
|
||||||
|
getPreferences().edit().putBoolean(EventReceiver.SETTING_ENABLED_ACCOUNTS,hasEnabledAccounts()).apply();
|
||||||
|
}
|
||||||
|
|
||||||
public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
|
public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1823,6 +1828,7 @@ public class XmppConnectionService extends Service {
|
||||||
updateAccountUi();
|
updateAccountUi();
|
||||||
getNotificationService().updateErrorNotification();
|
getNotificationService().updateErrorNotification();
|
||||||
toggleForegroundService();
|
toggleForegroundService();
|
||||||
|
syncEnabledAccountSetting();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue