Bug fixes + Buggy comment loading

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2023-07-21 22:04:04 +02:00
parent 09d8d17278
commit 258ff290bb
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
22 changed files with 458 additions and 478 deletions

View File

@ -35,7 +35,7 @@ public class SortType {
NEW("New", "New"),
RANDOM("random", "Random"),
RISING("rising", "Rising"),
TOP("top", "Top"),
TOP("Top", "Top"),
CONTROVERSIAL("controversial", "Controversial"),
RELEVANCE("relevance", "Relevance"),
COMMENTS("comments", "Comments"),

View File

@ -5,13 +5,9 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.dto.VoteDTO;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
@ -22,14 +18,13 @@ import retrofit2.Retrofit;
public class VoteThing {
public static void voteThing(Context context, final Retrofit retrofit, String accessToken,
public static void votePost(Context context, final Retrofit retrofit, String accessToken,
final VoteThingListener voteThingListener, final int postID,
final int point, final int position) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> voteThingCall = api.postLike(new VoteDTO(postID,point,accessToken));
Call<String> voteThingCall = api.postLike(new PostVoteDTO(postID, point, accessToken));
voteThingCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
@ -49,17 +44,65 @@ public class VoteThing {
});
}
public static void voteThing(Context context, final Retrofit retrofit, String accessToken,
public static void votePost(Context context, final Retrofit retrofit, String accessToken,
final VoteThingWithoutPositionListener voteThingWithoutPositionListener,
final String fullName, final String point) {
RedditAPI api = retrofit.create(RedditAPI.class);
final int postID, final int point) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Map<String, String> params = new HashMap<>();
params.put(APIUtils.DIR_KEY, point);
params.put(APIUtils.ID_KEY, fullName);
params.put(APIUtils.RANK_KEY, APIUtils.RANK);
Call<String> voteThingCall = api.voteThing(APIUtils.getOAuthHeader(accessToken), params);
Call<String> voteThingCall = api.postLike(new PostVoteDTO(postID, point, accessToken));
voteThingCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
voteThingWithoutPositionListener.onVoteThingSuccess();
} else {
voteThingWithoutPositionListener.onVoteThingFail();
Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
voteThingWithoutPositionListener.onVoteThingFail();
Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
public static void voteComment(Context context, final Retrofit retrofit, String accessToken,
final VoteThingListener voteThingListener, final int commentId,
final int point, final int position) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> voteThingCall = api.commentLike(new CommentVoteDTO(commentId, point, accessToken));
voteThingCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
voteThingListener.onVoteThingSuccess(position);
} else {
voteThingListener.onVoteThingFail(position);
Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
voteThingListener.onVoteThingFail(position);
Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
public static void voteComment(Context context, final Retrofit retrofit, String accessToken,
final VoteThingWithoutPositionListener voteThingWithoutPositionListener,
final int commentId, final int point) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> voteThingCall = api.commentLike(new CommentVoteDTO(commentId, point, accessToken));
voteThingCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {

View File

@ -423,14 +423,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
}
}
private void awardGiven(String awardsHTML, int awardCount, int position) {
if (sectionsPagerAdapter != null) {
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
if (fragment != null) {
fragment.awardGiven(awardsHTML, awardCount, position);
}
}
}
public void deleteComment(String fullName, int position) {
if (sectionsPagerAdapter != null) {
@ -779,14 +771,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
data.getExtras().getInt(EditCommentActivity.EXTRA_EDITED_COMMENT_POSITION));
}
} else if (requestCode == GIVE_AWARD_REQUEST_CODE) {
if (data != null && resultCode == Activity.RESULT_OK) {
Toast.makeText(this, R.string.give_award_success, Toast.LENGTH_SHORT).show();
int position = data.getIntExtra(GiveAwardActivity.EXTRA_RETURN_ITEM_POSITION, 0);
String newAwardsHTML = data.getStringExtra(GiveAwardActivity.EXTRA_RETURN_NEW_AWARDS);
int newAwardsCount = data.getIntExtra(GiveAwardActivity.EXTRA_RETURN_NEW_AWARDS_COUNT, 0);
awardGiven(newAwardsHTML, newAwardsCount, position);
}
} else if (requestCode == CommentActivity.WRITE_COMMENT_REQUEST_CODE) {
if (data != null && resultCode == Activity.RESULT_OK) {
if (data.hasExtra(RETURN_EXTRA_COMMENT_DATA_KEY)) {

View File

@ -51,7 +51,6 @@ import com.google.android.material.textfield.TextInputEditText;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.Executor;
@ -61,14 +60,6 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
import eu.toldi.infinityforlemmy.AppBarStateChangeListener;
import eu.toldi.infinityforlemmy.DeleteThing;
@ -77,6 +68,7 @@ import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RecyclerViewContentScrollingInterface;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
import eu.toldi.infinityforlemmy.adapters.SubredditAutocompleteRecyclerViewAdapter;
@ -86,7 +78,6 @@ import eu.toldi.infinityforlemmy.asynctasks.CheckIsFollowingUser;
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CopyTextBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.KarmaInfoBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostLayoutBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.RandomBottomSheetFragment;
@ -118,6 +109,13 @@ import eu.toldi.infinityforlemmy.user.UserViewModel;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Call;
import retrofit2.Callback;
@ -1216,14 +1214,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == GIVE_AWARD_REQUEST_CODE) {
Toast.makeText(this, R.string.give_award_success, Toast.LENGTH_SHORT).show();
int position = data.getIntExtra(GiveAwardActivity.EXTRA_RETURN_ITEM_POSITION, 0);
String newAwardsHTML = data.getStringExtra(GiveAwardActivity.EXTRA_RETURN_NEW_AWARDS);
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.giveAward(newAwardsHTML, position);
}
} else if (requestCode == EDIT_COMMENT_REQUEST_CODE) {
if (requestCode == EDIT_COMMENT_REQUEST_CODE) {
if (data != null) {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.editComment(
@ -1723,14 +1714,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
}
void giveAward(String awardsHTML, int position) {
if (fragmentManager != null) {
Fragment fragment = fragmentManager.findFragmentByTag("f1");
if (fragment instanceof CommentsListingFragment) {
((CommentsListingFragment) fragment).giveAward(awardsHTML, position);
}
}
}
void editComment(String commentMarkdown, int position) {
if (fragmentManager != null) {

View File

@ -30,12 +30,6 @@ import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import eu.toldi.infinityforlemmy.NetworkState;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.SaveThing;
@ -58,6 +52,12 @@ import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import retrofit2.Retrofit;
public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment, RecyclerView.ViewHolder> {
@ -189,17 +189,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (holder instanceof CommentViewHolder) {
Comment comment = getItem(holder.getBindingAdapterPosition());
if (comment != null) {
String name = "r/" + comment.getSubredditName();
String name = "r/" + comment.getCommunityName();
((CommentViewHolder) holder).authorTextView.setText(name);
((CommentViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML(), true);
} else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair());
}
if (mShowElapsedTime) {
((CommentViewHolder) holder).commentTimeTextView.setText(
@ -208,22 +201,13 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
if (comment.getAwards() != null && !comment.getAwards().equals("")) {
((CommentViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards(), true);
}
((CommentViewHolder) holder).markwonAdapter.setMarkdown(mMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged
((CommentViewHolder) holder).markwonAdapter.notifyDataSetChanged();
String commentText = "";
if (comment.isScoreHidden()) {
commentText = mActivity.getString(R.string.hidden);
} else {
commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
String commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType());
}
((CommentViewHolder) holder).scoreTextView.setText(commentText);
switch (comment.getVoteType()) {
@ -321,16 +305,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
}
public void giveAward(String awardsHTML, int position) {
if (position >= 0 && position < getItemCount()) {
Comment comment = getItem(position);
if (comment != null) {
comment.addAwards(awardsHTML);
notifyItemChanged(position);
}
}
}
public void editComment(String commentContentMarkdown, int position) {
Comment comment = getItem(position);
if (comment != null) {
@ -461,7 +435,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
Comment comment = getItem(getBindingAdapterPosition());
if (comment != null) {
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getSubredditName());
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getCommunityName());
mActivity.startActivity(intent);
}
});
@ -557,12 +531,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -582,10 +556,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
}
}
@ -627,12 +601,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -652,10 +626,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
}
}

View File

@ -38,13 +38,6 @@ import java.util.concurrent.Executor;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.SaveThing;
import eu.toldi.infinityforlemmy.SortType;
@ -71,6 +64,13 @@ import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import retrofit2.Retrofit;
public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -100,7 +100,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private Locale mLocale;
private RequestManager mGlide;
private RecyclerView.RecycledViewPool recycledViewPool;
private String mSingleCommentId;
private Integer mSingleCommentId;
private boolean mIsSingleCommentThreadMode;
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
@ -157,7 +157,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
CustomThemeWrapper customThemeWrapper,
Executor executor, Retrofit retrofit, Retrofit oauthRetrofit,
String accessToken, String accountName,
Post post, Locale locale, String singleCommentId,
Post post, Locale locale, Integer singleCommentId,
boolean isSingleCommentThreadMode,
SharedPreferences sharedPreferences,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
@ -359,22 +359,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (holder instanceof CommentViewHolder) {
Comment comment = getCurrentComment(position);
if (comment != null) {
if (mIsSingleCommentThreadMode && String.valueOf(comment.getId()).equals(mSingleCommentId)) {
if (mIsSingleCommentThreadMode && comment.getId() == mSingleCommentId) {
holder.itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor);
} else if (comment.getAwards() != null && !comment.getAwards().equals("")) {
holder.itemView.setBackgroundColor(mAwardedCommentBackgroundColor);
}
String authorPrefixed = "u/" + comment.getAuthor();
String authorPrefixed = comment.getAuthorQualifiedName();
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML(), true);
} else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair());
}
if (comment.isSubmitter()) {
((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
@ -433,10 +424,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
}
if (!mHideCommentAwards && comment.getAwards() != null && !comment.getAwards().equals("")) {
((CommentViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards(), true);
}
((CommentViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged
@ -445,15 +432,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (!mHideTheNumberOfVotes) {
String commentText = "";
String topScoreText = "";
if (comment.isScoreHidden()) {
commentText = mActivity.getString(R.string.hidden);
} else {
commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType());
topScoreText = mActivity.getString(R.string.top_score,
Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
((CommentViewHolder) holder).scoreTextView.setText(commentText);
((CommentViewHolder) holder).topScoreTextView.setText(topScoreText);
} else {
@ -578,10 +563,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else {
((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) {
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.top_score,
Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType())));
} else if (mHideTheNumberOfVotes) {
if (mHideTheNumberOfVotes) {
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote));
} else {
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.hidden));
@ -635,7 +617,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public void onFetchMoreCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments,
ArrayList<String> moreChildrenIds) {
ArrayList<Integer> moreChildrenIds) {
if (mVisibleComments.size() > parentPosition
&& parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) {
if (mVisibleComments.get(parentPosition).isExpanded()) {
@ -791,6 +773,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
/**
* Find position of comment with given {@code fullName} and
* {@link Comment#NOT_PLACEHOLDER} placeholder type
*
* @return position of the placeholder or -1 if not found
*/
private int findCommentPosition(String fullName, int positionHint) {
@ -800,6 +783,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
/**
* Find position of comment with given {@code fullName} and
* {@link Comment#PLACEHOLDER_LOAD_MORE_COMMENTS} placeholder type
*
* @return position of the placeholder or -1 if not found
*/
private int findLoadMoreCommentsPlaceholderPosition(String fullName, int positionHint) {
@ -947,7 +931,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
public void setSingleComment(String singleCommentId, boolean isSingleCommentThreadMode) {
public void setSingleComment(Integer singleCommentId, boolean isSingleCommentThreadMode) {
mSingleCommentId = singleCommentId;
mIsSingleCommentThreadMode = isSingleCommentThreadMode;
}
@ -1091,15 +1075,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
public void giveAward(String awardsHTML, int awardCount, int position) {
position = mIsSingleCommentThreadMode ? position + 1 : position;
Comment comment = getCurrentComment(position);
if (comment != null) {
comment.addAwards(awardsHTML);
notifyItemChanged(position);
}
}
public void setSaveComment(int position, boolean isSaved) {
Comment comment = getCurrentComment(position);
if (comment != null) {
@ -1416,7 +1391,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
topScoreTextView.setTextColor(mSecondaryTextColor);
}
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) {
if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score,
@ -1424,7 +1399,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
comment.getScore() + comment.getVoteType())));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.voteComment(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
int currentPosition = getBindingAdapterPosition();
@ -1446,7 +1421,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) {
if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score,
@ -1497,7 +1472,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
topScoreTextView.setTextColor(mSecondaryTextColor);
}
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) {
if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score,
@ -1506,7 +1481,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
int position = getBindingAdapterPosition();
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.voteComment(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -1528,7 +1503,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) {
if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score,

View File

@ -63,8 +63,6 @@ import javax.inject.Provider;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.R;
@ -106,6 +104,8 @@ import eu.toldi.infinityforlemmy.videoautoplay.ToroPlayer;
import eu.toldi.infinityforlemmy.videoautoplay.ToroUtil;
import eu.toldi.infinityforlemmy.videoautoplay.media.PlaybackInfo;
import eu.toldi.infinityforlemmy.videoautoplay.widget.Container;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Call;
import retrofit2.Retrofit;
@ -2326,7 +2326,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -2418,7 +2418,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -3652,7 +3652,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -3744,7 +3744,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();

View File

@ -59,15 +59,6 @@ import javax.inject.Provider;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.R;
@ -114,6 +105,15 @@ import eu.toldi.infinityforlemmy.videoautoplay.ToroPlayer;
import eu.toldi.infinityforlemmy.videoautoplay.ToroUtil;
import eu.toldi.infinityforlemmy.videoautoplay.media.PlaybackInfo;
import eu.toldi.infinityforlemmy.videoautoplay.widget.Container;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Call;
import retrofit2.Retrofit;
@ -1169,20 +1169,20 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
int previousScoreTextViewColor = mScoreTextView.getCurrentTextColor();
int previousVoteType = mPost.getVoteType();
String newVoteType;
int newVoteType;
mDownvoteButton.setColorFilter(mPostIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (previousVoteType != 1) {
//Not upvoted before
mPost.setVoteType(1);
newVoteType = APIUtils.DIR_UPVOTE;
newVoteType = Integer.valueOf(APIUtils.DIR_UPVOTE);
mUpvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
mScoreTextView.setTextColor(mUpvotedColor);
} else {
//Upvoted before
mPost.setVoteType(0);
newVoteType = APIUtils.DIR_UNVOTE;
newVoteType = Integer.valueOf(APIUtils.DIR_UNVOTE);
mUpvoteButton.setColorFilter(mPostIconAndInfoColor, PorterDuff.Mode.SRC_IN);
mScoreTextView.setTextColor(mPostIconAndInfoColor);
}
@ -1194,10 +1194,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
VoteThing.votePost(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
@Override
public void onVoteThingSuccess() {
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
if (newVoteType == Integer.parseInt(APIUtils.DIR_UPVOTE)) {
mPost.setVoteType(1);
mUpvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
mScoreTextView.setTextColor(mUpvotedColor);
@ -1230,7 +1230,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
}
}, mPost.getFullName(), newVoteType);
}, mPost.getId(), newVoteType);
});
mDownvoteButton.setOnClickListener(view -> {
@ -1249,20 +1249,20 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
int previousScoreTextViewColor = mScoreTextView.getCurrentTextColor();
int previousVoteType = mPost.getVoteType();
String newVoteType;
int newVoteType;
mUpvoteButton.setColorFilter(mPostIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (previousVoteType != -1) {
//Not upvoted before
mPost.setVoteType(-1);
newVoteType = APIUtils.DIR_DOWNVOTE;
newVoteType = Integer.parseInt(APIUtils.DIR_DOWNVOTE);
mDownvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
mScoreTextView.setTextColor(mDownvotedColor);
} else {
//Upvoted before
mPost.setVoteType(0);
newVoteType = APIUtils.DIR_UNVOTE;
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
mDownvoteButton.setColorFilter(mPostIconAndInfoColor, PorterDuff.Mode.SRC_IN);
mScoreTextView.setTextColor(mPostIconAndInfoColor);
}
@ -1274,10 +1274,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
VoteThing.votePost(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
@Override
public void onVoteThingSuccess() {
if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) {
if (newVoteType == Integer.parseInt(APIUtils.DIR_DOWNVOTE)) {
mPost.setVoteType(-1);
mDownvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
mScoreTextView.setTextColor(mDownvotedColor);
@ -1310,7 +1310,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
}
}, mPost.getFullName(), newVoteType);
}, mPost.getId(), newVoteType);
});
if (!mHideTheNumberOfComments) {

View File

@ -63,8 +63,6 @@ import javax.inject.Provider;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
@ -107,6 +105,8 @@ import eu.toldi.infinityforlemmy.videoautoplay.ToroPlayer;
import eu.toldi.infinityforlemmy.videoautoplay.ToroUtil;
import eu.toldi.infinityforlemmy.videoautoplay.media.PlaybackInfo;
import eu.toldi.infinityforlemmy.videoautoplay.widget.Container;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Call;
import retrofit2.Retrofit;
@ -2433,7 +2433,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -2529,7 +2529,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -3792,7 +3792,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -3888,7 +3888,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();

View File

@ -3,7 +3,8 @@ package eu.toldi.infinityforlemmy.apis;
import com.google.common.util.concurrent.ListenableFuture;
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
import eu.toldi.infinityforlemmy.dto.VoteDTO;
import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.Body;
@ -54,5 +55,24 @@ public interface LemmyAPI {
@Headers("Content-Type: application/json")
@POST("api/v3/post/like")
Call<String> postLike(@Body VoteDTO params);
Call<String> postLike(@Body PostVoteDTO params);
@Headers("Content-Type: application/json")
@POST("api/v3/comment/like")
Call<String> commentLike(@Body CommentVoteDTO params);
@GET("api/v3/comment/list")
Call<String> getComments(
@Query("type_") String type,
@Query("sort") String sort,
@Query("max_depth") Integer maxDepth,
@Query("page") Integer page,
@Query("limit") Integer limit,
@Query("community_id") Integer communityId,
@Query("community_name") String communityName,
@Query("post_id") Integer postId,
@Query("parent_id") Integer parentId,
@Query("saved_only") Boolean savedOnly,
@Query("auth") String auth
);
}

View File

@ -193,7 +193,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
reportTextView.setOnClickListener(view -> {
Intent intent = new Intent(activity, ReportActivity.class);
intent.putExtra(ReportActivity.EXTRA_SUBREDDIT_NAME, comment.getSubredditName());
intent.putExtra(ReportActivity.EXTRA_SUBREDDIT_NAME, comment.getCommunityName());
intent.putExtra(ReportActivity.EXTRA_THING_FULLNAME, comment.getFullName());
activity.startActivity(intent);

View File

@ -4,9 +4,9 @@ import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
import eu.toldi.infinityforlemmy.BuildConfig;
import eu.toldi.infinityforlemmy.utils.APIUtils;
public class Comment implements Parcelable {
public static final int VOTE_TYPE_NO_VOTE = 0;
@ -29,79 +29,77 @@ public class Comment implements Parcelable {
private int id;
private String fullName;
private String author;
private String authorFlair;
private String authorFlairHTML;
private String authorQualifiedName;
private String authorIconUrl;
private String linkAuthor;
private long commentTimeMillis;
private String commentMarkdown;
private String commentRawText;
private String linkId;
private String subredditName;
private String parentId;
private String communityName;
private String communityQualifiedName;
private Integer parentId;
private int score;
private int voteType;
private boolean isSubmitter;
private String distinguished;
private String permalink;
private String awards;
private int depth;
private int childCount;
private boolean collapsed;
private boolean hasReply;
private boolean scoreHidden;
private boolean saved;
private boolean isExpanded;
private boolean hasExpandedBefore;
private ArrayList<Comment> children;
private ArrayList<String> moreChildrenIds;
private ArrayList<Comment> children = new ArrayList<>();
private ArrayList<Integer> moreChildrenIds;
private int placeholderType;
private boolean isLoadingMoreChildren;
private boolean loadMoreChildrenFailed;
private long editedTimeMillis;
public Comment(int id, String fullName, String author, String authorFlair,
String authorFlairHTML, String linkAuthor,
private String[] path;
public Comment(int id, String fullName, String author, String authorQualifiedName, String linkAuthor,
long commentTimeMillis, String commentMarkdown, String commentRawText,
String linkId, String subredditName, String parentId, int score,
String linkId, String communityName, String communityQualifiedName, Integer parentId, int score,
int voteType, boolean isSubmitter, String distinguished, String permalink,
String awards, int depth, boolean collapsed, boolean hasReply,
boolean scoreHidden, boolean saved, long edited) {
int depth, boolean collapsed, boolean hasReply, boolean saved, long edited, String[] path) {
this.id = id;
this.fullName = fullName;
this.author = author;
this.authorFlair = authorFlair;
this.authorFlairHTML = authorFlairHTML;
this.authorQualifiedName = authorQualifiedName;
this.linkAuthor = linkAuthor;
this.commentTimeMillis = commentTimeMillis;
this.commentMarkdown = commentMarkdown;
this.commentRawText = commentRawText;
this.linkId = linkId;
this.subredditName = subredditName;
this.communityName = communityName;
this.communityQualifiedName = communityQualifiedName;
this.parentId = parentId;
this.score = score;
this.voteType = voteType;
this.isSubmitter = isSubmitter;
this.distinguished = distinguished;
this.permalink = APIUtils.API_BASE_URI + permalink;
this.awards = awards;
this.permalink = permalink;
this.depth = depth;
this.collapsed = collapsed;
this.hasReply = hasReply;
this.scoreHidden = scoreHidden;
this.saved = saved;
this.isExpanded = false;
this.hasExpandedBefore = false;
this.editedTimeMillis = edited;
this.path = path;
placeholderType = NOT_PLACEHOLDER;
}
public Comment(String parentFullName, int depth, int placeholderType) {
public Comment(String parentFullName, int depth, int placeholderType, Integer parentId) {
if (placeholderType == PLACEHOLDER_LOAD_MORE_COMMENTS) {
this.fullName = parentFullName;
} else {
this.fullName = parentFullName;
this.parentId = parentFullName.substring(3);
this.parentId = parentId;
}
this.depth = depth;
this.placeholderType = placeholderType;
@ -117,36 +115,39 @@ public class Comment implements Parcelable {
id = in.readInt();
fullName = in.readString();
author = in.readString();
authorFlair = in.readString();
authorFlairHTML = in.readString();
authorQualifiedName = in.readString();
authorIconUrl = in.readString();
linkAuthor = in.readString();
commentTimeMillis = in.readLong();
commentMarkdown = in.readString();
commentRawText = in.readString();
linkId = in.readString();
subredditName = in.readString();
parentId = in.readString();
communityName = in.readString();
communityQualifiedName = in.readString();
parentId = in.readInt();
score = in.readInt();
voteType = in.readInt();
isSubmitter = in.readByte() != 0;
distinguished = in.readString();
permalink = in.readString();
awards = in.readString();
depth = in.readInt();
childCount = in.readInt();
collapsed = in.readByte() != 0;
hasReply = in.readByte() != 0;
scoreHidden = in.readByte() != 0;
isExpanded = in.readByte() != 0;
hasExpandedBefore = in.readByte() != 0;
children = new ArrayList<>();
in.readTypedList(children, Comment.CREATOR);
moreChildrenIds = new ArrayList<>();
in.readStringList(moreChildrenIds);
List<String> childrenIDs = new ArrayList<>();
in.readStringList(childrenIDs);
for (int i = 0; i < childrenIDs.size(); i++) {
moreChildrenIds.add(Integer.valueOf(childrenIDs.get(i)));
}
placeholderType = in.readInt();
isLoadingMoreChildren = in.readByte() != 0;
loadMoreChildrenFailed = in.readByte() != 0;
in.readStringArray(path);
}
public int getId() {
@ -169,13 +170,6 @@ public class Comment implements Parcelable {
this.author = author;
}
public String getAuthorFlair() {
return authorFlair;
}
public String getAuthorFlairHTML() {
return authorFlairHTML;
}
public String getAuthorIconUrl() {
return authorIconUrl;
@ -213,15 +207,15 @@ public class Comment implements Parcelable {
return linkId;
}
public String getSubredditName() {
return subredditName;
public String getCommunityName() {
return communityName;
}
public String getParentId() {
public Integer getParentId() {
return parentId;
}
public void setParentId(String parentId) {
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
@ -253,14 +247,6 @@ public class Comment implements Parcelable {
return permalink;
}
public String getAwards() {
return awards;
}
public void addAwards(String newAwardsHTML) {
awards += newAwardsHTML;
}
public int getDepth() {
return depth;
}
@ -285,10 +271,6 @@ public class Comment implements Parcelable {
this.hasReply = hasReply;
}
public boolean isScoreHidden() {
return scoreHidden;
}
public boolean isSaved() {
return saved;
}
@ -362,11 +344,11 @@ public class Comment implements Parcelable {
}
}
public ArrayList<String> getMoreChildrenIds() {
public ArrayList<Integer> getMoreChildrenIds() {
return moreChildrenIds;
}
public void setMoreChildrenIds(ArrayList<String> moreChildrenIds) {
public void setMoreChildrenIds(ArrayList<Integer> moreChildrenIds) {
this.moreChildrenIds = moreChildrenIds;
}
@ -408,40 +390,58 @@ public class Comment implements Parcelable {
parcel.writeInt(id);
parcel.writeString(fullName);
parcel.writeString(author);
parcel.writeString(authorFlair);
parcel.writeString(authorFlairHTML);
parcel.writeString(authorQualifiedName);
parcel.writeString(authorIconUrl);
parcel.writeString(linkAuthor);
parcel.writeLong(commentTimeMillis);
parcel.writeString(commentMarkdown);
parcel.writeString(commentRawText);
parcel.writeString(linkId);
parcel.writeString(subredditName);
parcel.writeString(parentId);
parcel.writeString(communityName);
parcel.writeString(communityQualifiedName);
parcel.writeInt(parentId == null ? 0 : parentId);
parcel.writeInt(score);
parcel.writeInt(voteType);
parcel.writeByte((byte) (isSubmitter ? 1 : 0));
parcel.writeString(distinguished);
parcel.writeString(permalink);
parcel.writeString(awards);
parcel.writeInt(depth);
parcel.writeInt(childCount);
parcel.writeByte((byte) (collapsed ? 1 : 0));
parcel.writeByte((byte) (hasReply ? 1 : 0));
parcel.writeByte((byte) (scoreHidden ? 1 : 0));
parcel.writeByte((byte) (isExpanded ? 1 : 0));
parcel.writeByte((byte) (hasExpandedBefore ? 1 : 0));
parcel.writeTypedList(children);
parcel.writeStringList(moreChildrenIds);
List<String> childrenIds = new ArrayList<>();
if (moreChildrenIds != null) {
for (int j = 0; j < moreChildrenIds.size(); j++) {
childrenIds.add(String.valueOf(moreChildrenIds.get(i)));
}
}
parcel.writeStringList(childrenIds);
parcel.writeInt(placeholderType);
parcel.writeByte((byte) (isLoadingMoreChildren ? 1 : 0));
parcel.writeByte((byte) (loadMoreChildrenFailed ? 1 : 0));
parcel.writeStringArray(path);
}
public String[] getPath() {
return path;
}
public boolean isEdited() {
return editedTimeMillis != 0;
}
public long getEditedTimeMillis() {
return editedTimeMillis;
}
public String getAuthorQualifiedName() {
return authorQualifiedName;
}
public String getCommunityQualifiedName() {
return communityQualifiedName;
}
}

View File

@ -217,7 +217,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
for (int i = 0; i < commentsJSONArray.length(); i++) {
try {
JSONObject commentJSON = commentsJSONArray.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
comments.add(ParseComment.parseSingleComment(commentJSON, 0));
comments.add(ParseComment.parseSingleComment(commentJSON));
} catch (JSONException ignored) {
}
}

View File

@ -6,10 +6,10 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import retrofit2.Call;
@ -19,36 +19,25 @@ import retrofit2.Retrofit;
public class FetchComment {
public static void fetchComments(Executor executor, Handler handler, Retrofit retrofit,
@Nullable String accessToken, String article,
String commentId, SortType.Type sortType, String contextNumber, boolean expandChildren,
Locale locale, FetchCommentListener fetchCommentListener) {
RedditAPI api = retrofit.create(RedditAPI.class);
@Nullable String accessToken, Integer article,
Integer commentId, SortType.Type sortType, boolean expandChildren,
Integer page, FetchCommentListener fetchCommentListener) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> comments;
if (accessToken == null) {
if (commentId == null) {
comments = api.getPostAndCommentsById(article, sortType);
} else {
comments = api.getPostAndCommentsSingleThreadById(article, commentId, sortType, contextNumber);
}
} else {
if (commentId == null) {
comments = api.getPostAndCommentsByIdOauth(article, sortType, APIUtils.getOAuthHeader(accessToken));
} else {
comments = api.getPostAndCommentsSingleThreadByIdOauth(article, commentId, sortType, contextNumber,
APIUtils.getOAuthHeader(accessToken));
}
}
comments = api.getComments("All", sortType.value, 5, page, 25, null, null, article, commentId, false, accessToken);
comments.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
ParseComment.parseComment(executor, handler, response.body(),
ParseComment.parseComments(executor, handler, response.body(),
expandChildren, new ParseComment.ParseCommentListener() {
@Override
public void onParseCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments,
String parentId, ArrayList<String> moreChildrenIds) {
Integer parentId, ArrayList<Integer> moreChildrenIds) {
fetchCommentListener.onFetchCommentSuccess(expandedComments, parentId,
moreChildrenIds);
}
@ -72,7 +61,7 @@ public class FetchComment {
public static void fetchMoreComment(Executor executor, Handler handler, Retrofit retrofit,
@Nullable String accessToken,
ArrayList<String> allChildren,
ArrayList<Integer> allChildren,
boolean expandChildren, String postFullName,
SortType.Type sortType,
FetchMoreCommentListener fetchMoreCommentListener) {
@ -80,7 +69,7 @@ public class FetchComment {
return;
}
String childrenIds = String.join(",", allChildren);
String childrenIds = "";
if (childrenIds.isEmpty()) {
return;
@ -104,7 +93,7 @@ public class FetchComment {
@Override
public void onParseCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments,
String parentId, ArrayList<String> moreChildrenIds) {
Integer parentId, ArrayList<Integer> moreChildrenIds) {
fetchMoreCommentListener.onFetchMoreCommentSuccess(
topLevelComments, expandedComments, moreChildrenIds);
}
@ -127,7 +116,7 @@ public class FetchComment {
}
public interface FetchCommentListener {
void onFetchCommentSuccess(ArrayList<Comment> expandedComments, String parentId, ArrayList<String> children);
void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children);
void onFetchCommentFailed();
}
@ -135,7 +124,7 @@ public class FetchComment {
public interface FetchMoreCommentListener {
void onFetchMoreCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments,
ArrayList<String> moreChildrenIds);
ArrayList<Integer> moreChildrenIds);
void onFetchMoreCommentFailed();
}

View File

@ -20,7 +20,7 @@ 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 parentIdWithoutPrefix = " comment.getParentId().substring(3)";
String rootCommentId = parentIdWithoutPrefix.equals(comment.getLinkId()) ? String.valueOf(comment.getId()) : parentIdWithoutPrefix;
try {
Response<String> response = retrofit.create(RevedditAPI.class).getRemovedComments(

View File

@ -1,11 +1,6 @@
package eu.toldi.infinityforlemmy.comment;
import static eu.toldi.infinityforlemmy.comment.Comment.VOTE_TYPE_DOWNVOTE;
import static eu.toldi.infinityforlemmy.comment.Comment.VOTE_TYPE_NO_VOTE;
import static eu.toldi.infinityforlemmy.comment.Comment.VOTE_TYPE_UPVOTE;
import android.os.Handler;
import android.text.Html;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -14,29 +9,44 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import eu.toldi.infinityforlemmy.utils.JSONUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
public class ParseComment {
public static void parseComment(Executor executor, Handler handler, String response,
public static void parseComments(Executor executor, Handler handler, String response,
boolean expandChildren,
ParseCommentListener parseCommentListener) {
executor.execute(() -> {
try {
JSONArray childrenArray = new JSONArray(response);
String parentId = childrenArray.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY)
.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.NAME_KEY);
childrenArray = childrenArray.getJSONObject(1).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
JSONArray childrenArray = new JSONObject(response).getJSONArray("comments");
ArrayList<Comment> expandedNewComments = new ArrayList<>();
ArrayList<String> moreChildrenIds = new ArrayList<>();
ArrayList<Integer> moreChildrenIds = new ArrayList<>();
ArrayList<Comment> newComments = new ArrayList<>();
parseCommentRecursion(childrenArray, newComments, moreChildrenIds, 0);
for (int i = 0; i < childrenArray.length(); i++) {
Comment singleComment = parseSingleComment(childrenArray.getJSONObject(i));
newComments.add(singleComment);
if (singleComment.getDepth() > 0) {
Comment parent = findDirectParent(newComments, singleComment);
moreChildrenIds.add(singleComment.getId());
if (parent != null)
parent.addChild(singleComment);
}
}
//parseCommentRecursion(childrenArray, newComments, moreChildrenIds, 0);
expandChildren(newComments, expandedNewComments, expandChildren);
ArrayList<Comment> commentData;
@ -46,7 +56,7 @@ public class ParseComment {
commentData = newComments;
}
handler.post(() -> parseCommentListener.onParseCommentSuccess(newComments, commentData, parentId, moreChildrenIds));
handler.post(() -> parseCommentListener.onParseCommentSuccess(newComments, commentData, (newComments.size() == 0) ? null : newComments.get(0).getId(), moreChildrenIds));
} catch (JSONException e) {
e.printStackTrace();
handler.post(parseCommentListener::onParseCommentFailed);
@ -54,6 +64,10 @@ public class ParseComment {
});
}
private static void getChildrenCountRecursive(List<Comment> commentList, Comment root) {
}
static void parseMoreComment(Executor executor, Handler handler, String response, boolean expandChildren,
ParseCommentListener parseCommentListener) {
executor.execute(() -> {
@ -63,7 +77,7 @@ public class ParseComment {
ArrayList<Comment> newComments = new ArrayList<>();
ArrayList<Comment> expandedNewComments = new ArrayList<>();
ArrayList<String> moreChildrenIds = new ArrayList<>();
ArrayList<Integer> moreChildrenIds = new ArrayList<>();
// api response is a flat list of comments tree
// process it in order and rebuild the tree
@ -71,13 +85,13 @@ public class ParseComment {
JSONObject child = childrenArray.getJSONObject(i);
JSONObject childData = child.getJSONObject(JSONUtils.DATA_KEY);
if (child.getString(JSONUtils.KIND_KEY).equals(JSONUtils.KIND_VALUE_MORE)) {
String parentFullName = childData.getString(JSONUtils.PARENT_ID_KEY);
Integer parentFullName = Integer.valueOf(childData.getString(JSONUtils.PARENT_ID_KEY));
JSONArray childrenIds = childData.getJSONArray(JSONUtils.CHILDREN_KEY);
if (childrenIds.length() != 0) {
ArrayList<String> localMoreChildrenIds = new ArrayList<>(childrenIds.length());
ArrayList<Integer> localMoreChildrenIds = new ArrayList<>(childrenIds.length());
for (int j = 0; j < childrenIds.length(); j++) {
localMoreChildrenIds.add(childrenIds.getString(j));
localMoreChildrenIds.add(childrenIds.getInt(j));
}
Comment parentComment = findCommentByFullName(newComments, parentFullName);
@ -90,13 +104,15 @@ public class ParseComment {
moreChildrenIds.addAll(localMoreChildrenIds);
}
} else {
Comment parentComment = findCommentByFullName(newComments, parentFullName);
Comment continueThreadPlaceholder = new Comment(
parentFullName,
parentComment.getFullName(),
childData.getInt(JSONUtils.DEPTH_KEY),
Comment.PLACEHOLDER_CONTINUE_THREAD
Comment.PLACEHOLDER_CONTINUE_THREAD,
parentComment.getId()
);
Comment parentComment = findCommentByFullName(newComments, parentFullName);
if (parentComment != null) {
parentComment.setHasReply(true);
parentComment.addChild(continueThreadPlaceholder, parentComment.getChildCount());
@ -107,8 +123,8 @@ public class ParseComment {
}
}
} else {
Comment comment = parseSingleComment(childData, 0);
String parentFullName = comment.getParentId();
Comment comment = parseSingleComment(childData);
Integer parentFullName = comment.getParentId();
Comment parentComment = findCommentByFullName(newComments, parentFullName);
if (parentComment != null) {
@ -145,7 +161,7 @@ public class ParseComment {
executor.execute(() -> {
try {
JSONObject sentCommentData = new JSONObject(response);
Comment comment = parseSingleComment(sentCommentData, depth);
Comment comment = parseSingleComment(sentCommentData);
handler.post(() -> parseSentCommentListener.onParseSentCommentSuccess(comment));
} catch (JSONException e) {
@ -177,7 +193,7 @@ public class ParseComment {
actualCommentLength = comments.length() - 1;
if (moreChildrenIds.isEmpty() && comments.getJSONObject(comments.length() - 1).getString(JSONUtils.KIND_KEY).equals(JSONUtils.KIND_VALUE_MORE)) {
newCommentData.add(new Comment(more.getString(JSONUtils.PARENT_ID_KEY), more.getInt(JSONUtils.DEPTH_KEY), Comment.PLACEHOLDER_CONTINUE_THREAD));
//newCommentData.add(new Comment(more.getString(JSONUtils.PARENT_ID_KEY), more.getInt(JSONUtils.DEPTH_KEY), Comment.PLACEHOLDER_CONTINUE_THREAD));
return;
}
} else {
@ -186,19 +202,7 @@ public class ParseComment {
for (int i = 0; i < actualCommentLength; i++) {
JSONObject data = comments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
Comment singleComment = parseSingleComment(data, depth);
if (data.get(JSONUtils.REPLIES_KEY) instanceof JSONObject) {
JSONArray childrenArray = data.getJSONObject(JSONUtils.REPLIES_KEY)
.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
ArrayList<Comment> children = new ArrayList<>();
ArrayList<String> nextMoreChildrenIds = new ArrayList<>();
parseCommentRecursion(childrenArray, children, nextMoreChildrenIds, singleComment.getDepth());
singleComment.addChildren(children);
singleComment.setMoreChildrenIds(nextMoreChildrenIds);
singleComment.setChildCount(getChildCount(singleComment));
}
Comment singleComment = parseSingleComment(data);
newCommentData.add(singleComment);
}
}
@ -228,89 +232,60 @@ public class ParseComment {
}
if (c.hasMoreChildrenIds() && !c.getMoreChildrenIds().isEmpty()) {
//Add a load more placeholder
Comment placeholder = new Comment(c.getFullName(), c.getDepth() + 1, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS);
Comment placeholder = new Comment(c.getFullName(), c.getDepth() + 1, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS, c.getId());
visibleComments.add(placeholder);
c.addChild(placeholder, c.getChildren().size());
}
}
}
static Comment parseSingleComment(JSONObject singleCommentData, int depth) throws JSONException {
String id = singleCommentData.getString(JSONUtils.ID_KEY);
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
String author = singleCommentData.getString(JSONUtils.AUTHOR_KEY);
StringBuilder authorFlairHTMLBuilder = new StringBuilder();
if (singleCommentData.has(JSONUtils.AUTHOR_FLAIR_RICHTEXT_KEY)) {
JSONArray flairArray = singleCommentData.getJSONArray(JSONUtils.AUTHOR_FLAIR_RICHTEXT_KEY);
for (int i = 0; i < flairArray.length(); i++) {
JSONObject flairObject = flairArray.getJSONObject(i);
String e = flairObject.getString(JSONUtils.E_KEY);
if (e.equals("text")) {
authorFlairHTMLBuilder.append(Html.escapeHtml(flairObject.getString(JSONUtils.T_KEY)));
} else if (e.equals("emoji")) {
authorFlairHTMLBuilder.append("<img src=\"").append(Html.escapeHtml(flairObject.getString(JSONUtils.U_KEY))).append("\">");
}
}
}
String authorFlair = singleCommentData.isNull(JSONUtils.AUTHOR_FLAIR_TEXT_KEY) ? "" : singleCommentData.getString(JSONUtils.AUTHOR_FLAIR_TEXT_KEY);
String linkAuthor = singleCommentData.has(JSONUtils.LINK_AUTHOR_KEY) ? singleCommentData.getString(JSONUtils.LINK_AUTHOR_KEY) : null;
String linkId = singleCommentData.getString(JSONUtils.LINK_ID_KEY).substring(3);
String subredditName = singleCommentData.getString(JSONUtils.SUBREDDIT_KEY);
String parentId = singleCommentData.getString(JSONUtils.PARENT_ID_KEY);
boolean isSubmitter = singleCommentData.getBoolean(JSONUtils.IS_SUBMITTER_KEY);
String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY);
String commentMarkdown = "";
if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) {
commentMarkdown = Utils.parseInlineGifInComments(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(singleCommentData.getString(JSONUtils.BODY_KEY))));
if (!singleCommentData.isNull(JSONUtils.MEDIA_METADATA_KEY)) {
JSONObject mediaMetadataObject = singleCommentData.getJSONObject(JSONUtils.MEDIA_METADATA_KEY);
commentMarkdown = Utils.parseInlineEmotes(commentMarkdown, mediaMetadataObject);
}
}
String commentRawText = Utils.trimTrailingWhitespace(
Html.fromHtml(singleCommentData.getString(JSONUtils.BODY_HTML_KEY))).toString();
String permalink = Html.fromHtml(singleCommentData.getString(JSONUtils.PERMALINK_KEY)).toString();
StringBuilder awardingsBuilder = new StringBuilder();
JSONArray awardingsArray = singleCommentData.getJSONArray(JSONUtils.ALL_AWARDINGS_KEY);
for (int i = 0; i < awardingsArray.length(); i++) {
JSONObject award = awardingsArray.getJSONObject(i);
int count = award.getInt(JSONUtils.COUNT_KEY);
JSONArray icons = award.getJSONArray(JSONUtils.RESIZED_ICONS_KEY);
if (icons.length() > 4) {
String iconUrl = icons.getJSONObject(3).getString(JSONUtils.URL_KEY);
awardingsBuilder.append("<img src=\"").append(Html.escapeHtml(iconUrl)).append("\"> ").append("x").append(count).append(" ");
} else if (icons.length() > 0) {
String iconUrl = icons.getJSONObject(icons.length() - 1).getString(JSONUtils.URL_KEY);
awardingsBuilder.append("<img src=\"").append(Html.escapeHtml(iconUrl)).append("\"> ").append("x").append(count).append(" ");
}
}
int score = singleCommentData.getInt(JSONUtils.SCORE_KEY);
int voteType;
if (singleCommentData.isNull(JSONUtils.LIKES_KEY)) {
voteType = VOTE_TYPE_NO_VOTE;
} else {
voteType = singleCommentData.getBoolean(JSONUtils.LIKES_KEY) ? VOTE_TYPE_UPVOTE : VOTE_TYPE_DOWNVOTE;
score -= voteType;
}
long submitTime = singleCommentData.getLong(JSONUtils.PUBLISHED) * 1000;
boolean scoreHidden = singleCommentData.getBoolean(JSONUtils.SCORE_HIDDEN_KEY);
boolean saved = singleCommentData.getBoolean(JSONUtils.SAVED_KEY);
public static Comment parseSingleComment(JSONObject jsonObject) throws JSONException {
JSONObject commentObj = jsonObject.getJSONObject("comment");
JSONObject creatorObj = jsonObject.getJSONObject("creator");
JSONObject postObj = jsonObject.getJSONObject("post");
JSONObject communityObj = jsonObject.getJSONObject("community");
JSONObject countsObj = jsonObject.getJSONObject("counts");
if (singleCommentData.has(JSONUtils.DEPTH_KEY)) {
depth = singleCommentData.getInt(JSONUtils.DEPTH_KEY);
int id = commentObj.getInt("id");
String fullName = creatorObj.getString("name");
String author = creatorObj.getString("name");
String authorQualifiedName = LemmyUtils.actorID2FullName(creatorObj.getString("actor_id"));
String linkAuthor = creatorObj.getString("actor_id");
long commentTimeMillis = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
commentTimeMillis = ZonedDateTime.parse(commentObj.getString("published"),
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("Z"))).toInstant().toEpochMilli();
}
String commentMarkdown = commentObj.getString("content");
String commentRawText = commentObj.getString("content");
String linkId = postObj.getString("id");
String communityName = communityObj.getString("name");
String communityQualifiedName = communityObj.getString("actor_id");
int score = countsObj.getInt("score");
int voteType = (jsonObject.isNull("my_vote")) ? 0 : jsonObject.getInt("my_vote");
boolean isSubmitter = creatorObj.getInt("id") == postObj.getInt("creator_id");
String distinguished = commentObj.getString("distinguished");
String permalink = commentObj.getString("ap_id");
String[] path = commentObj.getString("path").split(Pattern.quote("."));
;
int depth = path.length - 2;
Integer parentId = (depth > 0) ? Integer.valueOf(path[path.length - 2]) : null;
boolean collapsed = false;
boolean hasReply = countsObj.getInt("child_count") > 0;
boolean saved = jsonObject.getBoolean("saved");
long edited = 0;
Comment comment = new Comment(id, fullName, author, authorQualifiedName, linkAuthor, commentTimeMillis,
commentMarkdown, commentRawText, linkId, communityName, communityQualifiedName, parentId,
score, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, saved, edited, path);
int child_count = countsObj.getInt("child_count");
comment.setChildCount(child_count);
return comment;
}
boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY);
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
// this key can either be a bool (false) or a long (edited timestamp)
long edited = singleCommentData.optLong(JSONUtils.EDITED_KEY) * 1000;
return new Comment(Integer.parseInt(id), fullName, author, authorFlair, authorFlairHTMLBuilder.toString(),
linkAuthor, submitTime, commentMarkdown, commentRawText,
linkId, subredditName, parentId, score, voteType, isSubmitter, distinguished,
permalink, awardingsBuilder.toString(), depth, collapsed, hasReply, scoreHidden, saved, edited);
}
@Nullable
private static String parseSentCommentErrorMessage(String response) {
@ -341,10 +316,51 @@ public class ParseComment {
return null;
}
public static Comment findDirectParent(List<Comment> commentList, Comment child) {
for (int i = 0; i < commentList.size(); i++) {
Comment result = findDirectParentRecursive(commentList.get(i), child);
if (result != null)
return result;
}
return null;
}
public static Comment findDirectParentRecursive(Comment root, Comment child) {
// Base case: if root is null
if (root == null) {
return null;
}
if (root.getId() == child.getParentId()) {
return root;
}
// Check if any child of the root is the given child comment
List<Comment> children = root.getChildren();
if (children != null) {
for (Comment comment : children) {
if (comment.getId() == child.getId()) {
return root;
}
}
// If the child comment is not an immediate child of the root,
// recursively call the function on the children of the root
for (Comment comment : children) {
Comment result = findDirectParentRecursive(comment, child);
if (result != null) {
return result;
}
}
}
return null;
}
@Nullable
private static Comment findCommentByFullName(@NonNull List<Comment> comments, @NonNull String fullName) {
private static Comment findCommentByFullName(@NonNull List<Comment> comments, @NonNull Integer fullName) {
for (Comment comment : comments) {
if (comment.getFullName().equals(fullName) &&
if (comment.getId() == fullName &&
comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) {
return comment;
}
@ -368,8 +384,8 @@ public class ParseComment {
}
public interface ParseCommentListener {
void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, String parentId,
ArrayList<String> moreChildrenIds);
void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, Integer parentId,
ArrayList<Integer> moreChildrenIds);
void onParseCommentFailed();
}

View File

@ -0,0 +1,25 @@
package eu.toldi.infinityforlemmy.dto;
public class CommentVoteDTO {
int comment_id;
int score;
String auth;
public CommentVoteDTO(int comment_id, int score, String auth) {
this.comment_id = comment_id;
this.score = score;
this.auth = auth;
}
public int getComment_id() {
return comment_id;
}
public int getScore() {
return score;
}
public String getAuth() {
return auth;
}
}

View File

@ -1,12 +1,12 @@
package eu.toldi.infinityforlemmy.dto;
public class VoteDTO {
public class PostVoteDTO {
private final int post_id;
private final int score;
private final String auth;
public VoteDTO(int post_id, int vote, String auth) {
public PostVoteDTO(int post_id, int vote, String auth) {
this.post_id = post_id;
this.score = vote;
this.auth = auth;

View File

@ -400,11 +400,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
return sortType;
}
public void giveAward(String awardsHTML, int position) {
if (mAdapter != null) {
mAdapter.giveAward(awardsHTML, position);
}
}
public void editComment(String commentMarkdown, int position) {
if (mAdapter != null) {

View File

@ -84,6 +84,7 @@ import eu.toldi.infinityforlemmy.activities.SubmitCrosspostActivity;
import eu.toldi.infinityforlemmy.activities.ViewPostDetailActivity;
import eu.toldi.infinityforlemmy.adapters.CommentsRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.adapters.PostDetailRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.apis.StreamableAPI;
import eu.toldi.infinityforlemmy.asynctasks.LoadUserData;
@ -202,7 +203,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@State
ArrayList<Comment> comments;
@State
ArrayList<String> children;
ArrayList<Integer> children;
@State
int pages_loaded = 0;
@State
boolean loadMoreChildrenSuccess = true;
@State
@ -224,7 +228,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private String mAccessToken;
private String mAccountName;
private int postListPosition = -1;
private String mSingleCommentId;
private Integer mSingleCommentId;
private String mContextNumber;
private boolean showToast = false;
private boolean mIsSmoothScrolling = false;
@ -541,7 +545,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
};
mSingleCommentId = getArguments().getString(EXTRA_SINGLE_COMMENT_ID);
mSingleCommentId = (getArguments().getString(EXTRA_SINGLE_COMMENT_ID) == null) ? null : Integer.valueOf(getArguments().getString(EXTRA_SINGLE_COMMENT_ID));
mContextNumber = getArguments().getString(EXTRA_CONTEXT_NUMBER, "8");
if (savedInstanceState == null) {
@ -770,12 +774,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
}
public void awardGiven(String awardsHTML, int awardCount, int position) {
if (mCommentsAdapter != null) {
mCommentsAdapter.giveAward(awardsHTML, awardCount, position);
}
}
public void changeFlair(Flair flair) {
Map<String, String> params = new HashMap<>();
params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON);
@ -1253,24 +1251,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mSwipeRefreshLayout.setRefreshing(true);
mGlide.clear(mFetchPostInfoImageView);
Call<String> postAndComments;
if (mAccessToken == null) {
if (isSingleCommentThreadMode && mSingleCommentId != null) {
postAndComments = mRetrofit.getRetrofit().create(RedditAPI.class).getPostAndCommentsSingleThreadById(
subredditId, mSingleCommentId, sortType, mContextNumber);
} else {
postAndComments = mRetrofit.getRetrofit().create(RedditAPI.class).getPostAndCommentsById(subredditId,
sortType);
}
} else {
if (isSingleCommentThreadMode && mSingleCommentId != null) {
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadByIdOauth(subredditId,
mSingleCommentId, sortType, mContextNumber, APIUtils.getOAuthHeader(mAccessToken));
} else {
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId,
sortType, APIUtils.getOAuthHeader(mAccessToken));
}
}
Call<String> postAndComments = mRetrofit.getRetrofit().create(LemmyAPI.class).getComments("All", sortType.value, 5, 1, 25, null, null, Integer.valueOf(subredditId), mSingleCommentId, false, mAccessToken);
postAndComments.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
@ -1331,10 +1312,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (mRespectSubredditRecommendedSortType) {
fetchCommentsRespectRecommendedSort(false);
} else {
ParseComment.parseComment(mExecutor, new Handler(), response.body(),
ParseComment.parseComments(mExecutor, new Handler(), response.body(),
mExpandChildren, new ParseComment.ParseCommentListener() {
@Override
public void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, String parentId, ArrayList<String> moreChildrenIds) {
public void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> moreChildrenIds) {
ViewPostDetailFragment.this.children = moreChildrenIds;
hasMoreChildren = children.size() != 0;
@ -1466,23 +1447,27 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
isFetchingComments = true;
mCommentsAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode);
mCommentsAdapter.initiallyLoading();
String commentId = null;
Integer commentId = null;
if (isSingleCommentThreadMode) {
commentId = mSingleCommentId;
}
Retrofit retrofit = mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit;
FetchComment.fetchComments(mExecutor, new Handler(), retrofit, mAccessToken, String.valueOf(mPost.getId()), commentId, sortType,
mContextNumber, mExpandChildren, mLocale, new FetchComment.FetchCommentListener() {
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, mPost.getId(), commentId, sortType, mExpandChildren, pages_loaded + 1,
new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments,
String parentId, ArrayList<String> children) {
Integer parentId, ArrayList<Integer> children) {
ViewPostDetailFragment.this.children = children;
pages_loaded++;
comments = expandedComments;
hasMoreChildren = children.size() != 0;
hasMoreChildren = expandedComments.size() != 0;
mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
if (hasMoreChildren) {
fetchMoreComments();
}
/*
if (children.size() > 0) {
(mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).clearOnScrollListeners();
(mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).addOnScrollListener(new RecyclerView.OnScrollListener() {
@ -1527,7 +1512,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
}
});
}
}*/
if (changeRefreshState) {
isRefreshing = false;
}
@ -1559,13 +1544,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
isLoadingMoreChildren = true;
Retrofit retrofit = mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit;
FetchComment.fetchMoreComment(mExecutor, new Handler(), retrofit, mAccessToken, children,
mExpandChildren, mPost.getFullName(), sortType, new FetchComment.FetchMoreCommentListener() {
FetchComment.fetchComments(mExecutor, new Handler(), retrofit, mAccessToken,
mPost.getId(), null, sortType, mExpandChildren, pages_loaded + 1, new FetchComment.FetchCommentListener() {
@Override
public void onFetchMoreCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments,
ArrayList<String> moreChildrenIds) {
children = moreChildrenIds;
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
pages_loaded++;
hasMoreChildren = !children.isEmpty();
mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
isLoadingMoreChildren = false;
@ -1573,7 +1556,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
@Override
public void onFetchMoreCommentFailed() {
public void onFetchCommentFailed() {
isLoadingMoreChildren = false;
loadMoreChildrenSuccess = false;
mCommentsAdapter.loadMoreCommentsFailed();
@ -1593,12 +1576,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
if (fetchPost) {
Retrofit retrofit;
if (mAccessToken == null) {
retrofit = mRetrofit.getRetrofit();
} else {
retrofit = mOauthRetrofit;
}
Retrofit retrofit = mRetrofit.getRetrofit();
FetchPost.fetchPost(mExecutor, new Handler(), retrofit, String.valueOf(mPost.getId()), mAccessToken,
new FetchPost.FetchPostListener() {
@Override

View File

@ -7,8 +7,6 @@ import androidx.annotation.Nullable;
import java.util.ArrayList;
import eu.toldi.infinityforlemmy.utils.APIUtils;
/**
* Created by alex on 3/1/18.
*/
@ -90,7 +88,7 @@ public class Post implements Parcelable {
this.authorNamePrefixed = authorNamePrefixed;
this.postTimeMillis = postTimeMillis;
this.title = title;
this.permalink = APIUtils.API_BASE_URI + permalink;
this.permalink = permalink;
this.score = score;
this.postType = postType;
this.voteType = voteType;
@ -122,7 +120,7 @@ public class Post implements Parcelable {
this.postTimeMillis = postTimeMillis;
this.title = title;
this.url = url;
this.permalink = APIUtils.API_BASE_URI + permalink;
this.permalink = permalink;
this.score = score;
this.postType = postType;
this.voteType = voteType;

View File

@ -261,7 +261,7 @@
<string name="search_in">Search in</string>
<string name="all_subreddits">All subreddits</string>
<string name="sort_best">Best</string>
<string name="sort_best">Active</string>
<string name="sort_hot">Hot</string>
<string name="sort_new">New</string>
<string name="sort_random">Random</string>