Error message for duplicated entry in polls
This commit is contained in:
parent
e4b90981f1
commit
976612f69b
|
@ -3689,7 +3689,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
||||||
poll_duration.setAdapter(pollduration);
|
poll_duration.setAdapter(pollduration);
|
||||||
poll_duration.setSelection(4);
|
poll_duration.setSelection(4);
|
||||||
poll_choice.setSelection(0);
|
poll_choice.setSelection(0);
|
||||||
if( poll != null){
|
if( poll != null && poll.getOptionsList() != null){
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for(PollOptions pollOptions: poll.getOptionsList()){
|
for(PollOptions pollOptions: poll.getOptionsList()){
|
||||||
if( i == 1){
|
if( i == 1){
|
||||||
|
@ -3760,79 +3760,101 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
||||||
dialog.dismiss();
|
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() {
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onShow(DialogInterface dialog) {
|
||||||
int poll_duration_pos = poll_duration.getSelectedItemPosition();
|
|
||||||
|
|
||||||
int poll_choice_pos = poll_choice.getSelectedItemPosition();
|
Button b = alertPollDiaslog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
String choice1 = choice_1.getText().toString().trim();
|
b.setOnClickListener(new View.OnClickListener() {
|
||||||
String choice2 = choice_2.getText().toString().trim();
|
|
||||||
|
|
||||||
if( choice1.isEmpty() && choice2.isEmpty()){
|
@Override
|
||||||
Toasty.error(getApplicationContext(), getString(R.string.poll_invalid_choices), Toast.LENGTH_SHORT).show();
|
public void onClick(View view) {
|
||||||
}else{
|
int poll_duration_pos = poll_duration.getSelectedItemPosition();
|
||||||
poll = new Poll();
|
|
||||||
poll.setMultiple(poll_choice_pos != 0);
|
|
||||||
int expire = 0;
|
|
||||||
switch (poll_duration_pos){
|
|
||||||
case 0:
|
|
||||||
expire = 300;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
expire = 1800;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
expire = 3600;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
expire = 21600;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
expire = 86400;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
expire = 259200;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
expire = 604800;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
expire = 864000;
|
|
||||||
}
|
|
||||||
poll.setExpires_in(expire);
|
|
||||||
|
|
||||||
List<PollOptions> pollOptions = new ArrayList<>();
|
int poll_choice_pos = poll_choice.getSelectedItemPosition();
|
||||||
PollOptions pollOption1 = new PollOptions();
|
String choice1 = choice_1.getText().toString().trim();
|
||||||
pollOption1.setTitle(choice1);
|
String choice2 = choice_2.getText().toString().trim();
|
||||||
pollOptions.add(pollOption1);
|
|
||||||
|
|
||||||
PollOptions pollOption2 = new PollOptions();
|
if( choice1.isEmpty() && choice2.isEmpty()){
|
||||||
pollOption2.setTitle(choice2);
|
Toasty.error(getApplicationContext(), getString(R.string.poll_invalid_choices), Toast.LENGTH_SHORT).show();
|
||||||
pollOptions.add(pollOption2);
|
}else{
|
||||||
|
poll = new Poll();
|
||||||
|
poll.setMultiple(poll_choice_pos != 0);
|
||||||
|
int expire = 0;
|
||||||
|
switch (poll_duration_pos){
|
||||||
|
case 0:
|
||||||
|
expire = 300;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
expire = 1800;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
expire = 3600;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
expire = 21600;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
expire = 86400;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
expire = 259200;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
expire = 604800;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
expire = 864000;
|
||||||
|
}
|
||||||
|
poll.setExpires_in(expire);
|
||||||
|
|
||||||
int childCount = poll_items_container.getChildCount();
|
List<PollOptions> pollOptions = new ArrayList<>();
|
||||||
if( childCount > 2){
|
PollOptions pollOption1 = new PollOptions();
|
||||||
for( int i = 2 ; i < childCount; i++){
|
pollOption1.setTitle(choice1);
|
||||||
PollOptions pollItem = new PollOptions();
|
pollOptions.add(pollOption1);
|
||||||
pollItem.setTitle(((EditText)poll_items_container.getChildAt(i)).getText().toString());
|
|
||||||
pollOptions.add(pollItem);
|
PollOptions pollOption2 = new PollOptions();
|
||||||
|
pollOption2.setTitle(choice2);
|
||||||
|
pollOptions.add(pollOption2);
|
||||||
|
|
||||||
|
int childCount = poll_items_container.getChildCount();
|
||||||
|
if( childCount > 2){
|
||||||
|
for( int i = 2 ; i < childCount; i++){
|
||||||
|
PollOptions pollItem = new PollOptions();
|
||||||
|
pollItem.setTitle(((EditText)poll_items_container.getChildAt(i)).getText().toString());
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
poll.setOptionsList(pollOptions);
|
|
||||||
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
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){
|
private void storeToot(boolean message, boolean forced){
|
||||||
|
|
|
@ -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 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>
|
||||||
|
<string name="poll_duplicated_entry">Your poll can\'t have duplicated options!</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue