Skip to content

Commit

Permalink
Merge pull request #19 from im-o/develop-material3-bug-fix
Browse files Browse the repository at this point in the history
Develop material3 bug fix
  • Loading branch information
im-o authored Aug 29, 2024
2 parents c2f1efd + 32e8f0f commit f44c62e
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
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.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import dagger.hilt.android.AndroidEntryPoint
import id.barakkastudio.core.ui.theme.JetShopeeTheme
import id.barakkastudio.sample.ui.splash.SplashScreen

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
Expand All @@ -20,7 +25,12 @@ class MainActivity : ComponentActivity() {
JetShopeeTheme {
Surface {
val windowSize = calculateWindowSizeClass(this)
JetMainApp(windowSize = windowSize.widthSizeClass)
var showSplashScreen by remember { mutableStateOf(true) }
if (showSplashScreen) {
SplashScreen(onTimeout = { showSplashScreen = false })
} else {
JetMainApp(windowSize = windowSize.widthSizeClass)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/kotlin/id/barakkastudio/core/util/Dimens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object Dimens {
val dp42: Dp = 42.dp
val dp48: Dp = 48.dp
val dp60: Dp = 60.dp
val dp120: Dp = 120.dp

val sp14: TextUnit = 14.sp
val sp18: TextUnit = 18.sp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package id.barakkastudio.sample.ui.component


import android.graphics.Bitmap
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
Expand Down Expand Up @@ -48,12 +50,20 @@ fun ProductCartItem(
modifier = modifier
.padding(8.dp)
.fillMaxWidth()
.wrapContentHeight()
) {
Row {
Row(
modifier = modifier
.fillMaxWidth()
.wrapContentHeight()
) {
SubcomposeAsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(product.thumbnail)
.placeholder(R.drawable.logo_nebenginaja)
.crossfade(true)
.size(150, 150)
.bitmapConfig(Bitmap.Config.RGB_565)
.build(),
loading = {
CircularProgressIndicator(
Expand All @@ -70,9 +80,9 @@ fun ProductCartItem(
)
Column(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.weight(1.0f)
.align(Alignment.CenterVertically)
) {
Text(
text = product.title ?: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package id.barakkastudio.sample.ui.component


import android.graphics.Bitmap
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.height
Expand Down Expand Up @@ -49,7 +50,10 @@ fun ProductItem(
SubcomposeAsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(product.thumbnail)
.placeholder(R.drawable.logo_nebenginaja)
.crossfade(true)
.size(150, 150)
.bitmapConfig(Bitmap.Config.RGB_565)
.build(),
loading = {
CircularProgressIndicator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fun ImageProductPager(product: Product) {
SubcomposeAsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(items?.get(page))
.placeholder(R.drawable.logo_nebenginaja)
.crossfade(true)
.build(),
loading = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package id.barakkastudio.sample.ui.splash

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import id.barakkastudio.core.R
import id.barakkastudio.core.ui.theme.JetShopeeTheme
import id.barakkastudio.core.util.Dimens
import kotlinx.coroutines.delay

/** Created by github.com/im-o on 8/29/2024. */

@Composable
fun SplashScreen(
onTimeout: () -> Unit, modifier: Modifier = Modifier
) {
LaunchedEffect(Unit) {
delay(2500)
onTimeout()
}
Box(
modifier = modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.primary), contentAlignment = Alignment.Center
) {
Column(
modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
modifier = modifier
.size(Dimens.dp120)
.shadow(elevation = Dimens.dp1, shape = RoundedCornerShape(Dimens.dp12))
.clip(shape = RoundedCornerShape(Dimens.dp12)),
painter = painterResource(id = R.drawable.logo_nebenginaja),
contentDescription = stringResource(id = R.string.app_name),
contentScale = ContentScale.Crop,
)
Spacer(modifier = modifier.height(Dimens.dp16))
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.onPrimary
)
}
}
}

@Preview
@Composable
fun SplashScreenPreview() {
JetShopeeTheme {
SplashScreen(onTimeout = {})
}
}

0 comments on commit f44c62e

Please sign in to comment.