aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/tzur/conversations/Settings.java
blob: 23eb3ee4747fbc158496e07f927e88091d6acf5c (plain)
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
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 abstract class Settings {

    /**
     * Initializes the settings provided via this static class.
     * @param preferences the shared preferences of the app.
     */
    public static void initSettingsClassWithPreferences(SharedPreferences preferences) {
        Log.d("SETTING", "Initializing settings");
        String[] preferenceNames = { "parse_emoticons", "send_button_status", "led_notification_color", "auto_download_file_wlan", "auto_download_file_link", "confirm_messages_list" };
        for (String name : preferenceNames) {
            Settings.synchronizeSettingsClassWithPreferences(preferences, name);
        }
    }

    /**
     * Synchronizes the setting value in this class on settings update in SettingsActivity.
     * @param preferences the shared preferences of the app.
     * @param name the name of the setting to synchronize.
     */
    public static void synchronizeSettingsClassWithPreferences(SharedPreferences preferences, String name) {
        Log.d("SETTING", "Synchronizing settings");
        switch (name) {
            case "parse_emoticons":
                Settings.PARSE_EMOTICONS = preferences.getBoolean(name, Settings.PARSE_EMOTICONS);
                break;
            case "send_button_status":
                Settings.SHOW_ONLINE_STATUS = preferences.getBoolean(name, Settings.SHOW_ONLINE_STATUS);
                break;
            case "led_notify_color":
                Settings.LED_COLOR = preferences.getInt(name, Settings.LED_COLOR);
                break;
            case "auto_download_file_wlan":
                Settings.DOWNLOAD_ONLY_WLAN = preferences.getBoolean(name, Settings.DOWNLOAD_ONLY_WLAN);
                break;
            case "auto_download_file_link":
                Settings.DOWNLOAD_IMAGE_LINKS = preferences.getBoolean(name, Settings.DOWNLOAD_IMAGE_LINKS);
                break;
            case "confirm_messages_list":
                int iPref = Settings.CONFIRM_MESSAGE_RECEIVED && Settings.CONFIRM_MESSAGE_READ ? 2 : Settings.CONFIRM_MESSAGE_RECEIVED ? 1 : 0;
                try {
                    iPref = Integer.valueOf(preferences.getString(name, new Integer(iPref).toString()));
                } catch (NumberFormatException e) {
                    // ignored, fallback-value set above
                }
                Settings.CONFIRM_MESSAGE_RECEIVED = iPref >= 1;
                Settings.CONFIRM_MESSAGE_READ = iPref >= 2;
                break;
        }
    }

    /**
     * Boolean if emoticons should be parsed to emoticons or not.
     */
    public static boolean PARSE_EMOTICONS = true;
    /**
     * Boolean if online status should be shown or not.
     */
    public static boolean SHOW_ONLINE_STATUS = true;
    /**
     * LED Color
     */
    public static int LED_COLOR = 0xffffffff;
    /**
     * Boolean if image-links should be downloaded or not.
     */
    public static boolean DOWNLOAD_IMAGE_LINKS = true;
    /**
     * Boolean if automatic downloads should be done only jif connected to WLAN.
     */
    public static boolean DOWNLOAD_ONLY_WLAN = true;
    /**
     * Boolean if confirm received messages
     */
    public static boolean CONFIRM_MESSAGE_RECEIVED = true;
    /**
     * Boolean if confirm read message
     */
    public static boolean CONFIRM_MESSAGE_READ = true;

}