Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN/USER] fix: 상세 화면 축제 목록 요청 로직 변경 및 Throwable 예외 처리 제거(#986) #987

Merged
merged 9 commits into from
May 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ private fun <T> handleBadRequestException(response: Response<T>) {
throw BookmarkLimitExceededException()
}
}
throw Throwable("400 Bad Request")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class ArtistDetailViewModel @Inject constructor(
runCatching {
val deferredArtistDetail =
async { artistRepository.loadArtistDetail(id, delayTimeMillis) }
val deferredFestivals = async { artistRepository.loadArtistFestivals(id, 10) }
val deferredFestivals = async {
artistRepository.loadArtistFestivals(id = id, size = FESTIVAL_PAGE_SIZE)
}

val artist = deferredArtistDetail.await().getOrThrow()
val festivalPage = deferredFestivals.await().getOrThrow()

Expand All @@ -66,7 +69,7 @@ class ArtistDetailViewModel @Inject constructor(
artist = artist,
bookMarked = isBookmarked,
festivals = festivalPage.toUiState(),
userRepository.isSigned(),
festivalPage.isLastPage,
onBookmarkClick = ::toggleArtistBookmark,
)

Expand All @@ -89,18 +92,19 @@ 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
}
val lastItem = currentFestivals.lastOrNull()
val isPast =
lastItem?.endDate?.isBefore(LocalDate.now()) ?: true || successUiState.isLast

val lastFestivalId = if (successUiState.isLast) null else lastItem?.id
val lastStartDate = if (successUiState.isLast) null else lastItem?.startDate

artistRepository.loadArtistFestivals(
id = artistId,
lastFestivalId = currentFestivals.lastOrNull()?.id,
lastStartDate = currentFestivals.lastOrNull()?.startDate,
lastFestivalId = lastFestivalId,
lastStartDate = lastStartDate,
isPast = isPast,
size = FESTIVAL_PAGE_SIZE,
).onSuccess { festivalsPage ->
_uiState.value = successUiState.copy(
festivals = currentFestivals + festivalsPage.toUiState(),
Expand Down Expand Up @@ -189,6 +193,7 @@ class ArtistDetailViewModel @Inject constructor(
}

companion object {
private const val FESTIVAL_PAGE_SIZE = 20
private const val KEY_LOAD_ARTIST_DETAIL = "KEY_LOAD_ARTIST_DETAIL"
private const val KEY_LOAD_MORE_ARTIST_FESTIVAL = "KEY_LOAD_MORE_ARTIST_FESTIVAL"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ArtistDetailFestivalViewHolder(
fun bind(item: FestivalItemUiState) {
binding.item = item
artistAdapter.submitList(item.artists)
binding.tvEmptyStage.visibility = if (item.artists.isEmpty()) View.VISIBLE else View.GONE
bindDDayView(item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FestivalBookmarkViewHolder(
fun bind(item: FestivalBookmarkItemUiState) {
binding.item = item
artistAdapter.submitList(item.artists)
binding.tvEmptyStage.visibility = if (item.artists.isEmpty()) View.VISIBLE else View.GONE
bindDDayView(item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FestivalListFestivalViewHolder(
fun bind(item: FestivalItemUiState) {
binding.item = item
artistAdapter.submitList(item.artists)
binding.tvEmptyStage.visibility = if (item.artists.isEmpty()) View.VISIBLE else View.GONE
bindDDayView(item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MyPageFragment : Fragment() {
binding.tvPersonalInfoPolicy.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW)
intent.data =
Uri.parse("https://wooteco-ash.notion.site/fe0ca28535044db999d998eb4ea37e83")
Uri.parse("https://sites.google.com/view/privacy-festago")
startActivity(intent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SchoolDetailFestivalViewHolder(
fun bind(item: FestivalItemUiState) {
binding.item = item
artistAdapter.submitList(item.artists)
binding.tvEmptyStage.visibility = if (item.artists.isEmpty()) View.VISIBLE else View.GONE
bindDDayView(item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.festago.festago.presentation.R
import com.festago.festago.presentation.databinding.FragmentSchoolDetailBinding
import com.festago.festago.presentation.databinding.ItemMediaBinding
import com.festago.festago.presentation.ui.artistdetail.ArtistDetailArgs
import com.festago.festago.presentation.ui.bindingadapter.setImage
import com.festago.festago.presentation.ui.festivaldetail.FestivalDetailArgs
import com.festago.festago.presentation.ui.schooldetail.uistate.MoreItemUiState
import com.festago.festago.presentation.ui.schooldetail.uistate.SchoolDetailUiState
Expand Down Expand Up @@ -74,7 +73,6 @@ class SchoolDetailFragment : Fragment() {

private fun loadSchoolDetail() {
binding.tvSchoolName.text = args.school.name
binding.ivSchoolLogoImage.setImage(args.school.profileImageUrl)
val delayTimeMillis = resources.getInteger(R.integer.nav_Anim_time).toLong()
vm.loadSchoolDetail(args.school.id, delayTimeMillis)
}
Expand All @@ -97,7 +95,6 @@ class SchoolDetailFragment : Fragment() {
binding.successUiState = uiState
binding.ivBookmark.isSelected = uiState.bookmarked
binding.tvSchoolName.text = uiState.schoolInfo.schoolName
binding.ivSchoolLogoImage.setImage(uiState.schoolInfo.logoUrl)
val items: List<Any> = if (uiState.isLast) {
uiState.festivals
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class SchoolDetailViewModel @Inject constructor(
viewModelScope.launch {
val deferredSchoolInfo =
async { schoolRepository.loadSchoolInfo(schoolId, delayTimeMillis) }
val deferredFestivalPage = async { schoolRepository.loadSchoolFestivals(schoolId) }
val deferredFestivalPage = async {
schoolRepository.loadSchoolFestivals(schoolId = schoolId, size = FESTIVAL_PAGE_SIZE)
}

runCatching {
val schoolInfo = deferredSchoolInfo.await().getOrThrow()
Expand Down Expand Up @@ -87,18 +89,17 @@ 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
}
val lastItem = currentFestivals.lastOrNull()
val isPast =
lastItem?.endDate?.isBefore(LocalDate.now()) ?: true || successUiState.isLast
val lastFestivalId = if (successUiState.isLast) null else lastItem?.id
val lastStartDate = if (successUiState.isLast) null else lastItem?.startDate
schoolRepository.loadSchoolFestivals(
schoolId = schoolId,
lastFestivalId = currentFestivals.lastOrNull()?.id?.toInt(),
lastStartDate = currentFestivals.lastOrNull()?.startDate,
lastFestivalId = lastFestivalId?.toInt(),
lastStartDate = lastStartDate,
isPast = isPast,
size = FESTIVAL_PAGE_SIZE,
).onSuccess { festivalsPage ->
_uiState.value = successUiState.copy(
festivals = currentFestivals + festivalsPage.festivals.map { it.toUiState() },
Expand Down Expand Up @@ -185,6 +186,7 @@ class SchoolDetailViewModel @Inject constructor(
)

companion object {
private const val FESTIVAL_PAGE_SIZE = 20
private const val KEY_LOAD_SCHOOL_DETAIL = "KEY_LOAD_SCHOOL_DETAIL"
private const val KEY_LOAD_MORE_SCHOOL_FESTIVALS = "KEY_LOAD_MORE_SCHOOL_FESTIVALS"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FestivalSearchViewHolder(
fun bind(item: FestivalSearchItemUiState) {
binding.item = item
artistAdapter.submitList(item.artists)
binding.tvEmptyStage.visibility = if (item.artists.isEmpty()) View.VISIBLE else View.GONE
binding.tvFestivalDDay.bindFestivalDday(item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
app:tabIndicatorHeight="2dp"
app:tabSelectedTextColor="@color/contents_gray_07"
app:tabTextAppearance="@style/H4Bold16Lh20"
app:tabTextColor="@color/contents_gray_07">
app:tabTextColor="@color/contents_gray_05">

<com.google.android.material.tabs.TabItem
android:id="@+id/tiBookmarkListFestival"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@
android:gravity="center_vertical"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
app:layout_constraintTop_toBottomOf="@id/tvMyPageAppbar"
android:visibility="gone">
app:layout_constraintTop_toBottomOf="@id/tvMyPageAppbar">

<androidx.cardview.widget.CardView
android:id="@+id/cvProfileImage"
Expand All @@ -92,10 +91,10 @@

<ImageView
android:id="@+id/ivProfileImage"
imageUrl="@{successUiState.userInfo.profileImageUrl}"
android:layout_width="60dp"
android:layout_height="60dp"
android:contentDescription="@null" />
android:contentDescription="@null"
android:src="@drawable/ic_user_profile_default" />

</androidx.cardview.widget.CardView>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<TextView
android:id="@+id/tvEmptyStage"
style="@style/H5Bold14Lh16"
visibility="@{item.artists.isEmpty()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
<TextView
android:id="@+id/tvEmptyStage"
style="@style/H5Bold14Lh16"
visibility="@{item.artists.isEmpty()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
<TextView
android:id="@+id/tvEmptyStage"
style="@style/H5Bold14Lh16"
visibility="@{item.artists.isEmpty()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@

<ImageView
android:id="@+id/ivFestivalImage"
imageUrl="@{school.imageUrl}"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/festival_list_iv_image"
android:scaleType="centerCrop"
tools:src="@color/background_gray_03" />
android:src="@drawable/img_default_school" />
</androidx.cardview.widget.CardView>

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
<TextView
android:id="@+id/tvEmptyStage"
style="@style/H5Bold14Lh16"
visibility="@{item.artists.isEmpty()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@
style="@style/B2Medium14Lh20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_artist_tv_no_plan"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:includeFontPadding="false"
android:text="@string/search_artist_tv_no_plan"
android:textColor="@color/contents_gray_05"
app:layout_constraintBottom_toBottomOf="@id/tvTodayStageCount"
app:layout_constraintStart_toEndOf="@id/tvTodayStageCount"
app:layout_constraintTop_toTopOf="@id/tvTodayStageCount" />
app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintStart_toStartOf="@+id/tvArtistName"
app:layout_constraintTop_toBottomOf="@+id/tvArtistName" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
<TextView
android:id="@+id/tvEmptyStage"
style="@style/H5Bold14Lh16"
visibility="@{item.artists.isEmpty()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

<ImageView
android:id="@+id/ivSchoolLogoImage"
imageUrl="@{item.logoUrl}"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
tools:src="@drawable/ic_launcher_foreground" />
android:src="@drawable/img_default_school"
tools:src="@drawable/img_default_school" />
</androidx.cardview.widget.CardView>

<TextView
Expand Down
Loading