aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-12-30 13:54:44 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-12-30 13:54:44 +0000
commitf529bba550b63ff1ea0b254c308257f5fd0c25ed (patch)
tree08b8206a108906431180fd079dd4a2368b78b7f2 /app
parentb7e1d92c7e45ee1b14ff53baebeb8af8dc6bbb5d (diff)
downloadinfinity-for-reddit-f529bba550b63ff1ea0b254c308257f5fd0c25ed.tar
infinity-for-reddit-f529bba550b63ff1ea0b254c308257f5fd0c25ed.tar.gz
infinity-for-reddit-f529bba550b63ff1ea0b254c308257f5fd0c25ed.tar.bz2
infinity-for-reddit-f529bba550b63ff1ea0b254c308257f5fd0c25ed.tar.lz
infinity-for-reddit-f529bba550b63ff1ea0b254c308257f5fd0c25ed.tar.xz
infinity-for-reddit-f529bba550b63ff1ea0b254c308257f5fd0c25ed.tar.zst
infinity-for-reddit-f529bba550b63ff1ea0b254c308257f5fd0c25ed.zip
Refreshing posts is working now.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java18
-rw-r--r--app/src/main/res/menu/menu_view_subreddit_detail.xml10
-rw-r--r--app/src/main/res/menu/view_subreddit_detail_activity.xml2
5 files changed, 18 insertions, 31 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
index 27c01fff..9ee9b399 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
@@ -12,6 +12,7 @@ class PostDataSourceFactory extends DataSource.Factory {
private String accessToken;
private Locale locale;
private String subredditName;
+ private boolean isBestPost;
private PostDataSource postDataSource;
private MutableLiveData<PostDataSource> postDataSourceLiveData;
@@ -21,12 +22,7 @@ class PostDataSourceFactory extends DataSource.Factory {
this.accessToken = accessToken;
this.locale = locale;
postDataSourceLiveData = new MutableLiveData<>();
-
- if(isBestPost) {
- postDataSource = new PostDataSource(retrofit, accessToken, locale, isBestPost);
- } else {
- postDataSource = new PostDataSource(retrofit, locale, isBestPost, subredditName);
- }
+ this.isBestPost = isBestPost;
}
PostDataSourceFactory(Retrofit retrofit, Locale locale, boolean isBestPost, String subredditName) {
@@ -34,16 +30,17 @@ class PostDataSourceFactory extends DataSource.Factory {
this.locale = locale;
this.subredditName = subredditName;
postDataSourceLiveData = new MutableLiveData<>();
+ this.isBestPost = isBestPost;
+ }
+ @Override
+ public DataSource create() {
if(isBestPost) {
postDataSource = new PostDataSource(retrofit, accessToken, locale, isBestPost);
} else {
postDataSource = new PostDataSource(retrofit, locale, isBestPost, subredditName);
}
- }
- @Override
- public DataSource create() {
postDataSourceLiveData.postValue(postDataSource);
return postDataSource;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index c4e10e45..fd7f3407 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -11,7 +11,6 @@ import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -137,7 +136,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
});
mPostViewModel.getPaginationNetworkState().observe(this, networkState -> {
- Log.i("networkstate", networkState.getStatus().toString());
mAdapter.setNetworkState(networkState);
});
@@ -146,7 +144,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void refresh() {
-
+ mPostViewModel.refresh();
}
private void showErrorView() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
index 4906bbad..e25e841f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
@@ -13,13 +13,13 @@ import java.util.Locale;
import retrofit2.Retrofit;
public class PostViewModel extends ViewModel {
- private PostDataSource postDataSource;
+ private PostDataSourceFactory postDataSourceFactory;
private LiveData<NetworkState> paginationNetworkState;
private LiveData<NetworkState> initialLoadingState;
private LiveData<PagedList<Post>> posts;
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, boolean isBestPost) {
- PostDataSourceFactory postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, isBestPost);
+ postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, isBestPost);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getInitialLoadStateLiveData());
@@ -32,11 +32,10 @@ public class PostViewModel extends ViewModel {
.build();
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
- postDataSource = postDataSourceFactory.getPostDataSource();
}
public PostViewModel(Retrofit retrofit, Locale locale, boolean isBestPost, String subredditName) {
- PostDataSourceFactory postDataSourceFactory = new PostDataSourceFactory(retrofit, locale, isBestPost, subredditName);
+ postDataSourceFactory = new PostDataSourceFactory(retrofit, locale, isBestPost, subredditName);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getInitialLoadStateLiveData());
@@ -50,7 +49,6 @@ public class PostViewModel extends ViewModel {
.build();
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
- postDataSource = postDataSourceFactory.getPostDataSource();
}
LiveData<PagedList<Post>> getPosts() {
@@ -61,16 +59,20 @@ public class PostViewModel extends ViewModel {
return paginationNetworkState;
}
- public LiveData<NetworkState> getInitialLoadingState() {
+ LiveData<NetworkState> getInitialLoadingState() {
return initialLoadingState;
}
+ void refresh() {
+ postDataSourceFactory.getPostDataSource().invalidate();
+ }
+
void retry() {
- postDataSource.retry();
+ postDataSourceFactory.getPostDataSource().retry();
}
void retryLoadingMore() {
- postDataSource.retryLoadingMore();
+ postDataSourceFactory.getPostDataSource().retryLoadingMore();
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
diff --git a/app/src/main/res/menu/menu_view_subreddit_detail.xml b/app/src/main/res/menu/menu_view_subreddit_detail.xml
deleted file mode 100644
index 98b7f78c..00000000
--- a/app/src/main/res/menu/menu_view_subreddit_detail.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<menu xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- tools:context="ml.docilealligator.infinityforreddit.ViewSubredditDetailActivity">
- <item
- android:id="@+id/action_settings"
- android:orderInCategory="100"
- android:title="@string/action_settings"
- app:showAsAction="never" />
-</menu>
diff --git a/app/src/main/res/menu/view_subreddit_detail_activity.xml b/app/src/main/res/menu/view_subreddit_detail_activity.xml
index aa3537f5..d9b85107 100644
--- a/app/src/main/res/menu/view_subreddit_detail_activity.xml
+++ b/app/src/main/res/menu/view_subreddit_detail_activity.xml
@@ -8,5 +8,5 @@
android:orderInCategory="1"
android:title="@string/action_refresh"
android:icon="@drawable/ic_refresh_white_24dp"
- app:showAsAction="always" />
+ app:showAsAction="never" />
</menu> \ No newline at end of file