Fix an issue with poll and Pleroma

This commit is contained in:
Thomas 2023-12-22 15:31:35 +01:00
parent 6b876158d5
commit 6ee9601e23
1 changed files with 46 additions and 75 deletions

View File

@ -57,7 +57,6 @@ import android.os.Looper;
import android.text.Html;
import android.text.SpannableString;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -303,51 +302,35 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
boolean remote) {
if (statusReturned == null) {
switch (typeOfAction) {
case BOOKMARK_ACTION:
statusToDeal.bookmarked = true;
break;
case REBLOG_ACTION:
case BOOKMARK_ACTION -> statusToDeal.bookmarked = true;
case REBLOG_ACTION -> {
statusToDeal.reblogged = true;
statusToDeal.reblogs_count++;
break;
case FAVOURITE_ACTION:
}
case FAVOURITE_ACTION -> {
statusToDeal.favourited = true;
statusToDeal.favourites_count++;
break;
case UNBOOKMARK_ACTION:
statusToDeal.bookmarked = false;
break;
case UNREBLOG_ACTION:
}
case UNBOOKMARK_ACTION -> statusToDeal.bookmarked = false;
case UNREBLOG_ACTION -> {
statusToDeal.reblogged = false;
statusToDeal.reblogs_count--;
break;
case UNFAVOURITE_ACTION:
}
case UNFAVOURITE_ACTION -> {
statusToDeal.favourited = false;
statusToDeal.favourites_count--;
break;
}
}
} else {
boolean isOK = true;
switch (typeOfAction) {
case BOOKMARK_ACTION:
isOK = statusReturned.bookmarked;
break;
case REBLOG_ACTION:
isOK = statusReturned.reblogged;
break;
case FAVOURITE_ACTION:
isOK = statusReturned.favourited;
break;
case UNBOOKMARK_ACTION:
isOK = !statusReturned.bookmarked;
break;
case UNREBLOG_ACTION:
isOK = !statusReturned.reblogged;
break;
case UNFAVOURITE_ACTION:
isOK = !statusReturned.favourited;
break;
}
boolean isOK = switch (typeOfAction) {
case BOOKMARK_ACTION -> statusReturned.bookmarked;
case REBLOG_ACTION -> statusReturned.reblogged;
case FAVOURITE_ACTION -> statusReturned.favourited;
case UNBOOKMARK_ACTION -> !statusReturned.bookmarked;
case UNREBLOG_ACTION -> !statusReturned.reblogged;
case UNFAVOURITE_ACTION -> !statusReturned.favourited;
default -> true;
};
if (!isOK) {
Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
return;
@ -367,18 +350,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
} else {
switch (typeOfAction) {
case REBLOG_ACTION:
statusToDeal.reblogs_count++;
break;
case FAVOURITE_ACTION:
statusToDeal.favourites_count++;
break;
case UNREBLOG_ACTION:
statusToDeal.reblogs_count--;
break;
case UNFAVOURITE_ACTION:
statusToDeal.favourites_count--;
break;
case REBLOG_ACTION -> statusToDeal.reblogs_count++;
case FAVOURITE_ACTION -> statusToDeal.favourites_count++;
case UNREBLOG_ACTION -> statusToDeal.reblogs_count--;
case UNFAVOURITE_ACTION -> statusToDeal.favourites_count--;
}
}
}
@ -770,12 +745,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.statusContentMaths.removeAllViews();
MathJaxConfig mathJaxConfig = new MathJaxConfig();
switch (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES:
mathJaxConfig.setTextColor("white");
break;
case Configuration.UI_MODE_NIGHT_NO:
mathJaxConfig.setTextColor("black");
break;
case Configuration.UI_MODE_NIGHT_YES -> mathJaxConfig.setTextColor("white");
case Configuration.UI_MODE_NIGHT_NO -> mathJaxConfig.setTextColor("black");
}
mathJaxConfig.setAutomaticLinebreaks(true);
@ -1021,9 +992,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (needToWarnForMissingDescription) {
AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(context);
alt_bld.setMessage(context.getString(R.string.reblog_missing_description));
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, null, statusToDeal);
});
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, null, statusToDeal));
alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alert = alt_bld.create();
alert.show();
@ -1246,21 +1215,21 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.visibility.setContentDescription(context.getString(R.string.v_public));
holder.binding.visibilitySmall.setContentDescription(context.getString(R.string.v_public));
switch (status.visibility) {
case "unlisted":
case "unlisted" -> {
holder.binding.visibility.setContentDescription(context.getString(R.string.v_unlisted));
holder.binding.visibilitySmall.setContentDescription(context.getString(R.string.v_unlisted));
ressource = R.drawable.ic_baseline_lock_open_24;
break;
case "private":
}
case "private" -> {
ressource = R.drawable.ic_baseline_lock_24;
holder.binding.visibility.setContentDescription(context.getString(R.string.v_private));
holder.binding.visibilitySmall.setContentDescription(context.getString(R.string.v_private));
break;
case "direct":
}
case "direct" -> {
ressource = R.drawable.ic_baseline_mail_24;
holder.binding.visibility.setContentDescription(context.getString(R.string.v_direct));
holder.binding.visibilitySmall.setContentDescription(context.getString(R.string.v_direct));
break;
}
}
if (statusToDeal.local_only) {
@ -1414,20 +1383,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
//--- BOOST VISIBILITY ---
switch (statusToDeal.visibility) {
case "public":
case "unlisted":
holder.binding.actionButtonBoost.setVisibility(View.VISIBLE);
break;
case "private":
case "public", "unlisted" ->
holder.binding.actionButtonBoost.setVisibility(View.VISIBLE);
case "private" -> {
if (status.account.id.compareTo(BaseMainActivity.currentUserID) == 0) {
holder.binding.actionButtonBoost.setVisibility(View.VISIBLE);
} else {
holder.binding.actionButtonBoost.setVisibility(View.GONE);
}
break;
case "direct":
holder.binding.actionButtonBoost.setVisibility(View.GONE);
break;
}
case "direct" -> holder.binding.actionButtonBoost.setVisibility(View.GONE);
}
//--- MAIN CONTENT ---
@ -1815,6 +1780,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
// --- POLL ---
if (statusToDeal.poll != null && statusToDeal.poll.options != null) {
int normalize;
if(statusToDeal.poll.multiple && statusToDeal.poll.voters_count != 0) {
normalize = statusToDeal.poll.voters_count;
} else {
normalize = statusToDeal.poll.votes_count;
}
if (statusToDeal.poll.voted || statusToDeal.poll.expired) {
holder.binding.poll.submitVote.setVisibility(View.GONE);
holder.binding.poll.rated.setVisibility(View.VISIBLE);
@ -1833,7 +1804,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
for (Poll.PollItem pollItem : statusToDeal.poll.options) {
@NonNull LayoutPollItemBinding pollItemBinding = LayoutPollItemBinding.inflate(inflater, holder.binding.poll.rated, true);
double value = Math.round((pollItem.votes_count * 100) / (double) statusToDeal.poll.voters_count);
double value = Math.round((pollItem.votes_count * 100) / (double) normalize);
pollItemBinding.pollItemPercent.setText(String.format("%s %%", (int) value));
pollItemBinding.pollItemText.setText(
pollItem.getSpanTitle(context, statusToDeal,
@ -1986,7 +1957,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
}));
holder.binding.poll.pollContainer.setVisibility(View.VISIBLE);
String pollInfo = context.getResources().getQuantityString(R.plurals.number_of_voters, statusToDeal.poll.voters_count, statusToDeal.poll.voters_count);
String pollInfo = context.getResources().getQuantityString(R.plurals.number_of_voters, normalize, normalize);
if (statusToDeal.poll.expired) {
pollInfo += " - " + context.getString(R.string.poll_finish_at, MastodonHelper.dateToStringPoll(statusToDeal.poll.expires_at));
} else {
@ -2783,7 +2754,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (id != null) {
b.putString(type, id);
}
if (type == ARG_TIMELINE_REFRESH_ALL) {
if (type.equals(ARG_TIMELINE_REFRESH_ALL)) {
b.putBoolean(ARG_TIMELINE_REFRESH_ALL, true);
}
Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION);