Skip to content

Commit 9ae9137

Browse files
committed
Update refresh
1 parent e334423 commit 9ae9137

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

app/src/main/java/com/hoc/pagination_mvi/data/PostRepositoryImpl.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package com.hoc.pagination_mvi.data
33
import com.hoc.pagination_mvi.data.remote.ApiService
44
import com.hoc.pagination_mvi.di.ApplicationScope
55
import com.hoc.pagination_mvi.domain.dispatchers_schedulers.CoroutinesDispatchersProvider
6-
import com.hoc.pagination_mvi.domain.entity.Photo
76
import com.hoc.pagination_mvi.domain.entity.Post
8-
import com.hoc.pagination_mvi.domain.repository.PhotoRepository
97
import com.hoc.pagination_mvi.domain.repository.PostRepository
108
import kotlinx.coroutines.withContext
119
import javax.inject.Inject

app/src/main/java/com/hoc/pagination_mvi/ui/main/MainInteractorImpl.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,21 @@ class MainInteractorImpl @Inject constructor(
9494
): Observable<Refresh> {
9595
return rxObservable(dispatchers.main) {
9696
send(Refresh.Refreshing)
97+
try {
98+
coroutineScope {
99+
val async1 = async { getPostsUseCase(limit = limitPost, start = 0) }
100+
val async2 = async { getPhotosUseCase(limit = limitPhoto, start = 0) }
97101

98-
coroutineScope {
99-
val async1 = async { getPostsUseCase(limit = limitPost, start = 0) }
100-
val async2 = async { getPhotosUseCase(limit = limitPhoto, start = 0) }
101-
102-
try {
103102
send(
104103
Refresh.Success(
105104
posts = async1.await().map(::PostVS),
106105
photos = async2.await().map(::PhotoVS)
107106
)
108107
)
109-
} catch (e: Exception) {
110-
delay(500)
111-
send(Refresh.Error(e))
112108
}
109+
} catch (e: Exception) {
110+
delay(500)
111+
send(Refresh.Error(e))
113112
}
114113
}
115114
}

app/src/main/java/com/hoc/pagination_mvi/ui/main/MainVM.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class MainVM @Inject constructor(
153153
is PostNextPage.Data -> if (change.posts.isEmpty()) singleEventS.onNext(SingleEvent.HasReachedMaxHorizontal)
154154
is PostNextPage.Error -> singleEventS.onNext(SingleEvent.GetPostsFailure(change.error))
155155
PostNextPage.Loading -> Unit
156+
///
157+
is Refresh.Success -> singleEventS.onNext(SingleEvent.RefreshSuccess)
158+
is Refresh.Error -> singleEventS.onNext(SingleEvent.RefreshFailure(change.error))
159+
Refresh.Refreshing -> Unit
156160
}
157161
}
158162
}

0 commit comments

Comments
 (0)