Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Dec 23, 2023
1 parent 567e1cc commit a7ef7a5
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 35 deletions.
53 changes: 29 additions & 24 deletions androidApp/src/main/java/dev/xinto/argos/ui/component/AppAuth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ data class AppAuthServiceConfiguration(
sealed interface AuthResult {

@Immutable
data class Error(val error: String): AuthResult
data class Error(val error: String) : AuthResult

@Immutable
data class Success(
val idToken: String?,
val accessToken: String?,
val refreshToken: String?
): AuthResult
) : AuthResult
}


Expand All @@ -55,7 +55,11 @@ data class AppAuthRequestHandler(
) {

fun performRequest() {
activityResult.launch(authorizationService.getAuthorizationRequestIntent(authorizationRequest))
activityResult.launch(
authorizationService.getAuthorizationRequestIntent(
authorizationRequest
)
)
}
}

Expand Down Expand Up @@ -84,33 +88,34 @@ fun rememberAppAuthRequest(
Uri.parse(request.redirectUri)
).setScope(request.scope).build()
}
val loginResult = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.data == null) {
onResult(AuthResult.Error("No intent"))
return@rememberLauncherForActivityResult
}
val loginResult =
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.data == null) {
onResult(AuthResult.Error("No intent"))
return@rememberLauncherForActivityResult
}

val authResponse = AuthorizationResponse.fromIntent(it.data!!)
val authException = AuthorizationException.fromIntent(it.data!!)
val authResponse = AuthorizationResponse.fromIntent(it.data!!)
val authException = AuthorizationException.fromIntent(it.data!!)

if (authResponse != null) {
authorizationService.performTokenRequest(authResponse.createTokenExchangeRequest()) { response, e ->
if (response != null) {
onResult(
AuthResult.Success(
idToken = response.idToken,
accessToken = response.accessToken,
refreshToken = response.refreshToken
if (authResponse != null) {
authorizationService.performTokenRequest(authResponse.createTokenExchangeRequest()) { response, e ->
if (response != null) {
onResult(
AuthResult.Success(
idToken = response.idToken,
accessToken = response.accessToken,
refreshToken = response.refreshToken
)
)
)
} else {
onResult(e!!.toAuthResult())
} else {
onResult(e!!.toAuthResult())
}
}
} else {
onResult(authException!!.toAuthResult())
}
} else {
onResult(authException!!.toAuthResult())
}
}
return remember(authorizationService, authorizationRequest, loginResult) {
AppAuthRequestHandler(authorizationService, authorizationRequest, loginResult)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.xinto.argos.ui.component

import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
Expand All @@ -10,7 +9,6 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.CachePolicy
import coil.request.ImageRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -20,10 +19,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.xinto.argos.ui.theme.ArgosTheme
import dev.xinto.argos.ui.component.AppAuthRequest
import dev.xinto.argos.ui.component.AppAuthServiceConfiguration
import dev.xinto.argos.ui.component.rememberAppAuthRequest
import dev.xinto.argos.ui.theme.ArgosTheme
import org.koin.androidx.compose.getViewModel

@Composable
Expand Down Expand Up @@ -59,7 +58,9 @@ fun LoginScreen(
modifier: Modifier = Modifier,
) {
Scaffold(modifier = modifier) {
Column(modifier = Modifier.fillMaxSize().padding(it)) {
Column(modifier = Modifier
.fillMaxSize()
.padding(it)) {
Box(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -70,9 +71,11 @@ fun LoginScreen(
is LoginState.Loading -> {
CircularProgressIndicator()
}

is LoginState.Error -> {
Text("Error")
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.runtime.Immutable
sealed interface LoginState {

@Immutable
data object Stale: LoginState
data object Stale : LoginState

@Immutable
data object Loading : LoginState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.xinto.argos.R
import dev.xinto.argos.ui.component.VerticalSegmentedButton
import dev.xinto.argos.ui.component.HorizontalSegmentedButton
import dev.xinto.argos.ui.component.SegmentedButtonColumn
import dev.xinto.argos.ui.component.SegmentedButtonRow
import dev.xinto.argos.ui.component.UserImage
import dev.xinto.argos.ui.component.VerticalSegmentedButton
import dev.xinto.argos.ui.theme.ArgosTheme
import org.koin.androidx.compose.getViewModel

Expand Down Expand Up @@ -82,7 +82,7 @@ fun UserDialog(
contentDescription = null
)
}
when(state) {
when (state) {
is UserState.Loading -> {
Box(
modifier = Modifier.height(200.dp),
Expand All @@ -91,6 +91,7 @@ fun UserDialog(
CircularProgressIndicator()
}
}

is UserState.Success -> {
Column(
modifier = Modifier
Expand Down Expand Up @@ -158,6 +159,7 @@ fun UserDialog(
}
}
}

is UserState.Error -> {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.lifecycle.viewModelScope
import dev.xinto.argos.domain.DomainResponse
import dev.xinto.argos.domain.combine
import dev.xinto.argos.domain.user.UserRepository
import dev.xinto.argos.ui.screen.main.MainState
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
Expand All @@ -24,6 +23,7 @@ class UserViewModel(
userInfo = it.value.first,
userState = it.value.second
)

is DomainResponse.Error -> UserState.Error
}
}.stateIn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.stateIn
class MessageViewModel(
savedStateHandle: SavedStateHandle,
messagesRepository: MessagesRepository
): ViewModel() {
) : ViewModel() {

private val message = messagesRepository.getMessage(
id = savedStateHandle[KEY_MESSAGE_ID]!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun NotificationsScreen(
modifier = modifier,
notifications = notifications,
onNotificationClick = {

},
onBackClick = onBackClick
)
Expand Down Expand Up @@ -81,6 +81,7 @@ fun NotificationsScreen(
is LoadState.Loading -> {
CircularProgressIndicator()
}

is LoadState.NotLoading -> {
LazyColumn(
modifier = Modifier.fillMaxSize(),
Expand All @@ -107,14 +108,17 @@ fun NotificationsScreen(
is LoadState.Loading -> {
CircularProgressIndicator()
}

is LoadState.Error -> {
Text(appendState.error.stackTraceToString())
}

else -> {}
}
}
}
}

is LoadState.Error -> {
Text(refreshState.error.stackTraceToString())
}
Expand Down

0 comments on commit a7ef7a5

Please sign in to comment.