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

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.text.TextUtilsCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.views.IconTextView;

import static se.leap.bitmaskclient.utils.PreferenceHelper.saveShowAlwaysOnDialog;
import static se.leap.bitmaskclient.utils.ViewHelper.convertDimensionToPx;


/**
 * Created by cyberta on 25.02.18.
 */



public class AlwaysOnDialog extends AppCompatDialogFragment {

    public final static String TAG = AlwaysOnDialog.class.getName();

    @InjectView(R.id.do_not_show_again)
    CheckBox doNotShowAgainCheckBox;

    @InjectView(R.id.user_message)
    IconTextView userMessage;

    @InjectView(R.id.block_vpn_user_message)
    AppCompatTextView blockVpnUserMessage;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.d_checkbox_confirm, null);
        ButterKnife.inject(this, view);

        userMessage.setIcon(R.drawable.ic_settings);
        userMessage.setText(getString(R.string.always_on_vpn_user_message));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            blockVpnUserMessage.setVisibility(View.VISIBLE);
        }

        builder.setView(view);
        return builder.create();
    }

    @OnClick(R.id.button_ok)
    public void onOkClicked() {
        if (doNotShowAgainCheckBox.isChecked()) {
            saveShowAlwaysOnDialog(getContext(), false);
        }
        Intent intent = new Intent("android.net.vpn.SETTINGS");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        dismiss();
    }

    @OnClick(R.id.button_cancel)
    public void onCancelClicked() {
        dismiss();
    }
}