support error messages in quick edit dialog

This commit is contained in:
Christian Schneppe 2017-12-16 22:33:34 +01:00
parent 04e21792f0
commit 090faad374
5 changed files with 41 additions and 25 deletions

View file

@ -2537,9 +2537,12 @@ public class XmppConnectionService extends Service {
return false;
}
public void renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
final MucOptions options = conversation.getMucOptions();
final Jid joinJid = options.createJoinJid(nick);
if (joinJid == null) {
return false;
}
if (options.online()) {
Account account = conversation.getAccount();
options.setOnRenameListener(new OnRenameListener() {
@ -2584,6 +2587,7 @@ public class XmppConnectionService extends Service {
joinMuc(conversation);
}
}
return true;
}
public void leaveMuc(Conversation conversation) {

View file

@ -223,8 +223,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private OnValueEdited onSubjectEdited = new OnValueEdited() {
@Override
public void onValueEdited(String value) {
public String onValueEdited(String value) {
xmppConnectionService.pushSubjectToConference(mConversation, value);
return null;
}
};
@ -274,8 +275,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
new OnValueEdited() {
@Override
public void onValueEdited(String value) {
xmppConnectionService.renameInMuc(mConversation, value, renameCallback);
public String onValueEdited(String value) {
if (xmppConnectionService.renameInMuc(mConversation, value, renameCallback)) {
return null;
} else {
return getString(R.string.invalid_username);
}
}
});
}

View file

@ -343,11 +343,11 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
quickEdit(contact.getDisplayName(), 0, new OnValueEdited() {
@Override
public void onValueEdited(String value) {
public String onValueEdited(String value) {
contact.setServerName(value);
ContactDetailsActivity.this.xmppConnectionService
.pushContactToServer(contact);
ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact);
populateView();
return null;
}
});
} else {

View file

@ -139,9 +139,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
activity.quickPasswordEdit(password, new OnValueEdited() {
@Override
public void onValueEdited(String value) {
activity.xmppConnectionService.providePasswordForMuc(
conversation, value);
public String onValueEdited(String value) {
activity.xmppConnectionService.providePasswordForMuc(conversation, value);
return null;
}
});
}

View file

@ -172,11 +172,11 @@ public abstract class XmppActivity extends Activity {
abstract protected void refreshUiReal();
protected interface OnValueEdited {
public void onValueEdited(String value);
String onValueEdited(String value);
}
public interface OnPresenceSelected {
public void onPresenceSelected();
void onPresenceSelected();
}
protected ServiceConnection mConnection = new ServiceConnection() {
@ -744,22 +744,12 @@ public abstract class XmppActivity extends Activity {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.quickedit, null);
final EditText editor = view.findViewById(R.id.editor);
OnClickListener mClickListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String value = editor.getText().toString();
if (!value.equals(previousValue) && value.trim().length() > 0) {
callback.onValueEdited(value);
}
}
};
if (password) {
editor.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
builder.setPositiveButton(R.string.accept, mClickListener);
builder.setPositiveButton(R.string.accept, null);
} else {
builder.setPositiveButton(R.string.ok, mClickListener);
builder.setPositiveButton(R.string.ok, null);
}
if (hint != 0) {
editor.setHint(hint);
@ -771,7 +761,24 @@ public abstract class XmppActivity extends Activity {
}
builder.setView(view);
builder.setNegativeButton(R.string.cancel, null);
builder.create().show();
final AlertDialog dialog = builder.create();
dialog.show();
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String value = editor.getText().toString();
if (!value.equals(previousValue) && value.trim().length() > 0) {
String error = callback.onValueEdited(value);
if (error != null) {
editor.setError(error);
return;
}
}
dialog.dismiss();
}
};
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
}
public boolean hasStoragePermission(int requestCode) {