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

#178 [refact] Rules 멀티 모듈로 Refactoring #179

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".App"
android:name=".HousApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/java/com/hous/hous_aos/App.kt

This file was deleted.

14 changes: 14 additions & 0 deletions app/src/main/java/com/hous/hous_aos/HousApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hous.hous_aos

import android.app.Application
import com.hous.hous_aos.util.TimberDebugTree
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

@HiltAndroidApp
class HousApp : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) Timber.plant(TimberDebugTree())
}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/hous/hous_aos/di/ApiModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hous.hous_aos.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ApiModule {
@Provides
@Singleton
fun provideHomeService(retrofit: Retrofit): com.hous.data.api.HomeApi =
retrofit.create(com.hous.data.api.HomeApi::class.java)

@Provides
@Singleton
fun provideRulesService(retrofit: Retrofit): com.hous.data.api.RulesApi =
retrofit.create(com.hous.data.api.RulesApi::class.java)

@Provides
@Singleton
fun provideProfileService(retrofit: Retrofit): com.hous.data.api.ProfileApi =
retrofit.create(com.hous.data.api.ProfileApi::class.java)

@Provides
@Singleton
fun provideNewRulesApi(retrofit: Retrofit): com.hous.data.api.NewRulesApi =
retrofit.create(com.hous.data.api.NewRulesApi::class.java)
}
24 changes: 2 additions & 22 deletions app/src/main/java/com/hous/hous_aos/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import java.util.concurrent.TimeUnit
import javax.inject.Singleton
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
Expand Down Expand Up @@ -71,24 +71,4 @@ object NetworkModule {
)
)
.build()

@Provides
@Singleton
fun provideHomeService(retrofit: Retrofit): com.hous.data.api.HomeApi =
retrofit.create(com.hous.data.api.HomeApi::class.java)

@Provides
@Singleton
fun provideRulesService(retrofit: Retrofit): com.hous.data.api.RulesApi =
retrofit.create(com.hous.data.api.RulesApi::class.java)

@Provides
@Singleton
fun provideProfileService(retrofit: Retrofit): com.hous.data.api.ProfileApi =
retrofit.create(com.hous.data.api.ProfileApi::class.java)

@Provides
@Singleton
fun provideNewRulesApi(retrofit: Retrofit): com.hous.data.api.NewRulesApi =
retrofit.create(com.hous.data.api.NewRulesApi::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EventDialogFragment : DialogFragment() {
_binding =
DataBindingUtil.inflate(inflater, R.layout.fragment_event_dialog, container, false)
binding.viewModel = viewModel
binding.lifecycleOwner = this@EventDialogFragment
binding.lifecycleOwner = viewLifecycleOwner
return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.hous.domain.model.Homie
import com.hous.domain.model.HomieInfo
import com.hous.hous_aos.R
import com.hous.hous_aos.ui.newrules.component.CategoryItem
import com.hous.hous_aos.ui.newrules.component.ManagerItem
Expand Down Expand Up @@ -143,7 +143,7 @@ fun NewRulesScreen(
Spacer(modifier = Modifier.size(12.dp))
}

itemsIndexed(uiState.ManagerList) { index, value ->
itemsIndexed(uiState.managerList) { index, value ->
ManagerItem(
manager = value,
currentIndex = index,
Expand Down Expand Up @@ -177,7 +177,7 @@ fun NewRulesScreen(
}

fun isAddDay(
homies: List<Homie>,
homies: List<HomieInfo>,
homieState: HashMap<String, Boolean>
): Boolean {
var temp = false
Expand Down
128 changes: 64 additions & 64 deletions app/src/main/java/com/hous/hous_aos/ui/newrules/NewRulesViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.hous.hous_aos.ui.newrules
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hous.domain.model.Category
import com.hous.domain.model.DayData
import com.hous.domain.model.Homie
import com.hous.domain.model.CategoryInfo
import com.hous.domain.model.DayDataInfo
import com.hous.domain.model.HomieInfo
import com.hous.domain.model.Manager
import com.hous.domain.model.State
import com.hous.domain.usecase.AddNewRuleUseCase
Expand Down Expand Up @@ -52,7 +52,7 @@ class NewRulesViewModel @Inject constructor(

private fun isDayCheck(): Boolean {
var isDay = true
for (manager in uiState.value.ManagerList) {
for (manager in uiState.value.managerList) {
var temp = false
for (dayList in manager.dayDataList) {
if (dayList.dayState == State.SELECT) {
Expand Down Expand Up @@ -105,89 +105,89 @@ class NewRulesViewModel @Inject constructor(
if (isChange) {
val tempManager = listOf(
Manager(
uiState.value.ManagerList[0].managerHomie,
uiState.value.managerList[0].managerHomie,
dayDataList = listOf(
DayData("월", State.UNSELECT),
DayData("화", State.UNSELECT),
DayData("수", State.UNSELECT),
DayData("목", State.UNSELECT),
DayData("금", State.UNSELECT),
DayData("토", State.UNSELECT),
DayData("일", State.UNSELECT)
DayDataInfo("월", State.UNSELECT),
DayDataInfo("화", State.UNSELECT),
DayDataInfo("수", State.UNSELECT),
DayDataInfo("목", State.UNSELECT),
DayDataInfo("금", State.UNSELECT),
DayDataInfo("토", State.UNSELECT),
DayDataInfo("일", State.UNSELECT)
)
)
)
_uiState.value = _uiState.value.copy(ManagerList = tempManager)
_uiState.value = _uiState.value.copy(managerList = tempManager)
} else {
val tempManager = listOf(
Manager(
uiState.value.ManagerList[0].managerHomie,
uiState.value.managerList[0].managerHomie,
dayDataList = listOf(
DayData("월", State.BLOCK),
DayData("화", State.BLOCK),
DayData("수", State.BLOCK),
DayData("목", State.BLOCK),
DayData("금", State.BLOCK),
DayData("토", State.BLOCK),
DayData("일", State.BLOCK)
DayDataInfo("월", State.BLOCK),
DayDataInfo("화", State.BLOCK),
DayDataInfo("수", State.BLOCK),
DayDataInfo("목", State.BLOCK),
DayDataInfo("금", State.BLOCK),
DayDataInfo("토", State.BLOCK),
DayDataInfo("일", State.BLOCK)
)
)
)
_uiState.value = _uiState.value.copy(ManagerList = tempManager)
_uiState.value = _uiState.value.copy(managerList = tempManager)
}
}

fun deleteManager(index: Int) {
uiState.value.homieState[uiState.value.ManagerList[index].managerHomie.userName] = true
if (uiState.value.ManagerList.size > 1) {
uiState.value.homieState[uiState.value.managerList[index].managerHomie.userName] = true
if (uiState.value.managerList.size > 1) {
val tempManager = mutableListOf<Manager>()
_uiState.value.ManagerList.forEach { manager -> tempManager.add(manager) }
_uiState.value.managerList.forEach { manager -> tempManager.add(manager) }
tempManager.removeAt(index)
_uiState.value = _uiState.value.copy(ManagerList = tempManager)
_uiState.value = _uiState.value.copy(managerList = tempManager)
} else {
_uiState.value = _uiState.value.copy(ManagerList = listOf(Manager()))
_uiState.value = _uiState.value.copy(managerList = listOf(Manager()))
setCheckBoxState("deleteManager", State.UNSELECT)
}
}

fun choiceManager(managerIndex: Int, homie: Homie) {
if (uiState.value.ManagerList[managerIndex].managerHomie.userName != "담당자 없음") {
_uiState.value.homieState[uiState.value.ManagerList[managerIndex].managerHomie.userName] =
fun choiceManager(managerIndex: Int, homie: HomieInfo) {
if (uiState.value.managerList[managerIndex].managerHomie.userName != "담당자 없음") {
_uiState.value.homieState[uiState.value.managerList[managerIndex].managerHomie.userName] =
true
}
val tempManager = Manager(
managerHomie = homie,
dayDataList = uiState.value.ManagerList[managerIndex].dayDataList
dayDataList = uiState.value.managerList[managerIndex].dayDataList
)
val tempManagerList = mutableListOf<Manager>()
_uiState.value.ManagerList.forEach { manager -> tempManagerList.add(manager) }
_uiState.value.managerList.forEach { manager -> tempManagerList.add(manager) }
tempManagerList[managerIndex] = tempManager
_uiState.value.homieState[homie.userName] = false
_uiState.value = _uiState.value.copy(ManagerList = tempManagerList)
_uiState.value = _uiState.value.copy(managerList = tempManagerList)
}

fun selectDay(managerIndex: Int, dayData: DayData) {
fun selectDay(managerIndex: Int, dayData: DayDataInfo) {
if (dayData.dayState != State.BLOCK) {
val tempManager = Manager(
managerHomie = _uiState.value.ManagerList[managerIndex].managerHomie,
managerHomie = _uiState.value.managerList[managerIndex].managerHomie,
dayDataList = changeDayState(dayData, managerIndex)
)
val tempManagerList = mutableListOf<Manager>()
uiState.value.ManagerList.forEach { manager -> tempManagerList.add(manager) }
uiState.value.managerList.forEach { manager -> tempManagerList.add(manager) }
tempManagerList[managerIndex] = tempManager
_uiState.value = _uiState.value.copy(ManagerList = tempManagerList)
_uiState.value = _uiState.value.copy(managerList = tempManagerList)
}
}

fun isShowAddButton(): Boolean =
uiState.value.ManagerList[uiState.value.ManagerList.size - 1].managerHomie.userName != "담당자 없음"
uiState.value.managerList[uiState.value.managerList.size - 1].managerHomie.userName != "담당자 없음"

fun addManager() {
val tempManagerList = mutableListOf<Manager>()
val nextManager = Manager(managerHomie = nextManager())
uiState.value.ManagerList.forEach { manager -> tempManagerList.add(manager) }
uiState.value.managerList.forEach { manager -> tempManagerList.add(manager) }
tempManagerList.add(nextManager)
_uiState.value = _uiState.value.copy(ManagerList = tempManagerList)
_uiState.value = _uiState.value.copy(managerList = tempManagerList)
}

fun addNewRule() {
Expand All @@ -197,16 +197,16 @@ class NewRulesViewModel @Inject constructor(
categoryId = uiState.value.categoryId,
notificationState = uiState.value.notificationState,
checkBoxState = uiState.value.checkBoxState,
managerList = uiState.value.ManagerList
managerList = uiState.value.managerList
)
}
}

private fun nextManager(): Homie {
var tempHomie = Homie("", "담당자 없음", typeColor = "NULL")
private fun nextManager(): HomieInfo {
var tempHomie = HomieInfo("", "담당자 없음", typeColor = "NULL")
for (i in uiState.value.homies) {
if (uiState.value.homieState[i.userName]!!) {
tempHomie = Homie(
tempHomie = HomieInfo(
id = i.id,
userName = i.userName,
typeColor = i.typeColor
Expand All @@ -218,23 +218,23 @@ class NewRulesViewModel @Inject constructor(
return tempHomie
}

private fun changeDayState(dayData: DayData, managerIndex: Int): List<DayData> {
val tempDay = mutableListOf<DayData>()
uiState.value.ManagerList[managerIndex].dayDataList.forEach { d ->
private fun changeDayState(dayData: DayDataInfo, managerIndex: Int): List<DayDataInfo> {
val tempDay = mutableListOf<DayDataInfo>()
uiState.value.managerList[managerIndex].dayDataList.forEach { d ->
if (d.day == dayData.day) {
when (dayData.dayState) {
State.UNSELECT -> {
tempDay.add(DayData(d.day, State.SELECT))
tempDay.add(DayDataInfo(d.day, State.SELECT))
setCheckBoxState("changeDayState Unselect", State.BLOCK)
}
State.SELECT -> {
tempDay.add(DayData(d.day, State.UNSELECT))
if (uiState.value.ManagerList.size == 1) {
tempDay.add(DayDataInfo(d.day, State.UNSELECT))
if (uiState.value.managerList.size == 1) {
var isCheck = true
uiState.value.ManagerList[0].dayDataList.forEach { dayData ->
uiState.value.managerList[0].dayDataList.forEach { dayData ->
if (dayData.dayState == State.SELECT) isCheck = false
}
if (isCheck && uiState.value.ManagerList[0].managerHomie.userName == "담당자 없음") {
if (isCheck && uiState.value.managerList[0].managerHomie.userName == "담당자 없음") {
setCheckBoxState("changeDayState select", State.UNSELECT)
}
}
Expand All @@ -252,20 +252,20 @@ data class NewRulesUiState(
val categoryId: String = "",
val notificationState: Boolean = false,
val checkBoxState: State = State.UNSELECT,
val ruleCategory: List<Category> =
val ruleCategory: List<CategoryInfo> =
listOf(
Category("1", "청소기"),
Category("2", "분리수거"),
Category("3", "세탁기"),
Category("4", "물 주기")
CategoryInfo("1", "청소기"),
CategoryInfo("2", "분리수거"),
CategoryInfo("3", "세탁기"),
CategoryInfo("4", "물 주기")
),
val homies: List<Homie> =
val homies: List<HomieInfo> =
listOf(
Homie("1", "강원용", typeColor = "RED"),
Homie("2", "이영주", typeColor = "BLUE"),
Homie("3", "이준원", typeColor = "YELLOW"),
Homie("4", "최인영", typeColor = "GREEN"),
Homie("5", "최소현", typeColor = "PURPLE")
HomieInfo("1", "강원용", typeColor = "RED"),
HomieInfo("2", "이영주", typeColor = "BLUE"),
HomieInfo("3", "이준원", typeColor = "YELLOW"),
HomieInfo("4", "최인영", typeColor = "GREEN"),
HomieInfo("5", "최소현", typeColor = "PURPLE")
),
val homieState: HashMap<String, Boolean> = hashMapOf(
"강원용" to true,
Expand All @@ -274,5 +274,5 @@ data class NewRulesUiState(
"최인영" to true,
"최소현" to true
),
val ManagerList: List<Manager> = listOf(Manager())
val managerList: List<Manager> = listOf(Manager())
)
Loading