Added editing rule groups

pull/212/head
M66B 2 years ago
parent 4c8866585d
commit 35993af770

@ -299,9 +299,10 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
popupMenu.getMenu().add(Menu.NONE, R.string.title_rule_execute, 2, R.string.title_rule_execute)
.setEnabled(ActivityBilling.isPro(context));
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset, 3, R.string.title_reset);
popupMenu.getMenu().add(Menu.NONE, R.string.title_rule_group, 4, R.string.title_rule_group);
if (protocol == EntityAccount.TYPE_IMAP) {
popupMenu.getMenu().add(Menu.NONE, R.string.title_move_to_folder, 4, R.string.title_move_to_folder);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 5, R.string.title_copy);
popupMenu.getMenu().add(Menu.NONE, R.string.title_move_to_folder, 5, R.string.title_move_to_folder);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 6, R.string.title_copy);
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@ -317,6 +318,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
} else if (itemId == R.string.title_reset) {
onActionReset();
return true;
} else if (itemId == R.string.title_rule_group) {
onActionGroup();
return true;
} else if (itemId == R.string.title_move_to_folder) {
onActionMove();
return true;
@ -460,6 +464,17 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
}.execute(context, owner, args, "rule:reset");
}
private void onActionGroup() {
Bundle args = new Bundle();
args.putLong("rule", rule.id);
args.putString("name", rule.group);
FragmentDialogRuleGroup fragment = new FragmentDialogRuleGroup();
fragment.setArguments(args);
fragment.setTargetFragment(parentFragment, FragmentRules.REQUEST_GROUP);
fragment.show(parentFragment.getParentFragmentManager(), "rule:group");
}
private void onActionMove() {
Bundle args = new Bundle();
args.putInt("icon", R.drawable.twotone_drive_file_move_24);

@ -86,6 +86,11 @@ public interface DaoRule {
" WHERE id = :id AND NOT (enabled IS :enabled)")
int setRuleEnabled(long id, boolean enabled);
@Query("UPDATE rule" +
" SET `group` = :group" +
" WHERE id = :id AND NOT (`group` IS :group)")
int setRuleGroup(long id, String group);
@Query("UPDATE rule" +
" SET applied = applied + 1, last_applied = :time" +
" WHERE id = :id")

@ -0,0 +1,107 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2023 by Marcel Bokhorst (M66B)
*/
import static android.app.Activity.RESULT_OK;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import java.util.List;
public class FragmentDialogRuleGroup extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Context context = getContext();
View view = LayoutInflater.from(context).inflate(R.layout.dialog_rule_group, null);
final AutoCompleteTextView etGroup = view.findViewById(R.id.etGroup);
ArrayAdapter adapterGroup = new ArrayAdapter<>(context, R.layout.spinner_item1_dropdown, android.R.id.text1);
etGroup.setThreshold(1);
etGroup.setAdapter(adapterGroup);
new SimpleTask<List<String>>() {
@Override
protected List<String> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
return db.rule().getGroups();
}
@Override
protected void onExecuted(Bundle args, List<String> groups) {
adapterGroup.clear();
adapterGroup.addAll(groups);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, new Bundle(), "rule:groups");
Bundle args = getArguments();
etGroup.setText(args.getString("name"));
etGroup.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId != EditorInfo.IME_ACTION_DONE)
return false;
AlertDialog dialog = (AlertDialog) getDialog();
if (dialog == null)
return false;
Button btnOk = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (btnOk == null)
return false;
btnOk.performClick();
return true;
}
});
return new AlertDialog.Builder(context)
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String group = etGroup.getText().toString().trim();
args.putString("name", TextUtils.isEmpty(group) ? null : group);
sendResult(RESULT_OK);
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}

@ -93,10 +93,11 @@ public class FragmentRules extends FragmentBase {
private static final int REQUEST_EXPORT = 1;
private static final int REQUEST_IMPORT = 2;
static final int REQUEST_MOVE = 3;
static final int REQUEST_RULE_COPY_ACCOUNT = 4;
static final int REQUEST_RULE_COPY_FOLDER = 5;
private static final int REQUEST_CLEAR = 6;
static final int REQUEST_GROUP = 3;
static final int REQUEST_MOVE = 4;
static final int REQUEST_RULE_COPY_ACCOUNT = 5;
static final int REQUEST_RULE_COPY_FOLDER = 6;
private static final int REQUEST_CLEAR = 7;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -266,6 +267,7 @@ public class FragmentRules extends FragmentBase {
String sort = prefs.getString("rule_sort", "order");
adapter.set(protocol, sort, rules);
rvRule.invalidateItemDecorations();
pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE);
@ -287,6 +289,10 @@ public class FragmentRules extends FragmentBase {
if (resultCode == RESULT_OK && data != null)
onImport(data);
break;
case REQUEST_GROUP:
if (resultCode == RESULT_OK && data != null)
onGroup(data.getBundleExtra("args"));
break;
case REQUEST_MOVE:
if (resultCode == RESULT_OK && data != null)
onMove(data.getBundleExtra("args"));
@ -675,6 +681,25 @@ public class FragmentRules extends FragmentBase {
}.execute(this, args, "rules:import");
}
private void onGroup(Bundle args) {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("rule");
String name = args.getString("name");
DB db = DB.getInstance(context);
db.rule().setRuleGroup(id, name);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "rule:group");
}
private void onMove(Bundle args) {
new SimpleTask<Void>() {
@Override

@ -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">
<TextView
android:id="@+id/tvGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/twotone_edit_24"
android:drawablePadding="6dp"
android:labelFor="@+id/etName"
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.EditTextAutoComplete
android:id="@+id/etGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="textCapSentences|textAutoCorrect"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvGroup">
<requestFocus />
</eu.faircode.email.EditTextAutoComplete>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save