diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseMyPuzzleBoardDto.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseMyPuzzleBoardDto.kt index bc33a3a9..5ea0b698 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseMyPuzzleBoardDto.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseMyPuzzleBoardDto.kt @@ -21,6 +21,8 @@ data class ResponseMyPuzzleBoardDto( val myPuzzle: MyPuzzle, @SerialName("userPuzzleBoard") val userPuzzleBoard: List, + @SerialName("puzzleBoardCount") + val puzzleBoardCount: Int, @SerialName("isReviewDay") val isReviewDay: Boolean, @SerialName("hasTodayReview") diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseReviewTypeDto.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseReviewTypeDto.kt index ec3f51e3..ebddefe1 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseReviewTypeDto.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/model/response/ResponseReviewTypeDto.kt @@ -1,5 +1,6 @@ package com.puzzling.puzzlingaos.data.model.response +import com.puzzling.puzzlingaos.domain.entity.ReviewType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -20,7 +21,15 @@ data class ResponseReviewTypeDto( val reviewTemplateId: Int, @SerialName("reviewTemplateName") val reviewTemplateName: String, - @SerialName("reviewTempalteMeaning") - val reviewTempalteMeaning: Int, + @SerialName("reviewTemplateMeaning") + val reviewTemplateMeaning: String, ) + + fun toReviewType() = data.map { type -> + ReviewType( + reviewTemplateId = type.reviewTemplateId, + reviewTemplateName = type.reviewTemplateName, + reviewTemplateMeaning = type.reviewTemplateMeaning, + ) + } } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/repository/WriteReviewRepositoryImpl.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/repository/WriteReviewRepositoryImpl.kt new file mode 100644 index 00000000..19ce8a6f --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/repository/WriteReviewRepositoryImpl.kt @@ -0,0 +1,64 @@ +package com.puzzling.puzzlingaos.data.repository + +import com.puzzling.puzzlingaos.data.model.request.RequestReview5FDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewAARDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewTILDto +import com.puzzling.puzzlingaos.data.model.response.ResponsePreviousTemplateDto +import com.puzzling.puzzlingaos.data.model.response.ResponseSaveReviewDto +import com.puzzling.puzzlingaos.data.source.remote.WriteReviewDataSource +import com.puzzling.puzzlingaos.domain.entity.ReviewType +import com.puzzling.puzzlingaos.domain.repository.WriteReviewRepository +import javax.inject.Inject + +class WriteReviewRepositoryImpl @Inject constructor( + private val writeReviewDataSource: WriteReviewDataSource, +) : WriteReviewRepository { + override suspend fun getReviewType(): Result> = runCatching { + writeReviewDataSource.getReviewTemplate().toReviewType() + } + + override suspend fun uploadTIL( + memberId: Int, + projectId: Int, + requestReviewTIL: RequestReviewTILDto, + + ): Result = runCatching { + writeReviewDataSource.uploadReviewTIL( + memberId, + projectId, + requestReviewTIL, + ) + } + + override suspend fun upload5F( + memberId: Int, + projectId: Int, + requestReview5F: RequestReview5FDto, + ): Result = runCatching { + writeReviewDataSource.uploadReview5F( + memberId, + projectId, + requestReview5F, + ) + } + + override suspend fun uploadAAR( + memberId: Int, + projectId: Int, + requestReviewAAR: RequestReviewAARDto, + ): Result = runCatching { + writeReviewDataSource.uploadReviewAAR( + memberId, + projectId, + requestReviewAAR, + ) + } + + override suspend fun getPreviousTemplate( + memberId: Int, + projectId: Int, + ): Result = + runCatching { + writeReviewDataSource.getPreviousTemplate(memberId, projectId) + } +} diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/service/WriteReviewService.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/service/WriteReviewService.kt index 6d504016..76382d33 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/data/service/WriteReviewService.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/service/WriteReviewService.kt @@ -45,7 +45,7 @@ interface WriteReviewService { [회고 글 작성 API(ARR)] ~/api/v1/member/{memberId}/project/{projectId}/review/ARR */ - @POST("api/v1/member/{memberId}/project/{projectId}/review/ARR") + @POST("api/v1/member/{memberId}/project/{projectId}/review/AAR") suspend fun postSaveReviewAAR( @Path("memberId") memberId: Int, @Path("projectId") projectId: Int, diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/source/remote/WriteReviewDataSource.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/source/remote/WriteReviewDataSource.kt index f1cfbc1b..58cc5a36 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/data/source/remote/WriteReviewDataSource.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/source/remote/WriteReviewDataSource.kt @@ -5,6 +5,7 @@ import com.puzzling.puzzlingaos.data.model.request.RequestReviewAARDto import com.puzzling.puzzlingaos.data.model.request.RequestReviewTILDto import com.puzzling.puzzlingaos.data.model.response.ResponsePreviousTemplateDto import com.puzzling.puzzlingaos.data.model.response.ResponseReviewTypeDto +import com.puzzling.puzzlingaos.data.model.response.ResponseSaveReviewDto interface WriteReviewDataSource { suspend fun getReviewTemplate(): ResponseReviewTypeDto @@ -13,19 +14,21 @@ interface WriteReviewDataSource { memberId: Int, projectId: Int, requestReviewTIL: RequestReviewTILDto, - ): RequestReviewTILDto +// requestTIL: TIL, + + ): ResponseSaveReviewDto suspend fun uploadReview5F( memberId: Int, projectId: Int, requestReview5F: RequestReview5FDto, - ): RequestReview5FDto + ): ResponseSaveReviewDto suspend fun uploadReviewAAR( memberId: Int, projectId: Int, requestReviewAAR: RequestReviewAARDto, - ): RequestReviewAARDto + ): ResponseSaveReviewDto suspend fun getPreviousTemplate( memberId: Int, diff --git a/app/src/main/java/com/puzzling/puzzlingaos/data/source/remote/impl/WriteReviewDataSourceImpl.kt b/app/src/main/java/com/puzzling/puzzlingaos/data/source/remote/impl/WriteReviewDataSourceImpl.kt new file mode 100644 index 00000000..ce187bca --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/data/source/remote/impl/WriteReviewDataSourceImpl.kt @@ -0,0 +1,47 @@ +package com.puzzling.puzzlingaos.data.source.remote.impl + +import com.puzzling.puzzlingaos.data.model.request.RequestReview5FDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewAARDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewTILDto +import com.puzzling.puzzlingaos.data.model.response.ResponsePreviousTemplateDto +import com.puzzling.puzzlingaos.data.model.response.ResponseReviewTypeDto +import com.puzzling.puzzlingaos.data.model.response.ResponseSaveReviewDto +import com.puzzling.puzzlingaos.data.service.WriteReviewService +import com.puzzling.puzzlingaos.data.source.remote.WriteReviewDataSource +import javax.inject.Inject + +class WriteReviewDataSourceImpl @Inject constructor( + private val apiService: WriteReviewService, +) : WriteReviewDataSource { + override suspend fun getReviewTemplate(): ResponseReviewTypeDto = + apiService.getReviewTemplate() + + override suspend fun uploadReviewTIL( + memberId: Int, + projectId: Int, + requestReviewTIL: RequestReviewTILDto, + ): ResponseSaveReviewDto = + apiService.postSaveReviewTIL(memberId, projectId, requestReviewTIL) + + override suspend fun uploadReview5F( + memberId: Int, + projectId: Int, + requestReview5F: RequestReview5FDto, + ): ResponseSaveReviewDto = + apiService.postSaveReview5F(memberId, projectId, requestReview5F) + + override suspend fun uploadReviewAAR( + memberId: Int, + projectId: Int, + requestReviewAAR: RequestReviewAARDto, + ): ResponseSaveReviewDto = + apiService.postSaveReviewAAR(memberId, projectId, requestReviewAAR) + + override suspend fun getPreviousTemplate( + memberId: Int, + projectId: Int, + ): ResponsePreviousTemplateDto = apiService.getPreviousTemplate( + memberId, + projectId, + ) +} diff --git a/app/src/main/java/com/puzzling/puzzlingaos/di/ApiModule.kt b/app/src/main/java/com/puzzling/puzzlingaos/di/ApiModule.kt index 8b790132..5db932ec 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/di/ApiModule.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/di/ApiModule.kt @@ -1,6 +1,7 @@ package com.puzzling.puzzlingaos.di import com.puzzling.puzzlingaos.data.service.PersonalReviewService +import com.puzzling.puzzlingaos.data.service.WriteReviewService import com.puzzling.puzzlingaos.data.service.ProjectService import dagger.Module import dagger.Provides @@ -17,6 +18,11 @@ object ApiModule { fun provideMyDashBoardService(@PuzzlingRetrofit retrofit: Retrofit): PersonalReviewService = retrofit.create(PersonalReviewService::class.java) + @Provides + @Singleton + fun provideWriteReviewService(@PuzzlingRetrofit retrofit: Retrofit): WriteReviewService = + retrofit.create(WriteReviewService::class.java) + @Provides @Singleton fun sendProjectRegister(@PuzzlingRetrofit retrofit: Retrofit): ProjectService = diff --git a/app/src/main/java/com/puzzling/puzzlingaos/di/DataSourceModule.kt b/app/src/main/java/com/puzzling/puzzlingaos/di/DataSourceModule.kt index 28b44543..999aa14c 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/di/DataSourceModule.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/di/DataSourceModule.kt @@ -2,8 +2,10 @@ package com.puzzling.puzzlingaos.di import com.puzzling.puzzlingaos.data.source.remote.MyDashBoardDataSource import com.puzzling.puzzlingaos.data.source.remote.ProjectDataSource +import com.puzzling.puzzlingaos.data.source.remote.WriteReviewDataSource import com.puzzling.puzzlingaos.data.source.remote.impl.MyDashBoardDataSourceImpl import com.puzzling.puzzlingaos.data.source.remote.impl.ProjectDataSourceImpl +import com.puzzling.puzzlingaos.data.source.remote.impl.WriteReviewDataSourceImpl import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -17,6 +19,10 @@ abstract class DataSourceModule { @Binds abstract fun providesPersonalReviewDataSource(DataSourceImpl: MyDashBoardDataSourceImpl): MyDashBoardDataSource + @Singleton + @Binds + abstract fun providesWriteReviewDataSource(DataSourceImpl: WriteReviewDataSourceImpl): WriteReviewDataSource + @Singleton @Binds abstract fun sendProjectRegisterDataSource(DataSourceImpl: ProjectDataSourceImpl): ProjectDataSource diff --git a/app/src/main/java/com/puzzling/puzzlingaos/di/RepositoryModule.kt b/app/src/main/java/com/puzzling/puzzlingaos/di/RepositoryModule.kt index 6f25599c..9682f396 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/di/RepositoryModule.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/di/RepositoryModule.kt @@ -2,8 +2,10 @@ package com.puzzling.puzzlingaos.di import com.puzzling.puzzlingaos.data.repository.MyBoardRepositoryImpl import com.puzzling.puzzlingaos.data.repository.ProjectRepositoryImpl +import com.puzzling.puzzlingaos.data.repository.WriteReviewRepositoryImpl import com.puzzling.puzzlingaos.domain.repository.MyBoardRepository import com.puzzling.puzzlingaos.domain.repository.ProjectRepository +import com.puzzling.puzzlingaos.domain.repository.WriteReviewRepository import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -17,6 +19,10 @@ abstract class RepositoryModule { @Binds abstract fun providesMyBoardRepository(repoImpl: MyBoardRepositoryImpl): MyBoardRepository + @Singleton + @Binds + abstract fun providesWriteReviewRepository(repoImpl: WriteReviewRepositoryImpl): WriteReviewRepository + @Singleton @Binds abstract fun sendProjectRepository(repoImpl: ProjectRepositoryImpl): ProjectRepository diff --git a/app/src/main/java/com/puzzling/puzzlingaos/di/RetrofitModule.kt b/app/src/main/java/com/puzzling/puzzlingaos/di/RetrofitModule.kt index 44df5e39..d67fddf1 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/di/RetrofitModule.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/di/RetrofitModule.kt @@ -67,8 +67,7 @@ object RetrofitModule { val builder = original.newBuilder() builder.addHeader( "Authorization", - "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2ODk2MTcyMTEsImV4cCI6MTY4OTk3NzIxMSwibWVtYmVySWQiOjJ9.w7II75HjzpXLVlBSRmcH5g5Q85oQ3KYq59KSlRvTV3w", - // "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2ODk2MzAyMjIsImV4cCI6MTY4OTk5MDIyMiwibWVtYmVySWQiOjF9.tR938XSLko7fuv8RduU6AL7dFs8JnzDNRS1OIfpFSC0", + "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2ODk3NTAxMTIsImV4cCI6MTY5MDExMDExMiwibWVtYmVySWQiOjJ9.cObREoCFGC8jgcBJjz0z7Bnb03KfP_Fzzup9Oge1tYA", ) chain.proceed(builder.build()) } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/AAR.kt b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/AAR.kt new file mode 100644 index 00000000..bcc50c7b --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/AAR.kt @@ -0,0 +1,10 @@ +package com.puzzling.puzzlingaos.domain.entity + +data class AAR( + val reviewTemplateId: Int, + val initialGoal: String, + val result: String, + val difference: String, + val persistence: String, + val actionPlan: String, +) diff --git a/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/F5.kt b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/F5.kt new file mode 100644 index 00000000..bbd6654e --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/F5.kt @@ -0,0 +1,11 @@ +package com.puzzling.puzzlingaos.domain.entity + +data class F5( + val reviewTemplateId: Int, + val fact: String, + val feeling: String, + val finding: String, + val feedback: String, + val actionPlan: String, + +) diff --git a/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/TIL.kt b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/TIL.kt new file mode 100644 index 00000000..0d4cb16e --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/domain/entity/TIL.kt @@ -0,0 +1,8 @@ +package com.puzzling.puzzlingaos.domain.entity + +data class TIL( + val reviewTemplateId: Int, + val liked: String, + val lacked: String, + val actionPlan: String, +) diff --git a/app/src/main/java/com/puzzling/puzzlingaos/domain/repository/WriteReviewRepository.kt b/app/src/main/java/com/puzzling/puzzlingaos/domain/repository/WriteReviewRepository.kt new file mode 100644 index 00000000..653615f3 --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/domain/repository/WriteReviewRepository.kt @@ -0,0 +1,35 @@ +package com.puzzling.puzzlingaos.domain.repository + +import com.puzzling.puzzlingaos.data.model.request.RequestReview5FDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewAARDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewTILDto +import com.puzzling.puzzlingaos.data.model.response.ResponsePreviousTemplateDto +import com.puzzling.puzzlingaos.data.model.response.ResponseSaveReviewDto +import com.puzzling.puzzlingaos.domain.entity.ReviewType + +interface WriteReviewRepository { + suspend fun getReviewType(): Result> + + suspend fun uploadTIL( + memberId: Int, + projectId: Int, + requestReviewTIL: RequestReviewTILDto, + ): Result + + suspend fun upload5F( + memberId: Int, + projectId: Int, + requestReview5F: RequestReview5FDto, + ): Result + + suspend fun uploadAAR( + memberId: Int, + projectId: Int, + requestReviewAAR: RequestReviewAARDto, + ): Result + + suspend fun getPreviousTemplate( + memberId: Int, + projectId: Int, + ): Result +} diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/HomeViewModel.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/HomeViewModel.kt index 6d87d819..bd0c7bc1 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/HomeViewModel.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/HomeViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.viewModelScope import com.puzzling.puzzlingaos.data.model.response.ResponseMyPageProjectDto import com.puzzling.puzzlingaos.domain.entity.Project import com.puzzling.puzzlingaos.domain.repository.MyBoardRepository +import com.puzzling.puzzlingaos.util.UserInfo import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject @@ -54,7 +55,7 @@ class HomeViewModel @Inject constructor( } private fun getProjectList() = viewModelScope.launch { - repository.getProceedingProject(1).onSuccess { response -> + repository.getProceedingProject(UserInfo.MEMBER_ID).onSuccess { response -> Log.d("home", "getProjectList() success:: $response") _projectList.value = response }.onFailure { diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardFragment.kt index e2e8c64e..147c4841 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardFragment.kt @@ -41,9 +41,20 @@ class PersonalDashboardFragment : private fun clickBottomBtn() { binding.clPersonalBottomBtn.setOnClickListener { - activity?.let { - val intent = Intent(context, WriteRetrospectiveActivity::class.java) - startActivity(intent) + when (viewModel.previousReviewType.value) { + 1 -> activity?.let { // TIL + val intent = Intent(context, WriteRetrospectiveActivity::class.java) + startActivity(intent) + } + 2 -> activity?.let { // 5F + val intent = Intent(context, WriteRetrospectiveActivity::class.java) + startActivity(intent) + } + 3 -> activity?.let { + // AAR + val intent = Intent(context, WriteRetrospectiveActivity::class.java) + startActivity(intent) + } } } } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardViewModel.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardViewModel.kt index abf8be18..c7242ea9 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardViewModel.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/home/personal/PersonalDashboardViewModel.kt @@ -9,6 +9,8 @@ import androidx.lifecycle.viewModelScope import com.puzzling.puzzlingaos.domain.entity.ActionPlan import com.puzzling.puzzlingaos.domain.entity.MyPuzzleBoard import com.puzzling.puzzlingaos.domain.repository.MyBoardRepository +import com.puzzling.puzzlingaos.domain.repository.WriteReviewRepository +import com.puzzling.puzzlingaos.util.UserInfo import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject @@ -16,6 +18,7 @@ import javax.inject.Inject @HiltViewModel class PersonalDashboardViewModel @Inject constructor( private val repository: MyBoardRepository, + private val writeReviewRepository: WriteReviewRepository, ) : ViewModel() { private val _myNickname = MutableLiveData() val myNickname: LiveData get() = _myNickname @@ -43,6 +46,10 @@ class PersonalDashboardViewModel @Inject constructor( val actionPlanList: LiveData> get() = _actionPlanList + private val _previousReviewType = MutableLiveData() + val previousReviewType: LiveData + get() = _previousReviewType + private val _isSuccess = MutableLiveData(false) val isSuccess: LiveData get() = _isSuccess @@ -51,6 +58,7 @@ class PersonalDashboardViewModel @Inject constructor( getMyPuzzleData() getActionPlan() getMyPuzzleBoard() + getPreviousTemplate() } private fun getMyPuzzleData() = viewModelScope.launch { @@ -72,7 +80,7 @@ class PersonalDashboardViewModel @Inject constructor( } private fun getMyPuzzleBoard() = viewModelScope.launch { - repository.getUserPuzzleBoard(1, 3, "2023-07-05") + repository.getUserPuzzleBoard(UserInfo.MEMBER_ID, UserInfo.PROJECT_ID, "2023-07-05") .onSuccess { response -> _myPuzzleBoardList.value = response Log.d("personal", "getMyPuzzleBoard() success:: $response") @@ -92,7 +100,7 @@ class PersonalDashboardViewModel @Inject constructor( } private fun getActionPlan() = viewModelScope.launch { - repository.getActionPlan(1, 3).onSuccess { response -> + repository.getActionPlan(UserInfo.MEMBER_ID, UserInfo.PROJECT_ID).onSuccess { response -> Log.d("personal", "getActionPlan() success:: $response") _actionPlanList.value = response }.onFailure { @@ -100,16 +108,15 @@ class PersonalDashboardViewModel @Inject constructor( } } -// val actionPlanList: List = -// listOf( -// ActionPlan("여기에는 글이 계속 작성되다가 작성되다가 작성되다가 작성되다가 이쯤 되면 끊기게 돼...", "7월 3일"), -// ActionPlan("여기에는 글이 계속 작성되다가 작성되다가 작성되다가 작성되다가 이쯤 되면 끊기게 돼...", "7월 4일"), -// ActionPlan("여기에는 글이 계속 작성되다가 작성되다가 작성되다가 작성되다가 이쯤 되면 끊기게 돼...", "7월 5일"), -// ActionPlan("여기에는 글이 계속 작성되다가 작성되다가 작성되다가 작성되다가 이쯤 되면 끊기게 돼...", "7월 6일"), -// ActionPlan("여기에는 글이 계속 작성되다가 작성되다가 작성되다가 작성되다가 이쯤 되면 끊기게 돼...", "7월 7일"), -// ) - - val _bottomButtonText = MutableLiveData() - val bottomButtonText: String - get() = _bottomButtonText.value ?: "회고 작성일이 아니에요" + private fun getPreviousTemplate() { + viewModelScope.launch { + writeReviewRepository.getPreviousTemplate(UserInfo.MEMBER_ID, UserInfo.PROJECT_ID) + .onSuccess { response -> + _previousReviewType.value = response.data.previousTemplateId + Log.d("write", "getPreviousTemplate() success:: ${_previousReviewType.value}") + }.onFailure { + Log.d("write", "getPreviousTemplate() Fail:: $it") + } + } + } } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/main/HomeChooseProjectFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/main/HomeChooseProjectFragment.kt index 070e86d0..079b38bc 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/main/HomeChooseProjectFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/main/HomeChooseProjectFragment.kt @@ -11,9 +11,11 @@ import com.puzzling.puzzlingaos.databinding.FragmentHomeChooseProjectBinding import com.puzzling.puzzlingaos.presentation.home.HomeViewModel import com.puzzling.puzzlingaos.presentation.invitationCode.InvitationCodeActivity import com.puzzling.puzzlingaos.presentation.register.RegisterActivity +import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.delay import kotlinx.coroutines.launch +@AndroidEntryPoint class HomeChooseProjectFragment : BottomSheetDialogFragment(R.layout.fragment_home_choose_project) { private val viewModel by activityViewModels() diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/ChooseRetrospectiveFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/ChooseReviewFragment.kt similarity index 72% rename from app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/ChooseRetrospectiveFragment.kt rename to app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/ChooseReviewFragment.kt index 75e3146f..ebca6473 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/ChooseRetrospectiveFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/ChooseReviewFragment.kt @@ -5,14 +5,17 @@ import android.view.View import androidx.fragment.app.activityViewModels import com.puzzling.puzzlingaos.R import com.puzzling.puzzlingaos.base.BottomSheetDialogFragment -import com.puzzling.puzzlingaos.databinding.FragmentChooseRetrospectiveBinding +import com.puzzling.puzzlingaos.databinding.FragmentChooseReviewBinding +import dagger.hilt.android.AndroidEntryPoint -class ChooseRetrospectiveFragment : - BottomSheetDialogFragment(R.layout.fragment_choose_retrospective) { - private val viewModel by activityViewModels() +@AndroidEntryPoint +class ChooseReviewFragment : + BottomSheetDialogFragment(R.layout.fragment_choose_review) { + private val viewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + binding.vm = viewModel clickItemButton() } diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/RegisterDialogFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/RegisterDialogFragment.kt index a2950655..55299598 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/RegisterDialogFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/RegisterDialogFragment.kt @@ -3,12 +3,17 @@ package com.puzzling.puzzlingaos.presentation.writeRetrospective import android.os.Bundle import android.util.Log import android.view.View +import androidx.fragment.app.activityViewModels import com.puzzling.puzzlingaos.R import com.puzzling.puzzlingaos.base.BaseDialogFragment import com.puzzling.puzzlingaos.databinding.FragmentRegisterDialogBinding +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class RegisterDialogFragment : BaseDialogFragment(R.layout.fragment_register_dialog) { + private val viewModel by activityViewModels() + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) initDialogCancelable() @@ -22,7 +27,13 @@ class RegisterDialogFragment : private fun clickBtn() { with(binding) { btnRegisterDialogTop.setOnClickListener { - Log.d("write", "서버로 작성한 글 Post") + Log.d("dialog", "register 버튼 누름") + when (viewModel.selectedReviewType.value) { + "TIL" -> viewModel.postReviewTIL() + "5F" -> viewModel.postReview5F() + "AAR" -> viewModel.postReviewAAR() + } + // TODO detailRetroActivity 넘어갈때 프로젝트 이름을 넘겨줌 } btnRegisterDialogBottom.setOnClickListener { dialog?.dismiss() diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/Write5fFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/Write5fFragment.kt index 0b1b53e1..d730a906 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/Write5fFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/Write5fFragment.kt @@ -1,3 +1,5 @@ +package com.puzzling.puzzlingaos.presentation.writeRetrospective + import android.os.Bundle import android.view.View import androidx.fragment.app.activityViewModels @@ -5,11 +7,12 @@ import androidx.lifecycle.MutableLiveData import com.puzzling.puzzlingaos.R import com.puzzling.puzzlingaos.base.BaseFragment import com.puzzling.puzzlingaos.databinding.FragmentWrite5fBinding -import com.puzzling.puzzlingaos.presentation.writeRetrospective.WriteRetrospectiveViewModel +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class Write5fFragment : BaseFragment(R.layout.fragment_write5f) { - private val viewModel by activityViewModels() + private val viewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteAarFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteAarFragment.kt index 963b8566..e1a209cf 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteAarFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteAarFragment.kt @@ -7,10 +7,12 @@ import androidx.lifecycle.MutableLiveData import com.puzzling.puzzlingaos.R import com.puzzling.puzzlingaos.base.BaseFragment import com.puzzling.puzzlingaos.databinding.FragmentWriteAarBinding +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class WriteAarFragment : BaseFragment(R.layout.fragment_write_aar) { - private val viewModel by activityViewModels() + private val viewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteRetrospectiveActivity.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteRetrospectiveActivity.kt index 8a394689..74ee3c0d 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteRetrospectiveActivity.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteRetrospectiveActivity.kt @@ -1,7 +1,5 @@ package com.puzzling.puzzlingaos.presentation.writeRetrospective -import Write5fFragment -import WriteTilFragment import android.os.Bundle import android.util.Log import androidx.activity.viewModels @@ -10,10 +8,13 @@ import androidx.fragment.app.commit import com.puzzling.puzzlingaos.R import com.puzzling.puzzlingaos.base.BaseActivity import com.puzzling.puzzlingaos.databinding.ActivityWriteRetrospectiveBinding +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class WriteRetrospectiveActivity : BaseActivity(R.layout.activity_write_retrospective) { - private val viewModel by viewModels() + private val viewModel by viewModels() + private var reviewType: String = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -34,8 +35,8 @@ class WriteRetrospectiveActivity : private fun clickBtn() { with(binding) { clWriteChip.setOnClickListener { - val chooseRetrospectiveFragment = ChooseRetrospectiveFragment() - chooseRetrospectiveFragment.show(supportFragmentManager, "show") + val chooseReviewFragment = ChooseReviewFragment() + chooseReviewFragment.show(supportFragmentManager, "show") } tvWriteRegister.setOnClickListener { if (viewModel.isInputEnabled.value == true) { @@ -54,10 +55,11 @@ class WriteRetrospectiveActivity : } private fun handleSelectedReviewType() { - viewModel.selectedReviewType.observe(this) { reviewType -> - binding.tvWriteChip.text = reviewType + viewModel.selectedReviewType.observe(this) { type -> + binding.tvWriteChip.text = type + reviewType = type Log.d("write", "review type:: $reviewType") - when (reviewType) { + when (type) { "TIL" -> { clearTilQuestionText() replaceFragment(WriteTilFragment()) @@ -74,26 +76,71 @@ class WriteRetrospectiveActivity : } } + // private fun clearTilQuestionText() { +// viewModel.tilQuestion1.value = "" +// viewModel.tilQuestion2.value = "" +// viewModel.tilQuestion3.value = "" +// } +// +// private fun clear5fQuestionText() { +// viewModel.question5f1.value = "" +// viewModel.question5f2.value = "" +// viewModel.question5f3.value = "" +// viewModel.question5f4.value = "" +// viewModel.question5f5.value = "" +// } +// +// private fun clearAarQuestionText() { +// viewModel.aarQuestion1.value = "" +// viewModel.aarQuestion2.value = "" +// viewModel.aarQuestion3.value = "" +// viewModel.aarQuestion4.value = "" +// viewModel.aarQuestion5.value = "" +// } + + private fun clearText(vararg text: String?): Array { + return Array(text.size) { "" } + } + private fun clearTilQuestionText() { - viewModel.tilQuestion1.value = "" - viewModel.tilQuestion2.value = "" - viewModel.tilQuestion3.value = "" + val clearedText = clearText( + viewModel.tilQuestion1.value, + viewModel.tilQuestion2.value, + viewModel.tilQuestion3.value, + ) + viewModel.tilQuestion1.value = clearedText[0] + viewModel.tilQuestion2.value = clearedText[1] + viewModel.tilQuestion3.value = clearedText[2] } private fun clear5fQuestionText() { - viewModel.question5f1.value = "" - viewModel.question5f2.value = "" - viewModel.question5f3.value = "" - viewModel.question5f4.value = "" - viewModel.question5f5.value = "" + val clearedText = clearText( + viewModel.question5f1.value, + viewModel.question5f2.value, + viewModel.question5f3.value, + viewModel.question5f4.value, + viewModel.question5f5.value, + ) + viewModel.question5f1.value = clearedText[0] + viewModel.question5f2.value = clearedText[1] + viewModel.question5f3.value = clearedText[2] + viewModel.question5f4.value = clearedText[3] + viewModel.question5f5.value = clearedText[4] } private fun clearAarQuestionText() { - viewModel.aarQuestion1.value = "" - viewModel.aarQuestion2.value = "" - viewModel.aarQuestion3.value = "" - viewModel.aarQuestion4.value = "" - viewModel.aarQuestion5.value = "" + val clearedText = clearText( + viewModel.aarQuestion1.value, + viewModel.aarQuestion2.value, + viewModel.aarQuestion3.value, + viewModel.aarQuestion4.value, + viewModel.aarQuestion5.value, + ) + viewModel.aarQuestion1.value = clearedText[0] + viewModel.aarQuestion2.value = clearedText[1] + viewModel.aarQuestion3.value = clearedText[2] + viewModel.aarQuestion4.value = clearedText[3] + viewModel.aarQuestion5.value = clearedText[4] } private fun checkBtnEnabled() { diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteRetrospectiveViewModel.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteRetrospectiveViewModel.kt deleted file mode 100644 index 47240ce3..00000000 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteRetrospectiveViewModel.kt +++ /dev/null @@ -1,130 +0,0 @@ -package com.puzzling.puzzlingaos.presentation.writeRetrospective - -import android.util.Log -import androidx.lifecycle.LiveData -import androidx.lifecycle.MediatorLiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel - -class WriteRetrospectiveViewModel : ViewModel() { - private val registerRegex = WRITE_REGEX.toRegex() - - val tilQuestion1 = MutableLiveData() - val tilQuestion2 = MutableLiveData() - val tilQuestion3 = MutableLiveData() - var isValidTilquestion1: MutableLiveData = MutableLiveData(true) - var isValidTilquestion2: MutableLiveData = MutableLiveData(true) - var isValidTilquestion3: MutableLiveData = MutableLiveData(true) - - val question5f1 = MutableLiveData() - val question5f2 = MutableLiveData() - val question5f3 = MutableLiveData() - val question5f4 = MutableLiveData() - val question5f5 = MutableLiveData() - var isValid5fquestion1: MutableLiveData = MutableLiveData(true) - var isValid5fquestion2: MutableLiveData = MutableLiveData(true) - var isValid5fquestion3: MutableLiveData = MutableLiveData(true) - var isValid5fquestion4: MutableLiveData = MutableLiveData(true) - var isValid5fquestion5: MutableLiveData = MutableLiveData(true) - - val aarQuestion1 = MutableLiveData() - val aarQuestion2 = MutableLiveData() - val aarQuestion3 = MutableLiveData() - val aarQuestion4 = MutableLiveData() - val aarQuestion5 = MutableLiveData() - var isValidAarquestion1: MutableLiveData = MutableLiveData(true) - var isValidAarquestion2: MutableLiveData = MutableLiveData(true) - var isValidAarquestion3: MutableLiveData = MutableLiveData(true) - var isValidAarquestion4: MutableLiveData = MutableLiveData(true) - var isValidAarquestion5: MutableLiveData = MutableLiveData(true) - - private val _isReviewTypeSelected = MutableLiveData(false) - val isReviewTypeSelected: LiveData - get() = _isReviewTypeSelected - - private val _selectedReviewType = MutableLiveData("TIL") - val selectedReviewType: LiveData - get() = _selectedReviewType - - private val _selectedChipText = MutableLiveData() - val selectedChipText: LiveData - get() = _selectedChipText - - fun setSelectedChipText(chipText: String) { - _selectedChipText.value = chipText - } - - fun validTextBox(textBox: String): Boolean { - return textBox.matches(registerRegex) - } - - fun validRegister(textBox: String): Boolean { - return textBox.matches(registerRegex) && !textBox.isNullOrBlank() - } - - fun isTilValid(): Boolean { - return validRegister(tilQuestion1.value.orEmpty()) && - validRegister(tilQuestion2.value.orEmpty()) && - validRegister(tilQuestion3.value.orEmpty()) - } - - fun is5fValid(): Boolean { - return validRegister(question5f1.value.orEmpty()) && - validRegister(question5f2.value.orEmpty()) && - validRegister(question5f3.value.orEmpty()) && - validRegister(question5f4.value.orEmpty()) && - validRegister(question5f5.value.orEmpty()) - } - - fun isAarValid(): Boolean { - return validRegister(aarQuestion1.value.orEmpty()) && - validRegister(aarQuestion2.value.orEmpty()) && - validRegister(aarQuestion3.value.orEmpty()) && - validRegister(aarQuestion4.value.orEmpty()) && - validRegister(aarQuestion5.value.orEmpty()) - } - - val isEnabledTilRegister = MediatorLiveData().apply { - addSource(tilQuestion1) { value = isTilValid() } - addSource(tilQuestion2) { value = isTilValid() } - addSource(tilQuestion3) { value = isTilValid() } - } - - val isEnabled5fRegister = MediatorLiveData().apply { - addSource(question5f1) { value = is5fValid() } - addSource(question5f2) { value = is5fValid() } - addSource(question5f3) { value = is5fValid() } - addSource(question5f4) { value = is5fValid() } - addSource(question5f5) { value = is5fValid() } - } - - val isEnabledAarRegister = MediatorLiveData().apply { - addSource(aarQuestion1) { value = isAarValid() } - addSource(aarQuestion2) { value = isAarValid() } - addSource(aarQuestion3) { value = isAarValid() } - addSource(aarQuestion4) { value = isAarValid() } - addSource(aarQuestion5) { value = isAarValid() } - } - - var isInputEnabled: MutableLiveData = MutableLiveData(false) - - fun checkBtnEnabled() { - isInputEnabled.value = when (_selectedReviewType.value) { - "TIL" -> isTilValid() - "5F" -> is5fValid() - "AAR" -> isAarValid() - else -> false - } - } - - fun setSelectedReviewTypeText(reviewType: String) { - _selectedReviewType.value = reviewType - Log.d("write", "_selectedReviewType.value :: ${_selectedReviewType.value}") - _isReviewTypeSelected.value = true - } - - companion object { - const val WRITE_REGEX = - "^[ㄱ-ㅎㅏ-ㅣ가-힣a-zA-Z0-9 \\\\\\\\s!@#\$%^&*()-_=+\\\\[{\\\\]}\\\\|;:'\",.<>/?]*\$" - } -} diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteReviewViewModel.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteReviewViewModel.kt new file mode 100644 index 00000000..62a4cfd6 --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteReviewViewModel.kt @@ -0,0 +1,321 @@ +package com.puzzling.puzzlingaos.presentation.writeRetrospective + +import android.util.Log +import androidx.lifecycle.LiveData +import androidx.lifecycle.MediatorLiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.puzzling.puzzlingaos.data.model.request.RequestReview5FDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewAARDto +import com.puzzling.puzzlingaos.data.model.request.RequestReviewTILDto +import com.puzzling.puzzlingaos.domain.entity.AAR +import com.puzzling.puzzlingaos.domain.entity.F5 +import com.puzzling.puzzlingaos.domain.entity.ReviewType +import com.puzzling.puzzlingaos.domain.entity.TIL +import com.puzzling.puzzlingaos.domain.repository.WriteReviewRepository +import com.puzzling.puzzlingaos.util.UserInfo +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class WriteReviewViewModel @Inject constructor( + private val repository: WriteReviewRepository, +) : ViewModel() { + private val registerRegex = WRITE_REGEX.toRegex() + private var til: TIL? = null + private var aar: AAR? = null + private var f5: F5? = null + + val tilQuestion1 = MutableLiveData() + val tilQuestion2 = MutableLiveData() + val tilQuestion3 = MutableLiveData() + var isValidTilquestion1: MutableLiveData = MutableLiveData(true) + var isValidTilquestion2: MutableLiveData = MutableLiveData(true) + var isValidTilquestion3: MutableLiveData = MutableLiveData(true) + + val question5f1 = MutableLiveData() + val question5f2 = MutableLiveData() + val question5f3 = MutableLiveData() + val question5f4 = MutableLiveData() + val question5f5 = MutableLiveData() + var isValid5fquestion1: MutableLiveData = MutableLiveData(true) + var isValid5fquestion2: MutableLiveData = MutableLiveData(true) + var isValid5fquestion3: MutableLiveData = MutableLiveData(true) + var isValid5fquestion4: MutableLiveData = MutableLiveData(true) + var isValid5fquestion5: MutableLiveData = MutableLiveData(true) + + val aarQuestion1 = MutableLiveData() + val aarQuestion2 = MutableLiveData() + val aarQuestion3 = MutableLiveData() + val aarQuestion4 = MutableLiveData() + val aarQuestion5 = MutableLiveData() + var isValidAarquestion1: MutableLiveData = MutableLiveData(true) + var isValidAarquestion2: MutableLiveData = MutableLiveData(true) + var isValidAarquestion3: MutableLiveData = MutableLiveData(true) + var isValidAarquestion4: MutableLiveData = MutableLiveData(true) + var isValidAarquestion5: MutableLiveData = MutableLiveData(true) + + private val _isReviewTypeSelected = MutableLiveData(false) + val isReviewTypeSelected: LiveData + get() = _isReviewTypeSelected + + private val _selectedReviewType = MutableLiveData("TIL") + val selectedReviewType: LiveData + get() = _selectedReviewType + + private val _reviewTypeText = MutableLiveData() + val reviewTypeText: LiveData + get() = _reviewTypeText + + private val _selectedChipText = MutableLiveData() + val selectedChipText: LiveData + get() = _selectedChipText + + private var _reviewTypeList: MutableLiveData> = MutableLiveData() + val reviewTypeList: LiveData> + get() = _reviewTypeList + + private var _reviewNameList: MutableLiveData> = MutableLiveData() + val reviewNameList: LiveData> + get() = _reviewNameList + + private var _reviewDescList: MutableLiveData> = MutableLiveData() + val reviewDescList: LiveData> + get() = _reviewDescList + + private var _templateIdList: MutableLiveData> = MutableLiveData() + val templateIdList: LiveData> + get() = _templateIdList + + private val _previousReviewType = MutableLiveData() + val previousReviewType: LiveData + get() = _previousReviewType + + fun setSelectedChipText(chipText: String) { + _selectedChipText.value = chipText + } + + fun validTextBox(textBox: String): Boolean { + return textBox.matches(registerRegex) + } + + fun validRegister(textBox: String): Boolean { + return textBox.matches(registerRegex) && !textBox.isNullOrBlank() + } + + fun isTilValid(): Boolean { + return validRegister(tilQuestion1.value.orEmpty()) && + validRegister(tilQuestion2.value.orEmpty()) && + validRegister(tilQuestion3.value.orEmpty()) + } + + fun is5fValid(): Boolean { + return validRegister(question5f1.value.orEmpty()) && + validRegister(question5f2.value.orEmpty()) && + validRegister(question5f3.value.orEmpty()) && + validRegister(question5f4.value.orEmpty()) && + validRegister(question5f5.value.orEmpty()) + } + + fun isAarValid(): Boolean { + return validRegister(aarQuestion1.value.orEmpty()) && + validRegister(aarQuestion2.value.orEmpty()) && + validRegister(aarQuestion3.value.orEmpty()) && + validRegister(aarQuestion4.value.orEmpty()) && + validRegister(aarQuestion5.value.orEmpty()) + } + + val isEnabledTilRegister = MediatorLiveData().apply { + addSource(tilQuestion1) { value = isTilValid() } + addSource(tilQuestion2) { value = isTilValid() } + addSource(tilQuestion3) { value = isTilValid() } + } + + val isEnabled5fRegister = MediatorLiveData().apply { + addSource(question5f1) { value = is5fValid() } + addSource(question5f2) { value = is5fValid() } + addSource(question5f3) { value = is5fValid() } + addSource(question5f4) { value = is5fValid() } + addSource(question5f5) { value = is5fValid() } + } + + val isEnabledAarRegister = MediatorLiveData().apply { + addSource(aarQuestion1) { value = isAarValid() } + addSource(aarQuestion2) { value = isAarValid() } + addSource(aarQuestion3) { value = isAarValid() } + addSource(aarQuestion4) { value = isAarValid() } + addSource(aarQuestion5) { value = isAarValid() } + } + + var isInputEnabled: MutableLiveData = MutableLiveData(false) + + fun checkBtnEnabled() { + isInputEnabled.value = when (_selectedReviewType.value) { + "TIL" -> isTilValid() + "5F" -> is5fValid() + "AAR" -> isAarValid() + else -> false + } + } + + init { + getReviewType() + getPreviousTemplate() + } + + fun setSelectedReviewTypeText(reviewType: String) { + _selectedReviewType.value = reviewType + Log.d("write", "_selectedReviewType.value :: ${_selectedReviewType.value}") + + _isReviewTypeSelected.value = true + } + + fun getTIL(): TIL { + return TIL( + reviewTemplateId = 1, + liked = tilQuestion1.value.toString(), + lacked = tilQuestion2.value.toString(), + actionPlan = tilQuestion3.value.toString(), + ).also { + til = it + } + } + + fun get5F(): F5 { + return F5( + reviewTemplateId = 2, + fact = question5f1.value.toString(), + feeling = question5f2.value.toString(), + finding = question5f3.value.toString(), + feedback = question5f4.value.toString(), + actionPlan = question5f5.value.toString(), + ).also { + f5 = it + } + } + + fun getAAR(): AAR { + return AAR( + reviewTemplateId = 3, + initialGoal = aarQuestion1.value.toString(), + result = aarQuestion2.value.toString(), + difference = aarQuestion3.value.toString(), + persistence = aarQuestion4.value.toString(), + actionPlan = aarQuestion5.value.toString(), + ).also { + aar = it + } + } + + fun postReviewTIL() { + val requestReviewTIL = RequestReviewTILDto( + 1, + tilQuestion1.value.toString(), + tilQuestion2.value.toString(), + tilQuestion3.value.toString(), + ) + viewModelScope.launch { + repository.uploadTIL( + UserInfo.MEMBER_ID, + UserInfo.PROJECT_ID, + requestReviewTIL, + ).onSuccess { + Log.d("write", "postReviewTIL() success!!") + }.onFailure { + Log.d("write", "postReviewTIL() Fail:: $it") + } + } + } + + fun postReview5F() { + val requestReview5F = RequestReview5FDto( + 2, + question5f1.value.toString(), + question5f2.value.toString(), + question5f3.value.toString(), + question5f4.value.toString(), + question5f5.value.toString(), + ) + viewModelScope.launch { + repository.upload5F( + UserInfo.MEMBER_ID, + UserInfo.PROJECT_ID, + requestReview5F, + ).onSuccess { + Log.d("write", "postReview5F() success!!") + }.onFailure { + Log.d("write", "postReview5F() Fail:: $it") + } + } + } + + fun postReviewAAR() { + val requestReviewAAR = RequestReviewAARDto( + 3, + aarQuestion1.value.toString(), + aarQuestion2.value.toString(), + aarQuestion3.value.toString(), + aarQuestion4.value.toString(), + aarQuestion5.value.toString(), + ) + viewModelScope.launch { + repository.uploadAAR( + UserInfo.MEMBER_ID, + UserInfo.PROJECT_ID, + requestReviewAAR, + ).onSuccess { + Log.d("write", "postReviewAAR() success!!") + }.onFailure { + Log.d("write", "postReviewAAR() Fail:: $it") + } + } + } + + private fun getReviewType() { + viewModelScope.launch { + repository.getReviewType().onSuccess { response -> + _reviewTypeList.value = response + val reviewTypes: List = + _reviewTypeList.value!! + Log.d("write", "getReviewType() success:: $response") + _reviewNameList.value = reviewTypes.map { + it.reviewTemplateName + } + _reviewDescList.value = reviewTypes.map { + it.reviewTemplateMeaning + } + _templateIdList.value = reviewTypes.map { + it.reviewTemplateId + } + Log.d("write", "_reviewName success:: ${_reviewNameList.value}") + Log.d("write", "_reviewDesc success:: ${_reviewDescList.value}") + }.onFailure { + Log.d("write", "getReviewType() Fail:: $it") + } + } + } + + private fun getPreviousTemplate() { + viewModelScope.launch { + repository.getPreviousTemplate(UserInfo.MEMBER_ID, UserInfo.PROJECT_ID) + .onSuccess { response -> + _previousReviewType.value = response.data.previousTemplateId + when (_previousReviewType.value) { + 1 -> _reviewTypeText.value = "TIL" + 2 -> _reviewTypeText.value = "5F" + 3 -> _reviewTypeText.value = "AAR" + } + Log.d("write", "getPreviousTemplate() success:: ${_previousReviewType.value}") + }.onFailure { + Log.d("write", "getPreviousTemplate() Fail:: $it") + } + } + } + + companion object { + const val WRITE_REGEX = + "^[ㄱ-ㅎㅏ-ㅣ가-힣a-zA-Z0-9 \\\\\\\\s!@#\$%^&*()-_=+\\\\[{\\\\]}\\\\|;:'\",.<>/?]*\$" + } +} diff --git a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteTilFragment.kt b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteTilFragment.kt index f4e80eb6..cce482bf 100644 --- a/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteTilFragment.kt +++ b/app/src/main/java/com/puzzling/puzzlingaos/presentation/writeRetrospective/WriteTilFragment.kt @@ -1,3 +1,5 @@ +package com.puzzling.puzzlingaos.presentation.writeRetrospective + import android.os.Bundle import android.view.View import androidx.fragment.app.activityViewModels @@ -5,11 +7,12 @@ import androidx.lifecycle.MutableLiveData import com.puzzling.puzzlingaos.R import com.puzzling.puzzlingaos.base.BaseFragment import com.puzzling.puzzlingaos.databinding.FragmentWriteTilBinding -import com.puzzling.puzzlingaos.presentation.writeRetrospective.WriteRetrospectiveViewModel +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class WriteTilFragment : BaseFragment(R.layout.fragment_write_til) { - private val viewModel by activityViewModels() + private val viewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/java/com/puzzling/puzzlingaos/util/Constants.kt b/app/src/main/java/com/puzzling/puzzlingaos/util/Constants.kt new file mode 100644 index 00000000..283f3300 --- /dev/null +++ b/app/src/main/java/com/puzzling/puzzlingaos/util/Constants.kt @@ -0,0 +1,6 @@ +package com.puzzling.puzzlingaos.util + +object UserInfo { + const val MEMBER_ID = 2 + const val PROJECT_ID = 138 +} diff --git a/app/src/main/res/layout/activity_write_retrospective.xml b/app/src/main/res/layout/activity_write_retrospective.xml index fb7b7390..f936e071 100644 --- a/app/src/main/res/layout/activity_write_retrospective.xml +++ b/app/src/main/res/layout/activity_write_retrospective.xml @@ -7,7 +7,7 @@ + type="com.puzzling.puzzlingaos.presentation.writeRetrospective.WriteReviewViewModel" /> @@ -113,7 +113,7 @@ android:layout_marginStart="18dp" android:layout_marginEnd="2dp" android:includeFontPadding="false" - android:text="@string/tv_write_chip" + android:text="@{vm.reviewTypeText}" android:textAppearance="@style/Kor.Body1.Bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0" diff --git a/app/src/main/res/layout/fragment_choose_retrospective.xml b/app/src/main/res/layout/fragment_choose_review.xml similarity index 86% rename from app/src/main/res/layout/fragment_choose_retrospective.xml rename to app/src/main/res/layout/fragment_choose_review.xml index 9bd5885f..7d33577b 100644 --- a/app/src/main/res/layout/fragment_choose_retrospective.xml +++ b/app/src/main/res/layout/fragment_choose_review.xml @@ -4,6 +4,9 @@ xmlns:tools="http://schemas.android.com/tools"> + @@ -42,7 +45,8 @@ android:layout_height="wrap_content" android:layout_marginStart="20dp" android:includeFontPadding="false" - android:text="TIL" + tools:text="TIL" + android:text="@{vm.reviewNameList[0]}" android:textAppearance="@style/Kor.Body1.Bold" app:layout_constraintBottom_toBottomOf="@+id/cl_choose_first" app:layout_constraintStart_toEndOf="@+id/cl_choose_first" @@ -56,7 +60,8 @@ android:textAppearance="@style/Kor.Detail1.Regular" android:textColor="@color/gray_600" android:includeFontPadding="false" - android:text="학습과 자기 반성을 통해 향후 더 나은 결정을\n 내릴 수 있게 해 주는 회고 방식이에요!" + android:text="@{vm.reviewDescList[0]}" + tools:text="학습과 자기 반성을 통해 향후 더 나은 결정을\n 내릴 수 있게 해 주는 회고 방식이에요!" app:layout_constraintStart_toEndOf="@+id/tv_choose_first" app:layout_constraintTop_toTopOf="@+id/tv_choose_first"/> @@ -76,7 +81,8 @@ android:layout_height="wrap_content" android:layout_marginStart="20dp" android:includeFontPadding="false" - android:text="5F" + android:text="@{vm.reviewNameList[1]}" + tools:text="5F" android:textAppearance="@style/Kor.Body1.Bold" app:layout_constraintBottom_toBottomOf="@+id/cl_choose_second" app:layout_constraintStart_toEndOf="@+id/cl_choose_second" @@ -90,7 +96,8 @@ android:textAppearance="@style/Kor.Detail1.Regular" android:textColor="@color/gray_600" android:includeFontPadding="false" - android:text="다양한 측면을 고려하여 개인과 프로젝트 전\n체적인 관점을 보여주는 회고 방식이에요!" + android:text="@{vm.reviewDescList[1]}" + tools:text="다양한 측면을 고려하여 개인과 프로젝트 전\n체적인 관점을 보여주는 회고 방식이에요!" app:layout_constraintStart_toEndOf="@+id/tv_choose_second" app:layout_constraintTop_toTopOf="@+id/tv_choose_second"/> @@ -110,7 +117,8 @@ android:layout_height="wrap_content" android:layout_marginStart="20dp" android:includeFontPadding="false" - android:text="AAR" + android:text="@{vm.reviewNameList[2]}" + tools:text="AAR" android:textAppearance="@style/Kor.Body1.Bold" app:layout_constraintBottom_toBottomOf="@+id/cl_choose_third" app:layout_constraintStart_toEndOf="@+id/cl_choose_third" @@ -125,7 +133,8 @@ android:textColor="@color/gray_600" android:layout_marginBottom="67dp" android:includeFontPadding="false" - android:text="목표 달성에 대한 책임감과 함께, 개선에 중\n점을 두는 회고 방식이에요!" + android:text="@{vm.reviewDescList[2]}" + tools:text="목표 달성에 대한 책임감과 함께, 개선에 중\n점을 두는 회고 방식이에요!" app:layout_constraintStart_toEndOf="@+id/tv_choose_third" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="@+id/tv_choose_third"/> diff --git a/app/src/main/res/layout/fragment_write5f.xml b/app/src/main/res/layout/fragment_write5f.xml index 3ab9cd44..52005ede 100644 --- a/app/src/main/res/layout/fragment_write5f.xml +++ b/app/src/main/res/layout/fragment_write5f.xml @@ -7,7 +7,7 @@ + type="com.puzzling.puzzlingaos.presentation.writeRetrospective.WriteReviewViewModel" /> diff --git a/app/src/main/res/layout/fragment_write_aar.xml b/app/src/main/res/layout/fragment_write_aar.xml index 02c8f69e..d6bbf86b 100644 --- a/app/src/main/res/layout/fragment_write_aar.xml +++ b/app/src/main/res/layout/fragment_write_aar.xml @@ -7,7 +7,7 @@ + type="com.puzzling.puzzlingaos.presentation.writeRetrospective.WriteReviewViewModel" /> @@ -64,7 +64,7 @@ android:hint="placeholder 위치, 텍스트박스는 기본 사이즈입니다. 양 옆 마진 16px을 가진 텍스트박스가 존재합니다. " android:scrollbars="vertical" android:selectAllOnFocus="false" - android:text="@={vm.question5f1}" /> + android:text="@={vm.aarQuestion1}" /> @@ -117,7 +117,7 @@ android:hint="placeholder 위치, 텍스트박스는 기본 사이즈입니다. 양 옆 마진 16px을 가진 텍스트박스가 존재합니다. " android:scrollbars="vertical" android:selectAllOnFocus="false" - android:text="@={vm.question5f2}" /> + android:text="@={vm.aarQuestion2}" /> + android:text="@={vm.aarQuestion3}" /> + android:text="@={vm.aarQuestion4}" /> + android:text="@={vm.aarQuestion5}" /> diff --git a/app/src/main/res/layout/fragment_write_til.xml b/app/src/main/res/layout/fragment_write_til.xml index 25a0ca25..b290c77b 100644 --- a/app/src/main/res/layout/fragment_write_til.xml +++ b/app/src/main/res/layout/fragment_write_til.xml @@ -7,7 +7,7 @@ + type="com.puzzling.puzzlingaos.presentation.writeRetrospective.WriteReviewViewModel" />