Skip to content
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

Merged
merged 19 commits into from
Jan 10, 2024
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
3 changes: 1 addition & 2 deletions app/src/main/java/com/hmh/hamyeonham/SampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.hmh.hamyeonham.common.view.viewBinding
import com.hmh.hamyeonham.databinding.ActivitySampleBinding
import com.hmh.hamyeonham.feature.main.MainActivity
import com.hmh.hamyeonham.feature.onboarding.OnBoardingActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -22,7 +21,7 @@ class SampleActivity : AppCompatActivity() {
val splashScreen = installSplashScreen()
initSplashAnimation(splashScreen)
setContentView(binding.root)
startActivity(Intent(this, OnBoardingActivity::class.java))
startActivity(Intent(this, MainActivity::class.java))
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ class GridSpacingItemDecoration(
}
}
}

class VerticalSpaceItemDecoration(private val verticalSpaceHeight: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view)

// 첫 번째와 마지막 아이템을 제외한 경우에만 마진 적용
if (position != 0) {
outRect.top = verticalSpaceHeight
}
Comment on lines +75 to +78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

position != 0 인데 마지막 아이템도 마진 적용되는 거 맞을까요?

}
}
2 changes: 1 addition & 1 deletion core/designsystem/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

<!-- Other Colors -->
<color name="white_btn">#EBECF4</color>
</resources>
</resources>
1 change: 1 addition & 0 deletions core/viewmodel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Empty file.
1 change: 1 addition & 0 deletions core/viewmodel/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
22 changes: 22 additions & 0 deletions core/viewmodel/main/build.gradle.kts
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")

}
Empty file.
21 changes: 21 additions & 0 deletions core/viewmodel/main/proguard-rules.pro
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
4 changes: 4 additions & 0 deletions core/viewmodel/main/src/main/AndroidManifest.xml
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
Copy link
Member

Choose a reason for hiding this comment

The 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()
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
}
}
21 changes: 21 additions & 0 deletions core/viewmodel/proguard-rules.pro
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
1 change: 1 addition & 0 deletions domain/challenge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
7 changes: 7 additions & 0 deletions domain/challenge/build.gradle.kts
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 {}
Empty file.
21 changes: 21 additions & 0 deletions domain/challenge/proguard-rules.pro
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
4 changes: 4 additions & 0 deletions domain/challenge/src/main/AndroidManifest.xml
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아주 깔끔한 UseCase 굿!

This file was deleted.

1 change: 1 addition & 0 deletions feature/challenge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
18 changes: 18 additions & 0 deletions feature/challenge/build.gradle.kts
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)
}
Empty file.
21 changes: 21 additions & 0 deletions feature/challenge/proguard-rules.pro
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
4 changes: 4 additions & 0 deletions feature/challenge/src/main/AndroidManifest.xml
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>
Loading