Skip to content

Commit

Permalink
Merge pull request #26 from TeamTripmate/feature/personalization
Browse files Browse the repository at this point in the history
[feat] 개인화 화면 구성 및 로직 구현
  • Loading branch information
easyhooon authored Aug 13, 2024
2 parents 8f09163 + 7f463f4 commit e86350e
Show file tree
Hide file tree
Showing 82 changed files with 2,498 additions and 82 deletions.
10 changes: 10 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Tripmate</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Tripmateandroid" parent="android:Theme.Material.Light.NoActionBar" />
</resources>
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.tripmate.android.core.common

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext

// https://www.youtube.com/watch?v=njchj9d_Lf8&t=1218s
@Composable
fun <T> ObserveAsEvents(flow: Flow<T>, onEvent: (T) -> Unit) {
val lifecycleOwner = LocalLifecycleOwner.current
LaunchedEffect(flow, lifecycleOwner.lifecycle) {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
withContext(Dispatchers.Main.immediate) {
flow.collect(onEvent)
}
}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.tripmate.android.core.common.extension

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.ViewModel
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavHostController

// https://youtu.be/h61Wqy3qcKg?si=OqctoATR5MGbypOW
@Composable
inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel(
navController: NavHostController,
): T {
val navGraphRoute = destination.parent?.route ?: return hiltViewModel()
val parentEntry = remember(this) {
navController.getBackStackEntry(navGraphRoute)
}
return hiltViewModel(parentEntry)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tripmate.android.core.data.di

import com.tripmate.android.core.data.repository.PersonalizationRepository
import com.tripmate.android.domain.repository.PersonalizationRepository
import com.tripmate.android.core.data.repository.PersonalizationRepositoryImpl
import dagger.Binds
import dagger.Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tripmate.android.core.data.repository

import com.tripmate.android.core.datastore.PersonalizationDataSource
import com.tripmate.android.domain.repository.PersonalizationRepository
import javax.inject.Inject

internal class PersonalizationRepositoryImpl @Inject constructor(
Expand Down
2 changes: 2 additions & 0 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ dependencies {
libs.coil.compose,
libs.timber,
libs.compose.keyboard.state,

libs.bundles.landscapist,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.tripmate.android.core.designsystem.component

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.tripmate.android.core.designsystem.ComponentPreview
import com.tripmate.android.core.designsystem.theme.Gray004
import com.tripmate.android.core.designsystem.theme.Gray009
import com.tripmate.android.core.designsystem.theme.Primary01
import com.tripmate.android.core.designsystem.theme.TripmateTheme

@Composable
fun TripmateButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
containerColor: Color = Primary01,
contentColor: Color = Color.White,
disabledContainerColor: Color = Gray009,
disabledContentColor: Color = Gray004,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
content: @Composable RowScope.() -> Unit,
) {
Button(
onClick = onClick,
modifier = modifier,
enabled = enabled,
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors(
containerColor = containerColor,
contentColor = contentColor,
disabledContainerColor = disabledContainerColor,
disabledContentColor = disabledContentColor,
),
contentPadding = contentPadding,
content = content,
)
}

@ComponentPreview
@Composable
fun TripmateButtonPreview() {
TripmateTheme {
TripmateButton(
onClick = {},
) {
Text("Button")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.tripmate.android.core.designsystem.component

import androidx.annotation.StringRes
import androidx.compose.foundation.background
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.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.BasicAlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import com.tripmate.android.core.designsystem.ComponentPreview
import com.tripmate.android.core.designsystem.R
import com.tripmate.android.core.designsystem.theme.Background02
import com.tripmate.android.core.designsystem.theme.Gray001
import com.tripmate.android.core.designsystem.theme.Gray004
import com.tripmate.android.core.designsystem.theme.Medium16_SemiBold
import com.tripmate.android.core.designsystem.theme.Primary01
import com.tripmate.android.core.designsystem.theme.Small14_Reg
import com.tripmate.android.core.designsystem.theme.TripmateTheme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TripMateDialog(
onDismissRequest: () -> Unit,
@StringRes titleResId: Int,
iconResId: Int?,
iconDescription: String?,
@StringRes descriptionResId: Int,
cancelTextResId: Int?,
confirmTextResId: Int,
onCancelClick: () -> Unit,
onConfirmClick: () -> Unit,
modifier: Modifier = Modifier,
properties: DialogProperties = DialogProperties(),
) {
BasicAlertDialog(
onDismissRequest = onDismissRequest,
modifier = modifier,
properties = properties,
) {
Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(16.dp))
.background(color = Background02),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(modifier = Modifier.height(60.dp))
if (iconResId != null && iconDescription != null) {
Icon(
imageVector = ImageVector.vectorResource(iconResId),
contentDescription = iconDescription,
tint = Color.Unspecified,
)
}
Text(
text = stringResource(id = titleResId),
style = Medium16_SemiBold,
color = Gray001,
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(id = descriptionResId),
color = Gray004,
style = Small14_Reg,
)
Spacer(modifier = Modifier.height(48.dp))
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp),
) {
TripmateButton(
onClick = onConfirmClick,
modifier = Modifier
.weight(1f)
.height(48.dp)
.then(
if (cancelTextResId != null) {
Modifier.padding(end = 4.dp)
} else {
Modifier
},
),
containerColor = Primary01,
contentColor = Color.White,
) {
Text(
text = stringResource(id = confirmTextResId),
color = Color.White,
style = Medium16_SemiBold,
)
}
if (cancelTextResId != null) {
TripmateButton(
onClick = onCancelClick,
modifier = Modifier
.weight(1f)
.height(48.dp)
.padding(start = 4.dp),
containerColor = Primary01,
) {
Text(
text = stringResource(id = cancelTextResId),
color = Color.White,
style = Medium16_SemiBold,
)
}
}
}
Spacer(modifier = Modifier.height(24.dp))
}
}
}

@ComponentPreview
@Composable
fun TripMateDialogPreview() {
TripmateTheme {
TripMateDialog(
onDismissRequest = {},
titleResId = R.string.under_age_title,
iconResId = null,
iconDescription = "",
descriptionResId = R.string.under_age_description,
cancelTextResId = null,
confirmTextResId = R.string.under_age_confirm,
onCancelClick = {},
onConfirmClick = {},
modifier = Modifier.padding(16.dp),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.tripmate.android.core.designsystem.component

import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalInspectionMode
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.coil.CoilImage
import com.skydoves.landscapist.components.rememberImageComponent
import com.skydoves.landscapist.placeholder.placeholder.PlaceholderPlugin
import com.tripmate.android.core.designsystem.ComponentPreview
import com.tripmate.android.core.designsystem.theme.TripmateTheme

@Composable
fun NetworkImage(
imgUrl: String?,
contentDescription: String?,
modifier: Modifier = Modifier,
placeholder: Painter? = null,
contentScale: ContentScale = ContentScale.Crop,
) {
if (LocalInspectionMode.current) {
// Image(
// painter = painterResource(id = R.drawable.item_placeholder),
// contentDescription = "Example Image Icon",
// modifier = modifier,
// )
} else {
CoilImage(
imageModel = { imgUrl },
modifier = modifier,
component = rememberImageComponent {
+PlaceholderPlugin.Loading(placeholder)
+PlaceholderPlugin.Failure(placeholder)
},
imageOptions = ImageOptions(
contentScale = contentScale,
alignment = Alignment.Center,
contentDescription = contentDescription,
),
)
}
}

@ComponentPreview
@Composable
fun NetworkImagePreview() {
TripmateTheme {
NetworkImage(
imgUrl = "",
contentDescription = "",
)
}
}
Loading

0 comments on commit e86350e

Please sign in to comment.