aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java319
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java97
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java133
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java1
-rw-r--r--app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml21
-rw-r--r--app/src/main/res/menu/view_post_detail_activity.xml9
-rw-r--r--app/src/main/res/values/strings.xml6
12 files changed, 447 insertions, 197 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
new file mode 100644
index 00000000..1dc7b411
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java
@@ -0,0 +1,13 @@
+package ml.docilealligator.infinityforreddit.API;
+
+import retrofit2.Call;
+import retrofit2.http.GET;
+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 51a5beaa..81e1ba8a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -60,6 +60,8 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.FlairBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostCommentSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
@@ -71,9 +73,9 @@ import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivit
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchComment;
+import ml.docilealligator.infinityforreddit.FetchRemovedComment;
+import ml.docilealligator.infinityforreddit.FetchRemovedPost;
import ml.docilealligator.infinityforreddit.Flair;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.FlairBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostCommentSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.ParseComment;
import ml.docilealligator.infinityforreddit.Post.FetchPost;
@@ -161,6 +163,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
@Named("no_oauth")
Retrofit mRetrofit;
@Inject
+ @Named("pushshift")
+ Retrofit pushshiftRetrofit;
+ @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
@@ -449,63 +454,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
if (mPost == null) {
fetchPostAndCommentsById(getIntent().getStringExtra(EXTRA_POST_ID));
} 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);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (mPost.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (mPost.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- if (mPost.getAuthor().equals(mAccountName)) {
- if (mPost.getPostType() == Post.TEXT_TYPE) {
- mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
- }
- mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
-
- MenuItem nsfwItem = mMenu.findItem(R.id.action_nsfw_view_post_detail_activity);
- nsfwItem.setVisible(true);
- if (mPost.isNSFW()) {
- nsfwItem.setTitle(R.string.action_unmark_nsfw);
- } else {
- nsfwItem.setTitle(R.string.action_mark_nsfw);
- }
-
- MenuItem spoilerItem = mMenu.findItem(R.id.action_spoiler_view_post_detail_activity);
- spoilerItem.setVisible(true);
- if (mPost.isSpoiler()) {
- spoilerItem.setTitle(R.string.action_unmark_spoiler);
- } else {
- spoilerItem.setTitle(R.string.action_mark_spoiler);
- }
-
- mMenu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true);
- }
-
- mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
- }
+ setupMenu();
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
@@ -559,6 +508,73 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
fab.setOnClickListener(view -> scrollToNextParentComment());
}
+ private void setupMenu() {
+ 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);
+
+ mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
+ mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
+
+ if (mAccessToken != null) {
+ if (mPost.isSaved()) {
+ saveItem.setVisible(true);
+ saveItem.setIcon(mSavedIcon);
+ } else {
+ saveItem.setVisible(true);
+ saveItem.setIcon(mUnsavedIcon);
+ }
+
+ if (mPost.isHidden()) {
+ hideItem.setVisible(true);
+ hideItem.setTitle(R.string.action_unhide_post);
+ } else {
+ hideItem.setVisible(true);
+ hideItem.setTitle(R.string.action_hide_post);
+ }
+
+ mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
+ } else {
+ saveItem.setVisible(false);
+ hideItem.setVisible(false);
+ }
+
+ if (mPost.getAuthor().equals(mAccountName)) {
+ if (mPost.getPostType() == Post.TEXT_TYPE) {
+ mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
+ }
+ mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
+
+ MenuItem nsfwItem = mMenu.findItem(R.id.action_nsfw_view_post_detail_activity);
+ nsfwItem.setVisible(true);
+ if (mPost.isNSFW()) {
+ nsfwItem.setTitle(R.string.action_unmark_nsfw);
+ } else {
+ nsfwItem.setTitle(R.string.action_mark_nsfw);
+ }
+
+ MenuItem spoilerItem = mMenu.findItem(R.id.action_spoiler_view_post_detail_activity);
+ spoilerItem.setVisible(true);
+ if (mPost.isSpoiler()) {
+ spoilerItem.setTitle(R.string.action_unmark_spoiler);
+ } else {
+ spoilerItem.setTitle(R.string.action_mark_spoiler);
+ }
+
+ mMenu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true);
+ }
+
+ mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
+
+ if ("[deleted]".equals(mPost.getAuthor()) ||
+ "[deleted]".equals(mPost.getSelfText()) ||
+ "[removed]".equals(mPost.getSelfText())
+ ) {
+ mMenu.findItem(R.id.action_see_removed_view_post_detail_activity).setVisible(true);
+ }
+ }
+ }
+
private Drawable getMenuItemIcon(int drawableId) {
Drawable icon = getDrawable(drawableId);
if (icon != null) {
@@ -602,45 +618,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
public void onParsePostSuccess(Post post) {
mPost = post;
- 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);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (post.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (post.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- if (mPost.getAuthor().equals(mAccountName)) {
- if (mPost.getPostType() == Post.TEXT_TYPE) {
- mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
- }
- mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
- }
-
- mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
- }
+ setupMenu();
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
@@ -910,38 +888,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAdapter.updatePost(mPost);
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
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);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (post.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (post.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
- }
+ setupMenu();
mSwipeRefreshLayout.setRefreshing(false);
}
@@ -1144,6 +1091,24 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
.show();
}
+ public void showRemovedComment(CommentData comment, int position) {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.fetching_removed_comment, Toast.LENGTH_SHORT).show();
+ FetchRemovedComment.fetchRemovedComment(
+ pushshiftRetrofit,
+ comment,
+ new FetchRemovedComment.FetchRemovedCommentListener() {
+ @Override
+ public void fetchSuccess(CommentData comment) {
+ mAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
+ }
+
+ @Override
+ public void fetchFailed() {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.show_removed_comment_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
public void changeToSingleThreadMode() {
isSingleCommentThreadMode = false;
mSingleCommentId = null;
@@ -1257,65 +1222,30 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
applyMenuItemTheme(menu);
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);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (mPost.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (mPost.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- if (mPost.getAuthor().equals(mAccountName)) {
- if (mPost.getPostType() == Post.TEXT_TYPE) {
- menu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
- }
- menu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
-
- MenuItem nsfwItem = menu.findItem(R.id.action_nsfw_view_post_detail_activity);
- nsfwItem.setVisible(true);
- if (mPost.isNSFW()) {
- nsfwItem.setTitle(R.string.action_unmark_nsfw);
- } else {
- nsfwItem.setTitle(R.string.action_mark_nsfw);
- }
-
- MenuItem spoilerItem = menu.findItem(R.id.action_spoiler_view_post_detail_activity);
- spoilerItem.setVisible(true);
- if (mPost.isSpoiler()) {
- spoilerItem.setTitle(R.string.action_unmark_spoiler);
- } else {
- spoilerItem.setTitle(R.string.action_mark_spoiler);
- }
-
- menu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true);
- }
-
- menu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
+ setupMenu();
}
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()) {
@@ -1450,12 +1380,12 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
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);
- editPostItent.putExtra(EditPostActivity.EXTRA_FULLNAME, mPost.getFullName());
- editPostItent.putExtra(EditPostActivity.EXTRA_TITLE, mPost.getTitle());
- editPostItent.putExtra(EditPostActivity.EXTRA_CONTENT, mPost.getSelfText());
- startActivityForResult(editPostItent, EDIT_POST_REQUEST_CODE);
+ Intent editPostIntent = new Intent(this, EditPostActivity.class);
+ editPostIntent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken);
+ editPostIntent.putExtra(EditPostActivity.EXTRA_FULLNAME, mPost.getFullName());
+ editPostIntent.putExtra(EditPostActivity.EXTRA_TITLE, mPost.getTitle());
+ editPostIntent.putExtra(EditPostActivity.EXTRA_CONTENT, mPost.getSelfText());
+ startActivityForResult(editPostIntent, EDIT_POST_REQUEST_CODE);
return true;
case R.id.action_delete_view_post_detail_activity:
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
@@ -1504,6 +1434,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;
@@ -1537,7 +1471,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
} else if (requestCode == EDIT_COMMENT_REQUEST_CODE) {
if (data != null && resultCode == RESULT_OK) {
- mAdapter.editComment(data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
+ mAdapter.editComment(null,
+ data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
data.getExtras().getInt(EditCommentActivity.EXTRA_EDITED_COMMENT_POSITION));
}
}
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 0510fae6..41acea18 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -1384,8 +1384,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
}
- public void editComment(String commentContent, int position) {
- mVisibleComments.get(position).setCommentMarkdown(commentContent);
+ 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);
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index f4f32b20..d70a167d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -131,6 +131,16 @@ class AppModule {
}
@Provides
+ @Named("pushshift")
+ @Singleton
+ Retrofit providePushshiftRetrofit() {
+ return new Retrofit.Builder()
+ .baseUrl(APIUtils.PUSHSHIFT_API_BASE_URI)
+ .addConverterFactory(ScalarsConverterFactory.create())
+ .build();
+ }
+
+ @Provides
@Singleton
OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) {
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java
index 364096e6..de4f5778 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java
@@ -47,7 +47,10 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag
TextView copyTextView;
@BindView(R.id.report_view_comment_more_bottom_sheet_fragment)
TextView reportTextView;
+ @BindView(R.id.see_removed_view_comment_more_bottom_sheet_fragment)
+ TextView seeRemovedTextView;
private AppCompatActivity activity;
+
public CommentMoreBottomSheetFragment() {
// Required empty public constructor
}
@@ -131,6 +134,20 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag
dismiss();
});
+ if ("[deleted]".equals(commentData.getAuthor()) ||
+ "[deleted]".equals(commentData.getCommentRawText()) ||
+ "[removed]".equals(commentData.getCommentRawText())
+ ) {
+ seeRemovedTextView.setVisibility(View.VISIBLE);
+
+ seeRemovedTextView.setOnClickListener(view -> {
+ dismiss();
+ if (activity instanceof ViewPostDetailActivity) {
+ ((ViewPostDetailActivity) activity).showRemovedComment(commentData, bundle.getInt(EXTRA_POSITION));
+ }
+ });
+ }
+
return rootView;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java
new file mode 100644
index 00000000..6e18e927
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java
@@ -0,0 +1,97 @@
+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.Utils.JSONUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class FetchRemovedComment {
+
+ public static void fetchRemovedComment(Retrofit retrofit, CommentData comment, FetchRemovedCommentListener listener) {
+ retrofit.create(PushshiftAPI.class).getRemovedComment(comment.getId())
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ new ParseCommentAsyncTask(response.body(), comment, listener).execute();
+ } else {
+ listener.fetchFailed();
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ t.printStackTrace();
+ listener.fetchFailed();
+ }
+ });
+ }
+
+ private static CommentData parseRemovedComment(JSONObject comment, CommentData commentData) throws JSONException {
+ String id = comment.getString(JSONUtils.ID_KEY);
+ if (id.equals(commentData.getId())) {
+ String author = comment.getString(JSONUtils.AUTHOR_KEY);
+ String commentMarkdown = "";
+ if (!comment.isNull(JSONUtils.BODY_KEY)) {
+ commentMarkdown = Utils.modifyMarkdown(comment.getString(JSONUtils.BODY_KEY).trim());
+ }
+
+ commentData.setAuthor(author);
+ commentData.setCommentMarkdown(commentMarkdown);
+ commentData.setCommentRawText(commentMarkdown);
+ return commentData;
+ } else {
+ return null;
+ }
+ }
+
+ public interface FetchRemovedCommentListener {
+ void fetchSuccess(CommentData comment);
+
+ void fetchFailed();
+ }
+
+ private static class ParseCommentAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ private String responseBody;
+ private FetchRemovedCommentListener listener;
+ CommentData comment;
+
+ public ParseCommentAsyncTask(String responseBody, CommentData comment, FetchRemovedCommentListener listener) {
+ this.responseBody = responseBody;
+ this.comment = comment;
+ this.listener = listener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ try {
+ JSONObject commentJSON = new JSONObject(responseBody).getJSONArray(JSONUtils.DATA_KEY).getJSONObject(0);
+ comment = parseRemovedComment(commentJSON, comment);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ comment = null;
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ if (comment != null)
+ listener.fetchSuccess(comment);
+ else
+ 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..2a8076a9
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java
@@ -0,0 +1,133 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.text.Html;
+
+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 = Utils.modifyMarkdown(postJson.getString(JSONUtils.SELFTEXT_KEY).trim());
+
+ post.setAuthor(author);
+ post.setTitle(title);
+ post.setSelfText(postContent);
+ post.setSelfTextPlain("");
+ post.setSelfTextPlainTrimmed("");
+
+ String url = postJson.optString(JSONUtils.URL_KEY);
+
+ if (url.endsWith("gif") || url.endsWith("mp4")) {
+ post.setVideoUrl(url);
+ post.setVideoDownloadUrl(url);
+ } else if (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) {
+ JSONObject redditVideoObject = postJson.getJSONObject("secure_media").getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
+ String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString();
+ String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
+
+ post.setVideoUrl(videoUrl);
+ post.setVideoDownloadUrl(videoDownloadUrl);
+ } else if (post.getPostType() == Post.LINK_TYPE) {
+ post.setUrl(url);
+ }
+
+ if (post.getPostType() == Post.VIDEO_TYPE) {
+ try {
+ Uri uri = Uri.parse(url);
+ String authority = uri.getAuthority();
+ if (authority != null && (authority.contains("gfycat.com") || authority.contains("redgifs.com"))) {
+ post.setPostType(Post.LINK_TYPE);
+ post.setUrl(url);
+ }
+ } catch (IllegalArgumentException ignore) {
+ }
+ }
+
+ if (!postJson.isNull("thumbnail")) {
+ post.setThumbnailPreviewUrl(postJson.getString("thumbnail"));
+ }
+
+ 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();
+ post = null;
+ }
+ 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..5a60bbdd 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;
}
@@ -320,6 +325,10 @@ public class Post implements Parcelable {
return thumbnailPreviewUrl;
}
+ public void setThumbnailPreviewUrl(String thumbnailPreviewUrl) {
+ this.thumbnailPreviewUrl = thumbnailPreviewUrl;
+ }
+
public String getUrl() {
return url;
}
@@ -524,4 +533,4 @@ public class Post implements Parcelable {
}
return ((Post) obj).id.equals(id);
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
index c080bdd4..7f49deee 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
@@ -21,6 +21,7 @@ public class APIUtils {
public static final String GFYCAT_API_BASE_URI = "https://api.gfycat.com/v1/gfycats/";
public static final String REDGIFS_API_BASE_URI = "https://api.redgifs.com/v1/gfycats/";
public static final String IMGUR_API_BASE_URI = "https://api.imgur.com/3/";
+ public static final String PUSHSHIFT_API_BASE_URI = "https://api.pushshift.io/";
public static final String CLIENT_ID_KEY = "client_id";
public static final String CLIENT_ID = "";
diff --git a/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml b/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml
index db9fadd9..c1126a2d 100644
--- a/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml
+++ b/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml
@@ -104,6 +104,25 @@
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" />
+ <TextView
+ android:id="@+id/see_removed_view_comment_more_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="?attr/selectableItemBackground"
+ android:clickable="true"
+ android:drawableStart="@drawable/ic_preview_24dp"
+ android:drawablePadding="48dp"
+ android:focusable="true"
+ android:gravity="center_vertical"
+ android:paddingStart="32dp"
+ android:paddingTop="16dp"
+ android:paddingEnd="32dp"
+ android:paddingBottom="16dp"
+ android:text="@string/see_removed_comment"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:visibility="gone" />
+
</LinearLayout>
-</androidx.core.widget.NestedScrollView> \ No newline at end of file
+</androidx.core.widget.NestedScrollView>
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 7adda6a6..53f28bc9 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>
@@ -276,6 +277,11 @@
<string name="are_you_sure">Are you sure?</string>
<string name="edit">Edit</string>
<string name="delete">Delete</string>
+ <string name="see_removed_comment">See Removed Comment</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>