Skip to content

Commit e6fcb1e

Browse files
committed
Modify: code enhancements & configuration changed
1 parent 2d2fc29 commit e6fcb1e

18 files changed

Lines changed: 290 additions & 32 deletions

app/app_dependences.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def versions = [
3030
workmanager : '1.0.0-alpha04',
3131

3232
// rx
33-
rxjava : '2.1.16',
33+
rxjava : '2.1.17',
3434
rxandroid : '2.0.2',
3535
rxlifecycle : '2.2.1',
3636
rxpermissions : '0.9.5@aar',

app/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'kotlin-android'
32

43
apply from: 'app_dependences.gradle'
54

@@ -102,7 +101,6 @@ dependencies {
102101
implementation deps.misc.multitype
103102
implementation deps.misc.gson
104103
implementation deps.misc.stream
105-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
106104
}
107105
repositories {
108106
mavenCentral()

app/src/main/java/com/artshell/misc/rv/official_paging_example/repository/inMemory/byItem/InMemoryByItemRepository.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.artshell.misc.rv.official_paging_example.repository.inMemory.byItem;
22

33
import android.arch.lifecycle.LiveData;
4-
import android.arch.lifecycle.Transformations;
54
import android.arch.paging.LivePagedListBuilder;
65
import android.arch.paging.PagedList;
76
import android.support.annotation.MainThread;
@@ -14,6 +13,8 @@
1413

1514
import java.util.concurrent.Executor;
1615

16+
import static android.arch.lifecycle.Transformations.switchMap;
17+
1718
/**
1819
* Repository implementation that returns a Listing that loads data directly from the network
1920
* and uses the Item's name as the key to discover prev/next pages.
@@ -40,13 +41,14 @@ public Listing<RedditPost> postsSubreddit(String subReddit, int pageSize) {
4041

4142
// provide custom executor for network requests, otherwise it will default to
4243
// Arch Components' IO pool which is also used for disk access
43-
LivePagedListBuilder<String, RedditPost> builder = new LivePagedListBuilder<>(sourceFactory, pagedConfig).setFetchExecutor(networkExecutor);
44+
LivePagedListBuilder<String, RedditPost> builder = new LivePagedListBuilder<>(sourceFactory, pagedConfig)
45+
.setFetchExecutor(networkExecutor);
4446

45-
LiveData<NetworkState> refreshState = Transformations.switchMap(sourceFactory.getSourceLiveData(), ItemKeyedSubredditDataSource::getInitialLoad);
47+
LiveData<NetworkState> refreshState = switchMap(sourceFactory.getSourceLiveData(), ItemKeyedSubredditDataSource::getInitialLoad);
4648

4749
return new Listing<>(
4850
builder.build(),
49-
Transformations.switchMap(sourceFactory.getSourceLiveData(), ItemKeyedSubredditDataSource::getNetworkState),
51+
switchMap(sourceFactory.getSourceLiveData(), ItemKeyedSubredditDataSource::getNetworkState),
5052
refreshState,
5153
() -> {
5254
ItemKeyedSubredditDataSource source = sourceFactory.getSourceLiveData().getValue();

app/src/main/java/com/artshell/misc/rv/official_paging_example/repository/inMemory/byItem/SubRedditDataSourceFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ public class SubRedditDataSourceFactory extends DataSource.Factory<String, Reddi
1717
private RedditApi webService;
1818
private String subredditName;
1919
private Executor retryExecutor;
20-
private MutableLiveData<ItemKeyedSubredditDataSource> sourceLiveData;
20+
private MutableLiveData<ItemKeyedSubredditDataSource> sourceLiveData = new MutableLiveData<>();
2121

2222
public SubRedditDataSourceFactory(RedditApi webService, String subredditName, Executor retryExecutor) {
2323
this.webService = webService;
2424
this.subredditName = subredditName;
2525
this.retryExecutor = retryExecutor;
26-
sourceLiveData = new MutableLiveData<>();
2726
}
2827

2928
public MutableLiveData<ItemKeyedSubredditDataSource> getSourceLiveData() {

app/src/main/java/com/artshell/misc/rv/official_paging_example/repository/inMemory/byPage/InMemoryByPageKeyRepository.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.artshell.misc.rv.official_paging_example.repository.inMemory.byPage;
22

33
import android.arch.lifecycle.LiveData;
4-
import android.arch.lifecycle.Transformations;
54
import android.arch.paging.LivePagedListBuilder;
65

76
import com.artshell.misc.rv.official_paging_example.api.RedditApi;
@@ -12,6 +11,8 @@
1211

1312
import java.util.concurrent.Executor;
1413

14+
import static android.arch.lifecycle.Transformations.switchMap;
15+
1516
/**
1617
* Repository implementation that returns a Listing that loads data directly from network by using
1718
* the previous / next page keys returned in the query.
@@ -33,13 +34,13 @@ public Listing<RedditPost> postsSubreddit(String subReddit, int pageSize) {
3334
// provide custom executor for network requests, otherwise it will default to
3435
// Arch Components' IO pool which is also used for disk access
3536
LivePagedListBuilder<String, RedditPost> pageList = new LivePagedListBuilder<>(sourceFactory, pageSize)
36-
.setFetchExecutor(networkExecutor);
37+
.setFetchExecutor(networkExecutor);
3738

38-
LiveData<NetworkState> refreshState = Transformations.switchMap(sourceFactory.getSourceLiveData(), PageKeyedSubredditDataSource::getInitialLoad);
39+
LiveData<NetworkState> refreshState = switchMap(sourceFactory.getSourceLiveData(), PageKeyedSubredditDataSource::getInitialLoad);
3940

4041
return new Listing<>(
4142
pageList.build(),
42-
Transformations.switchMap(sourceFactory.getSourceLiveData(), PageKeyedSubredditDataSource::getNetworkState),
43+
switchMap(sourceFactory.getSourceLiveData(), PageKeyedSubredditDataSource::getNetworkState),
4344
refreshState,
4445
() -> {
4546
PageKeyedSubredditDataSource source = sourceFactory.getSourceLiveData().getValue();

app/src/main/java/com/artshell/misc/rv/official_paging_example/repository/inMemory/byPage/PageKeyedSubredditDataSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull Load
8585
}
8686
callback.onResult(items, data.getBefore(), data.getAfter());
8787
}
88-
} catch (IOException ioex) {
88+
} catch (IOException ioExc) {
8989
retry = () -> loadInitial(params, callback);
90-
NetworkState error = NetworkState.error(ioex.getMessage() == null ? "unknown error" : ioex.getMessage());
90+
NetworkState error = NetworkState.error(ioExc.getMessage() == null ? "unknown error" : ioExc.getMessage());
9191
networkState.postValue(error);
9292
initialLoad.postValue(error);
9393
}

app/src/main/java/com/artshell/misc/rv/official_paging_example/repository/inMemory/byPage/SubRedditDataSourceFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class SubRedditDataSourceFactory extends DataSource.Factory<String, Reddi
1818
private RedditApi webService;
1919
private String subredditName;
2020
private Executor retryExecutor;
21-
private MutableLiveData<PageKeyedSubredditDataSource> sourceLiveData;
21+
private MutableLiveData<PageKeyedSubredditDataSource> sourceLiveData = new MutableLiveData<>();
2222

2323
public SubRedditDataSourceFactory(RedditApi webService, String subredditName, Executor retryExecutor) {
2424
this.webService = webService;

app/src/main/java/com/artshell/misc/rv/official_paging_example/ui/PostsAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
4141
default:
4242
throw new IllegalArgumentException("unknown view type " + viewType);
4343
}
44-
4544
}
4645

4746
@Override

app/src/main/java/com/artshell/misc/rv/official_paging_example/ui/SubRedditViewModel.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.arch.lifecycle.LiveData;
44
import android.arch.lifecycle.MutableLiveData;
5-
import android.arch.lifecycle.Transformations;
65
import android.arch.lifecycle.ViewModel;
76
import android.arch.paging.PagedList;
87
import android.support.annotation.NonNull;
@@ -13,16 +12,19 @@
1312
import com.artshell.misc.rv.official_paging_example.repository.NetworkState;
1413
import com.artshell.misc.rv.official_paging_example.repository.RedditPostRepository;
1514

15+
import static android.arch.lifecycle.Transformations.map;
16+
import static android.arch.lifecycle.Transformations.switchMap;
17+
1618
/**
1719
* A RecyclerView ViewHolder that displays a single reddit post.
1820
*/
1921
public class SubRedditViewModel extends ViewModel {
2022
private RedditPostRepository repository;
2123
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);
2628

2729
public SubRedditViewModel(@NonNull RedditPostRepository repository) {
2830
this.repository = repository;

arch-mvvm/arch_mvvm_dependences.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def versions = [
2727
workmanager : '1.0.0-alpha04',
2828

2929
// rx
30-
rxjava : '2.1.16',
30+
rxjava : '2.1.17',
3131
rxandroid : '2.0.2',
3232
rxlifecycle : '2.2.1',
3333
rxpermissions : '0.9.5@aar',

0 commit comments

Comments
 (0)