mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-08-18 02:51:58 +00:00
Fix issues in saving comments using CommentMoreBottomSheetFragment in ViewPostDetailFragmentNew.
This commit is contained in:
@ -70,7 +70,6 @@ import ml.docilealligator.infinityforreddit.post.PostType;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPostType;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPostsListInterface;
|
||||
import ml.docilealligator.infinityforreddit.thing.SaveThing;
|
||||
import ml.docilealligator.infinityforreddit.thing.SortType;
|
||||
import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback;
|
||||
import ml.docilealligator.infinityforreddit.user.UserProfileImagesBatchLoader;
|
||||
@ -531,7 +530,11 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
|
||||
public void saveComment(@NonNull Comment comment, int position) {
|
||||
if (comment.isSaved()) {
|
||||
ViewPostDetailFragmentNew fragment = mSectionsPagerAdapter.getCurrentFragment();
|
||||
if (fragment != null) {
|
||||
fragment.toggleSaveComment(comment, position);
|
||||
}
|
||||
/*if (comment.isSaved()) {
|
||||
comment.setSaved(false);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, accessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
@ -573,7 +576,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
Toast.makeText(ViewPostDetailActivity.this, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public boolean toggleSearchPanelVisibility() {
|
||||
|
||||
@ -1518,9 +1518,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getBindingAdapterPosition());
|
||||
}
|
||||
bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_IS_NSFW, mPost.isNSFW());
|
||||
if (comment.getDepth() >= mDepthThreshold) {
|
||||
bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_SHOW_REPLY_AND_SAVE_OPTION, true);
|
||||
}
|
||||
bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_SHOW_REPLY_OPTION, true);
|
||||
CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment();
|
||||
commentMoreBottomSheetFragment.setArguments(bundle);
|
||||
commentMoreBottomSheetFragment.show(mFragment.getChildFragmentManager(), commentMoreBottomSheetFragment.getTag());
|
||||
|
||||
@ -745,13 +745,6 @@ public class CommentsRecyclerViewAdapterNew extends ListAdapter<Comment, Recycle
|
||||
}
|
||||
}
|
||||
|
||||
public void setSaveComment(int position, boolean isSaved) {
|
||||
Comment comment = getItem(position);
|
||||
if (comment != null) {
|
||||
comment.setSaved(isSaved);
|
||||
}
|
||||
}
|
||||
|
||||
public int getSearchedPosition() {
|
||||
return mSearchedPosition;
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
public static final String EXTRA_COMMENT = "ECF";
|
||||
public static final String EXTRA_EDIT_AND_DELETE_AVAILABLE = "EEADA";
|
||||
public static final String EXTRA_POSITION = "EP";
|
||||
public static final String EXTRA_SHOW_REPLY_AND_SAVE_OPTION = "ESSARO";
|
||||
public static final String EXTRA_SHOW_REPLY_OPTION = "ESRO";
|
||||
public static final String EXTRA_IS_NSFW = "EIN";
|
||||
|
||||
private BaseActivity activity;
|
||||
@ -74,8 +74,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
return binding.getRoot();
|
||||
}
|
||||
boolean editAndDeleteAvailable = bundle.getBoolean(EXTRA_EDIT_AND_DELETE_AVAILABLE, false);
|
||||
//boolean showReplyAndSaveOption = bundle.getBoolean(EXTRA_SHOW_REPLY_AND_SAVE_OPTION, false);
|
||||
boolean showReplyAndSaveOption = true;
|
||||
boolean showReplyOption = bundle.getBoolean(EXTRA_SHOW_REPLY_OPTION, false);
|
||||
|
||||
if (!activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) && !"".equals(activity.accessToken)) {
|
||||
if (editAndDeleteAvailable) {
|
||||
@ -129,7 +128,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
});
|
||||
}
|
||||
|
||||
if (showReplyAndSaveOption) {
|
||||
if (showReplyOption) {
|
||||
if (!comment.isLocked()) {
|
||||
binding.replyTextViewCommentMoreBottomSheetFragment.setVisibility(View.VISIBLE);
|
||||
binding.replyTextViewCommentMoreBottomSheetFragment.setOnClickListener(view -> {
|
||||
@ -146,23 +145,24 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setVisibility(View.VISIBLE);
|
||||
if (comment.isSaved()) {
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(activity, R.drawable.ic_bookmark_day_night_24dp), null, null, null);
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setText(R.string.unsave_comment);
|
||||
} else {
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(activity, R.drawable.ic_bookmark_border_day_night_24dp), null, null, null);
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setText(R.string.save_comment);
|
||||
}
|
||||
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setOnClickListener(view -> {
|
||||
if (activity instanceof ViewPostDetailActivity) {
|
||||
((ViewPostDetailActivity) activity).saveComment(comment, bundle.getInt(EXTRA_POSITION));
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setVisibility(View.VISIBLE);
|
||||
if (comment.isSaved()) {
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(activity, R.drawable.ic_bookmark_day_night_24dp), null, null, null);
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setText(R.string.unsave_comment);
|
||||
} else {
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(activity, R.drawable.ic_bookmark_border_day_night_24dp), null, null, null);
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setText(R.string.save_comment);
|
||||
}
|
||||
|
||||
binding.saveTextViewCommentMoreBottomSheetFragment.setOnClickListener(view -> {
|
||||
if (activity instanceof ViewPostDetailActivity) {
|
||||
((ViewPostDetailActivity) activity).saveComment(comment, bundle.getInt(EXTRA_POSITION));
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
|
||||
binding.shareTextViewCommentMoreBottomSheetFragment.setOnClickListener(view -> {
|
||||
dismiss();
|
||||
try {
|
||||
|
||||
@ -865,10 +865,8 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
|
||||
}
|
||||
}
|
||||
|
||||
public void saveComment(int position, boolean isSaved) {
|
||||
if (mCommentsAdapter != null) {
|
||||
mCommentsAdapter.setSaveComment(position, isSaved);
|
||||
}
|
||||
public void toggleSaveComment(@NonNull Comment comment, int position) {
|
||||
viewPostDetailFragmentViewModel.toggleSaveComment(comment, position);
|
||||
}
|
||||
|
||||
public void searchComment(String query, boolean searchNextComment) {
|
||||
|
||||
@ -28,4 +28,10 @@ sealed class CommentModerationEvent(open val comment: Comment?, open val positio
|
||||
|
||||
data class Deleted(override val comment: Comment, override val position: Int) : CommentModerationEvent(comment, position, R.string.delete_post_success)
|
||||
data class DeleteFailed(override val comment: Comment?, override val position: Int) : CommentModerationEvent(comment, position, R.string.delete_post_failed)
|
||||
|
||||
data class Saved(override val comment: Comment, override val position: Int) : CommentModerationEvent(comment, position, R.string.comment_saved_success)
|
||||
data class SaveFailed(override val comment: Comment, override val position: Int) : CommentModerationEvent(comment, position, R.string.comment_saved_failed)
|
||||
|
||||
data class Unsaved(override val comment: Comment, override val position: Int) : CommentModerationEvent(comment, position, R.string.comment_unsaved_success)
|
||||
data class UnsaveFailed(override val comment: Comment, override val position: Int) : CommentModerationEvent(comment, position, R.string.comment_unsaved_failed)
|
||||
}
|
||||
@ -1479,6 +1479,82 @@ class ViewPostDetailFragmentViewModelNew(
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleSaveComment(comment: Comment, position: Int) {
|
||||
viewModelScope.launch {
|
||||
_dataState.value.comments?.let {
|
||||
if (accessToken != null) {
|
||||
val updatedComments = ArrayList(it)
|
||||
|
||||
var oldComment: Comment? = it.getOrNull(position)
|
||||
if (!oldComment?.id.equals(comment.id)) {
|
||||
val currentPosition = findCommentPosition(comment.fullName, position)
|
||||
if (currentPosition >= 0 && currentPosition < it.size) {
|
||||
oldComment = it[currentPosition]
|
||||
}
|
||||
}
|
||||
|
||||
oldComment?.let {
|
||||
if (oldComment.isSaved) {
|
||||
if (unsaveThing(
|
||||
oauthRetrofit, accessToken, oldComment.fullName
|
||||
)) {
|
||||
val updatedComment = Comment(oldComment)
|
||||
updatedComment.isSaved = !oldComment.isSaved
|
||||
|
||||
updatedComments[position] = updatedComment
|
||||
|
||||
_dataState.value = _dataState.value.copy(
|
||||
comments = updatedComments
|
||||
)
|
||||
|
||||
commentModerationEventLiveData.postValue(
|
||||
CommentModerationEvent.Unsaved(
|
||||
oldComment,
|
||||
position
|
||||
)
|
||||
)
|
||||
} else {
|
||||
commentModerationEventLiveData.postValue(
|
||||
CommentModerationEvent.UnsaveFailed(
|
||||
oldComment,
|
||||
position
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if (saveThing(
|
||||
oauthRetrofit, accessToken, oldComment.fullName
|
||||
)) {
|
||||
val updatedComment = Comment(oldComment)
|
||||
updatedComment.isSaved = !oldComment.isSaved
|
||||
|
||||
updatedComments[position] = updatedComment
|
||||
|
||||
_dataState.value = _dataState.value.copy(
|
||||
comments = updatedComments
|
||||
)
|
||||
|
||||
commentModerationEventLiveData.postValue(
|
||||
CommentModerationEvent.Saved(
|
||||
oldComment,
|
||||
position
|
||||
)
|
||||
)
|
||||
} else {
|
||||
commentModerationEventLiveData.postValue(
|
||||
CommentModerationEvent.SaveFailed(
|
||||
oldComment,
|
||||
position
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun editComment(comment: Comment, position: Int) {
|
||||
_dataState.value.comments?.let {
|
||||
val updatedComments = ArrayList(it)
|
||||
|
||||
Reference in New Issue
Block a user