summaryrefslogtreecommitdiff
path: root/app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java
blob: 10608a149bfb15f7ae6a679e149baf61a5123acc (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
package se.leap.bitmaskclient;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import butterknife.InjectView;
import butterknife.Optional;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;

import static android.widget.RelativeLayout.BELOW;
import static android.widget.RelativeLayout.LEFT_OF;

public class AddProviderActivity extends AddProviderBaseActivity {

    final public static String TAG = "AddProviderActivity";

    @InjectView(R.id.danger_checkbox)
    CheckBox checkboxDanger;

    @InjectView(R.id.button_save)
    Button saveButton;

    @Optional
    @InjectView(R.id.button_container)
    LinearLayout buttonContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_add_provider);
        init();

        checkboxDanger.setVisibility(View.VISIBLE);
        checkboxDanger.setText(R.string.danger_checkbox);
        checkboxDanger.setChecked(preferences.getBoolean(ProviderItem.DANGER_ON, false));
    }

    @Override
    public void setupSaveButton() {
        saveButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                preferences.edit().putBoolean(ProviderItem.DANGER_ON, checkboxDanger.isChecked()).apply();
                saveProvider();
            }
        });
    }

    @Override
    protected void showCompactLayout() {
        if (isCompactLayout) {
            return;
        }
        super.showCompactLayout();
        showCompactButtonLayout();
    }

    @Override
    protected void showStandardLayout() {
        if (!isCompactLayout) {
            return;
        }
        super.showStandardLayout();
        showStandardButtonLayout();
    }

    private void showCompactButtonLayout() {
        RelativeLayout.LayoutParams phoneButtonContainerParams = (RelativeLayout.LayoutParams) buttonContainer.getLayoutParams();
        phoneButtonContainerParams.addRule(BELOW, 0);
        buttonContainer.setLayoutParams(phoneButtonContainerParams);

        RelativeLayout.LayoutParams checkBoxParams = (RelativeLayout.LayoutParams) checkboxDanger.getLayoutParams();
        checkBoxParams.addRule(LEFT_OF, R.id.button_container);
        checkboxDanger.setLayoutParams(checkBoxParams);
    }

    private void showStandardButtonLayout() {
        RelativeLayout.LayoutParams phoneButtonContainerParams = (RelativeLayout.LayoutParams) buttonContainer.getLayoutParams();
        phoneButtonContainerParams.addRule(BELOW, R.id.danger_checkbox);
        buttonContainer.setLayoutParams(phoneButtonContainerParams);

        RelativeLayout.LayoutParams checkBoxParams = (RelativeLayout.LayoutParams) checkboxDanger.getLayoutParams();
        checkBoxParams.addRule(LEFT_OF, 0);
        checkboxDanger.setLayoutParams(checkBoxParams);
    }
}