Skip to content

Commit

Permalink
feat: 북마크 성공 및 실패 시 토스트 메세지를 띄운다
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed May 5, 2024
1 parent 2fabc1f commit 5adb64d
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import com.festago.festago.presentation.ui.artistdetail.uistate.FestivalItemUiSt
sealed interface ArtistDetailEvent {
class ShowArtistDetail(val artist: ArtistUiState) : ArtistDetailEvent
class ShowFestivalDetail(val festival: FestivalItemUiState) : ArtistDetailEvent
class FailedToFetchBookmarkList(val message: String) : ArtistDetailEvent
class BookmarkSuccess(val isBookmarked: Boolean) : ArtistDetailEvent
class BookmarkFailure(val message: String) : ArtistDetailEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,19 @@ class ArtistDetailFragment : Fragment() {
)
}

is ArtistDetailEvent.FailedToFetchBookmarkList -> {
is ArtistDetailEvent.BookmarkSuccess -> {
Toast.makeText(
requireContext(),
if (event.isBookmarked) {
getString(R.string.artist_detail_bookmark_success)
} else {
getString(R.string.artist_detail_bookmark_cancel)
},
Toast.LENGTH_SHORT,
).show()
}

is ArtistDetailEvent.BookmarkFailure -> {
Toast.makeText(requireContext(), event.message, Toast.LENGTH_SHORT)
.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import com.festago.festago.domain.model.festival.FestivalsPage
import com.festago.festago.domain.repository.ArtistRepository
import com.festago.festago.domain.repository.BookmarkRepository
import com.festago.festago.domain.repository.UserRepository
import com.festago.festago.presentation.ui.artistdetail.ArtistDetailEvent.FailedToFetchBookmarkList
import com.festago.festago.presentation.ui.artistdetail.ArtistDetailEvent.BookmarkFailure
import com.festago.festago.presentation.ui.artistdetail.ArtistDetailEvent.BookmarkSuccess
import com.festago.festago.presentation.ui.artistdetail.ArtistDetailEvent.ShowArtistDetail
import com.festago.festago.presentation.ui.artistdetail.ArtistDetailEvent.ShowFestivalDetail
import com.festago.festago.presentation.ui.artistdetail.uistate.ArtistDetailUiState
import com.festago.festago.presentation.ui.artistdetail.uistate.ArtistUiState
import com.festago.festago.presentation.ui.artistdetail.uistate.FestivalItemUiState
Expand Down Expand Up @@ -106,18 +109,26 @@ class ArtistDetailViewModel @Inject constructor(
val uiState = uiState.value as? ArtistDetailUiState.Success ?: return@launch

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

if (uiState.bookMarked) {
_uiState.value = uiState.copy(bookMarked = false)
bookmarkRepository.deleteArtistBookmark(artistId.toLong())
.onSuccess { _uiState.value = uiState.copy(bookMarked = false) }
.onFailure { _event.emit(FailedToFetchBookmarkList("최대 북마크 갯수를 초과했습니다")) }
.onSuccess { _event.emit(BookmarkSuccess(false)) }
.onFailure {
_uiState.value = uiState.copy(bookMarked = true)
_event.emit(BookmarkFailure("북마크를 해제할 수 없습니다. 인터넷 연결을 확인해주세요"))
}
} else {
_uiState.value = uiState.copy(bookMarked = true)
bookmarkRepository.addArtistBookmark(artistId.toLong())
.onSuccess { _uiState.value = uiState.copy(bookMarked = true) }
.onFailure { _event.emit(FailedToFetchBookmarkList("최대 북마크 갯수를 초과했습니다")) }
.onSuccess { _event.emit(BookmarkSuccess(true)) }
.onFailure {
_uiState.value = uiState.copy(bookMarked = false)
_event.emit(BookmarkFailure("다른 북마크를 해제하거나 인터넷 연결을 확인해주세요"))
}
}
}
}
Expand Down Expand Up @@ -147,14 +158,14 @@ class ArtistDetailViewModel @Inject constructor(
imageUrl = artist.imageUrl,
onArtistDetailClick = { artistDetail ->
viewModelScope.launch {
_event.emit(ArtistDetailEvent.ShowArtistDetail(artistDetail))
_event.emit(ShowArtistDetail(artistDetail))
}
},
)
},
onFestivalDetailClick = { festivalDetail ->
viewModelScope.launch {
_event.emit(ArtistDetailEvent.ShowFestivalDetail(festivalDetail))
_event.emit(ShowFestivalDetail(festivalDetail))
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import com.festago.festago.presentation.ui.festivaldetail.uiState.ArtistItemUiSt
sealed interface FestivalDetailEvent {
class ShowArtistDetail(val artist: ArtistItemUiState) : FestivalDetailEvent
class ShowSchoolDetail(val school: School) : FestivalDetailEvent
class FailedToFetchBookmarkList(val message: String) : FestivalDetailEvent
class BookmarkSuccess(val isBookmarked: Boolean) : FestivalDetailEvent
class BookmarkFailure(val message: String) : FestivalDetailEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,19 @@ class FestivalDetailFragment : Fragment() {
)
}

is FestivalDetailEvent.FailedToFetchBookmarkList -> {
is FestivalDetailEvent.BookmarkSuccess -> {
Toast.makeText(
requireContext(),
if (event.isBookmarked) {
getString(R.string.festival_detail_bookmark_success)
} else {
getString(R.string.festival_detail_bookmark_cancel)
},
Toast.LENGTH_SHORT,
).show()
}

is FestivalDetailEvent.BookmarkFailure -> {
Toast.makeText(requireContext(), event.message, Toast.LENGTH_SHORT).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import com.festago.festago.domain.model.stage.Stage
import com.festago.festago.domain.repository.BookmarkRepository
import com.festago.festago.domain.repository.FestivalRepository
import com.festago.festago.domain.repository.UserRepository
import com.festago.festago.presentation.ui.festivaldetail.FestivalDetailEvent.FailedToFetchBookmarkList
import com.festago.festago.presentation.ui.festivaldetail.FestivalDetailEvent.BookmarkFailure
import com.festago.festago.presentation.ui.festivaldetail.FestivalDetailEvent.BookmarkSuccess
import com.festago.festago.presentation.ui.festivaldetail.FestivalDetailEvent.ShowArtistDetail
import com.festago.festago.presentation.ui.festivaldetail.FestivalDetailEvent.ShowSchoolDetail
import com.festago.festago.presentation.ui.festivaldetail.uiState.ArtistItemUiState
import com.festago.festago.presentation.ui.festivaldetail.uiState.FestivalDetailUiState
import com.festago.festago.presentation.ui.festivaldetail.uiState.FestivalUiState
Expand Down Expand Up @@ -94,18 +97,26 @@ class FestivalDetailViewModel @Inject constructor(
val uiState = _uiState.value as? FestivalDetailUiState.Success ?: return@launch

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

if (uiState.bookmarked) {
_uiState.value = uiState.copy(bookmarked = false)
bookmarkRepository.deleteFestivalBookmark(festivalId)
.onSuccess { _uiState.value = uiState.copy(bookmarked = false) }
.onFailure { _event.emit(FailedToFetchBookmarkList("최대 북마크 갯수를 초과했습니다")) }
.onSuccess { _event.emit(BookmarkSuccess(false)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = true)
_event.emit(BookmarkFailure("북마크를 해제할 수 없습니다. 인터넷 연결을 확인해주세요"))
}
} else {
_uiState.value = uiState.copy(bookmarked = true)
bookmarkRepository.addFestivalBookmark(festivalId)
.onSuccess { _uiState.value = uiState.copy(bookmarked = true) }
.onFailure { _event.emit(FailedToFetchBookmarkList("최대 북마크 갯수를 초과했습니다")) }
.onSuccess { _event.emit(BookmarkSuccess(true)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("다른 북마크를 해제하거나 인터넷 연결을 확인해주세요"))
}
}
}
}
Expand All @@ -125,13 +136,13 @@ class FestivalDetailViewModel @Inject constructor(

private fun showArtistDetail(artist: ArtistItemUiState) {
viewModelScope.launch {
_event.emit(FestivalDetailEvent.ShowArtistDetail(artist))
_event.emit(ShowArtistDetail(artist))
}
}

private fun showSchoolDetail(school: School) {
viewModelScope.launch {
_event.emit(FestivalDetailEvent.ShowSchoolDetail(school))
_event.emit(ShowSchoolDetail(school))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ sealed interface SchoolDetailEvent {

class ShowFestivalDetail(val festival: FestivalItemUiState) : SchoolDetailEvent

class FailedToFetchBookmarkList(val message: String) : SchoolDetailEvent
class BookmarkSuccess(val isBookmarked: Boolean) : SchoolDetailEvent

class BookmarkFailure(val message: String) : SchoolDetailEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,19 @@ class SchoolDetailFragment : Fragment() {
)
}

is SchoolDetailEvent.FailedToFetchBookmarkList -> {
is SchoolDetailEvent.BookmarkSuccess -> {
Toast.makeText(
requireContext(),
if (event.isBookmarked) {
getString(R.string.school_detail_bookmark_success)
} else {
getString(R.string.school_detail_bookmark_cancel)
},
Toast.LENGTH_SHORT,
).show()
}

is SchoolDetailEvent.BookmarkFailure -> {
Toast.makeText(requireContext(), event.message, Toast.LENGTH_SHORT).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import com.festago.festago.domain.model.festival.Festival
import com.festago.festago.domain.repository.BookmarkRepository
import com.festago.festago.domain.repository.SchoolRepository
import com.festago.festago.domain.repository.UserRepository
import com.festago.festago.presentation.ui.schooldetail.SchoolDetailEvent.FailedToFetchBookmarkList
import com.festago.festago.presentation.ui.schooldetail.SchoolDetailEvent.BookmarkFailure
import com.festago.festago.presentation.ui.schooldetail.SchoolDetailEvent.BookmarkSuccess
import com.festago.festago.presentation.ui.schooldetail.SchoolDetailEvent.ShowArtistDetail
import com.festago.festago.presentation.ui.schooldetail.SchoolDetailEvent.ShowFestivalDetail
import com.festago.festago.presentation.ui.schooldetail.uistate.ArtistUiState
import com.festago.festago.presentation.ui.schooldetail.uistate.FestivalItemUiState
import com.festago.festago.presentation.ui.schooldetail.uistate.SchoolDetailUiState
Expand Down Expand Up @@ -104,17 +107,25 @@ class SchoolDetailViewModel @Inject constructor(

viewModelScope.launch {
if (!userRepository.isSigned()) {
_event.emit(FailedToFetchBookmarkList("로그인이 필요합니다"))
_event.emit(BookmarkFailure("로그인이 필요합니다"))
return@launch
}
if (uiState.bookmarked) {
_uiState.value = uiState.copy(bookmarked = false)
bookmarkRepository.deleteSchoolBookmark(schoolId.toLong())
.onSuccess { _uiState.value = uiState.copy(bookmarked = false) }
.onFailure { _event.emit(FailedToFetchBookmarkList("최대 북마크 갯수를 초과했습니다")) }
.onSuccess { _event.emit(BookmarkSuccess(false)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = true)
_event.emit(BookmarkFailure("북마크를 해제할 수 없습니다. 인터넷 연결을 확인해주세요"))
}
} else {
_uiState.value = uiState.copy(bookmarked = true)
bookmarkRepository.addSchoolBookmark(uiState.schoolInfo.id.toLong())
.onSuccess { _uiState.value = uiState.copy(bookmarked = true) }
.onFailure { _event.emit(FailedToFetchBookmarkList("최대 북마크 갯수를 초과했습니다")) }
.onSuccess { _event.emit(BookmarkSuccess(true)) }
.onFailure {
_uiState.value = uiState.copy(bookmarked = false)
_event.emit(BookmarkFailure("다른 북마크를 해제하거나 인터넷 연결을 확인해주세요"))
}
}
}
}
Expand Down Expand Up @@ -143,14 +154,14 @@ class SchoolDetailViewModel @Inject constructor(
imageUrl = artist.imageUrl,
onArtistDetailClick = { artistUiState ->
viewModelScope.launch {
_event.emit(SchoolDetailEvent.ShowArtistDetail(artistUiState))
_event.emit(ShowArtistDetail(artistUiState))
}
},
)
},
onFestivalDetailClick = { festivalUiState ->
viewModelScope.launch {
_event.emit(SchoolDetailEvent.ShowFestivalDetail(festivalUiState))
_event.emit(ShowFestivalDetail(festivalUiState))
}
},
)
Expand Down
9 changes: 7 additions & 2 deletions android/festago/presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +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 related to notification list-->
<string name="notification_list_tv_notification_app_bar">알림</string>
Expand All @@ -36,7 +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 related to festival dday -->
<string name="tv_dday_in_progress">진행 중</string>
Expand All @@ -46,8 +49,10 @@
<!-- String related to region bottom sheet -->
<string name="region_bottom_sheet_tv_region">지역별</string>

<!-- String related to artist detail -->
<!-- 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 related to search -->
<string name="search_et_search_hint">학교명, 아티스트명, 축제명으로 입력하세요.</string>
Expand Down

0 comments on commit 5adb64d

Please sign in to comment.