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

#135 pagination #137

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
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 @@ -2,7 +2,7 @@ package com.d_vide.D_VIDE.app.data.remote.responseDTO

data class FollowInfoDataDTO (
val userId: Long,
val profileImageUrl: String,
val profileImgUrl: String,
val nickname: String,
val followId: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GetRecruitings @Inject constructor(
latitude: Double,
longitude: Double,
category: Category,
offset: Int
offset: Int = 0
): Flow<Resource<RecruitingsDTO>> = flow {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import javax.inject.Inject
class GetMyReviews @Inject constructor(
private val repository: ReviewRepository,
) {
operator fun invoke(first: Int): Flow<Resource<ReviewsDTO>> = flow {
operator fun invoke(first: Int = 0): Flow<Resource<ReviewsDTO>> = flow {

try {
emit(Resource.Loading())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GetReviews @Inject constructor(
operator fun invoke(
longitude: Double,
latitude: Double,
first: Int
first: Int = 1
): Flow<Resource<ReviewsDTO>> = flow {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import javax.inject.Inject
class GetStoreReview @Inject constructor(
private val repository: ReviewRepository,
) {
operator fun invoke(first: Int, storeName: String): Flow<Resource<ReviewsDTO>> = flow {
operator fun invoke(first: Int = 0, storeName: String): Flow<Resource<ReviewsDTO>> = flow {

try {
emit(Resource.Loading())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ private fun NavGraphBuilder.MyReviewNavGraph(
navController = navController,
onReviewSelected = { id -> onReviewClick(id, from) },
onTagClick = { id -> onTagClick(id, from) },
onRecruitingClick = { id -> onRecruitingClick(id, from) }
onRecruitingClick = { id -> onRecruitingClick(id, from) },
upPress = upPress
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ data class FollowState(
val isLoading: Boolean = false,
val follows: List<FollowInfoDataDTO> = emptyList(),
val otherFollows: List<OtherFollowDataDTO> = emptyList(),
val error: String = ""
val error: String = "",
val offset: Int = 0,
val endReached: Boolean = false,
val pagingLoading : Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,86 @@ class FollowViewModel @Inject constructor(
private var _followIdDTO = mutableStateOf(FollowIdDTO(userInfo.userId))
var followIdDTO: State<FollowIdDTO> = _followIdDTO

fun getFollowInfo(relation: String="FOLLOWER", first: Int=0){
fun getFollowInfo(relation: String="FOLLOWER"){
viewModelScope.launch {
getFollowInfoUseCase(relation, first).collect() { result ->
getFollowInfoUseCase(relation, _state.value.offset).collect() { result ->
when (result) {
is Resource.Success -> {
_state.update {
it.copy(
follows = result.data?.follows ?: emptyList(),
isLoading = false
follows = it.follows + (result.data?.follows ?: emptyList()),
isLoading = false,
offset = it.offset + (result.data?.follows?.size ?: 0),
pagingLoading = false,
endReached = result.data?.follows?.size!! < 10
)
}
Log.d("팔로잉", "성공")
}
is Resource.Error -> {
_state.value =
FollowState(error = result.message ?: "An unexpected error occured")
Log.d("test", "error")
_state.update {
it.copy(
error = result.message ?: "An unexpected error occured in my review",
isLoading = false,
pagingLoading = false,
endReached = true
)
}
Log.d("팔로잉", "error")
}
is Resource.Loading -> {
_state.value = FollowState(isLoading = true)
Log.d("test", "loading")
_state.update {
it.copy(
isLoading = true,
pagingLoading = true
)
}
Log.d("팔로잉", "loading")
}
}
}
}
}

fun getOtherFollow(relation: String="FOLLOWER", first: Int=0, userId: Long){
getOtherFollowUseCase(relation, first, userId).onEach { result ->
when (result){
is Resource.Success -> {
_state.value = result.data?.let { FollowState(otherFollows = it, isLoading = false)}!!
}
is Resource.Error -> {
_state.value = FollowState(error = result.message ?: "An unexpected error occured")
Log.d("test", "error")
}
is Resource.Loading -> {
_state.value = FollowState(isLoading = true)
Log.d("test", "loading")
fun getOtherFollow(relation: String="FOLLOWER", userId: Long){
viewModelScope.launch {
getOtherFollowUseCase(relation, _state.value.offset, userId).collect() { result ->
when (result){
is Resource.Success -> {
_state.update {
it.copy(
otherFollows = it.otherFollows + (result.data ?: emptyList()),
isLoading = false,
offset = it.offset + (result.data?.size ?: 0),
pagingLoading = false,
endReached = result.data?.size!! < 10
)
}
Log.d("팔로워", "성공 ${_state.value.endReached}")
}
is Resource.Error -> {
_state.update {
it.copy(
error = result.message ?: "An unexpected error occured in my review",
isLoading = false,
pagingLoading = false,
endReached = true
)
}
Log.d("팔로워", "error")
}
is Resource.Loading -> {
_state.update {
it.copy(
isLoading = true,
pagingLoading = true
)
}
Log.d("팔로워", "loading")
}
}
}
}.launchIn(viewModelScope)
}
}
fun postFollow(userId: Long){
_userIdDTO.value = userIdDTO.value.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ package com.d_vide.D_VIDE.app.presentation.view.Followings
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.d_vide.D_VIDE.app._constants.Const
import com.d_vide.D_VIDE.app.domain.util.log
import com.d_vide.D_VIDE.app.presentation.view.UserFeed.BottomSheetUserFeedScreen
import com.d_vide.D_VIDE.app.presentation.view.UserFeed.UserProfileViewModel
import com.d_vide.D_VIDE.app.presentation.util.GradientComponent
import com.d_vide.D_VIDE.app.presentation.view.Followings.components.FollowingItem
import com.d_vide.D_VIDE.app.presentation.view.component.BlankIndicator
import com.d_vide.D_VIDE.app.presentation.view.component.TopRoundBar
import kotlinx.coroutines.launch

Expand All @@ -34,10 +35,16 @@ fun MyFollowScreen(
) {
val userViewModel = hiltViewModel<UserProfileViewModel>()
val userId = rememberSaveable{ mutableStateOf(0L) }
val viewModelState by followViewModel.state.collectAsState()
val follows = viewModelState.follows
val endReached = viewModelState.endReached
val pagingLoading = viewModelState.pagingLoading
var relation = ""


LaunchedEffect(key1 = true) {
val relation = if(isFollowing) "FOLLOWING" else "FOLLOWER"
followViewModel.getFollowInfo(relation, 0)
relation = if(isFollowing) "FOLLOWING" else "FOLLOWER"
followViewModel.getFollowInfo(relation)
}

BottomSheetUserFeedScreen(
Expand All @@ -53,32 +60,45 @@ fun MyFollowScreen(
modifier = Modifier.fillMaxHeight()
) {
LazyColumn(
modifier = Modifier.align(Alignment.Center),
horizontalAlignment = CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(top = 16.dp)
) {
followViewModel.state.value.follows.forEach { item ->
itemsIndexed(follows) { index, item ->
if (index >= follows.size - 1 && !endReached && !pagingLoading) {
followViewModel.getFollowInfo(relation)
}
FollowingItem(
userName = item.nickname,
profileUrl = item.profileImgUrl,
modifier = Modifier.padding(start = 33.dp, end = 40.dp),
onUserClick = {
userId.value = item.userId
userViewModel.getOtherUserInfo(item.userId)
scope.launch {
state.animateTo(
ModalBottomSheetValue.Expanded,
tween(500)
)
}
},
isFollowing = isFollowing,
userId = item.userId,
followId = item.followId,
)
}

if(follows.isEmpty()) {
item {
FollowingItem(
userName = item.nickname,
profileUrl = item.profileImageUrl,
modifier = Modifier.padding(start = 33.dp, end = 40.dp),
onUserClick = {
userId.value = item.userId
userViewModel.getOtherUserInfo(item.userId)
scope.launch {
state.animateTo(
ModalBottomSheetValue.Expanded,
tween(500)
)
}
},
isFollowing = isFollowing,
userId = item.userId,
followId = item.followId,
BlankIndicator(
modifier = Modifier
.align(Alignment.Center),
text = "회원님이 팔로우하는 사람들이\n 여기에 표시됩니다."
)
}
}
item { Spacer(Modifier.padding(bottom = Const.UIConst.HEIGHT_BOTTOM_BAR)) }
}
GradientComponent(Modifier.align(Alignment.BottomCenter))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package com.d_vide.D_VIDE.app.presentation.view.Followings
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
Expand All @@ -20,6 +19,7 @@ import com.d_vide.D_VIDE.app.presentation.view.UserFeed.BottomSheetUserFeedScree
import com.d_vide.D_VIDE.app.presentation.view.UserFeed.UserFeedViewModel
import com.d_vide.D_VIDE.app.presentation.util.GradientComponent
import com.d_vide.D_VIDE.app.presentation.view.Followings.components.FollowingItem
import com.d_vide.D_VIDE.app.presentation.view.component.BlankIndicator
import com.d_vide.D_VIDE.app.presentation.view.component.TopRoundBar
import kotlinx.coroutines.launch

Expand All @@ -35,12 +35,17 @@ fun OtherFollowScreen(
userViewModel: UserFeedViewModel = hiltViewModel(),
followViewModel: FollowViewModel = hiltViewModel(),
) {
val otherFollows = followViewModel.state.value.otherFollows
val coroutine = rememberCoroutineScope()
val userRememberId = rememberSaveable{ mutableStateOf(0L) }
val viewModelState by followViewModel.state.collectAsState()
val otherFollows = viewModelState.otherFollows
val endReached = viewModelState.endReached
val pagingLoading = viewModelState.pagingLoading
var relation = ""

coroutine.launch {
followViewModel.getOtherFollow(relation = if(isFollowing) "FOLLOWING" else "FOLLOWER", userId = userId)
LaunchedEffect(key1 = true) {
relation = if(isFollowing) "FOLLOWING" else "FOLLOWER"
followViewModel.getOtherFollow(relation = relation, userId = userId)
}
BottomSheetUserFeedScreen(
navController = navController,
Expand All @@ -55,33 +60,46 @@ fun OtherFollowScreen(
modifier = Modifier.fillMaxHeight()
) {
LazyColumn(
modifier = Modifier.align(Alignment.Center),
horizontalAlignment = CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(top = 16.dp, bottom = 16.dp)
) {
otherFollows.forEach { item ->
itemsIndexed(otherFollows) { index, item ->
if (index >= otherFollows.size - 1 && !endReached && !pagingLoading) {
followViewModel.getOtherFollow(relation, userId)
}
FollowingItem(
userName = item.nickname,
profileUrl = item.profileImgUrl,
modifier = Modifier.padding(start = 33.dp, end = 40.dp),
onUserClick = {
userRememberId.value = item.userId
scope.launch {
userViewModel.getOtherUserInfo(item.userId)
state.animateTo(
ModalBottomSheetValue.Expanded,
tween(500)
)
}
},
isFollowing = true,
userId = item.userId,
followId = item.followId,
followed = item.followed
)
}
if(otherFollows.isEmpty()) {
item {
FollowingItem(
userName = item.nickname,
profileUrl = item.profileImgUrl,
modifier = Modifier.padding(start = 33.dp, end = 40.dp),
onUserClick = {
userRememberId.value = item.userId
scope.launch {
userViewModel.getOtherUserInfo(item.userId)
state.animateTo(
ModalBottomSheetValue.Expanded,
tween(500)
)
}
},
isFollowing = true,
userId = item.userId,
followId = item.followId,
followed = item.followed
BlankIndicator(
modifier = Modifier
.align(Alignment.Center),
text = "회원님을 팔로우하는 사람들이\n 여기에 표시됩니다."
)
}
}


}
GradientComponent(Modifier.align(Alignment.BottomCenter))

Expand Down
Loading