mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 22:51:02 +00:00
Added contact editor
This commit is contained in:
parent
5c0eb6132f
commit
05f3677448
6 changed files with 235 additions and 54 deletions
|
@ -239,7 +239,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
popupMenu.getMenu().add(Menu.NONE, R.string.title_share, order++, R.string.title_share); // should be system whitelisted
|
||||
if (Shortcuts.can(context))
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_pin, order++, R.string.title_pin);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_advanced_edit_name, order++, R.string.title_advanced_edit_name);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_contact, order++, R.string.title_edit_contact);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_search, order++, R.string.title_search);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, order++, R.string.title_delete);
|
||||
|
||||
|
@ -256,7 +256,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
} else if (itemId == R.string.title_pin) {
|
||||
onActionPin();
|
||||
return true;
|
||||
} else if (itemId == R.string.title_advanced_edit_name) {
|
||||
} else if (itemId == R.string.title_edit_contact) {
|
||||
onActionEdit();
|
||||
return true;
|
||||
} else if (itemId == R.string.title_search) {
|
||||
|
@ -312,12 +312,15 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|||
private void onActionEdit() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", contact.id);
|
||||
args.putLong("account", contact.account);
|
||||
args.putInt("type", contact.type);
|
||||
args.putString("email", contact.email);
|
||||
args.putString("name", contact.name);
|
||||
|
||||
FragmentDialogEditName fragment = new FragmentDialogEditName();
|
||||
FragmentContacts.FragmentDialogEditContact fragment = new FragmentContacts.FragmentDialogEditContact();
|
||||
fragment.setArguments(args);
|
||||
fragment.setTargetFragment(parentFragment, FragmentContacts.REQUEST_EDIT_NAME);
|
||||
fragment.show(parentFragment.getParentFragmentManager(), "contact:name");
|
||||
fragment.setTargetFragment(parentFragment, FragmentContacts.REQUEST_EDIT_CONTACT);
|
||||
fragment.show(parentFragment.getParentFragmentManager(), "contact:edit");
|
||||
}
|
||||
|
||||
private void onActionSearch() {
|
||||
|
|
|
@ -53,6 +53,9 @@ public interface DaoContact {
|
|||
", last_contacted DESC")
|
||||
Cursor getFrequentlyContacted();
|
||||
|
||||
@Query("SELECT * FROM contact WHERE id = :id")
|
||||
EntityContact getContact(long id);
|
||||
|
||||
@Query("SELECT *" +
|
||||
" FROM contact" +
|
||||
" WHERE account = :account" +
|
||||
|
@ -89,9 +92,6 @@ public interface DaoContact {
|
|||
" AND email = :email")
|
||||
int deleteContact(long account, int type, String email);
|
||||
|
||||
@Query("UPDATE contact SET name = :name WHERE id = :id AND NOT (name IS :name)")
|
||||
int setContactName(long id, String name);
|
||||
|
||||
@Query("UPDATE contact SET state = :state WHERE id = :id AND NOT (state IS :state)")
|
||||
int setContactState(long id, int state);
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -50,6 +52,8 @@ import androidx.lifecycle.OnLifecycleEvent;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
@ -74,6 +78,7 @@ public class FragmentContacts extends FragmentBase {
|
|||
private RecyclerView rvContacts;
|
||||
private ContentLoadingProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
private FloatingActionButton fabAdd;
|
||||
|
||||
private Long account = null;
|
||||
private boolean junk = false;
|
||||
|
@ -85,7 +90,8 @@ public class FragmentContacts extends FragmentBase {
|
|||
private static final int REQUEST_ACCOUNT = 1;
|
||||
private static final int REQUEST_IMPORT = 2;
|
||||
private static final int REQUEST_EXPORT = 3;
|
||||
static final int REQUEST_EDIT_NAME = 4;
|
||||
static final int REQUEST_EDIT_ACCOUNT = 4;
|
||||
static final int REQUEST_EDIT_CONTACT = 5;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -111,6 +117,7 @@ public class FragmentContacts extends FragmentBase {
|
|||
rvContacts = view.findViewById(R.id.rvContacts);
|
||||
pbWait = view.findViewById(R.id.pbWait);
|
||||
grpReady = view.findViewById(R.id.grpReady);
|
||||
fabAdd = view.findViewById(R.id.fabAdd);
|
||||
|
||||
// Wire controls
|
||||
|
||||
|
@ -154,6 +161,19 @@ public class FragmentContacts extends FragmentBase {
|
|||
onMenuJunk(junk);
|
||||
adapter.search(searching);
|
||||
|
||||
fabAdd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (account == null) {
|
||||
FragmentDialogSelectAccount fragment = new FragmentDialogSelectAccount();
|
||||
fragment.setArguments(new Bundle());
|
||||
fragment.setTargetFragment(FragmentContacts.this, REQUEST_EDIT_ACCOUNT);
|
||||
fragment.show(getParentFragmentManager(), "contact:account");
|
||||
} else
|
||||
onAdd(account);
|
||||
}
|
||||
});
|
||||
|
||||
final Context context = getContext();
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
|
@ -265,7 +285,7 @@ public class FragmentContacts extends FragmentBase {
|
|||
FragmentDialogSelectAccount fragment = new FragmentDialogSelectAccount();
|
||||
fragment.setArguments(args);
|
||||
fragment.setTargetFragment(this, REQUEST_ACCOUNT);
|
||||
fragment.show(getParentFragmentManager(), "messages:accounts");
|
||||
fragment.show(getParentFragmentManager(), "contact:account");
|
||||
}
|
||||
|
||||
private void onMenuDeleteAll() {
|
||||
|
@ -278,6 +298,17 @@ public class FragmentContacts extends FragmentBase {
|
|||
fragment.show(getParentFragmentManager(), "contacts:delete");
|
||||
}
|
||||
|
||||
private void onAdd(long account) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("type", junk ? EntityContact.TYPE_JUNK : EntityContact.TYPE_TO);
|
||||
args.putLong("account", account);
|
||||
|
||||
FragmentContacts.FragmentDialogEditContact fragment = new FragmentContacts.FragmentDialogEditContact();
|
||||
fragment.setArguments(args);
|
||||
fragment.setTargetFragment(this, REQUEST_EDIT_CONTACT);
|
||||
fragment.show(getParentFragmentManager(), "contact:add");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
@ -296,9 +327,13 @@ public class FragmentContacts extends FragmentBase {
|
|||
if (resultCode == RESULT_OK && data != null)
|
||||
handleExport(data);
|
||||
break;
|
||||
case REQUEST_EDIT_NAME:
|
||||
case REQUEST_EDIT_ACCOUNT:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onEditName(data.getBundleExtra("args"));
|
||||
onAdd(data.getBundleExtra("args").getLong("account"));
|
||||
break;
|
||||
case REQUEST_EDIT_CONTACT:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onEditContact(data.getBundleExtra("args"));
|
||||
break;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
|
@ -469,25 +504,52 @@ public class FragmentContacts extends FragmentBase {
|
|||
}.execute(this, args, "");
|
||||
}
|
||||
|
||||
private void onEditName(Bundle args) {
|
||||
private void onEditContact(Bundle args) {
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
long account = args.getLong("account");
|
||||
int type = args.getInt("type");
|
||||
String email = args.getString("email");
|
||||
String name = args.getString("name");
|
||||
|
||||
if (TextUtils.isEmpty(email))
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_email));
|
||||
if (!Helper.EMAIL_ADDRESS.matcher(email).matches())
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email));
|
||||
if (TextUtils.isEmpty(name))
|
||||
name = null;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.contact().setContactName(id, name);
|
||||
|
||||
EntityContact contact;
|
||||
if (id > 0)
|
||||
contact = db.contact().getContact(id);
|
||||
else
|
||||
contact = new EntityContact();
|
||||
contact.account = account;
|
||||
contact.type = type;
|
||||
contact.email = email;
|
||||
contact.name = name;
|
||||
if (id > 0)
|
||||
db.contact().updateContact(contact);
|
||||
else {
|
||||
contact.times_contacted = 0;
|
||||
contact.first_contacted = new Date().getTime();
|
||||
contact.last_contacted = contact.first_contacted;
|
||||
contact.id = db.contact().insertContact(contact);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
if (ex instanceof IllegalArgumentException)
|
||||
ToastEx.makeText(getContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "contact:name");
|
||||
}
|
||||
|
@ -531,4 +593,34 @@ public class FragmentContacts extends FragmentBase {
|
|||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
public static class FragmentDialogEditContact extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_edit_contact, null);
|
||||
final Spinner spType = view.findViewById(R.id.spType);
|
||||
final EditText etEmail = view.findViewById(R.id.etEmail);
|
||||
final EditText etName = view.findViewById(R.id.etName);
|
||||
|
||||
final Bundle args = getArguments();
|
||||
spType.setSelection(args.getInt("type"));
|
||||
etEmail.setText(args.getString("email"));
|
||||
etName.setText(args.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) {
|
||||
args.putInt("type", spType.getSelectedItemPosition());
|
||||
args.putString("email", etEmail.getText().toString());
|
||||
args.putString("name", etName.getText().toString());
|
||||
sendResult(RESULT_OK);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
59
app/src/main/res/layout/dialog_edit_contact.xml
Normal file
59
app/src/main/res/layout/dialog_edit_contact.xml
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?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/tvCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableStart="@drawable/twotone_person_24"
|
||||
android:drawablePadding="6dp"
|
||||
android:labelFor="@+id/etName"
|
||||
android:text="@string/title_edit_contact"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spType"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:entries="@array/contactTypes"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etEmail"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:autofillHints="emailAddress"
|
||||
android:hint="@string/title_contact_email"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textEmailAddress"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/spType">
|
||||
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:autofillHints="name"
|
||||
android:hint="@string/title_contact_name"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textPersonName|textCapWords"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etEmail" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,47 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="eu.faircode.email.ActivitySetup">
|
||||
tools:context="eu.faircode.email.ActivityView">
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvHintActions"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="eu.faircode.email.ActivitySetup">
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvHintActions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="6dp"
|
||||
android:text="@string/title_hint_contact_actions"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvContacts"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvHintActions" />
|
||||
|
||||
<eu.faircode.email.ContentLoadingProgressBar
|
||||
android:id="@+id/pbWait"
|
||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpReady"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="rvContacts" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabAdd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="6dp"
|
||||
android:text="@string/title_hint_contact_actions"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvContacts"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvHintActions" />
|
||||
|
||||
<eu.faircode.email.ContentLoadingProgressBar
|
||||
android:id="@+id/pbWait"
|
||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpReady"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="rvContacts" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_padding"
|
||||
android:contentDescription="@string/title_insert_contact"
|
||||
android:tooltipText="@string/title_insert_contact"
|
||||
app:backgroundTint="?attr/colorFabBackground"
|
||||
app:srcCompat="@drawable/twotone_person_add_24"
|
||||
app:tint="?attr/colorFabForeground" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -1023,6 +1023,8 @@
|
|||
<string name="title_delete_channel">Delete notification channel</string>
|
||||
<string name="title_insert_contact">Add contact</string>
|
||||
<string name="title_edit_contact">Edit contact</string>
|
||||
<string name="title_contact_email">Email</string>
|
||||
<string name="title_contact_name">Name</string>
|
||||
<string name="title_import_contacts">Import vCards</string>
|
||||
<string name="title_export_contacts">Export vCards</string>
|
||||
<string name="title_create_sub_folder">Create sub folder</string>
|
||||
|
@ -2293,6 +2295,13 @@
|
|||
<item>@string/title_editasnew</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="contactTypes" translatable="false">
|
||||
<item>Recipient</item>
|
||||
<item>Sender</item>
|
||||
<item>Blocked</item>
|
||||
<item>Not blocked</item>
|
||||
</string-array>
|
||||
|
||||
<string name="fingerprint" translatable="false">17BA15C1AF55D925F98B99CEA4375D4CDF4C174B</string>
|
||||
<string name="fingerprint_fdroid" translatable="false">77CD40058858DC3A38523E01C227A39AA019F88B</string>
|
||||
<string name="fingerprint_amazon" translatable="false">200D0AA43A8ADBC7BB8237023C1553F4753CA7D2</string>
|
||||
|
|
Loading…
Reference in a new issue