Added setting to sort suggested addresses on usage frequency

pull/178/head
M66B 5 years ago
parent 7b617e4d7c
commit f5e9ee86d1

@ -63,8 +63,7 @@ public interface DaoContact {
" AND (:type IS NULL OR type = :type)" +
" AND (email LIKE :query COLLATE NOCASE OR name LIKE :query COLLATE NOCASE)" +
" AND state <> " + EntityContact.STATE_IGNORE +
" GROUP BY name, email" +
" LIMIT " + EntityContact.MAX_SUGGEST)
" GROUP BY name, email")
List<EntityContact> searchContacts(Long account, Integer type, String query);
@Insert

@ -61,8 +61,6 @@ public class EntityContact implements Serializable {
static final int STATE_FAVORITE = 1;
static final int STATE_IGNORE = 2;
static final int MAX_SUGGEST = 50; // per category: Android, local to/from
@PrimaryKey(autoGenerate = true)
public Long id;
@NonNull

@ -680,6 +680,7 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final boolean suggest_sent = prefs.getBoolean("suggest_sent", true);
final boolean suggest_received = prefs.getBoolean("suggest_received", false);
final boolean suggest_frequently = prefs.getBoolean("suggest_frequently", false);
final boolean cc_bcc = prefs.getBoolean("cc_bcc", false);
final boolean circular = prefs.getBoolean("circular", true);
final float dp3 = Helper.dp2pixels(getContext(), 3);
@ -764,13 +765,14 @@ public class FragmentCompose extends FragmentBase {
new String[]{wildcard, wildcard},
null);
while (map.size() < EntityContact.MAX_SUGGEST &&
cursor != null && cursor.moveToNext()) {
while (cursor != null && cursor.moveToNext()) {
EntityContact item = new EntityContact();
item.id = 0L;
item.name = cursor.getString(0);
item.email = cursor.getString(1);
item.avatar = cursor.getString(2);
item.times_contacted = 0;
item.last_contacted = 0L;
EntityContact existing = map.get(item.email);
if (existing == null ||
(existing.avatar == null && item.avatar != null))
@ -783,9 +785,15 @@ public class FragmentCompose extends FragmentBase {
items.addAll(db.contact().searchContacts(null, EntityContact.TYPE_TO, wildcard));
if (suggest_received)
items.addAll(db.contact().searchContacts(null, EntityContact.TYPE_FROM, wildcard));
for (EntityContact item : items)
if (!map.containsKey(item.email))
for (EntityContact item : items) {
EntityContact existing = map.get(item.email);
if (existing == null)
map.put(item.email, item);
else {
existing.times_contacted = Math.max(existing.times_contacted, item.times_contacted);
existing.last_contacted = Math.max(existing.last_contacted, item.last_contacted);
}
}
items = new ArrayList<>(map.values());
@ -795,10 +803,22 @@ public class FragmentCompose extends FragmentBase {
Collections.sort(items, new Comparator<EntityContact>() {
@Override
public int compare(EntityContact i1, EntityContact i2) {
int l = i1.id.compareTo(i2.id);
if (l != 0)
return l;
if (suggest_frequently) {
int t = -i1.times_contacted.compareTo(i2.times_contacted);
if (t != 0)
return t;
int l = -i1.last_contacted.compareTo(i2.last_contacted);
if (l != 0)
return l;
} else {
int a = -Boolean.compare(i1.id == 0, i2.id == 0);
if (a != 0)
return a;
}
if (TextUtils.isEmpty(i1.name) && TextUtils.isEmpty(i2.name))
return 0;
if (TextUtils.isEmpty(i1.name) && !TextUtils.isEmpty(i2.name))
return 1;
if (!TextUtils.isEmpty(i1.name) && TextUtils.isEmpty(i2.name))

@ -45,6 +45,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swKeyboard;
private SwitchCompat swSuggestSent;
private SwitchCompat swSuggestReceived;
private SwitchCompat swSuggestFrequently;
private Button btnLocalContacts;
private SwitchCompat swSendReminders;
private Spinner spSendDelayed;
@ -64,7 +65,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swLookupMx;
private final static String[] RESET_OPTIONS = new String[]{
"keyboard", "suggest_sent", "suggested_received", "send_reminders", "send_delayed",
"keyboard", "suggest_sent", "suggested_received", "suggest_frequently",
"send_reminders", "send_delayed",
"prefix_once", "extended_reply", "quote_reply", "resize_reply", "signature_location",
"plain_only", "format_flowed", "usenet_signature", "remove_signatures",
"receipt_default", "receipt_type", "lookup_mx"
@ -83,6 +85,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swKeyboard = view.findViewById(R.id.swKeyboard);
swSuggestSent = view.findViewById(R.id.swSuggestSent);
swSuggestReceived = view.findViewById(R.id.swSuggestReceived);
swSuggestFrequently = view.findViewById(R.id.swSuggestFrequently);
btnLocalContacts = view.findViewById(R.id.btnLocalContacts);
swSendReminders = view.findViewById(R.id.swSendReminders);
spSendDelayed = view.findViewById(R.id.spSendDelayed);
@ -128,6 +131,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
}
});
swSuggestFrequently.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("suggest_frequently", checked).apply();
}
});
btnLocalContacts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -299,6 +309,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swKeyboard.setChecked(prefs.getBoolean("keyboard", true));
swSuggestSent.setChecked(prefs.getBoolean("suggest_sent", true));
swSuggestReceived.setChecked(prefs.getBoolean("suggest_received", false));
swSuggestFrequently.setChecked(prefs.getBoolean("suggest_frequently", false));
swSendReminders.setChecked(prefs.getBoolean("send_reminders", true));
int send_delayed = prefs.getInt("send_delayed", 0);

@ -87,6 +87,18 @@
app:layout_constraintTop_toBottomOf="@id/swSuggestSent"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSuggestFrequently"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_suggest_frequently"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSuggestReceived"
app:switchPadding="12dp" />
<Button
android:id="@+id/btnLocalContacts"
style="?android:attr/buttonStyleSmall"
@ -96,7 +108,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_setup_manage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSuggestReceived" />
app:layout_constraintTop_toBottomOf="@id/swSuggestFrequently" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSendReminders"

@ -274,6 +274,7 @@
<string name="title_advanced_suggest_local">Suggest locally stored contacts</string>
<string name="title_advanced_suggest_sent">Suggest addresses found in sent messages</string>
<string name="title_advanced_suggest_received">Suggest addresses found in received messages</string>
<string name="title_advanced_suggest_frequently">Sort suggested addresses on frequency of use</string>
<string name="title_advanced_prefix_once">Prefix subject only once on replying or forwarding</string>
<string name="title_advanced_extended_reply">Use extended reply/forward header</string>
<string name="title_advanced_quote_reply">Quote replied text</string>

Loading…
Cancel
Save