diff options
Diffstat (limited to 'app/src/main/java')
7 files changed, 0 insertions, 474 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 1d0919d4..9bf59eac 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -428,15 +428,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } - public void showRemovedComment(Comment comment, int position) { - if (sectionsPagerAdapter != null) { - ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); - if (fragment != null) { - fragment.showRemovedComment(comment, position); - } - } - } - public void saveComment(@NonNull Comment comment, int position) { if (comment.isSaved()) { comment.setSaved(false); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 4978bdbd..53bb5d57 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -1038,24 +1038,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } } - public void editComment(Comment fetchedComment, Comment originalComment, int position) { - if (position >= mVisibleComments.size() || !mVisibleComments.get(position).equals(originalComment)) { - position = mVisibleComments.indexOf(originalComment); - if (position < 0) { - Toast.makeText(mActivity, R.string.show_removed_comment_failed, Toast.LENGTH_SHORT).show(); - return; - } - } - mVisibleComments.get(position).setSubmittedByAuthor(originalComment.isSubmitter()); - mVisibleComments.get(position).setCommentMarkdown(fetchedComment.getCommentMarkdown()); - - if (mIsSingleCommentThreadMode) { - notifyItemChanged(position + 1); - } else { - notifyItemChanged(position); - } - } - public void deleteComment(int position) { if (mVisibleComments != null && position >= 0 && position < mVisibleComments.size()) { if (mVisibleComments.get(position).hasReply()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java index 59345840..bd8b992f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java @@ -171,20 +171,6 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott dismiss(); }); - if ("[deleted]".equals(comment.getAuthor()) || - "[deleted]".equals(comment.getCommentRawText()) || - "[removed]".equals(comment.getCommentRawText()) - ) { - binding.seeRemovedViewCommentMoreBottomSheetFragment.setVisibility(View.VISIBLE); - - binding.seeRemovedViewCommentMoreBottomSheetFragment.setOnClickListener(view -> { - dismiss(); - if (activity instanceof ViewPostDetailActivity) { - ((ViewPostDetailActivity) activity).showRemovedComment(comment, bundle.getInt(EXTRA_POSITION)); - } - }); - } - binding.addToCommentFilterViewCommentMoreBottomSheetFragment.setOnClickListener(view -> { Intent intent = new Intent(activity, CommentFilterPreferenceActivity.class); intent.putExtra(CommentFilterPreferenceActivity.EXTRA_COMMENT, comment); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java deleted file mode 100644 index 24ab8d54..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java +++ /dev/null @@ -1,131 +0,0 @@ -package ml.docilealligator.infinityforreddit.comment; - -import android.os.Handler; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.concurrent.Executor; - -import ml.docilealligator.infinityforreddit.apis.PushshiftAPI; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import ml.docilealligator.infinityforreddit.utils.Utils; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class FetchRemovedComment { - - public static void fetchRemovedComment(Executor executor, Handler handler, Retrofit retrofit, Comment comment, - FetchRemovedCommentListener listener) { - executor.execute(() -> { - try { - Response<String> response = retrofit.create(PushshiftAPI.class).getRemovedComment(comment.getId()).execute(); - if (response.isSuccessful()) { - Comment removedComment = parseComment(response.body(), comment); - handler.post(() -> { - if (removedComment != null) { - listener.fetchSuccess(removedComment, comment); - } else { - listener.fetchFailed(); - } - }); - } else { - handler.post(listener::fetchFailed); - } - } catch (IOException e) { - e.printStackTrace(); - handler.post(listener::fetchFailed); - } - }); - } - - // At the moment of writing this code, directly fetching a removed comment from - // Pushift.io API returns an Internal Server Error, so we temporarily do it this way instead. - // If this fails to return the removed comment, we try our luck with Reveddit API - public static void searchRemovedComment(Executor executor, Handler handler, Retrofit retrofit, Comment comment, - FetchRemovedCommentListener listener) { - executor.execute(() -> { - long after = (comment.getCommentTimeMillis() / 1000) - 1; // 1 second before comment creation epoch - try { - Response<String> response = retrofit.create(PushshiftAPI.class).searchComments( - comment.getLinkId(), - 1000, - "id", - "id,author,body,is_submitter", - after, - after + 43200, // 12 Hours later - "*").execute(); - if (response.isSuccessful()) { - Comment removedComment = parseComment(response.body(), comment); - handler.post(() -> { - if (removedComment != null) { - listener.fetchSuccess(removedComment, comment); - } else { - listener.fetchFailed(); - } - }); - } else { - handler.post(listener::fetchFailed); - } - } catch (IOException e) { - e.printStackTrace(); - handler.post(listener::fetchFailed); - } - }); - } - - @Nullable - private static Comment parseComment(String responseBody, Comment comment) { - try { - JSONArray commentJSONArray = new JSONObject(responseBody).getJSONArray(JSONUtils.DATA_KEY); - JSONObject commentFound = null; - for (int i = 0; i < commentJSONArray.length(); i++) { - JSONObject commentJSON = commentJSONArray.getJSONObject(i); - if (!commentJSON.isNull("id") && commentJSON.getString("id").equals(comment.getId())) { - commentFound = commentJSON; - break; - } - } - if (commentFound == null) { - return null; - } - - return parseRemovedComment(commentFound, comment); - } catch (JSONException e) { - e.printStackTrace(); - return null; - } - } - - @Nullable - private static Comment parseRemovedComment(@NonNull JSONObject result, Comment comment) throws JSONException { - String id = result.getString(JSONUtils.ID_KEY); - String author = result.getString(JSONUtils.AUTHOR_KEY); - String body = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(result.optString(JSONUtils.BODY_KEY))); - boolean isSubmitter = result.getBoolean(JSONUtils.IS_SUBMITTER_KEY); - - if (id.equals(comment.getId()) && - (!author.equals(comment.getAuthor()) || - !body.equals(comment.getCommentRawText())) - ) { - comment.setAuthor(author); - comment.setCommentMarkdown(body); - comment.setCommentRawText(body); - comment.setSubmittedByAuthor(isSubmitter); - return comment; - } else { - return null; - } - } - - public interface FetchRemovedCommentListener { - void fetchSuccess(Comment fetchedComment, Comment originalComment); - - void fetchFailed(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java deleted file mode 100644 index ec7beea8..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java +++ /dev/null @@ -1,78 +0,0 @@ -package ml.docilealligator.infinityforreddit.comment; - -import android.os.Handler; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.concurrent.Executor; - -import ml.docilealligator.infinityforreddit.apis.RevedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import ml.docilealligator.infinityforreddit.utils.Utils; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class FetchRemovedCommentReveddit { - - public static void fetchRemovedComment(Executor executor, Handler handler, Retrofit retrofit, Comment comment, - long postCreatedUtc, int nComments, FetchRemovedCommentListener listener) { - executor.execute(() -> { - String parentIdWithoutPrefix = comment.getParentId().substring(3); - String rootCommentId = parentIdWithoutPrefix.equals(comment.getLinkId()) ? comment.getId() : parentIdWithoutPrefix; - try { - Response<String> response = retrofit.create(RevedditAPI.class).getRemovedComments( - APIUtils.getRevedditHeader(), - comment.getLinkId(), - (comment.getCommentTimeMillis() / 1000) - 1, - rootCommentId, - comment.getId(), - nComments, - postCreatedUtc / 1000, - true).execute(); - if (response.isSuccessful()) { - Comment removedComment = parseRemovedComment(new JSONObject(response.body()).getJSONObject(comment.getId()), comment); - handler.post(() -> { - if (removedComment != null) { - listener.fetchSuccess(removedComment, comment); - } else { - listener.fetchFailed(); - } - }); - } else { - handler.post(listener::fetchFailed); - } - } catch (IOException | JSONException e) { - e.printStackTrace(); - handler.post(listener::fetchFailed); - } - }); - } - - private static Comment parseRemovedComment(JSONObject result, Comment comment) throws JSONException { - String id = result.getString(JSONUtils.ID_KEY); - String author = result.getString(JSONUtils.AUTHOR_KEY); - String body = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(result.optString(JSONUtils.BODY_KEY))); - - if (id.equals(comment.getId()) && (!author.equals(comment.getAuthor()) || !body.equals(comment.getCommentRawText()))) { - comment.setAuthor(author); - comment.setCommentMarkdown(body); - comment.setCommentRawText(body); - if (result.has(JSONUtils.IS_SUBMITTER_KEY)) { - // This doesn't seem to be present for the Reveddit API anymore... - comment.setSubmittedByAuthor(result.getBoolean(JSONUtils.IS_SUBMITTER_KEY)); - } - return comment; - } else { - return null; - } - } - - public interface FetchRemovedCommentListener { - void fetchSuccess(Comment fetchedComment, Comment originalComment); - - void fetchFailed(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 249364f0..4a712ee0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -91,8 +91,6 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomShee import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostCommentSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.comment.Comment; import ml.docilealligator.infinityforreddit.comment.FetchComment; -import ml.docilealligator.infinityforreddit.comment.FetchRemovedComment; -import ml.docilealligator.infinityforreddit.comment.FetchRemovedCommentReveddit; import ml.docilealligator.infinityforreddit.comment.ParseComment; import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; import ml.docilealligator.infinityforreddit.commentfilter.FetchCommentFilter; @@ -107,7 +105,6 @@ import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFr import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostList; import ml.docilealligator.infinityforreddit.message.ReadMessage; import ml.docilealligator.infinityforreddit.post.FetchPost; -import ml.docilealligator.infinityforreddit.post.FetchRemovedPost; import ml.docilealligator.infinityforreddit.post.HidePost; import ml.docilealligator.infinityforreddit.post.ParsePost; import ml.docilealligator.infinityforreddit.post.Post; @@ -726,13 +723,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_fragment).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_fragment).setVisible(true); - } } } @@ -1138,9 +1128,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic intent.putExtra(ReportActivity.EXTRA_THING_FULLNAME, mPost.getFullName()); startActivity(intent); return true; - } else if (itemId == R.id.action_see_removed_view_post_detail_fragment) { - showRemovedPost(); - return true; } else if (itemId == R.id.action_crosspost_view_post_detail_fragment) { Intent submitCrosspostIntent = new Intent(activity, SubmitCrosspostActivity.class); submitCrosspostIntent.putExtra(SubmitCrosspostActivity.EXTRA_POST, mPost); @@ -1821,36 +1808,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic .show(); } - public void showRemovedComment(Comment comment, int position) { - Toast.makeText(activity, R.string.fetching_removed_comment, Toast.LENGTH_SHORT).show(); - FetchRemovedComment.fetchRemovedComment( - mExecutor, new Handler(), pushshiftRetrofit, comment, - new FetchRemovedComment.FetchRemovedCommentListener() { - @Override - public void fetchSuccess(Comment fetchedComment, Comment originalComment) { - mCommentsAdapter.editComment(fetchedComment, originalComment, position); - } - - @Override - public void fetchFailed() { - // Reveddit fallback - FetchRemovedCommentReveddit.fetchRemovedComment(mExecutor, new Handler(), revedditRetrofit, - comment, mPost.getPostTimeMillis(), mPost.getNComments(), - new FetchRemovedCommentReveddit.FetchRemovedCommentListener() { - @Override - public void fetchSuccess(Comment fetchedComment, Comment originalComment) { - mCommentsAdapter.editComment(fetchedComment, originalComment, position); - } - - @Override - public void fetchFailed() { - Toast.makeText(activity, R.string.show_removed_comment_failed, Toast.LENGTH_SHORT).show(); - } - }); - } - }); - } - public void changeToNormalThreadMode() { isSingleCommentThreadMode = false; mSingleCommentId = null; @@ -1892,28 +1849,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic TransitionManager.beginDelayedTransition((mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView), new AutoTransition()); } - public void showRemovedPost() { - Toast.makeText(activity, R.string.fetching_removed_post, Toast.LENGTH_SHORT).show(); - FetchRemovedPost.fetchRemovedPost( - pushshiftRetrofit, - mPost, - new FetchRemovedPost.FetchRemovedPostListener() { - @Override - public void fetchSuccess(Post post) { - mPost = post; - tryMarkingPostAsRead(); - if (mPostAdapter != null) { - mPostAdapter.updatePost(post); - } - } - - @Override - public void fetchFailed() { - Toast.makeText(activity, R.string.show_removed_post_failed, Toast.LENGTH_SHORT).show(); - } - }); - } - public boolean getIsNsfwSubreddit() { if (activity != null) { return activity.isNsfwSubreddit(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java deleted file mode 100644 index 5d815e83..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java +++ /dev/null @@ -1,159 +0,0 @@ -package ml.docilealligator.infinityforreddit.post; - -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 java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.apis.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 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 result, Post post) throws JSONException { - String id = result.getString(JSONUtils.ID_KEY); - String author = result.getString(JSONUtils.AUTHOR_KEY); - String title = result.getString(JSONUtils.TITLE_KEY); - String body = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(result.getString(JSONUtils.SELFTEXT_KEY))); - - if ( id.equals(post.getId()) && - (!author.equals(post.getAuthor()) || - foundSelfText(post.getSelfText(), body)) - ) { - post.setAuthor(author); - post.setTitle(title); - post.setSelfText(body); - post.setSelfTextPlain(""); - post.setSelfTextPlainTrimmed(""); - - String url = result.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 = result.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("redgifs.com")) { - post.setPostType(Post.LINK_TYPE); - post.setUrl(url); - } - } catch (IllegalArgumentException ignore) { - } - } - - if (!result.isNull("thumbnail")) { - ArrayList<Post.Preview> previews = post.getPreviews(); - if (previews != null && !previews.isEmpty()) { - if (previews.size() >= 2) { - Post.Preview preview = previews.get(1); - preview.setPreviewUrl(result.getString("thumbnail")); - previews.set(1, preview); - } else { - Post.Preview preview = previews.get(0); - preview.setPreviewUrl(result.getString("thumbnail")); - previews.set(0, preview); - } - } else { - Post.Preview preview = new Post.Preview(result.getString("thumbnail"), 1, 1, "", ""); - preview.setPreviewUrl(result.getString("thumbnail")); - ArrayList<Post.Preview> newPreviews = new ArrayList<>(); - newPreviews.add(preview); - post.setPreviews(newPreviews); - } - } - - return post; - } else { - return null; - } - } - - private static boolean foundSelfText(String oldText, String newText) { - return !(newText.equals("[deleted]") || newText.equals("[removed]")) && - !newText.equals(oldText); - } - - public interface FetchRemovedPostListener { - void fetchSuccess(Post post); - - void fetchFailed(); - } - - private static class ParsePostAsyncTask extends AsyncTask<Void, Void, Void> { - - private final String responseBody; - private final 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(); - } - } -} |