|
|
@@ -3,9 +3,14 @@
|
|
|
*/
|
|
|
package kr.co.zumo.app.lifeplus.activity;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.provider.Settings;
|
|
|
+import android.util.Log;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
import kr.co.zumo.app.R;
|
|
|
-import kr.co.zumo.app.lifeplus.model.SuperModel;
|
|
|
-import kr.co.zumo.app.lifeplus.util.ResourceUtil;
|
|
|
import kr.co.zumo.app.lifeplus.view.Event;
|
|
|
import kr.co.zumo.app.lifeplus.view.dialog.ConfirmDialog;
|
|
|
import kr.co.zumo.app.lifeplus.view.dialog.DialogBuilder;
|
|
|
@@ -27,76 +32,135 @@ public class SplashPresenter implements ISplashContract.Presenter {
|
|
|
private ISplashContract.Model model;
|
|
|
private ISplashContract.View view;
|
|
|
|
|
|
+ private boolean isRequestingLocationService = false;
|
|
|
+
|
|
|
public SplashPresenter(ISplashContract.Model model, ISplashContract.View view) {
|
|
|
this.model = model;
|
|
|
this.view = view;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void launchLocationPermission(Runnable runnable) {
|
|
|
- runnable.run();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void launchDeviceLocationPermission(Runnable runnable) {
|
|
|
- runnable.run();
|
|
|
+ private void launchLocationPermission(Runnable runnable) {
|
|
|
+ if (model.hasLocationPermissions(view.getActivity())) {
|
|
|
+ // 위치 앱 권한
|
|
|
+ runnable.run();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ view.requestLocationPermissions(new String[]{model.getPermissionsString()});
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void launchPushPermission(Runnable runnable) {
|
|
|
-
|
|
|
- if (SuperModel.getInstance().getPreferences().getFirstPermissionCompleted()) {
|
|
|
- // 이미 설정했다면 다음으로 이동
|
|
|
+ private void launchDeviceLocationPermission(Runnable runnable) {
|
|
|
+ if (model.canAccessDeviceLocating(view.getActivity())) {
|
|
|
+ // 위치 서비스 이용 가능하다면 다음으로 이동
|
|
|
runnable.run();
|
|
|
}
|
|
|
else {
|
|
|
- SuperModel.getInstance().getPreferences().setFirstPermissionCompleted();
|
|
|
- // 설정 창 표시
|
|
|
- launchPushPermissionInternal(runnable);
|
|
|
+ launchInternal(() -> {
|
|
|
+
|
|
|
+ isRequestingLocationService = true;
|
|
|
+ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
|
+ view.getActivity().startActivity(intent);
|
|
|
+
|
|
|
+ }, runnable, R.string.splash_permission_device_location_title, R.string.splash_permission_device_location_contents, R.string.cancel, R.string.splash_permission_device_location_accept);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void launchPushPermissionInternal(Runnable runnable) {
|
|
|
+ private void launchPushPermission(Runnable runnable) {
|
|
|
+ // 설정 창 표시
|
|
|
+ launchInternal(() -> {
|
|
|
+
|
|
|
+ model.setPushContentsAndService(true);
|
|
|
+ model.setPushEventEnabled(true);
|
|
|
+ runnable.run();
|
|
|
+
|
|
|
+ }, runnable, R.string.splash_permission_push_title, R.string.splash_permission_push_contents, R.string.splash_permission_do_not_accept, R.string.splash_permission_accept);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void launchInternal(Runnable runnableConfirm, Runnable runnableNext, int titleId, int contentsId, int negativeId, int positiveId) {
|
|
|
new DialogBuilder<ConfirmDialog, ICustomConfirmListener>(view.getActivity().getSupportFragmentManager(), DialogID.CONFIRM)
|
|
|
.listener(new ICustomConfirmListener<ConfirmDialog>() {
|
|
|
@Override
|
|
|
public void onPositiveResult(ConfirmDialog dialog, Event event) {
|
|
|
- model.setPushContentsAndService(true);
|
|
|
- model.setPushEventEnabled(true);
|
|
|
-
|
|
|
- this.onDialogCanceled(dialog);
|
|
|
+ runnableConfirm.run();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onNegativeResult(ConfirmDialog dialog, Event event) {
|
|
|
- this.onDialogCanceled(dialog);
|
|
|
+ dialog.dispose();
|
|
|
+ runnableNext.run();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onDialogCanceled(ConfirmDialog dialog) {
|
|
|
dialog.dispose();
|
|
|
- runnable.run();
|
|
|
+ runnableNext.run();
|
|
|
}
|
|
|
})
|
|
|
.attribute(dialog -> {
|
|
|
- dialog.setTitleId(R.string.splash_permission_push_title);
|
|
|
- dialog.setText(ResourceUtil.getString(R.string.splash_permission_push_contents));
|
|
|
- dialog.setNegativeButtonLabelId(R.string.splash_permission_do_not_accept);
|
|
|
- dialog.setPositiveButtonLabelId(R.string.splash_permission_accept);
|
|
|
+ dialog.setCancelable(false);
|
|
|
+ dialog.setTitleId(titleId);
|
|
|
+ dialog.setText(contentsId);
|
|
|
+ dialog.setNegativeButtonLabelId(negativeId);
|
|
|
+ dialog.setPositiveButtonLabelId(positiveId);
|
|
|
})
|
|
|
.show();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void launchAllPermission(Runnable runnable) {
|
|
|
+ public void launchAllPermission() {
|
|
|
+ // 앱 첫 실행시에만 실행한다.
|
|
|
+ if (model.getFirstPermissionCompleted()) {
|
|
|
+ // 이미 처리 완료했음.
|
|
|
+ view.onPermissionCompleted();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ model.setFirstPermissionCompleted();
|
|
|
|
|
|
- launchPushPermission(() -> {
|
|
|
- launchDeviceLocationPermission(() -> {
|
|
|
- launchLocationPermission(() -> {
|
|
|
- // 권한 처리 종료
|
|
|
- runnable.run();
|
|
|
+ launchPushPermission(() -> {
|
|
|
+ launchDeviceLocationPermission(() -> {
|
|
|
+ launchLocationPermission(() -> {
|
|
|
+ // 권한 처리 종료
|
|
|
+ view.onPermissionCompleted();
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
- });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ if (isRequestingLocationService) {
|
|
|
+ isRequestingLocationService = false;
|
|
|
+
|
|
|
+ launchLocationPermission(() -> {
|
|
|
+ // 권한 처리 종료
|
|
|
+ view.onPermissionCompleted();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
|
|
|
+ Log.i("APP# SplashPresenter | onRequestPermissionsResult", "|" + " grantResults: " + Arrays.toString(grantResults));
|
|
|
+ // If request is cancelled, the result arrays are empty.
|
|
|
+ if (grantResults.length > 0) {
|
|
|
+ // permission was granted
|
|
|
+ boolean granted = true;
|
|
|
+ for (int grantResult : grantResults) {
|
|
|
+ if (grantResult != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ granted = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (granted) {
|
|
|
+ // 모두 허용
|
|
|
+ model.setLocationServiceEnabled(true);
|
|
|
+
|
|
|
+ // 권한 처리 종료
|
|
|
+ view.onPermissionCompleted();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|