diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 126054077..1ece94922 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -633,6 +633,14 @@ public abstract class BaseStatusListFragment exten submitPollVote(holder.getItemID(), poll.id, poll.selectedOptions.stream().map(opt->poll.options.indexOf(opt)).collect(Collectors.toList())); } + public void onPollViewResultsButtonClick(PollFooterStatusDisplayItem.Holder holder, boolean shown){ + for(int i=0;i choices){ if(refreshing) return; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollFooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollFooterStatusDisplayItem.java index 6d86065e0..442372a60 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollFooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollFooterStatusDisplayItem.java @@ -15,6 +15,7 @@ import org.joinmastodon.android.ui.utils.UiUtils; public class PollFooterStatusDisplayItem extends StatusDisplayItem{ public final Poll poll; + public boolean resultsVisible=false; public final Status status; public PollFooterStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, Poll poll, Status status){ @@ -30,13 +31,19 @@ public class PollFooterStatusDisplayItem extends StatusDisplayItem{ public static class Holder extends StatusDisplayItem.Holder{ private TextView text; - private Button button; + private Button voteButton, resultsButton; public Holder(Activity activity, ViewGroup parent){ super(activity, R.layout.display_item_poll_footer, parent); text=findViewById(R.id.text); - button=findViewById(R.id.vote_btn); - button.setOnClickListener(v->item.parentFragment.onPollVoteButtonClick(this)); + voteButton=findViewById(R.id.vote_btn); + voteButton.setOnClickListener(v->item.parentFragment.onPollVoteButtonClick(this)); + resultsButton=findViewById(R.id.results_btn); + resultsButton.setOnClickListener(v-> { + item.resultsVisible = !item.resultsVisible; + item.parentFragment.onPollViewResultsButtonClick(this, item.resultsVisible); + rebind(); + }); } @Override @@ -51,8 +58,9 @@ public class PollFooterStatusDisplayItem extends StatusDisplayItem{ text+=" "+sep+" "+item.parentFragment.getString(R.string.poll_closed); } this.text.setText(text); - button.setVisibility(item.poll.isExpired() || item.poll.voted || (!item.poll.multiple && !GlobalUserPreferences.voteButtonForSingleChoice) ? View.GONE : View.VISIBLE); - button.setEnabled(item.poll.selectedOptions!=null && !item.poll.selectedOptions.isEmpty()); + resultsButton.setText(item.resultsVisible ? R.string.sk_poll_view : R.string.sk_poll_results); + voteButton.setVisibility(item.poll.isExpired() || item.poll.voted || (!item.poll.multiple && !GlobalUserPreferences.voteButtonForSingleChoice) ? View.GONE : View.VISIBLE); + voteButton.setEnabled(item.poll.selectedOptions!=null && !item.poll.selectedOptions.isEmpty() && !item.resultsVisible); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java index 9be62317b..beeea2796 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java @@ -18,6 +18,7 @@ import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.utils.UiUtils; +import java.util.Collections; import java.util.Locale; import me.grishka.appkit.imageloader.ImageLoaderViewHolder; @@ -45,6 +46,10 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{ text=HtmlParser.parseCustomEmoji(option.title, poll.emojis); emojiHelper.setText(text); showResults=poll.isExpired() || poll.voted; + calculateResults(); + } + + private void calculateResults() { int total=poll.votersCount>0 ? poll.votersCount : poll.votesCount; if(showResults && option.votesCount!=null && total>0){ votesFraction=(float)option.votesCount/(float)total; @@ -136,5 +141,11 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{ private void onButtonClick(View v){ item.parentFragment.onPollOptionClick(this); } + + public void showResults(boolean shown) { + item.showResults = shown; + item.calculateResults(); + rebind(); + } } } diff --git a/mastodon/src/main/res/layout/display_item_poll_footer.xml b/mastodon/src/main/res/layout/display_item_poll_footer.xml index 59d4482ab..824f77630 100644 --- a/mastodon/src/main/res/layout/display_item_poll_footer.xml +++ b/mastodon/src/main/res/layout/display_item_poll_footer.xml @@ -19,6 +19,16 @@ android:textColor="?colorM3OnSurfaceVariant" tools:text="fdsafdsafsdafds"/> +