51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
package com.safemobile.lib;
|
|
|
|
import android.app.Activity;
|
|
import android.app.AlertDialog;
|
|
|
|
import com.google.android.gms.tasks.Task;
|
|
import com.google.android.gms.tasks.TaskCompletionSource;
|
|
import com.safemobile.safedispatch.R;
|
|
import com.safemobile.interfaces.IDialogService;
|
|
|
|
public class DialogService implements IDialogService {
|
|
@Override
|
|
public Task<Boolean> showDialog(Activity activity, String title, String message, String cancel, String ok) {
|
|
TaskCompletionSource<Boolean> taskCompletionSource = new TaskCompletionSource<>();
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
|
.setTitle(title)
|
|
.setMessage(message)
|
|
.setCancelable(false)
|
|
.setNegativeButton(cancel, (dialog, which) -> {
|
|
taskCompletionSource.trySetResult(false);
|
|
dialog.dismiss();
|
|
})
|
|
.setPositiveButton(ok, (dialog, which) -> taskCompletionSource.trySetResult(true));
|
|
|
|
AlertDialog dialog = builder.create();
|
|
dialog.show();
|
|
|
|
return taskCompletionSource.getTask();
|
|
}
|
|
|
|
@Override
|
|
public Task<Boolean> showPermissionRequestDialog(Activity activity, String message, String cancel) {
|
|
return showDialog(
|
|
activity,
|
|
activity.getString(R.string.permission_denied),
|
|
message,
|
|
cancel,
|
|
activity.getString(R.string.go_to_settings));
|
|
}
|
|
|
|
@Override
|
|
public void showError(Activity activity, String message) {
|
|
showDialog(
|
|
activity,
|
|
activity.getString(R.string.DialogService_Info_ErrorMessage),
|
|
message,
|
|
null,
|
|
activity.getString(R.string.ok));
|
|
}
|
|
}
|