Skip to content

Commit 9169819

Browse files
committedFeb 13, 2018
[FIX] ReadMe links / Code snippets
1 parent a8a930b commit 9169819

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed
 

‎README.md

+22-30
Original file line numberDiff line numberDiff line change
@@ -31,62 +31,54 @@ Some of the features of the app include
3131
viewModel.getPosts()
3232
```
3333

34-
### [ViewModel](posts/src/main/java/com/karntrehan/posts/list/ListViewModel.kt)
34+
### [ViewModel](posts/src/main/java/com/karntrehan/posts/list/viewmodel/ListViewModel.kt)
3535
```java
3636
fun getPosts() {
3737
if (postsOutcome.value == null)
38-
repo.fetchPosts(compositeDisposable)
38+
repo.fetchPosts()
3939
}
4040
```
4141

42-
### [Repository](posts/src/main/java/com/karntrehan/posts/list/ListRepository.kt)
42+
### [Repository](posts/src/main/java/com/karntrehan/posts/list/model/ListRepository.kt)
4343
```java
4444
val postFetchOutcome: PublishSubject<Outcome<List<PostWithUser>>> = PublishSubject.create<Outcome<List<PostWithUser>>>()
4545

46-
private val TAG = "ListRepository"
47-
48-
fun fetchPosts(compositeDisposable: CompositeDisposable) {
46+
override fun fetchPosts() {
4947
postFetchOutcome.loading(true)
5048
//Observe changes to the db
51-
postDb.postDao().getAll()
52-
.performOnBackOutOnMain()
49+
local.getPostsWithUsers()
50+
.performOnBackOutOnMain(scheduler)
5351
.subscribe({ retailers ->
5452
postFetchOutcome.success(retailers)
5553
if (remoteFetch)
56-
refreshPosts(compositeDisposable)
54+
refreshPosts()
5755
remoteFetch = false
58-
}, { error -> handleError(error) }
56+
}, { error -> handleError(error) })
5957
.addTo(compositeDisposable)
60-
)
6158
}
6259

63-
fun refreshPosts(compositeDisposable: CompositeDisposable) {
60+
override fun refreshPosts() {
6461
postFetchOutcome.loading(true)
65-
Flowable.zip(
66-
postService.getUsers(),
67-
postService.getPosts(),
68-
BiFunction<List<User>, List<Post>, Unit> { t1, t2 -> saveUsersAndPosts(t1, t2) }
69-
)
70-
.performOnBackOutOnMain()
71-
.subscribe({}, { error -> handleError(error) })
72-
.addTo(compositeDisposable)
62+
Flowable.zip(
63+
remote.getUsers(),
64+
remote.getPosts(),
65+
BiFunction<List<User>, List<Post>, Unit> { t1, t2 -> saveUsersAndPosts(t1, t2) }
66+
)
67+
.performOnBackOutOnMain(scheduler)
68+
.subscribe({}, { error -> handleError(error) })
69+
.addTo(compositeDisposable)
7370
}
7471

75-
private fun saveUsersAndPosts(users: List<User>, posts: List<Post>) {
76-
Completable.fromAction {
77-
postDb.userDao().insertAll(users)
78-
postDb.postDao().insertAll(posts)
79-
}
80-
.performOnBackOutOnMain()
81-
.subscribe()
72+
override fun saveUsersAndPosts(users: List<User>, posts: List<Post>) {
73+
local.saveUsersAndPosts(users, posts)
8274
}
8375

84-
private fun handleError(error: Throwable) {
76+
override fun handleError(error: Throwable) {
8577
postFetchOutcome.failed(error)
8678
}
8779
```
8880

89-
### [ViewModel](posts/src/main/java/com/karntrehan/posts/list/ListViewModel.kt) ###
81+
### [ViewModel](posts/src/main/java/com/karntrehan/posts/list/viewmodel/ListViewModel.kt) ###
9082
```java
9183
val postsOutcome: LiveData<Outcome<List<Post>>> by lazy {
9284
//Convert publish subject to livedata
@@ -133,7 +125,7 @@ To run all the instrumented tests, run `./gradlew connectedAndroidTest`. This w
133125
* [Dagger 2](https://google.github.io/dagger/)
134126
* [Retrofit](http://square.github.io/retrofit/)
135127
* [OkHttp](http://square.github.io/okhttp/)
136-
* [Picasso](square.github.io/picasso/)
128+
* [Picasso](http://square.github.io/picasso/)
137129
* [Stetho](http://facebook.github.io/stetho/)
138130
* [Room](https://developer.android.com/topic/libraries/architecture/room.html)
139131
* [ViewModel](https://developer.android.com/topic/libraries/architecture/viewmodel.html)

0 commit comments

Comments
 (0)
Please sign in to comment.