aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/CustomView/CustomMarkwonView.java73
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MessageViewModel.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java6
19 files changed, 30 insertions, 164 deletions
diff --git a/app/src/main/java/CustomView/CustomMarkwonView.java b/app/src/main/java/CustomView/CustomMarkwonView.java
deleted file mode 100644
index c89ff405..00000000
--- a/app/src/main/java/CustomView/CustomMarkwonView.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package CustomView;
-
-import android.content.Context;
-import android.text.Spanned;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import org.commonmark.node.Node;
-
-import java.util.List;
-
-import io.noties.markwon.Markwon;
-import io.noties.markwon.MarkwonPlugin;
-
-public class CustomMarkwonView extends Markwon {
-
- public void setMarkdown(@Nullable String markdown, Context context) {
-
- }
-
- @NonNull
- @Override
- public Node parse(@NonNull String input) {
- return null;
- }
-
- @NonNull
- @Override
- public Spanned render(@NonNull Node node) {
- return null;
- }
-
- @NonNull
- @Override
- public Spanned toMarkdown(@NonNull String input) {
- return null;
- }
-
- @Override
- public void setMarkdown(@NonNull TextView textView, @NonNull String markdown) {
-
- }
-
- @Override
- public void setParsedMarkdown(@NonNull TextView textView, @NonNull Spanned markdown) {
-
- }
-
- @Override
- public boolean hasPlugin(@NonNull Class<? extends MarkwonPlugin> plugin) {
- return false;
- }
-
- @Nullable
- @Override
- public <P extends MarkwonPlugin> P getPlugin(@NonNull Class<P> type) {
- return null;
- }
-
- @NonNull
- @Override
- public <P extends MarkwonPlugin> P requirePlugin(@NonNull Class<P> type) {
- return null;
- }
-
- @NonNull
- @Override
- public List<? extends MarkwonPlugin> getPlugins() {
- return null;
- }
-}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java
index 377cc07c..ae2af2a1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentDataSource.java
@@ -30,8 +30,6 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
private MutableLiveData<NetworkState> initialLoadStateLiveData;
private MutableLiveData<Boolean> hasPostLiveData;
- private LoadInitialParams<String> initialParams;
- private LoadInitialCallback<String, CommentData> initialCallback;
private LoadParams<String> params;
private LoadCallback<String, CommentData> callback;
@@ -57,19 +55,12 @@ public class CommentDataSource extends PageKeyedDataSource<String, CommentData>
return hasPostLiveData;
}
- void retry() {
- loadInitial(initialParams, initialCallback);
- }
-
void retryLoadingMore() {
loadAfter(params, callback);
}
@Override
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, CommentData> callback) {
- initialParams = params;
- initialCallback = callback;
-
initialLoadStateLiveData.postValue(NetworkState.LOADING);
RedditAPI api = retrofit.create(RedditAPI.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java
index 38bc1844..4f5c1e92 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentViewModel.java
@@ -66,10 +66,6 @@ public class CommentViewModel extends ViewModel {
commentDataSourceFactory.getCommentDataSource().invalidate();
}
- void retry() {
- commentDataSourceFactory.getCommentDataSource().retry();
- }
-
void retryLoadingMore() {
commentDataSourceFactory.getCommentDataSource().retryLoadingMore();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java
index 3721d839..5826200b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java
@@ -109,8 +109,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mCommentViewModel.getInitialLoadingState().observe(this, networkState -> {
if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
+ mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
- mFetchCommentInfoLinearLayout.setOnClickListener(view -> mCommentViewModel.retry());
+ mProgressBar.setVisibility(View.GONE);
+ mFetchCommentInfoLinearLayout.setOnClickListener(view -> mCommentViewModel.refresh());
showErrorView(R.string.load_comments_failed);
} else {
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
@@ -119,6 +121,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
});
mCommentViewModel.hasComment().observe(this, hasComment -> {
+ mProgressBar.setVisibility(View.GONE);
if(hasComment) {
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
} else {
@@ -149,6 +152,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@Override
public void refresh() {
mCommentViewModel.refresh();
+ mAdapter.setNetworkState(null);
}
private void showErrorView(int stringResId) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index 3791b5cd..e3c1cdf6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -390,7 +390,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
- viewPager.setOffscreenPageLimit(2);
+ viewPager.setOffscreenPageLimit(3);
tabLayout.setupWithViewPager(viewPager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
index 3b2af4fb..45bf7737 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
@@ -22,8 +22,6 @@ class MessageDataSource extends PageKeyedDataSource<String, Message> {
private MutableLiveData<NetworkState> initialLoadStateLiveData;
private MutableLiveData<Boolean> hasPostLiveData;
- private LoadInitialParams<String> initialParams;
- private LoadInitialCallback<String, Message> initialCallback;
private LoadParams<String> params;
private LoadCallback<String, Message> callback;
@@ -49,19 +47,12 @@ class MessageDataSource extends PageKeyedDataSource<String, Message> {
return hasPostLiveData;
}
- void retry() {
- loadInitial(initialParams, initialCallback);
- }
-
void retryLoadingMore() {
loadAfter(params, callback);
}
@Override
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, Message> callback) {
- initialParams = params;
- initialCallback = callback;
-
initialLoadStateLiveData.postValue(NetworkState.LOADING);
FetchMessages.fetchMessagesAsync(oauthRetrofit, locale, accessToken, where, null, new FetchMessages.FetchMessagesListener() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageViewModel.java
index 4ad155d6..d111c8ad 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageViewModel.java
@@ -66,10 +66,6 @@ public class MessageViewModel extends ViewModel {
messageDataSourceFactory.getMessageDataSource().invalidate();
}
- void retry() {
- messageDataSourceFactory.getMessageDataSource().retry();
- }
-
void retryLoadingMore() {
messageDataSourceFactory.getMessageDataSource().retryLoadingMore();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index 009bcb18..c6e75042 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -226,7 +226,6 @@ class ParsePost {
if(!data.has(JSONUtils.PREVIEW_KEY) && previewUrl.equals("")) {
if(url.contains(permalink)) {
//Text post
- Log.i("text", Integer.toString(i));
int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
title, permalink, score, postType, voteType, gilded, flair, spoiler, nsfw,
@@ -238,7 +237,6 @@ class ParsePost {
}
} else {
//No preview link post
- Log.i("no preview link", Integer.toString(i));
int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
title, previewUrl, url, permalink, score, postType,
@@ -257,7 +255,6 @@ class ParsePost {
if(isVideo) {
//Video post
- Log.i("video", Integer.toString(i));
JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
int postType = Post.VIDEO_TYPE;
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.DASH_URL_KEY)).toString();
@@ -274,7 +271,6 @@ class ParsePost {
JSONObject variations = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0);
if (variations.has(JSONUtils.VARIANTS_KEY) && variations.getJSONObject(JSONUtils.VARIANTS_KEY).has(JSONUtils.MP4_KEY)) {
//Gif video post (MP4)
- Log.i("gif video mp4", Integer.toString(i));
int postType = Post.GIF_VIDEO_TYPE;
String videoUrl = Html.fromHtml(variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString();
String gifDownloadUrl = Html.fromHtml(variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString();
@@ -289,7 +285,6 @@ class ParsePost {
post.setGifOrVideoDownloadUrl(gifDownloadUrl);
} else if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) {
//Gif video post (Dash)
- Log.i("gif video dash", Integer.toString(i));
int postType = Post.GIF_VIDEO_TYPE;
String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY)
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY)).toString();
@@ -304,7 +299,6 @@ class ParsePost {
} else {
if (url.endsWith("jpg") || url.endsWith("png")) {
//Image post
- Log.i("image", Integer.toString(i));
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
@@ -316,7 +310,6 @@ class ParsePost {
} else {
if (url.contains(permalink)) {
//Text post but with a preview
- Log.i("text with image", Integer.toString(i));
int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
@@ -333,7 +326,6 @@ class ParsePost {
}
} else {
//Link post
- Log.i("link", Integer.toString(i));
int postType = Post.LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
@@ -353,7 +345,6 @@ class ParsePost {
} else {
if (url.endsWith("jpg") || url.endsWith("png")) {
//Image post
- Log.i("CP image", Integer.toString(i));
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
@@ -363,7 +354,6 @@ class ParsePost {
post.setPreviewHeight(previewHeight);
} else {
//CP No Preview Link post
- Log.i("CP no preview link", Integer.toString(i));
int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
index cbcef916..b5996f54 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java
@@ -52,8 +52,6 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
private MutableLiveData<NetworkState> initialLoadStateLiveData;
private MutableLiveData<Boolean> hasPostLiveData;
- private LoadInitialParams<String> initialParams;
- private LoadInitialCallback<String, Post> initialCallback;
private LoadParams<String> params;
private LoadCallback<String, Post> callback;
@@ -132,9 +130,6 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull final LoadInitialCallback<String, Post> callback) {
- initialParams = params;
- initialCallback = callback;
-
initialLoadStateLiveData.postValue(NetworkState.LOADING);
switch (postType) {
@@ -652,10 +647,6 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
});
}
- void retry() {
- loadInitial(initialParams, initialCallback);
- }
-
void retryLoadingMore() {
loadAfter(params, callback);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index b2c0e12a..1a65da3d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -296,7 +296,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else if(postType == PostDataSource.TYPE_SUBREDDIT) {
String subredditName = getArguments().getString(EXTRA_NAME);
- boolean displaySubredditName = subredditName.equals("popular") || subredditName.equals("all");
+ boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all"));
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, displaySubredditName, new PostRecyclerViewAdapter.Callback() {
@Override
@@ -392,8 +392,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel.getInitialLoadingState().observe(this, networkState -> {
if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
+ mFetchPostInfoLinearLayout.setVisibility(View.GONE);
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
- mFetchPostInfoLinearLayout.setOnClickListener(view -> mPostViewModel.retry());
+ mProgressBar.setVisibility(View.GONE);
+ mFetchPostInfoLinearLayout.setOnClickListener(view -> mPostViewModel.refresh());
showErrorView(R.string.load_posts_error);
} else {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
@@ -403,14 +405,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel.hasPost().observe(this, hasPost -> {
this.hasPost = hasPost;
+ mProgressBar.setVisibility(View.GONE);
if(hasPost) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
- mProgressBar.setVisibility(View.GONE);
} else {
if(isInLazyMode) {
stopLazyMode();
}
+ mFetchPostInfoLinearLayout.setOnClickListener(view -> {});
showErrorView(R.string.no_posts);
}
});
@@ -451,6 +454,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
hasPost = false;
mPostViewModel.refresh();
+ mAdapter.setNetworkState(null);
}
private void showErrorView(int stringResId) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
index d438dca8..aef2a574 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
@@ -169,10 +169,6 @@ public class PostViewModel extends ViewModel {
postDataSourceFactory.getPostDataSource().invalidate();
}
- void retry() {
- postDataSourceFactory.getPostDataSource().retry();
- }
-
void retryLoadingMore() {
postDataSourceFactory.getPostDataSource().retryLoadingMore();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java
index 123aa509..ed78ac0a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java
@@ -375,12 +375,6 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
}
}
- public void newSearch() {
- getItem(0);
- getItem(1);
- getItem(2);
- }
-
public void changeNSFW(boolean nsfw) {
if(postFragment != null) {
postFragment.changeNSFW(nsfw);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java
index 2fe1f958..c3dd6c1c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingDataSource.java
@@ -19,8 +19,6 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
private MutableLiveData<NetworkState> initialLoadStateLiveData;
private MutableLiveData<Boolean> hasSubredditLiveData;
- private LoadInitialParams<String> initialParams;
- private LoadInitialCallback<String, SubredditData> initialCallback;
private LoadParams<String> params;
private LoadCallback<String, SubredditData> callback;
@@ -47,9 +45,6 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
@Override
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, SubredditData> callback) {
- initialParams = params;
- initialCallback = callback;
-
initialLoadStateLiveData.postValue(NetworkState.LOADING);
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType,
@@ -102,10 +97,6 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
});
}
- void retry() {
- loadInitial(initialParams, initialCallback);
- }
-
void retryLoadingMore() {
loadAfter(params, callback);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java
index 61bd8fdd..c574abce 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java
@@ -130,8 +130,10 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mSubredditListingViewModel.getInitialLoadingState().observe(this, networkState -> {
if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
+ mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
- mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> mSubredditListingViewModel.retry());
+ mProgressBar.setVisibility(View.GONE);
+ mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> mSubredditListingViewModel.refresh());
showErrorView(R.string.search_subreddits_error);
} else {
mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
@@ -140,6 +142,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
});
mSubredditListingViewModel.hasSubredditLiveData().observe(this, hasSubreddit -> {
+ mProgressBar.setVisibility(View.GONE);
if(hasSubreddit) {
mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
} else {
@@ -173,5 +176,6 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
@Override
public void refresh() {
mSubredditListingViewModel.refresh();
+ mAdapter.setNetworkState(null);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java
index 3dcd6870..1412bd22 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingViewModel.java
@@ -20,7 +20,7 @@ public class SubredditListingViewModel extends ViewModel {
private LiveData<PagedList<SubredditData>> subreddits;
private MutableLiveData<String> sortTypeLiveData;
- SubredditListingViewModel(Retrofit retrofit, String query, String sortType) {
+ public SubredditListingViewModel(Retrofit retrofit, String query, String sortType) {
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType);
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
@@ -65,10 +65,6 @@ public class SubredditListingViewModel extends ViewModel {
subredditListingDataSourceFactory.getSubredditListingDataSource().invalidate();
}
- void retry() {
- subredditListingDataSourceFactory.getSubredditListingDataSource().retry();
- }
-
void retryLoadingMore() {
subredditListingDataSourceFactory.getSubredditListingDataSource().retryLoadingMore();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java
index 2dba6202..8d55746f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingDataSource.java
@@ -19,8 +19,6 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
private MutableLiveData<NetworkState> initialLoadStateLiveData;
private MutableLiveData<Boolean> hasUserLiveData;
- private PageKeyedDataSource.LoadInitialParams<String> initialParams;
- private PageKeyedDataSource.LoadInitialCallback<String, UserData> initialCallback;
private PageKeyedDataSource.LoadParams<String> params;
private PageKeyedDataSource.LoadCallback<String, UserData> callback;
@@ -47,9 +45,6 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
@Override
public void loadInitial(@NonNull PageKeyedDataSource.LoadInitialParams<String> params, @NonNull PageKeyedDataSource.LoadInitialCallback<String, UserData> callback) {
- initialParams = params;
- initialCallback = callback;
-
initialLoadStateLiveData.postValue(NetworkState.LOADING);
FetchUserData.fetchUserListingData(retrofit, query, null, sortType,
@@ -102,10 +97,6 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
});
}
- void retry() {
- loadInitial(initialParams, initialCallback);
- }
-
void retryLoadingMore() {
loadAfter(params, callback);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java
index c3471b9a..de8028bb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java
@@ -109,8 +109,10 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mUserListingViewModel.getInitialLoadingState().observe(this, networkState -> {
if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
+ mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
- mFetchUserListingInfoLinearLayout.setOnClickListener(view -> mUserListingViewModel.retry());
+ mProgressBar.setVisibility(View.GONE);
+ mFetchUserListingInfoLinearLayout.setOnClickListener(view -> mUserListingViewModel.refresh());
showErrorView(R.string.search_users_error);
} else {
mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
@@ -119,6 +121,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
});
mUserListingViewModel.hasUser().observe(this, hasUser -> {
+ mProgressBar.setVisibility(View.GONE);
if(hasUser) {
mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
} else {
@@ -152,5 +155,6 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
@Override
public void refresh() {
mUserListingViewModel.refresh();
+ mAdapter.setNetworkState(null);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java
index de4ab542..d25463e5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingViewModel.java
@@ -20,7 +20,7 @@ public class UserListingViewModel extends ViewModel {
private LiveData<PagedList<UserData>> users;
private MutableLiveData<String> sortTypeLiveData;
- UserListingViewModel(Retrofit retrofit, String query, String sortType) {
+ public UserListingViewModel(Retrofit retrofit, String query, String sortType) {
userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType);
initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
@@ -65,10 +65,6 @@ public class UserListingViewModel extends ViewModel {
userListingDataSourceFactory.getUserListingDataSource().invalidate();
}
- void retry() {
- userListingDataSourceFactory.getUserListingDataSource().retry();
- }
-
void retryLoadingMore() {
userListingDataSourceFactory.getUserListingDataSource().retryLoadingMore();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
index 5d052cbd..07b1cc83 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
@@ -229,8 +229,10 @@ public class ViewMessageActivity extends AppCompatActivity {
mMessageViewModel.getInitialLoadingState().observe(this, networkState -> {
if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
+ mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
- mFetchMessageInfoLinearLayout.setOnClickListener(view -> mMessageViewModel.retry());
+ mProgressBar.setVisibility(View.GONE);
+ mFetchMessageInfoLinearLayout.setOnClickListener(view -> mMessageViewModel.refresh());
showErrorView(R.string.load_messages_failed);
} else {
mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
@@ -239,6 +241,7 @@ public class ViewMessageActivity extends AppCompatActivity {
});
mMessageViewModel.hasMessage().observe(this, hasMessage -> {
+ mProgressBar.setVisibility(View.GONE);
if(hasMessage) {
mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
} else {
@@ -271,6 +274,7 @@ public class ViewMessageActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if(item.getItemId() == R.id.action_refresh_view_message_activity) {
mMessageViewModel.refresh();
+ mAdapter.setNetworkState(null);
return true;
} else if(item.getItemId() == android.R.id.home) {
finish();