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

친구 찾기 화면 틀 구현 #50

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.whyranoid.data.API
import com.whyranoid.data.AccountDataStore
import com.whyranoid.data.AppDatabase
import com.whyranoid.data.datasource.ChallengeDataSourceImpl
import com.whyranoid.data.datasource.OtherUserPagingSource
import com.whyranoid.data.datasource.UserDataSourceImpl
import com.whyranoid.data.datasource.account.AccountDataSourceImpl
import com.whyranoid.data.datasource.account.AccountService
Expand All @@ -21,6 +22,7 @@ import com.whyranoid.data.repository.ChallengeRepositoryImpl
import com.whyranoid.data.repository.FollowRepositoryImpl
import com.whyranoid.data.repository.GpsRepositoryImpl
import com.whyranoid.data.repository.NetworkRepositoryImpl
import com.whyranoid.data.repository.OtherUserRepositoryImpl
import com.whyranoid.data.repository.PostRepositoryImpl
import com.whyranoid.data.repository.RunningHistoryRepositoryImpl
import com.whyranoid.data.repository.RunningRepositoryImpl
Expand All @@ -36,6 +38,7 @@ import com.whyranoid.domain.repository.ChallengeRepository
import com.whyranoid.domain.repository.FollowRepository
import com.whyranoid.domain.repository.GpsRepository
import com.whyranoid.domain.repository.NetworkRepository
import com.whyranoid.domain.repository.OtherUserRepository
import com.whyranoid.domain.repository.PostRepository
import com.whyranoid.domain.repository.RunningHistoryRepository
import com.whyranoid.domain.repository.RunningRepository
Expand All @@ -45,6 +48,7 @@ import com.whyranoid.domain.usecase.GetChallengePreviewsByTypeUseCase
import com.whyranoid.domain.usecase.GetChallengingPreviewsUseCase
import com.whyranoid.domain.usecase.GetNewChallengePreviewsUseCase
import com.whyranoid.domain.usecase.GetPostUseCase
import com.whyranoid.domain.usecase.GetSearchedUserUseCase
import com.whyranoid.domain.usecase.GetUserBadgesUseCase
import com.whyranoid.domain.usecase.GetUserDetailUseCase
import com.whyranoid.domain.usecase.GetUserPostPreviewsUseCase
Expand All @@ -58,6 +62,7 @@ import com.whyranoid.presentation.screens.mypage.editprofile.EditProfileViewMode
import com.whyranoid.presentation.viewmodel.AddPostViewModel
import com.whyranoid.presentation.viewmodel.RunningEditViewModel
import com.whyranoid.presentation.viewmodel.RunningViewModel
import com.whyranoid.presentation.viewmodel.SearchFriendViewModel
import com.whyranoid.presentation.viewmodel.SelectHistoryViewModel
import com.whyranoid.presentation.viewmodel.SignInViewModel
import com.whyranoid.presentation.viewmodel.SplashViewModel
Expand Down Expand Up @@ -87,6 +92,7 @@ val viewModelModule = module {
factory { SelectHistoryViewModel(get()) }
factory { EditProfileViewModel(get()) }
factory { AddPostViewModel(get()) }
factory { SearchFriendViewModel(get()) }
}

val repositoryModule = module {
Expand All @@ -99,6 +105,7 @@ val repositoryModule = module {
single<FollowRepository> { FollowRepositoryImpl(get()) }
single<NetworkRepository> { NetworkRepositoryImpl(get()) }
single<GpsRepository> { GpsRepositoryImpl(get()) }
single<OtherUserRepository> { OtherUserRepositoryImpl(OtherUserPagingSource()) }
Copy link
Contributor

Choose a reason for hiding this comment

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

koin 모듈 부분 저도 건드려서 충돌 일어날 것 같아요 일어나면 잘 대처해야 할 것 가타요

}

val dataSourceModule = module {
Expand All @@ -125,6 +132,7 @@ val useCaseModule = module {
single { SignOutUseCase(get()) }
single { UploadPostUseCase(get(), get()) }
single { SendLikeUseCase(get(), get()) }
single { GetSearchedUserUseCase(get()) }
}

val databaseModule = module {
Expand Down
5 changes: 5 additions & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ dependencies {

// Retrofit
implementation("com.squareup.retrofit2:retrofit:2.9.0")

// paging
val pagingVersion = "3.2.1"
implementation("androidx.paging:paging-runtime-ktx:$pagingVersion")
implementation("androidx.paging:paging-compose:$pagingVersion")
Comment on lines +80 to +84
Copy link
Contributor

Choose a reason for hiding this comment

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

여기도 충돌 일어날 수 있습니다

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.whyranoid.data.datasource

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.whyranoid.domain.model.user.User

class OtherUserPagingSource(
private val dataSource: FakeFoundUserApi = FakeFoundUserApi,
) : PagingSource<Int, User>() {
override suspend fun load(
params: LoadParams<Int>
): LoadResult<Int, User> {
return try {
val pageNumber = params.key ?: 1
val response = dataSource.searchUsers(pageNumber)
LoadResult.Page(
data = response.data,
prevKey = null, // Only paging forward.
nextKey = pageNumber + PAGE_SIZE
)
} catch (e: Exception) {
LoadResult.Error(e)
}
}


override fun getRefreshKey(state: PagingState<Int, User>): Int? {
return state.anchorPosition?.let { anchorPosition ->
val anchorPage = state.closestPageToPosition(anchorPosition)
anchorPage?.prevKey?.plus(1) ?: anchorPage?.nextKey?.minus(1)
}
}

companion object {
const val PAGE_SIZE = 10
}
}

object FakeFoundUserApi {
private val DUMMY = (0..1000).map {
User.DUMMY.copy(
uid = it.toLong(),
name = "유저 $it",
nickname = "유저 $it",
)
}

fun searchUsers(
page: Int
): UserPageData {
return UserPageData(
data = DUMMY.subList(page, page + 10),
)
}


}

data class UserPageData(
val data: List<User>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.whyranoid.data.repository

import androidx.paging.Pager
import androidx.paging.PagingConfig
import com.whyranoid.data.datasource.OtherUserPagingSource
import com.whyranoid.domain.model.user.User
import com.whyranoid.domain.repository.OtherUserRepository

class OtherUserRepositoryImpl(
private val otherUserPagingSource: OtherUserPagingSource
): OtherUserRepository {
override fun searchUsers(query: String): Pager<Int, User> {
return Pager(
PagingConfig(
pageSize = 10,
enablePlaceholders = true,
)
) {
otherUserPagingSource
}
}
}
4 changes: 4 additions & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ dependencies {

// Coroutine
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

val pagingVersion = "3.2.1"
implementation("androidx.paging:paging-common:$pagingVersion")

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.whyranoid.domain.repository

import androidx.paging.Pager
import com.whyranoid.domain.model.user.User

interface OtherUserRepository {

fun searchUsers(query: String): Pager<Int, User>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.whyranoid.domain.usecase

import com.whyranoid.domain.repository.OtherUserRepository

class GetSearchedUserUseCase(
private val otherUserRepository: OtherUserRepository,
) {
operator fun invoke(query: String) = otherUserRepository.searchUsers(query).flow
}
6 changes: 6 additions & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ dependencies {
implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-auth-ktx:22.1.1")
implementation("com.google.android.gms:play-services-auth:20.6.0")

// paging
val pagingVersion = "3.2.1"
val pagingForComposeVersion = "1.0.0-alpha18"
implementation("androidx.paging:paging-runtime-ktx:$pagingVersion")
implementation("androidx.paging:paging-compose:$pagingForComposeVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.whyranoid.presentation.screens.challenge.ChallengeCompleteScreen
import com.whyranoid.presentation.screens.challenge.ChallengeDetailScreen
import com.whyranoid.presentation.screens.challenge.ChallengeExitScreen
import com.whyranoid.presentation.screens.challenge.ChallengeMainScreen
import com.whyranoid.presentation.screens.community.SearchFriendScreen
import com.whyranoid.presentation.screens.mypage.MyPageScreen
import com.whyranoid.presentation.screens.mypage.addpost.AddPostScreen
import com.whyranoid.presentation.screens.mypage.editprofile.EditProfileScreen
Expand Down Expand Up @@ -158,6 +159,9 @@ fun AppScreenContent(startWorker: () -> Unit, navController: NavHostController)
composable(Screen.Community.route) {
CommunityScreen(navController)
}
composable(Screen.SearchFriendScreen.route) {
SearchFriendScreen(navController)
}
composable(Screen.ChallengeMainScreen.route) {
ChallengeMainScreen(navController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fun CommunityScreen(
Icon(
modifier = Modifier
.clickable {
navController.navigate(Screen.SearchFriendScreen.route)
},
imageVector = Icons.Filled.Search,
contentDescription = "검색 버튼",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ sealed class Screen(
R.drawable.ic_community_screen_selected,
)

object SearchFriendScreen : Screen(
"searchFriendScreen",
)

object ChallengeMainScreen :
Screen(
"challengeMain",
Expand Down
Loading