Skip to content
Open
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
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ dependencies {
implementation(projects.data.device)
implementation(projects.data.onboarding)
implementation(projects.data.lock)
implementation(projects.data.main)

// Core
implementation(projects.core.common)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion core/viewmodel/main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies {
implementation(projects.domain.challenge)
implementation(projects.domain.userinfo)
implementation(projects.domain.lock)
implementation(projects.domain.main)

implementation(projects.core.network)
implementation(projects.core.common)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.hmh.hamyeonham.core.viewmodel

import com.hmh.hamyeonham.core.viewmodel.HomeItem.BannerModel
import com.hmh.hamyeonham.domain.main.banner.model.Banner
import com.hmh.hamyeonham.usagestats.model.UsageStatusAndGoal

sealed class HomeItem {
Expand All @@ -21,19 +19,4 @@ sealed class HomeItem {
val usageAppStatusAndGoal: UsageStatusAndGoal.App,
) : HomeItem()

data class BannerModel(
val title: String,
val subTitle: String,
val imageUrl: String,
val linkUrl: String,
val backgroundColors: List<String>
) : HomeItem()
}

fun Banner.toBannerModel() = BannerModel(
title,
subTitle,
imageUrl,
linkUrl,
backgroundColors,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.lifecycle.viewModelScope
import com.hmh.hamyeonham.common.time.getCurrentDayStartEndEpochMillis
import com.hmh.hamyeonham.core.domain.usagegoal.model.AppUsageGoal
import com.hmh.hamyeonham.core.domain.usagegoal.repository.UsageGoalsRepository
import com.hmh.hamyeonham.domain.main.MainRepository
import com.hmh.hamyeonham.lock.UpdateIsUnLockUseCase
import com.hmh.hamyeonham.usagestats.model.UsageStatusAndGoal
import com.hmh.hamyeonham.usagestats.usecase.GetUsageStatsListUseCase
Expand All @@ -18,7 +17,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import timber.log.Timber
Expand All @@ -28,7 +27,6 @@ import javax.inject.Inject
class MainViewModel @Inject constructor(
private val usageGoalsRepository: UsageGoalsRepository,
private val userInfoRepository: UserInfoRepository,
private val mainRepository: MainRepository,
private val getUsageStatsListUseCase: GetUsageStatsListUseCase,
private val updateIsUnLockUseCase: UpdateIsUnLockUseCase,
) : ViewModel() {
Expand All @@ -39,20 +37,14 @@ class MainViewModel @Inject constructor(
private val _usageStatusAndGoals = MutableStateFlow(UsageStatusAndGoal())
val usageStatusAndGoals = _usageStatusAndGoals.asStateFlow()

private val banner = MutableStateFlow<HomeItem.BannerModel?>(null)

val homeItems = combine(
banner,
usageStatusAndGoals
) { bannerModel, usageStatusAndGoals ->
combineHomeItems(bannerModel, usageStatusAndGoals)
}.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
val homeItems = usageStatusAndGoals
.map { usage -> combineHomeItems(usage) }
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())

private val _effect = MutableSharedFlow<MainEffect>()
val effect = _effect.asSharedFlow()

init {
getBanner()
viewModelScope.launch(Dispatchers.Main) {
updateIsUnLockUseCase()
}
Expand Down Expand Up @@ -122,21 +114,7 @@ class MainViewModel @Inject constructor(
_usageStatusAndGoals.value = usageStatsList
}

private fun getBanner() {
viewModelScope.launch {
val bannerData = mainRepository
.getBanner()
.getOrNull()
if (bannerData == null) return@launch
if (bannerData.imageUrl.isBlank()) return@launch
if (bannerData.title.isBlank()) return@launch

banner.value = bannerData.toBannerModel()
}
}

private fun combineHomeItems(
banner: HomeItem.BannerModel?,
usageStatusAndGoal: UsageStatusAndGoal
): List<HomeItem> {
val items = mutableListOf<HomeItem>()
Expand All @@ -149,10 +127,6 @@ class MainViewModel @Inject constructor(
)
)

banner?.let {
items.add(it)
}

items.addAll(
usageStatusAndGoal.apps.map { apps ->
HomeItem.UsageStaticsModel(apps)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.hmh.hamyeonham.common.view.ItemDiffCallback
import com.hmh.hamyeonham.core.viewmodel.HomeItem
import com.hmh.hamyeonham.feature.main.databinding.ItemBannerBinding
import com.hmh.hamyeonham.feature.main.databinding.ItemUsagestaticBinding
import com.hmh.hamyeonham.feature.main.databinding.ItemUsagestaticTotalBinding

Expand All @@ -31,11 +30,6 @@ class UsageStaticsAdapter : ListAdapter<HomeItem, RecyclerView.ViewHolder>(
val binding = ItemUsagestaticBinding.inflate(inflater, parent, false)
UsageStaticsViewHolder(binding, parent.context)
}

HomeItemViewType.BANNER_ITEM_TYPE -> {
val binding = ItemBannerBinding.inflate(inflater, parent, false)
BannerViewHolder(binding)
}
}
}

Expand All @@ -53,11 +47,6 @@ class UsageStaticsAdapter : ListAdapter<HomeItem, RecyclerView.ViewHolder>(
val item = currentList.getOrNull(position) as? HomeItem.UsageStaticsModel ?: return
holder.onBind(item)
}

is BannerViewHolder -> {
val item = currentList.getOrNull(position) as? HomeItem.BannerModel ?: return
holder.onBind(item)
}
}
}

Expand All @@ -66,7 +55,6 @@ class UsageStaticsAdapter : ListAdapter<HomeItem, RecyclerView.ViewHolder>(
val itemType = when (currentItem) {
is HomeItem.TotalModel -> HomeItemViewType.TOTAL_ITEM_TYPE
is HomeItem.UsageStaticsModel -> HomeItemViewType.APP_ITEM_TYPE
is HomeItem.BannerModel -> HomeItemViewType.BANNER_ITEM_TYPE
}
return HomeItemViewType.getOrdinal(itemType)
}
Expand All @@ -78,9 +66,7 @@ class UsageStaticsAdapter : ListAdapter<HomeItem, RecyclerView.ViewHolder>(

enum class HomeItemViewType {
TOTAL_ITEM_TYPE,
APP_ITEM_TYPE,
BANNER_ITEM_TYPE,
;
APP_ITEM_TYPE;

companion object {
fun fromOrdinal(ordinal: Int) =
Expand Down
53 changes: 0 additions & 53 deletions feature/main/src/main/res/layout/item_banner.xml

This file was deleted.

Loading