diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7e8bc1cc..61710f96 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,10 +36,10 @@ android:name=".IntroActivity" android:exported="true" android:theme="@style/Theme.Eggeum.Splash"> - - - - + + + + diff --git a/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/PlaceEntity.kt b/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/PlaceEntity.kt index d174d138..bef0ef17 100644 --- a/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/PlaceEntity.kt +++ b/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/PlaceEntity.kt @@ -12,7 +12,7 @@ public data class PlaceEntity( val address2: String?, val id: Int?, val image: ImageEntity?, - val info: InfoEntity?, + var info: InfoEntity?, val latitude: Double?, val longitude: Double?, val menu: MenuEntity?, diff --git a/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/ProductEntity.kt b/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/ProductEntity.kt index 14b43418..5e2d99de 100644 --- a/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/ProductEntity.kt +++ b/domain/src/main/kotlin/us/wedemy/eggeum/android/domain/model/place/ProductEntity.kt @@ -8,6 +8,6 @@ package us.wedemy.eggeum.android.domain.model.place public data class ProductEntity( - val name: String, - val price: Int, + var name: String, + var price: Int, ) diff --git a/update-cafe/src/main/AndroidManifest.xml b/update-cafe/src/main/AndroidManifest.xml index 797dd979..a518df09 100644 --- a/update-cafe/src/main/AndroidManifest.xml +++ b/update-cafe/src/main/AndroidManifest.xml @@ -12,10 +12,10 @@ android:exported="true" android:theme="@style/Theme.Eggeum.UpdateCafe" android:windowSoftInputMode="adjustPan" > - - - - + + + + diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeInfoFragment.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeInfoFragment.kt index 3436cdd5..b6b32a68 100644 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeInfoFragment.kt +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeInfoFragment.kt @@ -21,7 +21,6 @@ import us.wedemy.eggeum.android.common.extension.repeatOnStarted import us.wedemy.eggeum.android.common.extension.safeNavigate import us.wedemy.eggeum.android.common.ui.BaseFragment import us.wedemy.eggeum.android.domain.model.place.InfoEntity -import us.wedemy.eggeum.android.domain.model.place.UpsertPlaceEntity import us.wedemy.eggeum.android.updatecafe.databinding.FragmentInputCafeInfoBinding import us.wedemy.eggeum.android.updatecafe.viewmodel.InputCafeInfoViewModel @@ -56,14 +55,10 @@ class InputCafeInfoFragment : BaseFragment() { } private fun initView() { - repeatOnStarted { - launch { - /** - * Intent에서 placeId 가져오기 - */ - viewModel.getPlaceBody(1) - } - } + /** + * Intent에서 placeId 가져오기 + */ + viewModel.getPlaceBody(1) } private fun initListener() { @@ -135,19 +130,15 @@ class InputCafeInfoFragment : BaseFragment() { singleSeatCount = stringToIntOrElseNull(cafeSingleSeat), websiteUri = stringOrElseNull(cafeWebsiteUri), ) + viewModel.placeBody.info = infoEntity - val upsertPlaceEntity = UpsertPlaceEntity.of( - info = infoEntity, - placeId = 1, - name = if (cafeName != "") cafeName else null, - ) - - viewModel.upsertPlaceBody(upsertPlaceEntity = upsertPlaceEntity) + viewModel.upsertPlaceBody() } } } - private fun stringToBoolean(str: String): Boolean { - return str == "O" + private fun stringToBoolean(str: String): Boolean? { + return if (str == "") null + else str == "O" } private fun stringOrElseNull(str: String): String? { @@ -163,31 +154,43 @@ class InputCafeInfoFragment : BaseFragment() { private fun initObserver() { repeatOnStarted { launch { - viewModel.uiState.collect { uiState -> + viewModel.cafeInfo.collect { cafeInfo -> with(binding) { - tietInputCafeArea.hint = stringOrElseGuideMessage(uiState.areaSize) - tietInputCafeMeetingRoom.hint = intToStringOrElseGuideMessage(uiState.meetingRoomCount) - tietInputCafeMultiSeat.hint = intToStringOrElseGuideMessage(uiState.multiSeatCount) - tietInputCafeSingleSeat.hint = intToStringOrElseGuideMessage(uiState.singleSeatCount) - tietInputCafeBusinessHours.hint = uiState.businessHours + tietInputCafeArea.hint = stringOrElseGuideMessage(cafeInfo.areaSize) + tietInputCafeMeetingRoom.hint = intToStringOrElseGuideMessage(cafeInfo.meetingRoomCount) + tietInputCafeMultiSeat.hint = intToStringOrElseGuideMessage(cafeInfo.multiSeatCount) + tietInputCafeSingleSeat.hint = intToStringOrElseGuideMessage(cafeInfo.singleSeatCount) + tietInputCafeBusinessHours.hint = cafeInfo.businessHours ?.joinToString(" ~ ", "", "", -1) ?: guideMessage - tietInputParking.hint = stringOrElseGuideMessage(uiState.parking) - tietInputExistsSmokingArea.hint = boolToStringOrElseGuideMessage(uiState.existsSmokingArea) - tietInputExistsWifi.hint = boolToStringOrElseGuideMessage(uiState.existsWifi) - tietInputRestRoom.hint = stringOrElseGuideMessage(uiState.restRoom) - tietInputMobileCharging.hint = stringOrElseGuideMessage(uiState.mobileCharging) - tietInputInstagramUri.hint = stringOrElseGuideMessage(uiState.instagramUri) - tietInputWebsiteUri.hint = stringOrElseGuideMessage(uiState.websiteUri) - tietInputBlogUri.hint = stringOrElseGuideMessage(uiState.blogUri) - tietInputPhone.hint = stringOrElseGuideMessage(uiState.phone) + tietInputParking.hint = stringOrElseGuideMessage(cafeInfo.parking) + tietInputExistsSmokingArea.hint = boolToStringOrElseGuideMessage(cafeInfo.existsSmokingArea) + tietInputExistsWifi.hint = boolToStringOrElseGuideMessage(cafeInfo.existsWifi) + tietInputRestRoom.hint = stringOrElseGuideMessage(cafeInfo.restRoom) + tietInputMobileCharging.hint = stringOrElseGuideMessage(cafeInfo.mobileCharging) + tietInputInstagramUri.hint = stringOrElseGuideMessage(cafeInfo.instagramUri) + tietInputWebsiteUri.hint = stringOrElseGuideMessage(cafeInfo.websiteUri) + tietInputBlogUri.hint = stringOrElseGuideMessage(cafeInfo.blogUri) + tietInputPhone.hint = stringOrElseGuideMessage(cafeInfo.phone) + + cafeArea = stringOrElseDefault(cafeInfo.areaSize) + cafeMeetingRoom = intToStringOrElseDefault(cafeInfo.meetingRoomCount) + cafeMultiSeat = intToStringOrElseDefault(cafeInfo.multiSeatCount) + cafeSingleSeat = intToStringOrElseDefault(cafeInfo.singleSeatCount) + cafeBusinessHours = cafeInfo.businessHours + ?.joinToString(" ~ ", "", "", -1) ?: "" + cafeParking = stringOrElseDefault(cafeInfo.parking) + cafeExistsSmokingArea = boolToStringOrElseDefault(cafeInfo.existsSmokingArea) + cafeExistsWifi = boolToStringOrElseDefault(cafeInfo.existsWifi) + cafeRestRoom = stringOrElseDefault(cafeInfo.restRoom) + cafeMobileCharging = stringOrElseDefault(cafeInfo.mobileCharging) + cafeWebsiteUri = stringOrElseDefault(cafeInfo.websiteUri) + cafeInstagramUri = stringOrElseDefault(cafeInfo.instagramUri) + cafeBlogUri = stringOrElseDefault(cafeInfo.blogUri) + cafePhone = stringOrElseDefault(cafeInfo.phone) } } } - launch { - viewModel.placeName.collect { - cafeName = it - } - } + launch { binding.apply { viewModel.navigateToUpsertEvent.collect { @@ -206,6 +209,20 @@ class InputCafeInfoFragment : BaseFragment() { } } + private fun stringOrElseDefault(str: String?): String { + return str ?: "" + } + + private fun intToStringOrElseDefault(int: Int?): String { + return int?.toString() ?: "" + } + + private fun boolToStringOrElseDefault(bool: Boolean?): String { + return if (bool == null) "" + else if (bool) "O" + else "X" + } + private fun stringOrElseGuideMessage(str: String?): String { return str ?: guideMessage } diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeMenuFragment.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeMenuFragment.kt index 205d37d7..43ab9413 100644 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeMenuFragment.kt +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/InputCafeMenuFragment.kt @@ -11,29 +11,42 @@ package us.wedemy.eggeum.android.updatecafe.ui import android.os.Bundle import android.view.View -import androidx.fragment.app.viewModels +import androidx.core.widget.doAfterTextChanged +import androidx.fragment.app.activityViewModels +import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import dagger.hilt.android.AndroidEntryPoint import us.wedemy.eggeum.android.common.ui.BaseFragment import us.wedemy.eggeum.android.updatecafe.databinding.FragmentInputCafeMenuBinding -import us.wedemy.eggeum.android.updatecafe.viewmodel.InputCafeMenuViewModel +import us.wedemy.eggeum.android.updatecafe.ui.item.CafeMenuItem +import us.wedemy.eggeum.android.updatecafe.viewmodel.ProposeCafeInfoViewModel @AndroidEntryPoint class InputCafeMenuFragment : BaseFragment() { override fun getViewBinding() = FragmentInputCafeMenuBinding.inflate(layoutInflater) - private val viewModel by viewModels() + private val viewModel by activityViewModels() private val args by navArgs() + private lateinit var newCafeMenuName: String + private lateinit var newCafeMenuPrice: String + + private val beforeAndAfterCafeMenuItem = mutableMapOf() + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + initView() initListener() initObserver() } override fun onStart() { super.onStart() - with(binding) { + beforeAndAfterCafeMenuItem["before"] = CafeMenuItem(name = args.cafeMenuItem.name, price = args.cafeMenuItem.price) + } + + private fun initView() { + binding.apply { tietInputCafeName.hint = args.cafeMenuItem.name tietInputCafePrice.hint = args.cafeMenuItem.price.toString() } @@ -41,8 +54,26 @@ class InputCafeMenuFragment : BaseFragment() { private fun initListener() { with(binding) { + tietInputCafeName.doAfterTextChanged { + newCafeMenuName = it.toString() + } + tietInputCafePrice.doAfterTextChanged { + newCafeMenuPrice = it.toString() + } + btnUpdateMenuComplete.setOnClickListener { - // TODO: 다시 이전 페이지로 돌아가기 + // TODO: 데이터 변경 후, 이전 Fragment에 전달하기 + beforeAndAfterCafeMenuItem["after"] = CafeMenuItem(name = newCafeMenuName, price = newCafeMenuPrice.toInt()) + viewModel.setCafeMenuItemMap(cafeMenuItemMap = beforeAndAfterCafeMenuItem) + + if (!findNavController().navigateUp()) { + requireActivity().finish() + } + } + tbSelectInputCafeMenu.setNavigationOnClickListener { + if (!findNavController().navigateUp()) { + requireActivity().finish() + } } } } diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/SelectCafeMenuFragment.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/SelectCafeMenuFragment.kt index fa042313..9a5a468a 100644 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/SelectCafeMenuFragment.kt +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/SelectCafeMenuFragment.kt @@ -15,11 +15,10 @@ import android.os.Bundle import android.view.View import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat -import androidx.fragment.app.viewModels +import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch -import timber.log.Timber import us.wedemy.eggeum.android.common.extension.repeatOnStarted import us.wedemy.eggeum.android.common.extension.safeNavigate import us.wedemy.eggeum.android.common.ui.BaseFragment @@ -27,7 +26,7 @@ import us.wedemy.eggeum.android.domain.model.place.ProductEntity import us.wedemy.eggeum.android.updatecafe.ui.adapter.CafeMenuAdapter import us.wedemy.eggeum.android.updatecafe.databinding.FragmentSelectCafeMenuBinding import us.wedemy.eggeum.android.updatecafe.ui.item.CafeMenuItem -import us.wedemy.eggeum.android.updatecafe.viewmodel.SelectCafeMenuViewModel +import us.wedemy.eggeum.android.updatecafe.viewmodel.ProposeCafeInfoViewModel interface EditOnClickListener { fun editBtnClickListener(cafeMenu: CafeMenuItem) @@ -43,12 +42,12 @@ class SelectCafeMenuFragment : BaseFragment() { CafeMenuAdapter( object : EditOnClickListener { override fun editBtnClickListener(cafeMenu: CafeMenuItem) { - // TODO: cafeMenu 데이터 넘겨주기 + // TODO: savedInstanceState 방법 알아보기 val action = SelectCafeMenuFragmentDirections.actionFragmentSelectCafeMenuToFragmentInputCafeMenu( CafeMenuItem( name = cafeMenu.name, price = cafeMenu.price, - ) + ), ) findNavController().safeNavigate(action) } @@ -63,7 +62,9 @@ class SelectCafeMenuFragment : BaseFragment() { override fun getViewBinding() = FragmentSelectCafeMenuBinding.inflate(layoutInflater) - private val viewModel by viewModels() + private val viewModel by activityViewModels() + + private var callCount = 0 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { initView() @@ -71,33 +72,27 @@ class SelectCafeMenuFragment : BaseFragment() { initObserver() } - override fun onStart() { - super.onStart() - // TODO: 지도에서 placdId 받아와서 인자 넣기 - viewModel.getCafeMenuList(1) - } - private fun showEditOrDeleteDialog(item: CafeMenuItem) { val dialog = AlertDialog.Builder(requireContext()) .setMessage("삭제 하시겠어요?") .setPositiveButton("삭제", object : OnClickListener { override fun onClick(p0: DialogInterface?, p1: Int) { - // TODO: 삭제 API 호출 + val newCafeMenuList = mutableListOf() val cafeMenuList = viewModel.cafeMenuList.value - val newCafeMenuList = mutableListOf() cafeMenuList.forEach { if (!(it.name == item.name && it.price == item.price)) { - newCafeMenuList.add(it.toEntity()) + newCafeMenuList.add(it) } } - viewModel.placeBody.menu?.products = newCafeMenuList + viewModel.placeBody.menu?.products = newCafeMenuList.map { it.toEntity() } val newPlaceBody = (viewModel.placeBody.menu?.products as MutableList) - val changedUiState = viewModel.initializeCafeMenuItem(products = newPlaceBody) - viewModel.updateCafeMenuList(productList = changedUiState) + val newCafeMenuItemList = viewModel.initializeCafeMenuItem(products = newPlaceBody) + viewModel.updateCafeMenuList(cafeMenuItemList = newCafeMenuItemList) } }) .setNegativeButton("취소", null) // 취소 시에는 동작 없음. .show() + // TODO: 피그마 디자인처럼 다이얼로그 디자인 변경하기 dialog.apply { getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(requireContext(), us.wedemy.eggeum.android.design.R.color.teal_500)) @@ -107,11 +102,17 @@ class SelectCafeMenuFragment : BaseFragment() { } private fun initView() { - with(binding) { - rvCafeMenuList.apply { - setHasFixedSize(true) - adapter = cafeMenuAdapter - } + // TODO: 지도에서 placdId 받아와서 인자 넣기 + if (callCount == 0) { + viewModel.getCafeMenuList(1) + callCount++ + } else { + viewModel.editCafeMenuItem() + } + + binding.rvCafeMenuList.apply { + setHasFixedSize(true) + adapter = cafeMenuAdapter } } @@ -134,11 +135,7 @@ class SelectCafeMenuFragment : BaseFragment() { private fun initObserver() { repeatOnStarted { launch { - viewModel.cafeMenuList.collect { cafeMenuList -> - val cafeMenu = cafeMenuList.map { it } - Timber.d("" + cafeMenu) - cafeMenuAdapter.replaceAll(cafeMenu) - } + viewModel.cafeMenuList.collect { cafeMenuAdapter.replaceAll(it) } } } } diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/UpdateCafeActivity.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/UpdateCafeActivity.kt index 91258f63..2a52a4d8 100644 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/UpdateCafeActivity.kt +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/UpdateCafeActivity.kt @@ -7,6 +7,7 @@ package us.wedemy.eggeum.android.updatecafe.ui +import androidx.activity.viewModels import androidx.navigation.fragment.findNavController import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -14,10 +15,14 @@ import us.wedemy.eggeum.android.common.ui.BaseActivity import us.wedemy.eggeum.android.navigator.MainNavigator import us.wedemy.eggeum.android.updatecafe.R import us.wedemy.eggeum.android.updatecafe.databinding.ActivityUpdateCafeBinding +import us.wedemy.eggeum.android.updatecafe.viewmodel.ProposeCafeInfoViewModel @AndroidEntryPoint class UpdateCafeActivity : BaseActivity() { override val binding by lazy { ActivityUpdateCafeBinding.inflate(layoutInflater) } + + val viewModel by viewModels() + private val navController get() = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.findNavController() diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/item/CafeInfoItem.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/item/CafeInfoItem.kt new file mode 100644 index 00000000..253c845e --- /dev/null +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/item/CafeInfoItem.kt @@ -0,0 +1,47 @@ + +/* + * Designed and developed by Wedemy 2023. + * + * Licensed under the MIT. + * Please see full license: https://github.com/Wedemy/eggeum-android/blob/main/LICENSE + */ + +package us.wedemy.eggeum.android.updatecafe.ui.item + +import us.wedemy.eggeum.android.domain.model.place.InfoEntity + +data class CafeInfoItem( + val areaSize: String? = null, + val blogUri: String? = null, + val businessHours: List? = null, + val existsSmokingArea: Boolean? = null, + val existsWifi: Boolean? = null, + val instagramUri: String? = null, + val meetingRoomCount: Int? = null, + val mobileCharging: String? = null, + val multiSeatCount: Int? = null, + val parking: String? = null, + val phone: String? = null, + val restRoom: String? = null, + val singleSeatCount: Int? = null, + val websiteUri: String? = null, +) { + fun toEntity(): InfoEntity { + return InfoEntity( + areaSize = areaSize, + blogUri = blogUri, + businessHours = businessHours, + existsSmokingArea = existsSmokingArea, + existsWifi = existsWifi, + instagramUri = instagramUri, + meetingRoomCount = meetingRoomCount, + mobileCharging = mobileCharging, + multiSeatCount = multiSeatCount, + parking = parking, + phone = phone, + restRoom = restRoom, + singleSeatCount = singleSeatCount, + websiteUri = websiteUri, + ) + } +} diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/item/CafeMenuItem.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/item/CafeMenuItem.kt index 8c94ab3c..5bf5fd20 100644 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/item/CafeMenuItem.kt +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/ui/item/CafeMenuItem.kt @@ -16,9 +16,9 @@ import us.wedemy.eggeum.android.domain.model.place.ProductEntity data class CafeMenuItem( val name: String, val price: Int, -): Parcelable { +) : Parcelable { fun toEntity(): ProductEntity = ProductEntity( name = name, price = price, ) -} \ No newline at end of file +} diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/InputCafeInfoViewModel.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/InputCafeInfoViewModel.kt index b01a6239..ac455cb2 100644 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/InputCafeInfoViewModel.kt +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/InputCafeInfoViewModel.kt @@ -21,37 +21,20 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import timber.log.Timber -import us.wedemy.eggeum.android.domain.model.place.UpsertPlaceEntity +import us.wedemy.eggeum.android.domain.model.place.PlaceEntity import us.wedemy.eggeum.android.domain.usecase.GetPlaceUseCase import us.wedemy.eggeum.android.domain.usecase.UpsertlaceBodyUseCase - -data class CafeInfoUiState( - val areaSize: String? = null, - val blogUri: String? = null, - val businessHours: List? = null, - val existsSmokingArea: Boolean? = null, - val existsWifi: Boolean? = null, - val instagramUri: String? = null, - val meetingRoomCount: Int? = null, - val mobileCharging: String? = null, - val multiSeatCount: Int? = null, - val parking: String? = null, - val phone: String? = null, - val restRoom: String? = null, - val singleSeatCount: Int? = null, - val websiteUri: String? = null, -) +import us.wedemy.eggeum.android.updatecafe.ui.item.CafeInfoItem @HiltViewModel class InputCafeInfoViewModel @Inject constructor( private val getPlaceUseCase: GetPlaceUseCase, private val upsertlaceBodyUseCase: UpsertlaceBodyUseCase, ) : ViewModel() { - private val _uiState = MutableStateFlow(CafeInfoUiState()) - val uiState = _uiState.asStateFlow() + private val _cafeInfo = MutableStateFlow(CafeInfoItem()) + val cafeInfo = _cafeInfo.asStateFlow() - private val _placeName = MutableStateFlow("") - val placeName = _placeName.asStateFlow() + lateinit var placeBody: PlaceEntity private val _navigateToUpsertEvent = MutableSharedFlow(0) val navigateToUpsertEvent: SharedFlow = _navigateToUpsertEvent.asSharedFlow() @@ -63,10 +46,10 @@ class InputCafeInfoViewModel @Inject constructor( val result = getPlaceUseCase(placeId) when { result.isSuccess && result.getOrNull() != null -> { - val placeBody = result.getOrNull()!! + placeBody = result.getOrNull()!! Timber.d("plcaeBody >>> $placeBody") - _uiState.update { uiState -> - uiState.copy( + _cafeInfo.update { cafeInfo -> + cafeInfo.copy( areaSize = placeBody.info?.areaSize, blogUri = placeBody.info?.blogUri, businessHours = placeBody.info?.businessHours, @@ -83,7 +66,6 @@ class InputCafeInfoViewModel @Inject constructor( websiteUri = placeBody.info?.websiteUri, ) } - _placeName.emit(placeBody.name!!) } result.isSuccess && result.getOrNull() == null -> { Timber.e("Request succeeded but data validation failed.") @@ -97,9 +79,9 @@ class InputCafeInfoViewModel @Inject constructor( } } - fun upsertPlaceBody(upsertPlaceEntity: UpsertPlaceEntity) { + fun upsertPlaceBody() { viewModelScope.launch { - val result = upsertlaceBodyUseCase(upsertPlaceEntity) + val result = upsertlaceBodyUseCase(placeBody.toUpsertPlaceEntity()) when { result.isSuccess -> { _navigateToUpsertEvent.emit(true) diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/InputCafeMenuViewModel.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/InputCafeMenuViewModel.kt deleted file mode 100644 index b680ff26..00000000 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/InputCafeMenuViewModel.kt +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Designed and developed by Wedemy 2023. - * - * Licensed under the MIT. - * Please see full license: https://github.com/Wedemy/eggeum-android/blob/main/LICENSE - */ - -@file:Suppress("unused") - -package us.wedemy.eggeum.android.updatecafe.viewmodel - -import androidx.lifecycle.SavedStateHandle -import androidx.lifecycle.ViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject - -@HiltViewModel -class InputCafeMenuViewModel @Inject constructor(savedStateHandle: SavedStateHandle) : ViewModel() diff --git a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/SelectCafeMenuViewModel.kt b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/ProposeCafeInfoViewModel.kt similarity index 71% rename from update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/SelectCafeMenuViewModel.kt rename to update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/ProposeCafeInfoViewModel.kt index 90671a3a..ae5fd5af 100644 --- a/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/SelectCafeMenuViewModel.kt +++ b/update-cafe/src/main/kotlin/us/wedemy/eggeum/android/updatecafe/viewmodel/ProposeCafeInfoViewModel.kt @@ -27,7 +27,7 @@ import us.wedemy.eggeum.android.domain.usecase.UpsertlaceBodyUseCase import us.wedemy.eggeum.android.updatecafe.ui.item.CafeMenuItem @HiltViewModel -class SelectCafeMenuViewModel @Inject constructor( +class ProposeCafeInfoViewModel @Inject constructor( private val getPlaceUseCase: GetPlaceUseCase, private val upsertlaceBodyUseCase: UpsertlaceBodyUseCase, ) : ViewModel() { @@ -40,6 +40,13 @@ class SelectCafeMenuViewModel @Inject constructor( private val _showToastEvent = MutableSharedFlow() val showToastEvent: SharedFlow = _showToastEvent.asSharedFlow() + private val _cafeMenuItemMap = MutableStateFlow(emptyMap()) + private val cafeMenuItemMap = _cafeMenuItemMap.asStateFlow() + + fun setCafeMenuItemMap(cafeMenuItemMap: MutableMap) { + _cafeMenuItemMap.value = cafeMenuItemMap + } + fun getCafeMenuList(placeId: Int) { viewModelScope.launch { val result = getPlaceUseCase(placeId) @@ -48,8 +55,8 @@ class SelectCafeMenuViewModel @Inject constructor( placeBody = result.getOrNull()!! Timber.d("plcaeBody >>> $placeBody") placeBody.menu?.products?.let { - val productList: MutableList = initializeCafeMenuItem(products = it) - updateCafeMenuList(productList = productList) + val cafeMenuItemList: MutableList = initializeCafeMenuItem(products = it) + updateCafeMenuList(cafeMenuItemList = cafeMenuItemList) } } result.isSuccess && result.getOrNull() == null -> { @@ -72,8 +79,27 @@ class SelectCafeMenuViewModel @Inject constructor( return productList } - fun updateCafeMenuList(productList: MutableList) { - _cafeMenuList.value = productList + fun updateCafeMenuList(cafeMenuItemList: MutableList) { + _cafeMenuList.value = cafeMenuItemList + } + + fun editCafeMenuItem() { + val before = cafeMenuItemMap.value["before"] + val after = cafeMenuItemMap.value["after"] + + placeBody.menu?.products.let { productEntities -> + productEntities?.forEach { + if (it.name == before?.name && it.price == before.price) { + it.name = after?.name!! + it.price = after.price + } + } + } + + placeBody.menu?.products?.let { + val cafeMenuItemList: MutableList = initializeCafeMenuItem(products = it) + updateCafeMenuList(cafeMenuItemList = cafeMenuItemList) + } } fun updatePlaceBodyUseCase() { diff --git a/update-cafe/src/main/res/layout/fragment_input_cafe_menu.xml b/update-cafe/src/main/res/layout/fragment_input_cafe_menu.xml index 3c13b053..0e6b732f 100644 --- a/update-cafe/src/main/res/layout/fragment_input_cafe_menu.xml +++ b/update-cafe/src/main/res/layout/fragment_input_cafe_menu.xml @@ -142,7 +142,7 @@ style="@style/Widget.Eggeum.TextInputEditText.OutlinedBox" android:ellipsize="end" android:hint="@string/input_cafe_menu_price_hint" - android:inputType="text" + android:inputType="number" android:maxLines="1" />