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 45f344961..10c625484 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -41,6 +41,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; @@ -153,6 +154,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr private View pollWrap; private View addPollOptionBtn; private View sensitiveItem; + private View pollAllowMultipleItem; + private CheckBox pollAllowMultipleCheckbox; private TextView pollDurationView; private ArrayList pollOptions=new ArrayList<>(); @@ -297,6 +300,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(); @@ -311,6 +317,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); @@ -321,6 +328,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); @@ -391,6 +399,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("sensitive", sensitive); outState.putBoolean("hasSpoiler", hasSpoiler); @@ -698,6 +707,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()); } @@ -1208,6 +1218,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); @@ -1385,6 +1400,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/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java index 70be9b87b..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,14 +78,17 @@ 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){ - 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)); 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/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 @@ + + + + + + + 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"> diff --git a/mastodon/src/main/res/layout/fragment_compose.xml b/mastodon/src/main/res/layout/fragment_compose.xml index 8a93b7798..c949f3d92 100644 --- a/mastodon/src/main/res/layout/fragment_compose.xml +++ b/mastodon/src/main/res/layout/fragment_compose.xml @@ -132,6 +132,7 @@ android:outlineProvider="background" android:elevation="2dp"> + + + + + + + Gelb Beiträge Blau + Mehrfachantworten erlauben \ No newline at end of file diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 6fe19bf86..5369cd3d9 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -47,4 +47,5 @@ Blue Brown Yellow + Allow multiple choices