From 2b1f79e7f381ac1c262cb59026764d3daa15dcfe Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 13:52:38 +0900 Subject: [PATCH 01/37] =?UTF-8?q?#66=20[add]=20=EC=9C=A0=EC=A0=80=EB=B3=84?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8F=B0=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/response/DailyRoutineResponse.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt diff --git a/app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt b/app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt new file mode 100644 index 00000000..b32b4d2f --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt @@ -0,0 +1,35 @@ +package com.sopetit.softie.data.entity.response + +import com.sopetit.softie.domain.entity.DailyRoutine +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class DailyRoutineResponse( + @SerialName("DailyRoutineItem") + val routines: List +) { + @Serializable + data class DailyRoutineItem( + @SerialName("routineId") + val routineId: Int, + @SerialName("content") + val content: String, + @SerialName("iconImageUrl") + val iconImageUrl: String, + @SerialName("achieveCount") + val achieveCount: Int, + @SerialName("isAchieve") + val isAchieve: Boolean + ) + + fun toUserDailyRoutine() = routines.map { + DailyRoutine( + routineId = it.routineId, + content = it.content, + iconImageUrl = it.iconImageUrl, + achieveCount = it.achieveCount, + isAchieve = it.isAchieve + ) + } +} From 56f1c2c1d3907860d6fbae11fd54ad4f3b5b9c22 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 13:52:54 +0900 Subject: [PATCH 02/37] =?UTF-8?q?#66=20[add]=20=EC=9C=A0=EC=A0=80=EB=B3=84?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositoryImpl/DailyRoutineRepositoryImpl.kt | 15 +++++++++++++++ .../domain/repository/DailyRoutineRepository.kt | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt create mode 100644 app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt diff --git a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt new file mode 100644 index 00000000..28c8901c --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.sopetit.softie.data.repositoryImpl + +import com.sopetit.softie.data.source.DailyRoutineDataSource +import com.sopetit.softie.domain.entity.DailyRoutine +import com.sopetit.softie.domain.repository.DailyRoutineRepository +import javax.inject.Inject + +class DailyRoutineRepositoryImpl @Inject constructor( + private val dailyRoutineDataSource: DailyRoutineDataSource +) : DailyRoutineRepository { + override suspend fun getDailyRoutine(): Result> = + runCatching { dailyRoutineDataSource.getDailyRoutine() }.mapCatching { response -> + requireNotNull(response.data).toUserDailyRoutine() + } +} diff --git a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt new file mode 100644 index 00000000..44d1f59d --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt @@ -0,0 +1,7 @@ +package com.sopetit.softie.domain.repository + +import com.sopetit.softie.domain.entity.DailyRoutine + +interface DailyRoutineRepository { + suspend fun getDailyRoutine(): Result> +} From a6f652ccb9e5952360ffd7c693a8600e9ad118ef Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 13:53:05 +0900 Subject: [PATCH 03/37] =?UTF-8?q?#66=20[add]=20=EC=9C=A0=EC=A0=80=EB=B3=84?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopetit/softie/data/service/DailyRoutineService.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt new file mode 100644 index 00000000..61ae33fd --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -0,0 +1,10 @@ +package com.sopetit.softie.data.service + +import com.sopetit.softie.data.entity.BaseResponse +import com.sopetit.softie.data.entity.response.DailyRoutineResponse +import retrofit2.http.GET + +interface DailyRoutineService { + @GET("api/v1/routines/daily/member") + suspend fun getDailyRoutine(): BaseResponse +} From c1d208fef3725d2c80c9a281212b0ecd43207079 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 13:53:15 +0900 Subject: [PATCH 04/37] =?UTF-8?q?#66=20[add]=20=EC=9C=A0=EC=A0=80=EB=B3=84?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EC=86=8C=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softie/data/source/DailyRoutineDataSource.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt diff --git a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt new file mode 100644 index 00000000..cd95ca36 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt @@ -0,0 +1,13 @@ +package com.sopetit.softie.data.source + +import com.sopetit.softie.data.entity.BaseResponse +import com.sopetit.softie.data.entity.response.DailyRoutineResponse +import com.sopetit.softie.data.service.DailyRoutineService +import javax.inject.Inject + +class DailyRoutineDataSource @Inject constructor( + private val dailyRoutineService: DailyRoutineService +) { + suspend fun getDailyRoutine(): BaseResponse = + dailyRoutineService.getDailyRoutine() +} From 6b060d57d529d00eda67c814b5dfb52c911cb404 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 13:53:26 +0900 Subject: [PATCH 05/37] =?UTF-8?q?#66=20[add]=20=EC=9C=A0=EC=A0=80=EB=B3=84?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EC=9C=A0?= =?UTF-8?q?=EC=8A=A4=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softie/domain/usecase/GetDailyRoutineUseCase.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/domain/usecase/GetDailyRoutineUseCase.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/GetDailyRoutineUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/GetDailyRoutineUseCase.kt new file mode 100644 index 00000000..31cba036 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/GetDailyRoutineUseCase.kt @@ -0,0 +1,10 @@ +package com.sopetit.softie.domain.usecase + +import com.sopetit.softie.domain.repository.DailyRoutineRepository +import javax.inject.Inject + +class GetDailyRoutineUseCase @Inject constructor( + private val dailyRoutineRepository: DailyRoutineRepository +) { + suspend operator fun invoke() = dailyRoutineRepository.getDailyRoutine() +} From f344130cd014be4de7eacfa41398be4b9c797205 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 13:53:35 +0900 Subject: [PATCH 06/37] =?UTF-8?q?#66=20[add]=20=EC=9C=A0=EC=A0=80=EB=B3=84?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/sopetit/softie/di/RepositoryModule.kt | 8 ++++++++ .../java/com/sopetit/softie/di/RetrofitServiceModule.kt | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt b/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt index 46455174..c2542541 100644 --- a/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt +++ b/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt @@ -1,6 +1,8 @@ package com.sopetit.softie.di +import com.sopetit.softie.data.repositoryImpl.DailyRoutineRepositoryImpl import com.sopetit.softie.data.repositoryImpl.MemberRepositoryImpl +import com.sopetit.softie.domain.repository.DailyRoutineRepository import com.sopetit.softie.domain.repository.MemberRepository import dagger.Binds import dagger.Module @@ -16,4 +18,10 @@ abstract class RepositoryModule { abstract fun bindToMemberRepository( memberRepositoryImpl: MemberRepositoryImpl ): MemberRepository + + @Binds + @Singleton + abstract fun bindToDailyRoutineRepository( + dailyRoutineRepositoryImpl: DailyRoutineRepositoryImpl + ): DailyRoutineRepository } diff --git a/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt b/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt index 637d99c3..d092abbf 100644 --- a/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt +++ b/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt @@ -1,5 +1,6 @@ package com.sopetit.softie.di +import com.sopetit.softie.data.service.DailyRoutineService import com.sopetit.softie.data.service.MemberService import dagger.Module import dagger.Provides @@ -13,4 +14,8 @@ object RetrofitServiceModule { @Provides fun providesMemberService(@RetrofitModule.SoftieType retrofit: Retrofit): MemberService = retrofit.create(MemberService::class.java) + + @Provides + fun providesDailyRoutineService(@RetrofitModule.SoftieType retrofit: Retrofit): DailyRoutineService = + retrofit.create(DailyRoutineService::class.java) } From c37c17339f1dafe29b7e247a6bc698081265022b Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 14:28:39 +0900 Subject: [PATCH 07/37] =?UTF-8?q?#66=20[feat]=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=B3=84=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20?= =?UTF-8?q?=EB=B7=B0=EB=AA=A8=EB=8D=B8=20=EC=84=9C=EB=B2=84=ED=86=B5?= =?UTF-8?q?=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/dailyroutine/DailyRoutineViewModel.kt | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index 59fb7b4f..25e94b54 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -1,30 +1,23 @@ package com.sopetit.softie.ui.dailyroutine +import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.sopetit.softie.domain.entity.DailyRoutine +import com.sopetit.softie.domain.usecase.GetDailyRoutineUseCase +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import timber.log.Timber +import javax.inject.Inject -class DailyRoutineViewModel : ViewModel() { +@HiltViewModel +class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCase: GetDailyRoutineUseCase) : + ViewModel( + ) { - private val _mockDailyRoutineList: MutableLiveData> = MutableLiveData( - mutableListOf( - DailyRoutine( - 1, - "일찍 일어나기", - "", - 3, - true - ), - DailyRoutine( - 2, - "작업 끝내기", - "", - 5, - false - ) - ) - ) + private val _mockDailyRoutineList: MutableLiveData> = MutableLiveData() val mockDailyRoutineList: LiveData> get() = _mockDailyRoutineList @@ -51,6 +44,24 @@ class DailyRoutineViewModel : ViewModel() { val isEditBtnEnabled: LiveData get() = _isEditBtnEnabled + fun getDailyRoutine() { + viewModelScope.launch { + getDailyRoutineUseCase() + .onSuccess { response -> + _mockDailyRoutineList.value = response +// _isRoutineAchieveFirst.value = true +// _isRoutineAchieveSecond.value = true +// _isRoutineAchieveThird.value = true +// _isDeleteView.value = true +// _isEditBtnEnabled.value = true + } + .onFailure { throwable -> + Log.e("되나", "$throwable") + Timber.e("$throwable") + } + } + } + fun setRoutineAchieve(isAchieve: Boolean, index: Int) { when (index) { 0 -> _isRoutineAchieveFirst.value = isAchieve From c72aff4b76432da9853ef85f9c6a4755d72cf7d5 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 14:39:48 +0900 Subject: [PATCH 08/37] =?UTF-8?q?#66=20[feat]=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=B3=84=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20?= =?UTF-8?q?ui=EC=97=90=20=EB=B7=B0=EB=AA=A8=EB=8D=B8=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index 03c981d1..241746d7 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -63,6 +63,7 @@ class DailyRoutineFragment : btn: View, index: Int ) { + viewModel.getDailyRoutine() viewModel.mockDailyRoutineList.observe(viewLifecycleOwner) { dailyRoutineList -> val achieveCountMsg = getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) @@ -122,6 +123,7 @@ class DailyRoutineFragment : } private fun clickEditRadioBtn() { + viewModel.getDailyRoutine() viewModel.mockDailyRoutineList.observe(viewLifecycleOwner) { routineList -> with(binding) { changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) From 8010d8c2c9f8e61469abbe62803da71061d21712 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 17:01:49 +0900 Subject: [PATCH 09/37] =?UTF-8?q?#66=20[feat]=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=B3=84=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/response/DailyRoutineResponse.kt | 2 +- .../ui/dailyroutine/DailyRoutineFragment.kt | 9 +++-- .../ui/dailyroutine/DailyRoutineViewModel.kt | 39 ++++++++----------- .../res/layout/fragment_daily_routine.xml | 13 ++++--- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt b/app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt index b32b4d2f..eafe60d4 100644 --- a/app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt +++ b/app/src/main/java/com/sopetit/softie/data/entity/response/DailyRoutineResponse.kt @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable @Serializable data class DailyRoutineResponse( - @SerialName("DailyRoutineItem") + @SerialName("routines") val routines: List ) { @Serializable diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index 241746d7..9ccc80fc 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -14,7 +14,9 @@ import com.sopetit.softie.util.binding.BindingBottomSheet import com.sopetit.softie.util.binding.BindingFragment import com.sopetit.softie.util.setStatusBarColor import com.sopetit.softie.util.snackBar +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class DailyRoutineFragment : BindingFragment(R.layout.fragment_daily_routine) { @@ -27,6 +29,8 @@ class DailyRoutineFragment : binding.viewModel = viewModel + viewModel.getDailyRoutine() + moveToAddRoutine() getBundle() initSetDailyRoutineContent() @@ -63,8 +67,7 @@ class DailyRoutineFragment : btn: View, index: Int ) { - viewModel.getDailyRoutine() - viewModel.mockDailyRoutineList.observe(viewLifecycleOwner) { dailyRoutineList -> + viewModel.dailyRoutineListResponse.observe(viewLifecycleOwner) { dailyRoutineList -> val achieveCountMsg = getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) achieveMsg.text = achieveCountMsg @@ -124,7 +127,7 @@ class DailyRoutineFragment : private fun clickEditRadioBtn() { viewModel.getDailyRoutine() - viewModel.mockDailyRoutineList.observe(viewLifecycleOwner) { routineList -> + viewModel.dailyRoutineListResponse.observe(viewLifecycleOwner) { routineList -> with(binding) { changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) changeBtnSelectState(btnDailyRoutineRadioSecond, routineList[1].routineId) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index 25e94b54..65899090 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -1,6 +1,5 @@ package com.sopetit.softie.ui.dailyroutine -import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -16,11 +15,23 @@ import javax.inject.Inject class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCase: GetDailyRoutineUseCase) : ViewModel( ) { + private val _dailyRoutineListResponse: MutableLiveData> = MutableLiveData() + val dailyRoutineListResponse: LiveData> + get() = _dailyRoutineListResponse - private val _mockDailyRoutineList: MutableLiveData> = MutableLiveData() - - val mockDailyRoutineList: LiveData> - get() = _mockDailyRoutineList + fun getDailyRoutine() { + viewModelScope.launch { + getDailyRoutineUseCase() + .onSuccess { response -> + _dailyRoutineListResponse.value = response + Timber.d("뷰모델 서버 성공") + } + .onFailure { throwable -> + Timber.d("뷰모델 서버 실패") + Timber.e("$throwable") + } + } + } private val _isRoutineAchieveFirst: MutableLiveData = MutableLiveData() val isRoutineAchieveFirst: LiveData @@ -44,24 +55,6 @@ class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCa val isEditBtnEnabled: LiveData get() = _isEditBtnEnabled - fun getDailyRoutine() { - viewModelScope.launch { - getDailyRoutineUseCase() - .onSuccess { response -> - _mockDailyRoutineList.value = response -// _isRoutineAchieveFirst.value = true -// _isRoutineAchieveSecond.value = true -// _isRoutineAchieveThird.value = true -// _isDeleteView.value = true -// _isEditBtnEnabled.value = true - } - .onFailure { throwable -> - Log.e("되나", "$throwable") - Timber.e("$throwable") - } - } - } - fun setRoutineAchieve(isAchieve: Boolean, index: Int) { when (index) { 0 -> _isRoutineAchieveFirst.value = isAchieve diff --git a/app/src/main/res/layout/fragment_daily_routine.xml b/app/src/main/res/layout/fragment_daily_routine.xml index 274e3f81..12fa774c 100644 --- a/app/src/main/res/layout/fragment_daily_routine.xml +++ b/app/src/main/res/layout/fragment_daily_routine.xml @@ -36,6 +36,7 @@ android:layout_marginEnd="6dp" android:text="@{viewModel.isDeleteView ? @string/daily_routine_edit_cancel : @string/daily_routine_edit}" android:textAppearance="@style/body4" + android:clickable="@{viewModel.dailyRoutineListResponse.size() == 0 ? false : true}" android:textColor="@color/gray400" android:paddingVertical="12dp" android:paddingHorizontal="14dp" @@ -47,7 +48,7 @@ android:id="@+id/v_daily_routine_blank" android:layout_width="match_parent" android:layout_height="2dp" - android:visibility="@{viewModel.mockDailyRoutineList.size() == 0 ? View.VISIBLE : View.GONE}" + android:visibility="@{viewModel.dailyRoutineListResponse.size() == 0 ? View.VISIBLE : View.GONE}" app:layout_constraintTop_toBottomOf="@id/tv_daily_routine_name" /> @@ -108,7 +109,7 @@ android:layout_height="wrap_content" android:layout_marginStart="4dp" android:layout_marginTop="5dp" - android:text="@{@string/daily_routine_ing(viewModel.mockDailyRoutineList[0].achieveCount)}" + android:text="@{@string/daily_routine_ing(viewModel.dailyRoutineListResponse[0].achieveCount)}" android:textAppearance="@style/caption1" android:textColor="@color/gray300" app:layout_constraintStart_toEndOf="@id/iv_daily_routine_fin_first" @@ -145,7 +146,7 @@ android:layout_marginHorizontal="20dp" android:layout_marginTop="8dp" android:background="@drawable/shape_white_fill_gray100_stroke_20_rect" - android:visibility="@{viewModel.mockDailyRoutineList.size() >= 2 ? View.VISIBLE : View.GONE}" + android:visibility="@{viewModel.dailyRoutineListResponse.size() >= 2 ? View.VISIBLE : View.GONE}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cl_daily_routine_first"> @@ -228,7 +229,7 @@ android:layout_marginHorizontal="20dp" android:layout_marginTop="8dp" android:background="@drawable/shape_white_fill_gray100_stroke_20_rect" - android:visibility="@{viewModel.mockDailyRoutineList.size() == 3 ? View.VISIBLE : View.GONE}" + android:visibility="@{viewModel.dailyRoutineListResponse.size() == 3 ? View.VISIBLE : View.GONE}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cl_daily_routine_second"> @@ -315,7 +316,7 @@ android:layout_marginTop="8dp" android:background="@drawable/shape_gray200_line_20_rect" android:clickable="true" - android:visibility="@{viewModel.mockDailyRoutineList.size() == 3 ? View.GONE : View.VISIBLE}" + android:visibility="@{viewModel.dailyRoutineListResponse.size() == 3 ? View.GONE : View.VISIBLE}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cl_daily_routine_third"> From c8b91da5f3a1148af56420ffd57cfc3dcd90ffaf Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 17:30:30 +0900 Subject: [PATCH 10/37] =?UTF-8?q?#66=20[chore]=20ci=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index 65899090..ca794ec8 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -13,8 +13,7 @@ import javax.inject.Inject @HiltViewModel class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCase: GetDailyRoutineUseCase) : - ViewModel( - ) { + ViewModel() { private val _dailyRoutineListResponse: MutableLiveData> = MutableLiveData() val dailyRoutineListResponse: LiveData> get() = _dailyRoutineListResponse @@ -24,6 +23,7 @@ class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCa getDailyRoutineUseCase() .onSuccess { response -> _dailyRoutineListResponse.value = response + println(response) Timber.d("뷰모델 서버 성공") } .onFailure { throwable -> From 3f82e0957f71b6a0f8c06ceee7dc894ab27095ad Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 18:03:32 +0900 Subject: [PATCH 11/37] =?UTF-8?q?#66=20[chore]=20=EC=84=B8=EB=B2=88?= =?UTF-8?q?=EC=A7=B8=20=EB=A3=A8=ED=8B=B4=20=EC=A0=95=EB=A0=AC=20=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softie/ui/dailyroutine/DailyRoutineFragment.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index 9ccc80fc..70c3051c 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -3,8 +3,10 @@ package com.sopetit.softie.ui.dailyroutine import android.content.Intent import android.os.Bundle import android.view.View +import android.widget.ImageView import android.widget.TextView import androidx.fragment.app.viewModels +import coil.load import com.sopetit.softie.R import com.sopetit.softie.databinding.FragmentDailyRoutineBinding import com.sopetit.softie.domain.entity.Bear @@ -47,21 +49,31 @@ class DailyRoutineFragment : private fun initSetDailyRoutineContent() { with(binding) { routineItemView( + ivDailyRoutineIconFirst, tvDailyRoutineAddNameFirst, tvDailyRoutineIngFirst, btnDailyRoutineYetFinFirst, 0 ) routineItemView( + ivDailyRoutineIconSecond, tvDailyRoutineAddNameSecond, tvDailyRoutineIngSecond, btnDailyRoutineYetFinSecond, 1 ) + routineItemView( + ivDailyRoutineIconThird, + tvDailyRoutineAddNameThird, + tvDailyRoutineIngThird, + btnDailyRoutineYetFinThird, + 2 + ) } } private fun routineItemView( + dailyIcon: ImageView, routineTitle: TextView, achieveMsg: TextView, btn: View, @@ -72,6 +84,7 @@ class DailyRoutineFragment : getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) achieveMsg.text = achieveCountMsg routineTitle.text = dailyRoutineList[index].content + dailyIcon.load(dailyRoutineList[index].iconImageUrl) viewModel.setRoutineAchieve(dailyRoutineList[index].isAchieve, index) initSetDailyRoutineAchieve(btn, dailyRoutineList[index].routineId) @@ -131,6 +144,7 @@ class DailyRoutineFragment : with(binding) { changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) changeBtnSelectState(btnDailyRoutineRadioSecond, routineList[1].routineId) + changeBtnSelectState(btnDailyRoutineRadioThird, routineList[2].routineId) } } } From 78d256c6b8e01ddfb0ff0464a34bc1b9a9368730 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 19:33:13 +0900 Subject: [PATCH 12/37] =?UTF-8?q?#66=20[chore]=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EB=A1=9C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt | 5 +++-- .../sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index 982a81b9..7c6f7b1c 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -8,12 +8,12 @@ import android.widget.TextView import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.viewModels -import coil.load import com.sopetit.softie.R import com.sopetit.softie.databinding.FragmentDailyRoutineBinding import com.sopetit.softie.domain.entity.Bear import com.sopetit.softie.ui.dailyroutine.dailyroutineadd.DailyRoutineAddActivity import com.sopetit.softie.util.OriginalBottomSheet.Companion.BOTTOM_SHEET_TAG +import com.sopetit.softie.util.binding.BindingAdapter.setImage import com.sopetit.softie.util.binding.BindingBottomSheet import com.sopetit.softie.util.binding.BindingFragment import com.sopetit.softie.util.setStatusBarColor @@ -87,7 +87,8 @@ class DailyRoutineFragment : getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) achieveMsg.text = achieveCountMsg routineTitle.text = dailyRoutineList[index].content - dailyIcon.load(dailyRoutineList[index].iconImageUrl) +// dailyIcon.load(dailyRoutineList[index].iconImageUrl) + dailyIcon.setImage(dailyRoutineList[index].iconImageUrl) viewModel.setRoutineAchieve(dailyRoutineList[index].isAchieve, index) initSetDailyRoutineAchieve(btn, dailyRoutineList[index].routineId) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index ca794ec8..6034a7aa 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -23,7 +23,6 @@ class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCa getDailyRoutineUseCase() .onSuccess { response -> _dailyRoutineListResponse.value = response - println(response) Timber.d("뷰모델 서버 성공") } .onFailure { throwable -> From 21e37cdb63535e3fbb7c30e9f870db1ead98ae85 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 20:32:23 +0900 Subject: [PATCH 13/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopetit/softie/domain/entity/DailyAchieve.kt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/domain/entity/DailyAchieve.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/entity/DailyAchieve.kt b/app/src/main/java/com/sopetit/softie/domain/entity/DailyAchieve.kt new file mode 100644 index 00000000..17fe3291 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/entity/DailyAchieve.kt @@ -0,0 +1,7 @@ +package com.sopetit.softie.domain.entity + +data class DailyAchieve( + val routineId: Int, + val isAchieve: Boolean, + val achieveCount: Int +) From eb9a3f3fd1f1e4d94006a4652a2e837f1c085733 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 20:34:06 +0900 Subject: [PATCH 14/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8F=B0=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/response/AchieveDailyResponse.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/data/entity/response/AchieveDailyResponse.kt diff --git a/app/src/main/java/com/sopetit/softie/data/entity/response/AchieveDailyResponse.kt b/app/src/main/java/com/sopetit/softie/data/entity/response/AchieveDailyResponse.kt new file mode 100644 index 00000000..6b0d7114 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/entity/response/AchieveDailyResponse.kt @@ -0,0 +1,21 @@ +package com.sopetit.softie.data.entity.response + +import com.sopetit.softie.domain.entity.DailyAchieve +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class AchieveDailyResponse( + @SerialName("routineId") + val routineId: Int, + @SerialName("isAchieve") + val isAchieve: Boolean, + @SerialName("achieveCount") + val achieveCount: Int +) { + fun toAchieveDaily(): DailyAchieve = DailyAchieve( + routineId = this.routineId, + isAchieve = this.isAchieve, + achieveCount = this.achieveCount + ) +} From 361998b1bb754cb6f5fa9bc0916a446368b2860c Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 20:34:23 +0900 Subject: [PATCH 15/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repositoryImpl/DailyRoutineRepositoryImpl.kt | 6 ++++++ .../softie/domain/repository/DailyRoutineRepository.kt | 2 ++ 2 files changed, 8 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt index 28c8901c..26ae39d5 100644 --- a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt +++ b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt @@ -1,6 +1,7 @@ package com.sopetit.softie.data.repositoryImpl import com.sopetit.softie.data.source.DailyRoutineDataSource +import com.sopetit.softie.domain.entity.DailyAchieve import com.sopetit.softie.domain.entity.DailyRoutine import com.sopetit.softie.domain.repository.DailyRoutineRepository import javax.inject.Inject @@ -12,4 +13,9 @@ class DailyRoutineRepositoryImpl @Inject constructor( runCatching { dailyRoutineDataSource.getDailyRoutine() }.mapCatching { response -> requireNotNull(response.data).toUserDailyRoutine() } + + override suspend fun patchAchieveDaily(routineId: Int): Result = + runCatching { dailyRoutineDataSource.patchAchieveDaily(routineId) }.map { response -> + requireNotNull(response.data).toAchieveDaily() + } } diff --git a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt index 44d1f59d..3bcf79b6 100644 --- a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt +++ b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt @@ -1,7 +1,9 @@ package com.sopetit.softie.domain.repository +import com.sopetit.softie.domain.entity.DailyAchieve import com.sopetit.softie.domain.entity.DailyRoutine interface DailyRoutineRepository { suspend fun getDailyRoutine(): Result> + suspend fun patchAchieveDaily(routineId: Int): Result } From 83b836c86fb2df16b066fdbce8ddea6f4541e761 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 20:34:40 +0900 Subject: [PATCH 16/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EC=86=8C=EC=8A=A4,=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopetit/softie/data/service/DailyRoutineService.kt | 6 ++++++ .../sopetit/softie/data/source/DailyRoutineDataSource.kt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt index 61ae33fd..2d526724 100644 --- a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -1,10 +1,16 @@ package com.sopetit.softie.data.service import com.sopetit.softie.data.entity.BaseResponse +import com.sopetit.softie.data.entity.response.AchieveDailyResponse import com.sopetit.softie.data.entity.response.DailyRoutineResponse import retrofit2.http.GET +import retrofit2.http.PATCH +import retrofit2.http.Path interface DailyRoutineService { @GET("api/v1/routines/daily/member") suspend fun getDailyRoutine(): BaseResponse + + @PATCH("api/v1/routines/daily/member/routine/{routineId}") + suspend fun patchAchieveDaily(@Path("routineId") routineId: Int): BaseResponse } diff --git a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt index cd95ca36..f5d2e8d5 100644 --- a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt +++ b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt @@ -1,6 +1,7 @@ package com.sopetit.softie.data.source import com.sopetit.softie.data.entity.BaseResponse +import com.sopetit.softie.data.entity.response.AchieveDailyResponse import com.sopetit.softie.data.entity.response.DailyRoutineResponse import com.sopetit.softie.data.service.DailyRoutineService import javax.inject.Inject @@ -10,4 +11,7 @@ class DailyRoutineDataSource @Inject constructor( ) { suspend fun getDailyRoutine(): BaseResponse = dailyRoutineService.getDailyRoutine() + + suspend fun patchAchieveDaily(routineId: Int): BaseResponse = + dailyRoutineService.patchAchieveDaily(routineId) } From efb7939112fd78caa13c38005fe4ef2a40ed490f Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 20:34:50 +0900 Subject: [PATCH 17/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EC=9C=A0=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softie/domain/usecase/PatchAchieveDailyUseCase.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/domain/usecase/PatchAchieveDailyUseCase.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/PatchAchieveDailyUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/PatchAchieveDailyUseCase.kt new file mode 100644 index 00000000..0bd337f9 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/PatchAchieveDailyUseCase.kt @@ -0,0 +1,11 @@ +package com.sopetit.softie.domain.usecase + +import com.sopetit.softie.domain.repository.DailyRoutineRepository +import javax.inject.Inject + +class PatchAchieveDailyUseCase @Inject constructor( + private val achieveDailyRepository: DailyRoutineRepository +) { + suspend operator fun invoke(routineId: Int) = + achieveDailyRepository.patchAchieveDaily(routineId) +} From a366dfa2443e149acb5f0471c3eac61d0166b162 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Tue, 16 Jan 2024 23:34:07 +0900 Subject: [PATCH 18/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/dailyroutine/DailyRoutineFragment.kt | 15 ++++++- .../ui/dailyroutine/DailyRoutineViewModel.kt | 41 ++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index 7c6f7b1c..637d4e04 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -19,6 +19,7 @@ import com.sopetit.softie.util.binding.BindingFragment import com.sopetit.softie.util.setStatusBarColor import com.sopetit.softie.util.snackBar import dagger.hilt.android.AndroidEntryPoint +import timber.log.Timber @AndroidEntryPoint class DailyRoutineFragment : @@ -41,6 +42,7 @@ class DailyRoutineFragment : initSetDeleteView() initSetRoutineDelete() addDailyRoutineMsg() + achieveRoutine() } private fun getBundle() { @@ -95,10 +97,17 @@ class DailyRoutineFragment : } } + private fun achieveRoutine() { + viewModel.isRoutineAchieveFirst.observe(viewLifecycleOwner) { + } + viewModel.isRoutineAchieveSecond.observe(viewLifecycleOwner) { + } + viewModel.isRoutineAchieveThird.observe(viewLifecycleOwner) { + } + } + private fun initSetDailyRoutineAchieve(btn: View, routineId: Int) { btn.setOnClickListener { - // TODO 서버통신 구현 후 imageUri 버전으로 수정 - BindingBottomSheet.Builder().build( isDrawable = true, imageDrawable = R.drawable.ic_bear_face_crying, @@ -113,6 +122,8 @@ class DailyRoutineFragment : backBtnAction = {}, doBtnAction = { startDailyRoutineCompleteActivity() + viewModel.patchAchieveDaily(routineId) + Timber.d("routineID -> $routineId") } ).show(parentFragmentManager, BOTTOM_SHEET_TAG) } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index 6034a7aa..28fc96e0 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -6,13 +6,17 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.sopetit.softie.domain.entity.DailyRoutine import com.sopetit.softie.domain.usecase.GetDailyRoutineUseCase +import com.sopetit.softie.domain.usecase.PatchAchieveDailyUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import timber.log.Timber import javax.inject.Inject @HiltViewModel -class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCase: GetDailyRoutineUseCase) : +class DailyRoutineViewModel @Inject constructor( + private val getDailyRoutineUseCase: GetDailyRoutineUseCase, + private val patchAchieveDailyUseCase: PatchAchieveDailyUseCase +) : ViewModel() { private val _dailyRoutineListResponse: MutableLiveData> = MutableLiveData() val dailyRoutineListResponse: LiveData> @@ -44,6 +48,41 @@ class DailyRoutineViewModel @Inject constructor(private val getDailyRoutineUseCa val isRoutineAchieveThird: LiveData get() = _isRoutineAchieveThird + fun patchAchieveDaily(routineId: Int) { + viewModelScope.launch { + patchAchieveDailyUseCase(routineId) + .onSuccess { response -> +// routineAchieve(response) +// setRoutineAchieve( +// response.isAchieve, +// dailyRoutineListResponse.value.indexOf() +// ) + routineAchieve(routineId, response.isAchieve) + +// when (response.routineId) +// dailyRoutineListResponse.value?.get(0)?.routineId -> _isRoutineAchieveFirst.value = response.isAchieve +// dailyRoutineListResponse.value.get(1).routineId -> _isRoutineAchieveSeco.value = response.isAchieve +// +// _isRoutineAchieveFirst.value = response.isAchieve +// _isRoutineAchieveSecond.value = response.isAchieve +// _isRoutineAchieveThird.value = response.isAchieve + Timber.d("달성 서버 성공") + } + .onFailure { throwable -> + Timber.d("달성 서버 실패") + Timber.e("$throwable") + } + } + } + + fun routineAchieve(routineId: Int, isAchieve: Boolean) { + when (routineId) { + dailyRoutineListResponse.value?.get(0)?.routineId -> setRoutineAchieve(isAchieve, 0) + dailyRoutineListResponse.value?.get(1)?.routineId -> setRoutineAchieve(isAchieve, 1) + dailyRoutineListResponse.value?.get(2)?.routineId -> setRoutineAchieve(isAchieve, 2) + } + } + private val _isDeleteView: MutableLiveData = MutableLiveData(false) val isDeleteView: LiveData get() = _isDeleteView From f2885c4539ae41ac10c0caa1a308e3414811d91d Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 00:44:27 +0900 Subject: [PATCH 19/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EC=82=AD=EC=A0=9C=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt | 3 +++ .../sopetit/softie/domain/repository/DailyRoutineRepository.kt | 1 + 2 files changed, 4 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt index 26ae39d5..5e409198 100644 --- a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt +++ b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt @@ -18,4 +18,7 @@ class DailyRoutineRepositoryImpl @Inject constructor( runCatching { dailyRoutineDataSource.patchAchieveDaily(routineId) }.map { response -> requireNotNull(response.data).toAchieveDaily() } + + override suspend fun deleteDailyRoutine(routineId: Int): Result = + runCatching { dailyRoutineDataSource.deleteDailyRoutine(routineId) } } diff --git a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt index 3bcf79b6..65c398a2 100644 --- a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt +++ b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt @@ -6,4 +6,5 @@ import com.sopetit.softie.domain.entity.DailyRoutine interface DailyRoutineRepository { suspend fun getDailyRoutine(): Result> suspend fun patchAchieveDaily(routineId: Int): Result + suspend fun deleteDailyRoutine(routineId: Int): Result } From 1758ffacf263097d6c8f5cceb3f2662108199993 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 00:44:50 +0900 Subject: [PATCH 20/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EC=82=AD=EC=A0=9C=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EC=86=8C=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopetit/softie/data/source/DailyRoutineDataSource.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt index f5d2e8d5..292226ae 100644 --- a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt +++ b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt @@ -14,4 +14,7 @@ class DailyRoutineDataSource @Inject constructor( suspend fun patchAchieveDaily(routineId: Int): BaseResponse = dailyRoutineService.patchAchieveDaily(routineId) + + suspend fun deleteDailyRoutine(routineId: Int): BaseResponse = + dailyRoutineService.deleteDailyRoutine(routineId) } From d7840a5e5cde9e65548507c165ec8cde6ec00b9d Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 00:45:17 +0900 Subject: [PATCH 21/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EC=82=AD=EC=A0=9C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopetit/softie/data/service/DailyRoutineService.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt index 2d526724..ae51759a 100644 --- a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -3,6 +3,7 @@ package com.sopetit.softie.data.service import com.sopetit.softie.data.entity.BaseResponse import com.sopetit.softie.data.entity.response.AchieveDailyResponse import com.sopetit.softie.data.entity.response.DailyRoutineResponse +import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.PATCH import retrofit2.http.Path @@ -13,4 +14,7 @@ interface DailyRoutineService { @PATCH("api/v1/routines/daily/member/routine/{routineId}") suspend fun patchAchieveDaily(@Path("routineId") routineId: Int): BaseResponse + + @DELETE("api/v1/routines/daily/member/routine/{routineId}") + suspend fun deleteDailyRoutine(@Path("routineId") routineId: Int): BaseResponse } From a721cd77a320229e6721fde58700a45cc4277dbe Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 00:46:58 +0900 Subject: [PATCH 22/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=B0=8F=20timber=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/dailyroutine/DailyRoutineFragment.kt | 7 ++-- .../ui/dailyroutine/DailyRoutineViewModel.kt | 35 +++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index 637d4e04..3a0f3908 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -19,7 +19,6 @@ import com.sopetit.softie.util.binding.BindingFragment import com.sopetit.softie.util.setStatusBarColor import com.sopetit.softie.util.snackBar import dagger.hilt.android.AndroidEntryPoint -import timber.log.Timber @AndroidEntryPoint class DailyRoutineFragment : @@ -40,7 +39,7 @@ class DailyRoutineFragment : getBundle() initSetDailyRoutineContent() initSetDeleteView() - initSetRoutineDelete() + initSetRoutineDelete(0) addDailyRoutineMsg() achieveRoutine() } @@ -123,7 +122,6 @@ class DailyRoutineFragment : doBtnAction = { startDailyRoutineCompleteActivity() viewModel.patchAchieveDaily(routineId) - Timber.d("routineID -> $routineId") } ).show(parentFragmentManager, BOTTOM_SHEET_TAG) } @@ -186,7 +184,7 @@ class DailyRoutineFragment : binding.btnDailyRoutineDelete.text = deleteBtnContent } - private fun initSetRoutineDelete() { + private fun initSetRoutineDelete(routineId: Int) { viewModel.isEditBtnEnabled.observe(viewLifecycleOwner) { isBtnEnabled -> if (isBtnEnabled) { binding.btnDailyRoutineDelete.setOnClickListener { @@ -208,6 +206,7 @@ class DailyRoutineFragment : "데일리 루틴을 ${viewModel.editRoutineIdArray.size}개 삭제했어요" ) viewModel.setDeleteView(false) + viewModel.deleteDailyRoutine(routineId) } ).show(parentFragmentManager, BOTTOM_SHEET_TAG) } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index 28fc96e0..112ad930 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.sopetit.softie.domain.entity.DailyRoutine +import com.sopetit.softie.domain.usecase.DeleteDailyRoutineUseCase import com.sopetit.softie.domain.usecase.GetDailyRoutineUseCase import com.sopetit.softie.domain.usecase.PatchAchieveDailyUseCase import dagger.hilt.android.lifecycle.HiltViewModel @@ -15,7 +16,8 @@ import javax.inject.Inject @HiltViewModel class DailyRoutineViewModel @Inject constructor( private val getDailyRoutineUseCase: GetDailyRoutineUseCase, - private val patchAchieveDailyUseCase: PatchAchieveDailyUseCase + private val patchAchieveDailyUseCase: PatchAchieveDailyUseCase, + private val deleteDailyRoutineUseCase: DeleteDailyRoutineUseCase ) : ViewModel() { private val _dailyRoutineListResponse: MutableLiveData> = MutableLiveData() @@ -27,10 +29,8 @@ class DailyRoutineViewModel @Inject constructor( getDailyRoutineUseCase() .onSuccess { response -> _dailyRoutineListResponse.value = response - Timber.d("뷰모델 서버 성공") } .onFailure { throwable -> - Timber.d("뷰모델 서버 실패") Timber.e("$throwable") } } @@ -52,24 +52,9 @@ class DailyRoutineViewModel @Inject constructor( viewModelScope.launch { patchAchieveDailyUseCase(routineId) .onSuccess { response -> -// routineAchieve(response) -// setRoutineAchieve( -// response.isAchieve, -// dailyRoutineListResponse.value.indexOf() -// ) routineAchieve(routineId, response.isAchieve) - -// when (response.routineId) -// dailyRoutineListResponse.value?.get(0)?.routineId -> _isRoutineAchieveFirst.value = response.isAchieve -// dailyRoutineListResponse.value.get(1).routineId -> _isRoutineAchieveSeco.value = response.isAchieve -// -// _isRoutineAchieveFirst.value = response.isAchieve -// _isRoutineAchieveSecond.value = response.isAchieve -// _isRoutineAchieveThird.value = response.isAchieve - Timber.d("달성 서버 성공") } .onFailure { throwable -> - Timber.d("달성 서버 실패") Timber.e("$throwable") } } @@ -87,6 +72,20 @@ class DailyRoutineViewModel @Inject constructor( val isDeleteView: LiveData get() = _isDeleteView + fun deleteDailyRoutine(routineId: Int) { + viewModelScope.launch { + deleteDailyRoutineUseCase(routineId) + .onSuccess { + _isDeleteView.value = true + Timber.d("삭제 서버 성공") + } + .onFailure { throwable -> + Timber.d("삭제 서버 실패") + Timber.e("$throwable") + } + } + } + val editRoutineIdArray = ArrayList() private val _isEditBtnEnabled: MutableLiveData = MutableLiveData() From 675821cf4e996788b02864ca85926b98faca3f84 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 00:47:15 +0900 Subject: [PATCH 23/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EC=82=AD=EC=A0=9C=20=EC=9C=A0=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/usecase/DeleteDailyRoutineUseCase.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt new file mode 100644 index 00000000..d6310fcb --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt @@ -0,0 +1,11 @@ +package com.sopetit.softie.domain.usecase + +import com.sopetit.softie.domain.repository.DailyRoutineRepository +import javax.inject.Inject + +class DeleteDailyRoutineUseCase @Inject constructor( + private val deleteDailyRoutine: DailyRoutineRepository +) { + suspend operator fun invoke(routineId: Int) = + deleteDailyRoutine.deleteDailyRoutine(routineId) +} From ecf9ce20e6bd38fde05c4236461ef69b9676a1ec Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 00:47:33 +0900 Subject: [PATCH 24/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EA=B8=80=EC=9E=90=20=ED=96=89=EA=B0=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/fragment_daily_routine.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/res/layout/fragment_daily_routine.xml b/app/src/main/res/layout/fragment_daily_routine.xml index 12fa774c..75ea823c 100644 --- a/app/src/main/res/layout/fragment_daily_routine.xml +++ b/app/src/main/res/layout/fragment_daily_routine.xml @@ -90,6 +90,7 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:text="@string/daily_routine_user_add" + android:lineSpacingMultiplier="1.5" android:textAppearance="@style/body1" app:layout_constraintStart_toEndOf="@id/iv_daily_routine_icon_first" app:layout_constraintTop_toTopOf="@id/iv_daily_routine_icon_first" /> @@ -178,6 +179,7 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:text="@string/daily_routine_user_add" + android:lineSpacingMultiplier="1.5" android:textAppearance="@style/body1" app:layout_constraintStart_toEndOf="@id/iv_daily_routine_icon_second" app:layout_constraintTop_toTopOf="@id/iv_daily_routine_icon_second" /> @@ -261,6 +263,7 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:text="@string/daily_routine_user_add" + android:lineSpacingMultiplier="1.5" android:textAppearance="@style/body1" app:layout_constraintStart_toEndOf="@id/iv_daily_routine_icon_third" app:layout_constraintTop_toTopOf="@id/iv_daily_routine_icon_third" /> From f2e2849537373ad8a31fe229aecd45ed68089c02 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 00:57:47 +0900 Subject: [PATCH 25/37] =?UTF-8?q?#66=20[chore]=20=EC=B6=A9=EB=8F=8C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softie/data/service/DailyRoutineService.kt | 13 +++++-------- .../java/com/sopetit/softie/di/RepositoryModule.kt | 7 ------- .../com/sopetit/softie/di/RetrofitServiceModule.kt | 5 ----- .../domain/repository/DailyRoutineRepository.kt | 8 +++----- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt index 5a0b9d85..acd3fb92 100644 --- a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -1,13 +1,17 @@ package com.sopetit.softie.data.service import com.sopetit.softie.data.entity.BaseResponse +import com.sopetit.softie.data.entity.response.AchieveDailyResponse import com.sopetit.softie.data.entity.response.DailyRoutineListResponse +import com.sopetit.softie.data.entity.response.DailyRoutineResponse import com.sopetit.softie.data.entity.response.ThemeListResponse +import retrofit2.http.DELETE import retrofit2.http.GET +import retrofit2.http.PATCH +import retrofit2.http.Path import retrofit2.http.Query interface DailyRoutineService { - @GET("api/v1/routines/daily/themes") suspend fun getTheme(): BaseResponse @@ -15,14 +19,7 @@ interface DailyRoutineService { suspend fun getRoutineList( @Query("themes") themes: List ): BaseResponse -import com.sopetit.softie.data.entity.response.AchieveDailyResponse -import com.sopetit.softie.data.entity.response.DailyRoutineResponse -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.PATCH -import retrofit2.http.Path -interface DailyRoutineService { @GET("api/v1/routines/daily/member") suspend fun getDailyRoutine(): BaseResponse diff --git a/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt b/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt index 0a9fae62..3967a0cb 100644 --- a/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt +++ b/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt @@ -1,11 +1,9 @@ package com.sopetit.softie.di -import com.sopetit.softie.data.repositoryImpl.DailyRoutineRepositoryImpl import com.sopetit.softie.data.repositoryImpl.DailyRoutineRepositoryImpl import com.sopetit.softie.data.repositoryImpl.DollRepositoryImpl import com.sopetit.softie.data.repositoryImpl.MemberRepositoryImpl import com.sopetit.softie.domain.repository.DailyRoutineRepository -import com.sopetit.softie.domain.repository.DailyRoutineRepository import com.sopetit.softie.domain.repository.DollRepository import com.sopetit.softie.domain.repository.MemberRepository import dagger.Binds @@ -29,11 +27,6 @@ abstract class RepositoryModule { dailyRoutineRepositoryImpl: DailyRoutineRepositoryImpl ): DailyRoutineRepository - @Binds - @Singleton - abstract fun bindToDailyRoutineRepository( - dailyRoutineRepositoryImpl: DailyRoutineRepositoryImpl - ): DailyRoutineRepository @Binds @Singleton diff --git a/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt b/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt index 7989ba81..987b8e1b 100644 --- a/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt +++ b/app/src/main/java/com/sopetit/softie/di/RetrofitServiceModule.kt @@ -1,6 +1,5 @@ package com.sopetit.softie.di -import com.sopetit.softie.data.service.DailyRoutineService import com.sopetit.softie.data.service.DailyRoutineService import com.sopetit.softie.data.service.DollService import com.sopetit.softie.data.service.MemberService @@ -21,10 +20,6 @@ object RetrofitServiceModule { fun providesDailyRoutineService(@RetrofitModule.SoftieType retrofit: Retrofit): DailyRoutineService = retrofit.create(DailyRoutineService::class.java) - @Provides - fun providesDailyRoutineService(@RetrofitModule.SoftieType retrofit: Retrofit): DailyRoutineService = - retrofit.create(DailyRoutineService::class.java) - @Provides fun providesDollService(@RetrofitModule.SoftieType retrofit: Retrofit): DollService = retrofit.create(DollService::class.java) diff --git a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt index ece02f11..2df19560 100644 --- a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt +++ b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt @@ -2,17 +2,15 @@ package com.sopetit.softie.domain.repository import com.sopetit.softie.domain.entity.DailyAchieve import com.sopetit.softie.domain.entity.DailyRoutine +import com.sopetit.softie.domain.entity.Routine +import com.sopetit.softie.domain.entity.Theme interface DailyRoutineRepository { suspend fun getDailyRoutine(): Result> suspend fun patchAchieveDaily(routineId: Int): Result suspend fun deleteDailyRoutine(routineId: Int): Result -import com.sopetit.softie.domain.entity.Routine -import com.sopetit.softie.domain.entity.Theme - -interface DailyRoutineRepository { - suspend fun getTheme(): Result> suspend fun getRoutineList(themeId: List): Result> + } From 7121ee676e945ef03e0f43f4b3b4dc847a3d2050 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 01:29:53 +0900 Subject: [PATCH 26/37] =?UTF-8?q?#66=20[chore]=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/dailyroutine/DailyRoutineViewModel.kt | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index 112ad930..d63b260a 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -72,19 +72,19 @@ class DailyRoutineViewModel @Inject constructor( val isDeleteView: LiveData get() = _isDeleteView - fun deleteDailyRoutine(routineId: Int) { - viewModelScope.launch { - deleteDailyRoutineUseCase(routineId) - .onSuccess { - _isDeleteView.value = true - Timber.d("삭제 서버 성공") - } - .onFailure { throwable -> - Timber.d("삭제 서버 실패") - Timber.e("$throwable") - } - } - } +// fun deleteDailyRoutine(routineId: Int) { +// viewModelScope.launch { +// deleteDailyRoutineUseCase(routineId) +// .onSuccess { +// _isDeleteView.value = true +// Timber.d("삭제 서버 성공") +// } +// .onFailure { throwable -> +// Timber.d("삭제 서버 실패") +// Timber.e("$throwable") +// } +// } +// } val editRoutineIdArray = ArrayList() @@ -104,6 +104,20 @@ class DailyRoutineViewModel @Inject constructor( _isDeleteView.value = deleteEnabled } + fun deleteDailyRoutine(routineId: Int) { + viewModelScope.launch { + deleteDailyRoutineUseCase(routineId) + .onSuccess { + setDeleteView(deleteEnabled = false) + Timber.d("삭제 서버 성공") + } + .onFailure { throwable -> + Timber.d("삭제 서버 실패") + Timber.e("$throwable") + } + } + } + fun setEditRoutineIdArray(routineId: Int) { if (editRoutineIdArray.contains(routineId)) { editRoutineIdArray.removeAt(editRoutineIdArray.indexOf(routineId)) From 1f29c4be168ec7edf33a0c931b54cb88359ef93c Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 03:41:48 +0900 Subject: [PATCH 27/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/sopetit/softie/domain/entity/AddRoutine.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/domain/entity/AddRoutine.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/entity/AddRoutine.kt b/app/src/main/java/com/sopetit/softie/domain/entity/AddRoutine.kt new file mode 100644 index 00000000..43eab5a2 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/entity/AddRoutine.kt @@ -0,0 +1,5 @@ +package com.sopetit.softie.domain.entity + +data class AddRoutine( + val routineId: Int +) From 6cccba1c11fc8e3f0a479eb3b1e3fc098a204093 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 03:43:33 +0900 Subject: [PATCH 28/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8F=B0=EC=8A=A4,=EB=A6=AC=ED=80=98=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/entity/request/AddDailyRoutineRequest.kt | 15 +++++++++++++++ .../entity/response/AddDailyRoutineResponse.kt | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt create mode 100644 app/src/main/java/com/sopetit/softie/data/entity/response/AddDailyRoutineResponse.kt diff --git a/app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt b/app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt new file mode 100644 index 00000000..b9858c29 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt @@ -0,0 +1,15 @@ +package com.sopetit.softie.data.entity.request + +import com.sopetit.softie.domain.entity.AddRoutine +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class AddDailyRoutineRequest( + @SerialName("routineId") + val routineId: Int +) { + fun toAddDailyRoutine(): AddRoutine = AddRoutine( + routineId = this.routineId + ) +} diff --git a/app/src/main/java/com/sopetit/softie/data/entity/response/AddDailyRoutineResponse.kt b/app/src/main/java/com/sopetit/softie/data/entity/response/AddDailyRoutineResponse.kt new file mode 100644 index 00000000..2768c32e --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/entity/response/AddDailyRoutineResponse.kt @@ -0,0 +1,15 @@ +package com.sopetit.softie.data.entity.response + +import com.sopetit.softie.domain.entity.AddRoutine +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class AddDailyRoutineResponse( + @SerialName("routineId") + val routineId: Int +) { + fun toAddDailyRoutine(): AddRoutine = AddRoutine( + routineId = this.routineId + ) +} From 18fa2518489b5128d361c5bf1b394ae6f08266e6 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 12:05:13 +0900 Subject: [PATCH 29/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repositoryImpl/DailyRoutineRepositoryImpl.kt | 6 ++++++ .../softie/domain/repository/DailyRoutineRepository.kt | 2 ++ 2 files changed, 8 insertions(+) diff --git a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt index b6bb0620..97bbbcab 100644 --- a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt +++ b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt @@ -1,6 +1,7 @@ package com.sopetit.softie.data.repositoryImpl import com.sopetit.softie.data.source.DailyRoutineDataSource +import com.sopetit.softie.domain.entity.AddRoutine import com.sopetit.softie.domain.entity.DailyAchieve import com.sopetit.softie.domain.entity.DailyRoutine import com.sopetit.softie.domain.entity.Routine @@ -35,4 +36,9 @@ class DailyRoutineRepositoryImpl @Inject constructor( }.mapCatching { dailyRoutineList -> requireNotNull(dailyRoutineList.data).toRoutine() } + + override suspend fun postAddDailyRoutine(routineId: Int): Result = + runCatching { dailyRoutineDataSource.postAddDailyRoutine(routineId) }.map { response -> + response.toAddDailyRoutine() + } } diff --git a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt index 2df19560..81af3dbe 100644 --- a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt +++ b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt @@ -1,5 +1,6 @@ package com.sopetit.softie.domain.repository +import com.sopetit.softie.domain.entity.AddRoutine import com.sopetit.softie.domain.entity.DailyAchieve import com.sopetit.softie.domain.entity.DailyRoutine import com.sopetit.softie.domain.entity.Routine @@ -13,4 +14,5 @@ interface DailyRoutineRepository { suspend fun getRoutineList(themeId: List): Result> + suspend fun postAddDailyRoutine(routineId: Int): Result } From 2e8cbe9a7008a0266bf0a01845547ef1002b4290 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 12:05:38 +0900 Subject: [PATCH 30/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EC=86=8C=EC=8A=A4,=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopetit/softie/data/service/DailyRoutineService.kt | 6 ++++++ .../sopetit/softie/data/source/DailyRoutineDataSource.kt | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt index acd3fb92..b47bdeb1 100644 --- a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -1,13 +1,16 @@ package com.sopetit.softie.data.service import com.sopetit.softie.data.entity.BaseResponse +import com.sopetit.softie.data.entity.request.AddDailyRoutineRequest import com.sopetit.softie.data.entity.response.AchieveDailyResponse import com.sopetit.softie.data.entity.response.DailyRoutineListResponse import com.sopetit.softie.data.entity.response.DailyRoutineResponse import com.sopetit.softie.data.entity.response.ThemeListResponse +import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.PATCH +import retrofit2.http.POST import retrofit2.http.Path import retrofit2.http.Query @@ -28,4 +31,7 @@ interface DailyRoutineService { @DELETE("api/v1/routines/daily/member/routine/{routineId}") suspend fun deleteDailyRoutine(@Path("routineId") routineId: Int): BaseResponse + + @POST("api/v1/routines/daily/member") + suspend fun postAddDailyRoutine(@Body routineId: Int): AddDailyRoutineRequest } diff --git a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt index a2a369d4..58916665 100644 --- a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt +++ b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt @@ -1,10 +1,11 @@ package com.sopetit.softie.data.source import com.sopetit.softie.data.entity.BaseResponse -import com.sopetit.softie.data.entity.response.DailyRoutineListResponse -import com.sopetit.softie.data.entity.response.ThemeListResponse +import com.sopetit.softie.data.entity.request.AddDailyRoutineRequest import com.sopetit.softie.data.entity.response.AchieveDailyResponse +import com.sopetit.softie.data.entity.response.DailyRoutineListResponse import com.sopetit.softie.data.entity.response.DailyRoutineResponse +import com.sopetit.softie.data.entity.response.ThemeListResponse import com.sopetit.softie.data.service.DailyRoutineService import javax.inject.Inject @@ -19,8 +20,12 @@ class DailyRoutineDataSource @Inject constructor( suspend fun deleteDailyRoutine(routineId: Int): BaseResponse = dailyRoutineService.deleteDailyRoutine(routineId) + suspend fun getTheme(): BaseResponse = dailyRoutineService.getTheme() suspend fun getRoutineList(themeId: List): BaseResponse = dailyRoutineService.getRoutineList(themeId) + + suspend fun postAddDailyRoutine(routineId: Int): AddDailyRoutineRequest = + dailyRoutineService.postAddDailyRoutine(routineId) } From c4e2e4b90fa7042c746930fdc017629a1855cf15 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 12:05:50 +0900 Subject: [PATCH 31/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=AC=EC=84=B1=20=EC=9C=A0=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/usecase/PostAddDailyRoutineUseCase.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/domain/usecase/PostAddDailyRoutineUseCase.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/PostAddDailyRoutineUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/PostAddDailyRoutineUseCase.kt new file mode 100644 index 00000000..d02742be --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/PostAddDailyRoutineUseCase.kt @@ -0,0 +1,11 @@ +package com.sopetit.softie.domain.usecase + +import com.sopetit.softie.domain.repository.DailyRoutineRepository +import javax.inject.Inject + +class PostAddDailyRoutineUseCase @Inject constructor( + private val dailyRoutineRepository: DailyRoutineRepository +) { + suspend operator fun invoke(routineId: Int) = + dailyRoutineRepository.postAddDailyRoutine(routineId) +} From 0849b793ff5d35e3d96563663c0f1df9e3e49ada Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 20:49:04 +0900 Subject: [PATCH 32/37] =?UTF-8?q?#66=20[add]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=20=EB=A3=A8=ED=8B=B4=20=EB=AC=B8=EC=9E=A5=EC=88=98=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EB=B0=98=EC=9D=91=ED=98=95=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=A7=8C=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/layout/fragment_daily_routine.xml | 58 +++++++++++-------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/app/src/main/res/layout/fragment_daily_routine.xml b/app/src/main/res/layout/fragment_daily_routine.xml index 75ea823c..26bcfbc1 100644 --- a/app/src/main/res/layout/fragment_daily_routine.xml +++ b/app/src/main/res/layout/fragment_daily_routine.xml @@ -34,12 +34,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="6dp" + android:clickable="@{viewModel.dailyRoutineListResponse.size() == 0 ? false : true}" + android:paddingHorizontal="14dp" + android:paddingVertical="12dp" android:text="@{viewModel.isDeleteView ? @string/daily_routine_edit_cancel : @string/daily_routine_edit}" android:textAppearance="@style/body4" - android:clickable="@{viewModel.dailyRoutineListResponse.size() == 0 ? false : true}" android:textColor="@color/gray400" - android:paddingVertical="12dp" - android:paddingHorizontal="14dp" app:layout_constraintBottom_toBottomOf="@id/tv_daily_routine_name" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@id/tv_daily_routine_name" /> @@ -54,7 +54,7 @@ @@ -121,20 +123,22 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginHorizontal="20dp" + android:layout_marginTop="82dp" android:layout_marginBottom="16dp" android:background="@{viewModel.isRoutineAchieveFirst ? @drawable/shape_gray100_fill_10_rect : @drawable/shape_main1_fill_10_rect}" - android:enabled="@{!viewModel.isRoutineAchieveFirst}" android:clickable="@{!viewModel.isRoutineAchieveFirst}" - android:text="@{viewModel.isRoutineAchieveFirst ? @string/daily_routine_fin : @string/daily_routine_fin_btn}" + android:enabled="@{!viewModel.isRoutineAchieveFirst}" android:minHeight="0dp" + android:outlineProvider="none" android:paddingTop="10dp" android:paddingBottom="11dp" + android:text="@{viewModel.isRoutineAchieveFirst ? @string/daily_routine_fin : @string/daily_routine_fin_btn}" android:textAppearance="@style/body4" android:textColor="@color/white" - android:outlineProvider="none" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> @@ -143,7 +147,7 @@ @@ -199,9 +203,11 @@ android:layout_height="wrap_content" android:layout_marginStart="4dp" android:layout_marginTop="5dp" + android:layout_marginBottom="21dp" android:text="@string/daily_routine_ing" android:textAppearance="@style/caption1" android:textColor="@color/gray300" + app:layout_constraintBottom_toTopOf="@id/btn_daily_routine_yet_fin_second" app:layout_constraintStart_toEndOf="@id/iv_daily_routine_fin_second" app:layout_constraintTop_toBottomOf="@id/tv_daily_routine_add_name_second" /> @@ -210,24 +216,26 @@ android:layout_width="0dp" android:layout_height="38dp" android:layout_marginHorizontal="20dp" + android:layout_marginTop="82dp" android:layout_marginBottom="16dp" android:background="@{viewModel.isRoutineAchieveSecond ? @drawable/shape_gray100_fill_10_rect : @drawable/shape_main1_fill_10_rect}" - android:enabled="@{!viewModel.isRoutineAchieveSecond}" android:clickable="@{!viewModel.isRoutineAchieveSecond}" + android:enabled="@{!viewModel.isRoutineAchieveSecond}" + android:outlineProvider="none" android:text="@{viewModel.isRoutineAchieveSecond ? @string/daily_routine_fin : @string/daily_routine_fin_btn}" android:textAppearance="@style/body4" android:textColor="@color/white" - android:outlineProvider="none" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> @@ -283,9 +291,11 @@ android:layout_height="wrap_content" android:layout_marginStart="4dp" android:layout_marginTop="5dp" + android:layout_marginBottom="21dp" android:text="@string/daily_routine_ing" android:textAppearance="@style/caption1" android:textColor="@color/gray300" + app:layout_constraintBottom_toTopOf="@id/btn_daily_routine_yet_fin_third" app:layout_constraintStart_toEndOf="@id/iv_daily_routine_fin_third" app:layout_constraintTop_toBottomOf="@id/tv_daily_routine_add_name_third" /> @@ -294,20 +304,22 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginHorizontal="20dp" + android:layout_marginTop="82dp" android:layout_marginBottom="16dp" android:background="@{viewModel.isRoutineAchieveThird ? @drawable/shape_gray100_fill_10_rect : @drawable/shape_main1_fill_10_rect}" - android:enabled="@{!viewModel.isRoutineAchieveThird}" android:clickable="@{!viewModel.isRoutineAchieveThird}" - android:text="@{viewModel.isRoutineAchieveThird ? @string/daily_routine_fin : @string/daily_routine_fin_btn}" + android:enabled="@{!viewModel.isRoutineAchieveThird}" android:minHeight="0dp" + android:outlineProvider="none" android:paddingTop="10dp" android:paddingBottom="11dp" + android:text="@{viewModel.isRoutineAchieveThird ? @string/daily_routine_fin : @string/daily_routine_fin_btn}" android:textAppearance="@style/body4" android:textColor="@color/white" - android:outlineProvider="none" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> @@ -344,13 +356,13 @@ android:background="@{viewModel.isEditBtnEnabled ? @drawable/shape_red_fill_12_rect : @drawable/shape_gray200_fill_12_rect}" android:clickable="@{viewModel.isEditBtnEnabled ? true : false}" android:enabled="@{viewModel.isEditBtnEnabled ? true : false}" + android:outlineProvider="none" android:paddingTop="20dp" android:paddingBottom="18dp" android:text="@{@string/daily_routine_edit_delete(viewModel.editRoutineIdArray.size)}" android:textAppearance="@style/body1" android:textColor="@color/gray000" android:visibility="@{viewModel.isDeleteView ? View.VISIBLE : View.INVISIBLE}" - android:outlineProvider="none" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> From 55fac11a7b32ef46a2e6154e6158c701929935be Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 22:39:23 +0900 Subject: [PATCH 33/37] =?UTF-8?q?#66=20[add]=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=BC=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopetit/softie/domain/entity/UserDailyRoutine.kt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/src/main/java/com/sopetit/softie/domain/entity/UserDailyRoutine.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/entity/UserDailyRoutine.kt b/app/src/main/java/com/sopetit/softie/domain/entity/UserDailyRoutine.kt new file mode 100644 index 00000000..1bf8de82 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/entity/UserDailyRoutine.kt @@ -0,0 +1,8 @@ +package com.sopetit.softie.domain.entity + +data class UserDailyRoutine( + val routineId: Int, + val iconImageUrl: String, + val content: String, + val backgroundImageUrl: String +) From 409ada64a0cb54e499edc4cd6804c8ecb1dc7541 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Wed, 17 Jan 2024 22:40:23 +0900 Subject: [PATCH 34/37] =?UTF-8?q?#66=20[chore]=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/request/AddDailyRoutineRequest.kt | 7 +--- .../data/entity/response/DailyCardResponse.kt | 25 ++++++++++++ .../DailyRoutineRepositoryImpl.kt | 6 ++- .../data/service/DailyRoutineService.kt | 8 +++- .../data/source/DailyRoutineDataSource.kt | 4 +- .../ui/dailyroutine/DailyRoutineFragment.kt | 38 ++++++++++++++----- .../ui/dailyroutine/DailyRoutineViewModel.kt | 9 ++++- .../DailyRoutineAddActivity.kt | 29 ++++++++------ .../DailyRoutineAddViewModel.kt | 33 +++++++++++++++- .../res/layout/fragment_daily_routine.xml | 8 ++-- 10 files changed, 129 insertions(+), 38 deletions(-) create mode 100644 app/src/main/java/com/sopetit/softie/data/entity/response/DailyCardResponse.kt diff --git a/app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt b/app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt index b9858c29..27a234e1 100644 --- a/app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt +++ b/app/src/main/java/com/sopetit/softie/data/entity/request/AddDailyRoutineRequest.kt @@ -1,6 +1,5 @@ package com.sopetit.softie.data.entity.request -import com.sopetit.softie.domain.entity.AddRoutine import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -8,8 +7,4 @@ import kotlinx.serialization.Serializable data class AddDailyRoutineRequest( @SerialName("routineId") val routineId: Int -) { - fun toAddDailyRoutine(): AddRoutine = AddRoutine( - routineId = this.routineId - ) -} +) diff --git a/app/src/main/java/com/sopetit/softie/data/entity/response/DailyCardResponse.kt b/app/src/main/java/com/sopetit/softie/data/entity/response/DailyCardResponse.kt new file mode 100644 index 00000000..406626cd --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/data/entity/response/DailyCardResponse.kt @@ -0,0 +1,25 @@ +package com.sopetit.softie.data.entity.response + +import com.sopetit.softie.domain.entity.Routine +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +data class DailyCardResponse( + @SerialName("routines") + val routines: List +) { + @Serializable + data class RoutineItem( + @SerialName("routineId") + val routineId: Int, + @SerialName("content") + val content: String + ) + + fun toRoutine() = routines.map { + Routine( + routineId = it.routineId, + content = it.content + ) + } +} diff --git a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt index 97bbbcab..c4e55eff 100644 --- a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt +++ b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt @@ -38,7 +38,9 @@ class DailyRoutineRepositoryImpl @Inject constructor( } override suspend fun postAddDailyRoutine(routineId: Int): Result = - runCatching { dailyRoutineDataSource.postAddDailyRoutine(routineId) }.map { response -> - response.toAddDailyRoutine() + runCatching { + dailyRoutineDataSource.postAddDailyRoutine(routineId) + }.map { response -> + requireNotNull(response.data).toAddDailyRoutine() } } diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt index b47bdeb1..de4832db 100644 --- a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -1,8 +1,9 @@ package com.sopetit.softie.data.service import com.sopetit.softie.data.entity.BaseResponse -import com.sopetit.softie.data.entity.request.AddDailyRoutineRequest import com.sopetit.softie.data.entity.response.AchieveDailyResponse +import com.sopetit.softie.data.entity.response.AddDailyRoutineResponse +import com.sopetit.softie.data.entity.response.DailyCardResponse import com.sopetit.softie.data.entity.response.DailyRoutineListResponse import com.sopetit.softie.data.entity.response.DailyRoutineResponse import com.sopetit.softie.data.entity.response.ThemeListResponse @@ -33,5 +34,8 @@ interface DailyRoutineService { suspend fun deleteDailyRoutine(@Path("routineId") routineId: Int): BaseResponse @POST("api/v1/routines/daily/member") - suspend fun postAddDailyRoutine(@Body routineId: Int): AddDailyRoutineRequest + suspend fun postAddDailyRoutine(@Body routineId: Int): BaseResponse + + @GET("api/v1/routines/daily/theme/{themeId}") + suspend fun getDailyCardList(@Path("themeId") themeId: Int): BaseResponse } diff --git a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt index 58916665..bda23876 100644 --- a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt +++ b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt @@ -1,8 +1,8 @@ package com.sopetit.softie.data.source import com.sopetit.softie.data.entity.BaseResponse -import com.sopetit.softie.data.entity.request.AddDailyRoutineRequest import com.sopetit.softie.data.entity.response.AchieveDailyResponse +import com.sopetit.softie.data.entity.response.AddDailyRoutineResponse import com.sopetit.softie.data.entity.response.DailyRoutineListResponse import com.sopetit.softie.data.entity.response.DailyRoutineResponse import com.sopetit.softie.data.entity.response.ThemeListResponse @@ -26,6 +26,6 @@ class DailyRoutineDataSource @Inject constructor( suspend fun getRoutineList(themeId: List): BaseResponse = dailyRoutineService.getRoutineList(themeId) - suspend fun postAddDailyRoutine(routineId: Int): AddDailyRoutineRequest = + suspend fun postAddDailyRoutine(routineId: Int): BaseResponse = dailyRoutineService.postAddDailyRoutine(routineId) } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index 3a0f3908..b05a4ee2 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -13,7 +13,7 @@ import com.sopetit.softie.databinding.FragmentDailyRoutineBinding import com.sopetit.softie.domain.entity.Bear import com.sopetit.softie.ui.dailyroutine.dailyroutineadd.DailyRoutineAddActivity import com.sopetit.softie.util.OriginalBottomSheet.Companion.BOTTOM_SHEET_TAG -import com.sopetit.softie.util.binding.BindingAdapter.setImage +import com.sopetit.softie.util.binding.BindingAdapter.setCoilImage import com.sopetit.softie.util.binding.BindingBottomSheet import com.sopetit.softie.util.binding.BindingFragment import com.sopetit.softie.util.setStatusBarColor @@ -84,15 +84,21 @@ class DailyRoutineFragment : index: Int ) { viewModel.dailyRoutineListResponse.observe(viewLifecycleOwner) { dailyRoutineList -> - val achieveCountMsg = - getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) - achieveMsg.text = achieveCountMsg - routineTitle.text = dailyRoutineList[index].content -// dailyIcon.load(dailyRoutineList[index].iconImageUrl) - dailyIcon.setImage(dailyRoutineList[index].iconImageUrl) - viewModel.setRoutineAchieve(dailyRoutineList[index].isAchieve, index) + if (dailyRoutineList.isNotEmpty()) { + val achieveCountMsg = + getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) + achieveMsg.text = achieveCountMsg + routineTitle.text = dailyRoutineList[index].content + dailyIcon.setCoilImage(dailyRoutineList[index].iconImageUrl) + viewModel.setRoutineAchieve(dailyRoutineList[index].isAchieve, index) - initSetDailyRoutineAchieve(btn, dailyRoutineList[index].routineId) + initSetDailyRoutineAchieve(btn, dailyRoutineList[index].routineId) + + } else { + binding.clDailyRoutineFirst.visibility = View.GONE + binding.clDailyRoutineSecond.visibility = View.GONE + binding.clDailyRoutineThird.visibility = View.GONE + } } } @@ -245,4 +251,18 @@ class DailyRoutineFragment : startActivity(intent) } } + +// private fun addRoutine() { +// val intent = Intent() +// val routineId = intent.getIntExtra(HappyAddListActivity.ID, -1) +// val viewModel = ViewModelProvider(this).get(DailyRoutineViewModel::class.java) +// val dailyCard = viewModel.userDaily.value?.get(routineId - 1) +// +// dailyCard?.let { +// with(binding) { +// tvDailyRoutineAddNameFirst.text = dailyCard.content +// ivDailyRoutineIconFirst.setImageResource(dailyCard.iconImageUrl) +// } +// } +// } } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index d63b260a..fb00270d 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.sopetit.softie.domain.entity.DailyRoutine +import com.sopetit.softie.domain.entity.UserDailyRoutine import com.sopetit.softie.domain.usecase.DeleteDailyRoutineUseCase import com.sopetit.softie.domain.usecase.GetDailyRoutineUseCase import com.sopetit.softie.domain.usecase.PatchAchieveDailyUseCase @@ -29,9 +30,11 @@ class DailyRoutineViewModel @Inject constructor( getDailyRoutineUseCase() .onSuccess { response -> _dailyRoutineListResponse.value = response + Timber.d("유저 데일리 성공") } .onFailure { throwable -> Timber.e("$throwable") + Timber.d("유저 데일리 실패") } } } @@ -60,7 +63,7 @@ class DailyRoutineViewModel @Inject constructor( } } - fun routineAchieve(routineId: Int, isAchieve: Boolean) { + private fun routineAchieve(routineId: Int, isAchieve: Boolean) { when (routineId) { dailyRoutineListResponse.value?.get(0)?.routineId -> setRoutineAchieve(isAchieve, 0) dailyRoutineListResponse.value?.get(1)?.routineId -> setRoutineAchieve(isAchieve, 1) @@ -129,4 +132,8 @@ class DailyRoutineViewModel @Inject constructor( fun setEditBtnEnabled(enabled: Boolean) { _isEditBtnEnabled.value = enabled } + + private val _userDaily: LiveData = MutableLiveData() + val userDaily: LiveData + get() = _userDaily } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt index a77968c2..85aaa53a 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt @@ -11,6 +11,7 @@ import androidx.viewpager2.widget.CompositePageTransformer import androidx.viewpager2.widget.MarginPageTransformer import androidx.viewpager2.widget.ViewPager2 import com.sopetit.softie.R +import com.sopetit.softie.data.entity.request.AddDailyRoutineRequest import com.sopetit.softie.databinding.ActivityDailyRoutineAddBinding import com.sopetit.softie.domain.entity.Theme import com.sopetit.softie.ui.main.MainActivity @@ -18,7 +19,9 @@ import com.sopetit.softie.util.OriginalBottomSheet import com.sopetit.softie.util.binding.BindingActivity import com.sopetit.softie.util.binding.BindingBottomSheet import com.sopetit.softie.util.setStatusBarColorFromResource +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class DailyRoutineAddActivity : BindingActivity(R.layout.activity_daily_routine_add) { private lateinit var viewPager: ViewPager2 @@ -30,9 +33,13 @@ class DailyRoutineAddActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) viewPager = binding.vpDailyRoutineAddCard + binding.viewModel = dailyRoutineAddViewModel setStatusBarColorFromResource(R.color.background) + val request = AddDailyRoutineRequest(routineId = 1) + initSetDailyRoutineAdd(request) + setupAdapter() setViewPager() setupList() @@ -40,11 +47,9 @@ class DailyRoutineAddActivity : setItemDiv() initPagerDiv(0, 90) addClickListener() - initSetDailyRoutineAdd() } private fun addClickListener() { - addRoutine() backToDailyRoutine() } @@ -146,22 +151,14 @@ class DailyRoutineAddActivity : binding.rvDailyRoutineAddTheme.addItemDecoration(HorizontalItemDecorator(16)) } - private fun addRoutine() { - binding.btnDailyRoutineAdd.setOnClickListener { - finish() - } - } - private fun backToDailyRoutine() { binding.ivDailyRoutineAddBack.setOnClickListener { finish() } } - private fun initSetDailyRoutineAdd() { + private fun initSetDailyRoutineAdd(request: AddDailyRoutineRequest) { binding.btnDailyRoutineAdd.setOnClickListener { - // TODO 서버통신 구현 후 imageUri 버전으로 수정 - BindingBottomSheet.Builder().build( isDrawable = false, imageDrawable = 0, @@ -176,20 +173,30 @@ class DailyRoutineAddActivity : backBtnAction = {}, doBtnAction = { tossMsg() + dailyRoutineAddViewModel.postAddDailyRoutine(request.routineId) } ).show(supportFragmentManager, OriginalBottomSheet.BOTTOM_SHEET_TAG) } } + private fun tossMsg() { val resultIntent = Intent(this, MainActivity::class.java) setResult(Activity.RESULT_OK, resultIntent) finish() } +// private fun moveToDailyRoutine(id: Int) { +// Intent(this, MainActivity::class.java).apply { +// putExtra(ID, id) +// startActivity(this) +// } +// } + companion object { const val VIEW_PAGE = 3 const val PADDING_PAGE = 40 const val PADDING_CARD = 0 + const val ID = "id" } } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt index 5fd3feb8..a01e754f 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt @@ -3,11 +3,20 @@ package com.sopetit.softie.ui.dailyroutine.dailyroutineadd import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.sopetit.softie.domain.entity.AddRoutine import com.sopetit.softie.domain.entity.DailyCard import com.sopetit.softie.domain.entity.DailyRoutineAdd import com.sopetit.softie.domain.entity.Theme +import com.sopetit.softie.domain.usecase.PostAddDailyRoutineUseCase +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import timber.log.Timber +import javax.inject.Inject -class DailyRoutineAddViewModel : ViewModel() { +@HiltViewModel +class DailyRoutineAddViewModel @Inject constructor(private val postAddDailyRoutineUseCase: PostAddDailyRoutineUseCase) : + ViewModel() { private val _mockThemeList: MutableLiveData> = MutableLiveData( mutableListOf( Theme( @@ -539,10 +548,32 @@ class DailyRoutineAddViewModel : ViewModel() { ) ) + private val themeDailyRoutineList: LiveData> get() = _themeDailyRoutineList fun getDailyCardListForId(themeId: Int): List { return themeDailyRoutineList.value?.filter { it.themeId == themeId } ?: emptyList() } + + private val _addDailyRoutine: MutableLiveData = MutableLiveData() + val addDailyRoutine: LiveData + get() = _addDailyRoutine + + fun postAddDailyRoutine(routineId: Int) { + viewModelScope.launch { + postAddDailyRoutineUseCase.invoke(routineId) + .onSuccess { response -> + _addDailyRoutine.value = response + Timber.d("추가 성공") + } + .onFailure { throwable -> + Timber.e("$throwable") + Timber.d("추가 실패") + } + + } + } + + } diff --git a/app/src/main/res/layout/fragment_daily_routine.xml b/app/src/main/res/layout/fragment_daily_routine.xml index 26bcfbc1..c4a6fd3b 100644 --- a/app/src/main/res/layout/fragment_daily_routine.xml +++ b/app/src/main/res/layout/fragment_daily_routine.xml @@ -97,8 +97,8 @@ Date: Thu, 18 Jan 2024 02:20:16 +0900 Subject: [PATCH 35/37] =?UTF-8?q?#66=20[chore]=20=EB=8D=B0=EC=9D=BC?= =?UTF-8?q?=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95,=20=EB=A3=A8=ED=8B=B4id=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=A3=A8=ED=8B=B4=20list=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=EC=82=AD=EC=A0=9C=EC=8B=9C=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20get=ED=95=B4=EC=84=9C=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DailyRoutineRepositoryImpl.kt | 4 +- .../data/service/DailyRoutineService.kt | 2 +- .../data/source/DailyRoutineDataSource.kt | 4 +- .../repository/DailyRoutineRepository.kt | 2 +- .../usecase/DeleteDailyRoutineUseCase.kt | 4 +- .../ui/dailyroutine/DailyRoutineFragment.kt | 71 ++++++++----------- .../ui/dailyroutine/DailyRoutineViewModel.kt | 23 ++---- .../DailyRoutineAddActivity.kt | 6 -- 8 files changed, 45 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt index c4e55eff..ad5641f6 100644 --- a/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt +++ b/app/src/main/java/com/sopetit/softie/data/repositoryImpl/DailyRoutineRepositoryImpl.kt @@ -22,8 +22,8 @@ class DailyRoutineRepositoryImpl @Inject constructor( requireNotNull(response.data).toAchieveDaily() } - override suspend fun deleteDailyRoutine(routineId: Int): Result = - runCatching { dailyRoutineDataSource.deleteDailyRoutine(routineId) } + override suspend fun deleteDailyRoutine(routineIdList: List): Result = + runCatching { dailyRoutineDataSource.deleteDailyRoutine(routineIdList) } override suspend fun getTheme(): Result> = runCatching { dailyRoutineDataSource.getTheme() diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt index de4832db..035d35f6 100644 --- a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -31,7 +31,7 @@ interface DailyRoutineService { suspend fun patchAchieveDaily(@Path("routineId") routineId: Int): BaseResponse @DELETE("api/v1/routines/daily/member/routine/{routineId}") - suspend fun deleteDailyRoutine(@Path("routineId") routineId: Int): BaseResponse + suspend fun deleteDailyRoutine(@Query("routineId") routineIdList: List): BaseResponse @POST("api/v1/routines/daily/member") suspend fun postAddDailyRoutine(@Body routineId: Int): BaseResponse diff --git a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt index bda23876..25642a70 100644 --- a/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt +++ b/app/src/main/java/com/sopetit/softie/data/source/DailyRoutineDataSource.kt @@ -18,8 +18,8 @@ class DailyRoutineDataSource @Inject constructor( suspend fun patchAchieveDaily(routineId: Int): BaseResponse = dailyRoutineService.patchAchieveDaily(routineId) - suspend fun deleteDailyRoutine(routineId: Int): BaseResponse = - dailyRoutineService.deleteDailyRoutine(routineId) + suspend fun deleteDailyRoutine(routineIdList: List): BaseResponse = + dailyRoutineService.deleteDailyRoutine(routineIdList) suspend fun getTheme(): BaseResponse = dailyRoutineService.getTheme() diff --git a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt index 81af3dbe..f731db79 100644 --- a/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt +++ b/app/src/main/java/com/sopetit/softie/domain/repository/DailyRoutineRepository.kt @@ -9,7 +9,7 @@ import com.sopetit.softie.domain.entity.Theme interface DailyRoutineRepository { suspend fun getDailyRoutine(): Result> suspend fun patchAchieveDaily(routineId: Int): Result - suspend fun deleteDailyRoutine(routineId: Int): Result + suspend fun deleteDailyRoutine(routineIdList: List): Result suspend fun getTheme(): Result> suspend fun getRoutineList(themeId: List): Result> diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt index d6310fcb..86f88fce 100644 --- a/app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/DeleteDailyRoutineUseCase.kt @@ -6,6 +6,6 @@ import javax.inject.Inject class DeleteDailyRoutineUseCase @Inject constructor( private val deleteDailyRoutine: DailyRoutineRepository ) { - suspend operator fun invoke(routineId: Int) = - deleteDailyRoutine.deleteDailyRoutine(routineId) + suspend operator fun invoke(routineIdList: List) = + deleteDailyRoutine.deleteDailyRoutine(routineIdList) } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index b05a4ee2..e4e30ca3 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -39,9 +39,16 @@ class DailyRoutineFragment : getBundle() initSetDailyRoutineContent() initSetDeleteView() - initSetRoutineDelete(0) + initSetRoutineDelete() addDailyRoutineMsg() achieveRoutine() + updateDailyRoutine() + } + + private fun updateDailyRoutine() { + viewModel.isDailyRoutineDelete.observe(viewLifecycleOwner) { + if (viewModel.isDailyRoutineDelete.value == true) viewModel.getDailyRoutine() + } } private fun getBundle() { @@ -190,33 +197,29 @@ class DailyRoutineFragment : binding.btnDailyRoutineDelete.text = deleteBtnContent } - private fun initSetRoutineDelete(routineId: Int) { - viewModel.isEditBtnEnabled.observe(viewLifecycleOwner) { isBtnEnabled -> - if (isBtnEnabled) { - binding.btnDailyRoutineDelete.setOnClickListener { - BindingBottomSheet.Builder().build( - isDrawable = true, - imageDrawable = R.drawable.ic_bear_face_crying, - imageUri = "", - title = "정말 삭제할까요?", - content = "루틴을 삭제해도 달성 횟수는 저장돼요", - isContentVisible = true, - contentColor = R.color.red, - backBtnContent = "취소", - doBtnContent = "삭제할래", - doBtnColor = R.drawable.shape_red_fill_12_rect, - backBtnAction = {}, - doBtnAction = { - snackBar( - binding.root.rootView, - "데일리 루틴을 ${viewModel.editRoutineIdArray.size}개 삭제했어요" - ) - viewModel.setDeleteView(false) - viewModel.deleteDailyRoutine(routineId) - } - ).show(parentFragmentManager, BOTTOM_SHEET_TAG) + private fun initSetRoutineDelete() { + binding.btnDailyRoutineDelete.setOnClickListener { + BindingBottomSheet.Builder().build( + isDrawable = true, + imageDrawable = R.drawable.ic_bear_face_crying, + imageUri = "", + title = "정말 삭제할까요?", + content = "루틴을 삭제해도 달성 횟수는 저장돼요", + isContentVisible = true, + contentColor = R.color.red, + backBtnContent = "취소", + doBtnContent = "삭제할래", + doBtnColor = R.drawable.shape_red_fill_12_rect, + backBtnAction = {}, + doBtnAction = { + snackBar( + binding.root.rootView, + "데일리 루틴을 ${viewModel.editRoutineIdArray.size}개 삭제했어요" + ) + viewModel.setDeleteView(false) + viewModel.deleteDailyRoutine() } - } + ).show(parentFragmentManager, BOTTOM_SHEET_TAG) } } @@ -251,18 +254,4 @@ class DailyRoutineFragment : startActivity(intent) } } - -// private fun addRoutine() { -// val intent = Intent() -// val routineId = intent.getIntExtra(HappyAddListActivity.ID, -1) -// val viewModel = ViewModelProvider(this).get(DailyRoutineViewModel::class.java) -// val dailyCard = viewModel.userDaily.value?.get(routineId - 1) -// -// dailyCard?.let { -// with(binding) { -// tvDailyRoutineAddNameFirst.text = dailyCard.content -// ivDailyRoutineIconFirst.setImageResource(dailyCard.iconImageUrl) -// } -// } -// } } diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt index fb00270d..67808b7a 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt @@ -51,11 +51,15 @@ class DailyRoutineViewModel @Inject constructor( val isRoutineAchieveThird: LiveData get() = _isRoutineAchieveThird + private val _isDailyRoutineDelete: MutableLiveData = MutableLiveData(false) + val isDailyRoutineDelete: LiveData get() = _isDailyRoutineDelete + fun patchAchieveDaily(routineId: Int) { viewModelScope.launch { patchAchieveDailyUseCase(routineId) .onSuccess { response -> routineAchieve(routineId, response.isAchieve) + _isDailyRoutineDelete.value = false } .onFailure { throwable -> Timber.e("$throwable") @@ -75,20 +79,6 @@ class DailyRoutineViewModel @Inject constructor( val isDeleteView: LiveData get() = _isDeleteView -// fun deleteDailyRoutine(routineId: Int) { -// viewModelScope.launch { -// deleteDailyRoutineUseCase(routineId) -// .onSuccess { -// _isDeleteView.value = true -// Timber.d("삭제 서버 성공") -// } -// .onFailure { throwable -> -// Timber.d("삭제 서버 실패") -// Timber.e("$throwable") -// } -// } -// } - val editRoutineIdArray = ArrayList() private val _isEditBtnEnabled: MutableLiveData = MutableLiveData() @@ -107,12 +97,13 @@ class DailyRoutineViewModel @Inject constructor( _isDeleteView.value = deleteEnabled } - fun deleteDailyRoutine(routineId: Int) { + fun deleteDailyRoutine() { viewModelScope.launch { - deleteDailyRoutineUseCase(routineId) + deleteDailyRoutineUseCase(editRoutineIdArray) .onSuccess { setDeleteView(deleteEnabled = false) Timber.d("삭제 서버 성공") + _isDailyRoutineDelete.value = true } .onFailure { throwable -> Timber.d("삭제 서버 실패") diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt index 85aaa53a..5616d253 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt @@ -186,12 +186,6 @@ class DailyRoutineAddActivity : finish() } -// private fun moveToDailyRoutine(id: Int) { -// Intent(this, MainActivity::class.java).apply { -// putExtra(ID, id) -// startActivity(this) -// } -// } companion object { const val VIEW_PAGE = 3 From ccc385821cdd3ddd3f464a89ede50a4867aa81e7 Mon Sep 17 00:00:00 2001 From: heominhoe Date: Thu, 18 Jan 2024 05:29:55 +0900 Subject: [PATCH 36/37] =?UTF-8?q?#66=20[chore]=20=EB=8D=B0=EC=9D=BC?= =?UTF-8?q?=EB=A6=AC=20=EB=A3=A8=ED=8B=B4=20=EC=82=AD=EC=A0=9C=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=EC=97=B0=EA=B2=B0=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/service/DailyRoutineService.kt | 4 +- .../ui/dailyroutine/DailyRoutineFragment.kt | 104 ++++++++++++------ 2 files changed, 72 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt index 035d35f6..27172de8 100644 --- a/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt +++ b/app/src/main/java/com/sopetit/softie/data/service/DailyRoutineService.kt @@ -30,8 +30,8 @@ interface DailyRoutineService { @PATCH("api/v1/routines/daily/member/routine/{routineId}") suspend fun patchAchieveDaily(@Path("routineId") routineId: Int): BaseResponse - @DELETE("api/v1/routines/daily/member/routine/{routineId}") - suspend fun deleteDailyRoutine(@Query("routineId") routineIdList: List): BaseResponse + @DELETE("api/v1/routines/daily/member") + suspend fun deleteDailyRoutine(@Query("routines") routineIdList: List): BaseResponse @POST("api/v1/routines/daily/member") suspend fun postAddDailyRoutine(@Body routineId: Int): BaseResponse diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt index e4e30ca3..5b7de322 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt @@ -42,13 +42,6 @@ class DailyRoutineFragment : initSetRoutineDelete() addDailyRoutineMsg() achieveRoutine() - updateDailyRoutine() - } - - private fun updateDailyRoutine() { - viewModel.isDailyRoutineDelete.observe(viewLifecycleOwner) { - if (viewModel.isDailyRoutineDelete.value == true) viewModel.getDailyRoutine() - } } private fun getBundle() { @@ -58,6 +51,27 @@ class DailyRoutineFragment : } private fun initSetDailyRoutineContent() { + viewModel.dailyRoutineListResponse.observe(viewLifecycleOwner) { dailyRoutineList -> + when (dailyRoutineList.size) { + 3 -> { + makeRoutineItemThirdView() + makeRoutineItemSecondView() + makeRoutineItemFirstView() + } + + 2 -> { + makeRoutineItemFirstView() + makeRoutineItemSecondView() + } + + 1 -> { + makeRoutineItemFirstView() + } + } + } + } + + private fun makeRoutineItemFirstView() { with(binding) { routineItemView( ivDailyRoutineIconFirst, @@ -66,6 +80,11 @@ class DailyRoutineFragment : btnDailyRoutineYetFinFirst, 0 ) + } + } + + private fun makeRoutineItemSecondView() { + with(binding) { routineItemView( ivDailyRoutineIconSecond, tvDailyRoutineAddNameSecond, @@ -73,6 +92,11 @@ class DailyRoutineFragment : btnDailyRoutineYetFinSecond, 1 ) + } + } + + private fun makeRoutineItemThirdView() { + with(binding) { routineItemView( ivDailyRoutineIconThird, tvDailyRoutineAddNameThird, @@ -90,23 +114,16 @@ class DailyRoutineFragment : btn: View, index: Int ) { - viewModel.dailyRoutineListResponse.observe(viewLifecycleOwner) { dailyRoutineList -> - if (dailyRoutineList.isNotEmpty()) { - val achieveCountMsg = - getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) - achieveMsg.text = achieveCountMsg - routineTitle.text = dailyRoutineList[index].content - dailyIcon.setCoilImage(dailyRoutineList[index].iconImageUrl) - viewModel.setRoutineAchieve(dailyRoutineList[index].isAchieve, index) - - initSetDailyRoutineAchieve(btn, dailyRoutineList[index].routineId) - - } else { - binding.clDailyRoutineFirst.visibility = View.GONE - binding.clDailyRoutineSecond.visibility = View.GONE - binding.clDailyRoutineThird.visibility = View.GONE - } - } + val dailyRoutine = viewModel.dailyRoutineListResponse.value + + val achieveCountMsg = + getString(R.string.daily_routine_ing).format(dailyRoutine?.get(index)?.achieveCount) + achieveMsg.text = achieveCountMsg + routineTitle.text = dailyRoutine?.get(index)?.content + dailyIcon.setCoilImage(dailyRoutine?.get(index)?.iconImageUrl) + viewModel.setRoutineAchieve(dailyRoutine?.get(index)?.isAchieve ?: false, index) + + initSetDailyRoutineAchieve(btn, dailyRoutine?.get(index)?.routineId ?: 0) } private fun achieveRoutine() { @@ -165,12 +182,28 @@ class DailyRoutineFragment : } private fun clickEditRadioBtn() { - viewModel.getDailyRoutine() viewModel.dailyRoutineListResponse.observe(viewLifecycleOwner) { routineList -> - with(binding) { - changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) - changeBtnSelectState(btnDailyRoutineRadioSecond, routineList[1].routineId) - changeBtnSelectState(btnDailyRoutineRadioThird, routineList[2].routineId) + when (routineList.size) { + 3 -> { + with(binding) { + changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) + changeBtnSelectState(btnDailyRoutineRadioSecond, routineList[1].routineId) + changeBtnSelectState(btnDailyRoutineRadioThird, routineList[2].routineId) + } + } + + 2 -> { + with(binding) { + changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) + changeBtnSelectState(btnDailyRoutineRadioSecond, routineList[1].routineId) + } + } + + 1 -> { + with(binding) { + changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) + } + } } } } @@ -212,12 +245,15 @@ class DailyRoutineFragment : doBtnColor = R.drawable.shape_red_fill_12_rect, backBtnAction = {}, doBtnAction = { - snackBar( - binding.root.rootView, - "데일리 루틴을 ${viewModel.editRoutineIdArray.size}개 삭제했어요" - ) - viewModel.setDeleteView(false) viewModel.deleteDailyRoutine() + viewModel.isDailyRoutineDelete.observe(viewLifecycleOwner) { + snackBar( + binding.root.rootView, + "데일리 루틴을 ${viewModel.editRoutineIdArray.size}개 삭제했어요" + ) + viewModel.setDeleteView(false) + viewModel.getDailyRoutine() + } } ).show(parentFragmentManager, BOTTOM_SHEET_TAG) } From 77a8fe5eea5fc803644e74fd8d27e0d3f20fa0cf Mon Sep 17 00:00:00 2001 From: heominhoe Date: Thu, 18 Jan 2024 05:37:36 +0900 Subject: [PATCH 37/37] =?UTF-8?q?#66=20[chore]=20ci=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt | 1 - .../dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt | 2 -- .../dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt | 4 ---- 3 files changed, 7 deletions(-) diff --git a/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt b/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt index fe85bae3..b5cc6c88 100644 --- a/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt +++ b/app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt @@ -33,7 +33,6 @@ abstract class RepositoryModule { dailyRoutineRepositoryImpl: DailyRoutineRepositoryImpl ): DailyRoutineRepository - @Binds @Singleton abstract fun bindToDollRepository( diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt index 5616d253..3fb478a9 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt @@ -179,14 +179,12 @@ class DailyRoutineAddActivity : } } - private fun tossMsg() { val resultIntent = Intent(this, MainActivity::class.java) setResult(Activity.RESULT_OK, resultIntent) finish() } - companion object { const val VIEW_PAGE = 3 const val PADDING_PAGE = 40 diff --git a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt index a01e754f..10fc57bf 100644 --- a/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddViewModel.kt @@ -548,7 +548,6 @@ class DailyRoutineAddViewModel @Inject constructor(private val postAddDailyRouti ) ) - private val themeDailyRoutineList: LiveData> get() = _themeDailyRoutineList @@ -571,9 +570,6 @@ class DailyRoutineAddViewModel @Inject constructor(private val postAddDailyRouti Timber.e("$throwable") Timber.d("추가 실패") } - } } - - }