mirror of https://github.com/M66B/FairEmail.git
Added local contact name edit
This commit is contained in:
parent
0d93e0f86c
commit
4e5737982f
|
@ -20,9 +20,11 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
@ -40,11 +42,14 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.core.content.pm.ShortcutInfoCompat;
|
||||
import androidx.core.content.pm.ShortcutManagerCompat;
|
||||
|
@ -225,7 +230,8 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
popupMenu.getMenu().add(Menu.NONE, R.string.title_share, 2, R.string.title_share);
|
||||
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context))
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_pin, 3, R.string.title_pin);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, 4, R.string.title_delete);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_advanced_edit_name, 4, R.string.title_advanced_edit_name);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, 5, R.string.title_delete);
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
|
@ -240,6 +246,9 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
case R.string.title_pin:
|
||||
onActionPin();
|
||||
return true;
|
||||
case R.string.title_advanced_edit_name:
|
||||
onActionEdit();
|
||||
return true;
|
||||
case R.string.title_delete:
|
||||
onActionDelete();
|
||||
return true;
|
||||
|
@ -289,6 +298,16 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
ShortcutManagerCompat.requestPinShortcut(context, builder.build(), null);
|
||||
}
|
||||
|
||||
private void onActionEdit() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", contact.id);
|
||||
args.putString("name", contact.name);
|
||||
|
||||
FragmentEditName fragment = new FragmentEditName();
|
||||
fragment.setArguments(args);
|
||||
fragment.show(parentFragment.getParentFragmentManager(), "contact:edit");
|
||||
}
|
||||
|
||||
private void onActionDelete() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", contact.id);
|
||||
|
@ -457,4 +476,48 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
|
||||
holder.powner.recreate();
|
||||
}
|
||||
|
||||
public static class FragmentEditName extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_edit_name, null);
|
||||
final EditText etName = view.findViewById(R.id.etName);
|
||||
etName.setText(getArguments().getString("name"));
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", getArguments().getLong("id"));
|
||||
args.putString("name", etName.getText().toString());
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
String name = args.getString("name");
|
||||
|
||||
if (TextUtils.isEmpty(name))
|
||||
name = null;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.contact().setContactName(id, name);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(getContext(), getActivity(), args, "edit:name");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3182,7 +3182,7 @@ class Core {
|
|||
contact.id = db.contact().insertContact(contact);
|
||||
Log.i("Inserted contact=" + contact + " type=" + type);
|
||||
} else {
|
||||
if (!TextUtils.isEmpty(name))
|
||||
if (contact.name == null && !TextUtils.isEmpty(name))
|
||||
contact.name = name;
|
||||
contact.avatar = (avatar == null ? null : avatar.toString());
|
||||
contact.times_contacted++;
|
||||
|
|
|
@ -81,6 +81,9 @@ public interface DaoContact {
|
|||
" AND email = :email")
|
||||
int deleteContact(long account, int type, String email);
|
||||
|
||||
@Query("UPDATE contact SET name = :name WHERE id = :id")
|
||||
int setContactName(long id, String name);
|
||||
|
||||
@Query("UPDATE contact SET state = :state WHERE id = :id")
|
||||
int setContactState(long id, int state);
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="24dp">
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@+id/etKeyword"
|
||||
android:text="@string/title_advanced_edit_name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textCapSentences"
|
||||
android:text="Name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvName">
|
||||
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -590,6 +590,7 @@
|
|||
<string name="title_advanced_cleanup_hint">This will delete all temporary files</string>
|
||||
|
||||
<string name="title_advanced_never_favorite">Never favorite</string>
|
||||
<string name="title_advanced_edit_name">Edit name</string>
|
||||
|
||||
<string name="title_advanced_swipe_actions">Set swipe actions</string>
|
||||
<string name="title_advanced_swipe_actions_hint">This will set the swipe left and right action for all IMAP accounts</string>
|
||||
|
|
Loading…
Reference in New Issue