From 728690a7d7c420376dd6c6dfd40ab9400e4aae14 Mon Sep 17 00:00:00 2001 From: crownjoe Date: Tue, 5 Mar 2024 21:56:45 +0900 Subject: [PATCH 01/19] =?UTF-8?q?[FEAT/#230]=20=EB=AA=A8=EB=93=88=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/java/com/going/doorip/di/DataSourceModule.kt | 7 +++++++ app/src/main/java/com/going/doorip/di/RepositoryModule.kt | 7 +++++++ app/src/main/java/com/going/doorip/di/ServiceModule.kt | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/app/src/main/java/com/going/doorip/di/DataSourceModule.kt b/app/src/main/java/com/going/doorip/di/DataSourceModule.kt index d336e600..5a28cb28 100644 --- a/app/src/main/java/com/going/doorip/di/DataSourceModule.kt +++ b/app/src/main/java/com/going/doorip/di/DataSourceModule.kt @@ -2,6 +2,7 @@ package com.going.doorip.di import com.going.data.datasource.AuthDataSource import com.going.data.datasource.DashBoardDataSource +import com.going.data.datasource.EditTripDataSource import com.going.data.datasource.EnterTripDataSource import com.going.data.datasource.ProfileDataSource import com.going.data.datasource.SettingDataSource @@ -10,6 +11,7 @@ import com.going.data.datasource.TodoDataSource import com.going.data.datasource.TokenReissueDataSource import com.going.data.datasourceImpl.AuthDataSourceImpl import com.going.data.datasourceImpl.DashBoardDataSourceImpl +import com.going.data.datasourceImpl.EditTripDataSourceImpl import com.going.data.datasourceImpl.EnterTripDataSourceImpl import com.going.data.datasourceImpl.ProfileDataSourceImpl import com.going.data.datasourceImpl.SettingDataSourceImpl @@ -65,4 +67,9 @@ object DataSourceModule { @Singleton fun provideTokenReissueDataSource(tokenReissueDataSourceImpl: TokenReissueDataSourceImpl): TokenReissueDataSource = tokenReissueDataSourceImpl + + @Provides + @Singleton + fun provideEditTripDataSource(editTripDataSourceImpl: EditTripDataSourceImpl): EditTripDataSource = + editTripDataSourceImpl } diff --git a/app/src/main/java/com/going/doorip/di/RepositoryModule.kt b/app/src/main/java/com/going/doorip/di/RepositoryModule.kt index 4d7a671e..1d18e529 100644 --- a/app/src/main/java/com/going/doorip/di/RepositoryModule.kt +++ b/app/src/main/java/com/going/doorip/di/RepositoryModule.kt @@ -2,6 +2,7 @@ package com.going.doorip.di import com.going.data.repositoryImpl.AuthRepositoryImpl import com.going.data.repositoryImpl.DashBoardRepositoryImpl +import com.going.data.repositoryImpl.EditTripRepositoryImpl import com.going.data.repositoryImpl.EnterTripRepositoryImpl import com.going.data.repositoryImpl.ProfileRepositoryImpl import com.going.data.repositoryImpl.SettingRepositoryImpl @@ -11,6 +12,7 @@ import com.going.data.repositoryImpl.TokenReissueRepositoryImpl import com.going.data.repositoryImpl.TokenRepositoryImpl import com.going.domain.repository.AuthRepository import com.going.domain.repository.DashBoardRepository +import com.going.domain.repository.EditTripRepository import com.going.domain.repository.EnterTripRepository import com.going.domain.repository.ProfileRepository import com.going.domain.repository.SettingRepository @@ -72,4 +74,9 @@ object RepositoryModule { @Singleton fun provideTokenReissueRepository(tokenReissueRepositoryImpl: TokenReissueRepositoryImpl): TokenReissueRepository = tokenReissueRepositoryImpl + + @Provides + @Singleton + fun provideEditTripRepository(EditTripRepositoryImpl: EditTripRepositoryImpl): EditTripRepository = + EditTripRepositoryImpl } diff --git a/app/src/main/java/com/going/doorip/di/ServiceModule.kt b/app/src/main/java/com/going/doorip/di/ServiceModule.kt index 82056816..6e38d2e3 100644 --- a/app/src/main/java/com/going/doorip/di/ServiceModule.kt +++ b/app/src/main/java/com/going/doorip/di/ServiceModule.kt @@ -2,6 +2,7 @@ package com.going.doorip.di import com.going.data.service.AuthService import com.going.data.service.DashBoardService +import com.going.data.service.EditTripService import com.going.data.service.EnterTripService import com.going.data.service.ProfileService import com.going.data.service.SettingService @@ -60,4 +61,10 @@ object ServiceModule { @Singleton fun provideTokenReissueService(@REISSUE retrofit: Retrofit): TokenReissueService = retrofit.create(TokenReissueService::class.java) + + + @Provides + @Singleton + fun provideEditTripService(@JWT retrofit: Retrofit): EditTripService = + retrofit.create(EditTripService::class.java) } From c794a44016ef91c6a3a0db7dd36f230b0c9ce14e Mon Sep 17 00:00:00 2001 From: crownjoe Date: Tue, 5 Mar 2024 21:57:09 +0900 Subject: [PATCH 02/19] =?UTF-8?q?[FEAT/#230]=20datasource=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/EditTripDataSource.kt | 13 +++++++++++++ .../datasourceImpl/EditTripDataSourceImpl.kt | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 data/src/main/java/com/going/data/datasource/EditTripDataSource.kt create mode 100644 data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt diff --git a/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt new file mode 100644 index 00000000..b3dc3825 --- /dev/null +++ b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt @@ -0,0 +1,13 @@ +package com.going.data.datasource + +import com.going.data.dto.NonDataBaseResponse +import com.going.data.dto.request.EditTripInfoRequestDto +import retrofit2.http.Body +import retrofit2.http.Path + +interface EditTripDataSource { + suspend fun patchEditTripInfo( + @Path("tripId") tripId: Long, + @Body request: EditTripInfoRequestDto + ): NonDataBaseResponse +} \ No newline at end of file diff --git a/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt b/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt new file mode 100644 index 00000000..ced971e7 --- /dev/null +++ b/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt @@ -0,0 +1,18 @@ +package com.going.data.datasourceImpl + +import com.going.data.datasource.EditTripDataSource +import com.going.data.dto.NonDataBaseResponse +import com.going.data.dto.request.EditTripInfoRequestDto +import com.going.data.service.EditTripService +import javax.inject.Inject + +class EditTripDataSourceImpl @Inject constructor( + private val editTripService: EditTripService, +) : EditTripDataSource{ + + override suspend fun patchEditTripInfo( + tripId: Long, + request: EditTripInfoRequestDto + ): NonDataBaseResponse = editTripService.patchEditTripInfo( + tripId, request) +} \ No newline at end of file From cf00a9b446068d66b8d7fcafeb35aea64af2ca96 Mon Sep 17 00:00:00 2001 From: crownjoe Date: Tue, 5 Mar 2024 21:57:28 +0900 Subject: [PATCH 03/19] =?UTF-8?q?[FEAT/#230]=20repository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositoryImpl/EditTripRepositoryImpl.kt | 21 +++++++++++++++++++ .../domain/repository/EditTripRepository.kt | 10 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt create mode 100644 domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt diff --git a/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt new file mode 100644 index 00000000..3e487b7a --- /dev/null +++ b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt @@ -0,0 +1,21 @@ +package com.going.data.repositoryImpl + +import com.going.data.datasource.EditTripDataSource +import com.going.data.dto.request.toEditTrioRequestDto +import com.going.domain.entity.request.EditTripRequestModel +import com.going.domain.repository.EditTripRepository +import javax.inject.Inject + +class EditTripRepositoryImpl @Inject constructor( + private val editTripDataSource: EditTripDataSource, +) : EditTripRepository { + + override suspend fun postEditTripInfo( + tripId: Long, request: EditTripRequestModel + ): Result = + runCatching { + editTripDataSource.patchEditTripInfo( + tripId, request.toEditTrioRequestDto() + ) + } +} diff --git a/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt new file mode 100644 index 00000000..d1c56b9e --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt @@ -0,0 +1,10 @@ +package com.going.domain.repository + +import com.going.domain.entity.request.EditTripRequestModel + +interface EditTripRepository { + suspend fun postEditTripInfo( + tripId: Long, + request: EditTripRequestModel + ): Result +} \ No newline at end of file From 1062ce94fe04803e18f720e8fb3686a34062c9eb Mon Sep 17 00:00:00 2001 From: crownjoe Date: Tue, 5 Mar 2024 21:57:56 +0900 Subject: [PATCH 04/19] =?UTF-8?q?[FEAT/#230]=20Dto,=20Model=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/EditTripInfoRequestDto.kt | 19 +++++++++++++++++++ .../com/going/data/service/EditTripService.kt | 16 ++++++++++++++++ .../entity/request/EditTripRequestModel.kt | 7 +++++++ .../domain/entity/response/EditTripModel.kt | 5 +++++ .../domain/entity/response/QuitTripModel.kt | 5 +++++ 5 files changed, 52 insertions(+) create mode 100644 data/src/main/java/com/going/data/dto/request/EditTripInfoRequestDto.kt create mode 100644 data/src/main/java/com/going/data/service/EditTripService.kt create mode 100644 domain/src/main/kotlin/com/going/domain/entity/request/EditTripRequestModel.kt create mode 100644 domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt create mode 100644 domain/src/main/kotlin/com/going/domain/entity/response/QuitTripModel.kt diff --git a/data/src/main/java/com/going/data/dto/request/EditTripInfoRequestDto.kt b/data/src/main/java/com/going/data/dto/request/EditTripInfoRequestDto.kt new file mode 100644 index 00000000..ad89e96b --- /dev/null +++ b/data/src/main/java/com/going/data/dto/request/EditTripInfoRequestDto.kt @@ -0,0 +1,19 @@ +package com.going.data.dto.request + +import com.going.domain.entity.request.EditTripRequestModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +class EditTripInfoRequestDto( + @SerialName("title") + val title: String, + @SerialName("startDate") + val startDate: String, + @SerialName("endDate") + val endDate: String, +) + +fun EditTripRequestModel.toEditTrioRequestDto(): EditTripInfoRequestDto = + EditTripInfoRequestDto(title, startDate, endDate) + diff --git a/data/src/main/java/com/going/data/service/EditTripService.kt b/data/src/main/java/com/going/data/service/EditTripService.kt new file mode 100644 index 00000000..4849dff3 --- /dev/null +++ b/data/src/main/java/com/going/data/service/EditTripService.kt @@ -0,0 +1,16 @@ +package com.going.data.service + +import com.going.data.dto.NonDataBaseResponse +import com.going.data.dto.request.EditTripInfoRequestDto +import com.going.data.dto.request.StartInviteTripRequestDto +import retrofit2.http.Body +import retrofit2.http.PATCH +import retrofit2.http.Path + +interface EditTripService { + @PATCH("/api/trips/{tripId}") + suspend fun patchEditTripInfo( + @Path("tripId") tripId: Long, + @Body request: EditTripInfoRequestDto, + ): NonDataBaseResponse +} \ No newline at end of file diff --git a/domain/src/main/kotlin/com/going/domain/entity/request/EditTripRequestModel.kt b/domain/src/main/kotlin/com/going/domain/entity/request/EditTripRequestModel.kt new file mode 100644 index 00000000..f2615184 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/request/EditTripRequestModel.kt @@ -0,0 +1,7 @@ +package com.going.domain.entity.request + +data class EditTripRequestModel( + val title: String, + val startDate: String, + val endDate: String, +) diff --git a/domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt b/domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt new file mode 100644 index 00000000..6e812859 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt @@ -0,0 +1,5 @@ +package com.going.domain.entity.response + +data class EditTripModel( + val tripId: Long, +) diff --git a/domain/src/main/kotlin/com/going/domain/entity/response/QuitTripModel.kt b/domain/src/main/kotlin/com/going/domain/entity/response/QuitTripModel.kt new file mode 100644 index 00000000..e9231f6c --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/response/QuitTripModel.kt @@ -0,0 +1,5 @@ +package com.going.domain.entity.response + +data class QuitTripModel( + val tripId: Long, +) From f35e81d4876d17499099d332f13cf9b467ad1ccb Mon Sep 17 00:00:00 2001 From: crownjoe Date: Wed, 6 Mar 2024 00:18:59 +0900 Subject: [PATCH 05/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=B4=88=EA=B8=B0=20=EB=B7=B0,=20?= =?UTF-8?q?=EC=97=AC=ED=96=89=20=EC=88=98=EC=A0=95=20=EB=B7=B0=20ui=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 --- .../todo/editinfo/EditTripActivity.kt | 83 ++++++++ .../todo/editinfo/EditTripInfoActivity.kt | 25 +-- .../todo/editinfo/EditTripViewModel.kt | 38 ++++ .../main/res/layout/activity_edit_trip.xml | 183 ++++++++++++++++++ .../res/layout/activity_edit_trip_info.xml | 37 +--- presentation/src/main/res/values/strings.xml | 15 +- 6 files changed, 329 insertions(+), 52 deletions(-) create mode 100644 presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt create mode 100644 presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt create mode 100644 presentation/src/main/res/layout/activity_edit_trip.xml diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt new file mode 100644 index 00000000..89f1dbbb --- /dev/null +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt @@ -0,0 +1,83 @@ +package com.going.presentation.todo.editinfo + +import android.content.Intent +import android.os.Bundle +import androidx.activity.viewModels +import com.going.presentation.R +import com.going.presentation.dashboard.DashBoardActivity +import com.going.presentation.databinding.ActivityEditTripBinding +import com.going.ui.base.BaseActivity +import com.going.ui.extension.setOnSingleClickListener + +class EditTripActivity : + BaseActivity(R.layout.activity_edit_trip) { + private val viewModel by viewModels() + private var quitDialog: TripQuitDialogFragment? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + initBindingViewModel() + initEditBtnClickListener() + initQuitBtnClickListener() + showQuitDialog() + initBackBtnClickListener() + } + + private fun initBindingViewModel() { + binding.viewModel = viewModel + } + + private fun initQuitBtnClickListener() { + binding.btnEditTripQuit.setOnSingleClickListener { + showQuitDialog() + } + } + + private fun initEditBtnClickListener() { + binding.btnEditTripEdit.setOnSingleClickListener { + Intent(this, EditTripInfoActivity::class.java).apply { + putExtra(EditTripInfoActivity.NAME, viewModel.name.value) + putExtra(EditTripInfoActivity.START_YEAR, viewModel.startYear.value) + putExtra(EditTripInfoActivity.START_MONTH, viewModel.startMonth.value) + putExtra(EditTripInfoActivity.START_DAY, viewModel.startDay.value) + putExtra(EditTripInfoActivity.END_YEAR, viewModel.endYear.value) + putExtra(EditTripInfoActivity.END_MONTH, viewModel.endMonth.value) + putExtra(EditTripInfoActivity.END_DAY, viewModel.endDay.value) + addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(this) + } + } + } + + //인텐트 보내면 받기 + + private fun getTripInfo() { + //인텐트 보내면 받기 + } + + private fun setTripInfo() { + //binding.tv~ 뷰에 직접적으로 생기게 + } + + private fun showQuitDialog() { + quitDialog = TripQuitDialogFragment() + quitDialog?.show(supportFragmentManager, quitDialog?.tag) + Intent(this, DashBoardActivity::class.java).apply { + //정보 지워지게 구성 + startActivity(this) + } + } + + private fun initBackBtnClickListener() { + binding.btnEditTripInfoBack.setOnSingleClickListener { + //어느 뷰로 가는지 + finish() + } + } + + override fun onDestroy() { + super.onDestroy() + if (quitDialog?.isAdded == true) quitDialog?.dismiss() + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt index 136b94a0..2b961ab0 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt @@ -17,7 +17,6 @@ class EditTripInfoActivity : private var startBottomSheetDialog: EditDateBottomSheet? = null private var endBottomSheetDialog: EditDateBottomSheet? = null - private var quitDialog: TripQuitDialogFragment? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -28,7 +27,6 @@ class EditTripInfoActivity : initStartDateClickListener() initEndDateClickListener() initEditBtnClickListener() - initQuitBtnClickListener() initBackBtnClickListener() } @@ -70,7 +68,7 @@ class EditTripInfoActivity : } private fun initEditBtnClickListener() { - binding.btnEditTripInfoEdit.setOnSingleClickListener { + binding.btnEditTripSave.setOnSingleClickListener { Intent(this, DashBoardActivity::class.java).apply { putExtra(NAME, viewModel.name.value) putExtra(START_YEAR, viewModel.startYear.value) @@ -85,32 +83,15 @@ class EditTripInfoActivity : } } - private fun initQuitBtnClickListener() { - binding.btnEditTripInfoQuit.setOnSingleClickListener { - showQuitDialog() - } - } - - private fun showQuitDialog() { - quitDialog = TripQuitDialogFragment() - quitDialog?.show(supportFragmentManager, quitDialog?.tag) - Intent(this, DashBoardActivity::class.java).apply { - //정보 지워지게 구성 - startActivity(this) - } - } + //받아온 인텐트를 기본 화면에 넣어서 보여줘야함 private fun initBackBtnClickListener() { binding.btnEditTripInfoBack.setOnSingleClickListener { + //다른 뷰로 이동 finish() } } - override fun onDestroy() { - super.onDestroy() - if (quitDialog?.isAdded == true) quitDialog?.dismiss() - } - companion object { const val NAME = "name" const val START_YEAR = "startYear" diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt new file mode 100644 index 00000000..22853c38 --- /dev/null +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt @@ -0,0 +1,38 @@ +package com.going.presentation.todo.editinfo + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.going.presentation.entertrip.createtrip.preference.ParcelableTripData + +class EditTripViewModel: ViewModel() { + val name = MutableLiveData() + val nameLength = MutableLiveData(0) + + val startYear = MutableLiveData() + val startMonth = MutableLiveData() + val startDay = MutableLiveData() + + val endYear = MutableLiveData() + val endMonth = MutableLiveData() + val endDay = MutableLiveData() + + var tripIntentData: ParcelableTripData? = null + + + fun saveIntentData() { + tripIntentData = ParcelableTripData( //paecelable 안써도 됨 + name = name.value.orEmpty(), + startYear = startYear.value ?: 0, + startMonth = startMonth.value ?: 0, + startDay = startDay.value ?: 0, + endYear = endYear.value ?: 0, + endMonth = endMonth.value ?: 0, + endDay = endDay.value ?: 0 + ) + } + + companion object { + const val MAX_TRIP_LEN = 15 + } + +} diff --git a/presentation/src/main/res/layout/activity_edit_trip.xml b/presentation/src/main/res/layout/activity_edit_trip.xml new file mode 100644 index 00000000..efacb40c --- /dev/null +++ b/presentation/src/main/res/layout/activity_edit_trip.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/presentation/src/main/res/layout/activity_edit_trip_info.xml b/presentation/src/main/res/layout/activity_edit_trip_info.xml index f4d640cc..b8a4dd02 100644 --- a/presentation/src/main/res/layout/activity_edit_trip_info.xml +++ b/presentation/src/main/res/layout/activity_edit_trip_info.xml @@ -120,40 +120,23 @@ android:textColor="@color/gray_700" /> - - - + app:layout_constraintStart_toStartOf="parent" /> diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 8c003b69..bcda11b6 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -214,13 +214,12 @@ 브라우저 오류 - 여행 정보 + 여행 정보 수정 어떤 여행인가요? 여행 일정을 알려주세요 이번 여행 이름을 입력해 주세요 - - 나가기 - 수정하기 + 저장하기 선택하기 %1$d.%2$d.%3$d 시작일을 먼저 입력해 주세요 @@ -230,5 +229,15 @@ 취소 여행 이름에는 공백만 입력할 수 없어요 + + 여행 정보 + 어떤 여행인가요? + 여행 일정을 알려주세요 + - + 나가기 + 수정하기 + 선택하기 + %1$d.%2$d.%3$d + From f2372680b0cf3a2127b63f346efcef73d5abdfa1 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:57:29 +0900 Subject: [PATCH 06/19] =?UTF-8?q?[FEAT/#230]=20=EC=B6=A9=EB=8F=8C=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/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c5818107..fe212a4c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -159,6 +159,7 @@ android:exported="false" android:screenOrientation="portrait" /> + From aa464bd414636339b478d791f1e4f65233b675ab Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:59:50 +0900 Subject: [PATCH 07/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EB=94=94=ED=85=8C=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EB=B7=B0=20?= =?UTF-8?q?Model=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../going/domain/entity/request/TripInfoRequestModel.kt | 8 ++++++++ .../com/going/domain/entity/response/TripInfoModel.kt | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 domain/src/main/kotlin/com/going/domain/entity/request/TripInfoRequestModel.kt create mode 100644 domain/src/main/kotlin/com/going/domain/entity/response/TripInfoModel.kt diff --git a/domain/src/main/kotlin/com/going/domain/entity/request/TripInfoRequestModel.kt b/domain/src/main/kotlin/com/going/domain/entity/request/TripInfoRequestModel.kt new file mode 100644 index 00000000..346a2f06 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/request/TripInfoRequestModel.kt @@ -0,0 +1,8 @@ +package com.going.domain.entity.request + +data class TripInfoRequestModel( + val tripId: Long, + val title: String, + val startDate : String, + val endDate : String, +) diff --git a/domain/src/main/kotlin/com/going/domain/entity/response/TripInfoModel.kt b/domain/src/main/kotlin/com/going/domain/entity/response/TripInfoModel.kt new file mode 100644 index 00000000..5a1da384 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/response/TripInfoModel.kt @@ -0,0 +1,8 @@ +package com.going.domain.entity.response + +data class TripInfoModel( + val tripId: Long, + val title: String, + val startDate: String, + val endDate: String, +) From 4de23c39b1349eb006772e98d637d2fe1462a3cf Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:00:09 +0900 Subject: [PATCH 08/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EB=94=94=ED=85=8C=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EB=B7=B0=20?= =?UTF-8?q?DataSource=20=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/going/data/datasource/EditTripDataSource.kt | 6 ++++++ .../data/datasourceImpl/EditTripDataSourceImpl.kt | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt index b3dc3825..e2b44760 100644 --- a/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt +++ b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt @@ -1,7 +1,9 @@ package com.going.data.datasource +import com.going.data.dto.BaseResponse import com.going.data.dto.NonDataBaseResponse import com.going.data.dto.request.EditTripInfoRequestDto +import com.going.data.dto.response.TripInfoResponseDto import retrofit2.http.Body import retrofit2.http.Path @@ -10,4 +12,8 @@ interface EditTripDataSource { @Path("tripId") tripId: Long, @Body request: EditTripInfoRequestDto ): NonDataBaseResponse + + suspend fun getTripInfo( + tripId: Long + ): BaseResponse } \ No newline at end of file diff --git a/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt b/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt index ced971e7..a6b5a3d4 100644 --- a/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt +++ b/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt @@ -1,18 +1,26 @@ package com.going.data.datasourceImpl import com.going.data.datasource.EditTripDataSource +import com.going.data.dto.BaseResponse import com.going.data.dto.NonDataBaseResponse import com.going.data.dto.request.EditTripInfoRequestDto +import com.going.data.dto.response.TripInfoResponseDto import com.going.data.service.EditTripService import javax.inject.Inject class EditTripDataSourceImpl @Inject constructor( private val editTripService: EditTripService, -) : EditTripDataSource{ +) : EditTripDataSource { + + override suspend fun getTripInfo( + tripId: Long + ): BaseResponse = + editTripService.getTripInfo(tripId) override suspend fun patchEditTripInfo( tripId: Long, request: EditTripInfoRequestDto ): NonDataBaseResponse = editTripService.patchEditTripInfo( - tripId, request) + tripId, request + ) } \ No newline at end of file From 1ae947baccba84d398d398fc493974593b5fd668 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:00:27 +0900 Subject: [PATCH 09/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EB=94=94=ED=85=8C=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EB=B7=B0=20?= =?UTF-8?q?Repository=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../going/data/repositoryImpl/EditTripRepositoryImpl.kt | 8 ++++++++ .../com/going/domain/repository/EditTripRepository.kt | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt index 3e487b7a..2bef99ef 100644 --- a/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt +++ b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt @@ -3,12 +3,20 @@ package com.going.data.repositoryImpl import com.going.data.datasource.EditTripDataSource import com.going.data.dto.request.toEditTrioRequestDto import com.going.domain.entity.request.EditTripRequestModel +import com.going.domain.entity.request.TripInfoRequestModel +import com.going.domain.entity.response.TripInfoModel import com.going.domain.repository.EditTripRepository import javax.inject.Inject class EditTripRepositoryImpl @Inject constructor( private val editTripDataSource: EditTripDataSource, ) : EditTripRepository { + override suspend fun getTripInfo( + tripId: Long + ): Result = + runCatching { + editTripDataSource.getTripInfo(tripId).data.toTripInfoModel() + } override suspend fun postEditTripInfo( tripId: Long, request: EditTripRequestModel diff --git a/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt index d1c56b9e..426eded5 100644 --- a/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt +++ b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt @@ -1,8 +1,13 @@ package com.going.domain.repository import com.going.domain.entity.request.EditTripRequestModel +import com.going.domain.entity.response.TripInfoModel interface EditTripRepository { + + suspend fun getTripInfo( + tripId: Long + ): Result suspend fun postEditTripInfo( tripId: Long, request: EditTripRequestModel From ce5548a2ecee0ba84de7f240088cc14cb0e3c282 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:00:46 +0900 Subject: [PATCH 10/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EB=94=94=ED=85=8C=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EB=B7=B0=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/going/doorip/di/RepositoryModule.kt | 4 ++-- .../java/com/going/doorip/di/ServiceModule.kt | 1 - .../data/dto/response/TripInfoResponseDto.kt | 21 +++++++++++++++++++ .../com/going/data/service/EditTripService.kt | 12 +++++++++-- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt diff --git a/app/src/main/java/com/going/doorip/di/RepositoryModule.kt b/app/src/main/java/com/going/doorip/di/RepositoryModule.kt index 1d18e529..67542210 100644 --- a/app/src/main/java/com/going/doorip/di/RepositoryModule.kt +++ b/app/src/main/java/com/going/doorip/di/RepositoryModule.kt @@ -77,6 +77,6 @@ object RepositoryModule { @Provides @Singleton - fun provideEditTripRepository(EditTripRepositoryImpl: EditTripRepositoryImpl): EditTripRepository = - EditTripRepositoryImpl + fun provideEditTripRepository(editTripRepositoryImpl: EditTripRepositoryImpl): EditTripRepository = + editTripRepositoryImpl } diff --git a/app/src/main/java/com/going/doorip/di/ServiceModule.kt b/app/src/main/java/com/going/doorip/di/ServiceModule.kt index 6e38d2e3..c0c8299e 100644 --- a/app/src/main/java/com/going/doorip/di/ServiceModule.kt +++ b/app/src/main/java/com/going/doorip/di/ServiceModule.kt @@ -62,7 +62,6 @@ object ServiceModule { fun provideTokenReissueService(@REISSUE retrofit: Retrofit): TokenReissueService = retrofit.create(TokenReissueService::class.java) - @Provides @Singleton fun provideEditTripService(@JWT retrofit: Retrofit): EditTripService = diff --git a/data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt b/data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt new file mode 100644 index 00000000..9a73d280 --- /dev/null +++ b/data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt @@ -0,0 +1,21 @@ +package com.going.data.dto.response + +import com.going.domain.entity.request.TripInfoRequestModel +import com.going.domain.entity.response.TripInfoModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class TripInfoResponseDto( + @SerialName("tripId") + val tripId: Long, + @SerialName("title") + val title: String, + @SerialName("startDate") + val startDate: String, + @SerialName("endDate") + val endDate: String, +) { + fun toTripInfoModel(): TripInfoModel + = TripInfoModel(tripId, title, startDate, endDate) +} diff --git a/data/src/main/java/com/going/data/service/EditTripService.kt b/data/src/main/java/com/going/data/service/EditTripService.kt index 4849dff3..e0bcdf21 100644 --- a/data/src/main/java/com/going/data/service/EditTripService.kt +++ b/data/src/main/java/com/going/data/service/EditTripService.kt @@ -1,14 +1,22 @@ package com.going.data.service +import com.going.data.dto.BaseResponse import com.going.data.dto.NonDataBaseResponse import com.going.data.dto.request.EditTripInfoRequestDto -import com.going.data.dto.request.StartInviteTripRequestDto +import com.going.data.dto.response.TripInfoResponseDto import retrofit2.http.Body +import retrofit2.http.GET import retrofit2.http.PATCH import retrofit2.http.Path interface EditTripService { - @PATCH("/api/trips/{tripId}") + + @GET("api/trips/{tripId}") + suspend fun getTripInfo( + @Path("tripId") tripId: Long + ): BaseResponse + + @PATCH("api/trips/{tripId}") suspend fun patchEditTripInfo( @Path("tripId") tripId: Long, @Body request: EditTripInfoRequestDto, From 32a5776a1e142e80c896dfad7ee5f39c79208e43 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:01:02 +0900 Subject: [PATCH 11/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EB=94=94=ED=85=8C=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EB=B7=B0=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 5 +++ .../todo/editinfo/EditTripActivity.kt | 36 +++++++++++++----- .../todo/editinfo/EditTripInfoActivity.kt | 4 +- .../todo/editinfo/EditTripInfoViewModel.kt | 3 +- .../todo/ourtodo/OurTodoFragment.kt | 37 +++++++++++++++---- .../todo/ourtodo/OurTodoViewModel.kt | 29 ++++++++++++++- 6 files changed, 92 insertions(+), 22 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f1dc5261..34cb5cd3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -169,6 +169,11 @@ android:exported="false" android:screenOrientation="portrait" /> + + diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt index 89f1dbbb..eb102589 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt @@ -1,11 +1,14 @@ package com.going.presentation.todo.editinfo +import android.content.Context import android.content.Intent import android.os.Bundle import androidx.activity.viewModels import com.going.presentation.R import com.going.presentation.dashboard.DashBoardActivity import com.going.presentation.databinding.ActivityEditTripBinding +import com.going.presentation.todo.TodoActivity +import com.going.presentation.todo.create.TodoCreateActivity import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener @@ -37,27 +40,19 @@ class EditTripActivity : private fun initEditBtnClickListener() { binding.btnEditTripEdit.setOnSingleClickListener { Intent(this, EditTripInfoActivity::class.java).apply { - putExtra(EditTripInfoActivity.NAME, viewModel.name.value) - putExtra(EditTripInfoActivity.START_YEAR, viewModel.startYear.value) - putExtra(EditTripInfoActivity.START_MONTH, viewModel.startMonth.value) - putExtra(EditTripInfoActivity.START_DAY, viewModel.startDay.value) - putExtra(EditTripInfoActivity.END_YEAR, viewModel.endYear.value) - putExtra(EditTripInfoActivity.END_MONTH, viewModel.endMonth.value) - putExtra(EditTripInfoActivity.END_DAY, viewModel.endDay.value) + //섭통 결과물 addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) startActivity(this) } } } - //인텐트 보내면 받기 - private fun getTripInfo() { //인텐트 보내면 받기 } private fun setTripInfo() { - //binding.tv~ 뷰에 직접적으로 생기게 + //binding.tv~ 뷰에 직접적으로 넣어버리자 } private fun showQuitDialog() { @@ -80,4 +75,25 @@ class EditTripActivity : super.onDestroy() if (quitDialog?.isAdded == true) quitDialog?.dismiss() } + + companion object{ + private const val TRIP_ID = "TRIP_ID" + private const val TITLE = "TITLE" + private const val START_DATE = "START_DATE" + private const val END_DATE = "END_DATE" + + @JvmStatic + fun createIntent( + context: Context, + tripId: Long, + title: String, + startDate: String, + endDate: String + ): Intent = Intent(context, EditTripActivity::class.java).apply { + putExtra(TRIP_ID, tripId) + putExtra(TITLE, title) + putExtra(START_DATE, startDate) + putExtra(END_DATE, endDate) + } + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt index 2b961ab0..882fd18e 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt @@ -10,7 +10,9 @@ import com.going.presentation.databinding.ActivityEditTripInfoBinding import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.toast +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class EditTripInfoActivity : BaseActivity(R.layout.activity_edit_trip_info) { private val viewModel by viewModels() @@ -83,7 +85,7 @@ class EditTripInfoActivity : } } - //받아온 인텐트를 기본 화면에 넣어서 보여줘야함 + //섭통 해서 화면에 넣어서 보여줘야함 private fun initBackBtnClickListener() { binding.btnEditTripInfoBack.setOnSingleClickListener { diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt index 446c6a43..a1127115 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt @@ -20,7 +20,6 @@ class EditTripInfoViewModel : ViewModel() { val isEndDateAvailable = MutableLiveData(false) val isNameAvailable = MutableStateFlow(false) - private val isTripAvailable = MutableLiveData(false) var isCheckTripAvailable = MutableLiveData(false) fun getMaxTripLen() = MAX_TRIP_LEN @@ -66,7 +65,7 @@ class EditTripInfoViewModel : ViewModel() { fun checkTripAvailable() { isCheckTripAvailable.value = - (isTripAvailable.value == true && isStartDateAvailable.value == true && isEndDateAvailable.value == true) + (isNameAvailable.value == true && isStartDateAvailable.value == true && isEndDateAvailable.value == true) } companion object { diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index 995f7558..bffbe852 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -20,6 +20,7 @@ import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID import com.going.ui.util.RvItemDecoration import com.going.presentation.todo.ourtodo.checkfriends.CheckFriendsActivity import com.going.presentation.todo.create.TodoCreateActivity +import com.going.presentation.todo.editinfo.EditTripActivity import com.going.presentation.todo.ourtodo.friendlist.OurTodoFriendAdapter import com.going.presentation.todo.ourtodo.invite.FriendInviteDialog import com.going.presentation.todo.ourtodo.todolist.OurTodoViewPagerAdapter @@ -122,17 +123,35 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment private fun initTripFriendBtnClickListener() { binding.btnOurTripFriend.setOnSingleClickListener { - Intent(requireActivity(), CheckFriendsActivity::class.java).apply { + EditTripActivity.createIntent( + requireContext(), + viewModel.tripId, + viewModel.title, + viewModel.startDate, + viewModel.endDate).apply { + startActivity(this) + } + } + } +//여기 이슈 + private fun initTripInfoBtnClickListener() { + binding.btnOurTodoTripInfo.setOnSingleClickListener { + setTripInfo() + Intent(requireActivity(), EditTripActivity::class.java).apply { + putExtra(EXTRA_TRIP_ID, viewModel.tripId) + putExtra(EXTRA_TRIP_ID, viewModel.title) + putExtra(EXTRA_TRIP_ID, viewModel.tripId) putExtra(EXTRA_TRIP_ID, viewModel.tripId) startActivity(this) } } } - private fun initTripInfoBtnClickListener() { - binding.btnOurTodoTripInfo.setOnSingleClickListener { - // TODO : 여행정보 화면 이동 + private fun setTripInfo() { + arguments?.let { + viewModel.tripId = it.getLong(EXTRA_TRIP_ID) } + viewModel.getTripInfoFromServer() } private fun setOurTripInfo() { @@ -200,9 +219,10 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment val displayHeight = activity?.getWindowHeight() ?: return@addOnOffsetChangedListener val toolbarHeight = binding.toolbarOurTodo.height val appBarHeight = appBarLayout.totalScrollRange + verticalOffset - binding.layoutOurTodoEmpty.layoutParams = (binding.layoutOurTodoEmpty.layoutParams).also { - it.height = displayHeight - toolbarHeight - appBarHeight - 300 - } + binding.layoutOurTodoEmpty.layoutParams = + (binding.layoutOurTodoEmpty.layoutParams).also { + it.height = displayHeight - toolbarHeight - appBarHeight - 300 + } if (abs(verticalOffset) == appBarLayout.totalScrollRange) { setStatusBarColor(R.color.white_000) @@ -252,7 +272,8 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment private fun setTitleTextWithDay(day: Int, isComplete: Boolean) { when { day > 0 -> { - binding.tvOurTodoTitleDown.text = getString(R.string.our_todo_title_down_before).format(day) + binding.tvOurTodoTitleDown.text = + getString(R.string.our_todo_title_down_before).format(day) setDateTextColor(6, 6) } diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt index 1d314bea..b466c4c9 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt @@ -1,9 +1,12 @@ package com.going.presentation.todo.ourtodo +import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.going.domain.entity.response.OurTripInfoModel import com.going.domain.entity.response.TodoModel +import com.going.domain.entity.response.TripInfoModel +import com.going.domain.repository.EditTripRepository import com.going.domain.repository.TodoRepository import com.going.ui.state.UiState import dagger.hilt.android.lifecycle.HiltViewModel @@ -14,7 +17,8 @@ import javax.inject.Inject @HiltViewModel class OurTodoViewModel @Inject constructor( - private val todoRepository: TodoRepository + private val todoRepository: TodoRepository, + private val editTripRepository: EditTripRepository ) : ViewModel() { private val _ourTripInfoState = MutableStateFlow>(UiState.Empty) @@ -26,8 +30,13 @@ class OurTodoViewModel @Inject constructor( private val _todoCompleteListState = MutableStateFlow>>(UiState.Empty) val todoCompleteListState: StateFlow>> = _todoCompleteListState + private val _TripInfoState = MutableStateFlow>(UiState.Empty) + var inviteCode : String = "" var tripId : Long = 0 + var title : String = "" + var startDate : String = "" + var endDate : String = "" fun getOurTripInfoFromServer() { _ourTripInfoState.value = UiState.Loading @@ -65,6 +74,24 @@ class OurTodoViewModel @Inject constructor( } } + fun getTripInfoFromServer() { + _TripInfoState.value = UiState.Loading + viewModelScope.launch { + editTripRepository.getTripInfo(tripId) + .onSuccess { response -> + tripId = response.tripId + title = response.title + startDate = response.startDate + endDate = response.endDate + _TripInfoState.value = UiState.Success(response) + Log.d("sy",tripId.toString() ) + } + .onFailure { + _TripInfoState.value = UiState.Failure(it.message.orEmpty()) + } + } + } + fun resetListState() { _todoCompleteListState.value = UiState.Empty _todoUncompleteListState.value = UiState.Empty From e40579a3304a4d73c2cd47c72a5249c6f4f4d80c Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Thu, 7 Mar 2024 19:02:59 +0900 Subject: [PATCH 12/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EB=94=94=ED=85=8C=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EB=B7=B0=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../todo/editinfo/EditTripActivity.kt | 90 +++++++++++-------- .../todo/editinfo/EditTripViewModel.kt | 54 +++++++---- .../todo/ourtodo/OurTodoFragment.kt | 25 ++---- .../todo/ourtodo/OurTodoViewModel.kt | 32 +------ 5 files changed, 100 insertions(+), 103 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 34cb5cd3..3b8fb60a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -171,7 +171,7 @@ diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt index eb102589..6aa99e74 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt @@ -3,15 +3,23 @@ package com.going.presentation.todo.editinfo import android.content.Context import android.content.Intent import android.os.Bundle +import android.util.Log import androidx.activity.viewModels +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope import com.going.presentation.R import com.going.presentation.dashboard.DashBoardActivity import com.going.presentation.databinding.ActivityEditTripBinding -import com.going.presentation.todo.TodoActivity -import com.going.presentation.todo.create.TodoCreateActivity +import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener +import com.going.ui.extension.toast +import com.going.ui.state.UiState +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +@AndroidEntryPoint class EditTripActivity : BaseActivity(R.layout.activity_edit_trip) { private val viewModel by viewModels() @@ -21,9 +29,11 @@ class EditTripActivity : super.onCreate(savedInstanceState) initBindingViewModel() + getIntentData() + observeTripinfoState() initEditBtnClickListener() initQuitBtnClickListener() - showQuitDialog() + //showQuitDialog() initBackBtnClickListener() } @@ -31,9 +41,35 @@ class EditTripActivity : binding.viewModel = viewModel } + private fun getIntentData() { + val tripId = intent.getLongExtra(EXTRA_TRIP_ID, -1L) + viewModel.getTripInfoFromServer(tripId) + } + + private fun observeTripinfoState() { + viewModel.tripInfoState.flowWithLifecycle(lifecycle).onEach { state -> + when (state) { + is UiState.Success -> { + with(binding) { + tvEditTripName.text = viewModel?.title + tvEditTripInfoStartDate.text = viewModel?.startDate + tvEditTripInfoEndDate.text = viewModel?.endDate + } + } + + is UiState.Failure -> { + toast(getString(R.string.server_error)) + } + + is UiState.Loading -> return@onEach + is UiState.Empty -> return@onEach + } + }.launchIn(lifecycleScope) + } + private fun initQuitBtnClickListener() { binding.btnEditTripQuit.setOnSingleClickListener { - showQuitDialog() + //showQuitDialog() } } @@ -47,22 +83,14 @@ class EditTripActivity : } } - private fun getTripInfo() { - //인텐트 보내면 받기 - } - - private fun setTripInfo() { - //binding.tv~ 뷰에 직접적으로 넣어버리자 - } - - private fun showQuitDialog() { - quitDialog = TripQuitDialogFragment() - quitDialog?.show(supportFragmentManager, quitDialog?.tag) - Intent(this, DashBoardActivity::class.java).apply { - //정보 지워지게 구성 - startActivity(this) - } - } +// private fun showQuitDialog() { +// quitDialog = TripQuitDialogFragment() +// quitDialog?.show(supportFragmentManager, quitDialog?.tag) +// Intent(this, DashBoardActivity::class.java).apply { +// //정보 지워지게 구성 +// startActivity(this) +// } +// } private fun initBackBtnClickListener() { binding.btnEditTripInfoBack.setOnSingleClickListener { @@ -76,24 +104,8 @@ class EditTripActivity : if (quitDialog?.isAdded == true) quitDialog?.dismiss() } - companion object{ - private const val TRIP_ID = "TRIP_ID" - private const val TITLE = "TITLE" - private const val START_DATE = "START_DATE" - private const val END_DATE = "END_DATE" - - @JvmStatic - fun createIntent( - context: Context, - tripId: Long, - title: String, - startDate: String, - endDate: String - ): Intent = Intent(context, EditTripActivity::class.java).apply { - putExtra(TRIP_ID, tripId) - putExtra(TITLE, title) - putExtra(START_DATE, startDate) - putExtra(END_DATE, endDate) - } + companion object { + private const val EDIT_INFO_TRIP_ID = "TRIP_ID" + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt index 22853c38..0b344ba9 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt @@ -2,9 +2,21 @@ package com.going.presentation.todo.editinfo import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.going.domain.entity.response.TripInfoModel +import com.going.domain.repository.EditTripRepository import com.going.presentation.entertrip.createtrip.preference.ParcelableTripData - -class EditTripViewModel: ViewModel() { +import com.going.ui.state.UiState +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class EditTripViewModel @Inject constructor( + private val editTripRepository: EditTripRepository +) : ViewModel() { val name = MutableLiveData() val nameLength = MutableLiveData(0) @@ -16,19 +28,31 @@ class EditTripViewModel: ViewModel() { val endMonth = MutableLiveData() val endDay = MutableLiveData() - var tripIntentData: ParcelableTripData? = null - - - fun saveIntentData() { - tripIntentData = ParcelableTripData( //paecelable 안써도 됨 - name = name.value.orEmpty(), - startYear = startYear.value ?: 0, - startMonth = startMonth.value ?: 0, - startDay = startDay.value ?: 0, - endYear = endYear.value ?: 0, - endMonth = endMonth.value ?: 0, - endDay = endDay.value ?: 0 - ) + var tripId: Long = 0 + var title: String = "" + var startDate: String = "" + var endDate: String = "" + + + private val _tripInfoState = MutableStateFlow>(UiState.Empty) + val tripInfoState: StateFlow> get() = _tripInfoState + + + fun getTripInfoFromServer(tripId: Long) { + _tripInfoState.value = UiState.Loading + viewModelScope.launch { + editTripRepository.getTripInfo(tripId) + .onSuccess { + //tripId = response.tripId + title = it.title + startDate = it.startDate + endDate = it.endDate + _tripInfoState.value = UiState.Success(it) + } + .onFailure { + _tripInfoState.value = UiState.Failure(it.message.orEmpty()) + } + } } companion object { diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index bffbe852..c065f391 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -7,6 +7,7 @@ import android.os.Looper import android.text.SpannableStringBuilder import android.text.Spanned import android.text.style.ForegroundColorSpan +import android.util.Log import android.view.View import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels @@ -123,37 +124,22 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment private fun initTripFriendBtnClickListener() { binding.btnOurTripFriend.setOnSingleClickListener { - EditTripActivity.createIntent( - requireContext(), - viewModel.tripId, - viewModel.title, - viewModel.startDate, - viewModel.endDate).apply { - startActivity(this) + Intent(requireActivity(), CheckFriendsActivity::class.java).apply { + putExtra(EXTRA_TRIP_ID, viewModel.tripId) + startActivity(this) } } } -//여기 이슈 + private fun initTripInfoBtnClickListener() { binding.btnOurTodoTripInfo.setOnSingleClickListener { - setTripInfo() Intent(requireActivity(), EditTripActivity::class.java).apply { - putExtra(EXTRA_TRIP_ID, viewModel.tripId) - putExtra(EXTRA_TRIP_ID, viewModel.title) - putExtra(EXTRA_TRIP_ID, viewModel.tripId) putExtra(EXTRA_TRIP_ID, viewModel.tripId) startActivity(this) } } } - private fun setTripInfo() { - arguments?.let { - viewModel.tripId = it.getLong(EXTRA_TRIP_ID) - } - viewModel.getTripInfoFromServer() - } - private fun setOurTripInfo() { arguments?.let { viewModel.tripId = it.getLong(EXTRA_TRIP_ID) @@ -313,6 +299,7 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment const val TAB_COMPLETE = "완료했어요" const val INVITE_DIALOG = "inviteDialog" + const val debounceTime = 300L } diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt index b466c4c9..19877253 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt @@ -1,11 +1,9 @@ package com.going.presentation.todo.ourtodo -import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.going.domain.entity.response.OurTripInfoModel import com.going.domain.entity.response.TodoModel -import com.going.domain.entity.response.TripInfoModel import com.going.domain.repository.EditTripRepository import com.going.domain.repository.TodoRepository import com.going.ui.state.UiState @@ -17,8 +15,7 @@ import javax.inject.Inject @HiltViewModel class OurTodoViewModel @Inject constructor( - private val todoRepository: TodoRepository, - private val editTripRepository: EditTripRepository + private val todoRepository: TodoRepository ) : ViewModel() { private val _ourTripInfoState = MutableStateFlow>(UiState.Empty) @@ -30,13 +27,8 @@ class OurTodoViewModel @Inject constructor( private val _todoCompleteListState = MutableStateFlow>>(UiState.Empty) val todoCompleteListState: StateFlow>> = _todoCompleteListState - private val _TripInfoState = MutableStateFlow>(UiState.Empty) - - var inviteCode : String = "" - var tripId : Long = 0 - var title : String = "" - var startDate : String = "" - var endDate : String = "" + var inviteCode: String = "" + var tripId: Long = 0 fun getOurTripInfoFromServer() { _ourTripInfoState.value = UiState.Loading @@ -74,24 +66,6 @@ class OurTodoViewModel @Inject constructor( } } - fun getTripInfoFromServer() { - _TripInfoState.value = UiState.Loading - viewModelScope.launch { - editTripRepository.getTripInfo(tripId) - .onSuccess { response -> - tripId = response.tripId - title = response.title - startDate = response.startDate - endDate = response.endDate - _TripInfoState.value = UiState.Success(response) - Log.d("sy",tripId.toString() ) - } - .onFailure { - _TripInfoState.value = UiState.Failure(it.message.orEmpty()) - } - } - } - fun resetListState() { _todoCompleteListState.value = UiState.Empty _todoUncompleteListState.value = UiState.Empty From 1adaa2f5a12de30f160ae932ebc5f471a8de4ab2 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Thu, 7 Mar 2024 22:44:04 +0900 Subject: [PATCH 13/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B7=B0=20=EC=84=9C=EB=B2=84=ED=86=B5?= =?UTF-8?q?=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/editinfo/EditTripActivity.kt | 13 +++++--- .../todo/editinfo/EditTripInfoActivity.kt | 33 +++++++++++++++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt index 6aa99e74..63379df0 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.lifecycleScope import com.going.presentation.R import com.going.presentation.dashboard.DashBoardActivity import com.going.presentation.databinding.ActivityEditTripBinding +import com.going.presentation.entertrip.invitetrip.finish.InviteFinishActivity import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener @@ -75,11 +76,13 @@ class EditTripActivity : private fun initEditBtnClickListener() { binding.btnEditTripEdit.setOnSingleClickListener { - Intent(this, EditTripInfoActivity::class.java).apply { - //섭통 결과물 - addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(this) - } + EditTripInfoActivity.createIntent( + this, + viewModel.title, + viewModel.startDate, + viewModel.endDate, + ).apply { startActivity(this) } + } } diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt index 882fd18e..dbd3c446 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt @@ -1,5 +1,6 @@ package com.going.presentation.todo.editinfo +import android.content.Context import android.content.Intent import android.os.Bundle import androidx.activity.viewModels @@ -7,6 +8,7 @@ import androidx.core.widget.doAfterTextChanged import com.going.presentation.R import com.going.presentation.dashboard.DashBoardActivity import com.going.presentation.databinding.ActivityEditTripInfoBinding +import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.toast @@ -24,6 +26,7 @@ class EditTripInfoActivity : super.onCreate(savedInstanceState) initBindingViewModel() + getServerList() setEtInfoNameArguments() observeInfoNameTextChanged() initStartDateClickListener() @@ -36,6 +39,18 @@ class EditTripInfoActivity : binding.viewModel = viewModel } + private fun getServerList() { + val title = intent.getStringExtra(INFO_TITLE) + val startDate = intent.getStringExtra(INFO_START_DATE) + val endDate = intent.getStringExtra(INFO_END_DATE) + + with(binding) { + etEditTripInfoName.editText?.setText(title) + tvEditTripInfoStartDate.text = startDate + tvEditTripInfoEndDate.text = endDate + } + } + private fun setEtInfoNameArguments() { with(binding.etEditTripInfoName) { setMaxLen(viewModel.getMaxTripLen()) @@ -44,6 +59,7 @@ class EditTripInfoActivity : } } + private fun observeInfoNameTextChanged() { binding.etEditTripInfoName.editText.doAfterTextChanged { text -> viewModel.setNameState(text.toString(), binding.etEditTripInfoName.state) @@ -85,8 +101,6 @@ class EditTripInfoActivity : } } - //섭통 해서 화면에 넣어서 보여줘야함 - private fun initBackBtnClickListener() { binding.btnEditTripInfoBack.setOnSingleClickListener { //다른 뷰로 이동 @@ -96,12 +110,27 @@ class EditTripInfoActivity : companion object { const val NAME = "name" + const val INFO_TITLE = "title" const val START_YEAR = "startYear" const val START_MONTH = "startMonth" const val START_DAY = "startDay" + const val INFO_START_DATE = "INFO_START_DATE" const val END_YEAR = "endYear" const val END_MONTH = "endMonth" const val END_DAY = "endDay" + const val INFO_END_DATE = "INFO_END_DATE" + + @JvmStatic + fun createIntent( + context: Context, + title: String, + startDate: String, + endDate: String, + ): Intent = Intent(context, EditTripActivity::class.java).apply { + putExtra(INFO_TITLE, title) + putExtra(INFO_START_DATE, startDate) + putExtra(INFO_END_DATE, endDate) + } } } From c7ae49ca3fc6ddb3c0ff8e7ef4d5339e3e21aae7 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Sat, 9 Mar 2024 16:20:23 +0900 Subject: [PATCH 14/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B7=B0=20=EC=84=9C=EB=B2=84=ED=86=B5?= =?UTF-8?q?=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 4 +- .../data/datasource/EditTripDataSource.kt | 13 +- .../data/dto/response/TripInfoResponseDto.kt | 1 - .../repositoryImpl/EditTripRepositoryImpl.kt | 3 +- .../domain/entity/response/EditTripModel.kt | 5 - .../domain/repository/EditTripRepository.kt | 2 +- .../todo/change/TodoChangeActivity.kt | 2 - .../todo/editinfo/EditTripInfoViewModel.kt | 75 ----------- .../TripQuitDialogFragment.kt | 2 +- .../edit}/EditTripActivity.kt | 23 ++-- .../edit}/EditTripViewModel.kt | 5 +- .../info}/EditDateBottomSheet.kt | 2 +- .../edittrip/info/EditTripInfoViewModel.kt | 119 ++++++++++++++++++ .../todo/ourtodo/OurTodoFragment.kt | 5 +- .../main/res/layout/activity_edit_trip.xml | 4 +- .../res/layout/activity_edit_trip_info.xml | 4 +- presentation/src/main/res/values/strings.xml | 2 + 17 files changed, 151 insertions(+), 120 deletions(-) delete mode 100644 domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt delete mode 100644 presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt rename presentation/src/main/java/com/going/presentation/todo/{editinfo => edittrip}/TripQuitDialogFragment.kt (96%) rename presentation/src/main/java/com/going/presentation/todo/{editinfo => edittrip/edit}/EditTripActivity.kt (84%) rename presentation/src/main/java/com/going/presentation/todo/{editinfo => edittrip/edit}/EditTripViewModel.kt (91%) rename presentation/src/main/java/com/going/presentation/todo/{editinfo => edittrip/info}/EditDateBottomSheet.kt (98%) create mode 100644 presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0c046339..d65737f2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -170,12 +170,12 @@ android:screenOrientation="portrait" /> diff --git a/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt index e2b44760..ecb1d655 100644 --- a/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt +++ b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt @@ -4,16 +4,15 @@ import com.going.data.dto.BaseResponse import com.going.data.dto.NonDataBaseResponse import com.going.data.dto.request.EditTripInfoRequestDto import com.going.data.dto.response.TripInfoResponseDto -import retrofit2.http.Body -import retrofit2.http.Path interface EditTripDataSource { - suspend fun patchEditTripInfo( - @Path("tripId") tripId: Long, - @Body request: EditTripInfoRequestDto - ): NonDataBaseResponse - suspend fun getTripInfo( tripId: Long ): BaseResponse + + suspend fun patchEditTripInfo( + tripId: Long, + request: EditTripInfoRequestDto + ): NonDataBaseResponse + } \ No newline at end of file diff --git a/data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt b/data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt index 9a73d280..f45d2f71 100644 --- a/data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt +++ b/data/src/main/java/com/going/data/dto/response/TripInfoResponseDto.kt @@ -1,6 +1,5 @@ package com.going.data.dto.response -import com.going.domain.entity.request.TripInfoRequestModel import com.going.domain.entity.response.TripInfoModel import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt index 2bef99ef..7939ee69 100644 --- a/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt +++ b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt @@ -3,7 +3,6 @@ package com.going.data.repositoryImpl import com.going.data.datasource.EditTripDataSource import com.going.data.dto.request.toEditTrioRequestDto import com.going.domain.entity.request.EditTripRequestModel -import com.going.domain.entity.request.TripInfoRequestModel import com.going.domain.entity.response.TripInfoModel import com.going.domain.repository.EditTripRepository import javax.inject.Inject @@ -18,7 +17,7 @@ class EditTripRepositoryImpl @Inject constructor( editTripDataSource.getTripInfo(tripId).data.toTripInfoModel() } - override suspend fun postEditTripInfo( + override suspend fun patchEditTripInfo( tripId: Long, request: EditTripRequestModel ): Result = runCatching { diff --git a/domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt b/domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt deleted file mode 100644 index 6e812859..00000000 --- a/domain/src/main/kotlin/com/going/domain/entity/response/EditTripModel.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.going.domain.entity.response - -data class EditTripModel( - val tripId: Long, -) diff --git a/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt index 426eded5..e710230f 100644 --- a/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt +++ b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt @@ -8,7 +8,7 @@ interface EditTripRepository { suspend fun getTripInfo( tripId: Long ): Result - suspend fun postEditTripInfo( + suspend fun patchEditTripInfo( tripId: Long, request: EditTripRequestModel ): Result diff --git a/presentation/src/main/java/com/going/presentation/todo/change/TodoChangeActivity.kt b/presentation/src/main/java/com/going/presentation/todo/change/TodoChangeActivity.kt index 644f43f9..85c68f07 100644 --- a/presentation/src/main/java/com/going/presentation/todo/change/TodoChangeActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/change/TodoChangeActivity.kt @@ -5,7 +5,6 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.view.View -import androidx.activity.OnBackPressedCallback import androidx.activity.viewModels import androidx.core.view.isVisible import androidx.core.widget.doAfterTextChanged @@ -15,7 +14,6 @@ import com.going.presentation.R import com.going.presentation.databinding.ActivityTodoChangeBinding import com.going.presentation.todo.create.TodoCreateActivity.Companion.MAX_MEMO_LEN import com.going.presentation.todo.create.TodoCreateActivity.Companion.MAX_TODO_LEN -import com.going.presentation.todo.detail.TodoDetailActivity import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.toast diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt deleted file mode 100644 index a1127115..00000000 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoViewModel.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.going.presentation.todo.editinfo - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.going.presentation.designsystem.edittext.EditTextState -import kotlinx.coroutines.flow.MutableStateFlow - -class EditTripInfoViewModel : ViewModel() { - val name = MutableLiveData() - - val startYear = MutableLiveData() - val startMonth = MutableLiveData() - val startDay = MutableLiveData() - - val endYear = MutableLiveData() - val endMonth = MutableLiveData() - val endDay = MutableLiveData() - - val isStartDateAvailable = MutableLiveData(false) - val isEndDateAvailable = MutableLiveData(false) - - val isNameAvailable = MutableStateFlow(false) - var isCheckTripAvailable = MutableLiveData(false) - - fun getMaxTripLen() = MAX_TRIP_LEN - - fun setNameState(newName: String, state: EditTextState) { - name.value = newName - isNameAvailable.value = state == EditTextState.SUCCESS - } - - fun setStartDate(year: Int, month: Int, day: Int) { - startYear.value = year - startMonth.value = month - startDay.value = day - checkStartDateAvailable() - } - - fun setEndDate(year: Int, month: Int, day: Int) { - endYear.value = year - endMonth.value = month - endDay.value = day - checkEndDateAvailable() - } - - - fun checkStartDateAvailable() { - if (startYear.value != null && startMonth.value != null && startDay.value != null) { - isStartDateAvailable.value = true - checkTripAvailable() - } else { - isStartDateAvailable.value = false - } - } - - - fun checkEndDateAvailable() { - if (endYear.value != null && endMonth.value != null && endDay.value != null) { - isEndDateAvailable.value = true - checkTripAvailable() - } else { - isEndDateAvailable.value = false - } - } - - fun checkTripAvailable() { - isCheckTripAvailable.value = - (isNameAvailable.value == true && isStartDateAvailable.value == true && isEndDateAvailable.value == true) - } - - companion object { - const val MAX_TRIP_LEN = 15 - } -} - diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/TripQuitDialogFragment.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/TripQuitDialogFragment.kt similarity index 96% rename from presentation/src/main/java/com/going/presentation/todo/editinfo/TripQuitDialogFragment.kt rename to presentation/src/main/java/com/going/presentation/todo/edittrip/TripQuitDialogFragment.kt index 11271e94..93dca53e 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/TripQuitDialogFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/TripQuitDialogFragment.kt @@ -1,4 +1,4 @@ -package com.going.presentation.todo.editinfo +package com.going.presentation.todo.edittrip import android.os.Bundle import android.view.View diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt similarity index 84% rename from presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt rename to presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt index 63379df0..ca401dc7 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt @@ -1,17 +1,14 @@ -package com.going.presentation.todo.editinfo +package com.going.presentation.todo.edittrip.edit -import android.content.Context -import android.content.Intent import android.os.Bundle -import android.util.Log import androidx.activity.viewModels import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import com.going.presentation.R -import com.going.presentation.dashboard.DashBoardActivity import com.going.presentation.databinding.ActivityEditTripBinding -import com.going.presentation.entertrip.invitetrip.finish.InviteFinishActivity -import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID +import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID +import com.going.presentation.todo.edittrip.TripQuitDialogFragment +import com.going.presentation.todo.edittrip.info.EditTripInfoActivity import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.toast @@ -43,8 +40,8 @@ class EditTripActivity : } private fun getIntentData() { - val tripId = intent.getLongExtra(EXTRA_TRIP_ID, -1L) - viewModel.getTripInfoFromServer(tripId) + viewModel.tripId = intent.getLongExtra(TRIP_ID, -1L) + viewModel.getTripInfoFromServer(viewModel.tripId) } private fun observeTripinfoState() { @@ -74,13 +71,15 @@ class EditTripActivity : } } + private fun initEditBtnClickListener() { binding.btnEditTripEdit.setOnSingleClickListener { EditTripInfoActivity.createIntent( this, + viewModel.tripId, viewModel.title, viewModel.startDate, - viewModel.endDate, + viewModel.endDate ).apply { startActivity(this) } } @@ -107,8 +106,4 @@ class EditTripActivity : if (quitDialog?.isAdded == true) quitDialog?.dismiss() } - companion object { - private const val EDIT_INFO_TRIP_ID = "TRIP_ID" - - } } \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt similarity index 91% rename from presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt rename to presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt index 0b344ba9..2f482cca 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt @@ -1,11 +1,10 @@ -package com.going.presentation.todo.editinfo +package com.going.presentation.todo.edittrip.edit import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.going.domain.entity.response.TripInfoModel import com.going.domain.repository.EditTripRepository -import com.going.presentation.entertrip.createtrip.preference.ParcelableTripData import com.going.ui.state.UiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow @@ -43,7 +42,7 @@ class EditTripViewModel @Inject constructor( viewModelScope.launch { editTripRepository.getTripInfo(tripId) .onSuccess { - //tripId = response.tripId + //tripId = it.tripId title = it.title startDate = it.startDate endDate = it.endDate diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditDateBottomSheet.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt similarity index 98% rename from presentation/src/main/java/com/going/presentation/todo/editinfo/EditDateBottomSheet.kt rename to presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt index d94d2482..f77244d0 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditDateBottomSheet.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt @@ -1,4 +1,4 @@ -package com.going.presentation.todo.editinfo +package com.going.presentation.todo.edittrip.info import android.os.Bundle import android.view.View diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt new file mode 100644 index 00000000..32c486f1 --- /dev/null +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt @@ -0,0 +1,119 @@ +package com.going.presentation.todo.edittrip.info + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.going.domain.entity.request.EditTripRequestModel +import com.going.domain.repository.EditTripRepository +import com.going.presentation.designsystem.edittext.EditTextState +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class EditTripInfoViewModel @Inject constructor( + private val editTripRepository: EditTripRepository, + ) : ViewModel() { + + private val _tripEditState = MutableSharedFlow() + val tripEditState: SharedFlow = _tripEditState + + + var tripId: Long = 0 + + var currentTitle: String = "" + var currentStartDate: String = "" + var currentEndDate: String = "" + + val title = MutableLiveData() + + val startYear = MutableLiveData() + val startMonth = MutableLiveData() + val startDay = MutableLiveData() + var startDate = MutableLiveData() + + val endYear = MutableLiveData() + val endMonth = MutableLiveData() + val endDay = MutableLiveData() + var endDate = MutableLiveData() + + val isStartDateAvailable = MutableLiveData(false) + val isEndDateAvailable = MutableLiveData(false) + + val isTitleAvailable = MutableStateFlow(false) + var isCheckTripAvailable = MutableLiveData(false) + + fun getMaxTripLen() = MAX_TRIP_LEN + + fun patchTodoToServer() { + viewModelScope.launch { + editTripRepository.patchEditTripInfo( + tripId, + EditTripRequestModel( + title = title.value.orEmpty(), + startDate = startDate.value.orEmpty(), + endDate = endDate.value.orEmpty() + ) + ) + .onSuccess { + _tripEditState.emit(true) + } + .onFailure { + _tripEditState.emit(false) + } + } + } + + fun setTitleState(newTitle: String, state: EditTextState) { + title.value = newTitle + isTitleAvailable.value = state == EditTextState.SUCCESS + } + + fun setStartDate(year: Int, month: Int, day: Int) { + startYear.value = year + startMonth.value = month + startDay.value = day + checkStartDateAvailable() + startDate.value = String.format("%04d.%02d.%02d", year, month, day) + } + + + fun setEndDate(year: Int, month: Int, day: Int) { + endYear.value = year + endMonth.value = month + endDay.value = day + checkEndDateAvailable() + endDate.value = String.format("%04d.%02d.%02d", year, month, day) + } + + fun checkStartDateAvailable() { + if (startYear.value != null && startMonth.value != null && startDay.value != null) { + isStartDateAvailable.value = true + checkTripAvailable() + } else { + isStartDateAvailable.value = false + } + } + + fun checkEndDateAvailable() { + if (endYear.value != null && endMonth.value != null && endDay.value != null) { + isEndDateAvailable.value = true + checkTripAvailable() + } else { + isEndDateAvailable.value = false + } + } + + fun checkTripAvailable() { //버튼 활성화 + isCheckTripAvailable.value = + (currentTitle != title.value && currentStartDate != startDate.value && currentEndDate != endDate.value) + } + + companion object { + const val MAX_TRIP_LEN = 15 + } +} + diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index 0041dc84..cd6df80d 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -16,10 +16,11 @@ import androidx.viewpager2.widget.ViewPager2 import com.going.domain.entity.response.TripParticipantModel import com.going.presentation.R import com.going.presentation.databinding.FragmentOurTodoBinding +import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID import com.going.presentation.todo.create.TodoCreateActivity import com.going.presentation.todo.ourtodo.checkfriends.CheckFriendsActivity -import com.going.presentation.todo.editinfo.EditTripActivity +import com.going.presentation.todo.edittrip.edit.EditTripActivity import com.going.presentation.todo.ourtodo.friendlist.OurTodoFriendAdapter import com.going.presentation.todo.ourtodo.invite.FriendInviteDialog import com.going.presentation.todo.ourtodo.todolist.OurTodoViewPagerAdapter @@ -137,7 +138,7 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment private fun initTripInfoBtnClickListener() { binding.btnOurTodoTripInfo.setOnSingleClickListener { Intent(requireActivity(), EditTripActivity::class.java).apply { - putExtra(EXTRA_TRIP_ID, viewModel.tripId) + putExtra(TRIP_ID, viewModel.tripId) startActivity(this) } } diff --git a/presentation/src/main/res/layout/activity_edit_trip.xml b/presentation/src/main/res/layout/activity_edit_trip.xml index efacb40c..947277c3 100644 --- a/presentation/src/main/res/layout/activity_edit_trip.xml +++ b/presentation/src/main/res/layout/activity_edit_trip.xml @@ -7,14 +7,14 @@ + type="com.going.presentation.todo.edittrip.edit.EditTripViewModel" /> + tools:context=".todo.edittrip.edit.EditTripActivity"> + type="com.going.presentation.todo.edittrip.info.EditTripInfoViewModel" /> + tools:context=".todo.edittrip.info.EditTripInfoActivity"> 수정하기 선택하기 %1$d.%2$d.%3$d + 여행 정보 수정되었어요 + 여행 정보 수정에 실패했어요 From 257cd3f8a8aae0d4856f0967a7a2150f6213c8e2 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:27:16 +0900 Subject: [PATCH 15/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B7=B0=20=EC=84=9C=EB=B2=84=ED=86=B5?= =?UTF-8?q?=EC=8B=A0=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/edittrip/info/EditDateBottomSheet.kt | 41 +++---- .../info}/EditTripInfoActivity.kt | 105 ++++++++++-------- .../edittrip/info/EditTripInfoViewModel.kt | 11 +- .../res/layout/activity_edit_trip_info.xml | 7 +- 4 files changed, 96 insertions(+), 68 deletions(-) rename presentation/src/main/java/com/going/presentation/todo/{editinfo => edittrip/info}/EditTripInfoActivity.kt (51%) diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt index f77244d0..097af7e2 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt @@ -30,15 +30,12 @@ class EditDateBottomSheet(val isStart: Boolean) : val calendar = Calendar.getInstance() val datePicker = binding.dpEditTripDate.apply { updateDate( - calendar.get(Calendar.YEAR), - calendar.get(Calendar.MONTH), - calendar.get(Calendar.DAY_OF_MONTH) + viewModel.currentStartYear.value ?: calendar.get(Calendar.YEAR), + (viewModel.currentStartMonth.value ?: calendar.get(Calendar.MONTH)) - 1, + viewModel.currentStartDay.value ?: calendar.get(Calendar.DAY_OF_MONTH) ) } - calendar.set(2000, 0, 1) - datePicker.minDate = calendar.timeInMillis - - if (viewModel.endYear.value != null && viewModel.endMonth.value != null && viewModel.endDay.value != null) { + if (viewModel.endYear.value != viewModel.currentEndYear.value || viewModel.endMonth.value != viewModel.currentEndMonth.value || viewModel.endDay.value != viewModel.currentEndDay.value) { calendar.set( viewModel.endYear.value ?: 0, (viewModel.endMonth.value ?: 0) - 1, @@ -52,17 +49,24 @@ class EditDateBottomSheet(val isStart: Boolean) : } private fun customEndDate() { - binding.dpEditTripDate.apply { - minDate = Calendar.getInstance().apply { - set( - viewModel.startYear.value ?: 0, - (viewModel.startMonth.value ?: 0) - 1, - viewModel.startDay.value ?: 0 - ) - }.timeInMillis - maxDate = Calendar.getInstance().apply { - set(2100, 0, 1) - }.timeInMillis + val calendar = Calendar.getInstance() + val datePicker = binding.dpEditTripDate.apply { + updateDate( + viewModel.currentEndYear.value ?: calendar.get(Calendar.YEAR), + (viewModel.currentEndMonth.value ?: calendar.get(Calendar.MONTH)) - 1, + viewModel.currentEndDay.value ?: calendar.get(Calendar.DAY_OF_MONTH) + ) + } + if (viewModel.startYear.value != viewModel.currentStartYear.value || viewModel.startMonth.value != viewModel.currentStartMonth.value || viewModel.startDay.value != viewModel.currentStartDay.value) { + calendar.set( + viewModel.startYear.value ?: 0, + (viewModel.startMonth.value ?: 0) - 1, + viewModel.startDay.value ?: 0 + ) + datePicker.minDate = calendar.timeInMillis + } else { + calendar.set(2000, 0, 1) + datePicker.minDate = calendar.timeInMillis } } @@ -71,7 +75,6 @@ class EditDateBottomSheet(val isStart: Boolean) : if (isStart) { viewModel.setStartDate(year, month + 1, dayOfMonth) } else { - customEndDate() viewModel.setEndDate(year, month + 1, dayOfMonth) } } diff --git a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt similarity index 51% rename from presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt rename to presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt index dbd3c446..47b84ead 100644 --- a/presentation/src/main/java/com/going/presentation/todo/editinfo/EditTripInfoActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt @@ -1,18 +1,22 @@ -package com.going.presentation.todo.editinfo +package com.going.presentation.todo.edittrip.info +import android.app.Activity import android.content.Context import android.content.Intent import android.os.Bundle import androidx.activity.viewModels import androidx.core.widget.doAfterTextChanged +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope import com.going.presentation.R import com.going.presentation.dashboard.DashBoardActivity import com.going.presentation.databinding.ActivityEditTripInfoBinding -import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.toast import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach @AndroidEntryPoint class EditTripInfoActivity : @@ -26,7 +30,8 @@ class EditTripInfoActivity : super.onCreate(savedInstanceState) initBindingViewModel() - getServerList() + getTripInfoData() + observePatchEditState() setEtInfoNameArguments() observeInfoNameTextChanged() initStartDateClickListener() @@ -39,16 +44,45 @@ class EditTripInfoActivity : binding.viewModel = viewModel } - private fun getServerList() { - val title = intent.getStringExtra(INFO_TITLE) - val startDate = intent.getStringExtra(INFO_START_DATE) - val endDate = intent.getStringExtra(INFO_END_DATE) + private fun getTripInfoData() { + viewModel.tripId = intent.getLongExtra(TRIP_ID, -1L) + val currentTitle = intent.getStringExtra(TITLE) + viewModel.currentStartDate = intent.getStringExtra(START_DATE) ?: "" + viewModel.currentEndDate = intent.getStringExtra(END_DATE) ?: "" + + //binding.etEditTripInfoName.editText.setText(currentTitle) + + val (startYear, startMonth, startDay) = splitDate(viewModel.currentStartDate) + viewModel.currentStartYear.value = startYear + viewModel.currentStartMonth.value = startMonth + viewModel.currentStartDay.value = startDay + viewModel.setStartDate(startYear,startMonth,startDay) + + val (endYear, endMonth, endDay) = splitDate(viewModel.currentEndDate) + viewModel.currentEndYear.value = endYear + viewModel.currentEndMonth.value = endMonth + viewModel.currentEndDay.value = endDay + viewModel.setEndDate(endYear,endMonth,endDay) + } - with(binding) { - etEditTripInfoName.editText?.setText(title) - tvEditTripInfoStartDate.text = startDate - tvEditTripInfoEndDate.text = endDate - } + fun splitDate(date: String): Triple { + val parts = date.split(".") + val year = parts[0].toInt() + val month = parts[1].toInt() + val day = parts[2].toInt() + return Triple(year, month, day) + } + + private fun observePatchEditState() { + viewModel.tripEditState.flowWithLifecycle(lifecycle).onEach { result -> + if (result) { + toast(getString(R.string.edit_trip_toast_success)) + setResult(Activity.RESULT_OK) + finish() + return@onEach + } + toast(getString(R.string.edit_trip_toast_failure)) + }.launchIn(lifecycleScope) } private fun setEtInfoNameArguments() { @@ -62,7 +96,7 @@ class EditTripInfoActivity : private fun observeInfoNameTextChanged() { binding.etEditTripInfoName.editText.doAfterTextChanged { text -> - viewModel.setNameState(text.toString(), binding.etEditTripInfoName.state) + viewModel.setTitleState(text.toString(), binding.etEditTripInfoName.state) } } @@ -76,60 +110,43 @@ class EditTripInfoActivity : private fun initEndDateClickListener() { binding.tvEditTripInfoEndDate.setOnSingleClickListener { - if (viewModel.startYear.value != null && viewModel.startMonth.value != null && viewModel.startDay.value != null) { endBottomSheetDialog = EditDateBottomSheet(false) endBottomSheetDialog?.show(supportFragmentManager, endBottomSheetDialog?.tag) - } else { - toast(getString(R.string.create_trip_toast_error)) - } } } private fun initEditBtnClickListener() { binding.btnEditTripSave.setOnSingleClickListener { - Intent(this, DashBoardActivity::class.java).apply { - putExtra(NAME, viewModel.name.value) - putExtra(START_YEAR, viewModel.startYear.value) - putExtra(START_MONTH, viewModel.startMonth.value) - putExtra(START_DAY, viewModel.startDay.value) - putExtra(END_YEAR, viewModel.endYear.value) - putExtra(END_MONTH, viewModel.endMonth.value) - putExtra(END_DAY, viewModel.endDay.value) - addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(this) - } + viewModel.patchTodoToServer() + val intent = Intent(this, DashBoardActivity::class.java) + startActivity(intent) } } private fun initBackBtnClickListener() { binding.btnEditTripInfoBack.setOnSingleClickListener { - //다른 뷰로 이동 finish() } } companion object { - const val NAME = "name" - const val INFO_TITLE = "title" - const val START_YEAR = "startYear" - const val START_MONTH = "startMonth" - const val START_DAY = "startDay" - const val INFO_START_DATE = "INFO_START_DATE" - const val END_YEAR = "endYear" - const val END_MONTH = "endMonth" - const val END_DAY = "endDay" - const val INFO_END_DATE = "INFO_END_DATE" + const val TRIP_ID = "TRIP_ID" + const val TITLE = "TITLE" + const val START_DATE = "START_DATE" + const val END_DATE = "END_DATE" @JvmStatic fun createIntent( context: Context, + tripId: Long, title: String, startDate: String, - endDate: String, - ): Intent = Intent(context, EditTripActivity::class.java).apply { - putExtra(INFO_TITLE, title) - putExtra(INFO_START_DATE, startDate) - putExtra(INFO_END_DATE, endDate) + endDate: String + ): Intent = Intent(context, EditTripInfoActivity::class.java).apply { + putExtra(TRIP_ID, tripId) + putExtra(TITLE, title) + putExtra(START_DATE, startDate) + putExtra(END_DATE, endDate) } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt index 32c486f1..946860e0 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt @@ -21,7 +21,6 @@ class EditTripInfoViewModel @Inject constructor( private val _tripEditState = MutableSharedFlow() val tripEditState: SharedFlow = _tripEditState - var tripId: Long = 0 var currentTitle: String = "" @@ -30,6 +29,13 @@ class EditTripInfoViewModel @Inject constructor( val title = MutableLiveData() + var currentStartYear = MutableLiveData() + var currentStartMonth = MutableLiveData() + var currentStartDay = MutableLiveData() + var currentEndYear = MutableLiveData() + var currentEndMonth = MutableLiveData() + var currentEndDay = MutableLiveData() + val startYear = MutableLiveData() val startMonth = MutableLiveData() val startDay = MutableLiveData() @@ -70,6 +76,7 @@ class EditTripInfoViewModel @Inject constructor( fun setTitleState(newTitle: String, state: EditTextState) { title.value = newTitle isTitleAvailable.value = state == EditTextState.SUCCESS + checkTripAvailable() } fun setStartDate(year: Int, month: Int, day: Int) { @@ -109,7 +116,7 @@ class EditTripInfoViewModel @Inject constructor( fun checkTripAvailable() { //버튼 활성화 isCheckTripAvailable.value = - (currentTitle != title.value && currentStartDate != startDate.value && currentEndDate != endDate.value) + (currentTitle != title.value || currentStartDate != startDate.value || currentEndDate != endDate.value) } companion object { diff --git a/presentation/src/main/res/layout/activity_edit_trip_info.xml b/presentation/src/main/res/layout/activity_edit_trip_info.xml index f0a75b3b..fc12ca94 100644 --- a/presentation/src/main/res/layout/activity_edit_trip_info.xml +++ b/presentation/src/main/res/layout/activity_edit_trip_info.xml @@ -48,6 +48,7 @@ + - From 15fe07262b39810c86e718a201e91a55b3f06ce8 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Sat, 9 Mar 2024 23:50:30 +0900 Subject: [PATCH 16/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B7=B0=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/edittrip/edit/EditTripActivity.kt | 1 + .../todo/edittrip/edit/EditTripViewModel.kt | 8 +++++--- .../todo/edittrip/info/EditTripInfoActivity.kt | 13 ++++++++++--- .../todo/edittrip/info/EditTripInfoViewModel.kt | 11 +++++++---- .../src/main/res/layout/activity_edit_trip.xml | 4 ++-- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt index ca401dc7..41bce63c 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt @@ -52,6 +52,7 @@ class EditTripActivity : tvEditTripName.text = viewModel?.title tvEditTripInfoStartDate.text = viewModel?.startDate tvEditTripInfoEndDate.text = viewModel?.endDate + viewModel?.gettitleLength() } } diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt index 2f482cca..f9beae7d 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.going.domain.entity.response.TripInfoModel import com.going.domain.repository.EditTripRepository +import com.going.ui.extension.getGraphemeLength import com.going.ui.state.UiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow @@ -16,8 +17,7 @@ import javax.inject.Inject class EditTripViewModel @Inject constructor( private val editTripRepository: EditTripRepository ) : ViewModel() { - val name = MutableLiveData() - val nameLength = MutableLiveData(0) + val titleLength = MutableLiveData(0) val startYear = MutableLiveData() val startMonth = MutableLiveData() @@ -36,13 +36,15 @@ class EditTripViewModel @Inject constructor( private val _tripInfoState = MutableStateFlow>(UiState.Empty) val tripInfoState: StateFlow> get() = _tripInfoState + fun gettitleLength(){ + titleLength.value = title.getGraphemeLength() + } fun getTripInfoFromServer(tripId: Long) { _tripInfoState.value = UiState.Loading viewModelScope.launch { editTripRepository.getTripInfo(tripId) .onSuccess { - //tripId = it.tripId title = it.title startDate = it.startDate endDate = it.endDate diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt index 47b84ead..7f23f75c 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt @@ -30,10 +30,10 @@ class EditTripInfoActivity : super.onCreate(savedInstanceState) initBindingViewModel() - getTripInfoData() observePatchEditState() setEtInfoNameArguments() observeInfoNameTextChanged() + getTripInfoData() initStartDateClickListener() initEndDateClickListener() initEditBtnClickListener() @@ -46,11 +46,11 @@ class EditTripInfoActivity : private fun getTripInfoData() { viewModel.tripId = intent.getLongExtra(TRIP_ID, -1L) - val currentTitle = intent.getStringExtra(TITLE) + viewModel.currentTitle = intent.getStringExtra(TITLE) ?:"" viewModel.currentStartDate = intent.getStringExtra(START_DATE) ?: "" viewModel.currentEndDate = intent.getStringExtra(END_DATE) ?: "" - //binding.etEditTripInfoName.editText.setText(currentTitle) + binding.etEditTripInfoName.editText.setText(viewModel.currentTitle) val (startYear, startMonth, startDay) = splitDate(viewModel.currentStartDate) viewModel.currentStartYear.value = startYear @@ -98,6 +98,7 @@ class EditTripInfoActivity : binding.etEditTripInfoName.editText.doAfterTextChanged { text -> viewModel.setTitleState(text.toString(), binding.etEditTripInfoName.state) } + viewModel.checkTripAvailable() } @@ -106,6 +107,9 @@ class EditTripInfoActivity : startBottomSheetDialog = EditDateBottomSheet(true) startBottomSheetDialog?.show(supportFragmentManager, startBottomSheetDialog?.tag) } + viewModel.checkStartDateAvailable() + viewModel.checkTripAvailable() + } private fun initEndDateClickListener() { @@ -113,6 +117,9 @@ class EditTripInfoActivity : endBottomSheetDialog = EditDateBottomSheet(false) endBottomSheetDialog?.show(supportFragmentManager, endBottomSheetDialog?.tag) } + viewModel.checkEndDateAvailable() + viewModel.checkTripAvailable() + } private fun initEditBtnClickListener() { diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt index 946860e0..e8879508 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt @@ -16,7 +16,7 @@ import javax.inject.Inject @HiltViewModel class EditTripInfoViewModel @Inject constructor( private val editTripRepository: EditTripRepository, - ) : ViewModel() { +) : ViewModel() { private val _tripEditState = MutableSharedFlow() val tripEditState: SharedFlow = _tripEditState @@ -114,9 +114,12 @@ class EditTripInfoViewModel @Inject constructor( } } - fun checkTripAvailable() { //버튼 활성화 - isCheckTripAvailable.value = - (currentTitle != title.value || currentStartDate != startDate.value || currentEndDate != endDate.value) + fun checkTripAvailable() { + isCheckTripAvailable.value = !title.value.isNullOrEmpty() && ( + (title.value != null && currentTitle != title.value) || + currentStartDate != startDate.value || + currentEndDate != endDate.value + ) } companion object { diff --git a/presentation/src/main/res/layout/activity_edit_trip.xml b/presentation/src/main/res/layout/activity_edit_trip.xml index 947277c3..ffc67fff 100644 --- a/presentation/src/main/res/layout/activity_edit_trip.xml +++ b/presentation/src/main/res/layout/activity_edit_trip.xml @@ -69,7 +69,7 @@ android:paddingVertical="16dp" android:background="@drawable/shape_rect_4_gray700_line" android:maxLines="3" - android:text="@={viewModel.name}" + android:text="@={viewModel.title}" android:textAppearance="@style/TextAppearance.Doorip.Body3.Medi" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -80,7 +80,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" - android:text="@{@string/counter(viewModel.nameLength, viewModel.MAX_TRIP_LEN)}" + android:text="@{@string/counter(viewModel.titleLength, viewModel.MAX_TRIP_LEN)}" android:textColor="@color/gray_400" app:layout_constraintEnd_toEndOf="@id/tv_edit_trip_name" app:layout_constraintTop_toBottomOf="@id/tv_edit_trip_name" /> From f0b6e81ac41d8dc86e3fda0cddc4d7952b8a6964 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Sun, 10 Mar 2024 00:34:25 +0900 Subject: [PATCH 17/19] =?UTF-8?q?[FEAT/#230]=20=EC=97=AC=ED=96=89=20?= =?UTF-8?q?=EB=82=98=EA=B0=80=EA=B8=B0=20=EB=B7=B0=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=ED=86=B5=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/EditTripDataSource.kt | 4 +++ .../datasourceImpl/EditTripDataSourceImpl.kt | 6 ++++ .../repositoryImpl/EditTripRepositoryImpl.kt | 9 +++++ .../com/going/data/service/EditTripService.kt | 6 ++++ .../domain/repository/EditTripRepository.kt | 3 ++ ...gFragment.kt => QuitTripDialogFragment.kt} | 15 +++++--- .../todo/edittrip/edit/EditTripActivity.kt | 34 ++++++++++++------- .../todo/edittrip/edit/EditTripViewModel.kt | 19 +++++++++++ .../edittrip/info/EditTripInfoActivity.kt | 12 +++---- .../edittrip/info/EditTripInfoViewModel.kt | 2 +- ...alog.xml => fragment_quit_trip_dialog.xml} | 0 presentation/src/main/res/values/strings.xml | 4 ++- 12 files changed, 89 insertions(+), 25 deletions(-) rename presentation/src/main/java/com/going/presentation/todo/edittrip/{TripQuitDialogFragment.kt => QuitTripDialogFragment.kt} (61%) rename presentation/src/main/res/layout/{fragment_trip_quit_dialog.xml => fragment_quit_trip_dialog.xml} (100%) diff --git a/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt index ecb1d655..7e80a6b6 100644 --- a/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt +++ b/data/src/main/java/com/going/data/datasource/EditTripDataSource.kt @@ -15,4 +15,8 @@ interface EditTripDataSource { request: EditTripInfoRequestDto ): NonDataBaseResponse + suspend fun patchQuitTrip( + tripId: Long + ): NonDataBaseResponse + } \ No newline at end of file diff --git a/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt b/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt index a6b5a3d4..9bec20fe 100644 --- a/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt +++ b/data/src/main/java/com/going/data/datasourceImpl/EditTripDataSourceImpl.kt @@ -23,4 +23,10 @@ class EditTripDataSourceImpl @Inject constructor( ): NonDataBaseResponse = editTripService.patchEditTripInfo( tripId, request ) + + override suspend fun patchQuitTrip( + tripId: Long + ): NonDataBaseResponse = editTripService.patchQuitTrip( + tripId + ) } \ No newline at end of file diff --git a/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt index 7939ee69..944fd63c 100644 --- a/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt +++ b/data/src/main/java/com/going/data/repositoryImpl/EditTripRepositoryImpl.kt @@ -25,4 +25,13 @@ class EditTripRepositoryImpl @Inject constructor( tripId, request.toEditTrioRequestDto() ) } + + override suspend fun patchQuitTrip( + tripId: Long + ): Result = + runCatching { + editTripDataSource.patchQuitTrip( + tripId + ) + } } diff --git a/data/src/main/java/com/going/data/service/EditTripService.kt b/data/src/main/java/com/going/data/service/EditTripService.kt index e0bcdf21..61965143 100644 --- a/data/src/main/java/com/going/data/service/EditTripService.kt +++ b/data/src/main/java/com/going/data/service/EditTripService.kt @@ -21,4 +21,10 @@ interface EditTripService { @Path("tripId") tripId: Long, @Body request: EditTripInfoRequestDto, ): NonDataBaseResponse + + @PATCH("api/trips/{tripId}/leave") + suspend fun patchQuitTrip( + @Path("tripId") tripId: Long, + ): NonDataBaseResponse + } \ No newline at end of file diff --git a/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt index e710230f..57cf023f 100644 --- a/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt +++ b/domain/src/main/kotlin/com/going/domain/repository/EditTripRepository.kt @@ -12,4 +12,7 @@ interface EditTripRepository { tripId: Long, request: EditTripRequestModel ): Result + suspend fun patchQuitTrip( + tripId: Long + ): Result } \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/TripQuitDialogFragment.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/QuitTripDialogFragment.kt similarity index 61% rename from presentation/src/main/java/com/going/presentation/todo/edittrip/TripQuitDialogFragment.kt rename to presentation/src/main/java/com/going/presentation/todo/edittrip/QuitTripDialogFragment.kt index 93dca53e..ddaeb6ad 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/TripQuitDialogFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/QuitTripDialogFragment.kt @@ -1,16 +1,21 @@ package com.going.presentation.todo.edittrip +import android.content.Intent import android.os.Bundle import android.view.View import android.view.WindowManager +import androidx.fragment.app.activityViewModels import com.going.presentation.R -import com.going.presentation.databinding.FragmentTripQuitDialogBinding +import com.going.presentation.dashboard.DashBoardActivity +import com.going.presentation.databinding.FragmentQuitTripDialogBinding +import com.going.presentation.todo.edittrip.edit.EditTripViewModel import com.going.ui.base.BaseDialog import com.going.ui.extension.setOnSingleClickListener -class TripQuitDialogFragment : - BaseDialog(R.layout.fragment_trip_quit_dialog) { +class QuitTripDialogFragment : + BaseDialog(R.layout.fragment_quit_trip_dialog) { + private val viewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -37,7 +42,9 @@ class TripQuitDialogFragment : private fun initNegativeClickListener() { binding.tvDialogNegative.setOnSingleClickListener { - //대시보드 뷰로 이동 + viewModel.patchQuitTripFromServer() + val intent = Intent(requireActivity(), DashBoardActivity::class.java) + startActivity(intent) } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt index 41bce63c..ab33a6ba 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripActivity.kt @@ -1,5 +1,6 @@ package com.going.presentation.todo.edittrip.edit +import android.app.Activity import android.os.Bundle import androidx.activity.viewModels import androidx.lifecycle.flowWithLifecycle @@ -7,7 +8,7 @@ import androidx.lifecycle.lifecycleScope import com.going.presentation.R import com.going.presentation.databinding.ActivityEditTripBinding import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID -import com.going.presentation.todo.edittrip.TripQuitDialogFragment +import com.going.presentation.todo.edittrip.QuitTripDialogFragment import com.going.presentation.todo.edittrip.info.EditTripInfoActivity import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener @@ -21,7 +22,7 @@ import kotlinx.coroutines.flow.onEach class EditTripActivity : BaseActivity(R.layout.activity_edit_trip) { private val viewModel by viewModels() - private var quitDialog: TripQuitDialogFragment? = null + private var quitDialog: QuitTripDialogFragment? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -29,9 +30,9 @@ class EditTripActivity : initBindingViewModel() getIntentData() observeTripinfoState() + observePatchQuitState() initEditBtnClickListener() initQuitBtnClickListener() - //showQuitDialog() initBackBtnClickListener() } @@ -66,9 +67,21 @@ class EditTripActivity : }.launchIn(lifecycleScope) } + private fun observePatchQuitState() { + viewModel.quittripState.flowWithLifecycle(lifecycle).onEach { result -> + if (result) { + toast(getString(R.string.quit_trip_toast_success)) + setResult(Activity.RESULT_OK) + finish() + return@onEach + } + toast(getString(R.string.quit_trip_toast_failure)) + }.launchIn(lifecycleScope) + } + private fun initQuitBtnClickListener() { binding.btnEditTripQuit.setOnSingleClickListener { - //showQuitDialog() + showQuitDialog() } } @@ -86,18 +99,13 @@ class EditTripActivity : } } -// private fun showQuitDialog() { -// quitDialog = TripQuitDialogFragment() -// quitDialog?.show(supportFragmentManager, quitDialog?.tag) -// Intent(this, DashBoardActivity::class.java).apply { -// //정보 지워지게 구성 -// startActivity(this) -// } -// } + private fun showQuitDialog() { + quitDialog = QuitTripDialogFragment() + quitDialog?.show(supportFragmentManager, quitDialog?.tag) + } private fun initBackBtnClickListener() { binding.btnEditTripInfoBack.setOnSingleClickListener { - //어느 뷰로 가는지 finish() } } diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt index f9beae7d..7e3fd8e9 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/edit/EditTripViewModel.kt @@ -8,7 +8,9 @@ import com.going.domain.repository.EditTripRepository import com.going.ui.extension.getGraphemeLength import com.going.ui.state.UiState import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -36,6 +38,9 @@ class EditTripViewModel @Inject constructor( private val _tripInfoState = MutableStateFlow>(UiState.Empty) val tripInfoState: StateFlow> get() = _tripInfoState + private val _quittripState = MutableSharedFlow() + val quittripState: SharedFlow = _quittripState + fun gettitleLength(){ titleLength.value = title.getGraphemeLength() } @@ -56,6 +61,20 @@ class EditTripViewModel @Inject constructor( } } + fun patchQuitTripFromServer() { + viewModelScope.launch { + editTripRepository.patchQuitTrip( + tripId + ) + .onSuccess { + _quittripState.emit(true) + } + .onFailure { + _quittripState.emit(false) + } + } + } + companion object { const val MAX_TRIP_LEN = 15 } diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt index 7f23f75c..8fe06740 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt @@ -46,7 +46,7 @@ class EditTripInfoActivity : private fun getTripInfoData() { viewModel.tripId = intent.getLongExtra(TRIP_ID, -1L) - viewModel.currentTitle = intent.getStringExtra(TITLE) ?:"" + viewModel.currentTitle = intent.getStringExtra(TITLE) ?: "" viewModel.currentStartDate = intent.getStringExtra(START_DATE) ?: "" viewModel.currentEndDate = intent.getStringExtra(END_DATE) ?: "" @@ -56,13 +56,13 @@ class EditTripInfoActivity : viewModel.currentStartYear.value = startYear viewModel.currentStartMonth.value = startMonth viewModel.currentStartDay.value = startDay - viewModel.setStartDate(startYear,startMonth,startDay) + viewModel.setStartDate(startYear, startMonth, startDay) val (endYear, endMonth, endDay) = splitDate(viewModel.currentEndDate) viewModel.currentEndYear.value = endYear viewModel.currentEndMonth.value = endMonth viewModel.currentEndDay.value = endDay - viewModel.setEndDate(endYear,endMonth,endDay) + viewModel.setEndDate(endYear, endMonth, endDay) } fun splitDate(date: String): Triple { @@ -114,8 +114,8 @@ class EditTripInfoActivity : private fun initEndDateClickListener() { binding.tvEditTripInfoEndDate.setOnSingleClickListener { - endBottomSheetDialog = EditDateBottomSheet(false) - endBottomSheetDialog?.show(supportFragmentManager, endBottomSheetDialog?.tag) + endBottomSheetDialog = EditDateBottomSheet(false) + endBottomSheetDialog?.show(supportFragmentManager, endBottomSheetDialog?.tag) } viewModel.checkEndDateAvailable() viewModel.checkTripAvailable() @@ -124,7 +124,7 @@ class EditTripInfoActivity : private fun initEditBtnClickListener() { binding.btnEditTripSave.setOnSingleClickListener { - viewModel.patchTodoToServer() + viewModel.patchTripInfoFromServer() val intent = Intent(this, DashBoardActivity::class.java) startActivity(intent) } diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt index e8879508..356c790d 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt @@ -54,7 +54,7 @@ class EditTripInfoViewModel @Inject constructor( fun getMaxTripLen() = MAX_TRIP_LEN - fun patchTodoToServer() { + fun patchTripInfoFromServer() { viewModelScope.launch { editTripRepository.patchEditTripInfo( tripId, diff --git a/presentation/src/main/res/layout/fragment_trip_quit_dialog.xml b/presentation/src/main/res/layout/fragment_quit_trip_dialog.xml similarity index 100% rename from presentation/src/main/res/layout/fragment_trip_quit_dialog.xml rename to presentation/src/main/res/layout/fragment_quit_trip_dialog.xml diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 10e61de1..b03ea805 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -253,5 +253,7 @@ 여행 정보 수정되었어요 여행 정보 수정에 실패했어요 - + + 여행방에서 나왔어요 + 여행방에서 나오지 못했어요 From b24abe3641c5d5ec05c2eda3abf5008a6eaccbaa Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Sun, 10 Mar 2024 01:51:04 +0900 Subject: [PATCH 18/19] =?UTF-8?q?[FEAT/#230]=20=EC=98=A4=EB=A5=98=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 --- .../entertrip/invitetrip/finish/InviteFinishActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presentation/src/main/java/com/going/presentation/entertrip/invitetrip/finish/InviteFinishActivity.kt b/presentation/src/main/java/com/going/presentation/entertrip/invitetrip/finish/InviteFinishActivity.kt index ac2c1a69..6a7f1f53 100644 --- a/presentation/src/main/java/com/going/presentation/entertrip/invitetrip/finish/InviteFinishActivity.kt +++ b/presentation/src/main/java/com/going/presentation/entertrip/invitetrip/finish/InviteFinishActivity.kt @@ -80,7 +80,7 @@ class InviteFinishActivity : startDate: String, endDate: String, day: Int, - ): Intent = Intent(context, EnterTripActivity::class.java).apply { + ): Intent = Intent(context, InviteFinishActivity::class.java).apply { putExtra(TRIP_ID, tripId) putExtra(TITLE, title) putExtra(START, startDate) From 460c2b9a4f9fe63f6591c577c24c4e91b00b94b1 Mon Sep 17 00:00:00 2001 From: Seyeon CHO <135544903+crownjoe@users.noreply.github.com> Date: Sun, 10 Mar 2024 16:14:19 +0900 Subject: [PATCH 19/19] =?UTF-8?q?[CHORE/#230]=20=EC=BD=94=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/edittrip/QuitTripDialogFragment.kt | 5 +- .../todo/edittrip/info/EditDateBottomSheet.kt | 28 +++---- .../edittrip/info/EditTripInfoActivity.kt | 35 ++------ .../edittrip/info/EditTripInfoViewModel.kt | 84 +++++++++++++------ .../res/layout/activity_edit_trip_info.xml | 1 - 5 files changed, 83 insertions(+), 70 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/QuitTripDialogFragment.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/QuitTripDialogFragment.kt index ddaeb6ad..329576ed 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/QuitTripDialogFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/QuitTripDialogFragment.kt @@ -43,8 +43,9 @@ class QuitTripDialogFragment : private fun initNegativeClickListener() { binding.tvDialogNegative.setOnSingleClickListener { viewModel.patchQuitTripFromServer() - val intent = Intent(requireActivity(), DashBoardActivity::class.java) - startActivity(intent) + Intent(requireActivity(), DashBoardActivity::class.java).apply { + requireActivity().startActivity(this) + } } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt index 097af7e2..e63b53e6 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditDateBottomSheet.kt @@ -30,16 +30,16 @@ class EditDateBottomSheet(val isStart: Boolean) : val calendar = Calendar.getInstance() val datePicker = binding.dpEditTripDate.apply { updateDate( - viewModel.currentStartYear.value ?: calendar.get(Calendar.YEAR), - (viewModel.currentStartMonth.value ?: calendar.get(Calendar.MONTH)) - 1, - viewModel.currentStartDay.value ?: calendar.get(Calendar.DAY_OF_MONTH) + viewModel.currentStartYear ?: calendar.get(Calendar.YEAR), + (viewModel.currentStartMonth ?: calendar.get(Calendar.MONTH)) - 1, + viewModel.currentStartDay ?: calendar.get(Calendar.DAY_OF_MONTH) ) } - if (viewModel.endYear.value != viewModel.currentEndYear.value || viewModel.endMonth.value != viewModel.currentEndMonth.value || viewModel.endDay.value != viewModel.currentEndDay.value) { + if (viewModel.endYear != viewModel.currentEndYear || viewModel.endMonth != viewModel.currentEndMonth || viewModel.endDay != viewModel.currentEndDay) { calendar.set( - viewModel.endYear.value ?: 0, - (viewModel.endMonth.value ?: 0) - 1, - viewModel.endDay.value ?: 0 + viewModel.endYear ?: 0, + (viewModel.endMonth ?: 0) - 1, + viewModel.endDay ?: 0 ) datePicker.maxDate = calendar.timeInMillis } else { @@ -52,16 +52,16 @@ class EditDateBottomSheet(val isStart: Boolean) : val calendar = Calendar.getInstance() val datePicker = binding.dpEditTripDate.apply { updateDate( - viewModel.currentEndYear.value ?: calendar.get(Calendar.YEAR), - (viewModel.currentEndMonth.value ?: calendar.get(Calendar.MONTH)) - 1, - viewModel.currentEndDay.value ?: calendar.get(Calendar.DAY_OF_MONTH) + viewModel.currentEndYear ?: calendar.get(Calendar.YEAR), + (viewModel.currentEndMonth ?: calendar.get(Calendar.MONTH)) - 1, + viewModel.currentEndDay ?: calendar.get(Calendar.DAY_OF_MONTH) ) } - if (viewModel.startYear.value != viewModel.currentStartYear.value || viewModel.startMonth.value != viewModel.currentStartMonth.value || viewModel.startDay.value != viewModel.currentStartDay.value) { + if (viewModel.startYear != viewModel.currentStartYear || viewModel.startMonth != viewModel.currentStartMonth || viewModel.startDay != viewModel.currentStartDay) { calendar.set( - viewModel.startYear.value ?: 0, - (viewModel.startMonth.value ?: 0) - 1, - viewModel.startDay.value ?: 0 + viewModel.startYear ?: 0, + (viewModel.startMonth ?: 0) - 1, + viewModel.startDay ?: 0 ) datePicker.minDate = calendar.timeInMillis } else { diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt index 8fe06740..fefae519 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoActivity.kt @@ -51,26 +51,8 @@ class EditTripInfoActivity : viewModel.currentEndDate = intent.getStringExtra(END_DATE) ?: "" binding.etEditTripInfoName.editText.setText(viewModel.currentTitle) - - val (startYear, startMonth, startDay) = splitDate(viewModel.currentStartDate) - viewModel.currentStartYear.value = startYear - viewModel.currentStartMonth.value = startMonth - viewModel.currentStartDay.value = startDay - viewModel.setStartDate(startYear, startMonth, startDay) - - val (endYear, endMonth, endDay) = splitDate(viewModel.currentEndDate) - viewModel.currentEndYear.value = endYear - viewModel.currentEndMonth.value = endMonth - viewModel.currentEndDay.value = endDay - viewModel.setEndDate(endYear, endMonth, endDay) - } - - fun splitDate(date: String): Triple { - val parts = date.split(".") - val year = parts[0].toInt() - val month = parts[1].toInt() - val day = parts[2].toInt() - return Triple(year, month, day) + viewModel.splitStartDate() + viewModel.splitEndDate() } private fun observePatchEditState() { @@ -125,8 +107,9 @@ class EditTripInfoActivity : private fun initEditBtnClickListener() { binding.btnEditTripSave.setOnSingleClickListener { viewModel.patchTripInfoFromServer() - val intent = Intent(this, DashBoardActivity::class.java) - startActivity(intent) + Intent(this, DashBoardActivity::class.java).apply { + startActivity(this) + } } } @@ -137,10 +120,10 @@ class EditTripInfoActivity : } companion object { - const val TRIP_ID = "TRIP_ID" - const val TITLE = "TITLE" - const val START_DATE = "START_DATE" - const val END_DATE = "END_DATE" + private const val TRIP_ID = "TRIP_ID" + private const val TITLE = "TITLE" + private const val START_DATE = "START_DATE" + private const val END_DATE = "END_DATE" @JvmStatic fun createIntent( diff --git a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt index 356c790d..2dce5af1 100644 --- a/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/edittrip/info/EditTripInfoViewModel.kt @@ -27,23 +27,23 @@ class EditTripInfoViewModel @Inject constructor( var currentStartDate: String = "" var currentEndDate: String = "" - val title = MutableLiveData() - - var currentStartYear = MutableLiveData() - var currentStartMonth = MutableLiveData() - var currentStartDay = MutableLiveData() - var currentEndYear = MutableLiveData() - var currentEndMonth = MutableLiveData() - var currentEndDay = MutableLiveData() - - val startYear = MutableLiveData() - val startMonth = MutableLiveData() - val startDay = MutableLiveData() + var title: String? = null + + var currentStartYear: Int? = null + var currentStartMonth: Int? = null + var currentStartDay: Int? = null + var currentEndYear: Int? = null + var currentEndMonth: Int? = null + var currentEndDay: Int? = null + + var startYear: Int? = null + var startMonth: Int? = null + var startDay: Int? = null var startDate = MutableLiveData() - val endYear = MutableLiveData() - val endMonth = MutableLiveData() - val endDay = MutableLiveData() + var endYear: Int? = null + var endMonth: Int? = null + var endDay: Int? = null var endDate = MutableLiveData() val isStartDateAvailable = MutableLiveData(false) @@ -59,7 +59,7 @@ class EditTripInfoViewModel @Inject constructor( editTripRepository.patchEditTripInfo( tripId, EditTripRequestModel( - title = title.value.orEmpty(), + title = title.orEmpty(), startDate = startDate.value.orEmpty(), endDate = endDate.value.orEmpty() ) @@ -73,31 +73,61 @@ class EditTripInfoViewModel @Inject constructor( } } + fun splitStartDate() { + val (startYear, startMonth, startDay) = splitDate(currentStartDate) + currentStartYear = startYear + currentStartMonth = startMonth + currentStartDay = startDay + setStartDate(startYear, startMonth, startDay) + + val (endYear, endMonth, endDay) = splitDate(currentEndDate) + currentEndYear = endYear + currentEndMonth = endMonth + currentEndDay = endDay + setEndDate(endYear, endMonth, endDay) + } + + fun splitEndDate() { + val (endYear, endMonth, endDay) = splitDate(currentEndDate) + currentEndYear = endYear + currentEndMonth = endMonth + currentEndDay = endDay + setEndDate(endYear, endMonth, endDay) + } + + fun splitDate(date: String): Triple { + val parts = date.split(".") + val year = parts[0].toInt() + val month = parts[1].toInt() + val day = parts[2].toInt() + return Triple(year, month, day) + } + fun setTitleState(newTitle: String, state: EditTextState) { - title.value = newTitle + title = newTitle isTitleAvailable.value = state == EditTextState.SUCCESS checkTripAvailable() } fun setStartDate(year: Int, month: Int, day: Int) { - startYear.value = year - startMonth.value = month - startDay.value = day + startYear = year + startMonth = month + startDay = day checkStartDateAvailable() startDate.value = String.format("%04d.%02d.%02d", year, month, day) } fun setEndDate(year: Int, month: Int, day: Int) { - endYear.value = year - endMonth.value = month - endDay.value = day + endYear = year + endMonth = month + endDay = day checkEndDateAvailable() endDate.value = String.format("%04d.%02d.%02d", year, month, day) } fun checkStartDateAvailable() { - if (startYear.value != null && startMonth.value != null && startDay.value != null) { + if (startYear != null && startMonth != null && startDay != null) { isStartDateAvailable.value = true checkTripAvailable() } else { @@ -106,7 +136,7 @@ class EditTripInfoViewModel @Inject constructor( } fun checkEndDateAvailable() { - if (endYear.value != null && endMonth.value != null && endDay.value != null) { + if (endYear != null && endMonth != null && endDay != null) { isEndDateAvailable.value = true checkTripAvailable() } else { @@ -115,8 +145,8 @@ class EditTripInfoViewModel @Inject constructor( } fun checkTripAvailable() { - isCheckTripAvailable.value = !title.value.isNullOrEmpty() && ( - (title.value != null && currentTitle != title.value) || + isCheckTripAvailable.value = !title.isNullOrEmpty() && ( + (title != null && currentTitle != title) || currentStartDate != startDate.value || currentEndDate != endDate.value ) diff --git a/presentation/src/main/res/layout/activity_edit_trip_info.xml b/presentation/src/main/res/layout/activity_edit_trip_info.xml index fc12ca94..fa832ce5 100644 --- a/presentation/src/main/res/layout/activity_edit_trip_info.xml +++ b/presentation/src/main/res/layout/activity_edit_trip_info.xml @@ -58,7 +58,6 @@ app:canBlankError="true" app:hint="@string/edit_trip_info_et_name_hint" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tb_edit_trip_info" app:title="@string/edit_trip_info_tv_title" />