feat: Add ordering functionality for friends list
This commit is contained in:
@@ -8,11 +8,13 @@ import com.slack.eithernet.ApiResult
|
||||
interface FriendsRepository {
|
||||
|
||||
suspend fun getAllFriends(
|
||||
order: String,
|
||||
count: Int?,
|
||||
offset: Int?
|
||||
): ApiResult<FriendsInfo, RestApiErrorDomain>
|
||||
|
||||
suspend fun getFriends(
|
||||
order: String,
|
||||
count: Int?,
|
||||
offset: Int?
|
||||
): ApiResult<List<VkUser>, RestApiErrorDomain>
|
||||
|
||||
@@ -25,10 +25,11 @@ class FriendsRepositoryImpl(
|
||||
) : FriendsRepository {
|
||||
|
||||
override suspend fun getAllFriends(
|
||||
order: String,
|
||||
count: Int?,
|
||||
offset: Int?
|
||||
): ApiResult<FriendsInfo, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||
val friends = async { getFriends(count, offset) }.await()
|
||||
val friends = async { getFriends(order, count, offset) }.await()
|
||||
.successOrElse { failure ->
|
||||
return@withContext failure
|
||||
}
|
||||
@@ -42,11 +43,12 @@ class FriendsRepositoryImpl(
|
||||
}
|
||||
|
||||
override suspend fun getFriends(
|
||||
order: String,
|
||||
count: Int?,
|
||||
offset: Int?
|
||||
): ApiResult<List<VkUser>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||
val requestModel = GetFriendsRequest(
|
||||
order = "hints",
|
||||
order = order,
|
||||
count = count,
|
||||
offset = offset,
|
||||
fields = VkConstants.USER_FIELDS
|
||||
|
||||
@@ -8,11 +8,13 @@ import kotlinx.coroutines.flow.Flow
|
||||
interface FriendsUseCase {
|
||||
|
||||
fun getAllFriends(
|
||||
order: String = "hints",
|
||||
count: Int?,
|
||||
offset: Int?
|
||||
): Flow<State<FriendsInfo>>
|
||||
|
||||
fun getFriends(
|
||||
order: String = "hints",
|
||||
count: Int?,
|
||||
offset: Int?
|
||||
): Flow<State<List<VkUser>>>
|
||||
|
||||
@@ -11,19 +11,26 @@ import kotlinx.coroutines.flow.flow
|
||||
class FriendsUseCaseImpl(private val repository: FriendsRepository) :
|
||||
FriendsUseCase {
|
||||
|
||||
override fun getAllFriends(count: Int?, offset: Int?): Flow<State<FriendsInfo>> = flow {
|
||||
override fun getAllFriends(order: String, count: Int?, offset: Int?): Flow<State<FriendsInfo>> = flow {
|
||||
emit(State.Loading)
|
||||
|
||||
val newState = repository.getAllFriends(count, offset).mapToState()
|
||||
val newState = repository.getAllFriends(order, count, offset).mapToState()
|
||||
emit(newState)
|
||||
}
|
||||
|
||||
override fun getFriends(
|
||||
count: Int?, offset: Int?
|
||||
order: String,
|
||||
count: Int?,
|
||||
offset: Int?
|
||||
): Flow<State<List<VkUser>>> = flow {
|
||||
emit(State.Loading)
|
||||
|
||||
val newState = repository.getFriends(count, offset).mapToState()
|
||||
val newState = repository.getFriends(
|
||||
order = order,
|
||||
count = count,
|
||||
offset = offset
|
||||
).mapToState()
|
||||
|
||||
emit(newState)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11,18h2c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1h-2c-0.55,0 -1,0.45 -1,1s0.45,1 1,1zM3,7c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L4,6c-0.55,0 -1,0.45 -1,1zM7,13h10c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L7,11c-0.55,0 -1,0.45 -1,1s0.45,1 1,1z" />
|
||||
|
||||
</vector>
|
||||
Reference in New Issue
Block a user