Skip to content

Commit

Permalink
Return boolean value based on login prompt beeing shown or not (#106)
Browse files Browse the repository at this point in the history
Co-authored-by: filip-misztal <filip.misztal@schibsted.com>
  • Loading branch information
xserxses and filip-misztal committed Jan 29, 2024
1 parent 3ca05c7 commit 4aee789
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,23 +320,24 @@ class Client {
*
* @param supportFragmentManager Activity's Fragment manager.
* @param isCancelable set if loginPrompt should be cancelable by user.
* @return true if login prompt is shown, false otherwise.
*/
@JvmOverloads
suspend fun requestLoginPrompt(
context: Context,
supportFragmentManager: FragmentManager,
isCancelable: Boolean = true
) {
) : Boolean {
val internalSessionFound = hasSessionStorage(configuration.clientId)

if (!internalSessionFound && userHasSessionOnDevice(context.applicationContext)) {
return if (!internalSessionFound && userHasSessionOnDevice(context.applicationContext)) {
LoginPromptManager(
LoginPromptConfig(
this.getAuthenticationIntent(context),
isCancelable
)
).showLoginPromptIfAbsent(supportFragmentManager)
}
} else false
}

private suspend fun hasSessionStorage(clientId: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ internal class LoginPromptManager(private val loginPromptConfig: LoginPromptConf
* Show login prompt.
*
* @param supportFragmentManager Calling entity's fragment manager.
* @return true if login prompt is shown, false otherwise.
*/
fun showLoginPromptIfAbsent(supportFragmentManager: FragmentManager) {
fun showLoginPromptIfAbsent(supportFragmentManager: FragmentManager) : Boolean{
val loginPromptFragment =
supportFragmentManager.findFragmentByTag(fragmentTag) as? LoginPromptFragment

if (loginPromptFragment == null) {
return if (loginPromptFragment == null) {
initializeLoginPrompt(loginPromptConfig).show(supportFragmentManager, fragmentTag)
}
true
} else false
}

private fun initializeLoginPrompt(config: LoginPromptConfig): LoginPromptFragment =
Expand Down

0 comments on commit 4aee789

Please sign in to comment.