diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dc4668b..6892ea0c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -157,4 +157,4 @@ - + \ No newline at end of file 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 3eed8192..bbe9b82e 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.EnterPreferenceDataSource import com.going.data.datasource.EnterTripDataSource import com.going.data.datasource.MockDataSource import com.going.data.datasource.ProfileDataSource @@ -11,6 +12,7 @@ import com.going.data.datasource.TendencyDataSource import com.going.data.datasource.TodoDataSource import com.going.data.datasourceImpl.AuthDataSourceImpl import com.going.data.datasourceImpl.DashBoardDataSourceImpl +import com.going.data.datasourceImpl.EnterPreferenceDataSourceImpl import com.going.data.datasourceImpl.EnterTripDataSourceImpl import com.going.data.datasourceImpl.MockDataSourceImpl import com.going.data.datasourceImpl.ProfileDataSourceImpl @@ -65,11 +67,16 @@ object DataSourceModule { @Provides @Singleton - fun provideEnterTripDataSource(entertripDataSourceImpl: EnterTripDataSourceImpl): EnterTripDataSource = - entertripDataSourceImpl + fun provideEnterTripDataSource(enterTripDataSourceImpl: EnterTripDataSourceImpl): EnterTripDataSource = + enterTripDataSourceImpl @Provides @Singleton fun provideStartInviteTripDataSource(startInviteTripDataSourceImpl: StartInviteTripDataSourceImpl): StartInviteTripDataSource = startInviteTripDataSourceImpl + + @Provides + @Singleton + fun provideEnterPreferenceDataSource(enterPreferenceDataSourceImpl: EnterPreferenceDataSourceImpl): EnterPreferenceDataSource = + enterPreferenceDataSourceImpl } 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 a41ae448..918f751a 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.EnterPreferenceRepositoryImpl import com.going.data.repositoryImpl.EnterTripRepositoryImpl import com.going.data.repositoryImpl.MockRepositoryImpl import com.going.data.repositoryImpl.ProfileRepositoryImpl @@ -12,6 +13,7 @@ import com.going.data.repositoryImpl.TodoRepositoryImpl import com.going.data.repositoryImpl.TokenRepositoryImpl import com.going.domain.repository.AuthRepository import com.going.domain.repository.DashBoardRepository +import com.going.domain.repository.EnterPreferenceRepository import com.going.domain.repository.EnterTripRepository import com.going.domain.repository.MockRepository import com.going.domain.repository.ProfileRepository @@ -79,4 +81,9 @@ object RepositoryModule { @Singleton fun provideStartInviteTripRepository(startInviteTripRepositoryImpl: StartInviteTripRepositoryImpl): StartInviteTripRepository = startInviteTripRepositoryImpl + + @Provides + @Singleton + fun provideEnterPreferenceRepository(enterPreferenceRepositoryImpl: EnterPreferenceRepositoryImpl): EnterPreferenceRepository = + enterPreferenceRepositoryImpl } 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 b53b0056..0b92f490 100644 --- a/app/src/main/java/com/going/doorip/di/ServiceModule.kt +++ b/app/src/main/java/com/going/doorip/di/ServiceModule.kt @@ -1,8 +1,8 @@ package com.going.doorip.di -import android.provider.ContactsContract.Profile import com.going.data.service.AuthService import com.going.data.service.DashBoardService +import com.going.data.service.EnterPreferenceService import com.going.data.service.EnterTripService import com.going.data.service.MockService import com.going.data.service.ProfileService @@ -65,4 +65,9 @@ object ServiceModule { @Singleton fun provideStartInviteTripService(retrofit: Retrofit): StartInviteTripService = retrofit.create(StartInviteTripService::class.java) + + @Provides + @Singleton + fun provideEnterPreferenceService(retrofit: Retrofit): EnterPreferenceService = + retrofit.create(EnterPreferenceService::class.java) } diff --git a/data/src/main/java/com/going/data/datasource/EnterPreferenceDataSource.kt b/data/src/main/java/com/going/data/datasource/EnterPreferenceDataSource.kt new file mode 100644 index 00000000..1c2d6b19 --- /dev/null +++ b/data/src/main/java/com/going/data/datasource/EnterPreferenceDataSource.kt @@ -0,0 +1,13 @@ +package com.going.data.datasource + +import com.going.data.dto.BaseResponse +import com.going.data.dto.request.EnterPreferenceRequestDto +import com.going.data.dto.response.EnterPreferenceResponseDto +import retrofit2.http.Body + +interface EnterPreferenceDataSource { + suspend fun postTripInfo( + @Body request: EnterPreferenceRequestDto + ): BaseResponse + +} \ No newline at end of file diff --git a/data/src/main/java/com/going/data/datasourceImpl/DashBoardDataSourceImpl.kt b/data/src/main/java/com/going/data/datasourceImpl/DashBoardDataSourceImpl.kt index 6bafedb2..757c1fc8 100644 --- a/data/src/main/java/com/going/data/datasourceImpl/DashBoardDataSourceImpl.kt +++ b/data/src/main/java/com/going/data/datasourceImpl/DashBoardDataSourceImpl.kt @@ -10,7 +10,9 @@ class DashBoardDataSourceImpl @Inject constructor( private val dashBoardService: DashBoardService ) : DashBoardDataSource { - override suspend fun getTripList(progress: String): BaseResponse = + override suspend fun getTripList( + progress: String + ): BaseResponse = dashBoardService.getTripList(progress) } diff --git a/data/src/main/java/com/going/data/datasourceImpl/EnterPreferenceDataSourceImpl.kt b/data/src/main/java/com/going/data/datasourceImpl/EnterPreferenceDataSourceImpl.kt new file mode 100644 index 00000000..e733520d --- /dev/null +++ b/data/src/main/java/com/going/data/datasourceImpl/EnterPreferenceDataSourceImpl.kt @@ -0,0 +1,19 @@ +package com.going.data.datasourceImpl + +import com.going.data.datasource.EnterPreferenceDataSource +import com.going.data.dto.BaseResponse +import com.going.data.dto.request.EnterPreferenceRequestDto +import com.going.data.dto.response.EnterPreferenceResponseDto +import com.going.data.service.EnterPreferenceService +import javax.inject.Inject + +class EnterPreferenceDataSourceImpl @Inject constructor( + private val enterPreferenceService: EnterPreferenceService +) : EnterPreferenceDataSource { + + override suspend fun postTripInfo( + request: EnterPreferenceRequestDto + ): BaseResponse = + enterPreferenceService.postTripInfoFromServer(request) + +} \ No newline at end of file diff --git a/data/src/main/java/com/going/data/interceptor/AuthInterceptor.kt b/data/src/main/java/com/going/data/dto/interceptor/AuthInterceptor.kt similarity index 96% rename from data/src/main/java/com/going/data/interceptor/AuthInterceptor.kt rename to data/src/main/java/com/going/data/dto/interceptor/AuthInterceptor.kt index e64eb1b7..da83d5e7 100644 --- a/data/src/main/java/com/going/data/interceptor/AuthInterceptor.kt +++ b/data/src/main/java/com/going/data/dto/interceptor/AuthInterceptor.kt @@ -84,8 +84,8 @@ class AuthInterceptor @Inject constructor( return response } - private fun Request.newAuthBuilder() = - this.newBuilder().addHeader(AUTHORIZATION, "$BEARER ${dataStore.accessToken}") + private fun Request.newAuthBuilder() = + this.newBuilder().addHeader(AUTHORIZATION, "$BEARER ${dataStore.accessToken}") companion object { private const val CODE_TOKEN_EXPIRED = 401 diff --git a/data/src/main/java/com/going/data/dto/request/EnterPreferenceRequestDto.kt b/data/src/main/java/com/going/data/dto/request/EnterPreferenceRequestDto.kt new file mode 100644 index 00000000..4a073215 --- /dev/null +++ b/data/src/main/java/com/going/data/dto/request/EnterPreferenceRequestDto.kt @@ -0,0 +1,28 @@ +package com.going.data.dto.request + +import com.going.domain.entity.request.EnterPreferenceRequestModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class EnterPreferenceRequestDto( + @SerialName("title") + val title: String, + @SerialName("startDate") + val startDate: String, + @SerialName("endDate") + val endDate: String, + @SerialName("styleA") + val styleA: Int, + @SerialName("styleB") + val styleB: Int, + @SerialName("styleC") + val styleC: Int, + @SerialName("styleD") + val styleD: Int, + @SerialName("styleE") + val styleE: Int +) + +fun EnterPreferenceRequestModel.toEnterPreferenceRequestDto(): EnterPreferenceRequestDto = + EnterPreferenceRequestDto(title, startDate, endDate, styleA, styleB, styleC, styleD, styleE) diff --git a/data/src/main/java/com/going/data/dto/request/EnterTripRequestDto.kt b/data/src/main/java/com/going/data/dto/request/EnterTripRequestDto.kt index 963d3604..c75d44f8 100644 --- a/data/src/main/java/com/going/data/dto/request/EnterTripRequestDto.kt +++ b/data/src/main/java/com/going/data/dto/request/EnterTripRequestDto.kt @@ -12,4 +12,3 @@ data class EnterTripRequestDto( fun EnterTripRequestModel.toEnterTripRequestDto(): EnterTripRequestDto = EnterTripRequestDto(code) - diff --git a/data/src/main/java/com/going/data/dto/response/EnterPreferenceResponseDto.kt b/data/src/main/java/com/going/data/dto/response/EnterPreferenceResponseDto.kt new file mode 100644 index 00000000..4bf4b10c --- /dev/null +++ b/data/src/main/java/com/going/data/dto/response/EnterPreferenceResponseDto.kt @@ -0,0 +1,24 @@ +package com.going.data.dto.response + +import com.going.domain.entity.response.EnterPreferenceModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class EnterPreferenceResponseDto( + @SerialName("tripId") + val tripId: Long, + @SerialName("title") + val title: String, + @SerialName("startDate") + val startDate: String, + @SerialName("endDate") + val endDate: String, + @SerialName("code") + val code: String, + @SerialName("day") + val day: Int, +) { + fun toEnterPreferenceModel() = + EnterPreferenceModel(tripId, title, startDate, endDate, code, day) +} diff --git a/data/src/main/java/com/going/data/repositoryImpl/EnterPreferenceRepositoryImpl.kt b/data/src/main/java/com/going/data/repositoryImpl/EnterPreferenceRepositoryImpl.kt new file mode 100644 index 00000000..c5764c90 --- /dev/null +++ b/data/src/main/java/com/going/data/repositoryImpl/EnterPreferenceRepositoryImpl.kt @@ -0,0 +1,23 @@ +package com.going.data.repositoryImpl + +import com.going.data.datasource.EnterPreferenceDataSource +import com.going.data.dto.request.toEnterPreferenceRequestDto +import com.going.domain.entity.request.EnterPreferenceRequestModel +import com.going.domain.entity.response.EnterPreferenceModel +import com.going.domain.repository.EnterPreferenceRepository +import javax.inject.Inject + +class EnterPreferenceRepositoryImpl @Inject constructor( + private val enterPreferenceDataSource: EnterPreferenceDataSource +) : EnterPreferenceRepository { + + override suspend fun postTripInfo( + request: EnterPreferenceRequestModel + ): Result = + runCatching { + enterPreferenceDataSource.postTripInfo( + request.toEnterPreferenceRequestDto(), + ).data.toEnterPreferenceModel() + } + +} diff --git a/data/src/main/java/com/going/data/service/EnterPreferenceService.kt b/data/src/main/java/com/going/data/service/EnterPreferenceService.kt new file mode 100644 index 00000000..0f547484 --- /dev/null +++ b/data/src/main/java/com/going/data/service/EnterPreferenceService.kt @@ -0,0 +1,16 @@ +package com.going.data.service + +import com.going.data.dto.BaseResponse +import com.going.data.dto.request.EnterPreferenceRequestDto +import com.going.data.dto.response.EnterPreferenceResponseDto +import retrofit2.http.Body +import retrofit2.http.POST + +interface EnterPreferenceService { + + @POST("api/trips") + suspend fun postTripInfoFromServer( + @Body request: EnterPreferenceRequestDto, + ): BaseResponse + +} \ No newline at end of file diff --git a/domain/src/main/kotlin/com/going/domain/entity/request/EnterPreferenceRequestModel.kt b/domain/src/main/kotlin/com/going/domain/entity/request/EnterPreferenceRequestModel.kt new file mode 100644 index 00000000..83d5ccf1 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/request/EnterPreferenceRequestModel.kt @@ -0,0 +1,12 @@ +package com.going.domain.entity.request + +data class EnterPreferenceRequestModel( + val title: String, + val startDate: String, + val endDate: String, + val styleA: Int, + val styleB: Int, + val styleC: Int, + val styleD: Int, + val styleE: Int +) \ No newline at end of file diff --git a/domain/src/main/kotlin/com/going/domain/entity/response/EnterPreferenceModel.kt b/domain/src/main/kotlin/com/going/domain/entity/response/EnterPreferenceModel.kt new file mode 100644 index 00000000..5c6ecea1 --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/entity/response/EnterPreferenceModel.kt @@ -0,0 +1,10 @@ +package com.going.domain.entity.response + +data class EnterPreferenceModel( + val tripId: Long, + val title: String, + val startDate: String, + val endDate: String, + val code: String, + val day: Int +) \ No newline at end of file diff --git a/domain/src/main/kotlin/com/going/domain/repository/EnterPreferenceRepository.kt b/domain/src/main/kotlin/com/going/domain/repository/EnterPreferenceRepository.kt new file mode 100644 index 00000000..ff9c984f --- /dev/null +++ b/domain/src/main/kotlin/com/going/domain/repository/EnterPreferenceRepository.kt @@ -0,0 +1,12 @@ +package com.going.domain.repository + +import com.going.domain.entity.request.EnterPreferenceRequestModel +import com.going.domain.entity.response.EnterPreferenceModel + +interface EnterPreferenceRepository { + + suspend fun postTripInfo( + request: EnterPreferenceRequestModel + ): Result + +} \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/dashboard/DashBoardActivity.kt b/presentation/src/main/java/com/going/presentation/dashboard/DashBoardActivity.kt index 6b4d73bd..6ede4803 100644 --- a/presentation/src/main/java/com/going/presentation/dashboard/DashBoardActivity.kt +++ b/presentation/src/main/java/com/going/presentation/dashboard/DashBoardActivity.kt @@ -1,10 +1,13 @@ package com.going.presentation.dashboard +import android.content.Intent import android.os.Bundle import androidx.activity.viewModels import com.going.presentation.R import com.going.presentation.databinding.ActivityTripDashBoardBinding +import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity import com.going.ui.base.BaseActivity +import com.going.ui.extension.setOnSingleClickListener import com.google.android.material.tabs.TabLayoutMediator import dagger.hilt.android.AndroidEntryPoint @@ -22,6 +25,7 @@ class DashBoardActivity : setTabLayout() setViewPager() setTravelerName() + initCreateTripBtnClickListener() } @@ -51,6 +55,18 @@ class DashBoardActivity : } } + private fun initCreateTripBtnClickListener() { + binding.btnDashboardCreateTrip.setOnSingleClickListener { + navigateToDashboard() + } + } + + private fun navigateToDashboard() { + Intent(this, CreateTripActivity::class.java).apply { + startActivity(this) + } + } + companion object { const val TAB_ONGOING = "진행중인 여행" const val TAB_COMPLETED = "지나간 여행" diff --git a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/BottomSheetDateContentFragment.kt b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/BottomSheetDateContentFragment.kt index 2383950f..06c36a79 100644 --- a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/BottomSheetDateContentFragment.kt +++ b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/BottomSheetDateContentFragment.kt @@ -53,7 +53,7 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS calendar.set(Calendar.DAY_OF_MONTH, viewModel.endDay.value ?: 0) val endDate = calendar.time - if(startDate.before(endDate)) { + if (startDate.before(endDate)) { dismiss() } else { toast(getString(R.string.create_trip_toast_error)) diff --git a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterPreferenceActivity.kt b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterPreferenceActivity.kt index 9fe6e946..4b88f291 100644 --- a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterPreferenceActivity.kt +++ b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterPreferenceActivity.kt @@ -1,14 +1,19 @@ package com.going.presentation.entertrip.starttrip.createtrip +import android.content.Intent import android.os.Bundle import androidx.activity.viewModels import androidx.core.content.ContextCompat +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope import com.going.domain.entity.PreferenceData import com.going.presentation.R import com.going.presentation.databinding.ActivityEnterPreferenceBinding -import com.going.presentation.preferencetag.PreferenceTagAdapter -import com.going.presentation.preferencetag.PreferenceTagDecoration -import com.going.presentation.preferencetag.PreferenceTagViewModel +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.CODE +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.DAY +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.END +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.START +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.TITLE import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity.Companion.END_DAY import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity.Companion.END_MONTH import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity.Companion.END_YEAR @@ -16,9 +21,17 @@ import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity. import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity.Companion.START_DAY import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity.Companion.START_MONTH import com.going.presentation.entertrip.starttrip.invitetrip.CreateTripActivity.Companion.START_YEAR +import com.going.presentation.preferencetag.PreferenceTagAdapter +import com.going.presentation.preferencetag.PreferenceTagDecoration import com.going.ui.base.BaseActivity +import com.going.ui.extension.UiState 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 EnterPreferenceActivity : BaseActivity(R.layout.activity_enter_preference), PreferenceTagAdapter.OnPreferenceSelectedListener { @@ -26,13 +39,14 @@ class EnterPreferenceActivity : private var _adapter: PreferenceTagAdapter? = null private val adapter get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) } - private val viewModel by viewModels() + private val viewModel by viewModels() private val preferenceAnswers = MutableList(5) { Int.MAX_VALUE } private var title: String? = "" private var startDate: String? = "" private var endDate: String? = "" + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -40,7 +54,8 @@ class EnterPreferenceActivity : initItemDecoration() initBackClickListener() getCreateTripInfo() - sendStyleInfo() + initStartBtnClickListener() + observeEnterPreferenceListState() } @@ -57,7 +72,7 @@ class EnterPreferenceActivity : private fun initBackClickListener() { binding.btnPreferenceStart.setOnSingleClickListener { - sendStyleInfo() + finish() } } @@ -73,30 +88,69 @@ class EnterPreferenceActivity : } private fun getCreateTripInfo() { - val serverList = getIntent() + val infoList = getIntent() - if (serverList != null) { + if (infoList != null) { title = intent.getStringExtra(NAME) val startYear = intent.getIntExtra(START_YEAR, 0) - val startMonth = intent.getIntExtra(START_MONTH, 0) - val startDay = intent.getIntExtra(START_DAY, 0) + val startMonth = String.format(TWO_DIGIT_FORMAT, intent.getIntExtra(START_MONTH, 0)) + val startDay = String.format(TWO_DIGIT_FORMAT, intent.getIntExtra(START_DAY, 0)) val endYear = intent.getIntExtra(END_YEAR, 0) - val endMonth = intent.getIntExtra(END_MONTH, 0) - val endDay = intent.getIntExtra(END_DAY, 0) + val endMonth = String.format(TWO_DIGIT_FORMAT, intent.getIntExtra(END_MONTH, 0)) + val endDay = String.format(TWO_DIGIT_FORMAT, intent.getIntExtra(END_DAY, 0)) - startDate = String.format(SERVER_DATE, startYear, startMonth, startDay) + startDate = + String.format(SERVER_DATE, startYear, startMonth, startDay) endDate = String.format(SERVER_DATE, endYear, endMonth, endDay) } } - private fun sendStyleInfo() { - var styleA = preferenceAnswers[0] + private fun initStartBtnClickListener() { + binding.btnPreferenceStart.setOnSingleClickListener { + viewModel.getTripInfoFromServer() + } + } + + private fun observeEnterPreferenceListState() { + viewModel.enterPreferenceListState.flowWithLifecycle(lifecycle).onEach { state -> + when (state) { + is UiState.Success -> { + Intent(this, FinishTripActivity::class.java).apply { + putExtra(TITLE, state.data.title) + putExtra(START, state.data.startDate) + putExtra(END, state.data.endDate) + putExtra(CODE, state.data.code) + putExtra(DAY, state.data.day) + startActivity(this) + } + } + + is UiState.Failure -> toast(getString(R.string.server_error)) + + is UiState.Loading -> return@onEach + + is UiState.Empty -> return@onEach + + } + }.launchIn(lifecycleScope) + } + + private fun sendTripInfo() { + viewModel.title.value = title + viewModel.startDate.value = startDate + viewModel.endDate.value = endDate + viewModel.styleA.value = preferenceAnswers[0] + viewModel.styleB.value = preferenceAnswers[1] + viewModel.styleC.value = preferenceAnswers[2] + viewModel.styleD.value = preferenceAnswers[3] + viewModel.styleE.value = preferenceAnswers[4] } override fun onPreferenceSelected(item: PreferenceData, checkList: Int) { preferenceAnswers[item.number.toInt() - 1] = checkList isButtonValid() + sendTripInfo() } override fun onDestroy() { @@ -106,5 +160,6 @@ class EnterPreferenceActivity : companion object { const val SERVER_DATE = "%s.%s.%s" + const val TWO_DIGIT_FORMAT = "%02d" } -} +} \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterPreferenceViewModel.kt b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterPreferenceViewModel.kt new file mode 100644 index 00000000..23eb4b92 --- /dev/null +++ b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterPreferenceViewModel.kt @@ -0,0 +1,92 @@ +package com.going.presentation.entertrip.starttrip.createtrip + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.going.domain.entity.PreferenceData +import com.going.domain.entity.request.EnterPreferenceRequestModel +import com.going.domain.entity.response.EnterPreferenceModel +import com.going.domain.repository.EnterPreferenceRepository +import com.going.ui.extension.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 EnterPreferenceViewModel @Inject constructor( + private val enterPreferenceRepository: EnterPreferenceRepository +) : ViewModel() { + + private val _enterPreferenceListState = + MutableStateFlow>(UiState.Empty) + val enterPreferenceListState: StateFlow> get() = _enterPreferenceListState + + val title = MutableLiveData("") + val startDate = MutableLiveData("") + val endDate = MutableLiveData("") + val styleA = MutableLiveData(0) + val styleB = MutableLiveData(0) + val styleC = MutableLiveData(0) + val styleD = MutableLiveData(0) + val styleE = MutableLiveData(0) + + fun getTripInfoFromServer() { + _enterPreferenceListState.value = UiState.Loading + viewModelScope.launch { + enterPreferenceRepository.postTripInfo( + EnterPreferenceRequestModel( + title.value ?: "", + startDate.value ?: "", + endDate.value ?: "", + styleA.value ?: 0, + styleB.value ?: 0, + styleC.value ?: 0, + styleD.value ?: 0, + styleE.value ?: 0 + ) + ) + .onSuccess { + _enterPreferenceListState.value = UiState.Success(it) + } + .onFailure { + _enterPreferenceListState.value = UiState.Failure(it.message.orEmpty()) + } + } + } + + val preferenceTagList = listOf( + PreferenceData( + number = "01", + question = "계획은 어느정도로 세울까요?", + leftPrefer = "철저하게", + rightPrefer = "즉흥으로" + ), + PreferenceData( + number = "02", + question = "장소선택의 기준은 무엇인가요?", + leftPrefer = "관광지", + rightPrefer = "로컬장소" + ), + PreferenceData( + number = "03", + question = "어느 식당을 갈까요?", + leftPrefer = "유명 맛집", + rightPrefer = "가까운 곳" + ), + PreferenceData( + number = "04", + question = "기억하고 싶은 순간에!", + leftPrefer = "사진 필수", + rightPrefer = "눈에 담기" + ), + PreferenceData( + number = "05", + question = "하루 일정을 어떻게 채우나요?", + leftPrefer = "알차게", + rightPrefer = "여유롭게" + ), + ) + +} \ No newline at end of file diff --git a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterTripActivity.kt b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterTripActivity.kt index 6f2c7ac4..56b4e273 100644 --- a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/EnterTripActivity.kt @@ -10,8 +10,8 @@ import androidx.lifecycle.lifecycleScope import com.going.domain.entity.CodeState import com.going.presentation.R import com.going.presentation.databinding.ActivityEnterTripBinding -import com.going.presentation.entertrip.starttrip.invitetrip.InviteFinishActivity import com.going.presentation.entertrip.starttrip.StartTripSplashActivity +import com.going.presentation.entertrip.starttrip.invitetrip.InviteFinishActivity import com.going.ui.base.BaseActivity import com.going.ui.extension.UiState import com.going.ui.extension.setOnSingleClickListener @@ -123,6 +123,7 @@ class EnterTripActivity : BaseActivity(R.layout.activi const val TITLE = "title" const val START = "start" const val END = "end" + const val CODE = "code" const val DAY = "day" } diff --git a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/FinishTripActivity.kt b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/FinishTripActivity.kt index e443b854..d89fa2b3 100644 --- a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/FinishTripActivity.kt +++ b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/FinishTripActivity.kt @@ -5,30 +5,40 @@ import android.content.ClipboardManager 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.ActivityFinishTripBinding +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.DAY +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.END +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.START +import com.going.presentation.entertrip.starttrip.createtrip.EnterTripActivity.Companion.TITLE +import com.going.presentation.entertrip.starttrip.invitetrip.InviteFinishActivity.Companion.DATE_FORMAT +import com.going.presentation.entertrip.starttrip.invitetrip.InviteFinishActivity.Companion.D_DAY_FORMAT +import com.going.presentation.entertrip.starttrip.invitetrip.InviteFinishActivity.Companion.TRIP_FORMAT import com.going.ui.base.BaseActivity import com.going.ui.extension.setOnSingleClickListener +import com.kakao.sdk.auth.Constants.CODE class FinishTripActivity : BaseActivity(R.layout.activity_finish_trip) { - private val viewModel by viewModels() + + private var inviteCode: String? = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + getTripInfo() initCopyCodetvClickListener() initSendCodeBtnClickListener() initEnterTripBtnClickListener() - //checkDayLeft() + } private fun initCopyCodetvClickListener() { binding.tvFinishTripTermsText.setOnSingleClickListener { val clipboardManager = this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clipData = ClipData.newPlainText("INVITE_CODE_LABEL", viewModel.INVITE_CODE) + val clipData = ClipData.newPlainText("INVITE_CODE_LABEL", inviteCode) clipboardManager.setPrimaryClip(clipData) } } @@ -41,24 +51,34 @@ class FinishTripActivity : private fun initEnterTripBtnClickListener() { binding.btnFinishTripEnterTrip.setOnSingleClickListener { - Intent(this, EnterPreferenceActivity::class.java).apply { + Intent(this, DashBoardActivity::class.java).apply { startActivity(this) - //입장 코드 받아서 보내기 } finish() } } -// private fun checkDayLeft(){ -// 그 전 뷰에서 서버 붙여서 보내주는 day 값 알게 되면 맞게 로직 구현하겠습니다 -// if(dayLeft > 0) { -// binding.tvFinishTripDayLeft.text = dayLeft -// }else{ -// binding.tvFinishTripDayLeft.text = -// } -// } - companion object { - const val INVITE_CODE_LABEL = "Invite Code" + private fun getTripInfo() { + val intent = getIntent() + + if (intent != null) { + val title = intent.getStringExtra(TITLE) + val start = intent.getStringExtra(START) + val end = intent.getStringExtra(END) + val code = intent.getStringExtra(CODE) + val day = intent.getIntExtra(DAY, 0) + + binding.tvFinishTripName.text = title + binding.tvFinishTripDay.text = String.format(DATE_FORMAT, start, end) + binding.tvInviteCode.text = code + + if (day > 0) { + binding.tvFinishTripDayLeft.text = String.format(D_DAY_FORMAT, day) + } else { + binding.tvFinishTripDayLeft.text = TRIP_FORMAT + } + } } + } diff --git a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/FinishTripViewModel.kt b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/FinishTripViewModel.kt deleted file mode 100644 index 77c77819..00000000 --- a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/createtrip/FinishTripViewModel.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.going.presentation.entertrip.starttrip.createtrip - -import androidx.lifecycle.ViewModel - -class FinishTripViewModel : ViewModel(){ - val INVITE_CODE = "a1b2c3" -} - diff --git a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/invitetrip/CreateTripViewModel.kt b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/invitetrip/CreateTripViewModel.kt index 7052f6ef..bbbc8201 100644 --- a/presentation/src/main/java/com/going/presentation/entertrip/starttrip/invitetrip/CreateTripViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/entertrip/starttrip/invitetrip/CreateTripViewModel.kt @@ -75,7 +75,8 @@ class CreateTripViewModel : ViewModel() { } private fun checkTripAvailable() { - isCheckTripAvailable.value = (isTripAvailable.value == true && isStartDateAvailable.value == true && isEndDateAvailable.value == true) + isCheckTripAvailable.value = + (isTripAvailable.value == true && isStartDateAvailable.value == true && isEndDateAvailable.value == true) } diff --git a/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagAdapter.kt b/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagAdapter.kt index 89a1ec66..a5909c8b 100644 --- a/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagAdapter.kt +++ b/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagAdapter.kt @@ -1,12 +1,10 @@ package com.going.presentation.preferencetag import android.content.Context -import android.provider.MediaStore.Audio.Radio import android.view.LayoutInflater import android.view.ViewGroup -import android.widget.RadioButton -import com.going.domain.entity.PreferenceData import androidx.recyclerview.widget.ListAdapter +import com.going.domain.entity.PreferenceData import com.going.presentation.databinding.ItemPreferenceTagBinding import com.going.ui.extension.ItemDiffCallback @@ -19,7 +17,7 @@ class PreferenceTagAdapter( private val inflater by lazy { LayoutInflater.from(context) } interface OnPreferenceSelectedListener { - fun onPreferenceSelected(item: PreferenceData, checkedIndex: Int) + fun onPreferenceSelected(item: PreferenceData, checkedIndex: Int) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PreferenceTagViewHolder { diff --git a/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagDecoration.kt b/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagDecoration.kt index 3d179271..ba814fbc 100644 --- a/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagDecoration.kt +++ b/presentation/src/main/java/com/going/presentation/preferencetag/PreferenceTagDecoration.kt @@ -5,7 +5,7 @@ import android.graphics.Rect import android.view.View import androidx.recyclerview.widget.RecyclerView -class PreferenceTagDecoration (val context: Context) : RecyclerView.ItemDecoration() { +class PreferenceTagDecoration(val context: Context) : RecyclerView.ItemDecoration() { override fun getItemOffsets( outRect: Rect, diff --git a/presentation/src/main/res/drawable/sel_button_text_color_preference.xml b/presentation/src/main/res/drawable/sel_button_text_color_preference.xml deleted file mode 100644 index 5aa981d7..00000000 --- a/presentation/src/main/res/drawable/sel_button_text_color_preference.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/presentation/src/main/res/layout/activity_enter_preference.xml b/presentation/src/main/res/layout/activity_enter_preference.xml index 0be97a94..1ce217bd 100644 --- a/presentation/src/main/res/layout/activity_enter_preference.xml +++ b/presentation/src/main/res/layout/activity_enter_preference.xml @@ -5,11 +5,6 @@ - - - diff --git a/presentation/src/main/res/layout/activity_finish_preference.xml b/presentation/src/main/res/layout/activity_finish_preference.xml index a9c2ef7f..9db87d0c 100644 --- a/presentation/src/main/res/layout/activity_finish_preference.xml +++ b/presentation/src/main/res/layout/activity_finish_preference.xml @@ -80,7 +80,7 @@ android:enabled="false" android:outlineProvider="none" android:text="@string/preference_btn_finish" - android:textColor="@drawable/sel_button_text_color_preference" + android:textColor="@color/gray_200" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> diff --git a/presentation/src/main/res/layout/activity_finish_trip.xml b/presentation/src/main/res/layout/activity_finish_trip.xml index 659dcd7b..2cbf0494 100644 --- a/presentation/src/main/res/layout/activity_finish_trip.xml +++ b/presentation/src/main/res/layout/activity_finish_trip.xml @@ -5,9 +5,6 @@ - %s님의 여행 새로운 여행을 시작해 보세요 - 여행 생성하기 + 여행 추가하기 여행종료 - D - %d