Class DeviceUserManager

  • All Implemented Interfaces:

    
    public final class DeviceUserManager
    
                        

    Represents the device user manager to manage the user information saved on the device.

    Most of the operations in this service will automatically open the store before the operation and close the store afterwards.

    For getOnBoardedUsers, it will not close after the operation since it might be used in the paginated list and will be called multiple times.

    To save system resources, closing the store after being used is recommended, and the right time to close the store might be, for example, after onboarding or restore flow.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      DeviceUserManager(Context context)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

      • DeviceUserManager

        DeviceUserManager(Context context)
    • Method Detail

      • openStore

         final Unit openStore()

        Opens the store if not opened yet

      • createUser

         final DeviceUser createUser(User user)

        Creates a new user into the database, and return the user information

      • getOnBoardedUsers

         final List<DeviceUser> getOnBoardedUsers(Integer pageSize, Integer pageNo, String search)

        Retrieves onBoarded local user list.

        Parameters:
        pageSize - The load page size.
        pageNo - Which page to load, it starts from 0
        search - The filter string, it does a 'like' operation on 'name' attribute.
      • getOnBoardedUsers

         final Job getOnBoardedUsers(ServiceListener<List<DeviceUser>> listener, Integer pageSize, Integer pageNo, String search)

        Retrieves onBoarded local user list, and notifies the result with the given listener.

        Parameters:
        listener - The result listener.
        pageSize - The load page size.
        pageNo - Which page to load, it starts from 0
        search - The filter string, it does a 'like' operation on 'name' attribute.
      • getAllUsers

         final List<DeviceUser> getAllUsers(Integer pageSize, Integer pageNo, String search)

        Retrieves all local user list. By default only 20 users will be returned if no pageSize provided. pageNo starts from '0'. The returned list is sorted by the latest active user with descending order.

      • haveOtherOnBoardedUsers

         final Boolean haveOtherOnBoardedUsers(DeviceUser user)

        Checks whether there are other users already 'onBoarded'. This is usually been used when the current user forgets the passcode and restarting the app, then the app needs to decide which flow to use. If no users already onBoarded, it will go directly to the onboarding flow, otherwise, it should go into 'Sign In' step.

        Parameters:
        user - The user to check again for 'others'.
      • getCurrentUser

         final DeviceUser getCurrentUser()

        Retrieves the current user. It might return 'null' to indicate there is no user signed in this device before.

      • deleteUserById

         final Unit deleteUserById(String id)

        Deletes a user identified the given id. This is mostly for single user mode when resetting a client.

      • makeCurrent

         final Unit makeCurrent(DeviceUser user, Boolean onBoarded, SuspendFunction2<DeviceUser, DeviceUser, Unit> userSwitchCallback)

        Makes the given user as the current active user. if userSwitchCallback is provided, both the current and previous active user will be notified.

        Parameters:
        user - The user to be marked as the current active user
        onBoarded - By default, this user will also be marked as 'onboarded' if this parameter is not provided
        userSwitchCallback - The callback function which needs to know both the current and the previous users.
      • reset

         final Unit reset()

        Deletes the database.

      • isStoreOpen

         final Boolean isStoreOpen()

        Checkes whether the store is opened or not.

      • closeStore

         final Unit closeStore()

        Closes the database.