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"), NEW("New", "New"),
RANDOM("random", "Random"), RANDOM("random", "Random"),
RISING("rising", "Rising"), RISING("rising", "Rising"),
TOP("top", "Top"), TOP("Top", "Top"),
CONTROVERSIAL("controversial", "Controversial"), CONTROVERSIAL("controversial", "Controversial"),
RELEVANCE("relevance", "Relevance"), RELEVANCE("relevance", "Relevance"),
COMMENTS("comments", "Comments"), COMMENTS("comments", "Comments"),

View File

@ -5,13 +5,9 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
import eu.toldi.infinityforlemmy.apis.LemmyAPI; import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.apis.RedditAPI; import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
import eu.toldi.infinityforlemmy.dto.VoteDTO; import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -22,14 +18,13 @@ import retrofit2.Retrofit;
public class VoteThing { 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 VoteThingListener voteThingListener, final int postID,
final int point, final int position) { final int point, final int position) {
LemmyAPI api = retrofit.create(LemmyAPI.class); LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> voteThingCall = api.postLike(new PostVoteDTO(postID, point, accessToken));
Call<String> voteThingCall = api.postLike(new VoteDTO(postID,point,accessToken));
voteThingCall.enqueue(new Callback<String>() { voteThingCall.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) { 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 VoteThingWithoutPositionListener voteThingWithoutPositionListener,
final String fullName, final String point) { final int postID, final int point) {
RedditAPI api = retrofit.create(RedditAPI.class); 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>() { voteThingCall.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) { 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) { public void deleteComment(String fullName, int position) {
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {
@ -779,14 +771,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT), data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
data.getExtras().getInt(EditCommentActivity.EXTRA_EDITED_COMMENT_POSITION)); 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) { } else if (requestCode == CommentActivity.WRITE_COMMENT_REQUEST_CODE) {
if (data != null && resultCode == Activity.RESULT_OK) { if (data != null && resultCode == Activity.RESULT_OK) {
if (data.hasExtra(RETURN_EXTRA_COMMENT_DATA_KEY)) { 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.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -61,14 +60,6 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; 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.ActivityToolbarInterface;
import eu.toldi.infinityforlemmy.AppBarStateChangeListener; import eu.toldi.infinityforlemmy.AppBarStateChangeListener;
import eu.toldi.infinityforlemmy.DeleteThing; import eu.toldi.infinityforlemmy.DeleteThing;
@ -77,6 +68,7 @@ import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
import eu.toldi.infinityforlemmy.R; import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RecyclerViewContentScrollingInterface; import eu.toldi.infinityforlemmy.RecyclerViewContentScrollingInterface;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase; import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SortType; import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback; import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
import eu.toldi.infinityforlemmy.adapters.SubredditAutocompleteRecyclerViewAdapter; 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.asynctasks.SwitchAccount;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CopyTextBottomSheetFragment; import eu.toldi.infinityforlemmy.bottomsheetfragments.CopyTextBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.FABMoreOptionsBottomSheetFragment; import eu.toldi.infinityforlemmy.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.KarmaInfoBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostLayoutBottomSheetFragment; import eu.toldi.infinityforlemmy.bottomsheetfragments.PostLayoutBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostTypeBottomSheetFragment; import eu.toldi.infinityforlemmy.bottomsheetfragments.PostTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.RandomBottomSheetFragment; 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.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 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 pl.droidsonroids.gif.GifImageView;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
@ -1216,14 +1214,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (requestCode == GIVE_AWARD_REQUEST_CODE) { if (requestCode == EDIT_COMMENT_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 (data != null) { if (data != null) {
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.editComment( 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) { void editComment(String commentMarkdown, int position) {
if (fragmentManager != null) { if (fragmentManager != null) {

View File

@ -30,12 +30,6 @@ import java.util.Locale;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; 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.NetworkState;
import eu.toldi.infinityforlemmy.R; import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.SaveThing; 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.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 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; import retrofit2.Retrofit;
public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment, RecyclerView.ViewHolder> { public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment, RecyclerView.ViewHolder> {
@ -189,17 +189,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (holder instanceof CommentViewHolder) { if (holder instanceof CommentViewHolder) {
Comment comment = getItem(holder.getBindingAdapterPosition()); Comment comment = getItem(holder.getBindingAdapterPosition());
if (comment != null) { if (comment != null) {
String name = "r/" + comment.getSubredditName(); String name = "r/" + comment.getCommunityName();
((CommentViewHolder) holder).authorTextView.setText(name); ((CommentViewHolder) holder).authorTextView.setText(name);
((CommentViewHolder) holder).authorTextView.setTextColor(mSubredditColor); ((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) { if (mShowElapsedTime) {
((CommentViewHolder) holder).commentTimeTextView.setText( ((CommentViewHolder) holder).commentTimeTextView.setText(
@ -208,22 +201,13 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern)); ((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()); ((CommentViewHolder) holder).markwonAdapter.setMarkdown(mMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged // noinspection NotifyDataSetChanged
((CommentViewHolder) holder).markwonAdapter.notifyDataSetChanged(); ((CommentViewHolder) holder).markwonAdapter.notifyDataSetChanged();
String commentText = ""; String commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
if (comment.isScoreHidden()) {
commentText = mActivity.getString(R.string.hidden);
} else {
commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()); comment.getScore() + comment.getVoteType());
}
((CommentViewHolder) holder).scoreTextView.setText(commentText); ((CommentViewHolder) holder).scoreTextView.setText(commentText);
switch (comment.getVoteType()) { 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) { public void editComment(String commentContentMarkdown, int position) {
Comment comment = getItem(position); Comment comment = getItem(position);
if (comment != null) { if (comment != null) {
@ -461,7 +435,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
Comment comment = getItem(getBindingAdapterPosition()); Comment comment = getItem(getBindingAdapterPosition());
if (comment != null) { if (comment != null) {
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); 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); mActivity.startActivity(intent);
} }
}); });
@ -557,12 +531,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
scoreTextView.setTextColor(mCommentIconAndInfoColor); scoreTextView.setTextColor(mCommentIconAndInfoColor);
} }
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition(); int currentPosition = getBindingAdapterPosition();
@ -582,10 +556,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (currentPosition == position) { if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
}
} }
} }
@ -627,12 +601,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
scoreTextView.setTextColor(mCommentIconAndInfoColor); scoreTextView.setTextColor(mCommentIconAndInfoColor);
} }
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
}
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition(); int currentPosition = getBindingAdapterPosition();
@ -652,10 +626,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (currentPosition == position) { if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden()) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
}
} }
} }

View File

@ -38,13 +38,6 @@ import java.util.concurrent.Executor;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; 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.R;
import eu.toldi.infinityforlemmy.SaveThing; import eu.toldi.infinityforlemmy.SaveThing;
import eu.toldi.infinityforlemmy.SortType; 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.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 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; import retrofit2.Retrofit;
public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -100,7 +100,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private Locale mLocale; private Locale mLocale;
private RequestManager mGlide; private RequestManager mGlide;
private RecyclerView.RecycledViewPool recycledViewPool; private RecyclerView.RecycledViewPool recycledViewPool;
private String mSingleCommentId; private Integer mSingleCommentId;
private boolean mIsSingleCommentThreadMode; private boolean mIsSingleCommentThreadMode;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
@ -157,7 +157,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
CustomThemeWrapper customThemeWrapper, CustomThemeWrapper customThemeWrapper,
Executor executor, Retrofit retrofit, Retrofit oauthRetrofit, Executor executor, Retrofit retrofit, Retrofit oauthRetrofit,
String accessToken, String accountName, String accessToken, String accountName,
Post post, Locale locale, String singleCommentId, Post post, Locale locale, Integer singleCommentId,
boolean isSingleCommentThreadMode, boolean isSingleCommentThreadMode,
SharedPreferences sharedPreferences, SharedPreferences sharedPreferences,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) { CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
@ -359,22 +359,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (holder instanceof CommentViewHolder) { if (holder instanceof CommentViewHolder) {
Comment comment = getCurrentComment(position); Comment comment = getCurrentComment(position);
if (comment != null) { if (comment != null) {
if (mIsSingleCommentThreadMode && String.valueOf(comment.getId()).equals(mSingleCommentId)) { if (mIsSingleCommentThreadMode && comment.getId() == mSingleCommentId) {
holder.itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor); 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); ((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()) { if (comment.isSubmitter()) {
((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor); ((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
@ -433,10 +424,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE); ((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()); ((CommentViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged // noinspection NotifyDataSetChanged
@ -445,15 +432,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (!mHideTheNumberOfVotes) { if (!mHideTheNumberOfVotes) {
String commentText = ""; String commentText = "";
String topScoreText = ""; String topScoreText = "";
if (comment.isScoreHidden()) {
commentText = mActivity.getString(R.string.hidden);
} else {
commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes, commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()); comment.getScore() + comment.getVoteType());
topScoreText = mActivity.getString(R.string.top_score, topScoreText = mActivity.getString(R.string.top_score,
Utils.getNVotes(mShowAbsoluteNumberOfVotes, Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
}
((CommentViewHolder) holder).scoreTextView.setText(commentText); ((CommentViewHolder) holder).scoreTextView.setText(commentText);
((CommentViewHolder) holder).topScoreTextView.setText(topScoreText); ((CommentViewHolder) holder).topScoreTextView.setText(topScoreText);
} else { } else {
@ -578,10 +563,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else { } else {
((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern)); ((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
} }
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) { if (mHideTheNumberOfVotes) {
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.top_score,
Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType())));
} else if (mHideTheNumberOfVotes) {
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote)); ((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote));
} else { } else {
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.hidden)); ((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.hidden));
@ -635,7 +617,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override @Override
public void onFetchMoreCommentSuccess(ArrayList<Comment> topLevelComments, public void onFetchMoreCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments, ArrayList<Comment> expandedComments,
ArrayList<String> moreChildrenIds) { ArrayList<Integer> moreChildrenIds) {
if (mVisibleComments.size() > parentPosition if (mVisibleComments.size() > parentPosition
&& parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) { && parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) {
if (mVisibleComments.get(parentPosition).isExpanded()) { 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 * Find position of comment with given {@code fullName} and
* {@link Comment#NOT_PLACEHOLDER} placeholder type * {@link Comment#NOT_PLACEHOLDER} placeholder type
*
* @return position of the placeholder or -1 if not found * @return position of the placeholder or -1 if not found
*/ */
private int findCommentPosition(String fullName, int positionHint) { 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 * Find position of comment with given {@code fullName} and
* {@link Comment#PLACEHOLDER_LOAD_MORE_COMMENTS} placeholder type * {@link Comment#PLACEHOLDER_LOAD_MORE_COMMENTS} placeholder type
*
* @return position of the placeholder or -1 if not found * @return position of the placeholder or -1 if not found
*/ */
private int findLoadMoreCommentsPlaceholderPosition(String fullName, int positionHint) { 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; mSingleCommentId = singleCommentId;
mIsSingleCommentThreadMode = isSingleCommentThreadMode; 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) { public void setSaveComment(int position, boolean isSaved) {
Comment comment = getCurrentComment(position); Comment comment = getCurrentComment(position);
if (comment != null) { if (comment != null) {
@ -1416,7 +1391,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
topScoreTextView.setTextColor(mSecondaryTextColor); topScoreTextView.setTextColor(mSecondaryTextColor);
} }
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) { if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score, topScoreTextView.setText(mActivity.getString(R.string.top_score,
@ -1424,7 +1399,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
comment.getScore() + comment.getVoteType()))); comment.getScore() + comment.getVoteType())));
} }
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteComment(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position) { public void onVoteThingSuccess(int position) {
int currentPosition = getBindingAdapterPosition(); int currentPosition = getBindingAdapterPosition();
@ -1446,7 +1421,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (currentPosition == position) { if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) { if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score, topScoreTextView.setText(mActivity.getString(R.string.top_score,
@ -1497,7 +1472,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
topScoreTextView.setTextColor(mSecondaryTextColor); topScoreTextView.setTextColor(mSecondaryTextColor);
} }
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) { if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score, topScoreTextView.setText(mActivity.getString(R.string.top_score,
@ -1506,7 +1481,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} }
int position = getBindingAdapterPosition(); int position = getBindingAdapterPosition();
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteComment(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition(); int currentPosition = getBindingAdapterPosition();
@ -1528,7 +1503,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (currentPosition == position) { if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) { if (!mHideTheNumberOfVotes) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
topScoreTextView.setText(mActivity.getString(R.string.top_score, topScoreTextView.setText(mActivity.getString(R.string.top_score,

View File

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

View File

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

View File

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

View File

@ -3,7 +3,8 @@ package eu.toldi.infinityforlemmy.apis;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO; 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.Call;
import retrofit2.Response; import retrofit2.Response;
import retrofit2.http.Body; import retrofit2.http.Body;
@ -54,5 +55,24 @@ public interface LemmyAPI {
@Headers("Content-Type: application/json") @Headers("Content-Type: application/json")
@POST("api/v3/post/like") @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 -> { reportTextView.setOnClickListener(view -> {
Intent intent = new Intent(activity, ReportActivity.class); 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()); intent.putExtra(ReportActivity.EXTRA_THING_FULLNAME, comment.getFullName());
activity.startActivity(intent); activity.startActivity(intent);

View File

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

View File

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

View File

@ -20,7 +20,7 @@ public class FetchRemovedCommentReveddit {
public static void fetchRemovedComment(Executor executor, Handler handler, Retrofit retrofit, Comment comment, public static void fetchRemovedComment(Executor executor, Handler handler, Retrofit retrofit, Comment comment,
long postCreatedUtc, int nComments, FetchRemovedCommentListener listener) { long postCreatedUtc, int nComments, FetchRemovedCommentListener listener) {
executor.execute(() -> { 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; String rootCommentId = parentIdWithoutPrefix.equals(comment.getLinkId()) ? String.valueOf(comment.getId()) : parentIdWithoutPrefix;
try { try {
Response<String> response = retrofit.create(RevedditAPI.class).getRemovedComments( Response<String> response = retrofit.create(RevedditAPI.class).getRemovedComments(

View File

@ -1,11 +1,6 @@
package eu.toldi.infinityforlemmy.comment; 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.os.Handler;
import android.text.Html;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -14,29 +9,44 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import eu.toldi.infinityforlemmy.utils.JSONUtils; import eu.toldi.infinityforlemmy.utils.JSONUtils;
import eu.toldi.infinityforlemmy.utils.Utils; import eu.toldi.infinityforlemmy.utils.LemmyUtils;
public class ParseComment { 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, boolean expandChildren,
ParseCommentListener parseCommentListener) { ParseCommentListener parseCommentListener) {
executor.execute(() -> { executor.execute(() -> {
try { try {
JSONArray childrenArray = new JSONArray(response); JSONArray childrenArray = new JSONObject(response).getJSONArray("comments");
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);
ArrayList<Comment> expandedNewComments = new ArrayList<>(); ArrayList<Comment> expandedNewComments = new ArrayList<>();
ArrayList<String> moreChildrenIds = new ArrayList<>(); ArrayList<Integer> moreChildrenIds = new ArrayList<>();
ArrayList<Comment> newComments = 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); expandChildren(newComments, expandedNewComments, expandChildren);
ArrayList<Comment> commentData; ArrayList<Comment> commentData;
@ -46,7 +56,7 @@ public class ParseComment {
commentData = newComments; 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) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
handler.post(parseCommentListener::onParseCommentFailed); 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, static void parseMoreComment(Executor executor, Handler handler, String response, boolean expandChildren,
ParseCommentListener parseCommentListener) { ParseCommentListener parseCommentListener) {
executor.execute(() -> { executor.execute(() -> {
@ -63,7 +77,7 @@ public class ParseComment {
ArrayList<Comment> newComments = new ArrayList<>(); ArrayList<Comment> newComments = new ArrayList<>();
ArrayList<Comment> expandedNewComments = 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 // api response is a flat list of comments tree
// process it in order and rebuild the tree // process it in order and rebuild the tree
@ -71,13 +85,13 @@ public class ParseComment {
JSONObject child = childrenArray.getJSONObject(i); JSONObject child = childrenArray.getJSONObject(i);
JSONObject childData = child.getJSONObject(JSONUtils.DATA_KEY); JSONObject childData = child.getJSONObject(JSONUtils.DATA_KEY);
if (child.getString(JSONUtils.KIND_KEY).equals(JSONUtils.KIND_VALUE_MORE)) { 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); JSONArray childrenIds = childData.getJSONArray(JSONUtils.CHILDREN_KEY);
if (childrenIds.length() != 0) { 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++) { for (int j = 0; j < childrenIds.length(); j++) {
localMoreChildrenIds.add(childrenIds.getString(j)); localMoreChildrenIds.add(childrenIds.getInt(j));
} }
Comment parentComment = findCommentByFullName(newComments, parentFullName); Comment parentComment = findCommentByFullName(newComments, parentFullName);
@ -90,13 +104,15 @@ public class ParseComment {
moreChildrenIds.addAll(localMoreChildrenIds); moreChildrenIds.addAll(localMoreChildrenIds);
} }
} else { } else {
Comment parentComment = findCommentByFullName(newComments, parentFullName);
Comment continueThreadPlaceholder = new Comment( Comment continueThreadPlaceholder = new Comment(
parentFullName, parentComment.getFullName(),
childData.getInt(JSONUtils.DEPTH_KEY), childData.getInt(JSONUtils.DEPTH_KEY),
Comment.PLACEHOLDER_CONTINUE_THREAD Comment.PLACEHOLDER_CONTINUE_THREAD,
parentComment.getId()
); );
Comment parentComment = findCommentByFullName(newComments, parentFullName);
if (parentComment != null) { if (parentComment != null) {
parentComment.setHasReply(true); parentComment.setHasReply(true);
parentComment.addChild(continueThreadPlaceholder, parentComment.getChildCount()); parentComment.addChild(continueThreadPlaceholder, parentComment.getChildCount());
@ -107,8 +123,8 @@ public class ParseComment {
} }
} }
} else { } else {
Comment comment = parseSingleComment(childData, 0); Comment comment = parseSingleComment(childData);
String parentFullName = comment.getParentId(); Integer parentFullName = comment.getParentId();
Comment parentComment = findCommentByFullName(newComments, parentFullName); Comment parentComment = findCommentByFullName(newComments, parentFullName);
if (parentComment != null) { if (parentComment != null) {
@ -145,7 +161,7 @@ public class ParseComment {
executor.execute(() -> { executor.execute(() -> {
try { try {
JSONObject sentCommentData = new JSONObject(response); JSONObject sentCommentData = new JSONObject(response);
Comment comment = parseSingleComment(sentCommentData, depth); Comment comment = parseSingleComment(sentCommentData);
handler.post(() -> parseSentCommentListener.onParseSentCommentSuccess(comment)); handler.post(() -> parseSentCommentListener.onParseSentCommentSuccess(comment));
} catch (JSONException e) { } catch (JSONException e) {
@ -177,7 +193,7 @@ public class ParseComment {
actualCommentLength = comments.length() - 1; actualCommentLength = comments.length() - 1;
if (moreChildrenIds.isEmpty() && comments.getJSONObject(comments.length() - 1).getString(JSONUtils.KIND_KEY).equals(JSONUtils.KIND_VALUE_MORE)) { 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; return;
} }
} else { } else {
@ -186,19 +202,7 @@ public class ParseComment {
for (int i = 0; i < actualCommentLength; i++) { for (int i = 0; i < actualCommentLength; i++) {
JSONObject data = comments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); JSONObject data = comments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
Comment singleComment = parseSingleComment(data, depth); Comment singleComment = parseSingleComment(data);
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));
}
newCommentData.add(singleComment); newCommentData.add(singleComment);
} }
} }
@ -228,89 +232,60 @@ public class ParseComment {
} }
if (c.hasMoreChildrenIds() && !c.getMoreChildrenIds().isEmpty()) { if (c.hasMoreChildrenIds() && !c.getMoreChildrenIds().isEmpty()) {
//Add a load more placeholder //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); visibleComments.add(placeholder);
c.addChild(placeholder, c.getChildren().size()); c.addChild(placeholder, c.getChildren().size());
} }
} }
} }
static Comment parseSingleComment(JSONObject singleCommentData, int depth) throws JSONException { public static Comment parseSingleComment(JSONObject jsonObject) throws JSONException {
String id = singleCommentData.getString(JSONUtils.ID_KEY); JSONObject commentObj = jsonObject.getJSONObject("comment");
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY); JSONObject creatorObj = jsonObject.getJSONObject("creator");
String author = singleCommentData.getString(JSONUtils.AUTHOR_KEY); JSONObject postObj = jsonObject.getJSONObject("post");
StringBuilder authorFlairHTMLBuilder = new StringBuilder(); JSONObject communityObj = jsonObject.getJSONObject("community");
if (singleCommentData.has(JSONUtils.AUTHOR_FLAIR_RICHTEXT_KEY)) { JSONObject countsObj = jsonObject.getJSONObject("counts");
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);
if (singleCommentData.has(JSONUtils.DEPTH_KEY)) { int id = commentObj.getInt("id");
depth = singleCommentData.getInt(JSONUtils.DEPTH_KEY); 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 @Nullable
private static String parseSentCommentErrorMessage(String response) { private static String parseSentCommentErrorMessage(String response) {
@ -341,10 +316,51 @@ public class ParseComment {
return null; 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 @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) { for (Comment comment : comments) {
if (comment.getFullName().equals(fullName) && if (comment.getId() == fullName &&
comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) { comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) {
return comment; return comment;
} }
@ -368,8 +384,8 @@ public class ParseComment {
} }
public interface ParseCommentListener { public interface ParseCommentListener {
void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, String parentId, void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, Integer parentId,
ArrayList<String> moreChildrenIds); ArrayList<Integer> moreChildrenIds);
void onParseCommentFailed(); 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; package eu.toldi.infinityforlemmy.dto;
public class VoteDTO { public class PostVoteDTO {
private final int post_id; private final int post_id;
private final int score; private final int score;
private final String auth; 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.post_id = post_id;
this.score = vote; this.score = vote;
this.auth = auth; this.auth = auth;

View File

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

View File

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

View File

@ -261,7 +261,7 @@
<string name="search_in">Search in</string> <string name="search_in">Search in</string>
<string name="all_subreddits">All subreddits</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_hot">Hot</string>
<string name="sort_new">New</string> <string name="sort_new">New</string>
<string name="sort_random">Random</string> <string name="sort_random">Random</string>