mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Implement option to see removed comment.
This commit is contained in:
parent
66f4db6b40
commit
4a1bed82d7
@ -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);
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -130,6 +130,16 @@ class AppModule {
|
||||
.build();
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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 = "";
|
||||
|
@ -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>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
@ -276,6 +276,10 @@
|
||||
<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="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="cancel">Cancel</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="edit_success">Edit successful</string>
|
||||
|
Loading…
Reference in New Issue
Block a user