Skip to main content
Version: Next

Android

Library that implements profile settings screen functionality

Getting Started

Start profile activity:

// you need to be authenticated 
startActivity(ProfileActivity.getIntent(this))

Set notifications badge count:

// for single setting
HumaProfileManager.getInstance().setSettingNotificationsCount("setting 1", 1)

// for multiple settings
HumaProfileManager.getInstance().setSettingsNotificationsCount(
mapOf(
"setting 2" to 2,
"setting 3" to 3
)
)

Clear notifications badges:

HumaProfileManager.getInstance().clearNotifications()

Sync notifications count (will invoke ProfileSettingsRepository.getNotificationsCountBySettingId()):

HumaProfileManager.getInstance().syncProfileNotificationsCount(
onSynced = { /* on success */ },
onFailure = { error -> /* on failure */ }
)

Customization

If you want to use custom profile settings instead of the default ones, it is possible to provide ProfileSettingsRepository implementation when initializing HumaProfileManager.

Some settings will be hidden if needed (refer to SettingItem.shouldBeShown(/*..*/)), and empty section headers will be removed

HumaProfileManager.init(
profileSettingsRepository = object : ProfileSettingsRepository() {
override suspend fun getSettings(): Result<List<SettingsListItem>, Error> {
// returns a list of settings
}

override suspend fun getNotificationsCountBySettingId(): Result<Map<String, Int>, Error> {
// returns a map of notifications count by setting id
}
}
)

Sample settings interaction handlers

Toggle that launches a screen and handles screen result:

(Make sure to not use a getter if you change setting state in the handler)

override val interactionHandler = DefaultSettingInteractionHandler.Toggle(
isSelected = AppLockPreferences.isAppLockEnabled
) { toggle ->
InteractionHandlerResult.ScreenToOpen(
getIntentDelegate = { context ->
if (toggle.isSelected) {
LockHumaAppActivity.getTurnOnLockIntent(context)
} else {
LockHumaAppActivity.getTurnOffLockIntent(context)
}
},
onResult = { activityResultData, uiDelegate ->
if ((requireNotNull(activityResultData).resultCode) != Activity.RESULT_OK) {
Timber.d("A flow launched by toggle was canceled/failed, reverting toggle selection status..")
// revert toggle selection state if the flow failed
toggle.isSelected = !toggle.isSelected
// refresh settings list to display the updated state
uiDelegate.notifySettingChanged()
return@ScreenToOpen
}
uiDelegate.showMessage(resources.getString(
if (toggle.isSelected) {
R.string.bio_auth_profile_tab_state_changed
} else {
R.string.bio_auth_profile_tab_state_disabled
}
))
}
)
}

Default setting that just launches the screen:

// with helper extension function
override val interactionHandler get() = DefaultSettingInteractionHandler.forScreen { context ->
DownloadDataActivity.getLauncherIntent(context)
}

// without helper extension function
override val interactionHandler get() = DefaultSettingInteractionHandler.Default {
InteractionHandlerResult.ScreenToOpen(getIntentDelegate = { context ->
DownloadDataActivity.getLauncherIntent(context)
})
}