-
public abstract class Session
The Session class stores a User and all pending Record uploads.
OverviewThe User and all pending Record data is persisted between app launches but is deleted if is called.
Session is a singleton object and must be accessed by its getInstance method. The different components of the Validic Mobile library rely on a valid user existing in the current Session singleton object.
A New session is started with a provided User. To use an existing user ID, create a create a User object and provide it to the startSessionWithUser method. Note, starting a session will delete all local data if a current session exists.
ListenersWhen Session uploads a record it will notify the stored SessionListener. To receive these notifications, register a SessionListener by calling setSessionListener.
If the record upload is successful, didSubmitRecord will be called.
If a 400 error is returned from the server, the record will be discarded and didFailToSubmitRecord will be called.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
Session.SessionConnectionListener
Listener for a Session starting or ending
-
Field Summary
Fields Modifier and Type Field Description private static Session
instance
WeakReference<SessionListener>
sessionListener
private boolean
silencedCallbacks
-
Method Summary
Modifier and Type Method Description static Session
getInstance()
Retrieve the object instance void
setSessionListener(SessionListener sessionListener)
Sets the SessionListener void
setSilencedCallbacks(boolean silenceCallbacks)
Boolean to not send callbacks to the listener static boolean
isValid()
Returns true if a session with a user has been loaded in to memory. static String
libraryVersion()
Report the current version of the library boolean
callbacksAreSilenced()
Boolean to not send callbacks to the listener boolean
addSessionConnectionListener(Session.SessionConnectionListener listener)
Add a SessionConnectionListener to listen for a Session starting or ending boolean
removeSessionConnectionListener(Session.SessionConnectionListener listener)
Remove a SessionConnectionListener from the collection of listeners User
getUser()
Returns the current user of the session. abstract void
startSessionWithUser(User user)
Starts a new session with the specified User. abstract void
endSession()
Removes all locally stored session data and removes a user from internal storage abstract void
submitRecord(@NonNull() Record record)
Queues a Record for submission. abstract void
submitRecord(@NonNull() Record record, @Nullable() Bitmap image)
Queues a Record and associated android.graphics.Bitmap for submission. abstract void
submitRecords(@NonNull() Collection<Record> records)
Queues a collection of Record objects for submission. List<Record>
getQueuedRecords()
All pending Record objects to be uploaded. ConcurrentHashMap<String, ConcurrentHashMap<String, Object>>
getDataForBluetoothPeripheralID(Integer matchID)
get the stashed data for this peripheral ID e.g. void
setDataForBluetoothPeripheral(Integer setID, ConcurrentHashMap<String, ConcurrentHashMap<String, Object>> data)
set the stashed data for this peripheral ID e.g. -
-
Method Detail
-
getInstance
static Session getInstance()
Retrieve the object instance
-
setSessionListener
void setSessionListener(SessionListener sessionListener)
Sets the SessionListener
- Parameters:
sessionListener
- Callback for various Record related events.
-
setSilencedCallbacks
void setSilencedCallbacks(boolean silenceCallbacks)
Boolean to not send callbacks to the listener
-
isValid
static boolean isValid()
Returns true if a session with a user has been loaded in to memory.
-
libraryVersion
static String libraryVersion()
Report the current version of the library
-
callbacksAreSilenced
boolean callbacksAreSilenced()
Boolean to not send callbacks to the listener
-
addSessionConnectionListener
boolean addSessionConnectionListener(Session.SessionConnectionListener listener)
Add a SessionConnectionListener to listen for a Session starting or ending
- Parameters:
listener
- Listener to add
-
removeSessionConnectionListener
boolean removeSessionConnectionListener(Session.SessionConnectionListener listener)
Remove a SessionConnectionListener from the collection of listeners
- Parameters:
listener
- Listener to remove
-
startSessionWithUser
abstract void startSessionWithUser(User user)
Starts a new session with the specified User. Deletes existing session if present.
-
endSession
abstract void endSession()
Removes all locally stored session data and removes a user from internal storage
-
submitRecord
abstract void submitRecord(@NonNull() Record record)
Queues a Record for submission.
-
submitRecord
abstract void submitRecord(@NonNull() Record record, @Nullable() Bitmap image)
Queues a Record and associated android.graphics.Bitmap for submission.
-
submitRecords
abstract void submitRecords(@NonNull() Collection<Record> records)
-
getQueuedRecords
@NonNull() List<Record> getQueuedRecords()
All pending Record objects to be uploaded.
-
getDataForBluetoothPeripheralID
ConcurrentHashMap<String, ConcurrentHashMap<String, Object>> getDataForBluetoothPeripheralID(Integer matchID)
get the stashed data for this peripheral ID e.g. passwords obtained during pairing that need to be used later ... note that some peripherals will have info specific to a particular hardware (MAC) address and others will have the same info for all models, so if you have the same info for all models, you can just use whichever top level entry in the returned map that you want to use - that's up to the peripheral's Bluetooth controllers to decide
-
setDataForBluetoothPeripheral
void setDataForBluetoothPeripheral(Integer setID, ConcurrentHashMap<String, ConcurrentHashMap<String, Object>> data)
set the stashed data for this peripheral ID e.g. e.g. passwords obtained during pairing that need to be used later ... note that some peripherals will have info specific to a particular hardware (MAC) address and others will have the same info for all models, so if you have the same info for all models, you can just use whichever top level entry in the returned map that you want to use - that's up to the peripheral's Bluetooth controllers to decide
-
-
-
-