Skip to content

Commit

Permalink
#228 Fix issue related to changes in dining place selection
Browse files Browse the repository at this point in the history
  • Loading branch information
wateralsie committed Apr 16, 2024
1 parent e73b8f6 commit b179dbd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package `in`.koreatech.koin.domain.util.ext

import `in`.koreatech.koin.domain.model.dining.Dining
import `in`.koreatech.koin.domain.model.dining.DiningPlace
import `in`.koreatech.koin.domain.model.dining.DiningType

fun List<Dining>.typeFilter(type: DiningType) = this.filter {
Expand All @@ -9,11 +10,26 @@ fun List<Dining>.typeFilter(type: DiningType) = this.filter {


fun List<Dining>.arrange() = this.let {
val diningList = mutableListOf<Dining>()
val campus2 = this.filter { it.place == "2캠퍼스" }
val campus1 = this.filter { it.place != "2캠퍼스" }
campus1.sortedBy { it.place }
diningList.addAll(campus1)
diningList.addAll(campus2)
diningList.toList()
val allPlaces = DiningPlace.entries.map { it.place }

allPlaces.map { place ->
campus1.find { it.place == place } ?: Dining(
id = 0,
date = "",
type = "",
place = place,
priceCard = "",
priceCash = "",
kcal = "",
menu = listOf(),
imageUrl = "",
createdAt = "",
updatedAt = "",
soldoutAt = "",
changedAt = "",
error = ""
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ class MainActivity : KoinNavigationDrawerActivity() {
viewModel.setSelectedPosition(tab.position)
}

override fun onTabUnselected(p0: TabLayout.Tab?) {}
override fun onTabUnselected(tab: TabLayout.Tab) {}

override fun onTabReselected(p0: TabLayout.Tab?) {}
override fun onTabReselected(tab: TabLayout.Tab) {}
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ class DiningContainerFragment : Fragment(R.layout.fragment_dining_container) {
val diningArranged = list
.typeFilter(diningType)
.arrange()

if (list.isEmpty() || position >= diningArranged.size) {
binding.viewEmptyDining.emptyDiningListFrameLayout.isVisible = true
return
}
binding.viewEmptyDining.emptyDiningListFrameLayout.isVisible = false

listOf(
val menus = listOf(
binding.textViewDiningContainerMenu0,
binding.textViewDiningContainerMenu2,
binding.textViewDiningContainerMenu4,
Expand All @@ -81,24 +74,37 @@ class DiningContainerFragment : Fragment(R.layout.fragment_dining_container) {
binding.textViewDiningContainerMenu5,
binding.textViewDiningContainerMenu7,
binding.textViewDiningContainerMenu9
).zip(diningArranged[position].menu).forEach { (textView, menu) ->
)

if (list.isEmpty() || diningArranged[position].menu.isEmpty()) {
binding.viewEmptyDining.emptyDiningListFrameLayout.isVisible = true
return
}
binding.viewEmptyDining.emptyDiningListFrameLayout.isVisible = false

menus.forEach { it.text = "" }
menus.zip(diningArranged[position].menu).forEach { (textView, menu) ->
textView.text = menu
}

val isSoldOut = diningArranged[position].soldoutAt.isNotEmpty()
val isChanged = diningArranged[position].changedAt.isNotEmpty()
with (binding.textViewDiningStatus) {
with(binding.textViewDiningStatus) {
when {
isSoldOut -> {
text = context.getString(R.string.dining_soldout)
setTextColor(ContextCompat.getColor(context, R.color.dining_soldout_text))
background = ContextCompat.getDrawable(context, R.drawable.dining_soldout_fill_radius_4)
background =
ContextCompat.getDrawable(context, R.drawable.dining_soldout_fill_radius_4)
}

isChanged -> {
text = context.getString(R.string.dining_changed)
setTextColor(ContextCompat.getColor(context, R.color.dining_changed_text))
background = ContextCompat.getDrawable(context, R.drawable.dining_changed_fill_radius_4)
background =
ContextCompat.getDrawable(context, R.drawable.dining_changed_fill_radius_4)
}

else -> {
visibility = View.INVISIBLE
}
Expand Down

0 comments on commit b179dbd

Please sign in to comment.