Minor bugs fixed related to marking and unmarking spoiler and nsfw.

This commit is contained in:
Alex Ning 2019-09-01 14:32:24 +08:00
parent b34fcf1c6d
commit c9c4b7fc58
6 changed files with 81 additions and 13 deletions

View File

@ -980,6 +980,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
} else if(holder instanceof PostDetailViewHolder) {
((PostDetailViewHolder) holder).mUpvoteButton.clearColorFilter();
((PostDetailViewHolder) holder).mDownvoteButton.clearColorFilter();
((PostDetailViewHolder) holder).spoilerFlairlinearLayout.setVisibility(View.GONE);
((PostDetailViewHolder) holder).flairTextView.setVisibility(View.GONE);
((PostDetailViewHolder) holder).spoilerTextView.setVisibility(View.GONE);
((PostDetailViewHolder) holder).mNSFWChip.setVisibility(View.GONE);
}
}

View File

@ -819,7 +819,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
private PostFragment allPostFragment;
SectionsPagerAdapter(FragmentManager fm) {
super(fm);
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
@NonNull

View File

@ -195,8 +195,8 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
ArrayList<Post> 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<String, Post> {
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<String, Post> {
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<String, Post> {
ArrayList<Post> 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<String, Post> {
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<String, Post> {
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<String, Post> {
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<String, Post> {
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<String, Post> {
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<String, Post> {
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);
}
}

View File

@ -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

View File

@ -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<String, String> 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<String> call, @NonNull Response<String> 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<String> 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<String, String> 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<String> call, @NonNull Response<String> 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<String> 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<String, String> 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<String> call, @NonNull Response<String> 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<String> 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<String, String> 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<String> call, @NonNull Response<String> 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<String> 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);
}
});

View File

@ -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