Skip to content

Commit

Permalink
Hiding and unhiding posts are now available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Docile-Alligator committed Sep 8, 2019
1 parent 010a230 commit 5dbe271
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 46 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private static Post parseBasicData(JSONObject data, Locale locale) throws JSONEx
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);
Expand Down Expand Up @@ -204,24 +205,24 @@ private static Post parseBasicData(JSONObject data, Locale locale) throws JSONEx
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);
}
}

private static Post parseData(JSONObject data, String permalink, String id, String fullName,
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);
Expand All @@ -232,7 +233,7 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
//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("");
Expand All @@ -243,8 +244,8 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
//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 {
Expand All @@ -264,8 +265,8 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
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);
Expand All @@ -279,9 +280,10 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
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);
Expand All @@ -293,9 +295,10 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
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);
Expand All @@ -305,9 +308,10 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
//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);
Expand All @@ -316,9 +320,10 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
//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);
Expand All @@ -332,9 +337,10 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
//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 {
Expand All @@ -351,18 +357,20 @@ private static Post parseData(JSONObject data, String permalink, String id, Stri
//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);
}
}
}
Expand Down
27 changes: 21 additions & 6 deletions app/src/main/java/ml/docilealligator/infinityforreddit/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -159,6 +164,7 @@ protected Post(Parcel in) {
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;
Expand Down Expand Up @@ -319,6 +325,14 @@ int getPreviewHeight() {
return previewHeight;
}

boolean isHidden() {
return hidden;
}

void setHidden(boolean hidden) {
this.hidden = hidden;
}

boolean isSpoiler() {
return spoiler;
}
Expand Down Expand Up @@ -409,6 +423,7 @@ public void writeToParcel(Parcel parcel, int i) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ public void onPostUpdateEvent(PostUpdateEventToPostList event) {
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());
Expand Down
Loading

0 comments on commit 5dbe271

Please sign in to comment.