diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 6ba09d504..9a0f93b52 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -39,7 +39,6 @@ public class GlobalUserPreferences{ public static boolean showNewPostsButton; public static boolean toolbarMarquee; public static boolean disableSwipe; - public static boolean voteButtonForSingleChoice; public static boolean enableDeleteNotifications; public static boolean translateButtonOpenedOnly; public static boolean uniformNotificationIcon; @@ -99,7 +98,6 @@ public class GlobalUserPreferences{ showNewPostsButton=prefs.getBoolean("showNewPostsButton", true); toolbarMarquee=prefs.getBoolean("toolbarMarquee", true); disableSwipe=prefs.getBoolean("disableSwipe", false); - voteButtonForSingleChoice=prefs.getBoolean("voteButtonForSingleChoice", true); enableDeleteNotifications=prefs.getBoolean("enableDeleteNotifications", false); translateButtonOpenedOnly=prefs.getBoolean("translateButtonOpenedOnly", false); uniformNotificationIcon=prefs.getBoolean("uniformNotificationIcon", false); 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 390033bf3..590c98c12 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -516,7 +516,8 @@ public abstract class BaseStatusListFragment exten public void onPollOptionClick(PollOptionStatusDisplayItem.Holder holder){ Poll poll=holder.getItem().poll; Poll.Option option=holder.getItem().option; - if(poll.multiple || GlobalUserPreferences.voteButtonForSingleChoice){ + // MEGALODON: always show vote button +// if(poll.multiple){ if(poll.selectedOptions==null) poll.selectedOptions=new ArrayList<>(); boolean optionContained=poll.selectedOptions.contains(option); @@ -531,7 +532,7 @@ public abstract class BaseStatusListFragment exten for(int i=0;i exten } } } - }else{ - submitPollVote(holder.getItemID(), poll.id, Collections.singletonList(poll.options.indexOf(option))); - } +// }else{ +// submitPollVote(holder.getItemID(), poll.id, Collections.singletonList(poll.options.indexOf(option))); +// } } public void onPollVoteButtonClick(PollFooterStatusDisplayItem.Holder holder){ @@ -550,6 +551,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 2ec373335..fbfba530d 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 @@ -6,7 +6,6 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; -import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.model.Poll; @@ -14,6 +13,7 @@ import org.joinmastodon.android.ui.utils.UiUtils; public class PollFooterStatusDisplayItem extends StatusDisplayItem{ public final Poll poll; + public boolean resultsVisible=false; public PollFooterStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, Poll poll){ super(parentID, parentFragment); @@ -27,29 +27,40 @@ public class PollFooterStatusDisplayItem extends StatusDisplayItem{ public static class Holder extends StatusDisplayItem.Holder{ private TextView text; - private Button button; + private Button voteButton, resultsButton; + private ViewGroup wrapper; 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); + wrapper=findViewById(R.id.wrapper); + resultsButton.setOnClickListener(v-> { + item.resultsVisible = !item.resultsVisible; + item.parentFragment.onPollViewResultsButtonClick(this, item.resultsVisible); + rebind(); + UiUtils.beginLayoutTransition(wrapper); + }); } @Override public void onBind(PollFooterStatusDisplayItem item){ String text=item.parentFragment.getResources().getQuantityString(R.plurals.x_votes, item.poll.votesCount, item.poll.votesCount); - String sep=item.parentFragment.getString(R.string.sk_separator); - if(item.poll.expiresAt!=null && !item.poll.isExpired()){ - text+=" "+sep+" "+UiUtils.formatTimeLeft(itemView.getContext(), item.poll.expiresAt); - if(item.poll.multiple) - text+=" "+sep+" "+item.parentFragment.getString(R.string.poll_multiple_choice); - }else if(item.poll.isExpired()){ - text+=" "+sep+" "+item.parentFragment.getString(R.string.poll_closed); - } + String sep=" "+item.parentFragment.getString(R.string.sk_separator)+" "; + if(item.poll.expiresAt!=null && !item.poll.isExpired()) + text+=sep+UiUtils.formatTimeLeft(itemView.getContext(), item.poll.expiresAt).replaceAll(" ", " "); + else if(item.poll.isExpired()) + text+=sep+item.parentFragment.getString(R.string.poll_closed).replaceAll(" ", " "); + if(item.poll.multiple) + text+=sep+item.parentFragment.getString(R.string.sk_poll_multiple_choice).replaceAll(" ", " "); 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.setVisibility(item.poll.isExpired() || item.poll.voted ? View.GONE : View.VISIBLE); + resultsButton.setText(item.resultsVisible ? R.string.sk_poll_hide_results : R.string.sk_poll_show_results); + resultsButton.setSelected(item.resultsVisible); + voteButton.setVisibility(item.poll.isExpired() || item.poll.voted ? 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 3a875b06c..434709e1c 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 @@ -17,6 +17,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; @@ -44,6 +45,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; @@ -135,5 +140,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..406d559d5 100644 --- a/mastodon/src/main/res/layout/display_item_poll_footer.xml +++ b/mastodon/src/main/res/layout/display_item_poll_footer.xml @@ -6,18 +6,38 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + android:layout_height="wrap_content"> + + + +