Skip to content

Commit

Permalink
[chore] : ktForamt
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Feb 18, 2024
1 parent 1b422fa commit 2f5dc4d
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun MatchingResponse.toDomain(): Matching {
profile = profile.toDomain(subways),
similarity = similarity,
chemistrys = chemistryInfos.map { it.toDomain() },
recommends = recommends.map { it.toDomain() },
recommends = recommends.map { it.toDomain() }
)
}

Expand All @@ -39,7 +39,8 @@ private fun ProfileResponse.toDomain(subways: List<SubwayStation>): Profile {

private fun ChemistryResponse.toDomain(): Chemistry {
return Chemistry(
title = title, description = description
title = title,
description = description
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ data class Matching(
val profile: Profile = Profile(),
val similarity: Int = 0,
val chemistrys: List<Chemistry> = emptyList(),
val recommends: List<Recommend> = emptyList(),
val recommends: List<Recommend> = emptyList()
) {
init {
require(similarity in 0..100) {
"similarity must be in 0..100"
}
}


fun matches(job: Job, recommends: List<Recommend>): Boolean {
return recommends.any { recommend ->
(job.name == recommend.title) || (job.krName == recommend.title)
Expand Down Expand Up @@ -49,5 +48,4 @@ data class Matching(
subway.name == recommend.title
}
}

}
6 changes: 1 addition & 5 deletions feature/home/src/main/java/com/moya/funch/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,7 @@ private fun CodeCard(modifier: Modifier = Modifier, myCode: String) {
}

@Composable
private fun MyProfileCard(
job: Job,
modifier: Modifier = Modifier,
onMyProfileClick: () -> Unit
) {
private fun MyProfileCard(job: Job, modifier: Modifier = Modifier, onMyProfileClick: () -> Unit) {
Column(
modifier = modifier
.background(
Expand Down
2 changes: 1 addition & 1 deletion feature/home/src/main/java/com/moya/funch/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import com.moya.funch.usecase.CanMatchProfileUseCase
import com.moya.funch.usecase.LoadUserProfileUseCase
import com.moya.funch.usecase.LoadViewCountUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

data class HomeModel(
val myCode: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ import com.moya.funch.entity.profile.Profile
import com.moya.funch.match.model.MatchProfileUiModel
import com.moya.funch.usecase.MatchProfileUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.plus
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
internal class MatchViewModel @Inject constructor(
Expand All @@ -35,8 +34,6 @@ internal class MatchViewModel @Inject constructor(

private val matchCode: StateFlow<String> = savedStateHandle.getStateFlow(MATCH_CODE, "")

private var matchJob: kotlinx.coroutines.Job? = null

@OptIn(ExperimentalCoroutinesApi::class)
val uiState: StateFlow<MatchUiState> = matchCode.mapLatest { code ->
delay(2400)
Expand All @@ -56,9 +53,10 @@ internal class MatchViewModel @Inject constructor(
Timber.e("it")
emit(MatchUiState.Error)
}.stateIn(
matchJob?.let { viewModelScope.plus(it) } ?: viewModelScope,
viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = MatchUiState.Loading)
initialValue = MatchUiState.Loading
)

fun saveMatchCode(code: String) {
savedStateHandle[MATCH_CODE] = code
Expand Down Expand Up @@ -98,7 +96,7 @@ internal class MatchViewModel @Inject constructor(
Recommend("SOPT"),
Recommend("ENFJ"),
Recommend("A형"),
Recommend("목동역"),
Recommend("목동역")
)
)
}
Expand All @@ -110,6 +108,6 @@ internal sealed class MatchUiState {
data class Success(
val profile: MatchProfileUiModel,
val similarity: Int = 0,
val chemistrys: List<Chemistry> = emptyList(),
val chemistrys: List<Chemistry> = emptyList()
) : MatchUiState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.moya.funch.theme.FunchTheme
@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun MatchHorizontalPager(profile: MatchProfileUiModel, similarity: Int, chemistrys: List<Chemistry>) {

val pageCount = 3
val pagerState = rememberPagerState(pageCount = { pageCount })
HorizontalPager(
Expand Down Expand Up @@ -77,7 +76,7 @@ private fun Preview() {
Recommend("SOPT"),
Recommend("ENFJ"),
Recommend("A형"),
Recommend("목동역"),
Recommend("목동역")
)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ private fun MatchProfileCardContent(profile: MatchProfileUiModel) {
Column {
Spacer(modifier = Modifier.height(8.dp))
Text(
text = profile.name, style = FunchTheme.typography.t2, color = Color.White
text = profile.name,
style = FunchTheme.typography.t2,
color = Color.White
)
Spacer(modifier = Modifier.height(20.dp))

ProfileInfo(
profile.job, profile.clubs, profile.mbti, profile.blood, profile.subways
profile.job,
profile.clubs,
profile.mbti,
profile.blood,
profile.subways
)
}
}
Expand All @@ -84,15 +90,17 @@ private fun ProfileInfo(
subways: List<MatchingWrapper<SubwayStation>>
) {
Column(
modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(16.dp)
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
// job
Row(
modifier = Modifier.fillMaxWidth()
) {
ProfileItemTitle(title = job.profileItem.title)
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
MatchChip(
label = job.data.krName,
Expand All @@ -108,7 +116,8 @@ private fun ProfileInfo(
val title = clubs.firstOrNull()?.profileItem?.title.orEmpty()
ProfileItemTitle(title = title)
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
clubs.forEach { club ->
MatchChip(
Expand All @@ -125,7 +134,8 @@ private fun ProfileInfo(
) {
ProfileItemTitle(title = mbti.profileItem.title)
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
MatchChip(
label = mbti.data.name,
Expand All @@ -140,11 +150,12 @@ private fun ProfileInfo(
) {
ProfileItemTitle(title = blood.profileItem.title)
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
MatchChip(
label = blood.data.type,
mached = blood.matched,
mached = blood.matched
)
}
}
Expand All @@ -155,7 +166,8 @@ private fun ProfileInfo(
val title = subways.firstOrNull()?.profileItem?.title.orEmpty()
ProfileItemTitle(title = title)
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
subways.forEach { subway ->
MatchChip(
Expand All @@ -182,7 +194,6 @@ private fun <T> ProfileItem(item: MatchingWrapper<T>) {
// 아이템 타입에 따른 특수 처리 로직
when (item.profileItem) {
is ProfileItems.NonIcon -> {

}

is ProfileItems.LeadingIcon -> {
Expand All @@ -194,23 +205,26 @@ private fun <T> ProfileItem(item: MatchingWrapper<T>) {
}
// 공통 UI 컴포넌트 렌더링
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
// 아이템 데이터를 기반으로 MatchChip 렌더링
}
}
}


@Composable
private fun ProfileItemTitle(title: String) {
Box(
modifier = Modifier
.width(52.dp)
.height(48.dp), contentAlignment = Alignment.CenterStart
.height(48.dp),
contentAlignment = Alignment.CenterStart
) {
Text(
text = title, color = Gray400, style = FunchTheme.typography.b
text = title,
color = Gray400,
style = FunchTheme.typography.b
)
}
}
Expand All @@ -228,13 +242,16 @@ private fun MatchChip(
enabled = false,
leadingIcon = { LeadingIcon(painter = leadingPainter) },
label = { ChipLabel(label = label) },
trailingIcon = { TrailingIcon(painters = trailingPainter) })
trailingIcon = { TrailingIcon(painters = trailingPainter) }
)
}

@Composable
private fun ChipLabel(label: String) {
Text(
text = label, style = FunchTheme.typography.b, color = White
text = label,
style = FunchTheme.typography.b,
color = White
)
}

Expand All @@ -245,16 +262,17 @@ private fun LeadingIcon(painter: Painter? = null) {
modifier = Modifier
.size(32.dp)
.background(
color = Gray900, shape = FunchTheme.shapes.extraSmall
color = Gray900,
shape = FunchTheme.shapes.extraSmall
)
.clip(FunchTheme.shapes.extraSmall),
contentAlignment = Alignment.Center
) {

Image(
modifier = Modifier.size(18.dp), painter = it, contentDescription = ""
modifier = Modifier.size(18.dp),
painter = it,
contentDescription = ""
)

}
}
}
Expand All @@ -275,7 +293,9 @@ private fun TrailingIcon(painters: List<Painter>? = null) {
private fun Preview() {
FunchTheme {
MatchProfileCard(
MatchProfileUiModel.from(MatchViewModel.MOCK_MATCHING), 2, 3
MatchProfileUiModel.from(MatchViewModel.MOCK_MATCHING),
2,
3
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ private fun RecommendItem(recommend: String) {
}
}


@Preview(showBackground = true)
@Composable
private fun Preview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ internal fun SimilarityCard(similarity: Int, chemistrys: List<Chemistry>, curren
.fillMaxSize()
.background(Gray800, shape = FunchTheme.shapes.large)
.padding(top = 20.dp)
.padding(horizontal = 28.dp), horizontalAlignment = Alignment.CenterHorizontally
.padding(horizontal = 28.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
MatchPageIndicator(current = current, pageCount = pageCount)
Spacer(modifier = Modifier.height(8.dp))
SimilarityCardContent(similarity = similarity, chemistrys = chemistrys)
}
}


@Composable
private fun SimilarityCardContent(similarity: Int, chemistrys: List<Chemistry>) {
SimilarityText(similarity = similarity)
Expand All @@ -110,12 +110,16 @@ private fun SimilarityText(similarity: Int) {
append(text)
val start = text.indexOf("$similarity")
addStyle(
style = SpanStyle(brush = Brush.horizontalGradient(Gradient_Lemon500)), start = start, end = start + 3
style = SpanStyle(brush = Brush.horizontalGradient(Gradient_Lemon500)),
start = start,
end = start + 3
)
}

Text(
text = annotatedString, style = FunchTheme.typography.t2, color = White
text = annotatedString,
style = FunchTheme.typography.t2,
color = White
)
}

Expand All @@ -133,7 +137,8 @@ private fun ChemistryList(chemistrys: List<Chemistry>) {
private fun ChemistryItem(chemistry: Chemistry) {
val (title, description) = chemistry
Row(
Modifier.fillMaxWidth(), verticalAlignment = Alignment.Top
Modifier.fillMaxWidth(),
verticalAlignment = Alignment.Top
) {
Image(modifier = Modifier.size(24.dp), painter = title.toPainter(), contentDescription = "Chemistry Icon")
Spacer(modifier = Modifier.width(12.dp))
Expand Down Expand Up @@ -198,7 +203,9 @@ private fun String.toPainter(): Painter {
showSystemUi = true
)
@Preview(
name = "Phone - 891dpi", device = "spec:width = 411dp, height = 891dp, dpi = 420", showSystemUi = true
name = "Phone - 891dpi",
device = "spec:width = 411dp, height = 891dp, dpi = 420",
showSystemUi = true
)
private fun Preview() {
FunchTheme {
Expand Down
Loading

0 comments on commit 2f5dc4d

Please sign in to comment.