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] 디자인 수정 및 Domain Exception 추가 (#978) #979

Merged
merged 9 commits into from
May 19, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.festago.festago.data.util

import com.festago.festago.domain.exception.BookmarkLimitExceededException
import com.festago.festago.domain.exception.NetworkException
import com.festago.festago.domain.exception.UnauthorizedException
import retrofit2.Response
import java.net.UnknownHostException

suspend fun <T> runCatchingResponse(
block: suspend () -> Response<T>,
Expand All @@ -12,9 +15,9 @@ suspend fun <T> runCatchingResponse(
return Result.success(response.body()!!)
}

if (response.code() == 401) {
throw UnauthorizedException()
}
handleUnauthorizedException(response)

handleBadRequestException(response)

return Result.failure(
Throwable(
Expand All @@ -26,6 +29,26 @@ suspend fun <T> runCatchingResponse(
),
)
} catch (e: Exception) {
if (e is UnknownHostException) {
return Result.failure(NetworkException())
}
return Result.failure(e)
}
}

private fun <T> handleUnauthorizedException(response: Response<T>) {
if (response.code() == 401) {
throw UnauthorizedException()
}
}

private fun <T> handleBadRequestException(response: Response<T>) {
if (response.code() == 400) {
response.errorBody()?.string()?.let {
if (it.contains("BOOKMARK_LIMIT_EXCEEDED")) {
throw BookmarkLimitExceededException()
}
}
throw Throwable("400 Bad Request")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.festago.festago.domain.exception

class BookmarkLimitExceededException : Exception()

fun Throwable.isBookmarkLimitExceeded() = this is BookmarkLimitExceededException
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.festago.festago.domain.exception

class NetworkException : Exception()
fun Throwable.isNetworkError() = this is NetworkException
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.festago.festago.common.analytics.AnalyticsHelper
import com.festago.festago.common.analytics.logNetworkFailure
import com.festago.festago.domain.exception.isBookmarkLimitExceeded
import com.festago.festago.domain.exception.isNetworkError
import com.festago.festago.domain.exception.isUnauthorized
import com.festago.festago.domain.model.bookmark.BookmarkType
import com.festago.festago.domain.model.festival.FestivalsPage
import com.festago.festago.domain.repository.ArtistRepository
Expand Down Expand Up @@ -108,26 +111,35 @@ class ArtistDetailViewModel @Inject constructor(
viewModelScope.launch {
val uiState = uiState.value as? ArtistDetailUiState.Success ?: return@launch

if (!userRepository.isSigned()) {
_event.emit(BookmarkFailure("로그인이 필요합니다"))
return@launch
}

if (uiState.bookMarked) {
_uiState.value = uiState.copy(bookMarked = false)
bookmarkRepository.deleteArtistBookmark(artistId.toLong())
.onSuccess { _event.emit(BookmarkSuccess(false)) }
.onFailure {
_uiState.value = uiState.copy(bookMarked = true)
_event.emit(BookmarkFailure("북마크를 해제할 수 없습니다. 인터넷 연결을 확인해주세요"))
if (it.isUnauthorized()) {
_event.emit(BookmarkFailure("로그인이 필요해요"))
}
if (it.isNetworkError()) {
_uiState.value = uiState.copy(bookMarked = true)
_event.emit(BookmarkFailure("인터넷 연결을 확인해주세요"))
}
}
} else {
_uiState.value = uiState.copy(bookMarked = true)
bookmarkRepository.addArtistBookmark(artistId.toLong())
.onSuccess { _event.emit(BookmarkSuccess(true)) }
.onFailure {
_uiState.value = uiState.copy(bookMarked = false)
_event.emit(BookmarkFailure("다른 북마크를 해제하거나 인터넷 연결을 확인해주세요"))
if (it.isUnauthorized()) {
_event.emit(BookmarkFailure("로그인이 필요해요"))
}
if (it.isBookmarkLimitExceeded()) {
_uiState.value = uiState.copy(bookMarked = false)
_event.emit(BookmarkFailure("북마크는 12개까지 가능해요"))
}
Comment on lines +132 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

북마크 할 때도 isNetworkError 처리할 수 있을까요? 북마크 시에는 인터넷 연결이 끊겨도 문제 없이 북마크 되는 것처럼 보입니다. (실제로 북마크 처리 되는 건 아니지만..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다! 추가로 인터넷 문구가 너무 긴거 같아서 "인터넷 연결을 확인해주세요"으로 변경했습니다! 어떠신가요??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿굿

if (it.isNetworkError()) {
_uiState.value = uiState.copy(bookMarked = false)
_event.emit(BookmarkFailure("인터넷 연결을 확인해주세요"))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.festago.festago.common.analytics.AnalyticsHelper
import com.festago.festago.common.analytics.logNetworkFailure
import com.festago.festago.domain.exception.isBookmarkLimitExceeded
import com.festago.festago.domain.exception.isNetworkError
import com.festago.festago.domain.exception.isUnauthorized
import com.festago.festago.domain.model.artist.Artist
import com.festago.festago.domain.model.bookmark.BookmarkType
import com.festago.festago.domain.model.festival.FestivalDetail
Expand Down Expand Up @@ -96,26 +99,35 @@ class FestivalDetailViewModel @Inject constructor(
viewModelScope.launch {
val uiState = _uiState.value as? FestivalDetailUiState.Success ?: return@launch

if (!userRepository.isSigned()) {
_event.emit(BookmarkFailure("로그인이 필요합니다"))
return@launch
}

if (uiState.bookmarked) {
_uiState.value = uiState.copy(bookmarked = false)
bookmarkRepository.deleteFestivalBookmark(festivalId)
.onSuccess { _event.emit(BookmarkSuccess(false)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = true)
_event.emit(BookmarkFailure("북마크를 해제할 수 없습니다. 인터넷 연결을 확인해주세요"))
if (it.isUnauthorized()) {
_event.emit(BookmarkFailure("로그인이 필요해요"))
}
if (it.isNetworkError()) {
_uiState.value = uiState.copy(bookmarked = true)
_event.emit(BookmarkFailure("인터넷 연결을 확인해주세요"))
}
}
} else {
_uiState.value = uiState.copy(bookmarked = true)
bookmarkRepository.addFestivalBookmark(festivalId)
.onSuccess { _event.emit(BookmarkSuccess(true)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("다른 북마크를 해제하거나 인터넷 연결을 확인해주세요"))
if (it.isUnauthorized()) {
_event.emit(BookmarkFailure("로그인이 필요해요"))
}
if (it.isBookmarkLimitExceeded()) {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("북마크는 12개까지 가능해요"))
}
if (it.isNetworkError()) {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("인터넷 연결을 확인해주세요"))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.festago.festago.common.analytics.AnalyticsHelper
import com.festago.festago.common.analytics.logNetworkFailure
import com.festago.festago.domain.exception.isBookmarkLimitExceeded
import com.festago.festago.domain.exception.isNetworkError
import com.festago.festago.domain.exception.isUnauthorized
import com.festago.festago.domain.model.bookmark.BookmarkType
import com.festago.festago.domain.model.festival.Festival
import com.festago.festago.domain.repository.BookmarkRepository
Expand Down Expand Up @@ -106,25 +109,35 @@ class SchoolDetailViewModel @Inject constructor(
val uiState = uiState.value as? SchoolDetailUiState.Success ?: return

viewModelScope.launch {
if (!userRepository.isSigned()) {
_event.emit(BookmarkFailure("로그인이 필요합니다"))
return@launch
}
if (uiState.bookmarked) {
_uiState.value = uiState.copy(bookmarked = false)
bookmarkRepository.deleteSchoolBookmark(schoolId.toLong())
.onSuccess { _event.emit(BookmarkSuccess(false)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = true)
_event.emit(BookmarkFailure("북마크를 해제할 수 없습니다. 인터넷 연결을 확인해주세요"))
if (it.isUnauthorized()) {
_event.emit(BookmarkFailure("로그인이 필요해요"))
}
if (it.isNetworkError()) {
_uiState.value = uiState.copy(bookmarked = true)
_event.emit(BookmarkFailure("인터넷 연결을 확인해주세요"))
}
}
} else {
_uiState.value = uiState.copy(bookmarked = true)
bookmarkRepository.addSchoolBookmark(uiState.schoolInfo.id.toLong())
.onSuccess { _event.emit(BookmarkSuccess(true)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("다른 북마크를 해제하거나 인터넷 연결을 확인해주세요"))
if (it.isUnauthorized()) {
_event.emit(BookmarkFailure("로그인이 필요해요"))
}
if (it.isBookmarkLimitExceeded()) {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("북마크는 12개까지 가능해요"))
}
if (it.isNetworkError()) {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("인터넷 연결을 확인해주세요"))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ class ArtistSearchViewHolder(

fun bind(item: ArtistSearchItemUiState) {
binding.item = item
binding.tvTodayStageCount.setStageCount(
count = item.todayStage,
stringRes = R.string.search_artist_tv_today_stage_count,
)
binding.tvUpcomingStageCount.setStageCount(
item.upcomingStage,
stringRes = R.string.search_artist_tv_upcoming_stage_count,
)

if (item.todayStage == 0 && item.upcomingStage == 0) {
binding.tvTodayStageCount.visibility = TextView.GONE
binding.tvUpcomingStageCount.visibility = TextView.GONE
} else {
binding.tvTodayStageCount.setStageCount(
count = item.todayStage,
stringRes = R.string.search_artist_tv_today_stage_count,
)

binding.tvUpcomingStageCount.setStageCount(
item.upcomingStage,
stringRes = R.string.search_artist_tv_upcoming_stage_count,
)
binding.tvEmptyStage.visibility = TextView.GONE
}
}

private fun TextView.setStageCount(count: Int, @StringRes stringRes: Int) {
Expand All @@ -35,9 +43,15 @@ class ArtistSearchViewHolder(
getPartialColorText(
start = COLOR_INDEX,
end = COLOR_INDEX + count.toString().length,
color = context.getColor(R.color.secondary_pink_01),
color = when (count) {
0 -> context.getColor(R.color.contents_gray_05)
else -> context.getColor(R.color.secondary_pink_01)
},
)
}
if (count == 0) {
setTextColor(context.getColor(R.color.contents_gray_05))
}
}

private fun SpannableString.getPartialColorText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
app:tabGravity="fill"
app:tabIndicatorColor="@color/contents_gray_07"
app:tabIndicatorFullWidth="false"
app:tabRippleColor="@color/contents_gray_04"
app:tabIndicatorHeight="2dp"
app:tabSelectedTextColor="@color/contents_gray_07"
app:tabTextAppearance="@style/H4Bold16Lh20"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
tools:src="@drawable/ic_launcher_foreground" />
android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>

<TextView
Expand Down Expand Up @@ -86,5 +85,17 @@
app:layout_constraintTop_toTopOf="@id/tvTodayStageCount"
tools:text="공연 예정 2개" />

<TextView
android:id="@+id/tvEmptyStage"
style="@style/B2Medium14Lh20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_artist_tv_no_plan"
android:includeFontPadding="false"
android:textColor="@color/contents_gray_05"
app:layout_constraintBottom_toBottomOf="@id/tvTodayStageCount"
app:layout_constraintStart_toEndOf="@id/tvTodayStageCount"
app:layout_constraintTop_toTopOf="@id/tvTodayStageCount" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
13 changes: 7 additions & 6 deletions android/festago/presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<!-- String related to artist detail -->
<string name="artist_detail_tv_dday_format">D%1$s</string>
<string name="artist_detail_tv_empty_festivals">아직 축제가 없어요</string>
<string name="artist_detail_bookmark_success">아티스트를 북마크 했습니다</string>
<string name="artist_detail_bookmark_cancel">북마크를 취소했습니다</string>
<string name="artist_detail_bookmark_success">북마크에 추가했어요</string>
<string name="artist_detail_bookmark_cancel">북마크에서 삭제했어요</string>

<!-- String related to notification list-->
<string name="notification_list_tv_notification_app_bar">알림</string>
Expand All @@ -38,8 +38,8 @@

<!-- String related to festival detail -->
<string name="festival_detail_tv_empty_stages">아직 라인업이 공개되지 않았어요</string>
<string name="festival_detail_bookmark_success">축제를 북마크 했습니다</string>
<string name="festival_detail_bookmark_cancel">북마크를 취소했습니다</string>
<string name="festival_detail_bookmark_success">북마크에 추가했어요</string>
<string name="festival_detail_bookmark_cancel">북마크에서 삭제했어요</string>

<!-- String related to festival dday -->
<string name="tv_dday_in_progress">진행 중</string>
Expand All @@ -51,8 +51,8 @@

<!-- String related to school detail -->
<string name="school_detail_tv_empty_festivals">아직 축제가 없어요</string>
<string name="school_detail_bookmark_success">학교를 북마크 했습니다</string>
<string name="school_detail_bookmark_cancel">북마크를 취소했습니다</string>
<string name="school_detail_bookmark_success">북마크에 추가했어요</string>
<string name="school_detail_bookmark_cancel">북마크에서 삭제했어요</string>

<!-- String related to search -->
<string name="search_et_search_hint">학교명, 아티스트명, 축제명으로 입력하세요.</string>
Expand All @@ -68,6 +68,7 @@
<string name="search_school_tv_no_plan">예정 없음</string>
<string name="search_artist_tv_today_stage_count">오늘 공연 %d개</string>
<string name="search_artist_tv_upcoming_stage_count">공연 예정 %d개</string>
<string name="search_artist_tv_no_plan">예정 없음</string>
<string name="search_tv_no_result">앗! 검색 결과가 없네요</string>
<string name="search_tv_no_result_guide">찾으시는 정보가 없다면 저희에게 알려주세요</string>
<string name="search_tv_request_add">추가 요청하러 가기</string>
Expand Down
Loading