Added rule/group suggestions

This commit is contained in:
M66B 2023-04-06 09:31:47 +02:00
parent 18a80ad629
commit 06573cd57f
4 changed files with 59 additions and 2 deletions

View File

@ -62,6 +62,11 @@ public interface DaoRule {
" WHERE rule.folder = :folder")
LiveData<List<TupleRuleEx>> liveRules(long folder);
@Query("SELECT DISTINCT `group` FROM rule" +
" WHERE NOT `group` IS NULL" +
" ORDER by `group` COLLATE NOCASE")
List<String> getGroups();
@Query("SELECT COUNT(*) FROM rule")
int countTotal();

View File

@ -0,0 +1,41 @@
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 android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
public class EditTextAutoComplete extends AppCompatAutoCompleteTextView {
public EditTextAutoComplete(@NonNull Context context) {
super(context);
}
public EditTextAutoComplete(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public EditTextAutoComplete(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}

View File

@ -43,6 +43,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
@ -86,7 +87,7 @@ public class FragmentRule extends FragmentBase {
private TextView tvFolder;
private EditText etName;
private EditText etGroup;
private AutoCompleteTextView etGroup;
private EditText etOrder;
private CheckBox cbEnabled;
private CheckBox cbDaily;
@ -185,6 +186,7 @@ public class FragmentRule extends FragmentBase {
private Group grpDelete;
private Group grpLocalOnly;
private ArrayAdapter<String> adapterGroup;
private ArrayAdapter<String> adapterDay;
private ArrayAdapter<Action> adapterAction;
private ArrayAdapter<EntityIdentity> adapterIdentity;
@ -369,6 +371,10 @@ public class FragmentRule extends FragmentBase {
grpDelete = view.findViewById(R.id.grpDelete);
grpLocalOnly = view.findViewById(R.id.grpLocalOnly);
adapterGroup = new ArrayAdapter<>(getContext(), R.layout.spinner_item1_dropdown, android.R.id.text1);
etGroup.setThreshold(1);
etGroup.setAdapter(adapterGroup);
cbDaily.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -839,6 +845,7 @@ public class FragmentRule extends FragmentBase {
DB db = DB.getInstance(context);
data.account = db.account().getAccount(aid);
data.folder = db.folder().getFolder(fid);
data.groups = db.rule().getGroups();
data.identities = db.identity().getSynchronizingIdentities(aid);
data.answers = db.answer().getAnswers(false);
@ -851,6 +858,9 @@ public class FragmentRule extends FragmentBase {
data.account == null ? "" : data.account.name,
data.folder.getDisplayName(getContext())));
adapterGroup.clear();
adapterGroup.addAll(data.groups);
adapterIdentity.clear();
adapterIdentity.addAll(data.identities);
@ -1692,6 +1702,7 @@ public class FragmentRule extends FragmentBase {
private static class RefData {
EntityAccount account;
EntityFolder folder;
List<String> groups;
List<EntityIdentity> identities;
List<EntityAnswer> answers;
}

View File

@ -81,7 +81,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
<eu.faircode.email.EditTextPlain
<eu.faircode.email.EditTextAutoComplete
android:id="@+id/etGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"