Merge branch 'feat/view-poll-results'
# Conflicts: # mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollFooterStatusDisplayItem.java
This commit is contained in:
commit
43fe03c943
|
@ -633,6 +633,14 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> 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<list.getChildCount();i++){
|
||||
if(list.getChildViewHolder(list.getChildAt(i)) instanceof PollOptionStatusDisplayItem.Holder item && item.getItemID().equals(holder.getItemID())){
|
||||
item.showResults(shown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void submitPollVote(String parentID, String pollID, List<Integer> choices){
|
||||
if(refreshing)
|
||||
return;
|
||||
|
|
|
@ -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<PollFooterStatusDisplayItem>{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,16 @@
|
|||
android:textColor="?colorM3OnSurfaceVariant"
|
||||
tools:text="fdsafdsafsdafds"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/results_btn"
|
||||
style="@style/Widget.Mastodon.M3.Button.Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:minHeight="48dp"
|
||||
android:textAppearance="@style/m3_label_small"
|
||||
android:textAllCaps="true"
|
||||
android:text="@string/sk_poll_results"/>
|
||||
<Button
|
||||
android:id="@+id/vote_btn"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -656,4 +656,6 @@
|
|||
<string name="manage_list_members">Manage list members</string>
|
||||
<string name="list_no_members">No members yet</string>
|
||||
<string name="list_find_users">Find users to add</string>
|
||||
<string name="sk_poll_results">View results</string>
|
||||
<string name="sk_poll_view">Hide results</string>
|
||||
</resources>
|
Loading…
Reference in New Issue