Class BasePermissionHelper
- java.lang.Object
-
- androidx.fragment.app.Fragment
-
- com.cheetahdigital.uikit.helper.permissions.BasePermissionHelper
-
- All Implemented Interfaces:
android.content.ComponentCallbacks,android.view.View.OnCreateContextMenuListener,androidx.lifecycle.LifecycleOwner,androidx.lifecycle.ViewModelStoreOwner,androidx.savedstate.SavedStateRegistryOwner,ConfirmDialogFragment.ConfirmDialogListener
- Direct Known Subclasses:
AccountsPermissionHelper,CameraPermissionHelper,CameraStoragePermissionHelper,ContactsPermissionHelper,LocationPermissionHelper,StoragePermissionHelper
public abstract class BasePermissionHelper extends androidx.fragment.app.Fragment implements ConfirmDialogFragment.ConfirmDialogListener
Base class for permission helpers
-
-
Field Summary
Fields Modifier and Type Field Description protected android.app.ActivitymActivityprotected android.content.ContextmContextprotected java.lang.String[]mPermissions
-
Constructor Summary
Constructors Constructor Description BasePermissionHelper()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcheckPermission()Checks the permissions that was set on thegetPermissions()methodabstract java.lang.StringgetPermissionRationale()Set the description on why the permission is neededabstract java.lang.String[]getPermissions()Set the name of the permissions you need to checkbooleanisGranted()Check permission grant statusvoidonAttach(android.content.Context context)voidonCancel(java.lang.String tag)Method called on rational dialog negative button clickvoidonConfirm(java.lang.String tag)Method called on rationale dialog positive button clickvoidonCreate(android.os.Bundle savedInstanceState)voidonDetach()protected abstract voidonPermissionDenied()Method called after permission was deniedprotected abstract voidonPermissionGranted()Method called after permission was grantedvoidonRequestPermissionsResult(int requestCode, java.lang.String[] permissions, int[] grantResults)voidrequestPermissions()Request permissions that was set on thegetPermissions()methodbooleanshouldShowPermissionRationale()Check if appropriate to show explanation on why the permission is being requestedvoidshowPermissionRationale(int title, int message, int positive, int negative)Shows a dialog explaining why the needs the permissionvoidshowPermissionRationale(int title, int message, int positive, int negative, ConfirmDialogFragment.ConfirmDialogListener listener)Shows a dialog explaining why the needs the permission-
Methods inherited from class androidx.fragment.app.Fragment
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onActivityResult, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onDestroyView, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onResume, onSaveInstanceState, onStart, onStop, onViewCreated, onViewStateRestored, postponeEnterTransition, postponeEnterTransition, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
-
-
-
-
Method Detail
-
onAttach
public void onAttach(android.content.Context context)
- Overrides:
onAttachin classandroidx.fragment.app.Fragment
-
onCreate
public void onCreate(android.os.Bundle savedInstanceState)
- Overrides:
onCreatein classandroidx.fragment.app.Fragment
-
onDetach
public void onDetach()
- Overrides:
onDetachin classandroidx.fragment.app.Fragment
-
isGranted
public boolean isGranted()
Check permission grant status- Returns:
- true if permission is already granted
-
requestPermissions
public void requestPermissions()
Request permissions that was set on thegetPermissions()method
-
shouldShowPermissionRationale
public boolean shouldShowPermissionRationale()
Check if appropriate to show explanation on why the permission is being requested- Returns:
- true if the app has requested this permission previously and the user denied the request.
-
showPermissionRationale
public void showPermissionRationale(@StringRes int title, @StringRes int message, @StringRes int positive, @StringRes int negative)Shows a dialog explaining why the needs the permission- Parameters:
title- dialog titlemessage- explaining why the app needs the permissionpositive- first actionnegative- second action
-
showPermissionRationale
public void showPermissionRationale(@StringRes int title, @StringRes int message, @StringRes int positive, @StringRes int negative, ConfirmDialogFragment.ConfirmDialogListener listener)Shows a dialog explaining why the needs the permission- Parameters:
title- dialog titlemessage- explaining why the app needs the permissionpositive- first actionnegative- second actionlistener- callback for dialog
-
checkPermission
public void checkPermission()
Checks the permissions that was set on thegetPermissions()method
-
onRequestPermissionsResult
public void onRequestPermissionsResult(int requestCode, @NonNull java.lang.String[] permissions, @NonNull int[] grantResults)- Overrides:
onRequestPermissionsResultin classandroidx.fragment.app.Fragment
-
onConfirm
public void onConfirm(java.lang.String tag)
Method called on rationale dialog positive button click- Specified by:
onConfirmin interfaceConfirmDialogFragment.ConfirmDialogListener- Parameters:
tag- dialog identifier
-
onCancel
public void onCancel(java.lang.String tag)
Method called on rational dialog negative button click- Specified by:
onCancelin interfaceConfirmDialogFragment.ConfirmDialogListener- Parameters:
tag- dialog identifier
-
getPermissions
public abstract java.lang.String[] getPermissions()
Set the name of the permissions you need to check- Returns:
- permissions to check
-
getPermissionRationale
public abstract java.lang.String getPermissionRationale()
Set the description on why the permission is needed- Returns:
- description
-
onPermissionGranted
protected abstract void onPermissionGranted()
Method called after permission was granted
-
onPermissionDenied
protected abstract void onPermissionDenied()
Method called after permission was denied
-
-