1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
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 String imgTransferFolder() {
return getString("img_transfer_folder", getString("app_name", "Conversations+"));
}
public static String fileTransferFolder() {
return getString("file_transfer_folder", getString("app_name", "Conversations+"));
}
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, <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);
}
public static boolean allowMessageCorrection() {
return getBoolean("allow_message_correction", true);
}
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;
}
}
protected static <T extends Enum<T>> T getEnumFromStringPref(String key, T defaultValue) {
String enumValueAsString = getString(key, defaultValue.name());
return (T) Enum.valueOf(defaultValue.getClass(), enumValueAsString);
}
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);
}
}
|