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.
-
-
Constructor Summary
Constructors Constructor Description DeviceUserManager(Context context)
-
Method Summary
Modifier and Type Method Description final Unit
openStore()
Opens the store if not opened yet final DeviceUser
createUser(User user)
Creates a new user into the database, and return the user information final List<DeviceUser>
getOnBoardedUsers(Integer pageSize, Integer pageNo, String search)
Retrieves onBoarded local user list. 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. final List<DeviceUser>
getAllUsers(Integer pageSize, Integer pageNo, String search)
Retrieves all local user list. final Boolean
haveOtherOnBoardedUsers(DeviceUser user)
Checks whether there are other users already 'onBoarded'. final DeviceUser
getCurrentUser()
Retrieves the current user. final DeviceUser
findUserById(String id)
Finds a user by the given id. final Unit
deleteUserById(String id)
Deletes a user identified the given id. final Unit
makeCurrent(DeviceUser user, Boolean onBoarded, SuspendFunction2<DeviceUser, DeviceUser, Unit> userSwitchCallback)
Makes the given user as the current active user. final Unit
setOnBoarded(DeviceUser user, Boolean onBoarded)
Sets the onBoarded status for the given user. final Unit
reset()
Deletes the database. final Boolean
isStoreOpen()
Checkes whether the store is opened or not. final Unit
closeStore()
Closes the database. -
-
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 0search
- 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 0search
- The filter string, it does a 'like' operation on 'name' attribute.
-
getAllUsers
final List<DeviceUser> getAllUsers(Integer pageSize, Integer pageNo, String search)
-
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.
-
findUserById
final DeviceUser findUserById(String id)
Finds a user by the given id.
-
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 useronBoarded
- By default, this user will also be marked as 'onboarded' if this parameter is not provideduserSwitchCallback
- The callback function which needs to know both the current and the previous users.
-
setOnBoarded
final Unit setOnBoarded(DeviceUser user, Boolean onBoarded)
Sets the onBoarded status for the given user.
-
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.
-
-
-
-