Hiding and unhiding posts are now available.

This commit is contained in:
Alex Ning 2019-09-08 16:08:39 +08:00
parent 010a230baf
commit 5dbe271b2c
12 changed files with 240 additions and 50 deletions

Binary file not shown.

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit" applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 2 versionCode 3
versionName "1.0.1" versionName "1.0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {

View File

@ -0,0 +1,60 @@
package ml.docilealligator.infinityforreddit;
import androidx.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
class HidePost {
interface HidePostListener {
void success();
void failed();
}
static void hidePost(Retrofit oauthRetrofit, String accessToken, String fullname,
HidePostListener hidePostListener) {
Map<String, String> params = new HashMap<>();
params.put(RedditUtils.ID_KEY, fullname);
oauthRetrofit.create(RedditAPI.class).hide(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
hidePostListener.success();
} else {
hidePostListener.failed();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
hidePostListener.failed();
}
});
}
static void unhidePost(Retrofit oauthRetrofit, String accessToken, String fullname,
HidePostListener hidePostListener) {
Map<String, String> params = new HashMap<>();
params.put(RedditUtils.ID_KEY, fullname);
oauthRetrofit.create(RedditAPI.class).unhide(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
hidePostListener.success();
} else {
hidePostListener.failed();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
hidePostListener.failed();
}
});
}
}

View File

@ -84,4 +84,5 @@ public class JSONUtils {
static final String WAS_COMMENT_KEY = "was_comment"; static final String WAS_COMMENT_KEY = "was_comment";
static final String NEW_KEY = "new"; static final String NEW_KEY = "new";
static final String NUM_COMMENTS_KEY = "num_comments"; static final String NUM_COMMENTS_KEY = "num_comments";
static final String HIDDEN_KEY = "hidden";
} }

View File

@ -163,6 +163,7 @@ class ParsePost {
int score = data.getInt(JSONUtils.SCORE_KEY); int score = data.getInt(JSONUtils.SCORE_KEY);
int voteType; int voteType;
int gilded = data.getInt(JSONUtils.GILDED_KEY); int gilded = data.getInt(JSONUtils.GILDED_KEY);
boolean hidden = data.getBoolean(JSONUtils.HIDDEN_KEY);
boolean spoiler = data.getBoolean(JSONUtils.SPOILER_KEY); boolean spoiler = data.getBoolean(JSONUtils.SPOILER_KEY);
boolean nsfw = data.getBoolean(JSONUtils.NSFW_KEY); boolean nsfw = data.getBoolean(JSONUtils.NSFW_KEY);
boolean stickied = data.getBoolean(JSONUtils.STICKIED_KEY); boolean stickied = data.getBoolean(JSONUtils.STICKIED_KEY);
@ -204,15 +205,15 @@ class ParsePost {
Post crosspostParent = parseBasicData(data, locale); Post crosspostParent = parseBasicData(data, locale);
Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight,
score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, score, voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked,
true); saved, true);
post.setCrosspostParentId(crosspostParent.getId()); post.setCrosspostParentId(crosspostParent.getId());
return post; return post;
} else { } else {
return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight,
score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, score, voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked,
false); saved, false);
} }
} }
@ -220,8 +221,8 @@ class ParsePost {
String subredditName, String subredditNamePrefixed, String author, String subredditName, String subredditNamePrefixed, String author,
String formattedPostTime, String title, String previewUrl, int previewWidth, String formattedPostTime, String title, String previewUrl, int previewWidth,
int previewHeight, int score, int voteType, int gilded, String flair, int previewHeight, int score, int voteType, int gilded, String flair,
boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied,
boolean locked, boolean saved, boolean isCrosspost) throws JSONException { boolean archived, boolean locked, boolean saved, boolean isCrosspost) throws JSONException {
Post post; Post post;
boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY);
@ -232,7 +233,7 @@ class ParsePost {
//Text post //Text post
int postType = Post.TEXT_TYPE; int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
title, permalink, score, postType, voteType, gilded, flair, spoiler, nsfw, title, permalink, score, postType, voteType, gilded, flair, hidden, spoiler, nsfw,
stickied, archived, locked, saved, isCrosspost); stickied, archived, locked, saved, isCrosspost);
if(data.isNull(JSONUtils.SELFTEXT_KEY)) { if(data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
@ -243,8 +244,8 @@ class ParsePost {
//No preview link post //No preview link post
int postType = Post.NO_PREVIEW_LINK_TYPE; int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
title, previewUrl, url, permalink, score, postType, title, previewUrl, url, permalink, score, postType, voteType, gilded, flair,
voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
if(data.isNull(JSONUtils.SELFTEXT_KEY)) { if(data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
@ -264,8 +265,8 @@ class ParsePost {
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.DASH_URL_KEY)).toString(); String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.DASH_URL_KEY)).toString();
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime,
title, previewUrl, permalink, score, postType, voteType, title, previewUrl, permalink, score, postType, voteType, gilded, flair, hidden,
gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, true); spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, true);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
@ -279,9 +280,10 @@ class ParsePost {
String videoUrl = Html.fromHtml(variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString(); 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(); String gifDownloadUrl = Html.fromHtml(variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString();
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
previewUrl, permalink, score, postType, voteType, formattedPostTime, title, previewUrl, permalink, score, postType, voteType,
gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, false); gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved,
isCrosspost, false);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
post.setVideoUrl(videoUrl); post.setVideoUrl(videoUrl);
@ -293,9 +295,10 @@ class ParsePost {
String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY) String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY)
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY)).toString(); .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY)).toString();
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
previewUrl, permalink, score, postType, voteType, formattedPostTime, title, previewUrl, permalink, score, postType, voteType,
gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, true); gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved,
isCrosspost, true);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
post.setVideoUrl(videoUrl); post.setVideoUrl(videoUrl);
@ -305,9 +308,10 @@ class ParsePost {
//Image post //Image post
int postType = Post.IMAGE_TYPE; int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
title, url, url, permalink, score, postType, formattedPostTime, title, url, url, permalink, score, postType,
voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
@ -316,9 +320,10 @@ class ParsePost {
//Text post but with a preview //Text post but with a preview
int postType = Post.TEXT_TYPE; int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
title, permalink, score, postType, voteType, gilded, flair, spoiler, formattedPostTime, title, permalink, score, postType, voteType,
nsfw, stickied, archived, locked, saved, isCrosspost); gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked,
saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
@ -332,9 +337,10 @@ class ParsePost {
//Link post //Link post
int postType = Post.LINK_TYPE; int postType = Post.LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
title, previewUrl, url, permalink, score, postType, voteType, gilded, formattedPostTime, title, previewUrl, url, permalink, score, postType,
flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
if(data.isNull(JSONUtils.SELFTEXT_KEY)) { if(data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
@ -351,18 +357,20 @@ class ParsePost {
//Image post //Image post
int postType = Post.IMAGE_TYPE; int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
title, previewUrl, url, permalink, score, postType, formattedPostTime, title, previewUrl, url, permalink, score, postType,
voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
} else { } else {
//CP No Preview Link post //CP No Preview Link post
int postType = Post.NO_PREVIEW_LINK_TYPE; int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
url, url, permalink, score, postType, voteType, formattedPostTime, title, url, url, permalink, score, postType, voteType,
gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved,
isCrosspost);
} }
} }
} }

View File

@ -39,6 +39,7 @@ class Post implements Parcelable {
private int gilded; private int gilded;
private int previewWidth; private int previewWidth;
private int previewHeight; private int previewHeight;
private boolean hidden;
private boolean spoiler; private boolean spoiler;
private boolean nsfw; private boolean nsfw;
private boolean stickied; private boolean stickied;
@ -52,8 +53,9 @@ class Post implements Parcelable {
Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author,
String postTime, String title, String previewUrl, String permalink, int score, int postType, String postTime, String title, String previewUrl, String permalink, int score, int postType,
int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, int voteType, int gilded, String flair, boolean hidden, boolean spoiler, boolean nsfw,
boolean archived, boolean locked, boolean saved, boolean isCrosspost, boolean isDashVideo) { boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost,
boolean isDashVideo) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -69,6 +71,7 @@ class Post implements Parcelable {
this.voteType = voteType; this.voteType = voteType;
this.gilded = gilded; this.gilded = gilded;
this.flair = flair; this.flair = flair;
this.hidden = hidden;
this.spoiler = spoiler; this.spoiler = spoiler;
this.nsfw = nsfw; this.nsfw = nsfw;
this.stickied = stickied; this.stickied = stickied;
@ -81,8 +84,8 @@ class Post implements Parcelable {
Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author,
String postTime, String title, String previewUrl, String url, String permalink, int score, String postTime, String title, String previewUrl, String url, String permalink, int score,
int postType, int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, int postType, int voteType, int gilded, String flair, boolean hidden, boolean spoiler,
boolean archived, boolean locked, boolean saved, boolean isCrosspost) { boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -99,6 +102,7 @@ class Post implements Parcelable {
this.voteType = voteType; this.voteType = voteType;
this.gilded = gilded; this.gilded = gilded;
this.flair = flair; this.flair = flair;
this.hidden = hidden;
this.spoiler = spoiler; this.spoiler = spoiler;
this.nsfw = nsfw; this.nsfw = nsfw;
this.stickied = stickied; this.stickied = stickied;
@ -110,8 +114,8 @@ class Post implements Parcelable {
Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author,
String postTime, String title, String permalink, int score, int postType, int voteType, int gilded, String postTime, String title, String permalink, int score, int postType, int voteType, int gilded,
String flair, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, String flair, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean archived,
boolean saved, boolean isCrosspost) { boolean locked, boolean saved, boolean isCrosspost) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -126,6 +130,7 @@ class Post implements Parcelable {
this.voteType = voteType; this.voteType = voteType;
this.gilded = gilded; this.gilded = gilded;
this.flair = flair; this.flair = flair;
this.hidden = hidden;
this.spoiler = spoiler; this.spoiler = spoiler;
this.nsfw = nsfw; this.nsfw = nsfw;
this.stickied = stickied; this.stickied = stickied;
@ -159,6 +164,7 @@ class Post implements Parcelable {
gilded = in.readInt(); gilded = in.readInt();
previewWidth = in.readInt(); previewWidth = in.readInt();
previewHeight = in.readInt(); previewHeight = in.readInt();
hidden = in.readByte() != 0;
spoiler = in.readByte() != 0; spoiler = in.readByte() != 0;
nsfw = in.readByte() != 0; nsfw = in.readByte() != 0;
stickied = in.readByte() != 0; stickied = in.readByte() != 0;
@ -319,6 +325,14 @@ class Post implements Parcelable {
return previewHeight; return previewHeight;
} }
boolean isHidden() {
return hidden;
}
void setHidden(boolean hidden) {
this.hidden = hidden;
}
boolean isSpoiler() { boolean isSpoiler() {
return spoiler; return spoiler;
} }
@ -409,6 +423,7 @@ class Post implements Parcelable {
parcel.writeInt(gilded); parcel.writeInt(gilded);
parcel.writeInt(previewWidth); parcel.writeInt(previewWidth);
parcel.writeInt(previewHeight); parcel.writeInt(previewHeight);
parcel.writeByte((byte) (hidden ? 1 : 0));
parcel.writeByte((byte) (spoiler ? 1 : 0)); parcel.writeByte((byte) (spoiler ? 1 : 0));
parcel.writeByte((byte) (nsfw ? 1 : 0)); parcel.writeByte((byte) (nsfw ? 1 : 0));
parcel.writeByte((byte) (stickied ? 1 : 0)); parcel.writeByte((byte) (stickied ? 1 : 0));

View File

@ -544,6 +544,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
post.setVoteType(event.post.getVoteType()); post.setVoteType(event.post.getVoteType());
post.setScore(event.post.getScore()); post.setScore(event.post.getScore());
post.setNSFW(event.post.isNSFW()); post.setNSFW(event.post.isNSFW());
post.setHidden(event.post.isHidden());
post.setSpoiler(event.post.isSpoiler()); post.setSpoiler(event.post.isSpoiler());
post.setFlair(event.post.getFlair()); post.setFlair(event.post.getFlair());
post.setSaved(event.post.isSaved()); post.setSaved(event.post.isSaved());

View File

@ -176,4 +176,12 @@ public interface RedditAPI {
@FormUrlEncoded @FormUrlEncoded
@POST("/api/unsave") @POST("/api/unsave")
Call<String> unsave(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); Call<String> unsave(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
@FormUrlEncoded
@POST("/api/hide")
Call<String> hide(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
@FormUrlEncoded
@POST("/api/unhide")
Call<String> unhide(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
} }

View File

@ -304,6 +304,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
} else { } else {
if(mMenu != null) { if(mMenu != null) {
MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity); MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
if(mAccessToken != null) { if(mAccessToken != null) {
if(mPost.isSaved()) { if(mPost.isSaved()) {
saveItem.setVisible(true); saveItem.setVisible(true);
@ -312,8 +313,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
saveItem.setVisible(true); saveItem.setVisible(true);
saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px);
} }
if(mPost.isHidden()) {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_unhide_post);
} else {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_hide_post);
}
} else { } else {
saveItem.setVisible(false); saveItem.setVisible(false);
hideItem.setVisible(false);
} }
if(mPost.getAuthor().equals(mAccountName)) { if(mPost.getAuthor().equals(mAccountName)) {
@ -420,6 +430,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
if(mMenu != null) { if(mMenu != null) {
MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity); MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
if(mAccessToken != null) { if(mAccessToken != null) {
if(post.isSaved()) { if(post.isSaved()) {
saveItem.setVisible(true); saveItem.setVisible(true);
@ -428,8 +439,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
saveItem.setVisible(true); saveItem.setVisible(true);
saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px);
} }
if(post.isHidden()) {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_unhide_post);
} else {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_hide_post);
}
} else { } else {
saveItem.setVisible(false); saveItem.setVisible(false);
hideItem.setVisible(false);
} }
if(mPost.getAuthor().equals(mAccountName)) { if(mPost.getAuthor().equals(mAccountName)) {
@ -630,6 +650,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
isRefreshing = false; isRefreshing = false;
if(mMenu != null) { if(mMenu != null) {
MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity); MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
if(mAccessToken != null) { if(mAccessToken != null) {
if(post.isSaved()) { if(post.isSaved()) {
saveItem.setVisible(true); saveItem.setVisible(true);
@ -638,8 +659,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
saveItem.setVisible(true); saveItem.setVisible(true);
saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px);
} }
if(post.isHidden()) {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_unhide_post);
} else {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_hide_post);
}
} else { } else {
saveItem.setVisible(false); saveItem.setVisible(false);
hideItem.setVisible(false);
} }
mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null); mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
@ -668,7 +698,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
if(showToast) { if(showToast) {
Toast.makeText(ViewPostDetailActivity.this, resId, Toast.LENGTH_SHORT).show(); Toast.makeText(ViewPostDetailActivity.this, resId, Toast.LENGTH_SHORT).show();
} else { } else {
Snackbar.make(mCoordinatorLayout, resId, Snackbar.LENGTH_SHORT); Snackbar.make(mCoordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
} }
} }
@ -872,6 +902,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mMenu = menu; mMenu = menu;
if(mPost != null) { if(mPost != null) {
MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity); MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
if(mAccessToken != null) { if(mAccessToken != null) {
if(mPost.isSaved()) { if(mPost.isSaved()) {
saveItem.setVisible(true); saveItem.setVisible(true);
@ -880,8 +911,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
saveItem.setVisible(true); saveItem.setVisible(true);
saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px);
} }
if(mPost.isHidden()) {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_unhide_post);
} else {
hideItem.setVisible(true);
hideItem.setTitle(R.string.action_hide_post);
}
} else { } else {
saveItem.setVisible(false); saveItem.setVisible(false);
hideItem.setVisible(false);
} }
if(mPost.getAuthor().equals(mAccountName)) { if(mPost.getAuthor().equals(mAccountName)) {
@ -993,6 +1033,51 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
crosspostIntent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, mPost.getCrosspostParentId()); crosspostIntent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, mPost.getCrosspostParentId());
startActivity(crosspostIntent); startActivity(crosspostIntent);
return true; return true;
case R.id.action_hide_view_post_detail_activity:
if(mPost != null && mAccessToken != null) {
if(mPost.isHidden()) {
item.setTitle(R.string.action_hide_post);
HidePost.unhidePost(mOauthRetrofit, mAccessToken, mPost.getFullName(), new HidePost.HidePostListener() {
@Override
public void success() {
mPost.setHidden(false);
item.setTitle(R.string.action_hide_post);
showMessage(R.string.post_unhide_success);
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
@Override
public void failed() {
mPost.setHidden(true);
item.setTitle(R.string.action_unhide_post);
showMessage(R.string.post_unhide_failed);
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
});
} else {
item.setTitle(R.string.action_unhide_post);
HidePost.hidePost(mOauthRetrofit, mAccessToken, mPost.getFullName(), new HidePost.HidePostListener() {
@Override
public void success() {
mPost.setHidden(true);
item.setTitle(R.string.action_unhide_post);
showMessage(R.string.post_hide_success);
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
@Override
public void failed() {
mPost.setHidden(false);
item.setTitle(R.string.action_hide_post);
showMessage(R.string.post_hide_failed);
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
});
}
}
return true;
case R.id.action_edit_view_post_detail_activity: case R.id.action_edit_view_post_detail_activity:
Intent editPostItent = new Intent(this, EditPostActivity.class); Intent editPostItent = new Intent(this, EditPostActivity.class);
editPostItent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken); editPostItent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken);

View File

@ -29,34 +29,40 @@
android:visible="false" /> android:visible="false" />
<item <item
android:id="@+id/action_edit_view_post_detail_activity" android:id="@+id/action_hide_view_post_detail_activity"
android:orderInCategory="5" android:orderInCategory="5"
app:showAsAction="never"
android:visible="false" />
<item
android:id="@+id/action_edit_view_post_detail_activity"
android:orderInCategory="6"
android:title="@string/action_edit_post" android:title="@string/action_edit_post"
app:showAsAction="never" app:showAsAction="never"
android:visible="false" /> android:visible="false" />
<item <item
android:id="@+id/action_delete_view_post_detail_activity" android:id="@+id/action_delete_view_post_detail_activity"
android:orderInCategory="6" android:orderInCategory="7"
android:title="@string/action_delete_post" android:title="@string/action_delete_post"
app:showAsAction="never" app:showAsAction="never"
android:visible="false" /> android:visible="false" />
<item <item
android:id="@+id/action_nsfw_view_post_detail_activity" android:id="@+id/action_nsfw_view_post_detail_activity"
android:orderInCategory="7"
app:showAsAction="never"
android:visible="false" />
<item
android:id="@+id/action_spoiler_view_post_detail_activity"
android:orderInCategory="8" android:orderInCategory="8"
app:showAsAction="never" app:showAsAction="never"
android:visible="false" /> android:visible="false" />
<item <item
android:id="@+id/action_edit_flair_view_post_detail_activity" android:id="@+id/action_spoiler_view_post_detail_activity"
android:orderInCategory="9" android:orderInCategory="9"
app:showAsAction="never"
android:visible="false" />
<item
android:id="@+id/action_edit_flair_view_post_detail_activity"
android:orderInCategory="10"
android:title="@string/action_edit_flair" android:title="@string/action_edit_flair"
app:showAsAction="never" app:showAsAction="never"
android:visible="false" /> android:visible="false" />

View File

@ -30,6 +30,8 @@
<string name="action_stop_lazy_mode">Stop Lazy Mode</string> <string name="action_stop_lazy_mode">Stop Lazy Mode</string>
<string name="action_send">Send</string> <string name="action_send">Send</string>
<string name="action_sort">Sort</string> <string name="action_sort">Sort</string>
<string name="action_hide_post">Hide Post</string>
<string name="action_unhide_post">Unhide Post</string>
<string name="action_edit_post">Edit Post</string> <string name="action_edit_post">Edit Post</string>
<string name="action_delete_post">Delete Post</string> <string name="action_delete_post">Delete Post</string>
<string name="action_mark_nsfw">Mark NSFW</string> <string name="action_mark_nsfw">Mark NSFW</string>
@ -216,6 +218,10 @@
<string name="post_saved_failed">Unable to save post</string> <string name="post_saved_failed">Unable to save post</string>
<string name="post_unsaved_success">Post unsaved</string> <string name="post_unsaved_success">Post unsaved</string>
<string name="post_unsaved_failed">Unable to unsave post</string> <string name="post_unsaved_failed">Unable to unsave post</string>
<string name="post_hide_success">Post hidden</string>
<string name="post_hide_failed">Unable to hide post</string>
<string name="post_unhide_success">Post unhidden</string>
<string name="post_unhide_failed">Unable to unhide post</string>
<string name="delete_this_post">Delete This Post</string> <string name="delete_this_post">Delete This Post</string>
<string name="delete_this_comment">Delete This Comment</string> <string name="delete_this_comment">Delete This Comment</string>
<string name="are_you_sure">Are you sure?</string> <string name="are_you_sure">Are you sure?</string>