Quick sort senders/recipients

pull/214/head
M66B 11 months ago
parent 3a122b88ef
commit efc29f28c5

@ -8585,6 +8585,40 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
gotoPos = pos; gotoPos = pos;
} }
private static void quickSort(TupleMessageEx message, int low, int high) {
if (low < high) {
int pi = quickPartition(message, low, high);
quickSort(message, low, pi - 1);
quickSort(message, pi + 1, high);
}
}
private static int quickPartition(TupleMessageEx message, int low, int high) {
long pivot = message.group_received[high];
int i = (low - 1);
for (int j = low; j <= high; j++)
if (message.group_received[j] < pivot) {
i++;
quickSwap(message, i, j);
}
quickSwap(message, i + 1, high);
return (i + 1);
}
private static void quickSwap(TupleMessageEx message, int i, int j) {
long received = message.group_received[i];
message.group_received[i] = message.group_received[j];
message.group_received[j] = received;
Address sender = message.senders[i];
message.senders[i] = message.senders[j];
message.senders[j] = sender;
Address recipient = message.recipients[i];
message.recipients[i] = message.recipients[j];
message.recipients[j] = recipient;
}
void submitList(PagedList<TupleMessageEx> list) { void submitList(PagedList<TupleMessageEx> list) {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
TupleMessageEx message = list.get(i); TupleMessageEx message = list.get(i);
@ -8595,6 +8629,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
addExtra(message.senders, message.extra); addExtra(message.senders, message.extra);
message.resolveLabelColors(context); message.resolveLabelColors(context);
message.resolveKeywordColors(context); message.resolveKeywordColors(context);
if (message.group_received != null && message.group_received.length > 1 &&
message.senders != null && message.senders.length == message.group_received.length &&
message.recipients != null && message.recipients.length == message.group_received.length)
quickSort(message, 0, message.group_received.length - 1);
} }
} }

@ -3030,6 +3030,23 @@ public abstract class DB extends RoomDatabase {
} }
public static class Converters { public static class Converters {
@TypeConverter
public static long[] toLongArray(String value) {
if (TextUtils.isEmpty(value))
return new long[0];
else {
String[] received = TextUtils.split(value, ",");
long[] result = new long[received.length];
for (int i = 0; i < result.length; i++)
try {
result[i] = Long.parseLong(received[i]);
} catch (NumberFormatException ex) {
Log.e(ex);
}
return result;
}
}
@TypeConverter @TypeConverter
public static String[] toStringArray(String value) { public static String[] toStringArray(String value) {
if (value == null) if (value == null)

@ -53,6 +53,7 @@ public interface DaoMessage {
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" +
", '[' || group_concat(message.`to`, ',') || ']' AS recipients" + ", '[' || group_concat(message.`to`, ',') || ']' AS recipients" +
", group_concat(message.received, ',') AS group_received" +
", COUNT(message.id) AS count" + ", COUNT(message.id) AS count" +
", SUM(1 - message.ui_seen) AS unseen" + ", SUM(1 - message.ui_seen) AS unseen" +
", SUM(1 - message.ui_flagged) AS unflagged" + ", SUM(1 - message.ui_flagged) AS unflagged" +
@ -77,7 +78,6 @@ public interface DaoMessage {
" THEN message.received ELSE 0 END) AS dummy" + " THEN message.received ELSE 0 END) AS dummy" +
" FROM message" + " FROM message" +
// group_concat
" JOIN message AS mm ON mm.thread = message.thread" + " JOIN message AS mm ON mm.thread = message.thread" +
" AND (NOT :found OR mm.ui_found) AND (NOT mm.ui_hide OR :debug)" + " AND (NOT :found OR mm.ui_found) AND (NOT mm.ui_hide OR :debug)" +
" JOIN folder AS ff ON ff.id = mm.folder" + " JOIN folder AS ff ON ff.id = mm.folder" +
@ -114,8 +114,7 @@ public interface DaoMessage {
" WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" + " WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" +
" ELSE 0" + " ELSE 0" +
" END" + " END" +
", CASE WHEN :ascending THEN message.received ELSE -message.received END" + ", CASE WHEN :ascending THEN message.received ELSE -message.received END")
", mm.received")
DataSource.Factory<Integer, TupleMessageEx> pagedUnified( DataSource.Factory<Integer, TupleMessageEx> pagedUnified(
String type, String type,
boolean threading, boolean group_category, boolean threading, boolean group_category,
@ -133,6 +132,7 @@ public interface DaoMessage {
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" +
", '[' || group_concat(message.`to`, ',') || ']' AS recipients" + ", '[' || group_concat(message.`to`, ',') || ']' AS recipients" +
", group_concat(message.received, ',') AS group_received" +
", COUNT(message.id) AS count" + ", COUNT(message.id) AS count" +
", SUM(1 - message.ui_seen) AS unseen" + ", SUM(1 - message.ui_seen) AS unseen" +
", SUM(1 - message.ui_flagged) AS unflagged" + ", SUM(1 - message.ui_flagged) AS unflagged" +
@ -156,7 +156,6 @@ public interface DaoMessage {
" THEN message.received ELSE 0 END) AS dummy" + " THEN message.received ELSE 0 END) AS dummy" +
" FROM message" + " FROM message" +
// group_concat
" JOIN message AS mm ON mm.thread = message.thread" + " JOIN message AS mm ON mm.thread = message.thread" +
" AND (NOT :found OR mm.ui_found) AND (NOT mm.ui_hide OR :debug)" + " AND (NOT :found OR mm.ui_found) AND (NOT mm.ui_hide OR :debug)" +
" AND message.folder = :folder" + " AND message.folder = :folder" +
@ -189,8 +188,7 @@ public interface DaoMessage {
" WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" + " WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" +
" ELSE 0" + " ELSE 0" +
" END" + " END" +
", CASE WHEN :ascending THEN message.received ELSE -message.received END" + ", CASE WHEN :ascending THEN message.received ELSE -message.received END")
", mm.received")
DataSource.Factory<Integer, TupleMessageEx> pagedFolder( DataSource.Factory<Integer, TupleMessageEx> pagedFolder(
long folder, boolean threading, long folder, boolean threading,
String sort, boolean ascending, String sort, boolean ascending,
@ -206,6 +204,7 @@ public interface DaoMessage {
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
", message.`to` AS recipients" + ", message.`to` AS recipients" +
", message.received AS group_received" +
", 1 AS count" + ", 1 AS count" +
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
@ -512,6 +511,7 @@ public interface DaoMessage {
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
", message.`to` AS recipients" + ", message.`to` AS recipients" +
", message.received AS group_received" +
", 1 AS count" + ", 1 AS count" +
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
@ -543,6 +543,7 @@ public interface DaoMessage {
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
", message.`to` AS recipients" + ", message.`to` AS recipients" +
", message.received AS group_received" +
", 1 AS count" + ", 1 AS count" +
", 1 AS unseen" + ", 1 AS unseen" +
", 0 AS unflagged" + ", 0 AS unflagged" +

@ -55,6 +55,7 @@ public class TupleMessageEx extends EntityMessage {
public Boolean identitySynchronize; public Boolean identitySynchronize;
public Address[] senders; public Address[] senders;
public Address[] recipients; public Address[] recipients;
public long[] group_received;
public int count; public int count;
public int unseen; public int unseen;
public int unflagged; public int unflagged;

Loading…
Cancel
Save