Skip to content

Commit

Permalink
정보수정제안 api 구현 #147
Browse files Browse the repository at this point in the history
  • Loading branch information
kymjaehong committed Dec 14, 2023
1 parent 3857ff1 commit 0cf856a
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 136 deletions.
8 changes: 4 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
android:name=".IntroActivity"
android:exported="true"
android:theme="@style/Theme.Eggeum.Splash">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
8 changes: 4 additions & 4 deletions update-cafe/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
android:exported="true"
android:theme="@style/Theme.Eggeum.UpdateCafe"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -56,14 +55,10 @@ class InputCafeInfoFragment : BaseFragment<FragmentInputCafeInfoBinding>() {
}

private fun initView() {
repeatOnStarted {
launch {
/**
* Intent에서 placeId 가져오기
*/
viewModel.getPlaceBody(1)
}
}
/**
* Intent에서 placeId 가져오기
*/
viewModel.getPlaceBody(1)
}

private fun initListener() {
Expand Down Expand Up @@ -135,19 +130,15 @@ class InputCafeInfoFragment : BaseFragment<FragmentInputCafeInfoBinding>() {
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? {
Expand All @@ -163,31 +154,43 @@ class InputCafeInfoFragment : BaseFragment<FragmentInputCafeInfoBinding>() {
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 {
Expand All @@ -206,6 +209,20 @@ class InputCafeInfoFragment : BaseFragment<FragmentInputCafeInfoBinding>() {
}
}

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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,69 @@ 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<FragmentInputCafeMenuBinding>() {
override fun getViewBinding() = FragmentInputCafeMenuBinding.inflate(layoutInflater)

private val viewModel by viewModels<InputCafeMenuViewModel>()
private val viewModel by activityViewModels<ProposeCafeInfoViewModel>()

private val args by navArgs<InputCafeMenuFragmentArgs>()

private lateinit var newCafeMenuName: String
private lateinit var newCafeMenuPrice: String

private val beforeAndAfterCafeMenuItem = mutableMapOf<String, CafeMenuItem>()

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()
}
}

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()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ 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
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)
Expand All @@ -43,12 +42,12 @@ class SelectCafeMenuFragment : BaseFragment<FragmentSelectCafeMenuBinding>() {
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)
}
Expand All @@ -63,41 +62,37 @@ class SelectCafeMenuFragment : BaseFragment<FragmentSelectCafeMenuBinding>() {

override fun getViewBinding() = FragmentSelectCafeMenuBinding.inflate(layoutInflater)

private val viewModel by viewModels<SelectCafeMenuViewModel>()
private val viewModel by activityViewModels<ProposeCafeInfoViewModel>()

private var callCount = 0

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
initView()
initListener()
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<CafeMenuItem>()
val cafeMenuList = viewModel.cafeMenuList.value
val newCafeMenuList = mutableListOf<ProductEntity>()
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<ProductEntity>)
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))
Expand All @@ -107,11 +102,17 @@ class SelectCafeMenuFragment : BaseFragment<FragmentSelectCafeMenuBinding>() {
}

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
}
}

Expand All @@ -134,11 +135,7 @@ class SelectCafeMenuFragment : BaseFragment<FragmentSelectCafeMenuBinding>() {
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) }
}
}
}
Expand Down
Loading

0 comments on commit 0cf856a

Please sign in to comment.