Skip to content

Commit

Permalink
chore: clean up and minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed Mar 26, 2024
1 parent 9333e3b commit eaac814
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,26 @@ internal object OAuthRoute : Route(
return runCatching {
AuthRouter.Param(
accessToken =
requireNotNull(queryParameter(CALLBACK_QUERY_TOKEN_KEY)) {
"$CALLBACK_QUERY_TOKEN_KEY was not found in -> $fullyQualifiedUrl"
},
requireNotNull(queryParameter(CALLBACK_QUERY_TOKEN_KEY)) {
"$CALLBACK_QUERY_TOKEN_KEY was not found in -> $fullyQualifiedUrl"
},
tokenType =
requireNotNull(queryParameter(CALLBACK_QUERY_TOKEN_TYPE_KEY)) {
"$CALLBACK_QUERY_TOKEN_TYPE_KEY was not found in -> $fullyQualifiedUrl"
},
requireNotNull(queryParameter(CALLBACK_QUERY_TOKEN_TYPE_KEY)) {
"$CALLBACK_QUERY_TOKEN_TYPE_KEY was not found in -> $fullyQualifiedUrl"
},
expiresIn =
requireNotNull(queryParameter(CALLBACK_QUERY_TOKEN_EXPIRES_IN_KEY)) {
"$CALLBACK_QUERY_TOKEN_EXPIRES_IN_KEY was not found in -> $fullyQualifiedUrl"
}.toLong(),
)
}.getOrElse {
Timber.w(it)
AuthRouter.Param(
errorTitle = queryParameter(CALLBACK_QUERY_ERROR_KEY),
errorDescription = queryParameter(CALLBACK_QUERY_ERROR_DESCRIPTION_KEY),
requireNotNull(queryParameter(CALLBACK_QUERY_TOKEN_EXPIRES_IN_KEY)) {
"$CALLBACK_QUERY_TOKEN_EXPIRES_IN_KEY was not found in -> $fullyQualifiedUrl"
}.toLong(),
)
}
.onFailure(Timber::w)
.getOrDefault(
AuthRouter.Param(
errorTitle = queryParameter(CALLBACK_QUERY_ERROR_KEY),
errorDescription = queryParameter(CALLBACK_QUERY_ERROR_DESCRIPTION_KEY),
)
)
}

private fun DeepLinkUri.normalize(): Uri {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ class AuthContent(
requireBinding().stateLayout.loadStateFlow.value = it
}
viewModelState().model.observeOnce(viewLifecycleOwner) { user ->
if (user != null) {
runCatching {
presenter.runSignInWorker(user.id)
activity?.finish()
} else {
}.onFailure {
Snackbar.make(
requireView(),
R.string.auth_failed_message,
Expand All @@ -141,6 +140,8 @@ class AuthContent(
presenter.runSignOutWorker()
closeScreen()
}.show()
}.onSuccess {
activity?.onBackPressed()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
class AuthScreen : AniTrendScreen<AuthScreenBinding>() {

private val viewModel by viewModel<AuthViewModel>()
private val authRouterParam by extra<AuthRouter.Param>(AuthRouter.Param.KEY)

private fun checkIntentData() {
val key = AuthRouter.Param.KEY
val authRouterParam by extra<AuthRouter.Param>(key)
viewModel.onIntentData(
applicationContext,
authRouterParam
Expand All @@ -63,11 +62,6 @@ class AuthScreen : AniTrendScreen<AuthScreenBinding>() {
lifecycleScope.launch {
onUpdateUserInterface()
}
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
checkIntentData()
}
}
}

/**
Expand Down

0 comments on commit eaac814

Please sign in to comment.