am e2569831: Add sourceKey to Body table; add flags for reply/forward in Message

Merge commit 'e25698319325d5e9619bc45ae85d861b0f1c5954' into eclair-plus-aosp

* commit 'e25698319325d5e9619bc45ae85d861b0f1c5954':
  Add sourceKey to Body table; add flags for reply/forward in Message
This commit is contained in:
Marc Blank 2009-09-08 16:45:26 -07:00 committed by Android Git Automerger
commit 2682d82b81
5 changed files with 61 additions and 11 deletions

View File

@ -622,6 +622,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
values.put(MessageColumns.DISPLAY_NAME, message.mDisplayName); values.put(MessageColumns.DISPLAY_NAME, message.mDisplayName);
values.put(MessageColumns.FLAG_LOADED, message.mFlagLoaded); values.put(MessageColumns.FLAG_LOADED, message.mFlagLoaded);
values.put(MessageColumns.FLAG_ATTACHMENT, message.mFlagAttachment); values.put(MessageColumns.FLAG_ATTACHMENT, message.mFlagAttachment);
values.put(MessageColumns.FLAGS, message.mFlags);
return values; return values;
} }
@ -668,6 +669,16 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
message.mDisplayName = makeDisplayName(message.mTo, message.mCc, message.mBcc); message.mDisplayName = makeDisplayName(message.mTo, message.mCc, message.mBcc);
message.mFlagLoaded = Message.LOADED; message.mFlagLoaded = Message.LOADED;
message.mFlagAttachment = hasAttachments; message.mFlagAttachment = hasAttachments;
String action = getIntent().getAction();
// Use the Intent to set flags saying this message is a reply or a forward and save the
// unique id of the source message
if (ACTION_REPLY.equals(action) || ACTION_REPLY_ALL.equals(action)) {
message.mFlags |= Message.FLAG_TYPE_REPLY;
message.mSourceKey = mSource.mId;
} else if (ACTION_FORWARD.equals(action)) {
message.mFlags |= Message.FLAG_TYPE_FORWARD;
message.mSourceKey = mSource.mId;
}
} }
private Attachment[] getAttachmentsFromUI() { private Attachment[] getAttachmentsFromUI() {

View File

@ -185,6 +185,8 @@ public abstract class EmailContent {
public static final String HTML_REPLY = "htmlReply"; public static final String HTML_REPLY = "htmlReply";
// Replied-to or forwarded body (in text form) // Replied-to or forwarded body (in text form)
public static final String TEXT_REPLY = "textReply"; public static final String TEXT_REPLY = "textReply";
// Message id of the source (if this is a reply/forward)
public static final String SOURCE_MESSAGE_KEY = "sourceMessageKey";
} }
public static final class Body extends EmailContent implements BodyColumns { public static final class Body extends EmailContent implements BodyColumns {
@ -198,9 +200,10 @@ public abstract class EmailContent {
public static final int CONTENT_TEXT_CONTENT_COLUMN = 3; public static final int CONTENT_TEXT_CONTENT_COLUMN = 3;
public static final int CONTENT_HTML_REPLY_COLUMN = 4; public static final int CONTENT_HTML_REPLY_COLUMN = 4;
public static final int CONTENT_TEXT_REPLY_COLUMN = 5; public static final int CONTENT_TEXT_REPLY_COLUMN = 5;
public static final int CONTENT_SOURCE_KEY_COLUMN = 6;
public static final String[] CONTENT_PROJECTION = new String[] { public static final String[] CONTENT_PROJECTION = new String[] {
RECORD_ID, BodyColumns.MESSAGE_KEY, BodyColumns.HTML_CONTENT, BodyColumns.TEXT_CONTENT, RECORD_ID, BodyColumns.MESSAGE_KEY, BodyColumns.HTML_CONTENT, BodyColumns.TEXT_CONTENT,
BodyColumns.HTML_REPLY, BodyColumns.TEXT_REPLY BodyColumns.HTML_REPLY, BodyColumns.TEXT_REPLY, BodyColumns.SOURCE_MESSAGE_KEY
}; };
public static final int TEXT_TEXT_COLUMN = 1; public static final int TEXT_TEXT_COLUMN = 1;
@ -220,6 +223,7 @@ public abstract class EmailContent {
public String mTextContent; public String mTextContent;
public String mHtmlReply; public String mHtmlReply;
public String mTextReply; public String mTextReply;
public long mSourceKey;
public Body() { public Body() {
mBaseUri = CONTENT_URI; mBaseUri = CONTENT_URI;
@ -235,6 +239,7 @@ public abstract class EmailContent {
values.put(BodyColumns.TEXT_CONTENT, mTextContent); values.put(BodyColumns.TEXT_CONTENT, mTextContent);
values.put(BodyColumns.HTML_REPLY, mHtmlReply); values.put(BodyColumns.HTML_REPLY, mHtmlReply);
values.put(BodyColumns.TEXT_REPLY, mTextReply); values.put(BodyColumns.TEXT_REPLY, mTextReply);
values.put(BodyColumns.SOURCE_MESSAGE_KEY, mSourceKey);
return values; return values;
} }
@ -330,6 +335,7 @@ public abstract class EmailContent {
mTextContent = c.getString(CONTENT_TEXT_CONTENT_COLUMN); mTextContent = c.getString(CONTENT_TEXT_CONTENT_COLUMN);
mHtmlReply = c.getString(CONTENT_HTML_REPLY_COLUMN); mHtmlReply = c.getString(CONTENT_HTML_REPLY_COLUMN);
mTextReply = c.getString(CONTENT_TEXT_REPLY_COLUMN); mTextReply = c.getString(CONTENT_TEXT_REPLY_COLUMN);
mSourceKey = c.getLong(CONTENT_SOURCE_KEY_COLUMN);
return this; return this;
} }
@ -484,22 +490,33 @@ public abstract class EmailContent {
public String mBcc; public String mBcc;
public String mReplyTo; public String mReplyTo;
// The following transient members may be used while building and manipulating messages,
// but they are NOT persisted directly by EmailProvider
transient public String mText; transient public String mText;
transient public String mHtml; transient public String mHtml;
transient public String mTextReply; transient public String mTextReply;
transient public String mHtmlReply; transient public String mHtmlReply;
transient public long mSourceKey;
// Can be used while building messages, but is NOT saved by the Provider
transient public ArrayList<Attachment> mAttachments = null; transient public ArrayList<Attachment> mAttachments = null;
// Values used in mFlagRead
public static final int UNREAD = 0; public static final int UNREAD = 0;
public static final int READ = 1; public static final int READ = 1;
public static final int DELETED = 2; public static final int DELETED = 2;
// Values used in mFlagLoaded
public static final int NOT_LOADED = 0; public static final int NOT_LOADED = 0;
public static final int LOADED = 1; public static final int LOADED = 1;
public static final int PARTIALLY_LOADED = 2; public static final int PARTIALLY_LOADED = 2;
// Bits used in mFlags
// These three states are mutually exclusive, and indicate whether the message is an
// original, a reply, or a forward
public static final int FLAG_TYPE_ORIGINAL = 0;
public static final int FLAG_TYPE_REPLY = 1<<0;
public static final int FLAG_TYPE_FORWARD = 1<<1;
public static final int FLAG_TYPE_MASK = FLAG_TYPE_REPLY | FLAG_TYPE_FORWARD;
public Message() { public Message() {
mBaseUri = CONTENT_URI; mBaseUri = CONTENT_URI;
} }
@ -665,6 +682,9 @@ public abstract class EmailContent {
if (mHtmlReply != null) { if (mHtmlReply != null) {
cv.put(Body.HTML_REPLY, mHtmlReply); cv.put(Body.HTML_REPLY, mHtmlReply);
} }
if (mSourceKey != 0) {
cv.put(Body.SOURCE_MESSAGE_KEY, mSourceKey);
}
b = ContentProviderOperation.newInsert(Body.CONTENT_URI); b = ContentProviderOperation.newInsert(Body.CONTENT_URI);
b.withValues(cv); b.withValues(cv);
ContentValues backValues = new ContentValues(); ContentValues backValues = new ContentValues();

View File

@ -56,9 +56,13 @@ public class EmailProvider extends ContentProvider {
static final String BODY_DATABASE_NAME = "EmailProviderBody.db"; static final String BODY_DATABASE_NAME = "EmailProviderBody.db";
// Any changes to the database format *must* include update-in-place code. // Any changes to the database format *must* include update-in-place code.
// Original version: 3
public static final int DATABASE_VERSION = 3; public static final int DATABASE_VERSION = 3;
public static final int BODY_DATABASE_VERSION = 2;
// Any changes to the database format *must* include update-in-place code.
// Original version: 2
// Version 3: Add "sourceKey" column
public static final int BODY_DATABASE_VERSION = 3;
public static final String EMAIL_AUTHORITY = "com.android.email.provider"; public static final String EMAIL_AUTHORITY = "com.android.email.provider";
@ -480,18 +484,26 @@ public class EmailProvider extends ContentProvider {
+ BodyColumns.HTML_CONTENT + " text, " + BodyColumns.HTML_CONTENT + " text, "
+ BodyColumns.TEXT_CONTENT + " text, " + BodyColumns.TEXT_CONTENT + " text, "
+ BodyColumns.HTML_REPLY + " text, " + BodyColumns.HTML_REPLY + " text, "
+ BodyColumns.TEXT_REPLY + " text" + BodyColumns.TEXT_REPLY + " text, "
+ BodyColumns.SOURCE_MESSAGE_KEY + " text"
+ ");"; + ");";
db.execSQL("create table " + Body.TABLE_NAME + s); db.execSQL("create table " + Body.TABLE_NAME + s);
db.execSQL(createIndex(Body.TABLE_NAME, BodyColumns.MESSAGE_KEY)); db.execSQL(createIndex(Body.TABLE_NAME, BodyColumns.MESSAGE_KEY));
} }
static void upgradeBodyTable(SQLiteDatabase db, int oldVersion, int newVersion) { static void upgradeBodyTable(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 2) {
// Versions earlier than 2 require a wipe of the database
try { try {
db.execSQL("drop table " + Body.TABLE_NAME); db.execSQL("drop table " + Body.TABLE_NAME);
createBodyTable(db);
} catch (SQLException e) { } catch (SQLException e) {
} }
createBodyTable(db); } else if (oldVersion == 2) {
Log.d(TAG, "Upgrading Body from v2 to v3");
db.execSQL("alter table " + Body.TABLE_NAME +
" add " + Body.SOURCE_MESSAGE_KEY + " integer");
}
} }
private final int mDatabaseVersion = DATABASE_VERSION; private final int mDatabaseVersion = DATABASE_VERSION;

View File

@ -127,6 +127,7 @@ public class ProviderTestUtils extends Assert {
message.mHtml = "body html " + name; message.mHtml = "body html " + name;
message.mTextReply = "reply text " + name; message.mTextReply = "reply text " + name;
message.mHtmlReply = "reply html " + name; message.mHtmlReply = "reply html " + name;
message.mSourceKey = mailboxId;
} }
if (saveIt) { if (saveIt) {
@ -269,6 +270,7 @@ public class ProviderTestUtils extends Assert {
assertEquals(caller + " mHtml", expect.mHtml, actual.mHtml); assertEquals(caller + " mHtml", expect.mHtml, actual.mHtml);
assertEquals(caller + " mTextReply", expect.mTextReply, actual.mTextReply); assertEquals(caller + " mTextReply", expect.mTextReply, actual.mTextReply);
assertEquals(caller + " mHtmlReply", expect.mHtmlReply, actual.mHtmlReply); assertEquals(caller + " mHtmlReply", expect.mHtmlReply, actual.mHtmlReply);
assertEquals(caller + " mSourceKey", expect.mSourceKey, actual.mSourceKey);
} }
/** /**

View File

@ -203,6 +203,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
message2.mHtml = null; message2.mHtml = null;
message2.mTextReply = null; message2.mTextReply = null;
message2.mHtmlReply = null; message2.mHtmlReply = null;
message2.mSourceKey = 0;
Message message2get = EmailContent.Message.restoreMessageWithId(mMockContext, message2Id); Message message2get = EmailContent.Message.restoreMessageWithId(mMockContext, message2Id);
ProviderTestUtils.assertMessageEqual("testMessageSave", message2, message2get); ProviderTestUtils.assertMessageEqual("testMessageSave", message2, message2get);
@ -212,6 +213,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertEquals("body html", html2, body2.mHtmlContent); assertEquals("body html", html2, body2.mHtmlContent);
assertEquals("reply text", textReply2, body2.mTextReply); assertEquals("reply text", textReply2, body2.mTextReply);
assertEquals("reply html", htmlReply2, body2.mHtmlReply); assertEquals("reply html", htmlReply2, body2.mHtmlReply);
assertEquals("source key", message2.mMailboxKey, body2.mSourceKey);
// Message with attachments and body // Message with attachments and body
Message message3 = ProviderTestUtils.setupMessage("message3", account1Id, box1Id, true, Message message3 = ProviderTestUtils.setupMessage("message3", account1Id, box1Id, true,
@ -401,6 +403,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
values.put(BodyColumns.HTML_CONTENT, htmlContent); values.put(BodyColumns.HTML_CONTENT, htmlContent);
values.put(BodyColumns.TEXT_REPLY, textReply); values.put(BodyColumns.TEXT_REPLY, textReply);
values.put(BodyColumns.HTML_REPLY, htmlReply); values.put(BodyColumns.HTML_REPLY, htmlReply);
values.put(BodyColumns.SOURCE_MESSAGE_KEY, 17);
// 1 // 1
Message message1 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, false, Message message1 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, false,
@ -415,6 +418,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertEquals(body1.mHtmlContent, htmlContent); assertEquals(body1.mHtmlContent, htmlContent);
assertEquals(body1.mTextReply, textReply); assertEquals(body1.mTextReply, textReply);
assertEquals(body1.mHtmlReply, htmlReply); assertEquals(body1.mHtmlReply, htmlReply);
assertEquals(body1.mSourceKey, 17);
// 2 // 2
Message message2 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, true, Message message2 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, true,
@ -430,6 +434,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertEquals(body2.mHtmlContent, htmlContent); assertEquals(body2.mHtmlContent, htmlContent);
assertEquals(body2.mTextReply, textReply); assertEquals(body2.mTextReply, textReply);
assertEquals(body2.mHtmlReply, htmlReply); assertEquals(body2.mHtmlReply, htmlReply);
assertEquals(body2.mSourceKey, 17);
} }
/** /**