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

[FIX] 스크랩, 홈 로직 수정 #176

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class HomeActivity : BaseActivity<ActivityHomeBinding>(
}
}

private fun setLayoutBorder(){
private fun setLayoutBorder() {
binding.clHomeArchiving.clipToOutline = true
binding.clHomeScrap.clipToOutline = true
}
Expand Down Expand Up @@ -224,6 +224,11 @@ class HomeActivity : BaseActivity<ActivityHomeBinding>(
when (state) {
is UiState.Empty -> Unit
is UiState.Failure -> {
binding.tvHomeTeam.text = if(sharedPreference.teamId == 0){
"모두를 응원하는"
} else {
sharedPreference.teamName
}
makeSpotImageAppbar("내 정보 불러오기를 실패하였습니다.\uD83E\uDEE2")
}

Expand Down Expand Up @@ -262,8 +267,8 @@ class HomeActivity : BaseActivity<ActivityHomeBinding>(
message = "현재 잠실야구장만 이용할 수 있어요!",
endMessage = "잠실야구장 보기",
marginBottom = 87,
onClick = {startStadiumActivity(it)}
) .show()
onClick = { startStadiumActivity(it) }
).show()

} else {
MixpanelManager.track("home_find_view")
Expand Down Expand Up @@ -324,6 +329,7 @@ class HomeActivity : BaseActivity<ActivityHomeBinding>(
shimmerHomeStadium.visibility = View.GONE
}
}

private fun setHomeFeedVisibility(isSuccess: Boolean) {
val visibility = if (isSuccess) View.VISIBLE else View.GONE
with(binding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ class ScrapActivity : BaseActivity<ActivityScrapBinding>(
when (state) {
is UiState.Success -> {
binding.tvScrapCount.text = state.data.totalScrapCount.toString()
scrapAdapter.submitList(state.data.reviews)
isLoading = false
scrapAdapter.submitList(state.data.reviews) {
binding.rvScrapRecord.invalidateItemDecorations()
isLoading = false
}

setScrapScreenVisibility(ScrapScreenState.SUCCESS)
}

Expand Down Expand Up @@ -131,7 +134,7 @@ class ScrapActivity : BaseActivity<ActivityScrapBinding>(
val scrollBottom = !binding.rvScrapRecord.canScrollVertically(1)
val scrollTop = !binding.rvScrapRecord.canScrollVertically(-1)

if (scrollBottom && !isLoading && (viewModel.scrap.value as UiState.Success).data.hasNext) {
if (scrollBottom && !isLoading && viewModel.scrap.value is UiState.Success && (viewModel.scrap.value as UiState.Success).data.hasNext) {
viewModel.getNextScrapRecord()
isLoading = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class ScrapDetailPictureFragment : BindingFragment<FragmentScrapDetailPictureBin

private fun initObserve() {
viewModel.detailScrap.asLiveData().observe(viewLifecycleOwner) { data ->
adapter.submitList(data.reviews.map { it.baseReview }.toList())
binding.vpScrap.setCurrentItem(viewModel.currentPage.value, false)
adapter.submitList(data.reviews.map { it.baseReview }.toList()){
binding.vpScrap.setCurrentItem(viewModel.currentPage.value, false)
}
isLoading = false
}

Expand Down Expand Up @@ -151,16 +152,15 @@ class ScrapDetailPictureFragment : BindingFragment<FragmentScrapDetailPictureBin
} else {
if (viewModel.isFirstLike.value) {
updateRecyclerViewVisibility(false)
}
else
} else
hideLikeDescriptionView()
}
}

override fun onPageSelected(position: Int) {
super.onPageSelected(position)
binding.spotAppbar.setText(viewModel.detailScrap.value.reviews[position].baseReview.formattedStadiumToSection())
if (!isLoading && position >= adapter.itemCount - 2 && (viewModel.scrap.value as UiState.Success).data.hasNext) {
if (!isLoading && position >= adapter.itemCount - 2 && viewModel.scrap.value is UiState.Success && viewModel.detailScrap.value.hasNext) {
isLoading = true
viewModel.getNextScrapRecord()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data class BadReviewData(
class ScrapViewModel @Inject constructor(
private val homeRepository: HomeRepository,
private val viewfinderRepository: ViewfinderRepository,
private val sharedPreference: SharedPreference
private val sharedPreference: SharedPreference,
) : ViewModel() {

private var monthsSelected: List<MonthFilterData> = emptyList()
Expand Down Expand Up @@ -100,12 +100,12 @@ class ScrapViewModel @Inject constructor(
}
}

fun updateIsFirstLike(isFirstLike : Boolean) {
fun updateIsFirstLike(isFirstLike: Boolean) {
sharedPreference.isFirstLike = isFirstLike
_isFirstLike.value = isFirstLike
}

fun updateIsFirstShare(isFirstShare : Boolean) {
fun updateIsFirstShare(isFirstShare: Boolean) {
sharedPreference.isFirstShare = isFirstShare
}

Expand All @@ -114,23 +114,25 @@ class ScrapViewModel @Inject constructor(
}

fun reloadScrap() {
if(GlobalVariable.isScrap && _scrap.value is UiState.Empty) {
if (GlobalVariable.isScrap && _scrap.value is UiState.Empty) {
getScrapRecord()
}
}

fun updateScrapRecord() {
if(_detailScrap.value.reviews.count { it.baseReview.isScrapped } == 0){
if (_detailScrap.value.reviews.count { it.baseReview.isScrapped } == 0) {
_scrap.value = UiState.Empty
}else{
_scrap.value = UiState.Success( detailScrap.value.copy(
} else {
_scrap.value = UiState.Success(detailScrap.value.copy(
reviews = _detailScrap.value.reviews.filter { it.baseReview.isScrapped }
))
}
}


fun getNextScrapRecord() {
val data = (_scrap.value as? UiState.Success)?.data ?: return
if (!data.hasNext || data.nextCursor == null) return
viewModelScope.launch {
homeRepository.getScrap(
size = 20,
Expand All @@ -156,7 +158,14 @@ class ScrapViewModel @Inject constructor(
)
_scrap.value = UiState.Success(updatedScrap)
val currentDetailScrap = _detailScrap.value.reviews
_detailScrap.value = detailScrap.value.copy(reviews = currentDetailScrap + it.reviews)
_detailScrap.value =
detailScrap.value.copy(
reviews = currentDetailScrap + it.reviews,
nextCursor = it.nextCursor,
hasNext = it.hasNext,
totalScrapCount = it.totalScrapCount,
filter = it.filter
)
}.onFailure {}
}
}
Expand All @@ -181,7 +190,7 @@ class ScrapViewModel @Inject constructor(
getScrapRecord()
}

fun setCurrentPage(page : Int) {
fun setCurrentPage(page: Int) {
_currentPage.value = page
}

Expand Down Expand Up @@ -248,11 +257,11 @@ class ScrapViewModel @Inject constructor(
}
}
val updatedDetailList = detailScrap.value.reviews.map { review ->
if(review.baseReview.id == id){
if (review.baseReview.id == id) {
review.copy(
baseReview = review.baseReview.copy(
isLiked = !review.baseReview.isLiked,
likesCount = if (review.baseReview.isLiked) {
likesCount = if (review.baseReview.isLiked) {
review.baseReview.likesCount - 1
} else {
review.baseReview.likesCount + 1
Expand Down Expand Up @@ -290,7 +299,7 @@ class ScrapViewModel @Inject constructor(
}

val detailScrapUpdatedList = detailScrap.value.reviews.map { review ->
if(review.baseReview.id == id){
if (review.baseReview.id == id) {
review.copy(
baseReview = review.baseReview.copy(
isScrapped = !review.baseReview.isScrapped
Expand Down
Loading