diff --git a/app/src/main/java/com/stslex/aproselection/ui/InitialApp.kt b/app/src/main/java/com/stslex/aproselection/ui/InitialApp.kt index 555c410..bbb3867 100644 --- a/app/src/main/java/com/stslex/aproselection/ui/InitialApp.kt +++ b/app/src/main/java/com/stslex/aproselection/ui/InitialApp.kt @@ -1,28 +1,14 @@ package com.stslex.aproselection.ui -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.compose.rememberNavController -import com.google.accompanist.systemuicontroller.rememberSystemUiController -import com.stslex.aproselection.navigation.NavigationHost import com.stslex.aproselection.core.ui.theme.AppTheme +import com.stslex.aproselection.navigation.NavigationHost @Composable fun InitialApp() { val navController = rememberNavController() - val systemUiController = rememberSystemUiController() - val isDarkTheme = isSystemInDarkTheme() - - DisposableEffect(systemUiController, isDarkTheme) { - systemUiController.setSystemBarsColor( - color = Color.Transparent, - darkIcons = isDarkTheme.not(), - ) - onDispose {} - } NavigationHost(navController = navController) } diff --git a/app/src/main/java/com/stslex/aproselection/ui/MainActivity.kt b/app/src/main/java/com/stslex/aproselection/ui/MainActivity.kt index 2d53911..6a44d46 100644 --- a/app/src/main/java/com/stslex/aproselection/ui/MainActivity.kt +++ b/app/src/main/java/com/stslex/aproselection/ui/MainActivity.kt @@ -3,16 +3,12 @@ package com.stslex.aproselection.ui import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.core.view.WindowCompat import com.stslex.aproselection.core.ui.theme.AppTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - - WindowCompat.setDecorFitsSystemWindows(window, false) - setContent { AppTheme { InitialApp() diff --git a/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClient.kt b/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClient.kt index 4d63e51..e133342 100644 --- a/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClient.kt +++ b/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClient.kt @@ -4,5 +4,5 @@ import com.stslex.aproselection.core.network.clients.auth.model.HelloRequestMode interface AuthNetworkClient { - suspend fun getHello(): HelloRequestModel + suspend fun getHello(username: String): HelloRequestModel } \ No newline at end of file diff --git a/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClientImpl.kt b/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClientImpl.kt index 5127a00..7148185 100644 --- a/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClientImpl.kt +++ b/core/network/src/main/java/com/stslex/aproselection/core/network/clients/auth/AuthNetworkClientImpl.kt @@ -5,15 +5,21 @@ import com.stslex.aproselection.core.network.clients.auth.model.HelloRequestMode import io.ktor.client.call.body import io.ktor.client.request.get import io.ktor.http.appendPathSegments +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext class AuthNetworkClientImpl( private val networkClient: NetworkClient ) : AuthNetworkClient { - override suspend fun getHello(): HelloRequestModel = networkClient - .apiClient - .get { - url.appendPathSegments("hello") - } - .body() + override suspend fun getHello( + username: String + ): HelloRequestModel = withContext(Dispatchers.IO) { + networkClient + .apiClient + .get { + url.appendPathSegments("hello", username) + } + .body() + } } \ No newline at end of file diff --git a/core/ui/src/main/java/com/stslex/aproselection/core/ui/theme/Theme.kt b/core/ui/src/main/java/com/stslex/aproselection/core/ui/theme/Theme.kt index b8e9bcd..de204ff 100644 --- a/core/ui/src/main/java/com/stslex/aproselection/core/ui/theme/Theme.kt +++ b/core/ui/src/main/java/com/stslex/aproselection/core/ui/theme/Theme.kt @@ -9,11 +9,12 @@ import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect -import androidx.compose.ui.graphics.toArgb +import androidx.compose.runtime.DisposableEffect +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat +import com.google.accompanist.systemuicontroller.rememberSystemUiController private val DarkColorScheme = darkColorScheme( primary = Purple80, @@ -55,10 +56,19 @@ fun AppTheme( } val view = LocalView.current if (!view.isInEditMode) { - SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = colorScheme.primary.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + val window = (view.context as Activity).window + val systemUiController = rememberSystemUiController() + val isDarkTheme = isSystemInDarkTheme() + + DisposableEffect(systemUiController, isDarkTheme) { + WindowCompat.setDecorFitsSystemWindows(window, false) + systemUiController.setSystemBarsColor( + color = Color.Transparent, + darkIcons = isDarkTheme.not(), + ) + onDispose { + WindowCompat.setDecorFitsSystemWindows(window, true) + } } } diff --git a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepository.kt b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepository.kt index 243c41e..5b77795 100644 --- a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepository.kt +++ b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepository.kt @@ -4,5 +4,5 @@ import kotlinx.coroutines.flow.Flow interface AuthRepository { - val hello: Flow + fun getHello(username: String): Flow } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepositoryImpl.kt b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepositoryImpl.kt index f773f3b..8760b92 100644 --- a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepositoryImpl.kt +++ b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepositoryImpl.kt @@ -8,8 +8,10 @@ class AuthRepositoryImpl( private val networkClient: AuthNetworkClient ) : AuthRepository { - override val hello: Flow = flow { - val helloResponse = networkClient.getHello().text + override fun getHello(username: String): Flow = flow { + val helloResponse = networkClient + .getHello(username = username) + .text emit(helloResponse) } } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractor.kt b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractor.kt index 99b27b2..0629d66 100644 --- a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractor.kt +++ b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractor.kt @@ -4,5 +4,5 @@ import kotlinx.coroutines.flow.Flow interface AuthInteractor { - val hello: Flow + fun getHello(username: String): Flow } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractorImpl.kt b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractorImpl.kt index dac5c4a..d696509 100644 --- a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractorImpl.kt +++ b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractorImpl.kt @@ -7,6 +7,9 @@ class AuthInteractorImpl( private val repository: AuthRepository ) : AuthInteractor { - override val hello: Flow - get() = repository.hello + override fun getHello( + username: String + ): Flow = repository.getHello( + username = username + ) } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthScreen.kt b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthScreen.kt index 3f4aba2..3c29bac 100644 --- a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthScreen.kt +++ b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthScreen.kt @@ -1,37 +1,84 @@ package com.stslex.aproselection.feature.auth.ui +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Divider +import androidx.compose.material3.ElevatedButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text +import androidx.compose.material3.TextField import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp import com.stslex.aproselection.core.ui.navigation.NavigationScreen @Composable fun AuthScreen( text: String, navigate: (NavigationScreen) -> Unit, + setUsername: (String) -> Unit, modifier: Modifier = Modifier, ) { + var inputUsername by remember { + mutableStateOf("") + } + Box( - modifier = modifier.fillMaxSize() + modifier = modifier + .fillMaxSize() + .background(MaterialTheme.colorScheme.background), + contentAlignment = Alignment.Center, ) { - Text( - modifier = Modifier.align(Alignment.Center), - text = text, - style = MaterialTheme.typography.headlineMedium - ) + + Column( + horizontalAlignment = Alignment.CenterHorizontally + ) { + TextField( + value = inputUsername, + onValueChange = { value -> + if (inputUsername != value) { + inputUsername = value + } + }, + maxLines = 1, + ) + Divider(Modifier.padding(16.dp)) + ElevatedButton( + onClick = { + setUsername(inputUsername) + inputUsername = "" + } + ) { + Text( + text = "submit", + style = MaterialTheme.typography.headlineMedium + ) + } + Divider(Modifier.padding(16.dp)) + Text( + text = text, + style = MaterialTheme.typography.headlineMedium, + color = MaterialTheme.colorScheme.onBackground + ) + } } } -@Preview +@Preview(device = "id:pixel_6", showSystemUi = true, showBackground = true) @Composable fun AuthScreenPreview() { AuthScreen( text = "text", - navigate = {} + navigate = {}, + setUsername = {} ) } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthViewModel.kt b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthViewModel.kt index 0cd1f8c..4fc3873 100644 --- a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthViewModel.kt +++ b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/AuthViewModel.kt @@ -1,19 +1,33 @@ package com.stslex.aproselection.feature.auth.ui +import androidx.lifecycle.viewModelScope import com.stslex.aproselection.core.ui.base.BaseViewModel import com.stslex.aproselection.feature.auth.domain.interactor.AuthInteractor +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach class AuthViewModel( private val interactor: AuthInteractor ) : BaseViewModel() { + private val _text: MutableStateFlow = MutableStateFlow("...") + val text: StateFlow - get() = interactor - .hello + get() = _text.asStateFlow() + + fun setUsername(username: String) { + _text.value = "..." + interactor.getHello(username) .catch { throwable -> handleError(throwable) } - .stateIn("") + .onEach { receivedText -> + _text.emit(receivedText) + } + .launchIn(viewModelScope) + } } diff --git a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/navigation/AuthRouter.kt b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/navigation/AuthRouter.kt index e11ebeb..557bbd3 100644 --- a/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/navigation/AuthRouter.kt +++ b/feature/auth/src/main/java/com/stslex/aproselection/feature/auth/ui/navigation/AuthRouter.kt @@ -28,6 +28,7 @@ fun NavGraphBuilder.authRouter( AuthScreen( text = text, navigate = navigate, + setUsername = viewModel::setUsername, modifier = modifier ) }