aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java
blob: 28c0d745e1b6d530b16a1de48a638cd240b29768 (plain) (blame)
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
package org.bienvenidoainternet.baiparser;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.util.Log;

/**
 * Created by Renard on 16-03-2016.
 */
public class ThemeManager {
    private int currentThemeId;
    private int prefThemeId;
    private Activity activity;
    public ThemeManager(Activity activity){
        this.activity = activity;
        setCurrentThemeId();
    }

    public void setCurrentThemeId(){
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
        int themeId = Integer.valueOf(settings.getString("pref_theme", "1"));
        prefThemeId = themeId;
        switch (themeId) {
            case 1:
                currentThemeId = R.style.AppTheme_NoActionBar;
                break;
            case 2:
                currentThemeId = R.style.AppTheme_Dark;
                break;
            case 3:
                currentThemeId = R.style.AppTheme_HeadLine;
//                setTheme(R.style.AppTheme_HeadLine_Activity);
                break;
            case 4:
                currentThemeId = R.style.AppTheme_Black;
//                setTheme(R.style.AppTheme_Black_Activity);
                break;
        }
        Log.d("ThemeManager", "isDarkTheme: " + isDarkTheme());
    }

    public int getSageColor(){
        TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.sageColor});
        return a.getColor(0, Color.CYAN);
    }

    public int getMarginColor(){
        TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.marginColor});
        return a.getColor(0, Color.CYAN);
    }

    public void updateThemeId(int id){
        this.currentThemeId = id;
    }

    public int getNameColor() {
        TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.nameColor});
        return a.getColor(0, Color.CYAN);
    }

    public int getTripcodeColor() {
        TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.tripcodeColor});
        return a.getColor(0, Color.CYAN);
    }

    public int getPrimaryColor(){
        TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimary});
        return a.getColor(0, Color.CYAN);
    }
    public int getPrimaryDarkColor(){
        TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimaryDark});
        return a.getColor(0, Color.CYAN);
    }

    public boolean isDarkTheme(){
        TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.isDarkTheme});
        return a.getBoolean(0, false);
    }

    public int getThemeForActivity(){
        int id = R.style.AppTheme;
        switch (prefThemeId) {
            case 1: // pseudoch
                id = R.style.AppTheme;
                break;
            case 2: // nightmode
                id = R.style.AppTheme;
                break;
            case 3: // photon
                id = R.style.AppTheme_HeadLineActionBar;
                break;
            case 4: // tomorrow
                id = R.style.AppTheme_BlackActionBar;
                break;
        }
        return id;
    }

    public int getThemeForMainActivity(){
        int id = R.style.AppTheme_NoActionBar;
        switch (prefThemeId) {
            case 1: // pseudoch
                id = R.style.AppTheme_NoActionBar;
                break;
            case 2: // nightmode
                id = R.style.AppTheme_NoActionBar;
                break;
            case 3: // photon
                id = R.style.AppTheme_HeadLineActionBar_NoActionBar;
                break;
            case 4: // tomorrow
                id = R.style.AppTheme_BlackActionBar_NoActionBar;
                break;
        }
        return id;
    }


    public int getCurrentThemeId() {
        return currentThemeId;
    }
}