Skip to main content
Version: Next

Android

Huma Utils SDK is the core library for other SDK components. It provides access to core features like networking, notification handling and shared preferences

Getting Started

Networking

SDK uses OkHttp and Retrofit for networking. You can use the instance of Retrofit to create your API interface. SDK allows registering your interceptor or authenticator

//returns instance of NetworkManager
HumaUtilsManager.network

//returns instance of RegionManager of NetworkManager
HumaUtilsManager.network.regionManager

//returns instance of default Retrofit client
HumaUtilsManager.network.retrofit

//returns instance of uploading Retrofit client
HumaUtilsManager.network.uploadRetrofit

//register list of interceptors that will be injected to OkHttp client
HumaUtilsManager.network.registerInterceptor(vararg interceptor: Interceptor)

//register list of authenticators that will be injected to OkHttp client
HumaUtilsManager.network.registerAuthenticator(vararg authenticator: Authenticator)

Preferences

PreferencesManager exposes baseUrlPreferencesManager where the actual target is stored URL for NetworkManager. It contains method to obtain and store values in SharedPreferences with modifiers.

enum class SharedPrefType {
DEFAULT,
ENCRYPTED,
IMMUTABLE
}

//Saves value by provided key and pref type.
HumaUtilsManager.preferences.set(key: String, value: Any?, type: SharedPrefType = DEFAULT)

//Returns value by provided key and pref type. Uses default value if not found in storage.
HumaUtilsManager.preferences.get(key: String, default: T, type: SharedPrefType)

//Clears shared preferences. MFA preferences won't be cleared by default
HumaUtilsManager.preferences.clear(isClearMFAPref: Boolean = false)

Shared preferences can be set to fields with delegates:

BooleanStorage - for storing boolean values
FloatStorage - for storing float values
IntStorage - for storing integer values
LongStorage - for storing long values
SetStorage - for storing set of strings values
StringStorage - for storing string values
AnyStorage - for storing complex objects (they will be serialized to json and back)

Or you can use the inline function to set it to the field directly:

var uid: String by pref(UID, "") //default shared preferences field with key == UID
var uid: String by encryptedPref(UID, "") //encrypted shared preferences field with key == UID
var uid: String by immutablePref(UID, "") //immutable shared preferences field with key == UID

Notifications

NotificationManager allows registering new notification types and processing them via PushNotificationHandler. Also NotificationManager requires to provide auth state via AuthStateProvider as it has auto signoff on logout. If you using Huma Auth SDK it will register AuthStateProvider internally.

//register PushNotificationHandler
HumaUtilsManager.preferences.registerPushNotificationHandler(vararg handler: PushNotificationHandler)

//register AuthStateProvider
HumaUtilsManager.preferences.registerAuthStateProvider(authStateProvider: AuthStateProvider)