aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-10-21 23:49:06 +0200
committersteckbrief <steckbrief@chefmail.de>2015-10-21 23:49:06 +0200
commit85a25984f4bf4dfa2432fbc2c92f8117cf927fcf (patch)
treeb13aa11f4ce0be81e2b03cf74a00a33e03b2399f
parent1d9b4e959d70c2f008574f9a75c7eeb4b47c63ef (diff)
Access to preferences moved to global utility class ConversationsPlusPreferences. Unused imports removed. Unnecessary references to XmppConnectionService removed. Bug in call order in StartConversationActivity for the setting hide_offline fixed.
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java294
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java10
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/AbstractConnectionManager.java10
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java30
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java226
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java162
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java23
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java10
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java26
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java8
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java11
-rw-r--r--src/main/java/de/tzur/conversations/Settings.java11
24 files changed, 532 insertions, 350 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
index dfe67cb7..5c669650 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
@@ -3,6 +3,7 @@ package de.thedevstack.conversationsplus;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.preference.PreferenceManager;
import java.io.File;
@@ -21,6 +22,7 @@ public class ConversationsPlusApplication extends Application {
public void onCreate(){
super.onCreate();
ConversationsPlusApplication.instance = this;
+ ConversationsPlusPreferences.init(PreferenceManager.getDefaultSharedPreferences(getAppContext()));
}
/**
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java
new file mode 100644
index 00000000..788aed41
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java
@@ -0,0 +1,294 @@
+package de.thedevstack.conversationsplus;
+
+import android.content.SharedPreferences;
+
+import java.util.Set;
+
+import de.tzur.conversations.Settings;
+
+/**
+ * Utility Class to access shared preferences of Conversations+.
+ */
+public class ConversationsPlusPreferences extends Settings {
+ private static ConversationsPlusPreferences instance;
+ private final SharedPreferences sharedPreferences;
+
+ public static boolean showDynamicTags() {
+ return getBoolean("show_dynamic_tags", false);
+ }
+
+ /**
+ * Whether to send report to developer or not.
+ * @return
+ */
+ public static boolean neverSend() {
+ return getBoolean("never_send", false);
+ }
+
+ public static void applyNeverSend(boolean neverSend) {
+ applyBoolean("never_send", neverSend);
+ }
+
+ /**
+ * The name used for the resource part of the accounts' JID.
+ * @return the resource name, <i>mobile</i> as default value
+ */
+ public static String resource() {
+ return getString("resource", "mobile");
+ }
+
+ /**
+ * Whether to enable legacy SSL support.
+ * @return <code>true</code>if legacy support for SSL is enabled, <i>false</i> as default value
+ */
+ public static boolean enableLegacySSL() {
+ return getBoolean("enable_legacy_ssl", false);
+ }
+
+ public static boolean useSubject() {
+ return getBoolean("use_subject", true);
+ }
+
+ public static boolean displayEnterKey() {
+ return getBoolean("display_enter_key", false);
+ }
+
+ public static boolean useLargerFont() {
+ return getBoolean("use_larger_font", false);
+ }
+
+ public static boolean hideOffline() {
+ return getBoolean("hide_offline", false);
+ }
+
+ public static void commitHideOffline(boolean hideOffline) {
+ commitBoolean("hide_offline", hideOffline);
+ }
+
+ public static String recentlyUsedQuickAction() {
+ return getString("recently_used_quick_action", "text");
+ }
+
+ public static void applyRecentlyUsedQuickAction(String recentlyUsedQuickAction) {
+ applyString("recently_used_quick_action", recentlyUsedQuickAction);
+ }
+
+ public static String quickAction() {
+ return getString("quick_action", "recent");
+ }
+
+ public static boolean sendButtonStatus() {
+ return getBoolean("send_button_status", false);
+ }
+
+ public static boolean enterIsSend() {
+ return getBoolean("enter_is_send", false);
+ }
+
+ public static long autoAcceptFileSize() {
+ return getLongFromStringPref("auto_accept_file_size", 524288);
+ }
+
+ public static boolean vibrateOnNotification() {
+ return getBoolean("vibrate_on_notification", true);
+ }
+
+ public static String notificationRingtone() {
+ return getString("notification_ringtone", null);
+ }
+
+ public static boolean alwaysNotifyInConference() {
+ return getBoolean("always_notify_in_conference", false);
+ }
+
+ public static boolean showNotification() {
+ return getBoolean("show_notification", true);
+ }
+
+ public static long quietHoursEnd() {
+ return getLong("quiet_hours_end", 0);
+ }
+
+ public static long quietHoursStart() {
+ return getLong("quiet_hours_start", 0);
+ }
+
+ public static boolean enableQuietHours() {
+ return getBoolean("enable_quiet_hours", false);
+ }
+
+ public static boolean dontTrustSystemCAs() {
+ return getBoolean("dont_trust_system_cas", false);
+ }
+
+ public static boolean grantNewContacts() {
+ return getBoolean("grant_new_contacts", true);
+ }
+
+ public static boolean keepForegroundService() {
+ return getBoolean("keep_foreground_service", false);
+ }
+
+ public static void commitKeepForegroundService(boolean keepForegroundService) {
+ commitBoolean("keep_foreground_service", keepForegroundService);
+ }
+
+ public static boolean forceEncryption() {
+ return getBoolean("force_encryption", false);
+ }
+ public static boolean confirmMessages() {
+ return getBoolean("confirm_messages", true);
+ }
+
+ public static boolean dontSaveEncrypted() {
+ return getBoolean("dont_save_encrypted", false);
+ }
+
+ /**
+ * Whether the chat states should be send or not.
+ * @return
+ */
+ public static boolean chatStates() {
+ return getBoolean("chat_states", false);
+ }
+
+ /**
+ * Whether the receipient notification should be requested from the counterpart or not.
+ * <br>Default value is <code>false</code>
+ * @return <code>true</code> if the receipt should be requested, <code>false</code> otherwise
+ */
+ public static boolean indicateReceived() {
+ return getBoolean("indicate_received", false);
+ }
+
+ private ConversationsPlusPreferences(SharedPreferences sharedPreferences) {
+ this.sharedPreferences = sharedPreferences;
+ }
+
+ public synchronized static void init(SharedPreferences sharedPreferences) {
+ if (null == instance) {
+ instance = new ConversationsPlusPreferences(sharedPreferences);
+ initSettingsClassWithPreferences(sharedPreferences);
+ }
+ }
+
+ private static SharedPreferences getSharedPreferences() {
+ return instance.sharedPreferences;
+ }
+
+ private static SharedPreferences.Editor getSharedPreferencesEditor() {
+ return getSharedPreferences().edit();
+ }
+
+ private static String getString(String key, String defValue) {
+ return getSharedPreferences().getString(key, defValue);
+ }
+
+ private static float getFloat(String key, float defValue) {
+ return getSharedPreferences().getFloat(key, defValue);
+ }
+
+ private static float getFloatFromStringPref(String key, float defValue) {
+ try {
+ return Float.parseFloat(getString(key, String.valueOf(defValue)));
+ } catch (NumberFormatException e) {
+ return defValue;
+ }
+ }
+
+ private static int getInt(String key, int defValue) {
+ return getSharedPreferences().getInt(key, defValue);
+ }
+
+ private static int getIntFromStringPref(String key, int defValue) {
+ try {
+ return Integer.parseInt(getString(key, String.valueOf(defValue)));
+ } catch (NumberFormatException e) {
+ return defValue;
+ }
+ }
+
+ private static Set<String> getStringSet(String key, Set<String> defValues) {
+ return getSharedPreferences().getStringSet(key, defValues);
+ }
+
+ private static boolean contains(String key) {
+ return getSharedPreferences().contains(key);
+ }
+
+ private static long getLong(String key, long defValue) {
+ return getSharedPreferences().getLong(key, defValue);
+ }
+
+ private static long getLongFromStringPref(String key, long defValue) {
+ try {
+ return Long.parseLong(getString(key, String.valueOf(defValue)));
+ } catch (NumberFormatException e) {
+ return defValue;
+ }
+ }
+
+ private static boolean getBoolean(String key, boolean defValue) {
+ return getSharedPreferences().getBoolean(key, defValue);
+ }
+
+ private static void commitBoolean(String key, boolean value) {
+ putBoolean(key, value).commit();
+ }
+
+ private static void applyBoolean(String key, boolean value) {
+ putBoolean(key, value).apply();
+ }
+
+ private static SharedPreferences.Editor putBoolean(String key, boolean value) {
+ return getSharedPreferencesEditor().putBoolean(key, value);
+ }
+
+ private static void commitString(String key, String value) {
+ putString(key, value).commit();
+ }
+
+ private static void applyString(String key, String value) {
+ putString(key, value).apply();
+ }
+
+ private static SharedPreferences.Editor putString(String key, String value) {
+ return getSharedPreferencesEditor().putString(key, value);
+ }
+
+ private static void commitInt(String key, int value) {
+ putInt(key, value).commit();
+ }
+
+ private static void applyInt(String key, int value) {
+ putInt(key, value).apply();
+ }
+
+ private static SharedPreferences.Editor putInt(String key, int value) {
+ return getSharedPreferencesEditor().putInt(key, value);
+ }
+
+ private static void commitLong(String key, long value) {
+ putLong(key, value).commit();
+ }
+
+ private static void applyLong(String key, long value) {
+ putLong(key, value).apply();
+ }
+
+ private static SharedPreferences.Editor putLong(String key, long value) {
+ return getSharedPreferencesEditor().putLong(key, value);
+ }
+
+ private static void commitFloat(String key, float value) {
+ putFloat(key, value).commit();
+ }
+
+ private static void applyLong(String key, float value) {
+ putFloat(key, value).apply();
+ }
+
+ private static SharedPreferences.Editor putFloat(String key, float value) {
+ return getSharedPreferencesEditor().putFloat(key, value);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java b/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java
index ee7f492f..c9ee53ae 100644
--- a/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java
@@ -17,6 +17,7 @@ import org.json.JSONObject;
import android.util.Log;
import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
@@ -188,7 +189,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost {
Jid jid = Jid.fromSessionID(session);
Conversation conversation = mXmppConnectionService.find(account,jid);
if (conversation != null && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
- if (mXmppConnectionService.sendChatStates()) {
+ if (ConversationsPlusPreferences.chatStates()) {
packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
index 8d4b3c27..e26f7944 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
@@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.List;
import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -764,7 +765,7 @@ public class Conversation extends AbstractEntity implements Blockable {
return count;
}
if (getMode() == Conversation.MODE_SINGLE
- || account.getXmppConnectionService().getNotificationService().conferenceNotificationsEnabled()
+ || ConversationsPlusPreferences.alwaysNotifyInConference()
|| account.getXmppConnectionService().getNotificationService().wasHighlightedOrPrivate(message)
) {
++count;
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java
index 3f4bb839..5a6c6ebf 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java
@@ -14,7 +14,6 @@ import java.util.TimeZone;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.tzur.conversations.Settings;
-import de.thedevstack.conversationsplus.services.XmppConnectionService;
public abstract class AbstractGenerator {
private final String[] FEATURES = {
@@ -39,12 +38,6 @@ public abstract class AbstractGenerator {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
- protected XmppConnectionService mXmppConnectionService;
-
- protected AbstractGenerator(XmppConnectionService service) {
- this.mXmppConnectionService = service;
- }
-
public String getCapHash() {
StringBuilder s = new StringBuilder();
s.append("client/" + IDENTITY_TYPE + "//" + ConversationsPlusApplication.getNameAndVersion() + "<");
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
index 3382ee23..3d3dd360 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
@@ -1,6 +1,5 @@
package de.thedevstack.conversationsplus.generator;
-
import java.util.ArrayList;
import java.util.List;
@@ -9,7 +8,6 @@ import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.DownloadableFile;
import de.thedevstack.conversationsplus.services.MessageArchiveService;
-import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.utils.Xmlns;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.forms.Data;
@@ -19,10 +17,6 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
public class IqGenerator extends AbstractGenerator {
- public IqGenerator(final XmppConnectionService service) {
- super(service);
- }
-
public IqPacket discoResponse(final IqPacket request) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT);
packet.setId(request.getId());
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
index fa327141..af496fe1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
@@ -7,19 +7,17 @@ import java.util.TimeZone;
import net.java.otr4j.OtrException;
import net.java.otr4j.session.Session;
+
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
-import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.MessagePacket;
public class MessageGenerator extends AbstractGenerator {
- public MessageGenerator(XmppConnectionService service) {
- super(service);
- }
private MessagePacket preparePacket(Message message, boolean addDelay) {
Conversation conversation = message.getConversation();
@@ -29,13 +27,13 @@ public class MessageGenerator extends AbstractGenerator {
packet.setTo(message.getCounterpart());
packet.setType(MessagePacket.TYPE_CHAT);
packet.addChild("markable", "urn:xmpp:chat-markers:0");
- if (this.mXmppConnectionService.indicateReceived()) {
+ if (ConversationsPlusPreferences.indicateReceived()) {
packet.addChild("request", "urn:xmpp:receipts");
}
} else if (message.getType() == Message.TYPE_PRIVATE) {
packet.setTo(message.getCounterpart());
packet.setType(MessagePacket.TYPE_CHAT);
- if (this.mXmppConnectionService.indicateReceived()) {
+ if (ConversationsPlusPreferences.indicateReceived()) {
packet.addChild("request", "urn:xmpp:receipts");
}
} else {
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java
index 896aad71..1656bd51 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java
@@ -2,16 +2,11 @@ package de.thedevstack.conversationsplus.generator;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
-import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.stanzas.PresencePacket;
public class PresenceGenerator extends AbstractGenerator {
- public PresenceGenerator(XmppConnectionService service) {
- super(service);
- }
-
private PresencePacket subscription(String type, Contact contact) {
PresencePacket packet = new PresencePacket();
packet.setAttribute("type", type);
diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
index 1977e126..2969a18d 100644
--- a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
@@ -6,7 +6,7 @@ import android.util.Pair;
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus;
-import de.tzur.conversations.Settings;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
@@ -339,7 +339,7 @@ public class MessageParser extends AbstractParser implements
mXmppConnectionService.updateConversationUi();
}
- if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded) {
+ if (ConversationsPlusPreferences.confirmMessages() && remoteMsgId != null && !isForwarded) {
if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) {
MessagePacket receipt = mXmppConnectionService
.getMessageGenerator().received(account, packet, "urn:xmpp:chat-markers:0");
@@ -364,7 +364,7 @@ public class MessageParser extends AbstractParser implements
conversation.endOtrIfNeeded();
}
- if (message.getEncryption() == Message.ENCRYPTION_NONE || mXmppConnectionService.saveEncryptedMessages()) {
+ if (message.getEncryption() == Message.ENCRYPTION_NONE || !ConversationsPlusPreferences.dontSaveEncrypted()) {
mXmppConnectionService.databaseBackend.createMessage(message);
}
final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/AbstractConnectionManager.java b/src/main/java/de/thedevstack/conversationsplus/services/AbstractConnectionManager.java
index 0dedc01d..00c78348 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/AbstractConnectionManager.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/AbstractConnectionManager.java
@@ -1,5 +1,7 @@
package de.thedevstack.conversationsplus.services;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+
public class AbstractConnectionManager {
protected XmppConnectionService mXmppConnectionService;
@@ -12,12 +14,6 @@ public class AbstractConnectionManager {
}
public long getAutoAcceptFileSize() {
- String config = this.mXmppConnectionService.getPreferences().getString(
- "auto_accept_file_size", "524288");
- try {
- return Long.parseLong(config);
- } catch (NumberFormatException e) {
- return 524288;
- }
+ return ConversationsPlusPreferences.autoAcceptFileSize();
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java b/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java
index e6692d40..1536e8b1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java
@@ -6,7 +6,6 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
@@ -32,6 +31,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
@@ -40,7 +40,6 @@ import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.ui.ConversationActivity;
import de.thedevstack.conversationsplus.ui.ManageAccountActivity;
-import de.thedevstack.conversationsplus.ui.TimePreference;
import de.thedevstack.conversationsplus.utils.GeoHelper;
import de.thedevstack.conversationsplus.utils.UIHelper;
@@ -64,10 +63,10 @@ public class NotificationService {
public boolean notify(final Message message) {
return (message.getStatus() == Message.STATUS_RECEIVED)
- && notificationsEnabled()
+ && ConversationsPlusPreferences.showNotification()
&& !message.getConversation().isMuted()
&& (message.getConversation().getMode() == Conversation.MODE_SINGLE
- || conferenceNotificationsEnabled()
+ || ConversationsPlusPreferences.alwaysNotifyInConference()
|| wasHighlightedOrPrivate(message)
);
}
@@ -93,17 +92,12 @@ public class NotificationService {
mXmppConnectionService.sendBroadcast(i);
}
-
- public boolean notificationsEnabled() {
- return mXmppConnectionService.getPreferences().getBoolean("show_notification", true);
- }
-
public boolean isQuietHours() {
- if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) {
+ if (!ConversationsPlusPreferences.enableQuietHours()) {
return false;
}
- final long startTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
- final long endTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
+ final long startTime = ConversationsPlusPreferences.quietHoursStart() % Config.MILLISECONDS_IN_DAY;
+ final long endTime = ConversationsPlusPreferences.quietHoursEnd() % Config.MILLISECONDS_IN_DAY;
final long nowTime = Calendar.getInstance().getTimeInMillis() % Config.MILLISECONDS_IN_DAY;
if (endTime < startTime) {
@@ -113,10 +107,6 @@ public class NotificationService {
}
}
- public boolean conferenceNotificationsEnabled() {
- return mXmppConnectionService.getPreferences().getBoolean("always_notify_in_conference", false);
- }
-
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private boolean isInteractive() {
@@ -184,12 +174,10 @@ public class NotificationService {
}
private void updateNotification(final boolean notify) {
- final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
- .getSystemService(Context.NOTIFICATION_SERVICE);
- final SharedPreferences preferences = mXmppConnectionService.getPreferences();
+ final NotificationManager notificationManager = (NotificationManager) ConversationsPlusApplication.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE);
- final String ringtone = preferences.getString("notification_ringtone", null);
- final boolean vibrate = preferences.getBoolean("vibrate_on_notification", true);
+ final String ringtone = ConversationsPlusPreferences.notificationRingtone();
+ final boolean vibrate = ConversationsPlusPreferences.vibrateOnNotification();
if (notifications.size() == 0) {
notificationManager.cancel(NOTIFICATION_ID);
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index 5e529f3c..212bc76a 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -6,7 +6,6 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
@@ -20,7 +19,6 @@ import android.os.Looper;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
-import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.util.Log;
import android.util.LruCache;
@@ -49,6 +47,7 @@ import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import de.duenndns.ssl.MemorizingTrustManager;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
@@ -175,7 +174,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
};
- private final IqGenerator mIqGenerator = new IqGenerator(this);
+ private final IqGenerator mIqGenerator = new IqGenerator();
public DatabaseBackend databaseBackend;
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
@@ -222,8 +221,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
};
- private MessageGenerator mMessageGenerator = new MessageGenerator(this);
- private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
+ private MessageGenerator mMessageGenerator = new MessageGenerator();
+ private PresenceGenerator mPresenceGenerator = new PresenceGenerator();
private List<Account> accounts;
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
this);
@@ -343,7 +342,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void attachLocationToConversation(final Conversation conversation,
final Uri uri,
final UiCallback<Message> callback) {
- int encryption = conversation.getNextEncryption(forceEncryption());
+ int encryption = conversation.getNextEncryption(ConversationsPlusPreferences.forceEncryption());
if (encryption == Message.ENCRYPTION_PGP) {
encryption = Message.ENCRYPTION_DECRYPTED;
}
@@ -362,12 +361,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final Uri uri,
final UiCallback<Message> callback) {
final Message message;
- if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) {
+ boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
+ if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "",
Message.ENCRYPTION_DECRYPTED);
} else {
message = new Message(conversation, "",
- conversation.getNextEncryption(forceEncryption()));
+ conversation.getNextEncryption(forceEncryption));
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_FILE);
@@ -403,12 +403,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void attachImageToConversation(final Conversation conversation,
final Uri uri, final UiCallback<Message> callback) {
final Message message;
- if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) {
+ final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
+ if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "",
Message.ENCRYPTION_DECRYPTED);
} else {
message = new Message(conversation, "",
- conversation.getNextEncryption(forceEncryption()));
+ conversation.getNextEncryption(forceEncryption));
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
@@ -418,7 +419,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void run() {
try {
getFileBackend().copyImageToPrivateStorage(message, uri);
- if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
@@ -462,7 +463,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
mNotificationService.clear();
break;
case ACTION_DISABLE_FOREGROUND:
- getPreferences().edit().putBoolean("keep_foreground_service",false).commit();
+ ConversationsPlusPreferences.commitKeepForegroundService(false);
toggleForegroundService();
break;
case ACTION_TRY_AGAIN:
@@ -555,7 +556,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
private void resetAllAttemptCounts(boolean reallyAll) {
- Log.d(Config.LOGTAG,"resetting all attepmt counts");
+ Log.d(Config.LOGTAG, "resetting all attepmt counts");
for(Account account : accounts) {
if (account.hasErrorStatus() || reallyAll) {
final XmppConnection connection = account.getXmppConnection();
@@ -628,7 +629,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void toggleForegroundService() {
- if (getPreferences().getBoolean("keep_foreground_service",false)) {
+ if (ConversationsPlusPreferences.keepForegroundService()) {
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
} else {
stopForeground(true);
@@ -638,7 +639,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onTaskRemoved(final Intent rootIntent) {
super.onTaskRemoved(rootIntent);
- if (!getPreferences().getBoolean("keep_foreground_service",false)) {
+ if (!ConversationsPlusPreferences.keepForegroundService()) {
this.logoutAndSave();
}
}
@@ -672,9 +673,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public XmppConnection createConnection(final Account account) {
- final SharedPreferences sharedPref = getPreferences();
- account.setResource(sharedPref.getString("resource", "mobile")
- .toLowerCase(Locale.getDefault()));
+ account.setResource(ConversationsPlusPreferences.resource().toLowerCase(Locale.getDefault()));
final XmppConnection connection = new XmppConnection(account, this);
connection.setOnMessagePacketReceivedListener(this.mMessageParser);
connection.setOnStatusChangedListener(this.statusListener);
@@ -688,7 +687,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void sendChatState(Conversation conversation) {
- if (sendChatStates()) {
+ if (ConversationsPlusPreferences.chatStates()) {
MessagePacket packet = mMessageGenerator.generateChatState(conversation);
sendMessagePacket(conversation.getAccount(), packet);
}
@@ -813,14 +812,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
} else {
conversation.add(message);
- if (saveInDb && (message.getEncryption() == Message.ENCRYPTION_NONE || saveEncryptedMessages())) {
+ if (saveInDb && (message.getEncryption() == Message.ENCRYPTION_NONE || !ConversationsPlusPreferences.dontSaveEncrypted())) {
databaseBackend.createMessage(message);
}
updateConversationUi();
}
if (packet != null) {
if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
- if (this.sendChatStates()) {
+ if (ConversationsPlusPreferences.chatStates()) {
packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
}
}
@@ -1213,17 +1212,17 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void updateAccountPasswordOnServer(final Account account, final String newPassword, final OnAccountPasswordChanged callback) {
final IqPacket iq = getIqGenerator().generateSetPassword(account, newPassword);
sendIqPacket(account, iq, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(final Account account, final IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE.RESULT) {
- account.setPassword(newPassword);
- databaseBackend.updateAccount(account);
- callback.onPasswordChangeSucceeded();
- } else {
- callback.onPasswordChangeFailed();
- }
- }
- });
+ @Override
+ public void onIqPacketReceived(final Account account, final IqPacket packet) {
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ account.setPassword(newPassword);
+ databaseBackend.updateAccount(account);
+ callback.onPasswordChangeSucceeded();
+ } else {
+ callback.onPasswordChangeFailed();
+ }
+ }
+ });
}
public void deleteAccount(final Account account) {
@@ -1558,7 +1557,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
conversation.getMucOptions().setOffline();
conversation.deregisterWithBookmark();
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid()
- + ": leaving muc " + conversation.getJid());
+ + ": leaving muc " + conversation.getJid());
} else {
account.pendingConferenceLeaves.add(conversation);
}
@@ -1642,23 +1641,23 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
request.setTo(conversation.getJid().toBareJid());
request.query("http://jabber.org/protocol/disco#info");
sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(Account account, IqPacket packet) {
- if (packet.getType() != IqPacket.TYPE.ERROR) {
- ArrayList<String> features = new ArrayList<>();
- for (Element child : packet.query().getChildren()) {
- if (child != null && child.getName().equals("feature")) {
- String var = child.getAttribute("var");
- if (var != null) {
- features.add(var);
- }
- }
- }
- conversation.getMucOptions().updateFeatures(features);
- updateConversationUi();
- }
- }
- });
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ if (packet.getType() != IqPacket.TYPE.ERROR) {
+ ArrayList<String> features = new ArrayList<>();
+ for (Element child : packet.query().getChildren()) {
+ if (child != null && child.getName().equals("feature")) {
+ String var = child.getAttribute("var");
+ if (var != null) {
+ features.add(var);
+ }
+ }
+ }
+ conversation.getMucOptions().updateFeatures(features);
+ updateConversationUi();
+ }
+ }
+ });
}
public void pushConferenceConfiguration(final Conversation conversation, final Bundle options, final OnConferenceOptionsPushed callback) {
@@ -1802,9 +1801,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void createContact(Contact contact) {
- SharedPreferences sharedPref = getPreferences();
- boolean autoGrant = sharedPref.getBoolean("grant_new_contacts", true);
- if (autoGrant) {
+ if (ConversationsPlusPreferences.grantNewContacts()) {
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
contact.setOption(Contact.Options.ASKING);
}
@@ -1820,27 +1817,27 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
+ otrSession.getSessionID().getUserID());
conversation.findUnsentMessagesWithOtrEncryption(new Conversation.OnMessageFound() {
- @Override
- public void onMessageFound(Message message) {
- SessionID id = otrSession.getSessionID();
- try {
- message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
- } catch (InvalidJidException e) {
- return;
- }
- if (message.needsUploading()) {
- mJingleConnectionManager.createNewConnection(message);
- } else {
- MessagePacket outPacket = mMessageGenerator.generateOtrChat(message, true);
- if (outPacket != null) {
- message.setStatus(Message.STATUS_SEND);
- databaseBackend.updateMessage(message);
- sendMessagePacket(account, outPacket);
- }
- }
- updateConversationUi();
- }
- });
+ @Override
+ public void onMessageFound(Message message) {
+ SessionID id = otrSession.getSessionID();
+ try {
+ message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
+ } catch (InvalidJidException e) {
+ return;
+ }
+ if (message.needsUploading()) {
+ mJingleConnectionManager.createNewConnection(message);
+ } else {
+ MessagePacket outPacket = mMessageGenerator.generateOtrChat(message, true);
+ if (outPacket != null) {
+ message.setStatus(Message.STATUS_SEND);
+ databaseBackend.updateMessage(message);
+ sendMessagePacket(account, outPacket);
+ }
+ }
+ updateConversationUi();
+ }
+ });
}
public boolean renewSymmetricKey(Conversation conversation) {
@@ -2040,31 +2037,31 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private void fetchAvatarVcard(final Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrieveVcardAvatar(avatar);
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(Account account, IqPacket packet) {
- synchronized (mInProgressAvatarFetches) {
- mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
- }
- if (packet.getType() == IqPacket.TYPE.RESULT) {
- Element vCard = packet.findChild("vCard", "vcard-temp");
- Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
- String image = photo != null ? photo.findChildContent("BINVAL") : null;
- if (image != null) {
- avatar.image = image;
- if (getFileBackend().save(avatar)) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid()
- + ": successfully fetched vCard avatar for " + avatar.owner);
- Contact contact = account.getRoster()
- .getContact(avatar.owner);
- contact.setAvatar(avatar);
- getAvatarService().clear(contact);
- updateConversationUi();
- updateRosterUi();
- }
- }
- }
- }
- });
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ synchronized (mInProgressAvatarFetches) {
+ mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
+ }
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ Element vCard = packet.findChild("vCard", "vcard-temp");
+ Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
+ String image = photo != null ? photo.findChildContent("BINVAL") : null;
+ if (image != null) {
+ avatar.image = image;
+ if (getFileBackend().save(avatar)) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ + ": successfully fetched vCard avatar for " + avatar.owner);
+ Contact contact = account.getRoster()
+ .getContact(avatar.owner);
+ contact.setAvatar(avatar);
+ getAvatarService().clear(contact);
+ updateConversationUi();
+ updateRosterUi();
+ }
+ }
+ }
+ }
+ });
}
public void checkForAvatar(Account account, final UiCallback<Avatar> callback) {
@@ -2158,14 +2155,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void invite(Conversation conversation, Jid contact) {
- Log.d(Config.LOGTAG,conversation.getAccount().getJid().toBareJid()+": inviting "+contact+" to "+conversation.getJid().toBareJid());
+ Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": inviting " + contact + " to " + conversation.getJid().toBareJid());
MessagePacket packet = mMessageGenerator.invite(conversation, contact);
sendMessagePacket(conversation.getAccount(), packet);
}
public void directInvite(Conversation conversation, Jid jid) {
MessagePacket packet = mMessageGenerator.directInvite(conversation, jid);
- sendMessagePacket(conversation.getAccount(),packet);
+ sendMessagePacket(conversation.getAccount(), packet);
}
public void resetSendingToWaiting(Account account) {
@@ -2224,30 +2221,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
updateConversationUi();
}
- public SharedPreferences getPreferences() {
- return PreferenceManager
- .getDefaultSharedPreferences(getApplicationContext());
- }
-
- public boolean forceEncryption() {
- return getPreferences().getBoolean("force_encryption", false);
- }
- public boolean confirmMessages() {
- return getPreferences().getBoolean("confirm_messages", true);
- }
-
- public boolean sendChatStates() {
- return getPreferences().getBoolean("chat_states", false);
- }
-
- public boolean saveEncryptedMessages() {
- return !getPreferences().getBoolean("dont_save_encrypted", false);
- }
-
- public boolean indicateReceived() {
- return getPreferences().getBoolean("indicate_received", false);
- }
-
public int unreadCount() {
int count = 0;
for(Conversation conversation : getConversations()) {
@@ -2357,8 +2330,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void updateMemorizingTrustmanager() {
final MemorizingTrustManager tm;
- final boolean dontTrustSystemCAs = getPreferences().getBoolean("dont_trust_system_cas", false);
- if (dontTrustSystemCAs) {
+ if (ConversationsPlusPreferences.dontTrustSystemCAs()) {
tm = new MemorizingTrustManager(getApplicationContext(), null);
} else {
tm = new MemorizingTrustManager(getApplicationContext());
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
index bf0c126e..e8d822c8 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
@@ -6,10 +6,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
-import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
@@ -32,6 +30,7 @@ import org.openintents.openpgp.util.OpenPgpUtils;
import java.util.List;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.crypto.PgpEngine;
import de.thedevstack.conversationsplus.entities.Account;
@@ -208,8 +207,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
getActionBar().setDisplayHomeAsUpEnabled(true);
}
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
- this.showDynamicTags = preferences.getBoolean("show_dynamic_tags",false);
+ this.showDynamicTags = ConversationsPlusPreferences.showDynamicTags();
}
@Override
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
index 2aeeb9c7..4f30cda3 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
@@ -28,6 +28,8 @@ import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
+
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.timroes.android.listview.EnhancedListView;
import java.util.ArrayList;
@@ -47,7 +49,6 @@ import de.thedevstack.conversationsplus.services.XmppConnectionService.OnRosterU
import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter;
import de.thedevstack.conversationsplus.utils.ExceptionHelper;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
-import github.ankushsachdeva.emojicon.EmojiconEditText;
public class ConversationActivity extends XmppActivity
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
@@ -297,12 +298,12 @@ public class ConversationActivity extends XmppActivity
public void switchToConversation(Conversation conversation) {
setSelectedConversation(conversation);
runOnUiThread(new Runnable() {
- @Override
- public void run() {
- ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
- openConversation();
- }
- });
+ @Override
+ public void run() {
+ ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
+ openConversation();
+ }
+ });
}
private void updateActionBarTitle() {
@@ -316,7 +317,7 @@ public class ConversationActivity extends XmppActivity
if (titleShouldBeName && conversation != null) {
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeButtonEnabled(true);
- if (conversation.getMode() == Conversation.MODE_SINGLE || useSubjectToIdentifyConference()) {
+ if (conversation.getMode() == Conversation.MODE_SINGLE || ConversationsPlusPreferences.useSubject()) {
ab.setTitle(conversation.getName());
} else {
ab.setTitle(conversation.getJid().toBareJid().toString());
@@ -377,7 +378,7 @@ public class ConversationActivity extends XmppActivity
} else {
menuAdd.setVisible(!isConversationsOverviewHideable());
if (this.getSelectedConversation() != null) {
- if (this.getSelectedConversation().getNextEncryption(forceEncryption()) != Message.ENCRYPTION_NONE) {
+ if (this.getSelectedConversation().getNextEncryption(ConversationsPlusPreferences.forceEncryption()) != Message.ENCRYPTION_NONE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
menuSecure.setIcon(R.drawable.ic_lock_white_24dp);
} else {
@@ -477,20 +478,20 @@ public class ConversationActivity extends XmppActivity
public void attachFile(final int attachmentChoice) {
switch (attachmentChoice) {
case ATTACHMENT_CHOICE_LOCATION:
- getPreferences().edit().putString("recently_used_quick_action","location").apply();
+ ConversationsPlusPreferences.applyRecentlyUsedQuickAction("location");
break;
case ATTACHMENT_CHOICE_RECORD_VOICE:
- getPreferences().edit().putString("recently_used_quick_action","voice").apply();
+ ConversationsPlusPreferences.applyRecentlyUsedQuickAction("voice");
break;
case ATTACHMENT_CHOICE_TAKE_PHOTO:
- getPreferences().edit().putString("recently_used_quick_action","photo").apply();
+ ConversationsPlusPreferences.applyRecentlyUsedQuickAction("photo");
break;
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
- getPreferences().edit().putString("recently_used_quick_action","picture").apply();
+ ConversationsPlusPreferences.applyRecentlyUsedQuickAction("picture");
break;
}
final Conversation conversation = getSelectedConversation();
- final int encryption = conversation.getNextEncryption(forceEncryption());
+ final int encryption = conversation.getNextEncryption(ConversationsPlusPreferences.forceEncryption());
if (encryption == Message.ENCRYPTION_PGP) {
if (hasPgp()) {
if (conversation.getContact().getPgpKeyId() != 0) {
@@ -627,19 +628,19 @@ public class ConversationActivity extends XmppActivity
builder.setView(dialogView);
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.delete_messages),
- new OnClickListener() {
+ new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation);
- if (endConversationCheckBox.isChecked()) {
- endConversation(conversation);
- } else {
- updateConversationList();
- ConversationActivity.this.mConversationFragment.updateMessages();
- }
- }
- });
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation);
+ if (endConversationCheckBox.isChecked()) {
+ endConversation(conversation);
+ } else {
+ updateConversationList();
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ }
+ }
+ });
builder.create().show();
}
@@ -766,14 +767,15 @@ public class ConversationActivity extends XmppActivity
MenuItem otr = popup.getMenu().findItem(R.id.encryption_choice_otr);
MenuItem none = popup.getMenu().findItem(R.id.encryption_choice_none);
MenuItem pgp = popup.getMenu().findItem(R.id.encryption_choice_pgp);
+ boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
if (conversation.getMode() == Conversation.MODE_MULTI) {
otr.setEnabled(false);
} else {
- if (forceEncryption()) {
+ if (forceEncryption) {
none.setVisible(false);
}
}
- switch (conversation.getNextEncryption(forceEncryption())) {
+ switch (conversation.getNextEncryption(forceEncryption)) {
case Message.ENCRYPTION_NONE:
none.setChecked(true);
break;
@@ -797,24 +799,24 @@ public class ConversationActivity extends XmppActivity
final int[] durations = getResources().getIntArray(
R.array.mute_options_durations);
builder.setItems(R.array.mute_options_descriptions,
- new OnClickListener() {
+ new OnClickListener() {
- @Override
- public void onClick(final DialogInterface dialog, final int which) {
- final long till;
- if (durations[which] == -1) {
- till = Long.MAX_VALUE;
- } else {
- till = System.currentTimeMillis() + (durations[which] * 1000);
- }
- conversation.setMutedTill(till);
- ConversationActivity.this.xmppConnectionService.databaseBackend
- .updateConversation(conversation);
- updateConversationList();
- ConversationActivity.this.mConversationFragment.updateMessages();
- invalidateOptionsMenu();
- }
- });
+ @Override
+ public void onClick(final DialogInterface dialog, final int which) {
+ final long till;
+ if (durations[which] == -1) {
+ till = Long.MAX_VALUE;
+ } else {
+ till = System.currentTimeMillis() + (durations[which] * 1000);
+ }
+ conversation.setMutedTill(till);
+ ConversationActivity.this.xmppConnectionService.databaseBackend
+ .updateConversation(conversation);
+ updateConversationList();
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ invalidateOptionsMenu();
+ }
+ });
builder.create().show();
}
@@ -872,7 +874,7 @@ public class ConversationActivity extends XmppActivity
public void onResume() {
super.onResume();
final int theme = findTheme();
- final boolean usingEnterKey = usingEnterKey();
+ final boolean usingEnterKey = ConversationsPlusPreferences.displayEnterKey();
if (this.mTheme != theme || usingEnterKey != mUsingEnterKey) {
recreate();
}
@@ -895,7 +897,7 @@ public class ConversationActivity extends XmppActivity
conversation.getUuid());
}
savedInstanceState.putBoolean(STATE_PANEL_OPEN,
- isConversationsOverviewVisable());
+ isConversationsOverviewVisable());
if (this.mPendingImageUris.size() >= 1) {
savedInstanceState.putString(STATE_PENDING_URI, this.mPendingImageUris.get(0).toString());
}
@@ -1079,23 +1081,23 @@ public class ConversationActivity extends XmppActivity
if (conversation == null) {
return;
}
- xmppConnectionService.attachLocationToConversation(conversation,uri, new UiCallback<Message>() {
+ xmppConnectionService.attachLocationToConversation(conversation, uri, new UiCallback<Message>() {
- @Override
- public void success(Message message) {
- xmppConnectionService.sendMessage(message);
- }
+ @Override
+ public void success(Message message) {
+ xmppConnectionService.sendMessage(message);
+ }
- @Override
- public void error(int errorCode, Message object) {
+ @Override
+ public void error(int errorCode, Message object) {
- }
+ }
- @Override
- public void userInputRequried(PendingIntent pi, Message object) {
+ @Override
+ public void userInputRequried(PendingIntent pi, Message object) {
- }
- });
+ }
+ });
}
private void attachFileToConversation(Conversation conversation, Uri uri) {
@@ -1105,22 +1107,22 @@ public class ConversationActivity extends XmppActivity
prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG);
prepareFileToast.show();
xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback<Message>() {
- @Override
- public void success(Message message) {
- hidePrepareFileToast();
- xmppConnectionService.sendMessage(message);
- }
+ @Override
+ public void success(Message message) {
+ hidePrepareFileToast();
+ xmppConnectionService.sendMessage(message);
+ }
- @Override
- public void error(int errorCode, Message message) {
- displayErrorDialog(errorCode);
- }
+ @Override
+ public void error(int errorCode, Message message) {
+ displayErrorDialog(errorCode);
+ }
- @Override
- public void userInputRequried(PendingIntent pi, Message message) {
+ @Override
+ public void userInputRequried(PendingIntent pi, Message message) {
- }
- });
+ }
+ });
}
private void attachImageToConversation(Conversation conversation, Uri uri) {
@@ -1208,18 +1210,6 @@ public class ConversationActivity extends XmppActivity
});
}
- public boolean forceEncryption() {
- return getPreferences().getBoolean("force_encryption", false);
- }
-
- public boolean useSendButtonToIndicateStatus() {
- return getPreferences().getBoolean("send_button_status", false);
- }
-
- public boolean indicateReceived() {
- return getPreferences().getBoolean("indicate_received", false);
- }
-
@Override
protected void refreshUiReal() {
updateConversationList();
@@ -1273,10 +1263,6 @@ public class ConversationActivity extends XmppActivity
xmppConnectionService.sendUnblockRequest(conversation);
}
- public boolean enterIsSend() {
- return getPreferences().getBoolean("enter_is_send",false);
- }
-
@Override
public void onShowErrorToast(final int resId) {
runOnUiThread(new Runnable() {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index d715aee2..3fbe59f4 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -12,7 +12,6 @@ import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.InputType;
-import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
@@ -42,6 +41,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentLinkedQueue;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.ui.dialogs.MessageDetailsDialog;
import de.thedevstack.conversationsplus.ui.listeners.ConversationSwipeRefreshListener;
import de.thedevstack.conversationsplus.Config;
@@ -213,16 +213,17 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (body.length() == 0 || this.conversation == null) {
return;
}
- Message message = new Message(conversation, body, conversation.getNextEncryption(activity.forceEncryption()));
+ boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
+ Message message = new Message(conversation, body, conversation.getNextEncryption(forceEncryption));
if (conversation.getMode() == Conversation.MODE_MULTI) {
if (conversation.getNextCounterpart() != null) {
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_PRIVATE);
}
}
- if (conversation.getNextEncryption(activity.forceEncryption()) == Message.ENCRYPTION_OTR) {
- sendOtrMessage(message);
- } else if (conversation.getNextEncryption(activity.forceEncryption()) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_OTR) {
+ sendOtrMessage(message);
+ } else if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
sendPgpMessage(message);
} else {
sendPlainTextMessage(message);
@@ -236,7 +237,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
R.string.send_private_message_to,
conversation.getNextCounterpart().getResourcepart()));
} else {
- switch (conversation.getNextEncryption(activity.forceEncryption())) {
+ switch (conversation.getNextEncryption(ConversationsPlusPreferences.forceEncryption())) {
case Message.ENCRYPTION_NONE:
mEditMessage
.setHint(getString(R.string.send_plain_text_message));
@@ -255,7 +256,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
private void setupIme() {
- if (((ConversationActivity) getActivity()).usingEnterKey()) {
+ if (ConversationsPlusPreferences.displayEnterKey()) {
mEditMessage.setInputType(mEditMessage.getInputType() & (~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
} else {
mEditMessage.setInputType(mEditMessage.getInputType() | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
@@ -963,11 +964,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (conference && c.getNextCounterpart() != null) {
action = SendButtonAction.CANCEL;
} else {
- String setting = activity.getPreferences().getString("quick_action", "recent");
+ String setting = ConversationsPlusPreferences.quickAction();
if (!setting.equals("none") && UIHelper.receivedLocationQuestion(conversation.getLatestMessage())) {
setting = "location";
} else if (setting.equals("recent")) {
- setting = activity.getPreferences().getString("recently_used_quick_action", "text");
+ setting = ConversationsPlusPreferences.recentlyUsedQuickAction();
}
switch (setting) {
case "photo":
@@ -991,7 +992,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
action = SendButtonAction.TEXT;
}
}
- if (activity.useSendButtonToIndicateStatus() && c != null
+ if (ConversationsPlusPreferences.sendButtonStatus() && c != null
&& c.getAccount().getStatus() == Account.State.ONLINE) {
if (c.getMode() == Conversation.MODE_SINGLE) {
status = c.getContact().getMostAvailableStatus();
@@ -1178,7 +1179,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public boolean onEnterPressed() {
- if (activity.enterIsSend()) {
+ if (ConversationsPlusPreferences.enterIsSend()) {
sendMessage();
return true;
} else {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
index 46a68f65..c364ff00 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
@@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.tzur.conversations.Settings;
import de.duenndns.ssl.MemorizingTrustManager;
@@ -15,7 +16,6 @@ import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import github.ankushsachdeva.emojicon.EmojiconHandler;
import android.app.AlertDialog;
-import android.app.Fragment;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.content.SharedPreferences;
@@ -135,11 +135,10 @@ public class SettingsActivity extends XmppActivity implements
public void onSharedPreferenceChanged(SharedPreferences preferences,
String name) {
// need to synchronize the settings class first
- Settings.synchronizeSettingsClassWithPreferences(getPreferences(), name);
+ Settings.synchronizeSettingsClassWithPreferences(preferences, name);
switch (name) {
case "resource":
- String resource = preferences.getString("resource", "mobile")
- .toLowerCase(Locale.US);
+ String resource = ConversationsPlusPreferences.resource().toLowerCase(Locale.US);
if (xmppConnectionServiceBound) {
for (Account account : xmppConnectionService.getAccounts()) {
account.setResource(resource);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
index c5ac3985..4cd24a4b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
@@ -53,6 +53,7 @@ import java.util.Collections;
import java.util.List;
import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Blockable;
@@ -185,6 +186,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_conversation);
+ this.mHideOfflineContacts = ConversationsPlusPreferences.hideOffline();
mViewPager = (ViewPager) findViewById(R.id.start_conversation_view_pager);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
@@ -241,7 +243,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
});
- this.mHideOfflineContacts = getPreferences().getBoolean("hide_offline", false);
}
@@ -533,12 +534,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
new IntentIntegrator(this).initiateScan();
return true;
case R.id.action_hide_offline:
- mHideOfflineContacts = !item.isChecked();
- getPreferences().edit().putBoolean("hide_offline", mHideOfflineContacts).commit();
+ mHideOfflineContacts = !item.isChecked(); // the item is the menu item which is displayed, the inversion here calculates the new value
+ ConversationsPlusPreferences.commitHideOffline(mHideOfflineContacts);
if (mSearchEditText != null) {
filter(mSearchEditText.getText().toString());
}
- invalidateOptionsMenu();
+ invalidateOptionsMenu(); // Since the selection of this item changed the checked value, the options menu is now invalid
+ return true;
}
return super.onOptionsItemSelected(item);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
index 8341e631..f0e5992f 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
@@ -16,7 +16,6 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.ServiceConnection;
-import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
@@ -36,7 +35,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
-import android.preference.PreferenceManager;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -63,8 +61,8 @@ import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
-import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
@@ -98,8 +96,6 @@ public abstract class XmppActivity extends Activity {
protected int mColorGreen;
protected int mPrimaryColor;
- protected boolean mUseSubject = true;
-
private DisplayMetrics metrics;
protected int mTheme;
protected boolean mUsingEnterKey = false;
@@ -345,10 +341,7 @@ public abstract class XmppActivity extends Activity {
mSecondaryBackgroundColor = getResources().getColor(R.color.grey200);
this.mTheme = findTheme();
setTheme(this.mTheme);
- this.mUsingEnterKey = usingEnterKey();
- mUseSubject = getPreferences().getBoolean("use_subject", true);
-
- Settings.initSettingsClassWithPreferences(getPreferences());
+ this.mUsingEnterKey = ConversationsPlusPreferences.displayEnterKey();
final ActionBar ab = getActionBar();
if (ab!=null) {
@@ -356,19 +349,6 @@ public abstract class XmppActivity extends Activity {
}
}
- protected boolean usingEnterKey() {
- return getPreferences().getBoolean("display_enter_key", false);
- }
-
- protected SharedPreferences getPreferences() {
- return PreferenceManager
- .getDefaultSharedPreferences(getApplicationContext());
- }
-
- public boolean useSubjectToIdentifyConference() {
- return mUseSubject;
- }
-
public void switchToConversation(Conversation conversation) {
switchToConversation(conversation, null, false);
}
@@ -786,7 +766,7 @@ public abstract class XmppActivity extends Activity {
}
protected int findTheme() {
- if (getPreferences().getBoolean("use_larger_font", false)) {
+ if (ConversationsPlusPreferences.useLargerFont()) {
return R.style.ConversationsTheme_LargerText;
} else {
return R.style.ConversationsTheme;
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
index dab291cc..1fc6e066 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
@@ -21,6 +21,7 @@ import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.R;
@@ -59,7 +60,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
view.findViewById(R.id.conversationListRowFrame).setBackgroundColor(c);
}
TextView convName = (TextView) view.findViewById(R.id.conversation_name);
- if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
+ if (conversation.getMode() == Conversation.MODE_SINGLE || ConversationsPlusPreferences.useSubject()) {
convName.setText(conversation.getName());
} else {
convName.setText(conversation.getJid().toBareJid().toString());
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java
index 114e5cff..3f342528 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java
@@ -4,6 +4,7 @@ import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.ListItem;
@@ -12,13 +13,11 @@ import de.thedevstack.conversationsplus.utils.UIHelper;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import android.content.Context;
-import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
-import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -46,8 +45,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
public ListItemAdapter(XmppActivity activity, List<ListItem> objects) {
super(activity, 0, objects);
this.activity = activity;
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
- this.showDynamicTags = preferences.getBoolean("show_dynamic_tags",false);
+ this.showDynamicTags = ConversationsPlusPreferences.showDynamicTags();
}
@Override
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
index 48debdaf..550e3c4e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
@@ -25,8 +25,7 @@ import android.widget.Toast;
import java.util.List;
-import de.tzur.conversations.Settings;
-import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
@@ -129,12 +128,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
info = getContext().getString(R.string.offering);
break;
case Message.STATUS_SEND_RECEIVED:
- if (activity.indicateReceived()) {
+ if (ConversationsPlusPreferences.indicateReceived()) {
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
}
break;
case Message.STATUS_SEND_DISPLAYED:
- if (activity.indicateReceived()) {
+ if (ConversationsPlusPreferences.indicateReceived()) {
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
}
break;
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
index 492c65d2..d25e6d35 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
@@ -7,6 +7,7 @@ import java.io.InputStreamReader;
import java.util.List;
import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
@@ -38,9 +39,7 @@ public class ExceptionHelper {
public static void checkForCrash(Context context,
final XmppConnectionService service) {
try {
- final SharedPreferences preferences = PreferenceManager
- .getDefaultSharedPreferences(context);
- boolean neverSend = preferences.getBoolean("never_send", false);
+ boolean neverSend = ConversationsPlusPreferences.neverSend();
if (neverSend) {
return;
}
@@ -107,8 +106,7 @@ public class ExceptionHelper {
@Override
public void onClick(DialogInterface dialog, int which) {
- preferences.edit().putBoolean("never_send", true)
- .apply();
+ ConversationsPlusPreferences.applyNeverSend(true);
}
});
builder.create().show();
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
index 1687ef4b..79556a0a 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
@@ -1,13 +1,11 @@
package de.thedevstack.conversationsplus.xmpp;
import android.content.Context;
-import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
-import android.preference.PreferenceManager;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
@@ -26,7 +24,6 @@ import java.net.IDN;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
-import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -521,14 +518,6 @@ public class XmppConnection implements Runnable {
tagWriter.writeTag(startTLS);
}
- private SharedPreferences getPreferences() {
- return PreferenceManager.getDefaultSharedPreferences(applicationContext);
- }
-
- private boolean enableLegacySSL() {
- return getPreferences().getBoolean("enable_legacy_ssl", false);
- }
-
private void switchOverToTls(final Tag currentTag) throws XmlPullParserException, IOException {
tagReader.readTag();
try {
diff --git a/src/main/java/de/tzur/conversations/Settings.java b/src/main/java/de/tzur/conversations/Settings.java
index c919d60c..23eb3ee4 100644
--- a/src/main/java/de/tzur/conversations/Settings.java
+++ b/src/main/java/de/tzur/conversations/Settings.java
@@ -3,11 +3,13 @@ package de.tzur.conversations;
import android.content.SharedPreferences;
import android.util.Log;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+
/**
* This class is used to provide access to settings which have to be accessed frequently.
* Every setting in this class has to be updated using @see SettingsActivity#onSharedPreferenceChanged.
*/
-public final class Settings {
+public abstract class Settings {
/**
* Initializes the settings provided via this static class.
@@ -56,6 +58,7 @@ public final class Settings {
break;
}
}
+
/**
* Boolean if emoticons should be parsed to emoticons or not.
*/
@@ -85,10 +88,4 @@ public final class Settings {
*/
public static boolean CONFIRM_MESSAGE_READ = true;
- /**
- * This is a utility class - private constructor avoids any instantiation.
- */
- private Settings() {
- // Private constructor to avoid instantiation
- }
}