Search in sources :

Example 1 with IPresenter

use of com.yydcdut.note.presenters.IPresenter in project PhotoNoter by yydcdut.

the class PermissionAspect method aroundCheckAndRequestPermission.

@Around("pointcut2CheckAndRequestPermissions(aspectPermission)")
public void aroundCheckAndRequestPermission(ProceedingJoinPoint proceedingJoinPoint, AspectPermission aspectPermission) {
    if (aspectPermission == null) {
        return;
    }
    IPresenter iPresenter = (IPresenter) proceedingJoinPoint.getTarget();
    int value = aspectPermission.value();
    switch(value) {
        case PermissionUtils.CODE_CAMERA:
        case PermissionUtils.CODE_ADJUST_CAMERA:
            {
                if (hasPermission4Camera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_STORAGE:
            {
                if (hasPermission4Storage(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_LOCATION_AND_CAMERA:
            {
                if (hasPermission4LocationAndCamera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_AUDIO:
            {
                if (hasPermission4Audio(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_PHONE_STATE:
            {
                if (hasPermission4PhoneState(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
    }
}
Also used : IPresenter(com.yydcdut.note.presenters.IPresenter) Activity(android.app.Activity) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Example 2 with IPresenter

use of com.yydcdut.note.presenters.IPresenter in project PhotoNoter by yydcdut.

the class PermissionAspect method aroundCheckAndRequestPermission.

@Around("pointcut2CheckAndRequestPermissions(permission)")
public void aroundCheckAndRequestPermission(ProceedingJoinPoint proceedingJoinPoint, Permission permission) {
    if (permission == null) {
        return;
    }
    IPresenter iPresenter = (IPresenter) proceedingJoinPoint.getTarget();
    int value = permission.value();
    switch(value) {
        case PermissionUtils.CODE_CAMERA:
        case PermissionUtils.CODE_ADJUST_CAMERA:
            {
                if (hasPermission4Camera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getIView().getRequestType().isActivity()) {
                        requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
                    } else {
                        requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
                    }
                }
            }
            break;
        case PermissionUtils.CODE_STORAGE:
            {
                if (hasPermission4Storage(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getIView().getRequestType().isActivity()) {
                        requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
                    } else {
                        requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
                    }
                }
            }
            break;
        case PermissionUtils.CODE_LOCATION_AND_CAMERA:
            {
                if (hasPermission4LocationAndCamera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getIView().getRequestType().isActivity()) {
                        requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
                    } else {
                        requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
                    }
                }
            }
            break;
        case PermissionUtils.CODE_AUDIO:
            {
                if (hasPermission4Audio(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getIView().getRequestType().isActivity()) {
                        requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
                    } else {
                        requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
                    }
                }
            }
            break;
        case PermissionUtils.CODE_PHONE_STATE:
            {
                if (hasPermission4PhoneState(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getIView().getRequestType().isActivity()) {
                        requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
                    } else {
                        requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
                    }
                }
            }
            break;
    }
}
Also used : IPresenter(com.yydcdut.note.presenters.IPresenter) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Aggregations

IPresenter (com.yydcdut.note.presenters.IPresenter)2 JoinPoint (org.aspectj.lang.JoinPoint)2 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)2 Around (org.aspectj.lang.annotation.Around)2 Activity (android.app.Activity)1