Edit account name on reviewing account

pull/194/merge
M66B 3 years ago
parent d0ce363229
commit 114fe7e236

@ -27,9 +27,13 @@ import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -51,7 +55,7 @@ public class FragmentDialogAccount extends FragmentDialogBase {
final Context context = getContext(); final Context context = getContext();
final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_review_account, null); final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_review_account, null);
final TextView tvName = dview.findViewById(R.id.tvName); final EditText etName = dview.findViewById(R.id.etName);
final TextView tvInbox = dview.findViewById(R.id.tvInbox); final TextView tvInbox = dview.findViewById(R.id.tvInbox);
final TextView tvDrafts = dview.findViewById(R.id.tvDrafts); final TextView tvDrafts = dview.findViewById(R.id.tvDrafts);
final TextView tvSent = dview.findViewById(R.id.tvSent); final TextView tvSent = dview.findViewById(R.id.tvSent);
@ -77,7 +81,8 @@ public class FragmentDialogAccount extends FragmentDialogBase {
tvJunk.setCompoundDrawablesRelative(null, null, null, null); tvJunk.setCompoundDrawablesRelative(null, null, null, null);
tvArchive.setCompoundDrawablesRelative(null, null, null, null); tvArchive.setCompoundDrawablesRelative(null, null, null, null);
tvName.setText(null); etName.setText(null);
etName.setEnabled(false);
tvLeft.setText(null); tvLeft.setText(null);
tvRight.setText(null); tvRight.setText(null);
@ -87,6 +92,52 @@ public class FragmentDialogAccount extends FragmentDialogBase {
Bundle args = getArguments(); Bundle args = getArguments();
final long account = args.getLong("account"); final long account = args.getLong("account");
Runnable update = new Runnable() {
@Override
public void run() {
try {
String tag = (String) etName.getTag();
String name = etName.getText().toString();
if (!TextUtils.isEmpty(name) && !name.equals(tag)) {
args.putString("name", name);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("account");
String name = args.getString("name");
DB db = DB.getInstance(context);
db.account().setAccountName(id, name);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
// Ignored
}
}.execute(FragmentDialogAccount.this, args, "account:name");
}
} catch (Throwable ex) {
Log.e(ex);
}
}
};
etName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
update.run();
dismiss();
return true;
}
return false;
}
});
btnAccount.setOnClickListener(new View.OnClickListener() { btnAccount.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -115,7 +166,11 @@ public class FragmentDialogAccount extends FragmentDialogBase {
db.account().liveAccount(account).observe(this, new Observer<EntityAccount>() { db.account().liveAccount(account).observe(this, new Observer<EntityAccount>() {
@Override @Override
public void onChanged(EntityAccount account) { public void onChanged(EntityAccount account) {
tvName.setText(account.name); if (!etName.isEnabled()) {
etName.setTag(account.name);
etName.setText(account.name);
etName.setEnabled(true);
}
btnGmail.setVisibility( btnGmail.setVisibility(
hasGmail && account.auth_type == AUTH_TYPE_GMAIL hasGmail && account.auth_type == AUTH_TYPE_GMAIL
? View.VISIBLE : View.GONE); ? View.VISIBLE : View.GONE);
@ -179,6 +234,7 @@ public class FragmentDialogAccount extends FragmentDialogBase {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
update.run();
sendResult(RESULT_OK); sendResult(RESULT_OK);
} }
}) })

@ -10,14 +10,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedEditText
android:id="@+id/tvName" android:id="@+id/etName"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawableStart="@drawable/twotone_account_circle_24" android:drawableStart="@drawable/twotone_edit_24"
android:drawablePadding="6dp" android:drawablePadding="6dp"
android:imeOptions="actionDone"
android:inputType="text"
android:singleLine="true"
android:text="Name" android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -30,7 +34,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvName" /> app:layout_constraintTop_toBottomOf="@+id/etName" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvInbox" android:id="@+id/tvInbox"

Loading…
Cancel
Save