use TextInputLayout in quickedit dialog
This commit is contained in:
parent
9cc22ce992
commit
1fc432af53
|
@ -493,7 +493,11 @@ public class Contact implements ListItem, Blockable {
|
||||||
return this.mLastPresence;
|
return this.mLastPresence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class Options {
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class Options {
|
||||||
public static final int TO = 0;
|
public static final int TO = 0;
|
||||||
public static final int FROM = 1;
|
public static final int FROM = 1;
|
||||||
public static final int ASKING = 2;
|
public static final int ASKING = 2;
|
||||||
|
|
|
@ -244,12 +244,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
setSupportActionBar((Toolbar) binding.toolbar);
|
setSupportActionBar((Toolbar) binding.toolbar);
|
||||||
configureActionBar(getSupportActionBar());
|
configureActionBar(getSupportActionBar());
|
||||||
this.binding.editNickButton.setOnClickListener(v -> quickEdit(mConversation.getMucOptions().getActualNick(),
|
this.binding.editNickButton.setOnClickListener(v -> quickEdit(mConversation.getMucOptions().getActualNick(),
|
||||||
0,
|
R.string.nickname_for_this_group_chat,
|
||||||
value -> {
|
value -> {
|
||||||
if (xmppConnectionService.renameInMuc(mConversation, value, renameCallback)) {
|
if (xmppConnectionService.renameInMuc(mConversation, value, renameCallback)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return getString(R.string.invalid_username);
|
return getString(R.string.invalid_muc_nick);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
|
this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
|
||||||
|
|
|
@ -228,7 +228,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
|
||||||
case R.id.action_edit_contact:
|
case R.id.action_edit_contact:
|
||||||
Uri systemAccount = contact.getSystemAccount();
|
Uri systemAccount = contact.getSystemAccount();
|
||||||
if (systemAccount == null) {
|
if (systemAccount == null) {
|
||||||
quickEdit(contact.getDisplayName(), 0, value -> {
|
quickEdit(contact.getServerName(), R.string.contact_name, value -> {
|
||||||
contact.setServerName(value);
|
contact.setServerName(value);
|
||||||
ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact);
|
ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact);
|
||||||
populateView();
|
populateView();
|
||||||
|
|
|
@ -18,6 +18,7 @@ import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.databinding.DataBindingUtil;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
|
@ -34,6 +35,7 @@ import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.BoolRes;
|
import android.support.annotation.BoolRes;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AlertDialog.Builder;
|
import android.support.v7.app.AlertDialog.Builder;
|
||||||
|
@ -48,7 +50,6 @@ import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -59,6 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.PgpEngine;
|
import eu.siacs.conversations.crypto.PgpEngine;
|
||||||
|
import eu.siacs.conversations.databinding.DialogQuickeditBinding;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
@ -687,11 +689,11 @@ public abstract class XmppActivity extends ActionBarActivity {
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void quickEdit(String previousValue, int hint, OnValueEdited callback) {
|
protected void quickEdit(String previousValue, @StringRes int hint, OnValueEdited callback) {
|
||||||
quickEdit(previousValue, callback, hint, false, false);
|
quickEdit(previousValue, callback, hint, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void quickEdit(String previousValue, int hint, OnValueEdited callback, boolean permitEmpty) {
|
protected void quickEdit(String previousValue, @StringRes int hint, OnValueEdited callback, boolean permitEmpty) {
|
||||||
quickEdit(previousValue, callback, hint, false, permitEmpty);
|
quickEdit(previousValue, callback, hint, false, permitEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,35 +704,32 @@ public abstract class XmppActivity extends ActionBarActivity {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
private void quickEdit(final String previousValue,
|
private void quickEdit(final String previousValue,
|
||||||
final OnValueEdited callback,
|
final OnValueEdited callback,
|
||||||
final int hint,
|
final @StringRes int hint,
|
||||||
boolean password,
|
boolean password,
|
||||||
boolean permitEmpty) {
|
boolean permitEmpty) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
View view = getLayoutInflater().inflate(R.layout.quickedit, null);
|
DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.dialog_quickedit, null, false);
|
||||||
final EditText editor = view.findViewById(R.id.editor);
|
|
||||||
if (password) {
|
if (password) {
|
||||||
editor.setInputType(InputType.TYPE_CLASS_TEXT
|
binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
||||||
}
|
}
|
||||||
builder.setPositiveButton(R.string.accept, null);
|
builder.setPositiveButton(R.string.accept, null);
|
||||||
if (hint != 0) {
|
if (hint != 0) {
|
||||||
editor.setHint(hint);
|
binding.inputLayout.setHint(getString(hint));
|
||||||
}
|
}
|
||||||
editor.requestFocus();
|
binding.inputEditText.requestFocus();
|
||||||
editor.setText("");
|
|
||||||
if (previousValue != null) {
|
if (previousValue != null) {
|
||||||
editor.getText().append(previousValue);
|
binding.inputEditText.getText().append(previousValue);
|
||||||
}
|
}
|
||||||
builder.setView(view);
|
builder.setView(binding.getRoot());
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
final AlertDialog dialog = builder.create();
|
final AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
View.OnClickListener clickListener = v -> {
|
View.OnClickListener clickListener = v -> {
|
||||||
String value = editor.getText().toString();
|
String value = binding.inputEditText.getText().toString();
|
||||||
if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) {
|
if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) {
|
||||||
String error = callback.onValueEdited(value);
|
String error = callback.onValueEdited(value);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
editor.setError(error);
|
binding.inputLayout.setError(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
34
src/main/res/layout/dialog_quickedit.xml
Normal file
34
src/main/res/layout/dialog_quickedit.xml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="?attr/dialog_horizontal_padding"
|
||||||
|
android:paddingRight="?attr/dialog_horizontal_padding"
|
||||||
|
android:paddingTop="?attr/dialog_vertical_padding">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/input_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:errorEnabled="true"
|
||||||
|
app:errorTextAppearance="@style/TextAppearance.Conversations.Design.Error"
|
||||||
|
app:hintTextAppearance="@style/TextAppearance.Conversations.Design.Hint">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/input_edit_text"
|
||||||
|
style="@style/Widget.Conversations.EditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="textPersonName">
|
||||||
|
|
||||||
|
<requestFocus/>
|
||||||
|
</android.support.design.widget.TextInputEditText>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</layout>
|
|
@ -1,19 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="16dp" >
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/editor"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ems="10"
|
|
||||||
android:inputType="textPersonName"
|
|
||||||
style="@style/Widget.Conversations.EditText">
|
|
||||||
|
|
||||||
<requestFocus />
|
|
||||||
</EditText>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
|
@ -719,4 +719,6 @@
|
||||||
<string name="group_chat_avatar">Group chat avatar</string>
|
<string name="group_chat_avatar">Group chat avatar</string>
|
||||||
<string name="host_does_not_support_group_chat_avatars">Host does not support group chat avatars</string>
|
<string name="host_does_not_support_group_chat_avatars">Host does not support group chat avatars</string>
|
||||||
<string name="only_the_owner_can_change_group_chat_avatar">Only the owner can change group chat avatar</string>
|
<string name="only_the_owner_can_change_group_chat_avatar">Only the owner can change group chat avatar</string>
|
||||||
|
<string name="contact_name">Contact name</string>
|
||||||
|
<string name="nickname_for_this_group_chat">Nickname for this group chat</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue