|
@@ -1,399 +0,0 @@
|
|
|
-/*
|
|
|
|
|
- * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
|
|
|
|
|
- */
|
|
|
|
|
-package kr.co.zumo.app.lifeplus.activity;
|
|
|
|
|
-
|
|
|
|
|
-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.util.Log;
|
|
|
|
|
-
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-
|
|
|
|
|
-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.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.network.NetworkWatcher;
|
|
|
|
|
-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.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.screen.setting.MemberInfoModelHelper;
|
|
|
|
|
-import kr.co.zumo.app.lifeplus.zumo.bean.api.MemberInfoBean;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * SplashPresenter
|
|
|
|
|
- * <pre>
|
|
|
|
|
- * </pre>
|
|
|
|
|
- *
|
|
|
|
|
- * @author 민효동
|
|
|
|
|
- * @version 1.0
|
|
|
|
|
- * @history 민효동 [2019. 2. 20.] [최초 작성]
|
|
|
|
|
- * @since 2019. 2. 20.
|
|
|
|
|
- */
|
|
|
|
|
-public class SplashPresenter implements ISplashContract.Presenter, IModuleEmergencyHandler {
|
|
|
|
|
-
|
|
|
|
|
- private ISplashContract.Model model;
|
|
|
|
|
- private ISplashContract.View view;
|
|
|
|
|
-
|
|
|
|
|
- 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;
|
|
|
|
|
-
|
|
|
|
|
- APIModuleHelper.setEmergencyHandler(this);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void launchLocationPermission(Runnable runnable) {
|
|
|
|
|
- if (model.hasLocationPermissions(view.getActivity())) {
|
|
|
|
|
- // 위치 앱 권한
|
|
|
|
|
- runnable.run();
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- view.requestLocationPermissions(new String[]{model.getPermissionsString()});
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void launchDeviceLocationPermission(Runnable runnable) {
|
|
|
|
|
- if (model.canAccessDeviceLocating(view.getActivity())) {
|
|
|
|
|
- // 위치 서비스 이용 가능하다면 다음으로 이동
|
|
|
|
|
- runnable.run();
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- 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 launchPushPermission(Runnable runnable) {
|
|
|
|
|
- // 설정 창 표시
|
|
|
|
|
- launchInternal(() -> {
|
|
|
|
|
-
|
|
|
|
|
-// model.setPushContentsAndService(true);
|
|
|
|
|
- model.setPushEventEnabled(true);
|
|
|
|
|
- // 앱 첫 실행 시 사용자 선택을 로그인 후 반영해줘야 한다.
|
|
|
|
|
- MemberInfoModelHelper.getInstance().setAppInitPushSetting(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) {
|
|
|
|
|
- dialog.dispose();
|
|
|
|
|
- runnableConfirm.run();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onNegativeResult(ConfirmDialog dialog, Event event) {
|
|
|
|
|
- dialog.dispose();
|
|
|
|
|
- runnableNext.run();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onDialogCanceled(ConfirmDialog dialog) {
|
|
|
|
|
- dialog.dispose();
|
|
|
|
|
- runnableNext.run();
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .attribute(dialog -> {
|
|
|
|
|
- dialog.setCancelable(false);
|
|
|
|
|
- dialog.setTitleId(titleId);
|
|
|
|
|
- dialog.setText(contentsId);
|
|
|
|
|
- dialog.setNegativeButtonLabelId(negativeId);
|
|
|
|
|
- dialog.setPositiveButtonLabelId(positiveId);
|
|
|
|
|
- })
|
|
|
|
|
- .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.
|
|
|
|
|
- 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();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @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();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void setupInternal() {
|
|
|
|
|
-
|
|
|
|
|
- Context context = App.getInstance().getContext();
|
|
|
|
|
-
|
|
|
|
|
- // 앱이 실행 중인지 판단한다.
|
|
|
|
|
- if (SuperModel.getInstance().isAppInitialized() && App.getInstance().isDisposable() == false) {
|
|
|
|
|
- Log.e("APP# SplashPresenter | setupInternal", "|" + " restart from call...........");
|
|
|
|
|
-
|
|
|
|
|
- view.finish();
|
|
|
|
|
- view.onLink();
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- Log.e("APP# SplashPresenter | setupInternal", "|" + " first ...........................");
|
|
|
|
|
-
|
|
|
|
|
- SuperModelInit.instant(context);
|
|
|
|
|
-
|
|
|
|
|
- starter = new ScreenStarter(view.getActivity());
|
|
|
|
|
-
|
|
|
|
|
- // 네트워크 연결 체크
|
|
|
|
|
- disposable.add(
|
|
|
|
|
- new NetworkWatcher().check(context)
|
|
|
|
|
- .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
- .subscribe(isConnected -> {
|
|
|
|
|
- disposable.dispose();
|
|
|
|
|
-
|
|
|
|
|
- if (isConnected) {
|
|
|
|
|
- AppShieldHelper.getInstance().checkApp(context);
|
|
|
|
|
- AppVersionHelper.getInstance().fetch(view.getActivity(), flag -> {
|
|
|
|
|
- switch (flag) {
|
|
|
|
|
- case AppVersionHelper.IAppVersionListener.FLAG_FORCE:
|
|
|
|
|
- // 강제 업데이트
|
|
|
|
|
- showPopupAppUpdate();
|
|
|
|
|
- break;
|
|
|
|
|
- case AppVersionHelper.IAppVersionListener.FLAG_LATEST:
|
|
|
|
|
- // 선택 업데이트
|
|
|
|
|
- showPopupAppUpdateLatest();
|
|
|
|
|
- break;
|
|
|
|
|
- case AppVersionHelper.IAppVersionListener.FLAG_UNABLE:
|
|
|
|
|
- /* falls through */
|
|
|
|
|
- default:
|
|
|
|
|
- launchStarter(true);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- launchStarter(isConnected);
|
|
|
|
|
- }
|
|
|
|
|
- }, Throwable::printStackTrace)
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void launchStarter(boolean isConnected) {
|
|
|
|
|
- Context context = App.getInstance().getContext();
|
|
|
|
|
- starter.launch(isConnected, (context1, fragmentFlag, memberStatus) -> {
|
|
|
|
|
- /**
|
|
|
|
|
- * App init
|
|
|
|
|
- */
|
|
|
|
|
- AppInitializer.init(context);
|
|
|
|
|
-
|
|
|
|
|
- // topic 가입
|
|
|
|
|
- FirebaseMessagingHelper.getInstance().subscribeToTopic();
|
|
|
|
|
-
|
|
|
|
|
- if (MemberInfoBean.isInActiveAccount(memberStatus)) {
|
|
|
|
|
- // 휴면 회원
|
|
|
|
|
- showRestPopup();
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- view.linkActivity(fragmentFlag);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- private void showRestPopup() {
|
|
|
|
|
- DialogProvider.of(view.getActivity().getSupportFragmentManager()).showRestDialog(() -> {
|
|
|
|
|
- activateMember();
|
|
|
|
|
- }, () -> {
|
|
|
|
|
- // 앱 종료
|
|
|
|
|
- exit();
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void activateMember() {
|
|
|
|
|
- // 휴면 해제
|
|
|
|
|
- model.activateMember(new IAPIModuleListener<LifeplusAPIBean>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onApiSuccess(LifeplusAPIBean resultBean) {
|
|
|
|
|
- view.linkActivity(ScreenStarter.SCREEN_MAIN);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onApiError(String errorMessage, APIError error) {
|
|
|
|
|
- DialogProvider.of(view.getActivity().getSupportFragmentManager()).showErrorDialog(errorMessage, () -> {
|
|
|
|
|
- // 앱 종료
|
|
|
|
|
- exit();
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onApiStart() {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onApiEnd() {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void showPopupAppUpdate() {
|
|
|
|
|
- DialogProvider.of(view.getActivity().getSupportFragmentManager()).showPopupAppUpdate(() -> {
|
|
|
|
|
- gotoPlayStore();
|
|
|
|
|
- }, () -> {
|
|
|
|
|
- // 앱 종료
|
|
|
|
|
- exit();
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void showPopupAppUpdateLatest() {
|
|
|
|
|
- DialogProvider.of(view.getActivity().getSupportFragmentManager()).showPopupAppUpdateLatest(() -> {
|
|
|
|
|
- gotoPlayStore();
|
|
|
|
|
- }, () -> {
|
|
|
|
|
- // 다음 진행
|
|
|
|
|
- launchStarter(true);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- 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();
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- protected void exit() {
|
|
|
|
|
- view.getActivity().finishAffinity();
|
|
|
|
|
- AppInitializer.dispose();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /***********************************
|
|
|
|
|
- * IModuleEmergencyHandler
|
|
|
|
|
- ***********************************/
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean onApiEmergency(IEmergency emergency) {
|
|
|
|
|
- if (emergency.getEmergencyCode() == EmergencyBean.CODE_INVALID_APP) {
|
|
|
|
|
- // 미인증 앱
|
|
|
|
|
- showPopupInvalidApp();
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|