Error message for duplicated entry in polls

This commit is contained in:
tom79 2019-08-20 10:18:21 +02:00
parent e4b90981f1
commit 976612f69b
2 changed files with 87 additions and 64 deletions

View File

@ -3689,7 +3689,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
poll_duration.setAdapter(pollduration);
poll_duration.setSelection(4);
poll_choice.setSelection(0);
if( poll != null){
if( poll != null && poll.getOptionsList() != null){
int i = 1;
for(PollOptions pollOptions: poll.getOptionsList()){
if( i == 1){
@ -3760,9 +3760,18 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
dialog.dismiss();
}
});
alertPoll.setPositiveButton(R.string.validate, null);
final AlertDialog alertPollDiaslog = alertPoll.create();
alertPollDiaslog.setOnShowListener(new DialogInterface.OnShowListener() {
alertPoll.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
@Override
public void onShow(DialogInterface dialog) {
Button b = alertPollDiaslog.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int poll_duration_pos = poll_duration.getSelectedItemPosition();
int poll_choice_pos = poll_choice.getSelectedItemPosition();
@ -3819,20 +3828,33 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
pollOptions.add(pollItem);
}
}
List<String> options = new ArrayList<>();
boolean doubleTitle = false;
for(PollOptions po: pollOptions){
if( !options.contains(po.getTitle().trim())){
options.add(po.getTitle().trim());
}else{
doubleTitle = true;
}
}
if( !doubleTitle) {
poll.setOptionsList(pollOptions);
dialog.dismiss();
}else {
Toasty.error(getApplicationContext(), getString(R.string.poll_duplicated_entry), Toast.LENGTH_SHORT).show();
}
}
poll_action.setVisibility(View.VISIBLE);
if(social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
toot_picture.setVisibility(View.GONE);
picture_scrollview.setVisibility(View.GONE);
}
}
});
alertPoll.show();
}
});
alertPollDiaslog.show();
}
private void storeToot(boolean message, boolean forced){

View File

@ -1177,4 +1177,5 @@
<string name="join_instance">For joining my instance \"%1$s\", you can download Fedilab:\n\nF-Droid: %2$s\nGoogle: %3$s\n\nThen open the link below with Fedilab and create your account :)\n\n%4$s
</string>
<string name="poll_duplicated_entry">Your poll can\'t have duplicated options!</string>
</resources>