diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-09-08 08:08:39 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-09-08 08:08:39 +0000 |
commit | 5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf (patch) | |
tree | 9db4a30fbebd32e75126a52f02a43df53b4062f8 | |
parent | 010a230baf5aff1f77e44304b9f1e86b1a3b20f9 (diff) | |
download | infinity-for-reddit-5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf.tar infinity-for-reddit-5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf.tar.gz infinity-for-reddit-5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf.tar.bz2 infinity-for-reddit-5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf.tar.lz infinity-for-reddit-5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf.tar.xz infinity-for-reddit-5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf.tar.zst infinity-for-reddit-5dbe271b2cd4ce479e9d6d8d7b6a1c36409328bf.zip |
Hiding and unhiding posts are now available.
-rw-r--r-- | .idea/caches/build_file_checksums.ser | bin | 533 -> 533 bytes | |||
-rw-r--r-- | .idea/caches/gradle_models.ser | bin | 309041 -> 309041 bytes | |||
-rw-r--r-- | app/build.gradle | 4 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/HidePost.java | 60 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java | 1 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java | 72 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Post.java | 27 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java | 1 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java | 8 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java | 87 | ||||
-rw-r--r-- | app/src/main/res/menu/view_post_detail_activity.xml | 16 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 6 |
12 files changed, 236 insertions, 46 deletions
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser Binary files differindex b366bf4e..278bd13e 100644 --- a/.idea/caches/build_file_checksums.ser +++ b/.idea/caches/build_file_checksums.ser diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser Binary files differindex e9a9389d..cb1fa4d8 100644 --- a/.idea/caches/gradle_models.ser +++ b/.idea/caches/gradle_models.ser diff --git a/app/build.gradle b/app/build.gradle index 1e7a6afe..d76d3708 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "ml.docilealligator.infinityforreddit" minSdkVersion 21 targetSdkVersion 29 - versionCode 2 - versionName "1.0.1" + versionCode 3 + versionName "1.0.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/HidePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/HidePost.java new file mode 100644 index 00000000..ec6770d2 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/HidePost.java @@ -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(); + } + }); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java index 91d67096..4346ccbe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java @@ -84,4 +84,5 @@ public class JSONUtils { static final String WAS_COMMENT_KEY = "was_comment"; static final String NEW_KEY = "new"; static final String NUM_COMMENTS_KEY = "num_comments"; + static final String HIDDEN_KEY = "hidden"; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index 1cae9ee3..efe58ff0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -163,6 +163,7 @@ class ParsePost { int score = data.getInt(JSONUtils.SCORE_KEY); int voteType; int gilded = data.getInt(JSONUtils.GILDED_KEY); + boolean hidden = data.getBoolean(JSONUtils.HIDDEN_KEY); boolean spoiler = data.getBoolean(JSONUtils.SPOILER_KEY); boolean nsfw = data.getBoolean(JSONUtils.NSFW_KEY); boolean stickied = data.getBoolean(JSONUtils.STICKIED_KEY); @@ -204,15 +205,15 @@ class ParsePost { Post crosspostParent = parseBasicData(data, locale); Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, - score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, - true); + score, voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, + saved, true); post.setCrosspostParentId(crosspostParent.getId()); return post; } else { return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, - score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, - false); + score, voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, + saved, false); } } @@ -220,8 +221,8 @@ class ParsePost { String subredditName, String subredditNamePrefixed, String author, String formattedPostTime, String title, String previewUrl, int previewWidth, int previewHeight, int score, int voteType, int gilded, String flair, - boolean spoiler, boolean nsfw, boolean stickied, boolean archived, - boolean locked, boolean saved, boolean isCrosspost) throws JSONException { + boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, + boolean archived, boolean locked, boolean saved, boolean isCrosspost) throws JSONException { Post post; boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); @@ -232,7 +233,7 @@ class ParsePost { //Text post int postType = Post.TEXT_TYPE; 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); if(data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); @@ -243,8 +244,8 @@ class ParsePost { //No preview link post int postType = Post.NO_PREVIEW_LINK_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, previewUrl, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + title, previewUrl, url, permalink, score, postType, voteType, gilded, flair, + hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -264,8 +265,8 @@ class ParsePost { String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.DASH_URL_KEY)).toString(); post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, true); + title, previewUrl, permalink, score, postType, voteType, gilded, flair, hidden, + spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, true); post.setPreviewWidth(previewWidth); 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 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, - previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, false); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + formattedPostTime, title, previewUrl, permalink, score, postType, voteType, + gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, + isCrosspost, false); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -293,9 +295,10 @@ class ParsePost { String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY) .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY)).toString(); - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, - previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, true); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + formattedPostTime, title, previewUrl, permalink, score, postType, voteType, + gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, + isCrosspost, true); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -305,9 +308,10 @@ class ParsePost { //Image post int postType = Post.IMAGE_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, url, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + formattedPostTime, title, url, url, permalink, score, postType, + voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, + locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -316,9 +320,10 @@ class ParsePost { //Text post but with a preview int postType = Post.TEXT_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, permalink, score, postType, voteType, gilded, flair, spoiler, - nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + formattedPostTime, title, permalink, score, postType, voteType, + gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, + saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -332,9 +337,10 @@ class ParsePost { //Link post int postType = Post.LINK_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, previewUrl, url, permalink, score, postType, voteType, gilded, - flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + formattedPostTime, title, previewUrl, url, permalink, score, postType, + voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, + locked, saved, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -351,18 +357,20 @@ class ParsePost { //Image post int postType = Post.IMAGE_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, previewUrl, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + formattedPostTime, title, previewUrl, url, permalink, score, postType, + voteType, gilded, flair, hidden, spoiler, nsfw, stickied, archived, + locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); } else { //CP No Preview Link post int postType = Post.NO_PREVIEW_LINK_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, - url, url, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + formattedPostTime, title, url, url, permalink, score, postType, voteType, + gilded, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, + isCrosspost); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 9a5371c2..8d9fd436 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -39,6 +39,7 @@ class Post implements Parcelable { private int gilded; private int previewWidth; private int previewHeight; + private boolean hidden; private boolean spoiler; private boolean nsfw; private boolean stickied; @@ -52,8 +53,9 @@ class Post implements Parcelable { Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, String postTime, String title, String previewUrl, String permalink, int score, int postType, - int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, - boolean archived, boolean locked, boolean saved, boolean isCrosspost, boolean isDashVideo) { + int voteType, int gilded, String flair, boolean hidden, boolean spoiler, boolean nsfw, + boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost, + boolean isDashVideo) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -69,6 +71,7 @@ class Post implements Parcelable { this.voteType = voteType; this.gilded = gilded; this.flair = flair; + this.hidden = hidden; this.spoiler = spoiler; this.nsfw = nsfw; this.stickied = stickied; @@ -81,8 +84,8 @@ class Post implements Parcelable { Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, 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, - boolean archived, boolean locked, boolean saved, boolean isCrosspost) { + int postType, int voteType, int gilded, String flair, boolean hidden, boolean spoiler, + boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -99,6 +102,7 @@ class Post implements Parcelable { this.voteType = voteType; this.gilded = gilded; this.flair = flair; + this.hidden = hidden; this.spoiler = spoiler; this.nsfw = nsfw; this.stickied = stickied; @@ -110,8 +114,8 @@ class Post implements Parcelable { 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 flair, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, - boolean saved, boolean isCrosspost) { + String flair, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, + boolean locked, boolean saved, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -126,6 +130,7 @@ class Post implements Parcelable { this.voteType = voteType; this.gilded = gilded; this.flair = flair; + this.hidden = hidden; this.spoiler = spoiler; this.nsfw = nsfw; this.stickied = stickied; @@ -159,6 +164,7 @@ class Post implements Parcelable { gilded = in.readInt(); previewWidth = in.readInt(); previewHeight = in.readInt(); + hidden = in.readByte() != 0; spoiler = in.readByte() != 0; nsfw = in.readByte() != 0; stickied = in.readByte() != 0; @@ -319,6 +325,14 @@ class Post implements Parcelable { return previewHeight; } + boolean isHidden() { + return hidden; + } + + void setHidden(boolean hidden) { + this.hidden = hidden; + } + boolean isSpoiler() { return spoiler; } @@ -409,6 +423,7 @@ class Post implements Parcelable { parcel.writeInt(gilded); parcel.writeInt(previewWidth); parcel.writeInt(previewHeight); + parcel.writeByte((byte) (hidden ? 1 : 0)); parcel.writeByte((byte) (spoiler ? 1 : 0)); parcel.writeByte((byte) (nsfw ? 1 : 0)); parcel.writeByte((byte) (stickied ? 1 : 0)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index e6e6fb12..2bb47053 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -544,6 +544,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { post.setVoteType(event.post.getVoteType()); post.setScore(event.post.getScore()); post.setNSFW(event.post.isNSFW()); + post.setHidden(event.post.isHidden()); post.setSpoiler(event.post.isSpoiler()); post.setFlair(event.post.getFlair()); post.setSaved(event.post.isSaved()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java index e4838897..55904d2b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java @@ -176,4 +176,12 @@ public interface RedditAPI { @FormUrlEncoded @POST("/api/unsave") 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); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 06487bcb..42a63247 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -304,6 +304,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } else { if(mMenu != null) { 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(mPost.isSaved()) { saveItem.setVisible(true); @@ -312,8 +313,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo saveItem.setVisible(true); 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 { saveItem.setVisible(false); + hideItem.setVisible(false); } if(mPost.getAuthor().equals(mAccountName)) { @@ -420,6 +430,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo if(mMenu != null) { 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(post.isSaved()) { saveItem.setVisible(true); @@ -428,8 +439,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo saveItem.setVisible(true); 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 { saveItem.setVisible(false); + hideItem.setVisible(false); } if(mPost.getAuthor().equals(mAccountName)) { @@ -630,6 +650,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo isRefreshing = false; if(mMenu != null) { 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(post.isSaved()) { saveItem.setVisible(true); @@ -638,8 +659,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo saveItem.setVisible(true); 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 { saveItem.setVisible(false); + hideItem.setVisible(false); } 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) { Toast.makeText(ViewPostDetailActivity.this, resId, Toast.LENGTH_SHORT).show(); } 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; if(mPost != null) { 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(mPost.isSaved()) { saveItem.setVisible(true); @@ -880,8 +911,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo saveItem.setVisible(true); 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 { saveItem.setVisible(false); + hideItem.setVisible(false); } if(mPost.getAuthor().equals(mAccountName)) { @@ -993,6 +1033,51 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo crosspostIntent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, mPost.getCrosspostParentId()); startActivity(crosspostIntent); 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: Intent editPostItent = new Intent(this, EditPostActivity.class); editPostItent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken); diff --git a/app/src/main/res/menu/view_post_detail_activity.xml b/app/src/main/res/menu/view_post_detail_activity.xml index 83888218..d971b154 100644 --- a/app/src/main/res/menu/view_post_detail_activity.xml +++ b/app/src/main/res/menu/view_post_detail_activity.xml @@ -29,34 +29,40 @@ android:visible="false" /> <item - android:id="@+id/action_edit_view_post_detail_activity" + android:id="@+id/action_hide_view_post_detail_activity" 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" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_delete_view_post_detail_activity" - android:orderInCategory="6" + android:orderInCategory="7" android:title="@string/action_delete_post" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_nsfw_view_post_detail_activity" - android:orderInCategory="7" + android:orderInCategory="8" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_spoiler_view_post_detail_activity" - android:orderInCategory="8" + android:orderInCategory="9" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_edit_flair_view_post_detail_activity" - android:orderInCategory="9" + android:orderInCategory="10" android:title="@string/action_edit_flair" app:showAsAction="never" android:visible="false" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4d561b3..900c8750 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,6 +30,8 @@ <string name="action_stop_lazy_mode">Stop Lazy Mode</string> <string name="action_send">Send</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_delete_post">Delete Post</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_unsaved_success">Post unsaved</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_comment">Delete This Comment</string> <string name="are_you_sure">Are you sure?</string> |