Git commit 5696bc062ddfc609391d51aa4f8a1648fd56e024 by Simon Redman. Committed on 31/03/2018 at 22:58. Pushed by sredman into branch 'sms-history'. Change getSMS to getMessagesInThread M +13 -14 src/org/kde/kdeconnect/Helpers/SMSHelper.java https://commits.kde.org/kdeconnect-android/5696bc062ddfc609391d51aa4f8a1648= fd56e024 diff --git a/src/org/kde/kdeconnect/Helpers/SMSHelper.java b/src/org/kde/kd= econnect/Helpers/SMSHelper.java index ffbcccf..637f3f8 100644 --- a/src/org/kde/kdeconnect/Helpers/SMSHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SMSHelper.java @@ -77,40 +77,39 @@ public class SMSHelper { } = /** - * Get all the SMS threads on the phone as well as a bunch of useful-l= ooking data - *

- * Return a map keyed by Android's Thread ID to a list of all the mess= ages in that thread - * Each message is represented by a map containing the keys which seem= ed most useful and interesting + * Get all the messages in a requested thread * - * @param context android.content.Context running the request - * @return Mapping of thread ID to list of messages in that thread + * @param context android.content.Context running the request + * @param threadID Thread to look up + * @return List of all messages in the thread */ - public static Map> getSMS(Context context) { - HashMap> toReturn =3D new HashMap<>(); + public static List getMessagesInThread(Context context, Threa= dID threadID) { + List toReturn =3D new ArrayList<>(); = Uri smsUri =3D getSMSUri(); = + final String selection =3D ThreadID.lookupColumn + " =3D=3D ?"; + final String[] selectionArgs =3D new String[] { threadID.toString(= ) }; + Cursor smsCursor =3D context.getContentResolver().query( smsUri, Message.smsColumns, - null, - null, + selection, + selectionArgs, null); = if (smsCursor !=3D null && smsCursor.moveToFirst()) { int threadColumn =3D smsCursor.getColumnIndexOrThrow(ThreadID.= lookupColumn); do { int thread =3D smsCursor.getInt(threadColumn); - if (!toReturn.containsKey(thread)) { - toReturn.put(new ThreadID(thread), new ArrayList()); - } + Message messageInfo =3D new Message(); for (int columnIdx =3D 0; columnIdx < smsCursor.getColumnC= ount(); columnIdx++) { String colName =3D smsCursor.getColumnName(columnIdx); String body =3D smsCursor.getString(columnIdx); messageInfo.put(colName, body); } - toReturn.get(thread).add(messageInfo); + toReturn.add(messageInfo); } while (smsCursor.moveToNext()); } else { // No SMSes available?