-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat/challenge]: 챌린지 기초 작업 #66
Changes from all commits
6cffb36
82fda1a
0949121
d2167c1
c057553
142d6f7
d55468a
12dd368
468f6be
290f343
44ac3bb
cfda0d3
ec89ac2
9626348
88021cc
9ff4398
5506d61
682ff06
7baef2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ | |
|
||
<!-- Other Colors --> | ||
<color name="white_btn">#EBECF4</color> | ||
</resources> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
hmh("feature") | ||
} | ||
|
||
|
||
android { | ||
namespace = "com.hmh.hamyeonham.core.main" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.domain.usagestats) | ||
implementation(projects.domain.challenge) | ||
|
||
implementation(projects.core.common) | ||
|
||
// TEST | ||
testImplementation("androidx.arch.core:core-testing:2.2.0") | ||
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") | ||
testImplementation ("io.mockk:mockk:1.12.1") | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.hmh.hamyeonham.core | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.hmh.hamyeonham.challenge.model.ChallengeStatus | ||
import com.hmh.hamyeonham.usagestats.model.UsageGoal | ||
import com.hmh.hamyeonham.usagestats.usecase.GetUsageGoalsUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import javax.inject.Inject | ||
|
||
data class MainState( | ||
val challengeStatus: ChallengeStatus = ChallengeStatus(), | ||
val usageGoals: List<UsageGoal> = emptyList(), | ||
) | ||
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MVI 패턴 적용 참고해서 나중에 저도 잘 다듬어보겠습니다 |
||
|
||
@HiltViewModel | ||
class MainViewModel @Inject constructor( | ||
private val getUsageGoalsUseCase: GetUsageGoalsUseCase, | ||
) : ViewModel() { | ||
private val _mainState = MutableStateFlow(MainState()) | ||
val mainState = _mainState.asStateFlow() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mainState에 MainViewModel에서 사용하는 여러 dataFlow를 저장하는 건가요? |
||
|
||
init { | ||
setGoalTimeList(getUsageGoalsUseCase()) | ||
} | ||
|
||
fun setChallengeStatus(challengeStatus: ChallengeStatus) { | ||
updateState { | ||
copy(challengeStatus = challengeStatus) | ||
} | ||
} | ||
|
||
fun setGoalTimeList(usageGoal: List<UsageGoal>) { | ||
updateState { | ||
copy(usageGoals = usageGoal) | ||
} | ||
} | ||
|
||
fun updateState(transform: MainState.() -> MainState) { | ||
val currentState = mainState.value | ||
val newState = currentState.transform() | ||
_mainState.value = newState | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.hmh.hamyeonham.core.main | ||
|
||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
import com.hmh.hamyeonham.challenge.model.ChallengeStatus | ||
import com.hmh.hamyeonham.core.MainViewModel | ||
import com.hmh.hamyeonham.usagestats.usecase.GetUsageGoalsUseCase | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TestRule | ||
|
||
class MainViewModelTest { | ||
|
||
@get:Rule | ||
var rule: TestRule = InstantTaskExecutorRule() | ||
|
||
private lateinit var getUsageGoalsUseCase: GetUsageGoalsUseCase | ||
private lateinit var viewModel: MainViewModel | ||
|
||
@Before | ||
fun setUp() { | ||
getUsageGoalsUseCase = mockk(relaxed = true) | ||
viewModel = MainViewModel(getUsageGoalsUseCase) | ||
} | ||
|
||
@Test | ||
fun `setChallengeStatus가 호출될 때 mainState가 제대로 업데이트 되는지 테스트`() = runTest { | ||
val testChallengeStatus = ChallengeStatus() // ChallengeStatus의 적절한 초기화 필요 | ||
viewModel.setChallengeStatus(testChallengeStatus) | ||
|
||
val updatedState = viewModel.mainState.first() | ||
assertEquals(testChallengeStatus, updatedState.challengeStatus) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
`java-library` | ||
kotlin("jvm") | ||
} | ||
|
||
dependencies {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.hmh.hamyeonham.challenge.model | ||
|
||
|
||
data class ChallengeStatus( | ||
val apps: List<App> = emptyList(), | ||
val isSuccessList: List<Boolean?> = emptyList(), | ||
val goalTime: Int = 0, | ||
val period: Int = 0, | ||
) { | ||
data class App( | ||
val appCode: String, | ||
val appGoalTime: Int | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
package com.hmh.hamyeonham.usagestats.model | ||
|
||
data class UsageGoal( | ||
val packageName: String, | ||
val goalTime: Long, | ||
) | ||
val packageName: String = "", | ||
val goalTime: Long = 0, | ||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런식으로 초기화 할 수 있구나~ 배워갑니다~ |
||
) { | ||
|
||
val goalTimeInHours: Long | ||
get() = goalTime / 1000 / 60 / 60 | ||
val goalTimeInMinutes: Long | ||
get() = goalTime / 1000 / 60 | ||
|
||
val formattedGoalTime: String | ||
get() { | ||
val hours = goalTimeInHours | ||
val minutes = goalTimeInMinutes | ||
return buildString { | ||
if (hours > 0) { | ||
append("$hours 시간") | ||
} | ||
if (minutes > 0) { | ||
if (hours > 0) append(" ") | ||
append("$minutes 분") | ||
} | ||
} | ||
} | ||
Comment on lines
+13
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확장성을 위해서 이 함수를 common에 넣는 건 안좋은 방법인가요? 궁금합니다! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hmh.hamyeonham.usagestats.usecase | ||
|
||
import com.hmh.hamyeonham.usagestats.model.UsageGoal | ||
import com.hmh.hamyeonham.usagestats.repository.UsageGoalsRepository | ||
import javax.inject.Inject | ||
|
||
class GetUsageGoalsUseCase @Inject constructor( | ||
private val getUsageGoalsUseCase: UsageGoalsRepository | ||
) { | ||
operator fun invoke(): List<UsageGoal> { | ||
return getUsageGoalsUseCase.getUsageGoals() | ||
} | ||
} | ||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아주 깔끔한 UseCase 굿! |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
hmh("feature") | ||
} | ||
|
||
android { | ||
namespace = "com.hmh.hamyeonham.feature.challenge" | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(projects.domain.usagestats) | ||
implementation(projects.domain.challenge) | ||
|
||
implementation(projects.core.common) | ||
implementation(projects.core.designsystem) | ||
implementation(projects.core.viewmodel.main) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
position != 0 인데 마지막 아이템도 마진 적용되는 거 맞을까요?