diff options
author | Hermes Junior <ohermesjunior@gmail.com> | 2020-06-12 14:30:56 +0000 |
---|---|---|
committer | OHermesJunior <ohermesjunior@gmail.com> | 2020-06-16 17:29:14 +0000 |
commit | 1b972aca2eb20cd7895ba20f015ba480a7f2ade6 (patch) | |
tree | 201e1c515fcc5c939558e5dd9e95844fede62522 /app/src/main | |
parent | 99418267c44a6d3f3af54c7b24993347a863d5e4 (diff) | |
download | infinity-for-reddit-1b972aca2eb20cd7895ba20f015ba480a7f2ade6.tar infinity-for-reddit-1b972aca2eb20cd7895ba20f015ba480a7f2ade6.tar.gz infinity-for-reddit-1b972aca2eb20cd7895ba20f015ba480a7f2ade6.tar.bz2 infinity-for-reddit-1b972aca2eb20cd7895ba20f015ba480a7f2ade6.tar.lz infinity-for-reddit-1b972aca2eb20cd7895ba20f015ba480a7f2ade6.tar.xz infinity-for-reddit-1b972aca2eb20cd7895ba20f015ba480a7f2ade6.tar.zst infinity-for-reddit-1b972aca2eb20cd7895ba20f015ba480a7f2ade6.zip |
Implement option to see removed post.
Diffstat (limited to '')
8 files changed, 149 insertions, 3 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java index 66c92a02..1dc7b411 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java @@ -7,4 +7,7 @@ import retrofit2.http.Query; public interface PushshiftAPI { @GET("reddit/comment/search/") Call<String> getRemovedComment(@Query("ids") String commentId); + + @GET("reddit/submission/search/") + Call<String> getRemovedPost(@Query("ids") String postId); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index 8548b40e..9610d7c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -565,6 +565,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null); + + if (mPost.getSelfText().equals("[deleted]")) { + mMenu.findItem(R.id.action_see_removed_view_post_detail_activity).setVisible(true); + } } } @@ -1220,6 +1224,25 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS return true; } + public void showRemovedPost() { + Toast.makeText(ViewPostDetailActivity.this, R.string.fetching_removed_post, Toast.LENGTH_SHORT).show(); + FetchRemovedPost.fetchRemovedPost( + pushshiftRetrofit, + mPost, + new FetchRemovedPost.FetchRemovedPostListener() { + @Override + public void fetchSuccess(Post post) { + mPost = post; + mAdapter.updatePost(post); + } + + @Override + public void fetchFailed() { + Toast.makeText(ViewPostDetailActivity.this, R.string.show_removed_post_failed, Toast.LENGTH_SHORT).show(); + } + }); + } + @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { @@ -1408,6 +1431,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS intent.putExtra(ReportActivity.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName()); intent.putExtra(ReportActivity.EXTRA_THING_FULLNAME, mPost.getFullName()); startActivity(intent); + return true; + case R.id.action_see_removed_view_post_detail_activity: + showRemovedPost(); + return true; case android.R.id.home: onBackPressed(); return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index f52a6b69..41acea18 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1387,6 +1387,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy public void editComment(String commentAuthor, String commentContentMarkdown, int position) { if (commentAuthor != null) mVisibleComments.get(position).setAuthor(commentAuthor); + mVisibleComments.get(position).setCommentMarkdown(commentContentMarkdown); if (mIsSingleCommentThreadMode) { notifyItemChanged(position + 2); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java index 4ff9e2d5..e2db7aed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java @@ -31,6 +31,7 @@ public class FetchRemovedComment { @Override public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + t.printStackTrace(); listener.fetchFailed(); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java new file mode 100644 index 00000000..00a0f6a0 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java @@ -0,0 +1,100 @@ +package ml.docilealligator.infinityforreddit; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; + +import org.json.JSONException; +import org.json.JSONObject; + +import ml.docilealligator.infinityforreddit.API.PushshiftAPI; +import ml.docilealligator.infinityforreddit.Post.Post; +import ml.docilealligator.infinityforreddit.Utils.JSONUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class FetchRemovedPost { + + public static void fetchRemovedPost(Retrofit retrofit, Post post, FetchRemovedPostListener listener) { + retrofit.create(PushshiftAPI.class).getRemovedPost(post.getId()) + .enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if (response.isSuccessful()) { + new ParsePostAsyncTask(response.body(), post, listener).execute(); + } else { + listener.fetchFailed(); + } + } + + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + t.printStackTrace(); + listener.fetchFailed(); + } + }); + } + + private static Post parseRemovedPost(JSONObject postJson, Post post) throws JSONException { + String id = postJson.getString(JSONUtils.ID_KEY); + if (id.equals(post.getId())) { + String author = postJson.getString(JSONUtils.AUTHOR_KEY); + String title = postJson.getString(JSONUtils.TITLE_KEY); + String postContent = ""; + if (!postJson.isNull(JSONUtils.SELFTEXT_KEY)) { + postContent = Utils.modifyMarkdown(postJson.getString(JSONUtils.SELFTEXT_KEY).trim()); + } + + post.setAuthor(author); + post.setTitle(title); + post.setSelfText(postContent); + post.setSelfTextPlain(""); + post.setSelfTextPlainTrimmed(""); + return post; + } else { + return null; + } + } + + public interface FetchRemovedPostListener { + void fetchSuccess(Post post); + + void fetchFailed(); + } + + private static class ParsePostAsyncTask extends AsyncTask<Void, Void, Void> { + + private String responseBody; + private FetchRemovedPostListener listener; + Post post; + + public ParsePostAsyncTask(String responseBody, Post post, FetchRemovedPostListener listener) { + this.responseBody = responseBody; + this.post = post; + this.listener = listener; + } + + @Override + protected Void doInBackground(Void... voids) { + try { + JSONObject postJson = new JSONObject(responseBody).getJSONArray(JSONUtils.DATA_KEY).getJSONObject(0); + post = parseRemovedPost(postJson, post); + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (post != null) + listener.fetchSuccess(post); + else + listener.fetchFailed(); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java index a05a97f2..54e7ec7f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java @@ -252,6 +252,11 @@ public class Post implements Parcelable { return author; } + public void setAuthor(String author) { + this.author = author; + this.authorNamePrefixed = "u/" + author; + } + public String getAuthorNamePrefixed() { return authorNamePrefixed; } @@ -524,4 +529,4 @@ public class Post implements Parcelable { } return ((Post) obj).id.equals(id); } -}
\ No newline at end of file +} 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 32f83c41..29c49e1f 100644 --- a/app/src/main/res/menu/view_post_detail_activity.xml +++ b/app/src/main/res/menu/view_post_detail_activity.xml @@ -80,5 +80,12 @@ android:orderInCategory="12" android:title="@string/action_report" app:showAsAction="never" + android:visible="false"/> + + <item + android:id="@+id/action_see_removed_view_post_detail_activity" + android:orderInCategory="13" + android:title="@string/action_see_removed" + app:showAsAction="never" android:visible="false" /> -</menu>
\ No newline at end of file +</menu> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa9f039b..cddcf9bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -61,6 +61,7 @@ <string name="action_share">Share</string> <string name="action_preview">Preview</string> <string name="action_report">Report</string> + <string name="action_see_removed">See Removed</string> <string name="action_set_wallpaper">Set as Wallpaper</string> <string name="parse_json_response_error">Error occurred when parsing the JSON response</string> @@ -277,9 +278,10 @@ <string name="edit">Edit</string> <string name="delete">Delete</string> <string name="see_removed_comment">See Removed Comment</string> - <string name="see_removed_post">See Removed Post</string> <string name="fetching_removed_comment">Fetching removed comment</string> <string name="show_removed_comment_failed">Could not find the removed comment</string> + <string name="fetching_removed_post">Fetching removed post</string> + <string name="show_removed_post_failed">Could not find the removed post</string> <string name="cancel">Cancel</string> <string name="ok">OK</string> <string name="edit_success">Edit successful</string> |