aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java16
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java20
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java18
-rw-r--r--src/main/java/de/pixart/messenger/services/EventReceiver.java15
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java15
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java12
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java23
9 files changed, 62 insertions, 63 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 5744d67a7..833b1eb3b 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -58,6 +58,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify";
private static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets";
public static final String ATTRIBUTE_LAST_CLEAR_HISTORY = "last_clear_history";
+ public static final String ATTRIBUTE_NEXT_MESSAGE = "next_message";
private String draftMessage;
private String name;
@@ -80,8 +81,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
private transient String otrFingerprint = null;
private Smp mSmp = new Smp();
- private String nextMessage;
-
private transient MucOptions mucOptions = null;
private byte[] symmetricKey;
@@ -788,19 +787,18 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
public String getNextMessage() {
- if (this.nextMessage == null) {
- return "";
- } else {
- return this.nextMessage;
- }
+ final String nextMessage = getAttribute(ATTRIBUTE_NEXT_MESSAGE);
+ return nextMessage == null ? "" : nextMessage;
}
public boolean smpRequested() {
return smp().status == Smp.STATUS_CONTACT_REQUESTED;
}
- public void setNextMessage(String message) {
- this.nextMessage = message;
+ public boolean setNextMessage(String message) {
+ boolean changed = !getNextMessage().equals(message);
+ this.setAttribute(ATTRIBUTE_NEXT_MESSAGE, message);
+ return changed;
}
public void setSymmetricKey(byte[] key) {
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/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 727892af0..350dfb7c9 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -149,17 +149,17 @@ public class FileBackend {
}
private static long getFileSize(Context context, Uri uri) {
- Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
- if (cursor != null && cursor.moveToFirst()) {
- long size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
- cursor.close();
- return size;
- } else {
- if (cursor != null) {
+ try {
+ final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
+ if (cursor != null && cursor.moveToFirst()) {
+ long size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
cursor.close();
+ return size;
+ } else {
+ return -1;
}
- File f = new File(uri.getPath());
- return f.length();
+ } catch (Exception e) {
+ return -1;
}
}
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..8293d39f0 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;
@@ -2491,6 +2497,15 @@ public class XmppConnectionService extends Service {
}
}
+ private boolean hasEnabledAccounts() {
+ for(Account account : this.accounts) {
+ if (!account.isOptionSet(Account.OPTION_DISABLED)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public void renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
final MucOptions options = conversation.getMucOptions();
final Jid joinJid = options.createJoinJid(nick);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index a23daa6c0..895ce5063 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -389,11 +389,7 @@ public class ConversationActivity extends XmppActivity
SharedPreferences.Editor editor = UpdateTimeStamp.edit();
editor.putLong("lastUpdateTime", lastUpdateTime);
editor.commit();
- // run AppUpdater
Log.d(Config.LOGTAG, "AppUpdater: CurrentTime: " + lastUpdateTime);
- //Intent AppUpdater = new Intent(this, UpdaterActivity.class);
- //startActivity(AppUpdater);
-
UpdateService task = new UpdateService(this);
task.execute("false");
Log.d(Config.LOGTAG, "AppUpdater started");
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index ff023997f..d1a007e3b 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -909,7 +909,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
if (this.conversation != null) {
final String msg = mEditMessage.getText().toString();
- this.conversation.setNextMessage(msg);
+ if (this.conversation.setNextMessage(msg)) {
+ activity.xmppConnectionService.updateConversation(this.conversation);
+ }
updateChatState(this.conversation, msg);
}
}
@@ -930,7 +932,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
setupIme();
if (this.conversation != null) {
final String msg = mEditMessage.getText().toString();
- this.conversation.setNextMessage(msg);
+ if (this.conversation.setNextMessage(msg)) {
+ activity.xmppConnectionService.updateConversation(conversation);
+ }
if (this.conversation != conversation) {
updateChatState(this.conversation, msg);
messageListAdapter.stopAudioPlayer();
@@ -1173,7 +1177,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
mEditMessage.append(conversation.getDraftMessage());
conversation.setDraftMessage(null);
}
- conversation.setNextMessage(mEditMessage.getText().toString());
+ if (conversation.setNextMessage(mEditMessage.getText().toString())) {
+ activity.xmppConnectionService.updateConversation(conversation);
+ }
updateChatMsgHint();
new Handler().post(new Runnable() {
@Override
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 0fe6e7600..bdf321dc3 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -377,8 +377,6 @@ public abstract class XmppActivity extends Activity {
break;
case R.id.action_check_updates:
if (xmppConnectionService.hasInternetConnection()) {
- //startActivity(new Intent(this, UpdaterActivity.class));
-
UpdateService task = new UpdateService(this);
task.execute("true");
} else {
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 7245a977d..c3693c24b 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -118,7 +118,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
};
- private ConversationActivity activity;
+ private final ConversationActivity activity;
private DisplayMetrics metrics;
@@ -815,9 +815,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.load_more_messages = (Button) view.findViewById(R.id.load_more_messages);
break;
default:
- view = new View(getContext());
- viewHolder = null;
- break;
+ throw new AssertionError("Unknown view type");
}
if (viewHolder.messageBody != null) {
listSelectionManager.onCreate(viewHolder.messageBody, new MessageBodyActionModeCallback(viewHolder.messageBody));
@@ -913,16 +911,13 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
} else {
displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground);
- if (viewHolder != null) {
- viewHolder.message_box
- .setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- activity.showInstallPgpDialog();
- }
- });
- }
+ viewHolder.message_box.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ activity.showInstallPgpDialog();
+ }
+ });
}
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
displayDecryptionFailed(viewHolder, darkBackground);