Skip to content

Commit

Permalink
[feat]: hus 라이브러리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kez-lab committed Nov 20, 2024
1 parent 2a166d4 commit 3e4ebc4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ dependencies {

// Hilt Worker
implementation(libs.androidx.hilt.common)

// HMH - Usage Stats
implementation(libs.hmh.hus)
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/hmh/hamyeonham/HMHApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.amplitude.api.Amplitude
import com.hmh.hamyeonham.core.notification.AppNotificationManager
import com.hmh.hamyeonham.hus.usagestats.HMHUsageStatsManager
import com.kakao.sdk.common.KakaoSdk
import dagger.hilt.EntryPoint
import dagger.hilt.EntryPoints
Expand Down Expand Up @@ -35,6 +36,7 @@ class HMHApplication : Application(), Configuration.Provider {
setAmplitude()

KakaoSdk.init(this, BuildConfig.KAKAO_API_KEY)
HMHUsageStatsManager.init(this)
notificationManager.setupNotificationChannel()
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

dependencies {
classpath(libs.kotlin.gradleplugin)
classpath(libs.hilt.plugin)

classpath(libs.agp)
classpath(libs.ktlint)
classpath(libs.oss.plugin)
Expand Down
2 changes: 2 additions & 0 deletions data/usagestats/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ dependencies {
implementation(projects.core.network)
implementation(projects.core.domain)
implementation(projects.core.common)

implementation(libs.hmh.hus)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.content.Context
import com.hmh.hamyeonham.core.domain.usagegoal.repository.UsageGoalsRepository
import com.hmh.hamyeonham.usagestats.datasource.local.DeletedAppUsageLocalDataSource
import com.hmh.hamyeonham.usagestats.datasource.local.DeletedAppUsageLocalDataSourceImpl
import com.hmh.hamyeonham.usagestats.datasource.local.UsageStatusLocalDataSource
import com.hmh.hamyeonham.usagestats.datasource.local.UsageStatusLocalDataSourceImpl
import com.hmh.hamyeonham.usagestats.repository.DefaultDeleteGoalRepository
import com.hmh.hamyeonham.usagestats.repository.DefaultUsageGoalsRepository
import com.hmh.hamyeonham.usagestats.repository.DefaultUsageStatsRepository
Expand All @@ -33,9 +31,6 @@ object UsageStatsModule {
@Module
@InstallIn(SingletonComponent::class)
interface Binder {
@Binds
@Singleton
fun provideUsageStatusDataSource(usageStatsDataSource: UsageStatusLocalDataSourceImpl): UsageStatusLocalDataSource

@Binds
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@ package com.hmh.hamyeonham.usagestats.repository

import com.hmh.hamyeonham.common.time.getCurrentDayStartEndEpochMillis
import com.hmh.hamyeonham.common.time.getTargetDayStartEndEpochMillis
import com.hmh.hamyeonham.usagestats.datasource.local.UsageStatusLocalDataSource
import com.hmh.hamyeonham.hus.usagestats.HMHUsageStatsManager
import com.hmh.hamyeonham.usagestats.model.UsageStatus
import kotlinx.datetime.toLocalDate
import javax.inject.Inject

class DefaultUsageStatsRepository @Inject constructor(
private val usageStatusLocalDataSource: UsageStatusLocalDataSource,
) : UsageStatsRepository {
class DefaultUsageStatsRepository @Inject constructor() : UsageStatsRepository {
override suspend fun getUsageStats(targetDate: String): List<UsageStatus> {
val (startTime, endTime) = getTargetDayStartEndEpochMillis(targetDate.toLocalDate())
val usageStatsList = usageStatusLocalDataSource.getUsageStats(startTime, endTime)
val usageStatsList = HMHUsageStatsManager.getUsageStats(startTime, endTime)
return usageStatsList.map { usageStatModel ->
UsageStatus(usageStatModel.packageName, usageStatModel.totalTimeInForeground)
UsageStatus(usageStatModel.packageName, usageStatModel.timeInForeground)
}
}

override suspend fun getUsageStats(
startTime: Long,
endTime: Long,
): List<UsageStatus> {
val usageStatsList = usageStatusLocalDataSource.getUsageStats(startTime, endTime)
val usageStatsList = HMHUsageStatsManager.getUsageStats(startTime, endTime)
return usageStatsList.map { usageStatModel ->
UsageStatus(usageStatModel.packageName, usageStatModel.totalTimeInForeground)
UsageStatus(usageStatModel.packageName, usageStatModel.timeInForeground)
}
}

Expand Down Expand Up @@ -76,6 +74,6 @@ class DefaultUsageStatsRepository @Inject constructor(
}

override fun getForegroundAppPackageName(): String? {
return usageStatusLocalDataSource.getForegroundAppPackageName()
return HMHUsageStatsManager.getForegroundAppPackageName()
}
}
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ androidx-hilt = "1.2.0"
work-runtime-ktx = "2.9.0"
timber = "5.0.1"
amplitude = "2.+"
hus = "0.0.5"


[libraries]
Expand Down Expand Up @@ -216,6 +217,9 @@ androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx"
#amplitude
amplitude = { module = "com.amplitude:android-sdk", version.ref = "amplitude" }

#HMH-UsageStats
hmh-hus = { group = "xyz.hmh-api", name = "hmh-hus", version.ref = "hus" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
Expand Down

0 comments on commit 3e4ebc4

Please sign in to comment.