mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-04 03:43:55 +01:00
Added contact picker to rule definition, added action remark
This commit is contained in:
@@ -122,6 +122,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
static final int REQUEST_ATTACHMENT = 2;
|
||||
static final int REQUEST_ATTACHMENTS = 3;
|
||||
static final int REQUEST_DECRYPT = 4;
|
||||
static final int REQUEST_SENDER = 5;
|
||||
|
||||
static final String ACTION_VIEW_MESSAGES = BuildConfig.APPLICATION_ID + ".VIEW_MESSAGES";
|
||||
static final String ACTION_VIEW_THREAD = BuildConfig.APPLICATION_ID + ".VIEW_THREAD";
|
||||
@@ -1377,6 +1378,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
if (data != null)
|
||||
decrypt(data, message);
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void saveRaw(Intent data) {
|
||||
|
||||
@@ -21,8 +21,12 @@ package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -32,8 +36,10 @@ import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
@@ -50,6 +56,8 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
public class FragmentRule extends FragmentBase {
|
||||
private ViewGroup view;
|
||||
private ScrollView scroll;
|
||||
@@ -60,11 +68,13 @@ public class FragmentRule extends FragmentBase {
|
||||
private CheckBox cbStop;
|
||||
private EditText etSender;
|
||||
private CheckBox cbSender;
|
||||
private ImageView ivSender;
|
||||
private EditText etSubject;
|
||||
private CheckBox cbSubject;
|
||||
private EditText etHeader;
|
||||
private CheckBox cbHeader;
|
||||
private Spinner spAction;
|
||||
private TextView tvActionRemark;
|
||||
private Spinner spTarget;
|
||||
private Spinner spIdent;
|
||||
private Spinner spAnswer;
|
||||
@@ -108,11 +118,13 @@ public class FragmentRule extends FragmentBase {
|
||||
cbStop = view.findViewById(R.id.cbStop);
|
||||
etSender = view.findViewById(R.id.etSender);
|
||||
cbSender = view.findViewById(R.id.cbSender);
|
||||
ivSender = view.findViewById(R.id.ivSender);
|
||||
etSubject = view.findViewById(R.id.etSubject);
|
||||
cbSubject = view.findViewById(R.id.cbSubject);
|
||||
etHeader = view.findViewById(R.id.etHeader);
|
||||
cbHeader = view.findViewById(R.id.cbHeader);
|
||||
spAction = view.findViewById(R.id.spAction);
|
||||
tvActionRemark = view.findViewById(R.id.tvActionRemark);
|
||||
spTarget = view.findViewById(R.id.spTarget);
|
||||
spIdent = view.findViewById(R.id.spIdent);
|
||||
spAnswer = view.findViewById(R.id.spAnswer);
|
||||
@@ -122,6 +134,17 @@ public class FragmentRule extends FragmentBase {
|
||||
grpMove = view.findViewById(R.id.grpMove);
|
||||
grpAnswer = view.findViewById(R.id.grpAnswer);
|
||||
|
||||
ivSender.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent pick = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Email.CONTENT_URI);
|
||||
if (pick.resolveActivity(getContext().getPackageManager()) == null)
|
||||
Snackbar.make(view, R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
|
||||
else
|
||||
startActivityForResult(Helper.getChooser(getContext(), pick), ActivityView.REQUEST_SENDER);
|
||||
}
|
||||
});
|
||||
|
||||
adapterAction = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<Action>());
|
||||
adapterAction.setDropDownViewResource(R.layout.spinner_item1_dropdown);
|
||||
spAction.setAdapter(adapterAction);
|
||||
@@ -173,6 +196,8 @@ public class FragmentRule extends FragmentBase {
|
||||
}
|
||||
});
|
||||
|
||||
tvActionRemark.setVisibility(View.GONE);
|
||||
|
||||
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
@@ -205,16 +230,19 @@ public class FragmentRule extends FragmentBase {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("account", account);
|
||||
args.putLong("folder", folder);
|
||||
|
||||
new SimpleTask<RefData>() {
|
||||
@Override
|
||||
protected RefData onExecute(Context context, Bundle args) {
|
||||
long account = args.getLong("account");
|
||||
long aid = args.getLong("account");
|
||||
long fid = args.getLong("folder");
|
||||
|
||||
RefData data = new RefData();
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
data.folders = db.folder().getFolders(account);
|
||||
data.folder = db.folder().getFolder(fid);
|
||||
data.folders = db.folder().getFolders(aid);
|
||||
|
||||
if (data.folders == null)
|
||||
data.folders = new ArrayList<>();
|
||||
@@ -223,7 +251,7 @@ public class FragmentRule extends FragmentBase {
|
||||
folder.display = folder.getDisplayName(context);
|
||||
EntityFolder.sort(context, data.folders);
|
||||
|
||||
data.identities = db.identity().getIdentities(account);
|
||||
data.identities = db.identity().getIdentities(aid);
|
||||
data.answers = db.answer().getAnswers();
|
||||
|
||||
return data;
|
||||
@@ -240,6 +268,10 @@ public class FragmentRule extends FragmentBase {
|
||||
adapterAnswer.clear();
|
||||
adapterAnswer.addAll(data.answers);
|
||||
|
||||
tvActionRemark.setText(
|
||||
getString(R.string.title_rule_action_remark, data.folder.getDisplayName(getContext())));
|
||||
tvActionRemark.setVisibility(View.VISIBLE);
|
||||
|
||||
Bundle rargs = new Bundle();
|
||||
rargs.putLong("id", id);
|
||||
|
||||
@@ -339,6 +371,38 @@ public class FragmentRule extends FragmentBase {
|
||||
}.execute(this, args, "rule:accounts");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log.i("Request=" + requestCode + " result=" + resultCode + " data=" + data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == ActivityView.REQUEST_SENDER) {
|
||||
if (data != null)
|
||||
handlePickContact(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePickContact(Intent data) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
Uri uri = data.getData();
|
||||
if (uri != null)
|
||||
cursor = getContext().getContentResolver().query(uri,
|
||||
new String[]{
|
||||
ContactsContract.CommonDataKinds.Email.ADDRESS
|
||||
},
|
||||
null, null, null);
|
||||
if (cursor != null && cursor.moveToFirst())
|
||||
etSender.setText(cursor.getString(0));
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void onActionTrash() {
|
||||
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
||||
.setMessage(R.string.title_ask_delete_rule)
|
||||
@@ -535,6 +599,7 @@ public class FragmentRule extends FragmentBase {
|
||||
}
|
||||
|
||||
private class RefData {
|
||||
EntityFolder folder;
|
||||
List<EntityFolder> folders;
|
||||
List<EntityIdentity> identities;
|
||||
List<EntityAnswer> answers;
|
||||
|
||||
@@ -117,10 +117,21 @@
|
||||
android:hint="@string/title_optional"
|
||||
android:inputType="textEmailAddress"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ivSender"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbSender" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivSender"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:src="@drawable/baseline_person_24"
|
||||
app:layout_constraintBottom_toBottomOf="@id/etSender"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/etSender" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAndSubject"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -239,7 +250,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_rule_action"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAction" />
|
||||
|
||||
@@ -251,6 +262,17 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAction" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvActionRemark"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_rule_action_remark"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/spAction" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparatorParameters"
|
||||
android:layout_width="match_parent"
|
||||
@@ -258,7 +280,7 @@
|
||||
android:layout_marginTop="24dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/spAction" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvActionRemark" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMoveTarget"
|
||||
|
||||
@@ -416,6 +416,7 @@
|
||||
<string name="title_rule_regex">Regex</string>
|
||||
<string name="title_rule_and">AND</string>
|
||||
<string name="title_rule_action">Action</string>
|
||||
<string name="title_rule_action_remark">This action will be applied to new messages arriving in the folder %1$s</string>
|
||||
<string name="title_rule_folder">Folder</string>
|
||||
<string name="title_rule_identity">Identity</string>
|
||||
<string name="title_rule_answer">Reply template</string>
|
||||
|
||||
Reference in New Issue
Block a user