|
|
@@ -1,13 +1,13 @@
|
|
|
/*
|
|
|
* COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
|
|
|
*/
|
|
|
-package kr.co.zumo.app.lifeplus.activity;
|
|
|
+package kr.co.zumo.app.lifeplus.view.screen.splash;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.provider.Settings;
|
|
|
-import android.support.v4.app.FragmentActivity;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
@@ -16,31 +16,33 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
import io.reactivex.disposables.CompositeDisposable;
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
import kr.co.zumo.app.R;
|
|
|
+import kr.co.zumo.app.lifeplus.activity.ActivityBase;
|
|
|
+import kr.co.zumo.app.lifeplus.activity.AppInitializer;
|
|
|
+import kr.co.zumo.app.lifeplus.activity.DynamicLinkLauncher;
|
|
|
+import kr.co.zumo.app.lifeplus.activity.MainActivity;
|
|
|
+import kr.co.zumo.app.lifeplus.activity.ScreenStarter;
|
|
|
import kr.co.zumo.app.lifeplus.application.App;
|
|
|
-import kr.co.zumo.app.lifeplus.bean.api.EmergencyBean;
|
|
|
import kr.co.zumo.app.lifeplus.bean.api.LifeplusAPIBean;
|
|
|
import kr.co.zumo.app.lifeplus.helper.AppShieldHelper;
|
|
|
import kr.co.zumo.app.lifeplus.helper.AppVersionHelper;
|
|
|
import kr.co.zumo.app.lifeplus.helper.FirebaseMessagingHelper;
|
|
|
-import kr.co.zumo.app.lifeplus.helper.Helper;
|
|
|
import kr.co.zumo.app.lifeplus.model.SuperModel;
|
|
|
import kr.co.zumo.app.lifeplus.model.SuperModelInit;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APIError;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APIModuleHelper;
|
|
|
-import kr.co.zumo.app.lifeplus.model.module.IAPIModuleListener;
|
|
|
-import kr.co.zumo.app.lifeplus.model.module.IEmergency;
|
|
|
-import kr.co.zumo.app.lifeplus.model.module.IModuleEmergencyHandler;
|
|
|
+import kr.co.zumo.app.lifeplus.model.module.APIModuleListener;
|
|
|
import kr.co.zumo.app.lifeplus.network.NetworkWatcher;
|
|
|
+import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
|
|
|
import kr.co.zumo.app.lifeplus.util.AppUtil;
|
|
|
-import kr.co.zumo.app.lifeplus.util.ResourceUtil;
|
|
|
import kr.co.zumo.app.lifeplus.view.Event;
|
|
|
-import kr.co.zumo.app.lifeplus.view.IView;
|
|
|
import kr.co.zumo.app.lifeplus.view.command.AppUpdateCommand;
|
|
|
+import kr.co.zumo.app.lifeplus.view.command.ExitCommand;
|
|
|
import kr.co.zumo.app.lifeplus.view.dialog.ConfirmDialog;
|
|
|
import kr.co.zumo.app.lifeplus.view.dialog.DialogBuilder;
|
|
|
import kr.co.zumo.app.lifeplus.view.dialog.DialogID;
|
|
|
import kr.co.zumo.app.lifeplus.view.dialog.DialogProvider;
|
|
|
import kr.co.zumo.app.lifeplus.view.dialog.ICustomConfirmListener;
|
|
|
+import kr.co.zumo.app.lifeplus.view.presenter.Presenter;
|
|
|
import kr.co.zumo.app.lifeplus.view.screen.setting.MemberInfoModelHelper;
|
|
|
import kr.co.zumo.app.lifeplus.zumo.bean.api.MemberInfoBean;
|
|
|
|
|
|
@@ -51,33 +53,178 @@ import kr.co.zumo.app.lifeplus.zumo.bean.api.MemberInfoBean;
|
|
|
*
|
|
|
* @author 민효동
|
|
|
* @version 1.0
|
|
|
- * @history 민효동 [2019. 2. 20.] [최초 작성]
|
|
|
- * @since 2019. 2. 20.
|
|
|
+ * @history 민효동 [2019-04-02] [최초 작성]
|
|
|
+ * @since 2019-04-02
|
|
|
*/
|
|
|
-public class SplashPresenter implements ISplashContract.Presenter, IModuleEmergencyHandler {
|
|
|
+public class SplashPresenter extends Presenter<SplashModel, ISplashView> {
|
|
|
|
|
|
- private ISplashContract.Model model;
|
|
|
- private ISplashContract.View view;
|
|
|
+ private final static int REQUEST_CODE = 9909;
|
|
|
|
|
|
private CompositeDisposable disposable = new CompositeDisposable();
|
|
|
private ScreenStarter starter;
|
|
|
|
|
|
private boolean isRequestingLocationService = false;
|
|
|
|
|
|
- SplashPresenter(ISplashContract.Model model, ISplashContract.View view) {
|
|
|
- this.model = model;
|
|
|
- this.view = view;
|
|
|
+ public SplashPresenter(SplashModel model, ISplashView view) {
|
|
|
+ super(model, view);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void createViewInternal() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void destroyInternal() {
|
|
|
+
|
|
|
+ if (null != disposable) {
|
|
|
+ disposable.dispose();
|
|
|
+ disposable = null;
|
|
|
+ }
|
|
|
+ if (null != starter) {
|
|
|
+ starter.dispose();
|
|
|
+ starter = null;
|
|
|
+ }
|
|
|
+ view = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void destroyViewInternal() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void startInternal() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void startInternalOnce() {
|
|
|
+
|
|
|
+ // 전체 퍼미션 확인
|
|
|
+
|
|
|
+ // 앱 첫 실행시에만 실행한다.
|
|
|
+ if (model.getFirstPermissionCompleted()) {
|
|
|
+ // 이미 처리 완료했음.
|
|
|
+ onPermissionCompleted();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ model.setFirstPermissionCompleted();
|
|
|
+
|
|
|
+ launchPushPermission(() -> {
|
|
|
+ launchDeviceLocationPermission(() -> {
|
|
|
+ launchLocationPermission(() -> {
|
|
|
+ // 권한 처리 종료
|
|
|
+ onPermissionCompleted();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void stopInternal() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void resumeInternal() {
|
|
|
+ if (isRequestingLocationService) {
|
|
|
+ isRequestingLocationService = false;
|
|
|
+
|
|
|
+ launchLocationPermission(() -> {
|
|
|
+ // 권한 처리 종료
|
|
|
+ onPermissionCompleted();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void pauseInternal() {
|
|
|
|
|
|
- APIModuleHelper.setEmergencyHandler(this);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected void onEventInternal(Event event) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onScreenReady() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResult(Event event) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void requestLocationPermissions(@NonNull String[] permissions) {
|
|
|
+ Log.i("APP# SplashPresenter | requestLocationPermissions", "|" + " permissions: " + Arrays.toString(permissions));
|
|
|
+ view.requestLocationPermissions(REQUEST_CODE, permissions);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
+ switch (requestCode) {
|
|
|
+ case REQUEST_CODE: {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 권한 처리 종료
|
|
|
+ onPermissionCompleted();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void linkActivity(int screenId) {
|
|
|
+ // 로그인/가입 같은 액티비티에서 처리됨
|
|
|
+ if (screenId == ScreenStarter.SCREEN_SIGN_IN || screenId == ScreenStarter.SCREEN_SIGN_UP) {
|
|
|
+ if (false == APIModuleHelper.isDispatched()) {
|
|
|
+ go(ScreenID.SIGN_IN);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (false == APIModuleHelper.isDispatched()) {
|
|
|
+ Intent intent = new Intent(view.getActivity(), MainActivity.class);
|
|
|
+ intent.putExtra(ScreenStarter.SCREEN_ID, screenId);
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+
|
|
|
+ if (false == APIModuleHelper.isDispatched()) {
|
|
|
+ finish();
|
|
|
+ ((ActivityBase) view.getActivity()).startActivity(intent, ActivityBase.SLIDE_TYPE_HOME);
|
|
|
+
|
|
|
+ doOnLink();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void launchLocationPermission(Runnable runnable) {
|
|
|
if (model.hasLocationPermissions(view.getActivity())) {
|
|
|
// 위치 앱 권한
|
|
|
runnable.run();
|
|
|
}
|
|
|
else {
|
|
|
- view.requestLocationPermissions(new String[]{model.getPermissionsString()});
|
|
|
+ requestLocationPermissions(new String[]{model.getPermissionsString()});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -141,43 +288,6 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
.show();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void start() {
|
|
|
-
|
|
|
- // 전체 퍼미션 확인
|
|
|
-
|
|
|
- // 앱 첫 실행시에만 실행한다.
|
|
|
- if (model.getFirstPermissionCompleted()) {
|
|
|
- // 이미 처리 완료했음.
|
|
|
- onPermissionCompleted();
|
|
|
- }
|
|
|
- else {
|
|
|
- model.setFirstPermissionCompleted();
|
|
|
-
|
|
|
- launchPushPermission(() -> {
|
|
|
- launchDeviceLocationPermission(() -> {
|
|
|
- launchLocationPermission(() -> {
|
|
|
- // 권한 처리 종료
|
|
|
- onPermissionCompleted();
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResume() {
|
|
|
- if (isRequestingLocationService) {
|
|
|
- isRequestingLocationService = false;
|
|
|
-
|
|
|
- launchLocationPermission(() -> {
|
|
|
- // 권한 처리 종료
|
|
|
- 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.
|
|
|
@@ -201,23 +311,6 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
onPermissionCompleted();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void dispose() {
|
|
|
- if (null != disposable) {
|
|
|
- disposable.dispose();
|
|
|
- disposable = null;
|
|
|
- }
|
|
|
- if (null != model) {
|
|
|
- model.dispose();
|
|
|
- model = null;
|
|
|
- }
|
|
|
- if (null != starter) {
|
|
|
- starter.dispose();
|
|
|
- starter = null;
|
|
|
- }
|
|
|
- view = null;
|
|
|
- }
|
|
|
-
|
|
|
private void onPermissionCompleted() {
|
|
|
setupInternal();
|
|
|
}
|
|
|
@@ -230,8 +323,9 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
if (SuperModel.getInstance().isAppInitialized() && App.getInstance().isDisposable() == false) {
|
|
|
Log.e("APP# SplashPresenter | setupInternal", "|" + " restart from call...........");
|
|
|
|
|
|
- view.finish();
|
|
|
- view.onLink();
|
|
|
+ finish();
|
|
|
+
|
|
|
+ doOnLink();
|
|
|
}
|
|
|
else {
|
|
|
Log.e("APP# SplashPresenter | setupInternal", "|" + " first ...........................");
|
|
|
@@ -276,6 +370,10 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void doOnLink() {
|
|
|
+ DynamicLinkLauncher.launch(view.getActivity());
|
|
|
+ }
|
|
|
+
|
|
|
private void launchStarter(boolean isConnected) {
|
|
|
Context context = App.getInstance().getContext();
|
|
|
starter.launch(isConnected, (context1, fragmentFlag, memberStatus) -> {
|
|
|
@@ -292,7 +390,7 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
showRestPopup();
|
|
|
}
|
|
|
else {
|
|
|
- view.linkActivity(fragmentFlag);
|
|
|
+ linkActivity(fragmentFlag);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
@@ -310,10 +408,10 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
|
|
|
private void activateMember() {
|
|
|
// 휴면 해제
|
|
|
- model.activateMember(new IAPIModuleListener<LifeplusAPIBean>() {
|
|
|
+ model.activateMember(new APIModuleListener<LifeplusAPIBean>() {
|
|
|
@Override
|
|
|
public void onApiSuccess(LifeplusAPIBean resultBean) {
|
|
|
- view.linkActivity(ScreenStarter.SCREEN_MAIN);
|
|
|
+ linkActivity(ScreenStarter.SCREEN_MAIN);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -323,16 +421,6 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
exit();
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onApiStart() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onApiEnd() {
|
|
|
-
|
|
|
- }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -356,44 +444,11 @@ public class SplashPresenter implements ISplashContract.Presenter, IModuleEmerge
|
|
|
|
|
|
private void gotoPlayStore() {
|
|
|
// 플레이 스토어 이동
|
|
|
- new AppUpdateCommand(AppUtil.getPackageName()).execute(null, new IView() {
|
|
|
- @Override
|
|
|
- public FragmentActivity getActivity() {
|
|
|
- return view.getActivity();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getScreenId() { return 0; }
|
|
|
-
|
|
|
- @Override
|
|
|
- public <H extends Helper> H getHelper(Class<H> helperClass) { return null; }
|
|
|
- }, null);
|
|
|
- }
|
|
|
-
|
|
|
- private void showPopupInvalidApp() {
|
|
|
- Log.d("APP# ScreenStarter | showPopupInvalidApp", "|" + " ---------- ");
|
|
|
- DialogProvider.of(view.getActivity().getSupportFragmentManager()).showErrorDialog(ResourceUtil.getString(R.string.emergency_invalid_app), () -> {
|
|
|
- // 앱 종료
|
|
|
- exit();
|
|
|
- });
|
|
|
+ onCommand(new AppUpdateCommand(AppUtil.getPackageName()));
|
|
|
}
|
|
|
|
|
|
protected void exit() {
|
|
|
- view.getActivity().finishAffinity();
|
|
|
- AppInitializer.dispose();
|
|
|
+ onCommand(new ExitCommand());
|
|
|
}
|
|
|
|
|
|
- /***********************************
|
|
|
- * IModuleEmergencyHandler
|
|
|
- ***********************************/
|
|
|
- @Override
|
|
|
- public boolean onApiEmergency(IEmergency emergency) {
|
|
|
- if (emergency.getEmergencyCode() == EmergencyBean.CODE_INVALID_APP) {
|
|
|
- // 미인증 앱
|
|
|
- showPopupInvalidApp();
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|