Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/designsystem/src/main/res/drawable/icon_plus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="14dp"
android:height="14dp"
android:viewportWidth="14"
android:viewportHeight="14">
<path
android:pathData="M7,2C7.69,2 8.25,2.56 8.25,3.25V5.75H10.75C11.44,5.75 12,6.31 12,7C12,7.69 11.44,8.25 10.75,8.25H8.25V10.75C8.25,11.44 7.69,12 7,12C6.31,12 5.75,11.44 5.75,10.75V8.25H3.25C2.56,8.25 2,7.69 2,7C2,6.31 2.56,5.75 3.25,5.75H5.75V3.25C5.75,2.56 6.31,2 7,2Z"
android:fillColor="#4A5256"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="14dp"
android:height="14dp"
android:viewportWidth="14"
android:viewportHeight="14">
<path
android:pathData="M7,2C7.69,2 8.25,2.56 8.25,3.25V10.75C8.25,11.44 7.69,12 7,12C6.31,12 5.75,11.44 5.75,10.75V3.25C5.75,2.56 6.31,2 7,2Z"
android:fillColor="#E7EDF0"/>
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hanbang.navigation.feature.lottoresult

import com.hanbang.navigation.model.Route
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

@Serializable
data class RouteLottoResultAd(val round: Int): Route

@Serializable
data class RouteLottoResult(val lottoResultJson: String) : Route

@Serializable
data class RouteLottoResultModel(
val round: Int = 0,
val recommendedNumbers: Map<Int, Boolean>,
val resultNumbers: List<Int>,
val bonusNumber: Int,
val rank: Int,
val prizeAmount: Long
)

fun RouteLottoResultModel.toJson(): String {
val json = Json { isLenient = true }
return try {
json.encodeToString(this)
} catch (e: Exception) {
"{}"
}
}

fun String.toRouteLottoResultModel(): RouteLottoResultModel {
val json = Json { isLenient = true }
return try {
json.decodeFromString(RouteLottoResultModel.serializer(), this)
} catch (e: Exception) {
RouteLottoResultModel(0, mapOf(), listOf(), 0, 0, 0)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hanbang.data.datasource

import com.hanbang.data.model.CheckLottoResultDto
import com.hanbang.data.model.DailyFortuneDetailDto
import com.hanbang.data.model.DailyFortuneDto
import com.hanbang.data.model.FourPillarDto
Expand Down Expand Up @@ -52,4 +53,9 @@ interface UserRemoteDataSource {
userId: String,
fortuneDate: String
): DailyFortuneDetailDto

suspend fun checkLottoResult(
userId: String,
round: Int
): CheckLottoResultDto
}
29 changes: 29 additions & 0 deletions data/src/main/java/com/hanbang/data/model/CheckLottoResultDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.hanbang.data.model

import com.hanbang.domain.model.CheckLottoResult

data class CheckLottoResultDto(
val userId: String,
val round: Int,
val drawNumbers: List<Int>,
val bonusNumber: Int,
val recommendedNumbers: List<Int>,
val matchedCount: Int,
val matchedNumbers: List<Int>,
val hasBonus: Boolean,
val rank: Int,
val prizeAmount: Long
)

internal fun CheckLottoResultDto.toDomain() = CheckLottoResult(
userId = userId,
round = round,
drawNumbers = drawNumbers,
bonusNumber = bonusNumber,
recommendedNumbers = recommendedNumbers,
matchedCount = matchedCount,
matchedNumbers = matchedNumbers,
hasBonus = hasBonus,
rank = rank,
prizeAmount = prizeAmount
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ data class LottoRecommendationDto(
val userId: String,
val round: Int,
val content: LottoRecommendationContentDto?,
val isFinished: Boolean
)

internal fun LottoRecommendationDto.toDomain(): LottoRecommendation {
return LottoRecommendation(
userId = userId,
round = round,
content = content?.toDomain(),
isFinished = isFinished
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.hanbang.data.datasource.DeviceLocalDataSource
import com.hanbang.data.datasource.UserLocalDataSource
import com.hanbang.data.datasource.UserRemoteDataSource
import com.hanbang.data.model.toDomain
import com.hanbang.domain.model.CheckLottoResult
import com.hanbang.domain.model.DailyFortuneDetail
import com.hanbang.domain.model.FourPillar
import com.hanbang.domain.model.DailyFortune
Expand Down Expand Up @@ -119,4 +120,10 @@ class DefaultSattoRepository @Inject constructor(
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
return dateTime.format(formatter)
}

override fun checkLottoResult(round: Int): Flow<CheckLottoResult> = flow {
val userId = userLocalDataSource.getUserId()
val checkLottoResultDto = userRemoteDataSource.checkLottoResult(userId, round)
emit(checkLottoResultDto.toDomain())
}.flowOn(Dispatchers.IO)
}
14 changes: 14 additions & 0 deletions domain/src/main/java/com/hanbang/domain/model/CheckLottoResult.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hanbang.domain.model

data class CheckLottoResult(
val userId: String,
val round: Int,
val drawNumbers: List<Int>,
val bonusNumber: Int,
val recommendedNumbers: List<Int>,
val matchedCount: Int,
val matchedNumbers: List<Int>,
val hasBonus: Boolean,
val rank: Int,
val prizeAmount: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ data class LottoRecommendation(
val userId: String,
val round: Int,
val content: LottoRecommendationContent?,
val isFinished: Boolean
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hanbang.domain.repository

import com.hanbang.domain.model.CheckLottoResult
import com.hanbang.domain.model.DailyFortuneDetail
import com.hanbang.domain.model.FourPillar
import com.hanbang.domain.model.DailyFortune
Expand Down Expand Up @@ -46,4 +47,6 @@ interface SattoRepository {
fun getLottoRecommendation(): Flow<LottoRecommendation>

fun createLottoRecommendation(): Flow<LottoRecommendation>

fun checkLottoResult(round: Int): Flow<CheckLottoResult>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hanbang.domain.usecase

import com.hanbang.domain.model.CheckLottoResult
import com.hanbang.domain.repository.SattoRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class CheckLottoResultUseCase @Inject constructor(
private val sattoRepository: SattoRepository
) {
operator fun invoke(round: Int): Flow<CheckLottoResult> = sattoRepository.checkLottoResult(round)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import org.orbitmvi.orbit.compose.collectSideEffect
@Composable
internal fun LottoAdScreen(
viewModel: LottoAdViewModel = hiltViewModel(),
navigateToLottoRecommend: () -> Unit
navigateToLottoRecommend: () -> Unit,
navigateToBack: () -> Unit
) {
viewModel.collectSideEffect {
when (it) {
Expand All @@ -54,12 +55,16 @@ internal fun LottoAdScreen(
}

val state = viewModel.collectAsState().value
LottoAdContent(state = state)
LottoAdContent(
state = state,
navigateToBack = navigateToBack
)
}

@Composable
private fun LottoAdContent(
state: LottoAdUiState
state: LottoAdUiState,
navigateToBack: () -> Unit = {}
) {
val alphaAnim = remember { Animatable(0f) }
LaunchedEffect(Unit) {
Expand Down Expand Up @@ -91,6 +96,7 @@ private fun LottoAdContent(
TopAppBar(
containerColor = Color.Transparent,
contentColor = Color.White,
onNavigationClick = navigateToBack
)
Text(
text = "${state.userName}의 사주 분석 완료",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
import com.hanbang.domain.usecase.CreateLottoRecommendationUseCase
import com.hanbang.domain.usecase.GetUserUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
Expand All @@ -30,6 +31,8 @@ class LottoAdViewModel @Inject constructor(
}
)

private val coroutineExceptionHandler = CoroutineExceptionHandler { _, _ -> }

private var animationJob: Job? = null
private var currentMillis: Long = 0

Expand All @@ -46,7 +49,7 @@ class LottoAdViewModel @Inject constructor(
if (animationJob?.isActive == true) return@intent

animationJob?.cancel()
animationJob = viewModelScope.launch {
animationJob = viewModelScope.launch(coroutineExceptionHandler) {
val lottoDeferred = async { createLottoRecommendationUseCase().first() }
currentMillis = System.currentTimeMillis()
reduce { state.copy(isPlaying = true) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ fun NavController.navigateToLottoAd() {
}

fun NavGraphBuilder.lottoAdNavGraph(
navigateToLottoRecommend: () -> Unit
navigateToLottoRecommend: () -> Unit,
navigateToBack: () -> Unit
) {
composable<RouteLottoRecommendAd> {
LottoAdScreen(
navigateToLottoRecommend = navigateToLottoRecommend
navigateToLottoRecommend = navigateToLottoRecommend,
navigateToBack = navigateToBack
)
}
}
12 changes: 7 additions & 5 deletions feature/home/src/main/java/com/hanbang/home/main/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal fun HomeRoute(
onShowErrorSnackBar: (HbSnackBarType) -> Unit,
onClickRecommend: () -> Unit,
onClickViewMore: () -> Unit,
onClickCheckResult: () -> Unit
onClickCheckResult: (Int) -> Unit
) {
val uiState = viewModel.collectAsState().value

Expand Down Expand Up @@ -123,7 +123,7 @@ private fun HomeContent(
data: HomeUiState.Content,
onClickRecommend: () -> Unit,
onClickViewMore: () -> Unit,
onClickCheckResult: () -> Unit
onClickCheckResult: (Int) -> Unit
) {
LazyColumn(
modifier = Modifier.fillMaxSize().padding(bottom = padding.calculateBottomPadding()),
Expand All @@ -142,6 +142,7 @@ private fun HomeContent(
item {
Spacer(modifier = Modifier.height(24.dp))
LottoRecommendCardItem(
round = data.round,
date = data.date,
userName = data.userName,
numbers = data.lottoNumbers,
Expand Down Expand Up @@ -204,13 +205,14 @@ private fun HomeImage() {

@Composable
private fun LottoRecommendCardItem(
round: Int,
date: LocalDate,
userName: String,
numbers: List<Int?>,
openType: HomeUiState.Content.OpenType,
onClickRecommend: () -> Unit = {},
onClickViewMore: () -> Unit = {},
onClickCheckResult: () -> Unit = {}
onClickCheckResult: (Int) -> Unit = {}
) {
Box(
modifier = Modifier
Expand Down Expand Up @@ -256,8 +258,8 @@ private fun LottoRecommendCardItem(
modifier = Modifier
.padding(start = 20.dp, end = 20.dp, bottom = 24.dp)
.background(color = Primary2, shape = RoundedCornerShape(8.dp))
.padding(vertical = 12.dp)
.clickable { onClickRecommend() }
.padding(vertical = 12.dp)
) {
Text(
text = "번호 추천받기",
Expand Down Expand Up @@ -302,8 +304,8 @@ private fun LottoRecommendCardItem(
modifier = Modifier
.padding(start = 20.dp, end = 20.dp, bottom = 24.dp)
.background(color = Primary2, shape = RoundedCornerShape(8.dp))
.clickable { onClickCheckResult(round) }
.padding(vertical = 12.dp)
.clickable { onClickCheckResult() }
) {
Text(
text = "결과 확인하기",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import kotlinx.coroutines.launch
import org.orbitmvi.orbit.Container
import org.orbitmvi.orbit.ContainerHost
import org.orbitmvi.orbit.viewmodel.container
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalDateTime
import javax.inject.Inject
Expand Down Expand Up @@ -64,7 +63,7 @@ class HomeViewModel @Inject constructor(
date = now.toLocalDate(),
openType = when {
lottoRecommendation.content == null -> HomeUiState.Content.OpenType.RECOMMEND
now.isAlreadyOpened() -> HomeUiState.Content.OpenType.OPENED
lottoRecommendation.isFinished -> HomeUiState.Content.OpenType.OPENED
lottoRecommendation.content != null -> HomeUiState.Content.OpenType.MORE
else -> HomeUiState.Content.OpenType.FALLBACK
},
Expand All @@ -81,10 +80,4 @@ class HomeViewModel @Inject constructor(
}
}
}

private fun LocalDateTime.isAlreadyOpened(): Boolean {
return this.dayOfWeek >= DayOfWeek.SATURDAY
&& this.hour >= 20
&& this.minute > 30
}
}
Loading
Loading