aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/dialog/LiveMapInfoDialogBuilder.java
blob: 6ad59ec517e69101f171fe1ba423498b7eedc789 (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
package cgeo.geocaching.ui.dialog;

import cgeo.geocaching.R;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.CgeoApplication;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.CheckBox;

public class LiveMapInfoDialogBuilder {

    public static AlertDialog create(Activity activity) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

        // AlertDialog has always dark style, so we have to apply it as well always
        final View layout = View.inflate(new ContextThemeWrapper(activity, R.style.dark), R.layout.livemapinfo, null);
        builder.setView(layout);

        final CheckBox checkBoxHide = (CheckBox) layout.findViewById(R.id.live_map_hint_hide);

        final int showCount = Settings.getLiveMapHintShowCount();
        if (showCount > 2) {
            checkBoxHide.setVisibility(View.VISIBLE);
        }
        Settings.setLiveMapHintShowCount(showCount + 1);

        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                CgeoApplication.getInstance().setLiveMapHintShown();
                if (checkBoxHide.getVisibility() == View.VISIBLE && checkBoxHide.isChecked()) {
                    Settings.setHideLiveHint(true);
                }
            }
        });
        return builder.create();
    }

}