summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java
blob: f0e2de8562a95e86588ac50114a2c405e40b1ecf (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
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
package se.leap.bitmaskclient;

import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import butterknife.InjectView;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;

/**
 * Base Activity for configuration wizard activities
 *
 * Created by fupduck on 09.01.18.
 */

public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity {

    protected SharedPreferences preferences;

    @InjectView(R.id.provider_header_logo)
    AppCompatImageView providerHeaderLogo;

    @InjectView(R.id.provider_header_text)
    AppCompatTextView providerHeaderText;

    @InjectView(R.id.loading_screen)
    protected LinearLayout loadingScreen;

    @InjectView(R.id.progressbar)
    protected ProgressBar progressBar;

    @InjectView(R.id.progressbar_description)
    protected AppCompatTextView progressbarText;

    @InjectView(R.id.content)
    protected LinearLayout content;

    protected Provider provider;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);

        provider = getIntent().getParcelableExtra(PROVIDER_KEY);
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        if (provider != null)
            setProviderHeaderText(provider.getName());
        setProgressbarColorForPreLollipop();
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        if (provider != null)
            setProviderHeaderText(provider.getName());
        setProgressbarColorForPreLollipop();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        if (provider != null)
            setProviderHeaderText(provider.getName());
        setProgressbarColorForPreLollipop();
    }

    private void setProgressbarColorForPreLollipop() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            progressBar.getIndeterminateDrawable().setColorFilter(
                    ContextCompat.getColor(this, R.color.colorPrimary),
                    PorterDuff.Mode.SRC_IN);
        }
    }


    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (provider != null) {
            outState.putParcelable(PROVIDER_KEY, provider);
        }
    }

    protected void restoreState(Bundle savedInstanceState) {
        if (savedInstanceState != null && savedInstanceState.containsKey(PROVIDER_KEY)) {
            provider = savedInstanceState.getParcelable(PROVIDER_KEY);
        }
    }

    protected void setProviderHeaderLogo(@DrawableRes int providerHeaderLogo) {
        this.providerHeaderLogo.setImageResource(providerHeaderLogo);
    }

    protected void setProviderHeaderText(String providerHeaderText) {
        this.providerHeaderText.setText(providerHeaderText);
    }

    protected void setProviderHeaderText(@StringRes int providerHeaderText) {
        this.providerHeaderText.setText(providerHeaderText);
    }

    protected void hideProgressBar() {
        loadingScreen.setVisibility(GONE);
        content.setVisibility(VISIBLE);
    }

    protected void showProgressBar() {
        content.setVisibility(GONE);
        loadingScreen.setVisibility(VISIBLE);
    }

    protected void setProgressbarText(String progressbarText) {
        this.progressbarText.setText(progressbarText);
    }

    protected void setProgressbarText(@StringRes int progressbarText) {
        this.progressbarText.setText(progressbarText);
    }

}