aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java294
2 files changed, 296 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
index 2def66f7..0ca0b394 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;
@@ -23,6 +24,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);
+ }
+}