|
@@ -24,6 +24,8 @@ package uk.co.md87.android.contexthome.modules;
|
24
|
24
|
|
25
|
25
|
import android.content.ContentUris;
|
26
|
26
|
import android.content.Context;
|
|
27
|
+import android.content.Intent;
|
|
28
|
+import android.content.SharedPreferences;
|
27
|
29
|
import android.database.Cursor;
|
28
|
30
|
import android.net.Uri;
|
29
|
31
|
import android.provider.Contacts;
|
|
@@ -45,16 +47,17 @@ import uk.co.md87.android.contexthome.R;
|
45
|
47
|
*/
|
46
|
48
|
public class EmailModule implements Module {
|
47
|
49
|
|
48
|
|
- private static final Uri INBOX_URI = Uri.parse("content://gmail-ls/"
|
49
|
|
- + "conversations/chris87@gmail.com");
|
50
|
|
-
|
51
|
50
|
/** {@inheritDoc} */
|
52
|
51
|
@Override
|
53
|
52
|
public View getView(final Context context, final int weight) {
|
54
|
53
|
final LinearLayout layout = new LinearLayout(context);
|
55
|
54
|
layout.setOrientation(LinearLayout.VERTICAL);
|
56
|
55
|
|
57
|
|
- final Cursor cursor = context.getContentResolver().query(INBOX_URI,
|
|
56
|
+ final Uri inboxUri = Uri.parse("content://gmail-ls/"
|
|
57
|
+ + "conversations/" + context.getSharedPreferences("email",
|
|
58
|
+ Context.MODE_WORLD_READABLE).getString("account", "chris87@gmail.com"));
|
|
59
|
+
|
|
60
|
+ final Cursor cursor = context.getContentResolver().query(inboxUri,
|
58
|
61
|
new String[] { "conversation_id" }, null, null, null);
|
59
|
62
|
|
60
|
63
|
final int convIdIndex = cursor.getColumnIndex("conversation_id");
|
|
@@ -66,7 +69,7 @@ public class EmailModule implements Module {
|
66
|
69
|
boolean success = cursor.moveToFirst();
|
67
|
70
|
for (int i = 0; i < weight && success; i++) {
|
68
|
71
|
final long convId = cursor.getLong(convIdIndex);
|
69
|
|
- final Uri uri = INBOX_URI.buildUpon().appendEncodedPath(String.valueOf(convId)
|
|
72
|
+ final Uri uri = inboxUri.buildUpon().appendEncodedPath(String.valueOf(convId)
|
70
|
73
|
+ "/messages").build();
|
71
|
74
|
|
72
|
75
|
final Cursor messageCursor = context.getContentResolver().query(uri,
|
|
@@ -76,12 +79,14 @@ public class EmailModule implements Module {
|
76
|
79
|
|
77
|
80
|
final int subjectIndex = messageCursor.getColumnIndex("subject");
|
78
|
81
|
final int addressIndex = messageCursor.getColumnIndex("fromAddress");
|
|
82
|
+ final int messageIdIndex = messageCursor.getColumnIndex("messageId");
|
79
|
83
|
|
80
|
84
|
final String body = messageCursor.getString(subjectIndex);
|
81
|
85
|
final String address = messageCursor.getString(addressIndex);
|
82
|
86
|
final int count = messageCursor.getCount();
|
|
87
|
+ final long messageId = messageCursor.getLong(messageIdIndex);
|
83
|
88
|
|
84
|
|
- layout.addView(getView(context, body, address, count), params);
|
|
89
|
+ layout.addView(getView(context, body, address, messageId, count), params);
|
85
|
90
|
|
86
|
91
|
messageCursor.close();
|
87
|
92
|
|
|
@@ -93,8 +98,18 @@ public class EmailModule implements Module {
|
93
|
98
|
return layout;
|
94
|
99
|
}
|
95
|
100
|
|
96
|
|
- private View getView(Context context, String text, String address, int count) {
|
|
101
|
+ private View getView(final Context context, String text, String address, final long messageId, int count) {
|
97
|
102
|
final View view = View.inflate(context, R.layout.titledimage, null);
|
|
103
|
+ view.setClickable(true);
|
|
104
|
+ view.setFocusable(true);
|
|
105
|
+ view.setOnClickListener(new View.OnClickListener() {
|
|
106
|
+
|
|
107
|
+ public void onClick(View arg0) {
|
|
108
|
+ final Intent intent = new Intent();
|
|
109
|
+ intent.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
|
|
110
|
+ context.startActivity(intent);
|
|
111
|
+ }
|
|
112
|
+ });
|
98
|
113
|
|
99
|
114
|
final Uri contactUri = Uri.parse("content://contacts/contact_methods");
|
100
|
115
|
|