diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index 5c580ae6..e04d13dd 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -72,6 +72,7 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.vanniktech.emoji.EmojiManager; @@ -1705,7 +1706,7 @@ public class ComposeAdapter extends RecyclerView.Adapter { if (pollCountItem[0] < finalMax_entry) { - ComposePollItemBinding composePollItemBinding = ComposePollItemBinding.inflate(LayoutInflater.from(context), new LinearLayout(context), false); + ComposePollItemBinding composePollItemBinding = ComposePollItemBinding.inflate(LayoutInflater.from(composePollBinding.optionsList.getContext()), composePollBinding.optionsList, false); + if (composePollBinding.pollType.getCheckedButtonId() == R.id.poll_type_multiple) + composePollItemBinding.typeIndicator.setImageResource(R.drawable.ic_compose_poll_option_mark_multiple); composePollItemBinding.text.setFilters(fArray); - composePollItemBinding.text.setHint(context.getString(R.string.poll_choice_s, (pollCountItem[0] + 1))); + composePollItemBinding.textLayout.setHint(context.getString(R.string.poll_choice_s, (pollCountItem[0] + 1))); LinearLayoutCompat viewItem = composePollItemBinding.getRoot(); composePollBinding.optionsList.addView(composePollItemBinding.getRoot()); composePollItemBinding.buttonRemove.setOnClickListener(view -> { @@ -1764,27 +1767,31 @@ public class ComposeAdapter extends RecyclerView.Adapter pollduration = ArrayAdapter.createFromResource(context, R.array.poll_duration, android.R.layout.simple_spinner_dropdown_item); - - ArrayAdapter pollchoice = ArrayAdapter.createFromResource(context, - R.array.poll_choice_type, android.R.layout.simple_spinner_dropdown_item); - composePollBinding.pollType.setAdapter(pollchoice); composePollBinding.pollDuration.setAdapter(pollduration); composePollBinding.pollDuration.setSelection(4); - composePollBinding.pollType.setSelection(0); if (statusDraft != null && statusDraft.poll != null && statusDraft.poll.options != null) { int i = 1; for (Poll.PollItem pollItem : statusDraft.poll.options) { if (i == 1) { + if (statusDraft.poll.multiple) + composePollBinding.option1.typeIndicator.setImageResource(R.drawable.ic_compose_poll_option_mark_multiple); if (pollItem.title != null) composePollBinding.option1.text.setText(pollItem.title); } else if (i == 2) { + if (statusDraft.poll.multiple) + composePollBinding.option2.typeIndicator.setImageResource(R.drawable.ic_compose_poll_option_mark_multiple); if (pollItem.title != null) composePollBinding.option2.text.setText(pollItem.title); } else { ComposePollItemBinding composePollItemBinding = ComposePollItemBinding.inflate(LayoutInflater.from(context), new LinearLayout(context), false); + if (composePollBinding.pollType.getCheckedButtonId() == R.id.poll_type_multiple) + composePollItemBinding.typeIndicator.setImageResource(R.drawable.ic_compose_poll_option_mark_multiple); + else + composePollItemBinding.typeIndicator.setImageResource(R.drawable.ic_compose_poll_option_mark_single); + composePollItemBinding.text.setFilters(fArray); - composePollItemBinding.text.setHint(context.getString(R.string.poll_choice_s, (pollCountItem[0] + 1))); + composePollItemBinding.textLayout.setHint(context.getString(R.string.poll_choice_s, (pollCountItem[0] + 1))); composePollItemBinding.text.setText(pollItem.title); composePollBinding.optionsList.addView(composePollItemBinding.getRoot()); composePollItemBinding.buttonRemove.setOnClickListener(view -> { @@ -1822,9 +1829,9 @@ public class ComposeAdapter extends RecyclerView.Adapter { + composePollBinding.pollType.addOnButtonCheckedListener((group, checkedId, isChecked) -> { + if (isChecked) { + if (checkedId == R.id.poll_type_single) { + if (statusDraft != null && statusDraft.poll != null) statusDraft.poll.multiple = false; + for (int i = 0; i < composePollBinding.optionsList.getChildCount(); i++) { + ComposePollItemBinding child = ComposePollItemBinding.bind(composePollBinding.optionsList.getChildAt(i)); + child.typeIndicator.setImageResource(R.drawable.ic_compose_poll_option_mark_single); + } + } else if (checkedId == R.id.poll_type_multiple) { + if (statusDraft != null && statusDraft.poll != null) statusDraft.poll.multiple = true; + for (int i = 0; i < composePollBinding.optionsList.getChildCount(); i++) { + ComposePollItemBinding child = ComposePollItemBinding.bind(composePollBinding.optionsList.getChildAt(i)); + child.typeIndicator.setImageResource(R.drawable.ic_compose_poll_option_mark_multiple); + } + } + } + }); Button b = alertPollDiaslog.getButton(AlertDialog.BUTTON_POSITIVE); b.setOnClickListener(view1 -> { int poll_duration_pos = composePollBinding.pollDuration.getSelectedItemPosition(); - int poll_choice_pos = composePollBinding.pollType.getSelectedItemPosition(); + int selected_poll_type_id = composePollBinding.pollType.getCheckedButtonId(); String choice1 = composePollBinding.option1.text.getText().toString().trim(); String choice2 = composePollBinding.option2.text.getText().toString().trim(); @@ -1850,7 +1874,7 @@ public class ComposeAdapter extends RecyclerView.Adapter + android:fillColor="@android:color/white" + android:pathData="M18,19L6,19c-0.55,0 -1,-0.45 -1,-1L5,6c0,-0.55 0.45,-1 1,-1h12c0.55,0 1,0.45 1,1v12c0,0.55 -0.45,1 -1,1zM19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2z" /> diff --git a/app/src/main/res/drawable/ic_compose_poll_option_mark_single.xml b/app/src/main/res/drawable/ic_compose_poll_option_mark_single.xml new file mode 100644 index 00000000..d5c87f8f --- /dev/null +++ b/app/src/main/res/drawable/ic_compose_poll_option_mark_single.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/compose_poll.xml b/app/src/main/res/layout/compose_poll.xml index 6cc1a04e..8c09c999 100644 --- a/app/src/main/res/layout/compose_poll.xml +++ b/app/src/main/res/layout/compose_poll.xml @@ -14,97 +14,96 @@ You should have received a copy of the GNU General Public License along with Fedilab; if not, see --> - + android:layout_height="wrap_content"> - + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingHorizontal="24dp" + android:paddingVertical="12dp"> + android:orientation="vertical"> - + android:layout_marginTop="0dp" /> - - - - - - - - - - - - - - - - - - - - - - - + - + - + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/compose_poll_item.xml b/app/src/main/res/layout/compose_poll_item.xml index 04b86ee9..3f42b4fd 100644 --- a/app/src/main/res/layout/compose_poll_item.xml +++ b/app/src/main/res/layout/compose_poll_item.xml @@ -15,6 +15,7 @@ see --> + android:layout_width="24dp" + android:layout_height="24dp" + android:src="@drawable/ic_compose_poll_option_mark_single" /> - + android:layout_marginHorizontal="6dp" + android:layout_weight="1"> - + + + + + style="@style/Widget.Material3.Button.IconButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:icon="@drawable/ic_baseline_close_24" /> diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index b2a1a6bb..a77b7b9a 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -100,7 +100,7 @@ true - - - - - - + +