Skip to content

Commit

Permalink
refactor: (#34) snackbar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkoro committed Apr 21, 2024
1 parent c6b51f1 commit 5a800ad
Show file tree
Hide file tree
Showing 20 changed files with 382 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ data class ContentHeight(
val small: Dp = 5.dp,
val medium: Dp = 10.dp,
val large: Dp = 15.dp,
val orderItemExpanded: Dp = 320.dp,
val orderItemNotExpanded: Dp = 90.dp,
)

val LocalContentHeight = compositionLocalOf { ContentHeight() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kenkoro.taurus.client.core.local

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

data class Padding(val snackbar: Dp = 18.dp)

val LocalPadding = compositionLocalOf { Padding() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kenkoro.taurus.client.core.local

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

data class StrokeWidth(val standard: Dp = 4.dp)

val LocalStrokeWidth = compositionLocalOf { StrokeWidth() }
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,4 @@ interface OrderDao {

@Query("select * from orderentity")
fun pagingSource(): PagingSource<Int, OrderEntity>

@Query("select count(*) from orderentity")
suspend fun count(): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OrderKtorApi(
override suspend fun newOrder(request: OrderRequestDto): HttpResponse =
client.post {
url {
protocol = URLProtocol.HTTPS
protocol = URLProtocol.HTTP
host = Urls.HOST
port = Urls.PORT
path(Urls.Order.NEW_ORDER)
Expand All @@ -41,7 +41,7 @@ class OrderKtorApi(
override suspend fun getOrder(orderId: Int): HttpResponse =
client.get {
url {
protocol = URLProtocol.HTTPS
protocol = URLProtocol.HTTP
host = Urls.HOST
port = Urls.PORT
path(Urls.Order.GET_ORDER)
Expand All @@ -63,7 +63,7 @@ class OrderKtorApi(
): HttpResponse =
client.get {
url {
protocol = URLProtocol.HTTPS
protocol = URLProtocol.HTTP
host = Urls.HOST
port = Urls.PORT
path(Urls.Order.GET_ORDERS)
Expand All @@ -87,7 +87,7 @@ class OrderKtorApi(
): HttpResponse =
client.put {
url {
protocol = URLProtocol.HTTPS
protocol = URLProtocol.HTTP
host = Urls.HOST
port = Urls.PORT
path("${Urls.Order.GET_ORDER}/$orderId/edit/${data.toUrl}")
Expand All @@ -105,7 +105,7 @@ class OrderKtorApi(
): HttpResponse =
client.delete {
url {
protocol = URLProtocol.HTTPS
protocol = URLProtocol.HTTP
host = Urls.HOST
port = Urls.PORT
path(Urls.Order.DELETE_ORDER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UserKtorApi(
override suspend fun login(request: LoginRequestDto): HttpResponse =
client.post {
url {
protocol = URLProtocol.HTTPS
protocol = URLProtocol.HTTP
host = Urls.HOST
port = Urls.PORT
path(Urls.User.LOGIN)
Expand All @@ -32,7 +32,7 @@ class UserKtorApi(
override suspend fun getUser(user: String): HttpResponse =
client.get {
url {
protocol = URLProtocol.HTTPS
protocol = URLProtocol.HTTP
host = Urls.HOST
port = Urls.PORT
path("${Urls.User.GET_USER}/$user")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.kenkoro.taurus.client.feature.sewing.data.util

enum class OrderStatus {
NotStarted,
Cutted,
Cut,
Checked,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.kenkoro.taurus.client.feature.sewing.data.util

object Urls {
private const val KTOR_LOCALHOST = "ktor-backend.loca.lt"
private const val LOCALHOST = "10.10.106.97"
private const val LOCALHOST = "10.10.65.179"
private const val LOCALHOST_PHONE = "192.168.224.149"
const val HOST = LOCALHOST
const val HOST = LOCALHOST_PHONE
const val PORT = 8080

object User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ data class Order(
val color: String = "Цвет",
val category: String = "Категория",
val quantity: Int = 0,
val status: OrderStatus = OrderStatus.Cutted,
val status: OrderStatus = OrderStatus.Cut,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand Down Expand Up @@ -44,7 +43,7 @@ fun AppNavHost(
val networkConnectivityObserver: ConnectivityObserver = NetworkConnectivityObserver(context)
val networkStatus by networkConnectivityObserver
.observer()
.collectAsState(initial = NetworkStatus.Unavailable)
.collectAsState(initial = NetworkStatus.Available)

val userViewModel: UserViewModel = hiltViewModel()
val orderViewModel: OrderViewModel = hiltViewModel()
Expand All @@ -55,7 +54,6 @@ fun AppNavHost(
composable(route = Screen.LoginScreen.route) {
LoginScreen(
networkStatus = networkStatus,
scope = userViewModel.viewModelScope,
onLoginNavigate = {
navController.navigate(Screen.OrderScreen.route)
},
Expand All @@ -75,12 +73,11 @@ fun AppNavHost(
}
composable(route = Screen.OrderScreen.route) {
OrderScreen(
networkStatus = networkStatus,
orders = orderViewModel.orderPagingFlow.collectAsLazyPagingItems(),
user = userViewModel.user,
networkStatus = networkStatus,
loginResponse = userViewModel.loginResponse,
isLoginFailed = userViewModel.isLoginFailed,
scope = orderViewModel.viewModelScope,
onLogin = { loginRequestDto, context, encryptSubjectAndPassword ->
userViewModel.login(
loginRequestDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
package com.kenkoro.taurus.client.feature.sewing.presentation.screen.login

import android.content.Context
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.tooling.preview.Preview
import com.kenkoro.taurus.client.core.connectivity.NetworkStatus
import com.kenkoro.taurus.client.core.local.LocalContentHeight
import com.kenkoro.taurus.client.core.local.LocalContentWidth
import com.kenkoro.taurus.client.feature.sewing.data.source.remote.dto.request.LoginRequestDto
import com.kenkoro.taurus.client.feature.sewing.presentation.screen.login.components.LoginFieldsContent
import com.kenkoro.taurus.client.feature.sewing.presentation.screen.login.components.LoginHelpContent
import com.kenkoro.taurus.client.feature.sewing.presentation.shared.components.ErrorSnackbar
import com.kenkoro.taurus.client.feature.sewing.presentation.shared.components.TaurusSnackbar
import com.kenkoro.taurus.client.feature.sewing.presentation.util.LoginResponse
import com.kenkoro.taurus.client.ui.theme.AppTheme
import kotlinx.coroutines.CoroutineScope

@Composable
fun LoginScreen(
subject: String,
password: String,
networkStatus: NetworkStatus,
scope: CoroutineScope,
onLoginNavigate: () -> Unit,
onSubjectChange: (String) -> Unit,
onPasswordChange: (String) -> Unit,
Expand All @@ -41,52 +40,79 @@ fun LoginScreen(
) {
val contentWidth = LocalContentWidth.current
val contentHeight = LocalContentHeight.current

val snackbarHostState = remember { SnackbarHostState() }
val errorSnackbarHostState = remember { SnackbarHostState() }

AppTheme {
Scaffold(
snackbarHost = {
SnackbarHost(hostState = snackbarHostState) {
ErrorSnackbar(
modifier = Modifier.padding(bottom = 80.dp),
snackbarData = it,
)
}
TaurusSnackbar(
snackbarHostState = snackbarHostState,
onDismiss = { snackbarHostState.currentSnackbarData?.dismiss() },
)

TaurusSnackbar(
snackbarHostState = errorSnackbarHostState,
onDismiss = { errorSnackbarHostState.currentSnackbarData?.dismiss() },
containerColor = MaterialTheme.colorScheme.errorContainer,
contentColor = MaterialTheme.colorScheme.onErrorContainer,
)
},
) {
Surface(
modifier =
Modifier
.fillMaxSize()
.padding(it),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
LoginFieldsContent(
modifier =
Modifier
.width(contentWidth.standard)
.weight(9F),
onLoginNavigate = onLoginNavigate,
snackbarHostState = snackbarHostState,
subject = subject,
onSubjectChange = onSubjectChange,
password = password,
onPasswordChange = onPasswordChange,
onLogin = onLogin,
onLoginResponseChange = onLoginResponseChange,
networkStatus = networkStatus,
scope = scope,
)
LoginHelpContent(
modifier = Modifier.weight(1F),
snackbarHostState = snackbarHostState,
)
Spacer(modifier = Modifier.height(contentHeight.medium))
}
}
content = {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceAround,
) {
LoginFieldsContent(
modifier =
Modifier
.width(contentWidth.standard)
.weight(9F),
onLoginNavigate = onLoginNavigate,
subject = subject,
onSubjectChange = onSubjectChange,
password = password,
onPasswordChange = onPasswordChange,
onLogin = onLogin,
onLoginResponseChange = onLoginResponseChange,
networkStatus = networkStatus,
errorSnackbarHostState = errorSnackbarHostState,
)
LoginHelpContent(
modifier =
Modifier
.weight(1F)
.height(contentHeight.standard),
snackbarHostState = snackbarHostState,
)
Spacer(modifier = Modifier.height(contentHeight.medium))
}
},
)
}
}
}

@Preview
@Composable
private fun LoginScreenPrev() {
AppTheme {
LoginScreen(
subject = "",
password = "",
networkStatus = NetworkStatus.Available,
onLoginNavigate = { /*TODO*/ },
onSubjectChange = { _ -> },
onPasswordChange = { _ -> },
onLogin = { _, _, _ -> LoginResponse.Success },
onLoginResponseChange = { _ -> },
)
}
}
Loading

0 comments on commit 5a800ad

Please sign in to comment.