Skip to content

Commit

Permalink
[AN/USER] fix: 요구사항에 맞게 기능을 수정한다(#900) (#902)
Browse files Browse the repository at this point in the history
* feat(SearchRepository): 한 글자 대학은 검색할 수 없다.

* feat: 아티스트 상세, 학교 상세에서 이전 축제도 보여준다.

* fix: 종료된 축제 요청 로직 수정

* fix: Dday 오류 수정
  • Loading branch information
SeongHoonC authored May 1, 2024
1 parent f58299e commit ec8720a
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ class DefaultSearchRepository @Inject constructor(
}

override suspend fun searchSchools(searchQuery: String): Result<List<SchoolSearch>> {
if (searchQuery.length <= MIN_SCHOOL_SEARCH_QUERY_LENGTH) {
return Result.success(emptyList())
}
return runCatchingResponse {
searchRetrofitService.searchSchools(searchQuery)
}.onSuccessOrCatch { schoolSearchResponses -> schoolSearchResponses.map { it.toDomain() } }
}

companion object {
const val MIN_SCHOOL_SEARCH_QUERY_LENGTH = 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import java.time.LocalDate
import javax.inject.Inject

@HiltViewModel
Expand All @@ -44,8 +45,12 @@ class ArtistDetailViewModel @Inject constructor(
_uiState.value = ArtistDetailUiState.Success(
deferredArtistDetail.await().getOrThrow(),
festivalPage.toUiState(),
festivalPage.isLastPage
festivalPage.isLastPage,
)

if (festivalPage.festivals.isEmpty()) {
loadMoreArtistFestivals(id)
}
}.onFailure {
handleFailure(key = KEY_LOAD_ARTIST_DETAIL, throwable = it)
}
Expand All @@ -57,15 +62,22 @@ class ArtistDetailViewModel @Inject constructor(

viewModelScope.launch {
val currentFestivals = successUiState.festivals

val lastItem = successUiState.festivals.lastOrNull()
val isPast = when {
lastItem == null -> true
lastItem.endDate < LocalDate.now() -> true
successUiState.isLast -> true
else -> false
}
artistRepository.loadArtistFestivals(
id = artistId,
lastFestivalId = currentFestivals.lastOrNull()?.id,
lastStartDate = currentFestivals.lastOrNull()?.startDate,
isPast = isPast,
).onSuccess { festivalsPage ->
_uiState.value = successUiState.copy(
festivals = currentFestivals + festivalsPage.toUiState(),
isLast = festivalsPage.isLastPage
isLast = festivalsPage.isLastPage,
)
}.onFailure {
handleFailure(key = KEY_LOAD_MORE_ARTIST_FESTIVAL, throwable = it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.festago.festago.presentation.ui.artistdetail.adapter.festival

import android.content.res.Resources
import android.graphics.Color
import android.graphics.Rect
import android.util.TypedValue
import android.view.LayoutInflater
Expand All @@ -16,7 +17,7 @@ import com.festago.festago.presentation.ui.artistdetail.uistate.FestivalItemUiSt
import java.time.LocalDate

class ArtistDetailFestivalViewHolder(
private val binding: ItemArtistDetailFestivalBinding
private val binding: ItemArtistDetailFestivalBinding,
) : ArtistDetailViewHolder(binding) {
private val artistAdapter = ArtistAdapter()

Expand All @@ -34,36 +35,39 @@ class ArtistDetailFestivalViewHolder(
private fun bindDDayView(item: FestivalItemUiState) {
val context = binding.root.context

val dDayView = binding.tvFestivalDDay

when {
LocalDate.now() > item.endDate -> Unit

LocalDate.now() >= item.startDate -> {
dDayView.text = context.getString(R.string.festival_list_tv_dday_in_progress)
dDayView.setTextColor(context.getColor(R.color.secondary_pink_01))
dDayView.background = AppCompatResources.getDrawable(
LocalDate.now() in item.startDate..item.endDate -> {
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_in_progress)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.secondary_pink_01))
binding.tvFestivalDDay.background = AppCompatResources.getDrawable(
context,
R.drawable.bg_artist_detail_dday_in_progress,
R.drawable.bg_festival_list_dday_in_progress,
)
}

LocalDate.now() >= item.startDate.minusDays(7) -> {
dDayView.text = context.getString(
R.string.artist_detail_tv_dday_format,
item.startDate.compareTo(LocalDate.now()).toString(),
)
dDayView.setTextColor(context.getColor(android.R.color.white))
dDayView.setBackgroundColor(0xffff1273.toInt())
LocalDate.now() < item.startDate -> {
val dDay = LocalDate.now().toEpochDay() - item.startDate.toEpochDay()
val backgroundColor = if (dDay >= -7L) {
context.getColor(R.color.secondary_pink_01)
} else {
context.getColor(R.color.contents_gray_07)
}
binding.tvFestivalDDay.setBackgroundColor(backgroundColor)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.background_gray_01))
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_format, dDay.toString())
}

else -> {
dDayView.text = context.getString(
R.string.artist_detail_tv_dday_format,
(LocalDate.now().toEpochDay() - item.startDate.toEpochDay()).toString(),
binding.tvFestivalDDay.setBackgroundColor(Color.TRANSPARENT)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.background_gray_01))
binding.tvFestivalDDay.background = AppCompatResources.getDrawable(
context,
R.drawable.bg_festival_detail_dday_end,
)
dDayView.setTextColor(context.getColor(android.R.color.white))
dDayView.setBackgroundColor(context.getColor(android.R.color.black))
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_end)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class FestivalDetailFragment : Fragment() {
private fun TextView.setFestivalDDay(startDate: LocalDate, endDate: LocalDate) {
when {
LocalDate.now() in startDate..endDate -> {
text = context.getString(R.string.festival_detail_tv_dday_in_progress)
text = context.getString(R.string.tv_dday_in_progress)
setTextColor(context.getColor(R.color.secondary_pink_01))
background = AppCompatResources.getDrawable(
context,
Expand All @@ -122,7 +122,7 @@ class FestivalDetailFragment : Fragment() {
}
setBackgroundColor(backgroundColor)
setTextColor(context.getColor(R.color.background_gray_01))
text = context.getString(R.string.festival_detail_tv_dday_format, dDay.toString())
text = context.getString(R.string.tv_dday_format, dDay.toString())
}

else -> {
Expand All @@ -132,7 +132,7 @@ class FestivalDetailFragment : Fragment() {
context,
R.drawable.bg_festival_detail_dday_end,
)
text = context.getString(R.string.festival_detail_tv_dday_end)
text = context.getString(R.string.tv_dday_end)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.festago.festago.presentation.ui.home.festivallist.festival

import android.content.res.Resources
import android.graphics.Color
import android.graphics.Rect
import android.util.TypedValue
import android.view.LayoutInflater
Expand Down Expand Up @@ -36,35 +37,39 @@ class FestivalListFestivalViewHolder(
private fun bindDDayView(item: FestivalItemUiState) {
val context = binding.root.context

val dDayView = binding.tvFestivalDDay
when {
LocalDate.now() > item.endDate -> Unit

LocalDate.now() >= item.startDate -> {
dDayView.text = context.getString(R.string.festival_list_tv_dday_in_progress)
dDayView.setTextColor(context.getColor(R.color.secondary_pink_01))
dDayView.background = AppCompatResources.getDrawable(
LocalDate.now() in item.startDate..item.endDate -> {
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_in_progress)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.secondary_pink_01))
binding.tvFestivalDDay.background = AppCompatResources.getDrawable(
context,
R.drawable.bg_festival_list_dday_in_progress,
)
}

LocalDate.now() >= item.startDate.minusDays(7) -> {
dDayView.setTextColor(context.getColor(R.color.background_gray_01))
dDayView.text = context.getString(
R.string.festival_list_tv_dday_format,
LocalDate.now().compareTo(item.startDate).toString(),
)
dDayView.setBackgroundColor(0xffff1273.toInt())
LocalDate.now() < item.startDate -> {
val dDay = LocalDate.now().toEpochDay() - item.startDate.toEpochDay()
val backgroundColor = if (dDay >= -7L) {
context.getColor(R.color.secondary_pink_01)
} else {
context.getColor(R.color.contents_gray_07)
}
binding.tvFestivalDDay.setBackgroundColor(backgroundColor)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.background_gray_01))
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_format, dDay.toString())
}

else -> binding.tvFestivalDDay.apply {
dDayView.setTextColor(context.getColor(R.color.background_gray_01))
dDayView.text = context.getString(
R.string.festival_list_tv_dday_format,
(LocalDate.now().toEpochDay() - item.startDate.toEpochDay()).toString(),
else -> {
binding.tvFestivalDDay.setBackgroundColor(Color.TRANSPARENT)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.background_gray_01))
binding.tvFestivalDDay.background = AppCompatResources.getDrawable(
context,
R.drawable.bg_festival_detail_dday_end,
)
dDayView.setBackgroundColor(context.getColor(android.R.color.black))
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_end)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.festago.festago.presentation.ui.schooldetail

import android.content.res.Resources
import android.graphics.Color
import android.graphics.Rect
import android.util.TypedValue
import android.view.LayoutInflater
Expand Down Expand Up @@ -33,35 +34,39 @@ class SchoolDetailFestivalViewHolder(
private fun bindDDayView(item: FestivalItemUiState) {
val context = binding.root.context

val dDayView = binding.tvFestivalDDay
when {
LocalDate.now() > item.endDate -> Unit

LocalDate.now() >= item.startDate -> {
dDayView.text = context.getString(R.string.festival_list_tv_dday_in_progress)
dDayView.setTextColor(context.getColor(R.color.secondary_pink_01))
dDayView.background = AppCompatResources.getDrawable(
LocalDate.now() in item.startDate..item.endDate -> {
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_in_progress)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.secondary_pink_01))
binding.tvFestivalDDay.background = AppCompatResources.getDrawable(
context,
R.drawable.bg_festival_list_dday_in_progress,
)
}

LocalDate.now() >= item.startDate.minusDays(7) -> {
dDayView.setTextColor(context.getColor(R.color.background_gray_01))
dDayView.text = context.getString(
R.string.festival_list_tv_dday_format,
LocalDate.now().compareTo(item.startDate).toString(),
)
dDayView.setBackgroundColor(0xffff1273.toInt())
LocalDate.now() < item.startDate -> {
val dDay = LocalDate.now().toEpochDay() - item.startDate.toEpochDay()
val backgroundColor = if (dDay >= -7L) {
context.getColor(R.color.secondary_pink_01)
} else {
context.getColor(R.color.contents_gray_07)
}
binding.tvFestivalDDay.setBackgroundColor(backgroundColor)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.background_gray_01))
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_format, dDay.toString())
}

else -> binding.tvFestivalDDay.apply {
dDayView.setTextColor(context.getColor(R.color.background_gray_01))
dDayView.text = context.getString(
R.string.festival_list_tv_dday_format,
(LocalDate.now().toEpochDay() - item.startDate.toEpochDay()).toString(),
else -> {
binding.tvFestivalDDay.setBackgroundColor(Color.TRANSPARENT)
binding.tvFestivalDDay.setTextColor(context.getColor(R.color.background_gray_01))
binding.tvFestivalDDay.background = AppCompatResources.getDrawable(
context,
R.drawable.bg_festival_detail_dday_end,
)
dDayView.setBackgroundColor(context.getColor(android.R.color.black))
binding.tvFestivalDDay.text =
context.getString(R.string.tv_dday_end)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import java.time.LocalDate
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -46,6 +47,9 @@ class SchoolDetailViewModel @Inject constructor(
festivals = festivalPage.festivals.map { it.toUiState() },
isLast = festivalPage.isLastPage,
)
if (festivalPage.festivals.isEmpty()) {
loadMoreSchoolFestivals(schoolId)
}
}.onFailure {
handleFailure(key = KEY_LOAD_SCHOOL_DETAIL, throwable = it)
}
Expand All @@ -57,15 +61,22 @@ class SchoolDetailViewModel @Inject constructor(

viewModelScope.launch {
val currentFestivals = successUiState.festivals

val lastItem = successUiState.festivals.lastOrNull()
val isPast = when {
lastItem == null -> true
lastItem.endDate > LocalDate.now() -> true
successUiState.isLast -> true
else -> false
}
schoolRepository.loadSchoolFestivals(
schoolId = schoolId,
lastFestivalId = currentFestivals.lastOrNull()?.id?.toInt(),
lastStartDate = currentFestivals.lastOrNull()?.startDate
lastStartDate = currentFestivals.lastOrNull()?.startDate,
isPast = isPast,
).onSuccess { festivalsPage ->
_uiState.value = successUiState.copy(
festivals = currentFestivals + festivalsPage.festivals.map { it.toUiState() },
isLast = festivalsPage.isLastPage
isLast = festivalsPage.isLastPage,
)
}.onFailure {
handleFailure(key = KEY_LOAD_MORE_SCHOOL_FESTIVALS, throwable = it)
Expand Down Expand Up @@ -99,14 +110,14 @@ class SchoolDetailViewModel @Inject constructor(
viewModelScope.launch {
_event.emit(SchoolDetailEvent.ShowArtistDetail(id))
}
}
},
)
},
onFestivalDetailClick = { id ->
viewModelScope.launch {
_event.emit(SchoolDetailEvent.ShowFestivalDetail(id))
}
}
},
)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FestivalSearchViewHolder(
}
setBackgroundColor(backgroundColor)
setTextColor(context.getColor(R.color.background_gray_01))
text = context.getString(R.string.festival_detail_tv_dday_format, dDay.toString())
text = context.getString(R.string.tv_dday_format, dDay.toString())
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions android/festago/presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
<string name="notification_list_tv_no_notification_explain">새로운 소식이 도착하면 알려드릴게요</string>

<!-- String related to festival detail -->
<string name="festival_detail_tv_dday_in_progress">진행 중</string>
<string name="festival_detail_tv_dday_format">D%1$s</string>
<string name="festival_detail_tv_dday_end">종료</string>
<string name="festival_detail_tv_empty_stages">아직 라인업이 공개되지 않았어요</string>


<!-- String related to festival dday -->
<string name="tv_dday_in_progress">진행 중</string>
<string name="tv_dday_format">D%1$s</string>
<string name="tv_dday_end">종료</string>

<!-- String related to region bottom sheet -->
<string name="region_bottom_sheet_tv_region">지역별</string>

Expand Down

0 comments on commit ec8720a

Please sign in to comment.