From kde-commits Sat Mar 31 22:52:51 2018 From: Simon Redman Date: Sat, 31 Mar 2018 22:52:51 +0000 To: kde-commits Subject: [kdeconnect-android/sms-history] src/org/kde/kdeconnect/Helpers: Add custom type for ThreadID Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=152253678506206 Git commit 0644a39124f016a57787289d383d6ea9cca317cd by Simon Redman. Committed on 31/03/2018 at 22:41. Pushed by sredman into branch 'sms-history'. Add custom type for ThreadID M +38 -9 src/org/kde/kdeconnect/Helpers/SMSHelper.java https://commits.kde.org/kdeconnect-android/0644a39124f016a57787289d383d6ea9= cca317cd diff --git a/src/org/kde/kdeconnect/Helpers/SMSHelper.java b/src/org/kde/kd= econnect/Helpers/SMSHelper.java index 702e35a..3c45011 100644 --- a/src/org/kde/kdeconnect/Helpers/SMSHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SMSHelper.java @@ -45,7 +45,7 @@ public class SMSHelper { Telephony.Sms.TYPE, // Compare with Telephony.TextBasedSms= Columns.MESSAGE_TYPE_* Telephony.Sms.PERSON, // Some obscure value that corresponds= to the contact Telephony.Sms.READ, // Whether we have received a read rep= ort for this message (int) - Telephony.Sms.THREAD_ID, // Magic number which binds (message)= threads + ThreadID.lookupColumn, // Magic number which binds (message) t= hreads }; = /** @@ -98,8 +98,8 @@ public class SMSHelper { * @param context android.content.Context running the request * @return Mapping of thread ID to list of messages in that thread */ - public static Map>> getSMS(Context c= ontext) { - HashMap>> toReturn =3D new HashM= ap<>(); + public static Map>> getSMS(Context = context) { + HashMap>> toReturn =3D new Hash= Map<>(); = Uri smsUri =3D getSMSUri(); = @@ -111,11 +111,11 @@ public class SMSHelper { null); = if (smsCursor !=3D null && smsCursor.moveToFirst()) { - int threadColumn =3D smsCursor.getColumnIndexOrThrow(Telephony= .Sms.THREAD_ID); + int threadColumn =3D smsCursor.getColumnIndexOrThrow(ThreadID.= lookupColumn); do { int thread =3D smsCursor.getInt(threadColumn); if (!toReturn.containsKey(thread)) { - toReturn.put(thread, new ArrayList= >()); + toReturn.put(new ThreadID(thread), new ArrayList>()); } Map messageInfo =3D new HashMap<>(); for (int columnIdx =3D 0; columnIdx < smsCursor.getColumnC= ount(); columnIdx++) { @@ -143,8 +143,8 @@ public class SMSHelper { * @param context android.content.Context running the request * @return Mapping of thread_id to the interesting information from th= e first message in each thread */ - public static Map> getConversations(Conte= xt context) { - HashMap> toReturn =3D new HashMap<>(); + public static Map> getConversations(Cont= ext context) { + HashMap> toReturn =3D new HashMap<>(= ); = Uri conversationUri =3D getConversationUri(); = @@ -156,7 +156,7 @@ public class SMSHelper { null); = if (conversationsCursor !=3D null && conversationsCursor.moveToFir= st()) { - int threadColumn =3D conversationsCursor.getColumnIndexOrThrow= (Telephony.Sms.THREAD_ID); + int threadColumn =3D conversationsCursor.getColumnIndexOrThrow= (ThreadID.lookupColumn); do { int thread =3D conversationsCursor.getInt(threadColumn); = @@ -166,7 +166,7 @@ public class SMSHelper { String body =3D conversationsCursor.getString(columnId= x); messageInfo.put(colName, body); } - toReturn.put(thread, messageInfo); + toReturn.put(new ThreadID(thread), messageInfo); } while (conversationsCursor.moveToNext()); } else { // No conversations available? @@ -179,5 +179,34 @@ public class SMSHelper { return toReturn; } = + /** + * Represent an ID used to uniquely identify a message thread + */ + public static class ThreadID { + Integer threadID; + static final String lookupColumn =3D Telephony.Sms.THREAD_ID; + + public ThreadID(Integer threadID) { + this.threadID =3D threadID; + } + + public String toString() { + return this.threadID.toString(); + } + + @Override + public int hashCode() { + return this.threadID.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other.getClass().isAssignableFrom(ThreadID.class)) { + return ((ThreadID) other).threadID.equals(this.threadID); + } + + return false; + } + } } =