|
2 | 2 |
|
3 | 3 | import android.arch.lifecycle.LiveData; |
4 | 4 | import android.arch.lifecycle.MutableLiveData; |
5 | | -import android.arch.lifecycle.Transformations; |
6 | 5 | import android.arch.lifecycle.ViewModel; |
7 | 6 | import android.arch.paging.PagedList; |
8 | 7 | import android.support.annotation.NonNull; |
|
13 | 12 | import com.artshell.misc.rv.official_paging_example.repository.NetworkState; |
14 | 13 | import com.artshell.misc.rv.official_paging_example.repository.RedditPostRepository; |
15 | 14 |
|
| 15 | +import static android.arch.lifecycle.Transformations.map; |
| 16 | +import static android.arch.lifecycle.Transformations.switchMap; |
| 17 | + |
16 | 18 | /** |
17 | 19 | * A RecyclerView ViewHolder that displays a single reddit post. |
18 | 20 | */ |
19 | 21 | public class SubRedditViewModel extends ViewModel { |
20 | 22 | private RedditPostRepository repository; |
21 | 23 | private MutableLiveData<String> subredditName = new MutableLiveData<>(); |
22 | | - private LiveData<Listing<RedditPost>> repoResult = Transformations.map(subredditName, name -> repository.postsSubreddit(name, 30)); |
23 | | - public LiveData<PagedList<RedditPost>> posts = Transformations.switchMap(repoResult, Listing::getPagedList); |
24 | | - public LiveData<NetworkState> networkState = Transformations.switchMap(repoResult, Listing::getNetworkState); |
25 | | - public LiveData<NetworkState> refreshState = Transformations.switchMap(repoResult, Listing::getRefreshState); |
| 24 | + private LiveData<Listing<RedditPost>> repoResult = map(subredditName, name -> repository.postsSubreddit(name, 30)); |
| 25 | + public LiveData<PagedList<RedditPost>> posts = switchMap(repoResult, Listing::getPagedList); |
| 26 | + public LiveData<NetworkState> networkState = switchMap(repoResult, Listing::getNetworkState); |
| 27 | + public LiveData<NetworkState> refreshState = switchMap(repoResult, Listing::getRefreshState); |
26 | 28 |
|
27 | 29 | public SubRedditViewModel(@NonNull RedditPostRepository repository) { |
28 | 30 | this.repository = repository; |
|
0 commit comments