Fix poll expiration

fixes #238, fixes #417
This commit is contained in:
Grishka
2022-11-26 20:13:46 +03:00
parent 2cabe94ba0
commit 62411a563f
3 changed files with 9 additions and 5 deletions

View File

@@ -13,7 +13,7 @@ public class Poll extends BaseModel{
@RequiredField @RequiredField
public String id; public String id;
public Instant expiresAt; public Instant expiresAt;
public boolean expired; private boolean expired;
public boolean multiple; public boolean multiple;
public int votersCount; public int votersCount;
public boolean voted; public boolean voted;
@@ -48,6 +48,10 @@ public class Poll extends BaseModel{
'}'; '}';
} }
public boolean isExpired(){
return expired || expiresAt.isBefore(Instant.now());
}
@Parcel @Parcel
public static class Option{ public static class Option{
public String title; public String title;

View File

@@ -38,13 +38,13 @@ public class PollFooterStatusDisplayItem extends StatusDisplayItem{
@Override @Override
public void onBind(PollFooterStatusDisplayItem item){ public void onBind(PollFooterStatusDisplayItem item){
String text=item.parentFragment.getResources().getQuantityString(R.plurals.x_voters, item.poll.votersCount, item.poll.votersCount); String text=item.parentFragment.getResources().getQuantityString(R.plurals.x_voters, item.poll.votersCount, item.poll.votersCount);
if(item.poll.expiresAt!=null && !item.poll.expired){ if(item.poll.expiresAt!=null && !item.poll.isExpired()){
text+=" · "+UiUtils.formatTimeLeft(itemView.getContext(), item.poll.expiresAt); text+=" · "+UiUtils.formatTimeLeft(itemView.getContext(), item.poll.expiresAt);
}else if(item.poll.expired){ }else if(item.poll.isExpired()){
text+=" · "+item.parentFragment.getString(R.string.poll_closed); text+=" · "+item.parentFragment.getString(R.string.poll_closed);
} }
this.text.setText(text); this.text.setText(text);
button.setVisibility(item.poll.expired || item.poll.voted || !item.poll.multiple ? View.GONE : View.VISIBLE); button.setVisibility(item.poll.isExpired() || item.poll.voted || !item.poll.multiple ? View.GONE : View.VISIBLE);
button.setEnabled(item.poll.selectedOptions!=null && !item.poll.selectedOptions.isEmpty()); button.setEnabled(item.poll.selectedOptions!=null && !item.poll.selectedOptions.isEmpty());
} }
} }

View File

@@ -33,7 +33,7 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
this.poll=poll; this.poll=poll;
text=HtmlParser.parseCustomEmoji(option.title, poll.emojis); text=HtmlParser.parseCustomEmoji(option.title, poll.emojis);
emojiHelper.setText(text); emojiHelper.setText(text);
showResults=poll.expired || poll.voted; showResults=poll.isExpired() || poll.voted;
if(showResults && option.votesCount!=null && poll.votersCount>0){ if(showResults && option.votesCount!=null && poll.votersCount>0){
votesFraction=(float)option.votesCount/(float)poll.votersCount; votesFraction=(float)option.votesCount/(float)poll.votersCount;
int mostVotedCount=0; int mostVotedCount=0;