mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 03:18:24 +01:00
Edit comments
This comments adds functionality to edit comments. Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
parent
5b26d57fdb
commit
388b895499
@ -32,8 +32,6 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -43,15 +41,16 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import eu.toldi.infinityforlemmy.Infinity;
|
import eu.toldi.infinityforlemmy.Infinity;
|
||||||
import eu.toldi.infinityforlemmy.R;
|
import eu.toldi.infinityforlemmy.R;
|
||||||
|
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
||||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||||
|
import eu.toldi.infinityforlemmy.dto.EditCommentDTO;
|
||||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -84,8 +83,8 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
|||||||
@BindView(R.id.markdown_bottom_bar_recycler_view_edit_comment_activity)
|
@BindView(R.id.markdown_bottom_bar_recycler_view_edit_comment_activity)
|
||||||
RecyclerView markdownBottomBarRecyclerView;
|
RecyclerView markdownBottomBarRecyclerView;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("oauth")
|
@Named("no_oauth")
|
||||||
Retrofit mOauthRetrofit;
|
RetrofitHolder retrofit;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("upload_media")
|
@Named("upload_media")
|
||||||
Retrofit mUploadMediaRetrofit;
|
Retrofit mUploadMediaRetrofit;
|
||||||
@ -99,7 +98,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
|||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private String mFullName;
|
private int mCommentId;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mCommentContent;
|
private String mCommentContent;
|
||||||
private boolean isSubmitting = false;
|
private boolean isSubmitting = false;
|
||||||
@ -129,7 +128,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
mFullName = getIntent().getStringExtra(EXTRA_FULLNAME);
|
mCommentId = getIntent().getIntExtra(EXTRA_FULLNAME, 0);
|
||||||
|
if (mCommentId == 0) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT);
|
mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT);
|
||||||
contentEditText.setText(mCommentContent);
|
contentEditText.setText(mCommentContent);
|
||||||
@ -225,12 +227,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
|||||||
|
|
||||||
String content = contentEditText.getText().toString();
|
String content = contentEditText.getText().toString();
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
retrofit.getRetrofit().create(LemmyAPI.class).commentEdit(new EditCommentDTO(mCommentId, content, null, null, mAccessToken))
|
||||||
params.put(APIUtils.THING_ID_KEY, mFullName);
|
|
||||||
params.put(APIUtils.TEXT_KEY, content);
|
|
||||||
|
|
||||||
mOauthRetrofit.create(RedditAPI.class)
|
|
||||||
.editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
|
|
||||||
.enqueue(new Callback<String>() {
|
.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
@ -278,10 +275,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
|||||||
Toast.makeText(EditCommentActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
Toast.makeText(EditCommentActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
Utils.uploadImageToReddit(this, mExecutor, retrofit.getRetrofit(), mUploadMediaRetrofit,
|
||||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
Utils.uploadImageToReddit(this, mExecutor, retrofit.getRetrofit(), mUploadMediaRetrofit,
|
||||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||||
editComment();
|
editComment();
|
||||||
|
@ -5,6 +5,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||||||
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
|
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
|
||||||
import eu.toldi.infinityforlemmy.dto.CommentDTO;
|
import eu.toldi.infinityforlemmy.dto.CommentDTO;
|
||||||
import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
|
import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
|
||||||
|
import eu.toldi.infinityforlemmy.dto.EditCommentDTO;
|
||||||
import eu.toldi.infinityforlemmy.dto.FollowCommunityDTO;
|
import eu.toldi.infinityforlemmy.dto.FollowCommunityDTO;
|
||||||
import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
|
import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
|
||||||
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
||||||
@ -128,4 +129,8 @@ public interface LemmyAPI {
|
|||||||
@Headers("Content-Type: application/json")
|
@Headers("Content-Type: application/json")
|
||||||
@POST("api/v3/comment")
|
@POST("api/v3/comment")
|
||||||
Call<String> postComment(@Body CommentDTO params);
|
Call<String> postComment(@Body CommentDTO params);
|
||||||
|
|
||||||
|
@Headers("Content-Type: application/json")
|
||||||
|
@PUT("api/v3/comment")
|
||||||
|
Call<String> commentEdit(@Body EditCommentDTO params);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
|||||||
|
|
||||||
editTextView.setOnClickListener(view -> {
|
editTextView.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(activity, EditCommentActivity.class);
|
Intent intent = new Intent(activity, EditCommentActivity.class);
|
||||||
intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getFullName());
|
intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getId());
|
||||||
intent.putExtra(EditCommentActivity.EXTRA_CONTENT, comment.getCommentMarkdown());
|
intent.putExtra(EditCommentActivity.EXTRA_CONTENT, comment.getCommentMarkdown());
|
||||||
intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION));
|
intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION));
|
||||||
if (activity instanceof ViewPostDetailActivity) {
|
if (activity instanceof ViewPostDetailActivity) {
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package eu.toldi.infinityforlemmy.dto;
|
||||||
|
|
||||||
|
public class EditCommentDTO {
|
||||||
|
|
||||||
|
private int comment_id;
|
||||||
|
private String content;
|
||||||
|
private Integer language_id;
|
||||||
|
private String form_id;
|
||||||
|
private String auth;
|
||||||
|
|
||||||
|
public EditCommentDTO(int comment_id, String content, Integer language_id, String form_id, String auth) {
|
||||||
|
this.comment_id = comment_id;
|
||||||
|
this.content = content;
|
||||||
|
this.language_id = language_id;
|
||||||
|
this.form_id = form_id;
|
||||||
|
this.auth = auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getComment_id() {
|
||||||
|
return comment_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLanguage_id() {
|
||||||
|
return language_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getForm_id() {
|
||||||
|
return form_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuth() {
|
||||||
|
return auth;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user