From c9c4b7fc58622743d452a4e0c4f0da6633096575 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 1 Sep 2019 14:32:24 +0800 Subject: Minor bugs fixed related to marking and unmarking spoiler and nsfw. --- .../CommentAndPostRecyclerViewAdapter.java | 4 ++ .../infinityforreddit/MainActivity.java | 2 +- .../infinityforreddit/PostDataSource.java | 20 +++---- .../infinityforreddit/SearchResultActivity.java | 2 +- .../infinityforreddit/ViewPostDetailActivity.java | 64 ++++++++++++++++++++++ .../infinityforreddit/ViewUserDetailActivity.java | 2 +- 6 files changed, 81 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index 17314525..753c7259 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -980,6 +980,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { ArrayList singlePostList = new ArrayList<>(); singlePostList.add(post); hasPostLiveData.postValue(true); - callback.onResult(singlePostList, null, null); initialLoadStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(singlePostList, null, null); } @Override @@ -226,8 +226,8 @@ class PostDataSource extends PageKeyedDataSource { hasPostLiveData.postValue(false); } - callback.onResult(newPosts, null, nextPageKey); initialLoadStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, null, nextPageKey); } @Override @@ -268,8 +268,8 @@ class PostDataSource extends PageKeyedDataSource { if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadBestPostsAfter(params, callback, lastItem); } else { - callback.onResult(newPosts, lastItem); paginationNetworkStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, lastItem); } } @@ -313,8 +313,8 @@ class PostDataSource extends PageKeyedDataSource { ArrayList singlePostList = new ArrayList<>(); singlePostList.add(post); hasPostLiveData.postValue(true); - callback.onResult(singlePostList, null, null); initialLoadStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(singlePostList, null, null); } @Override @@ -344,8 +344,8 @@ class PostDataSource extends PageKeyedDataSource { hasPostLiveData.postValue(false); } - callback.onResult(newPosts, null, nextPageKey); initialLoadStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, null, nextPageKey); } @Override @@ -392,8 +392,8 @@ class PostDataSource extends PageKeyedDataSource { if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadSubredditPostsAfter(params, callback, lastItem); } else { - callback.onResult(newPosts, lastItem); paginationNetworkStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, lastItem); } } @@ -451,8 +451,8 @@ class PostDataSource extends PageKeyedDataSource { hasPostLiveData.postValue(false); } - callback.onResult(newPosts, null, nextPageKey); initialLoadStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, null, nextPageKey); } @Override @@ -498,8 +498,8 @@ class PostDataSource extends PageKeyedDataSource { if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadUserPostsAfter(params, callback, lastItem); } else { - callback.onResult(newPosts, lastItem); paginationNetworkStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, lastItem); } } @@ -566,8 +566,8 @@ class PostDataSource extends PageKeyedDataSource { hasPostLiveData.postValue(false); } - callback.onResult(newPosts, null, nextPageKey); initialLoadStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, null, nextPageKey); } @Override @@ -622,8 +622,8 @@ class PostDataSource extends PageKeyedDataSource { if(newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadSearchPostsAfter(params, callback, lastItem); } else { - callback.onResult(newPosts, lastItem); paginationNetworkStateLiveData.postValue(NetworkState.LOADED); + callback.onResult(newPosts, lastItem); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java index ed78ac0a..9a6652c5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java @@ -271,7 +271,7 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos private UserListingFragment userListingFragment; public SectionsPagerAdapter(FragmentManager fm) { - super(fm); + super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); } @NonNull diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index fc2cab68..06487bcb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -673,6 +673,10 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } private void markNSFW() { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_unmark_nsfw); + } + Map params = new HashMap<>(); params.put(RedditUtils.ID_KEY, mPost.getFullName()); mOauthRetrofit.create(RedditAPI.class).markNSFW(RedditUtils.getOAuthHeader(mAccessToken), params) @@ -680,21 +684,37 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if(response.isSuccessful()) { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_unmark_nsfw); + } + refresh(true, false); showMessage(R.string.mark_nsfw_success); } else { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_mark_nsfw); + } + showMessage(R.string.mark_nsfw_failed); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_mark_nsfw); + } + showMessage(R.string.mark_nsfw_failed); } }); } private void unmarkNSFW() { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_mark_nsfw); + } + Map params = new HashMap<>(); params.put(RedditUtils.ID_KEY, mPost.getFullName()); mOauthRetrofit.create(RedditAPI.class).unmarkNSFW(RedditUtils.getOAuthHeader(mAccessToken), params) @@ -702,21 +722,37 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if(response.isSuccessful()) { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_mark_nsfw); + } + refresh(true, false); showMessage(R.string.unmark_nsfw_success); } else { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_unmark_nsfw); + } + showMessage(R.string.unmark_nsfw_failed); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { + if(mMenu != null) { + mMenu.findItem(R.id.action_nsfw_view_post_detail_activity).setTitle(R.string.action_unmark_nsfw); + } + showMessage(R.string.unmark_nsfw_failed); } }); } private void markSpoiler() { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_unmark_spoiler); + } + Map params = new HashMap<>(); params.put(RedditUtils.ID_KEY, mPost.getFullName()); mOauthRetrofit.create(RedditAPI.class).markSpoiler(RedditUtils.getOAuthHeader(mAccessToken), params) @@ -724,21 +760,37 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if(response.isSuccessful()) { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_unmark_spoiler); + } + refresh(true, false); showMessage(R.string.mark_spoiler_success); } else { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_mark_spoiler); + } + showMessage(R.string.mark_spoiler_failed); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_mark_spoiler); + } + showMessage(R.string.mark_spoiler_failed); } }); } private void unmarkSpoiler() { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_mark_spoiler); + } + Map params = new HashMap<>(); params.put(RedditUtils.ID_KEY, mPost.getFullName()); mOauthRetrofit.create(RedditAPI.class).unmarkSpoiler(RedditUtils.getOAuthHeader(mAccessToken), params) @@ -746,15 +798,27 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if(response.isSuccessful()) { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_mark_spoiler); + } + refresh(true, false); showMessage(R.string.unmark_spoiler_success); } else { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_unmark_spoiler); + } + showMessage(R.string.unmark_spoiler_failed); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { + if(mMenu != null) { + mMenu.findItem(R.id.action_spoiler_view_post_detail_activity).setTitle(R.string.action_unmark_spoiler); + } + showMessage(R.string.unmark_spoiler_failed); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index f062585f..e929a101 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -645,7 +645,7 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi private CommentsListingFragment commentsListingFragment; SectionsPagerAdapter(FragmentManager fm) { - super(fm); + super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); } @NonNull -- cgit v1.2.3