40
40
import android .view .animation .LinearInterpolator ;
41
41
import android .view .inputmethod .InputMethodManager ;
42
42
import android .widget .Button ;
43
+ import android .widget .CheckBox ;
43
44
import android .widget .EditText ;
44
45
import android .widget .FrameLayout ;
45
46
import android .widget .ImageButton ;
@@ -150,6 +151,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
150
151
private ReorderableLinearLayout pollOptionsView ;
151
152
private View pollWrap ;
152
153
private View addPollOptionBtn ;
154
+ private View pollAllowMultipleItem ;
155
+ private CheckBox pollAllowMultipleCheckbox ;
153
156
private TextView pollDurationView ;
154
157
155
158
private ArrayList <DraftPollOption > pollOptions =new ArrayList <>();
@@ -288,6 +291,9 @@ public void onIconChanged(int icon){
288
291
pollOptionsView =view .findViewById (R .id .poll_options );
289
292
pollWrap =view .findViewById (R .id .poll_wrap );
290
293
addPollOptionBtn =view .findViewById (R .id .add_poll_option );
294
+ pollAllowMultipleItem =view .findViewById (R .id .poll_allow_multiple );
295
+ pollAllowMultipleCheckbox =view .findViewById (R .id .poll_allow_multiple_checkbox );
296
+ pollAllowMultipleItem .setOnClickListener (v ->this .togglePollAllowMultiple ());
291
297
292
298
addPollOptionBtn .setOnClickListener (v ->{
293
299
createDraftPollOption ().edit .requestFocus ();
@@ -302,6 +308,7 @@ public void onIconChanged(int icon){
302
308
pollBtn .setSelected (true );
303
309
mediaBtn .setEnabled (false );
304
310
pollWrap .setVisibility (View .VISIBLE );
311
+ updatePollAllowMultiple (savedInstanceState .getBoolean ("pollAllowMultiple" , false ));
305
312
for (String oldText :savedInstanceState .getStringArrayList ("pollOptions" )){
306
313
DraftPollOption opt =createDraftPollOption ();
307
314
opt .edit .setText (oldText );
@@ -312,6 +319,7 @@ public void onIconChanged(int icon){
312
319
pollBtn .setSelected (true );
313
320
mediaBtn .setEnabled (false );
314
321
pollWrap .setVisibility (View .VISIBLE );
322
+ updatePollAllowMultiple (editingStatus .poll .multiple );
315
323
for (Poll .Option eopt :editingStatus .poll .options ){
316
324
DraftPollOption opt =createDraftPollOption ();
317
325
opt .edit .setText (eopt .title );
@@ -381,6 +389,7 @@ public void onSaveInstanceState(Bundle outState){
381
389
outState .putStringArrayList ("pollOptions" , opts );
382
390
outState .putInt ("pollDuration" , pollDuration );
383
391
outState .putString ("pollDurationStr" , pollDurationStr );
392
+ outState .putBoolean ("pollAllowMultiple" , pollAllowMultipleItem .isSelected ());
384
393
}
385
394
outState .putBoolean ("hasSpoiler" , hasSpoiler );
386
395
if (!attachments .isEmpty ()){
@@ -658,6 +667,7 @@ private void publish(){
658
667
if (!pollOptions .isEmpty ()){
659
668
req .poll =new CreateStatus .Request .Poll ();
660
669
req .poll .expiresIn =pollDuration ;
670
+ req .poll .multiple =pollAllowMultipleItem .isSelected ();
661
671
for (DraftPollOption opt :pollOptions )
662
672
req .poll .options .add (opt .edit .getText ().toString ());
663
673
}
@@ -1158,6 +1168,11 @@ private DraftPollOption createDraftPollOption(){
1158
1168
option .view =LayoutInflater .from (getActivity ()).inflate (R .layout .compose_poll_option , pollOptionsView , false );
1159
1169
option .edit =option .view .findViewById (R .id .edit );
1160
1170
option .dragger =option .view .findViewById (R .id .dragger_thingy );
1171
+ ImageView icon = option .view .findViewById (R .id .icon );
1172
+ icon .setImageDrawable (getContext ().getDrawable (pollAllowMultipleItem .isSelected () ?
1173
+ R .drawable .ic_poll_checkbox_regular_selector :
1174
+ R .drawable .ic_poll_option_button
1175
+ ));
1161
1176
1162
1177
option .dragger .setOnLongClickListener (v ->{
1163
1178
pollOptionsView .startDragging (option .view );
@@ -1319,6 +1334,27 @@ private void updateVisibilityIcon(){
1319
1334
});
1320
1335
}
1321
1336
1337
+ private void togglePollAllowMultiple () {
1338
+ updatePollAllowMultiple (!pollAllowMultipleItem .isSelected ());
1339
+ }
1340
+
1341
+ private void updatePollAllowMultiple (boolean multiple ){
1342
+ pollAllowMultipleItem .setSelected (multiple );
1343
+ pollAllowMultipleCheckbox .setChecked (multiple );
1344
+ ImageView btn = addPollOptionBtn .findViewById (R .id .add_poll_option_icon );
1345
+ btn .setImageDrawable (getContext ().getDrawable (multiple ?
1346
+ R .drawable .ic_fluent_add_square_24_regular :
1347
+ R .drawable .ic_fluent_add_circle_24_regular
1348
+ ));
1349
+ for (DraftPollOption opt :pollOptions ) {
1350
+ ImageView icon = opt .view .findViewById (R .id .icon );
1351
+ icon .setImageDrawable (getContext ().getDrawable (multiple ?
1352
+ R .drawable .ic_poll_checkbox_regular_selector :
1353
+ R .drawable .ic_poll_option_button
1354
+ ));
1355
+ }
1356
+ }
1357
+
1322
1358
@ Override
1323
1359
public void onSelectionChanged (int start , int end ){
1324
1360
if (ignoreSelectionChanges )
0 commit comments