package de.thedevstack.conversationsplus;
import android.content.SharedPreferences;
import java.util.Set;
import de.thedevstack.conversationsplus.enums.UserDecision;
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 UserDecision resizePicture() {
return getEnumFromStringPref("resize_picture", UserDecision.ASK);
}
public static void applyResizePicture(UserDecision decision) {
applyString("resize_picture", decision.name());
}
/**
* Whether automatic downloads should only be done when connected to Wifi or not.
* @return
*/
public static boolean autoDownloadFileWLAN() {
return getBoolean("auto_download_file_wlan", true);
}
/**
* Whether image-links should be downloaded or not.
* @return
*/
public static boolean autoDownloadFileLink() {
return getBoolean("auto_download_file_link", true);
}
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, mobile as default value
*/
public static String resource() {
return getString("resource", "mobile");
}
/**
* Whether to enable legacy SSL support.
* @return true
if legacy support for SSL is enabled, false 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.
*
Default value is false
* @return true
if the receipt should be requested, false
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 getStringSet(String key, Set 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;
}
}
protected static > T getEnumFromStringPref(String key, T defaultValue) {
return (T) T.valueOf(defaultValue.getClass(), defaultValue.name());
}
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);
}
}