package org.tanrabad.survey.utils;

import android.Manifest;
import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v4.app.ActivityCompat;

import org.tanrabad.survey.utils.prompt.AlertDialogPromptMessage;
import org.tanrabad.survey.utils.prompt.PromptMessage;
import org.tanrabad.survey.R;

public class LocationPermissionPrompt {

    private static final int REQUEST_CODE_ASK_PERMISSIONS = 777;
    public static final String PERMISSION_TO_REQUEST = Manifest.permission.ACCESS_FINE_LOCATION;

    public static void show(final Activity activity) {
        if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, PERMISSION_TO_REQUEST)) {
            PromptMessage promptMessage = new AlertDialogPromptMessage(activity);
            promptMessage.setOnConfirm(getString(activity, R.string.ok),
                    new PromptMessage.OnConfirmListener() {
                @Override
                public void onConfirm() {
                    ActivityCompat.requestPermissions(activity,
                            new String[]{PERMISSION_TO_REQUEST},
                            REQUEST_CODE_ASK_PERMISSIONS);
                }
            });
            promptMessage.setOnCancel(getString(activity, R.string.cancel),
                    new PromptMessage.OnCancelListener() {
                @Override
                public void onCancel() {
                    activity.finish();
                }
            });
            promptMessage.show(null, "คุณจำเป็นต้องเปิดใช้สิทธิ์การเข้าถึงตำแหน่งปัจจุบัน");
            return;
        }
        ActivityCompat.requestPermissions(activity,
                new String[]{PERMISSION_TO_REQUEST},
                REQUEST_CODE_ASK_PERMISSIONS);

    }

    @NonNull
    private static String getString(Activity activity, @StringRes int stringId) {
        return activity.getResources().getString(stringId);
    }
}

@@ -368,16 +368,161 @@
 urvey.R;
+%0Aimport org.tanrabad.survey.utils.prompt.PromptMessage.OnCancelListener;%0Aimport org.tanrabad.survey.utils.prompt.PromptMessage.OnConfirmListener;
 %0A%0Apublic
@@ -1033,47 +1033,13 @@
 ok),
-%0A                    new PromptMessage.
+ new 
 OnCo
@@ -1256,36 +1256,8 @@
 ST%7D,
-%0A                           
  REQ
@@ -1397,47 +1397,13 @@
 el),
-%0A                    new PromptMessage.
+ new 
 OnCa
@@ -1786,32 +1786,16 @@
 EQUEST%7D,
-%0A               
  REQUEST

fix style