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

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.R;

import static android.view.View.VISIBLE;

public class AboutFragment extends Fragment {

    final public static String TAG = AboutFragment.class.getSimpleName();
    final public static int VIEWED = 0;

    @InjectView(R.id.version)
    TextView versionTextView;

    @InjectView(R.id.terms_of_service)
    TextView termsOfService;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.f_about, container, false);
        ButterKnife.inject(this, view);
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        String version;
        String name = "Bitmask";
        try {
            PackageInfo packageinfo = getActivity().getPackageManager().getPackageInfo(
                    getActivity().getPackageName(), 0);
            version = packageinfo.versionName;
            name = getString(R.string.app_name);
        } catch (NameNotFoundException e) {
            version = "error fetching version";
        }

        versionTextView.setText(getString(R.string.version_info, name, version));

        if (BuildConfig.FLAVOR_branding.equals("custom") && hasTermsOfServiceResource()) {
            termsOfService.setText(getString(getTermsOfServiceResource()));
            termsOfService.setVisibility(VISIBLE);
        }
    }

    private boolean hasTermsOfServiceResource() {
        return getTermsOfServiceResource() != 0;
    }

    private int getTermsOfServiceResource() {
        return this.getContext().getResources().getIdentifier("terms_of_service", "string", this.getContext().getPackageName());
    }

}