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

* Set reply/forward flag and sourceKey as appropriate in MessageCompose
* Update provider tests accordingly

Change-Id: I7f49d80a735314a1a38f09fbf1f234257c41af8c
This commit is contained in:
Marc Blank 2009-09-07 16:03:02 -07:00
parent 4587efc1d3
commit e256983193
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.FLAG_LOADED, message.mFlagLoaded);
values.put(MessageColumns.FLAG_ATTACHMENT, message.mFlagAttachment);
values.put(MessageColumns.FLAGS, message.mFlags);
return values;
}
@ -668,6 +669,16 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
message.mDisplayName = makeDisplayName(message.mTo, message.mCc, message.mBcc);
message.mFlagLoaded = Message.LOADED;
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() {

View File

@ -185,6 +185,8 @@ public abstract class EmailContent {
public static final String HTML_REPLY = "htmlReply";
// Replied-to or forwarded body (in text form)
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 {
@ -198,9 +200,10 @@ public abstract class EmailContent {
public static final int CONTENT_TEXT_CONTENT_COLUMN = 3;
public static final int CONTENT_HTML_REPLY_COLUMN = 4;
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[] {
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;
@ -220,6 +223,7 @@ public abstract class EmailContent {
public String mTextContent;
public String mHtmlReply;
public String mTextReply;
public long mSourceKey;
public Body() {
mBaseUri = CONTENT_URI;
@ -235,6 +239,7 @@ public abstract class EmailContent {
values.put(BodyColumns.TEXT_CONTENT, mTextContent);
values.put(BodyColumns.HTML_REPLY, mHtmlReply);
values.put(BodyColumns.TEXT_REPLY, mTextReply);
values.put(BodyColumns.SOURCE_MESSAGE_KEY, mSourceKey);
return values;
}
@ -330,6 +335,7 @@ public abstract class EmailContent {
mTextContent = c.getString(CONTENT_TEXT_CONTENT_COLUMN);
mHtmlReply = c.getString(CONTENT_HTML_REPLY_COLUMN);
mTextReply = c.getString(CONTENT_TEXT_REPLY_COLUMN);
mSourceKey = c.getLong(CONTENT_SOURCE_KEY_COLUMN);
return this;
}
@ -484,22 +490,33 @@ public abstract class EmailContent {
public String mBcc;
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 mHtml;
transient public String mTextReply;
transient public String mHtmlReply;
// Can be used while building messages, but is NOT saved by the Provider
transient public long mSourceKey;
transient public ArrayList<Attachment> mAttachments = null;
// Values used in mFlagRead
public static final int UNREAD = 0;
public static final int READ = 1;
public static final int DELETED = 2;
// Values used in mFlagLoaded
public static final int NOT_LOADED = 0;
public static final int LOADED = 1;
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() {
mBaseUri = CONTENT_URI;
}
@ -665,6 +682,9 @@ public abstract class EmailContent {
if (mHtmlReply != null) {
cv.put(Body.HTML_REPLY, mHtmlReply);
}
if (mSourceKey != 0) {
cv.put(Body.SOURCE_MESSAGE_KEY, mSourceKey);
}
b = ContentProviderOperation.newInsert(Body.CONTENT_URI);
b.withValues(cv);
ContentValues backValues = new ContentValues();

View File

@ -56,9 +56,13 @@ public class EmailProvider extends ContentProvider {
static final String BODY_DATABASE_NAME = "EmailProviderBody.db";
// 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 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";
@ -480,18 +484,26 @@ public class EmailProvider extends ContentProvider {
+ BodyColumns.HTML_CONTENT + " text, "
+ BodyColumns.TEXT_CONTENT + " 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(createIndex(Body.TABLE_NAME, BodyColumns.MESSAGE_KEY));
}
static void upgradeBodyTable(SQLiteDatabase db, int oldVersion, int newVersion) {
try {
db.execSQL("drop table " + Body.TABLE_NAME);
} catch (SQLException e) {
}
createBodyTable(db);
if (oldVersion < 2) {
// Versions earlier than 2 require a wipe of the database
try {
db.execSQL("drop table " + Body.TABLE_NAME);
createBodyTable(db);
} catch (SQLException e) {
}
} 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;

View File

@ -127,6 +127,7 @@ public class ProviderTestUtils extends Assert {
message.mHtml = "body html " + name;
message.mTextReply = "reply text " + name;
message.mHtmlReply = "reply html " + name;
message.mSourceKey = mailboxId;
}
if (saveIt) {
@ -269,6 +270,7 @@ public class ProviderTestUtils extends Assert {
assertEquals(caller + " mHtml", expect.mHtml, actual.mHtml);
assertEquals(caller + " mTextReply", expect.mTextReply, actual.mTextReply);
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.mTextReply = null;
message2.mHtmlReply = null;
message2.mSourceKey = 0;
Message message2get = EmailContent.Message.restoreMessageWithId(mMockContext, message2Id);
ProviderTestUtils.assertMessageEqual("testMessageSave", message2, message2get);
@ -212,6 +213,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertEquals("body html", html2, body2.mHtmlContent);
assertEquals("reply text", textReply2, body2.mTextReply);
assertEquals("reply html", htmlReply2, body2.mHtmlReply);
assertEquals("source key", message2.mMailboxKey, body2.mSourceKey);
// Message with attachments and body
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.TEXT_REPLY, textReply);
values.put(BodyColumns.HTML_REPLY, htmlReply);
values.put(BodyColumns.SOURCE_MESSAGE_KEY, 17);
// 1
Message message1 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, false,
@ -415,6 +418,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertEquals(body1.mHtmlContent, htmlContent);
assertEquals(body1.mTextReply, textReply);
assertEquals(body1.mHtmlReply, htmlReply);
assertEquals(body1.mSourceKey, 17);
// 2
Message message2 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, true,
@ -430,6 +434,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertEquals(body2.mHtmlContent, htmlContent);
assertEquals(body2.mTextReply, textReply);
assertEquals(body2.mHtmlReply, htmlReply);
assertEquals(body2.mSourceKey, 17);
}
/**