Skip to content

Commit

Permalink
[feat/#34]: 가게 상세 정보 화면 DataBinding 연결 및 StoreInfoModel 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
NaZe0320 committed Feb 3, 2024
1 parent a699afb commit d95ed2a
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 30 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/com/umc/coumo/domain/model/MenuModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package com.umc.coumo.domain.model
import android.net.Uri

data class MenuModel(
val id: Int,
val name: String,
val content: String,
val description: String,
val image: Uri? = null,
val isNew: Boolean = false
)
13 changes: 12 additions & 1 deletion app/src/main/java/com/umc/coumo/domain/model/StoreInfoModel.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package com.umc.coumo.domain.model

class StoreInfoModel {
import android.net.Uri

data class StoreInfoModel(
val name: String,
val description: String,
val location: String,
val longitude: Double,
val latitude: Double,
val image: List<Uri>?,
val coupon: CouponModel,
val menuList: List<MenuModel>,
) {
}
31 changes: 24 additions & 7 deletions app/src/main/java/com/umc/coumo/domain/viewmodel/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.umc.coumo.domain.viewmodel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.umc.coumo.domain.model.CouponModel
import com.umc.coumo.domain.model.MenuModel
import com.umc.coumo.domain.model.StoreInfoModel
import com.umc.coumo.domain.type.DetailTabType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
Expand All @@ -17,6 +19,9 @@ class HomeViewModel @Inject constructor(): ViewModel() {
private val _menuList = MutableLiveData<List<MenuModel>>()
val menuList: LiveData<List<MenuModel>> get() = _menuList

private val _storeData = MutableLiveData<StoreInfoModel>()
val storeData: LiveData<StoreInfoModel> get() = _storeData

init {
testData()
}
Expand All @@ -25,14 +30,26 @@ class HomeViewModel @Inject constructor(): ViewModel() {
_currentTab.value = tab
}

fun loadStoreData() {
// TODO( API 에서 데이터 가져오기 )
testData()
}

private fun testData() {
val list = listOf(
MenuModel(id = 0, name = "아이스 바닐라 라떼", content = "Tall: 4,800\nGrande: 6,800\nTrenta: 6,800"),
MenuModel(id = 1, name = "아이스 바닐라 라떼2", content = "Tall: 4,800\nGrande: 6,800\nTrenta: 6,800", isNew = true),
MenuModel(id = 2, name = "아이스 바닐라 라떼3", content = "Tall: 4,800\nGrande: 6,800\nTrenta: 6,800",),
MenuModel(id = 3, name = "아이스 바닐라 라떼4", content = "Tall: 4,800\nGrande: 6,800\nTrenta: 6,800",),
MenuModel(id = 4, name = "아이스 바닐라 라떼5", content = "Tall: 4,800\nGrande: 6,800\nTrenta: 6,800",),
_storeData.value = StoreInfoModel(
name = "가게 이름",
description = "가게 정보",
location = "가게 위치 정보",
longitude = 126.12,
latitude = 36.12,
image = null,
coupon = CouponModel("?",1,"1",1,null),
menuList = listOf(
MenuModel("메뉴 이름1","메뉴 정보1"),
MenuModel("메뉴 이름2","메뉴 정보2", isNew = true),
MenuModel("메뉴 이름3","메뉴 정보3"),
MenuModel("메뉴 이름4","메뉴 정보4"),
)
)
_menuList.value = list
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MenuAdapter(
): ListAdapter<MenuModel, RecyclerView.ViewHolder>(
ItemDiffCallback<MenuModel>(
onContentsTheSame = {old, new -> old == new},
onItemsTheSame = {old, new -> old.id == new.id}
onItemsTheSame = {old, new -> old.name == new.name}
)
) {
companion object {
Expand Down Expand Up @@ -49,17 +49,11 @@ companion object {
}
}



inner class MenuViewHolder(
private val binding: ItemMenuBinding
): RecyclerView.ViewHolder(binding.root) {
fun bind(item: MenuModel) {
binding.item = item

itemView.setOnClickListener {
listener?.onItemClick(item.id)
}
}
}

Expand All @@ -68,10 +62,6 @@ companion object {
): RecyclerView.ViewHolder(binding.root) {
fun bind(item: MenuModel) {
binding.item = item

itemView.setOnClickListener {
listener?.onItemClick(item.id)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class HomeDetailInfoFragment: BindingFragmentNoneBackPress<FragmentHomeDetailInf
}
})

viewModel.menuList.observe(viewLifecycleOwner) {
viewModel.storeData.observe(viewLifecycleOwner) {
viewLifecycleOwner.lifecycleScope.launch (Dispatchers.Main) {
menuAdapter.submitList(it)
menuAdapter.submitList(it.menuList)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/shape_rect_round_12.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="12dp" />
</shape>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_home_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/horizontal_padding"
android:layout_marginTop="24dp"
android:text="앙떼띠 로스터리 (강남점)"
android:text="@{viewModel.storeData.name}"
android:textSize="24sp"
android:textColor="@color/font_text"
android:fontFamily="@font/pretendard_700"
Expand All @@ -64,7 +64,7 @@
android:paddingVertical="6dp"
android:background="@drawable/shape_rect_side_round"
android:backgroundTint="#E4D9F8"
android:text="쿠모로 4개 모았어요!"
android:text="@{@string/coupon_format(viewModel.storeData.coupon.stampCount)}"
android:textSize="12sp"
android:textColor="#4E4E4E"
android:fontFamily="@font/pretendard_600"
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/fragment_home_detail_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="viewModel"
type="com.umc.coumo.domain.viewmodel.HomeViewModel" />
</data>

<androidx.core.widget.NestedScrollView
Expand All @@ -18,7 +20,7 @@
android:id="@+id/tv_store_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="양떼띠 로스터리는 2017년에 오픈한 강남의 유명 카페입니다. 강남역 직장인들을 위해 평일 오전 7시~9시에 아메리카노 2000원 이벤트를 진행 중입니다."
android:text="@{viewModel.storeData.description}"
android:textSize="14sp"
android:textColor="#161515"
android:fontFamily="@font/pretendard_400"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<androidx.constraintlayout.utils.widget.ImageFilterView
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/shape_rect_round_6"
android:background="@drawable/shape_rect_round_12"
imageUri="@{item.image}"
android:scaleType="centerCrop"
android:clipToOutline="true"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_menu_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/pretendard_700"
android:text="@{item.content}"
android:text="@{item.description}"
android:textColor="@color/main"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -79,7 +79,7 @@
<TextView
style="@style/NewChipStyle"
android:visibility="@{item.isNew ? View.VISIBLE : View.INVISIBLE}"
android:layout_marginEnd="40dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down

0 comments on commit d95ed2a

Please sign in to comment.