-
Notifications
You must be signed in to change notification settings - Fork 1
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
친구 찾기 화면 틀 구현 #50
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 충돌 일어날 수 있습니다 |
||
} |
61 changes: 61 additions & 0 deletions
61
data/src/main/java/com/whyranoid/data/datasource/OtherUserPagingSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
) |
22 changes: 22 additions & 0 deletions
22
data/src/main/java/com/whyranoid/data/repository/OtherUserRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
domain/src/main/java/com/whyranoid/domain/repository/OtherUserRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
9 changes: 9 additions & 0 deletions
9
domain/src/main/java/com/whyranoid/domain/usecase/GetSearchedUserUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
koin 모듈 부분 저도 건드려서 충돌 일어날 것 같아요 일어나면 잘 대처해야 할 것 가타요