From 4a9cb9f2dcaacd1f304ccb2e3e325e9e15a64a27 Mon Sep 17 00:00:00 2001 From: sk Date: Thu, 8 Dec 2022 15:53:35 +0100 Subject: [PATCH 1/4] fix poll option displaying wrong own vote fixes #132 --- mastodon/src/main/res/layout/display_item_poll_option.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/mastodon/src/main/res/layout/display_item_poll_option.xml b/mastodon/src/main/res/layout/display_item_poll_option.xml index 7d9f53ec7..5747d0f3b 100644 --- a/mastodon/src/main/res/layout/display_item_poll_option.xml +++ b/mastodon/src/main/res/layout/display_item_poll_option.xml @@ -26,7 +26,6 @@ android:layout_height="24dp" android:layout_marginStart="12dp" android:layout_gravity="center_vertical" - android:duplicateParentState="true" android:tint="?colorDarkIcon" android:src="@drawable/ic_poll_option_button"/> From b58074361931b5b4af89f2f5179b920c50978671 Mon Sep 17 00:00:00 2001 From: sk Date: Thu, 8 Dec 2022 16:03:46 +0100 Subject: [PATCH 2/4] fix poll option displaying wrong own vote fixes #132 --- .../android/ui/displayitems/PollOptionStatusDisplayItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 70be9b87b..c16169b04 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 @@ -80,10 +80,10 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{ percent.setVisibility(item.showResults ? View.VISIBLE : View.GONE); itemView.setClickable(!item.showResults); if(item.showResults){ - icon.setSelected(item.poll.ownVotes.contains(item.poll.options.indexOf(item.option))); progressBg.setLevel(Math.round(10000f*item.votesFraction)); button.setBackground(progressBg); itemView.setSelected(item.isMostVoted); + icon.setSelected(item.poll.ownVotes.contains(item.poll.options.indexOf(item.option))); percent.setText(String.format(Locale.getDefault(), "%d%%", Math.round(item.votesFraction*100f))); }else{ itemView.setSelected(item.poll.selectedOptions!=null && item.poll.selectedOptions.contains(item.option)); From 6fd58c96827cb1d2da329cebdc170a1425dd18d7 Mon Sep 17 00:00:00 2001 From: sk Date: Thu, 8 Dec 2022 19:55:46 +0100 Subject: [PATCH 3/4] improve semantics for poll options --- .../ui/displayitems/PollOptionStatusDisplayItem.java | 9 +++++++-- .../drawable/ic_fluent_checkbox_checked_24_filled.xml | 3 +++ .../drawable/ic_fluent_checkbox_checked_24_regular.xml | 3 +++ .../drawable/ic_fluent_checkbox_unchecked_24_filled.xml | 3 +++ .../drawable/ic_fluent_checkbox_unchecked_24_regular.xml | 3 +++ .../res/drawable/ic_fluent_radio_button_24_filled.xml | 3 +++ .../res/drawable/ic_fluent_radio_button_24_selector.xml | 8 ++++++++ .../res/drawable/ic_poll_checkbox_filled_selector.xml | 7 +++++++ .../res/drawable/ic_poll_checkbox_regular_selector.xml | 7 +++++++ 9 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_filled.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_regular.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_filled.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_regular.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_radio_button_24_filled.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_radio_button_24_selector.xml create mode 100644 mastodon/src/main/res/drawable/ic_poll_checkbox_filled_selector.xml create mode 100644 mastodon/src/main/res/drawable/ic_poll_checkbox_regular_selector.xml 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 c16169b04..c00edada3 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 @@ -5,6 +5,7 @@ import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import org.joinmastodon.android.R; @@ -60,7 +61,8 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{ public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ private final TextView text, percent; - private final View icon, button; + private final View button; + private final ImageView icon; private final Drawable progressBg; public Holder(Activity activity, ViewGroup parent){ @@ -76,9 +78,12 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{ @Override public void onBind(PollOptionStatusDisplayItem item){ text.setText(item.text); -// icon.setVisibility(item.showResults ? View.GONE : View.VISIBLE); percent.setVisibility(item.showResults ? View.VISIBLE : View.GONE); itemView.setClickable(!item.showResults); + icon.setImageDrawable(itemView.getContext().getDrawable(item.poll.multiple ? + item.showResults ? R.drawable.ic_poll_checkbox_regular_selector : R.drawable.ic_poll_checkbox_filled_selector : + item.showResults ? R.drawable.ic_poll_option_button : R.drawable.ic_fluent_radio_button_24_selector + )); if(item.showResults){ progressBg.setLevel(Math.round(10000f*item.votesFraction)); button.setBackground(progressBg); diff --git a/mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_filled.xml new file mode 100644 index 000000000..fa9b028b3 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_filled.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_regular.xml new file mode 100644 index 000000000..033e1a14d --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_checkbox_checked_24_regular.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_filled.xml new file mode 100644 index 000000000..49398070b --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_filled.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_regular.xml new file mode 100644 index 000000000..792b97833 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_checkbox_unchecked_24_regular.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_radio_button_24_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_radio_button_24_filled.xml new file mode 100644 index 000000000..179f464bc --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_radio_button_24_filled.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_radio_button_24_selector.xml b/mastodon/src/main/res/drawable/ic_fluent_radio_button_24_selector.xml new file mode 100644 index 000000000..80162e2b7 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_radio_button_24_selector.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/mastodon/src/main/res/drawable/ic_poll_checkbox_filled_selector.xml b/mastodon/src/main/res/drawable/ic_poll_checkbox_filled_selector.xml new file mode 100644 index 000000000..1e03f145c --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_poll_checkbox_filled_selector.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/mastodon/src/main/res/drawable/ic_poll_checkbox_regular_selector.xml b/mastodon/src/main/res/drawable/ic_poll_checkbox_regular_selector.xml new file mode 100644 index 000000000..e22f22dea --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_poll_checkbox_regular_selector.xml @@ -0,0 +1,7 @@ + + + + + + + From 5b28468efd49387b4f8b83f142f3adf3104ca60c Mon Sep 17 00:00:00 2001 From: sk Date: Thu, 8 Dec 2022 20:53:34 +0100 Subject: [PATCH 4/4] add option to allow multiple poll choices --- .../android/fragments/ComposeFragment.java | 36 +++++++++++++++++++ .../ic_fluent_add_square_24_regular.xml | 3 ++ .../main/res/layout/compose_poll_option.xml | 1 + .../src/main/res/layout/fragment_compose.xml | 34 ++++++++++++++++++ mastodon/src/main/res/values/strings.xml | 1 + 5 files changed, 75 insertions(+) create mode 100644 mastodon/src/main/res/drawable/ic_fluent_add_square_24_regular.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index 406d74673..cdee35419 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -40,6 +40,7 @@ import android.view.WindowManager; import android.view.animation.LinearInterpolator; import android.view.inputmethod.InputMethodManager; import android.widget.Button; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageButton; @@ -150,6 +151,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr private ReorderableLinearLayout pollOptionsView; private View pollWrap; private View addPollOptionBtn; + private View pollAllowMultipleItem; + private CheckBox pollAllowMultipleCheckbox; private TextView pollDurationView; private ArrayList pollOptions=new ArrayList<>(); @@ -288,6 +291,9 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr pollOptionsView=view.findViewById(R.id.poll_options); pollWrap=view.findViewById(R.id.poll_wrap); addPollOptionBtn=view.findViewById(R.id.add_poll_option); + pollAllowMultipleItem=view.findViewById(R.id.poll_allow_multiple); + pollAllowMultipleCheckbox=view.findViewById(R.id.poll_allow_multiple_checkbox); + pollAllowMultipleItem.setOnClickListener(v->this.togglePollAllowMultiple()); addPollOptionBtn.setOnClickListener(v->{ createDraftPollOption().edit.requestFocus(); @@ -302,6 +308,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr pollBtn.setSelected(true); mediaBtn.setEnabled(false); pollWrap.setVisibility(View.VISIBLE); + updatePollAllowMultiple(savedInstanceState.getBoolean("pollAllowMultiple", false)); for(String oldText:savedInstanceState.getStringArrayList("pollOptions")){ DraftPollOption opt=createDraftPollOption(); opt.edit.setText(oldText); @@ -312,6 +319,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr pollBtn.setSelected(true); mediaBtn.setEnabled(false); pollWrap.setVisibility(View.VISIBLE); + updatePollAllowMultiple(editingStatus.poll.multiple); for(Poll.Option eopt:editingStatus.poll.options){ DraftPollOption opt=createDraftPollOption(); opt.edit.setText(eopt.title); @@ -381,6 +389,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr outState.putStringArrayList("pollOptions", opts); outState.putInt("pollDuration", pollDuration); outState.putString("pollDurationStr", pollDurationStr); + outState.putBoolean("pollAllowMultiple", pollAllowMultipleItem.isSelected()); } outState.putBoolean("hasSpoiler", hasSpoiler); if(!attachments.isEmpty()){ @@ -658,6 +667,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr if(!pollOptions.isEmpty()){ req.poll=new CreateStatus.Request.Poll(); req.poll.expiresIn=pollDuration; + req.poll.multiple=pollAllowMultipleItem.isSelected(); for(DraftPollOption opt:pollOptions) req.poll.options.add(opt.edit.getText().toString()); } @@ -1158,6 +1168,11 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr option.view=LayoutInflater.from(getActivity()).inflate(R.layout.compose_poll_option, pollOptionsView, false); option.edit=option.view.findViewById(R.id.edit); option.dragger=option.view.findViewById(R.id.dragger_thingy); + ImageView icon = option.view.findViewById(R.id.icon); + icon.setImageDrawable(getContext().getDrawable(pollAllowMultipleItem.isSelected() ? + R.drawable.ic_poll_checkbox_regular_selector : + R.drawable.ic_poll_option_button + )); option.dragger.setOnLongClickListener(v->{ pollOptionsView.startDragging(option.view); @@ -1319,6 +1334,27 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr }); } + private void togglePollAllowMultiple() { + updatePollAllowMultiple(!pollAllowMultipleItem.isSelected()); + } + + private void updatePollAllowMultiple(boolean multiple){ + pollAllowMultipleItem.setSelected(multiple); + pollAllowMultipleCheckbox.setChecked(multiple); + ImageView btn = addPollOptionBtn.findViewById(R.id.add_poll_option_icon); + btn.setImageDrawable(getContext().getDrawable(multiple ? + R.drawable.ic_fluent_add_square_24_regular : + R.drawable.ic_fluent_add_circle_24_regular + )); + for (DraftPollOption opt:pollOptions) { + ImageView icon = opt.view.findViewById(R.id.icon); + icon.setImageDrawable(getContext().getDrawable(multiple ? + R.drawable.ic_poll_checkbox_regular_selector : + R.drawable.ic_poll_option_button + )); + } + } + @Override public void onSelectionChanged(int start, int end){ if(ignoreSelectionChanges) diff --git a/mastodon/src/main/res/drawable/ic_fluent_add_square_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_add_square_24_regular.xml new file mode 100644 index 000000000..0aa232d6c --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_add_square_24_regular.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/layout/compose_poll_option.xml b/mastodon/src/main/res/layout/compose_poll_option.xml index d806da362..d93a68014 100644 --- a/mastodon/src/main/res/layout/compose_poll_option.xml +++ b/mastodon/src/main/res/layout/compose_poll_option.xml @@ -15,6 +15,7 @@ android:outlineProvider="background" android:elevation="2dp"> + + + + + + + Welcome Back Log in with the server where you created your account. Server URL + Allow multiple choices \ No newline at end of file