|
@@ -31,11 +31,14 @@ import android.net.Uri;
|
31
|
31
|
import android.provider.Contacts;
|
32
|
32
|
import android.provider.Contacts.People;
|
33
|
33
|
import android.text.Html;
|
|
34
|
+import android.util.Log;
|
34
|
35
|
import android.view.View;
|
35
|
36
|
import android.widget.ImageView;
|
36
|
37
|
import android.widget.LinearLayout;
|
37
|
38
|
import android.widget.LinearLayout.LayoutParams;
|
38
|
39
|
import android.widget.TextView;
|
|
40
|
+import java.util.ArrayList;
|
|
41
|
+import java.util.List;
|
39
|
42
|
|
40
|
43
|
import uk.co.md87.android.contexthome.Module;
|
41
|
44
|
import uk.co.md87.android.contexthome.R;
|
|
@@ -66,40 +69,54 @@ public class EmailModule implements Module {
|
66
|
69
|
LayoutParams.WRAP_CONTENT);
|
67
|
70
|
params.weight = 1;
|
68
|
71
|
|
69
|
|
- boolean success = cursor.moveToFirst();
|
70
|
|
- for (int i = 0; i < weight && success; ) {
|
71
|
|
- final long convId = cursor.getLong(convIdIndex);
|
|
72
|
+ final List<Object[]> messages = new ArrayList<Object[]>(weight);
|
|
73
|
+ final List<Long> convIds = new ArrayList<Long>();
|
|
74
|
+
|
|
75
|
+ if (cursor.moveToFirst()) {
|
|
76
|
+ do {
|
|
77
|
+ convIds.add(cursor.getLong(convIdIndex));
|
|
78
|
+ } while (cursor.moveToNext());
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ cursor.close();
|
|
82
|
+
|
|
83
|
+ Log.e("!!!!!", convIds.toString());
|
|
84
|
+
|
|
85
|
+ for (Long convId : convIds) {
|
72
|
86
|
final Uri uri = inboxUri.buildUpon().appendEncodedPath(String.valueOf(convId)
|
73
|
87
|
+ "/messages").build();
|
74
|
88
|
|
75
|
89
|
final Cursor messageCursor = context.getContentResolver().query(uri,
|
76
|
90
|
new String[] { "fromAddress", "subject", "messageId" }, null, null, null);
|
77
|
91
|
|
|
92
|
+ while (messageCursor.getExtras().getString("status").equals("LOADING")) {
|
|
93
|
+ messageCursor.requery();
|
|
94
|
+ Thread.yield();
|
|
95
|
+ }
|
|
96
|
+
|
78
|
97
|
if (messageCursor.moveToFirst()) {
|
79
|
98
|
final int subjectIndex = messageCursor.getColumnIndex("subject");
|
80
|
99
|
final int addressIndex = messageCursor.getColumnIndex("fromAddress");
|
81
|
|
- final int messageIdIndex = messageCursor.getColumnIndex("messageId");
|
82
|
100
|
|
83
|
101
|
final String body = messageCursor.getString(subjectIndex);
|
84
|
102
|
final String address = messageCursor.getString(addressIndex);
|
85
|
103
|
final int count = messageCursor.getCount();
|
86
|
|
- final long messageId = messageCursor.getLong(messageIdIndex);
|
87
|
|
-
|
88
|
|
- layout.addView(getView(context, body, address, messageId, count), params);
|
89
|
104
|
|
90
|
|
- i++;
|
|
105
|
+ messages.add(new Object[] { body, address, count });
|
91
|
106
|
}
|
92
|
107
|
|
93
|
108
|
messageCursor.close();
|
94
|
|
- success = cursor.moveToNext();
|
95
|
109
|
}
|
96
|
|
- cursor.close();
|
97
|
|
-
|
|
110
|
+
|
|
111
|
+ for (Object[] message : messages) {
|
|
112
|
+ layout.addView(getView(context, (String) message[0],
|
|
113
|
+ (String) message[1], (Integer) message[2]), params);
|
|
114
|
+ }
|
98
|
115
|
|
99
|
116
|
return layout;
|
100
|
117
|
}
|
101
|
118
|
|
102
|
|
- private View getView(final Context context, String text, String address, final long messageId, int count) {
|
|
119
|
+ private View getView(final Context context, String text, String address, int count) {
|
103
|
120
|
final View view = View.inflate(context, R.layout.titledimage, null);
|
104
|
121
|
view.setClickable(true);
|
105
|
122
|
view.setFocusable(true);
|