support error messages in quick edit dialog

This commit is contained in:
Daniel Gultsch 2017-12-09 18:46:21 +01:00
parent b0d83ae4b9
commit a973833a4f
5 changed files with 43 additions and 26 deletions

View File

@ -2348,9 +2348,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() {
@ -2395,6 +2398,7 @@ public class XmppConnectionService extends Service {
joinMuc(conversation);
}
}
return true;
}
public void leaveMuc(Conversation conversation) {

View File

@ -204,8 +204,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;
}
};
@ -254,8 +255,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

@ -284,11 +284,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

@ -133,9 +133,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

@ -7,6 +7,7 @@ import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
@ -167,11 +168,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() {
@ -733,23 +734,13 @@ public abstract class XmppActivity extends Activity {
boolean password) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.quickedit, null);
final EditText editor = (EditText) 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);
}
}
};
final EditText editor = view.findViewById(R.id.editor);
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.edit, mClickListener);
builder.setPositiveButton(R.string.edit, null);
}
if (hint != 0) {
editor.setHint(hint);
@ -761,7 +752,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) {