Skip to content
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
18 changes: 9 additions & 9 deletions app/src/main/java/com/into/websoso/ui/main/feed/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import com.into.websoso.core.designsystem.theme.WebsosoTheme
import com.into.websoso.databinding.DialogRemovePopupMenuBinding
import com.into.websoso.databinding.DialogReportPopupMenuBinding
import com.into.websoso.databinding.FragmentFeedBinding
import com.into.websoso.feature.feed.UpdateFeedRoute
import com.into.websoso.feature.feed.UpdatedFeedViewModel
import com.into.websoso.feature.feed.FeedRoute
import com.into.websoso.feature.feed.FeedViewModel
import com.into.websoso.ui.createFeed.CreateFeedActivity
import com.into.websoso.ui.feedDetail.FeedDetailActivity
import com.into.websoso.ui.feedDetail.model.EditFeedModel
Expand All @@ -35,7 +35,7 @@ import javax.inject.Inject
class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {
@Inject
lateinit var tracker: Tracker
private val updatedFeedViewModel: UpdatedFeedViewModel by viewModels()
private val feedViewModel: FeedViewModel by viewModels()

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -49,8 +49,8 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
WebsosoTheme {
UpdateFeedRoute(
viewModel = updatedFeedViewModel,
FeedRoute(
viewModel = feedViewModel,
onWriteClick = ::navigateToWriteFeed,
onProfileClick = { userId, isMyFeed ->
navigateToProfile(
Expand All @@ -71,21 +71,21 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {

false -> showDialog<DialogReportPopupMenuBinding>(
menuType = ReportMenuType.SPOILER_FEED.name,
event = { updatedFeedViewModel.updateReportedSpoilerFeed(feedId) },
event = { feedViewModel.updateReportedSpoilerFeed(feedId) },
)
}
},
onSecondItemClick = { feedId, isMyFeed ->
when (isMyFeed) {
true -> showDialog<DialogRemovePopupMenuBinding>(
menuType = REMOVE_FEED.name,
event = { updatedFeedViewModel.updateRemovedFeed(feedId) },
event = { feedViewModel.updateRemovedFeed(feedId) },
)

false -> showDialog<DialogReportPopupMenuBinding>(
menuType = ReportMenuType.IMPERTINENCE_FEED.name,
event = {
updatedFeedViewModel.updateReportedImpertinenceFeed(
feedViewModel.updateReportedImpertinenceFeed(
feedId,
)
},
Expand Down Expand Up @@ -148,7 +148,7 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {

private fun navigateToFeedEdit(feedId: Long) {
val feedContent =
updatedFeedViewModel.uiState.value.myFeedData.feeds
feedViewModel.uiState.value.myFeedData.feeds
.find { it.id == feedId }
?.let { feed ->
EditFeedModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import kotlinx.serialization.Serializable
data class UserFeedsResponseDto(
@SerialName("feeds")
val feeds: List<UserFeedResponseDto>,
@SerialName("feedsCount")
val feedsCount: Int,
@SerialName("isLoadable")
val isLoadable: Boolean,
) {
Expand Down
10 changes: 7 additions & 3 deletions data/user/src/main/java/com/into/websoso/user/UserRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ class UserRepository
isVisible: Boolean? = null,
isUnVisible: Boolean? = null,
sortCriteria: String? = null,
): UserFeedsEntity =
userApi
): UserFeedsEntity {
val isDefaultFilter =
genres == null && isVisible == null && isUnVisible == null && sortCriteria == null

return userApi
.getUserFeeds(
userId,
lastFeedId,
Expand All @@ -66,7 +69,8 @@ class UserRepository
isVisible,
isUnVisible,
sortCriteria,
).toData()
).toData(isDefaultFilter = isDefaultFilter)
}

suspend fun fetchMyProfile(): MyProfileEntity = userApi.getMyProfile().toData()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import com.into.websoso.user.model.MyProfileEntity
import com.into.websoso.user.model.UserFeedsEntity
import com.into.websoso.user.model.UserInfoEntity

fun UserFeedsResponseDto.toData(): UserFeedsEntity =
fun UserFeedsResponseDto.toData(isDefaultFilter: Boolean): UserFeedsEntity =
UserFeedsEntity(
isLoadable = this.isLoadable,
feedsCount = if (isDefaultFilter) feedsCount else this.feeds.size,
feeds = this.feeds.map { it.toData() },
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.into.websoso.user.model

data class UserFeedsEntity(
val isLoadable: Boolean,
val feedsCount: Int,
val feeds: List<UserFeedEntity>,
) {
data class UserFeedEntity(
Expand Down
57 changes: 37 additions & 20 deletions domain/feed/src/main/java/com/into/websoso/feed/GetFeedsUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
package com.into.websoso.feed

import com.into.websoso.data.feed.repository.FeedRepository
import com.into.websoso.data.feed.repository.UpdatedFeedRepository
import com.into.websoso.feed.mapper.toDomain
import com.into.websoso.feed.model.Feed
import com.into.websoso.feed.model.Feeds
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class GetFeedsUseCase @Inject constructor(
private val feedRepository: FeedRepository,
) {
suspend operator fun invoke(
feedsOption: String = DEFAULT_OPTION,
lastFeedId: Long = INITIAL_ID,
): Feeds {
val isFeedRefreshed: Boolean = lastFeedId == INITIAL_ID
class GetFeedsUseCase
@Inject
constructor(
private val feedRepository: UpdatedFeedRepository,
) {
val sosoAllFlow: Flow<List<Feed>> = feedRepository.sosoAllFeeds
.map { list -> list.map { it.toDomain() } }

return feedRepository
.fetchFeeds(
feedsOption = feedsOption,
val sosoRecommendedFlow: Flow<List<Feed>> = feedRepository.sosoRecommendedFeeds
.map { list -> list.map { it.toDomain() } }

/**
* [Modified] 데이터 로드 트리거
* - 서버에서 데이터를 가져와 Repository 내부의 HotFlow를 업데이트합니다.
* - 반환값은 UI의 페이징 상태(isLoadable, lastId) 관리를 위한 메타데이터입니다.
*/
suspend operator fun invoke(
feedsOption: String = DEFAULT_OPTION,
lastFeedId: Long = INITIAL_ID,
): Feeds {
val isFeedRefreshed: Boolean = lastFeedId == INITIAL_ID

val feedsEntity = feedRepository.fetchFeeds(
lastFeedId = lastFeedId,
size = if (isFeedRefreshed) INITIAL_REQUEST_SIZE else ADDITIONAL_REQUEST_SIZE,
).toDomain()
}
feedsOption = feedsOption,
)

return feedsEntity.toDomain()
}

companion object {
private const val DEFAULT_OPTION = "ALL"
private const val INITIAL_ID: Long = 0
private const val INITIAL_REQUEST_SIZE = 40
private const val ADDITIONAL_REQUEST_SIZE = 20
companion object {
private const val DEFAULT_OPTION = "ALL"
private const val INITIAL_ID: Long = 0
private const val INITIAL_REQUEST_SIZE = 40
private const val ADDITIONAL_REQUEST_SIZE = 20
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package com.into.websoso.feed

import com.into.websoso.data.feed.repository.UpdatedFeedRepository
import com.into.websoso.feed.mapper.toDomain
import com.into.websoso.feed.mapper.toFeedEntity
import com.into.websoso.feed.model.Feed
import com.into.websoso.feed.model.Feeds
import com.into.websoso.user.UserRepository
import com.into.websoso.user.model.MyProfileEntity
import com.into.websoso.user.model.UserFeedsEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class GetMyFeedsUseCase
@Inject
constructor(
private val userRepository: UserRepository,
private val feedRepository: UpdatedFeedRepository,
) {
val myFeedsFlow: Flow<List<Feed>> = feedRepository.myFeeds
.map { list -> list.map { it.toDomain() } }

private var myProfile: MyProfileEntity? = null
private var myId: Long? = null

Expand All @@ -27,7 +36,7 @@ class GetMyFeedsUseCase
val profile = myProfile ?: userRepository.fetchMyProfile().also { myProfile = it }
val myId = myId ?: userRepository.fetchUserInfo().userId.also { myId = it }

val myFeeds: UserFeedsEntity = userRepository.fetchMyActivities(
val myFeedsEntity: UserFeedsEntity = userRepository.fetchMyActivities(
lastFeedId = lastFeedId,
size = if (isFeedRefreshed) INITIAL_REQUEST_SIZE else ADDITIONAL_REQUEST_SIZE,
genres = genres?.toTypedArray(),
Expand All @@ -36,10 +45,20 @@ class GetMyFeedsUseCase
sortCriteria = sortCriteria,
)

val convertedFeeds = myFeedsEntity.feeds.map { userFeed ->
userFeed.toFeedEntity(userProfile = profile, userId = myId)
}

feedRepository.updateMyFeedsCache(
feeds = convertedFeeds,
isRefreshed = isFeedRefreshed,
)

return Feeds(
category = "내 활동",
isLoadable = myFeeds.isLoadable,
feeds = myFeeds.feeds.map { it.toDomain(myProfile = profile, id = myId) },
isLoadable = myFeedsEntity.isLoadable,
totalCount = myFeedsEntity.feedsCount,
feeds = emptyList(),
)
}

Expand Down

This file was deleted.

This file was deleted.

Loading
Loading