diff options
Diffstat (limited to 'app/src/main/java')
7 files changed, 160 insertions, 5 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..66c92a02 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java @@ -0,0 +1,10 @@ +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); +} 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..bf01f564 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,8 @@ 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.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 +162,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Named("no_oauth") Retrofit mRetrofit; @Inject + @Named("pushshift") + Retrofit pushshiftRetrofit; + @Inject @Named("oauth") Retrofit mOauthRetrofit; @Inject @@ -1144,6 +1148,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; @@ -1537,7 +1559,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..f52a6b69 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,10 @@ 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..bfdb0b0f 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,17 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag dismiss(); }); + if (commentData.getCommentRawText().equals("[removed]")) { + 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..4ff9e2d5 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java @@ -0,0 +1,95 @@ +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) { + 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(); + } + 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/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 = ""; |