aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java51
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java3
13 files changed, 141 insertions, 88 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java
index 786ec3b2..9d3dab85 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java
@@ -227,6 +227,9 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing
userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag());
return true;
case R.id.action_refresh_account_posts_activity:
+ if(mMenu != null) {
+ mMenu.findItem(R.id.action_lazy_mode_account_posts_activity).setTitle(R.string.action_start_lazy_mode);
+ }
if(mFragment != null) {
((PostFragment) mFragment).refresh();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java
index 5826200b..b2dafa7f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java
@@ -106,20 +106,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class);
mCommentViewModel.getComments().observe(this, comments -> mAdapter.submitList(comments));
- 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)) {
- mProgressBar.setVisibility(View.GONE);
- mFetchCommentInfoLinearLayout.setOnClickListener(view -> mCommentViewModel.refresh());
- showErrorView(R.string.load_comments_failed);
- } else {
- mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
- mProgressBar.setVisibility(View.VISIBLE);
- }
- });
-
mCommentViewModel.hasComment().observe(this, hasComment -> {
mProgressBar.setVisibility(View.GONE);
if(hasComment) {
@@ -132,6 +118,18 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
});
+ mCommentViewModel.getInitialLoadingState().observe(this, networkState -> {
+ if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
+ mProgressBar.setVisibility(View.GONE);
+ } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mProgressBar.setVisibility(View.GONE);
+ mFetchCommentInfoLinearLayout.setOnClickListener(view -> refresh());
+ showErrorView(R.string.load_comments_failed);
+ } else {
+ mProgressBar.setVisibility(View.VISIBLE);
+ }
+ });
+
mCommentViewModel.getPaginationNetworkState().observe(this, networkState -> {
mAdapter.setNetworkState(networkState);
});
@@ -151,13 +149,14 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@Override
public void refresh() {
+ mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
mCommentViewModel.refresh();
mAdapter.setNetworkState(null);
}
private void showErrorView(int stringResId) {
- mProgressBar.setVisibility(View.GONE);
if(activity != null && isAdded()) {
+ mProgressBar.setVisibility(View.GONE);
mFetchCommentInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchCommentInfoTextView.setText(stringResId);
mGlide.load(R.drawable.error_image).into(mFetchCommentInfoImageView);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java
index f4425773..27a9ddf0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java
@@ -19,6 +19,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.appbar.CollapsingToolbarLayout;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -43,19 +44,24 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType
static final String EXTRA_SORT_TYPE = "EST";
static final String EXTRA_USER_WHERE = "EUW";
+ private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
private static final String FRAGMENT_OUT_STATE = "FOS";
@BindView(R.id.appbar_layout_filtered_posts_activity) AppBarLayout appBarLayout;
+ @BindView(R.id.collapsing_toolbar_layout_filtered_posts_activity) CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar;
+ private boolean isInLazyMode = false;
private boolean mNullAccessToken = false;
private String mAccessToken;
private String name;
private int postType;
private Fragment mFragment;
+ private Menu mMenu;
+ private AppBarLayout.LayoutParams params;
private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment;
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
@@ -72,7 +78,7 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_filtered_posts);
+ setContentView(R.layout.activity_filtered_thing);
ButterKnife.bind(this);
@@ -142,12 +148,15 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
+
name = getIntent().getStringExtra(EXTRA_NAME);
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
int filter = getIntent().getIntExtra(EXTRA_FILTER, Post.TEXT_TYPE);
String sortType = getIntent().getStringExtra(EXTRA_SORT_TYPE);
if(savedInstanceState != null) {
+ isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
if(!mNullAccessToken && mAccessToken == null) {
@@ -259,6 +268,17 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.filtered_posts_activity, menu);
+ mMenu = menu;
+ MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity);
+ if(isInLazyMode) {
+ lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
+ collapsingToolbarLayout.setLayoutParams(params);
+ } else {
+ lazyModeItem.setTitle(R.string.action_start_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
+ collapsingToolbarLayout.setLayoutParams(params);
+ }
return true;
}
@@ -268,7 +288,7 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType
case android.R.id.home:
finish();
return true;
- case R.id.action_sort_filtered_posts_activity:
+ case R.id.action_sort_filtered_thing_activity:
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag());
@@ -287,8 +307,30 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType
userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag());
}
return true;
- case R.id.action_refresh_filtered_posts_activity:
- ((FragmentCommunicator) mFragment).refresh();
+ case R.id.action_refresh_filtered_thing_activity:
+ if(mMenu != null) {
+ mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity).setTitle(R.string.action_start_lazy_mode);
+ }
+ if(mFragment instanceof FragmentCommunicator) {
+ ((FragmentCommunicator) mFragment).refresh();
+ }
+ return true;
+ case R.id.action_lazy_mode_filtered_thing_activity:
+ MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity);
+ if(isInLazyMode) {
+ ((FragmentCommunicator) mFragment).stopLazyMode();
+ isInLazyMode = false;
+ lazyModeItem.setTitle(R.string.action_start_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
+ collapsingToolbarLayout.setLayoutParams(params);
+ } else {
+ if(((FragmentCommunicator) mFragment).startLazyMode()) {
+ isInLazyMode = true;
+ lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
+ collapsingToolbarLayout.setLayoutParams(params);
+ }
+ }
return true;
}
return false;
@@ -300,6 +342,7 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType
if (mFragment != null) {
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
}
+ outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index e3c1cdf6..57b94e00 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -706,6 +706,9 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
startActivity(intent);
return true;
case R.id.action_refresh_main_activity:
+ if(mMenu != null) {
+ mMenu.findItem(R.id.action_lazy_mode_main_activity).setTitle(R.string.action_start_lazy_mode);
+ }
sectionsPagerAdapter.refresh();
mFetchUserInfoSuccess = false;
loadUserData();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
index 812cae62..cd3ae2d3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit;
+import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
@@ -75,6 +76,7 @@ class PostDataSourceFactory extends DataSource.Factory {
this.nsfw = nsfw;
}
+ @NonNull
@Override
public DataSource create() {
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index 379c3f7d..2aa27594 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -389,20 +389,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel = new ViewModelProvider(this, factory).get(PostViewModel.class);
mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts));
- 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)) {
- mProgressBar.setVisibility(View.GONE);
- mFetchPostInfoLinearLayout.setOnClickListener(view -> mPostViewModel.refresh());
- showErrorView(R.string.load_posts_error);
- } else {
- mFetchPostInfoLinearLayout.setVisibility(View.GONE);
- mProgressBar.setVisibility(View.VISIBLE);
- }
- });
-
mPostViewModel.hasPost().observe(this, hasPost -> {
this.hasPost = hasPost;
mProgressBar.setVisibility(View.GONE);
@@ -418,6 +404,18 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
});
+ mPostViewModel.getInitialLoadingState().observe(this, networkState -> {
+ if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
+ mProgressBar.setVisibility(View.GONE);
+ } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mProgressBar.setVisibility(View.GONE);
+ mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh());
+ showErrorView(R.string.load_posts_error);
+ } else {
+ mProgressBar.setVisibility(View.VISIBLE);
+ }
+ });
+
mPostViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
return rootView;
@@ -452,14 +450,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
stopLazyMode();
}
+ mFetchPostInfoLinearLayout.setVisibility(View.GONE);
hasPost = false;
mPostViewModel.refresh();
mAdapter.setNetworkState(null);
}
private void showErrorView(int stringResId) {
- mProgressBar.setVisibility(View.GONE);
if(activity != null && isAdded()) {
+ mProgressBar.setVisibility(View.GONE);
mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchPostInfoTextView.setText(stringResId);
mGlide.load(R.drawable.error_image).into(mFetchPostInfoImageView);
@@ -494,6 +493,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void stopLazyMode() {
isInLazyMode = false;
isLazyModePaused = false;
+ lazyModeRunnable.resetOldPosition();
lazyModeHandler.removeCallbacks(lazyModeRunnable);
resumeLazyModeCountDownTimer.cancel();
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 3cc6ed8f..e13fd779 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -104,7 +104,8 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
@Override
public boolean areContentsTheSame(@NonNull Post post, @NonNull Post t1) {
- return post.getTitle().equals(t1.getTitle());
+ return post.getTitle().equals(t1.getTitle()) && post.getSelfText().equals(t1.getSelfText())
+ && post.getScore() == t1.getScore();
}
};
@@ -357,7 +358,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
loadImage(holder, post);
}
- if(mPostType == PostDataSource.TYPE_SUBREDDIT && post.isStickied()) {
+ if(mPostType == PostDataSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
mGlide.load(R.drawable.thumbtack).into(((DataViewHolder) holder).stickiedPostImageView);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
index 97fc836b..cae2bace 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
@@ -48,10 +48,9 @@ public class PostViewModel extends ViewModel {
(new PagedList.Config.Builder())
.setEnablePlaceholders(false)
.setPageSize(25)
- .setInitialLoadSizeHint(75)
.build();
- posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> {
+ posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
@@ -80,10 +79,9 @@ public class PostViewModel extends ViewModel {
(new PagedList.Config.Builder())
.setEnablePlaceholders(false)
.setPageSize(25)
- .setInitialLoadSizeHint(75)
.build();
- posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> {
+ posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
@@ -112,10 +110,9 @@ public class PostViewModel extends ViewModel {
(new PagedList.Config.Builder())
.setEnablePlaceholders(false)
.setPageSize(25)
- .setInitialLoadSizeHint(75)
.build();
- posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> {
+ posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
@@ -144,10 +141,9 @@ public class PostViewModel extends ViewModel {
(new PagedList.Config.Builder())
.setEnablePlaceholders(false)
.setPageSize(25)
- .setInitialLoadSizeHint(75)
.build();
- posts = Transformations.switchMap(sortTypeLiveData, sort -> {
+ posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java
index c574abce..03660f57 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java
@@ -127,20 +127,6 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class);
mSubredditListingViewModel.getSubreddits().observe(this, subredditData -> mAdapter.submitList(subredditData));
- 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)) {
- mProgressBar.setVisibility(View.GONE);
- mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> mSubredditListingViewModel.refresh());
- showErrorView(R.string.search_subreddits_error);
- } else {
- mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
- mProgressBar.setVisibility(View.VISIBLE);
- }
- });
-
mSubredditListingViewModel.hasSubredditLiveData().observe(this, hasSubreddit -> {
mProgressBar.setVisibility(View.GONE);
if(hasSubreddit) {
@@ -153,6 +139,18 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
}
});
+ mSubredditListingViewModel.getInitialLoadingState().observe(this, networkState -> {
+ if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
+ mProgressBar.setVisibility(View.GONE);
+ } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mProgressBar.setVisibility(View.GONE);
+ mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> refresh());
+ showErrorView(R.string.search_subreddits_error);
+ } else {
+ mProgressBar.setVisibility(View.VISIBLE);
+ }
+ });
+
mSubredditListingViewModel.getPaginationNetworkState().observe(this, networkState -> {
mAdapter.setNetworkState(networkState);
});
@@ -161,8 +159,8 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
}
private void showErrorView(int stringResId) {
- mProgressBar.setVisibility(View.GONE);
if(getActivity() != null && isAdded()) {
+ mProgressBar.setVisibility(View.GONE);
mFetchSubredditListingInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchSubredditListingInfoTextView.setText(stringResId);
Glide.with(this).load(R.drawable.error_image).into(mFetchSubredditListingInfoImageView);
@@ -175,6 +173,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
@Override
public void refresh() {
+ mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
mSubredditListingViewModel.refresh();
mAdapter.setNetworkState(null);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java
index de8028bb..ed62f453 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java
@@ -106,20 +106,6 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mUserListingViewModel = new ViewModelProvider(this, factory).get(UserListingViewModel.class);
mUserListingViewModel.getUsers().observe(this, UserData -> mAdapter.submitList(UserData));
- 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)) {
- mProgressBar.setVisibility(View.GONE);
- mFetchUserListingInfoLinearLayout.setOnClickListener(view -> mUserListingViewModel.refresh());
- showErrorView(R.string.search_users_error);
- } else {
- mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
- mProgressBar.setVisibility(View.VISIBLE);
- }
- });
-
mUserListingViewModel.hasUser().observe(this, hasUser -> {
mProgressBar.setVisibility(View.GONE);
if(hasUser) {
@@ -132,6 +118,18 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
}
});
+ mUserListingViewModel.getInitialLoadingState().observe(this, networkState -> {
+ if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
+ mProgressBar.setVisibility(View.GONE);
+ } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mProgressBar.setVisibility(View.GONE);
+ mFetchUserListingInfoLinearLayout.setOnClickListener(view -> refresh());
+ showErrorView(R.string.search_users_error);
+ } else {
+ mProgressBar.setVisibility(View.VISIBLE);
+ }
+ });
+
mUserListingViewModel.getPaginationNetworkState().observe(this, networkState -> {
mAdapter.setNetworkState(networkState);
});
@@ -140,8 +138,8 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
}
private void showErrorView(int stringResId) {
- mProgressBar.setVisibility(View.GONE);
if(getActivity() != null && isAdded()) {
+ mProgressBar.setVisibility(View.GONE);
mFetchUserListingInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchUserListingInfoTextView.setText(stringResId);
Glide.with(this).load(R.drawable.error_image).into(mFetchUserListingInfoImageView);
@@ -154,6 +152,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
@Override
public void refresh() {
+ mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
mUserListingViewModel.refresh();
mAdapter.setNetworkState(null);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
index 07b1cc83..34f1d653 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java
@@ -226,20 +226,6 @@ public class ViewMessageActivity extends AppCompatActivity {
mMessageViewModel = new ViewModelProvider(this, factory).get(MessageViewModel.class);
mMessageViewModel.getMessages().observe(this, messages -> mAdapter.submitList(messages));
- 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)) {
- mProgressBar.setVisibility(View.GONE);
- mFetchMessageInfoLinearLayout.setOnClickListener(view -> mMessageViewModel.refresh());
- showErrorView(R.string.load_messages_failed);
- } else {
- mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
- mProgressBar.setVisibility(View.VISIBLE);
- }
- });
-
mMessageViewModel.hasMessage().observe(this, hasMessage -> {
mProgressBar.setVisibility(View.GONE);
if(hasMessage) {
@@ -252,6 +238,22 @@ public class ViewMessageActivity extends AppCompatActivity {
}
});
+ mMessageViewModel.getInitialLoadingState().observe(this, networkState -> {
+ if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
+ mProgressBar.setVisibility(View.GONE);
+ } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mProgressBar.setVisibility(View.GONE);
+ mFetchMessageInfoLinearLayout.setOnClickListener(view -> {
+ mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
+ mMessageViewModel.refresh();
+ mAdapter.setNetworkState(null);
+ });
+ showErrorView(R.string.load_messages_failed);
+ } else {
+ mProgressBar.setVisibility(View.VISIBLE);
+ }
+ });
+
mMessageViewModel.getPaginationNetworkState().observe(this, networkState -> {
mAdapter.setNetworkState(networkState);
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
index c1f10bd4..fb322422 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
@@ -478,6 +478,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
startActivity(intent);
break;
case R.id.action_refresh_view_subreddit_detail_activity:
+ if(mMenu != null) {
+ mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
+ }
if(mFragment instanceof FragmentCommunicator) {
((FragmentCommunicator) mFragment).refresh();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
index 939ca6d9..f062585f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
@@ -533,6 +533,9 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
startActivity(intent);
return true;
case R.id.action_refresh_view_user_detail_activity:
+ if(mMenu != null) {
+ mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity).setTitle(R.string.action_start_lazy_mode);
+ }
sectionsPagerAdapter.refresh();
return true;
case R.id.action_lazy_mode_view_user_detail_activity: