Package 

Class PermissionsViewModel


  • 
    public final class PermissionsViewModel
    extends ViewModel
                        

    ViewModel that handles the business logic for permission requests. This separates the permission handling logic from the Activity lifecycle. Uses AndroidX ViewModel with StateFlow for lifecycle-aware state management.

    Responsibilities:

    • Store permission request state (survives configuration changes)

    • Handle permission result business logic

    • Manage callbacks and preferences

    • Does NOT hold Activity references or call Activity APIs directly

    • Constructor Detail

      • PermissionsViewModel

        PermissionsViewModel()
    • Method Detail

      • initialize

         final Boolean initialize(Activity activity, String permissionType, String androidPermission)

        Initialize OneSignal and the ViewModel with intent data. Returns false if initialization fails.

        Parameters:
        activity - Activity context (not stored, used only for initialization)
      • shouldRequestPermission

         final Boolean shouldRequestPermission()

        Check if we should request permission (prevents duplicate requests). Activity should call this before requesting permission.

      • resetWaitingState

         final Unit resetWaitingState()

        Reset the waiting flag. This should be called when the activity is interrupted or destroyed without completing the permission request flow. This ensures the permission dialog can be shown again.

      • recordRationaleState

         final Unit recordRationaleState(Boolean shouldShowRationale)

        Record the rationale state before the permission request. Activity calls this with the result of shouldShowRequestPermissionRationale().

      • onRequestPermissionsResult

         final Unit onRequestPermissionsResult(Array<String> permissions, IntArray grantResults, Boolean shouldShowRationaleAfter)

        Handle the permission request result. Activity should call this with the result from onRequestPermissionsResult.

        Parameters:
        shouldShowRationaleAfter - The result of shouldShowRequestPermissionRationale AFTER the user responded