1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12:15 -05:00

Make it possible to instantiate a localFolder by id.

This commit is contained in:
Jesse Vincent 2009-12-27 16:53:16 +00:00
parent 4cec247699
commit 09ecd2bc9a

View File

@ -293,11 +293,11 @@ public class LocalStore extends Store implements Serializable
try try
{ {
cursor = mDb.rawQuery("SELECT name, id, unread_count, visible_limit, last_updated, status, push_state, last_pushed FROM folders", null); cursor = mDb.rawQuery("SELECT id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed FROM folders", null);
while (cursor.moveToNext()) while (cursor.moveToNext())
{ {
LocalFolder folder = new LocalFolder(cursor.getString(0)); LocalFolder folder = new LocalFolder(cursor.getString(1));
folder.open(cursor.getInt(1), cursor.getInt(2), cursor.getInt(3), cursor.getLong(4), cursor.getString(5), cursor.getString(6), cursor.getLong(7)); folder.open(cursor.getInt(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3), cursor.getLong(4), cursor.getString(5), cursor.getString(6), cursor.getLong(7));
folders.add(folder); folders.add(folder);
} }
@ -584,6 +584,11 @@ public class LocalStore extends Store implements Serializable
} }
public LocalFolder(long id)
{
this.mFolderId = id;
}
public long getId() public long getId()
{ {
return mFolderId; return mFolderId;
@ -599,19 +604,25 @@ public class LocalStore extends Store implements Serializable
Cursor cursor = null; Cursor cursor = null;
try try
{ {
cursor = mDb.rawQuery("SELECT id, unread_count, visible_limit, last_updated, status, push_state, last_pushed FROM folders " String baseQuery =
+ "where folders.name = ?", "SELECT id, name,unread_count, visible_limit, last_updated, status, push_state, last_pushed FROM folders ";
new String[] if (mName != null)
{ {
mName cursor = mDb.rawQuery(baseQuery + "where folders.name = ?", new String[] { mName });
}); }
else
{
cursor = mDb.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString(mFolderId) });
}
if (cursor.moveToFirst()) if (cursor.moveToFirst())
{ {
int folderId = cursor.getInt(0); int folderId = cursor.getInt(0);
if (folderId > 0) if (folderId > 0)
{ {
open(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2), cursor.getLong(3), cursor.getString(4), cursor.getString(5), cursor.getLong(6)); open(folderId, cursor.getString(1), cursor.getInt(2), cursor.getInt(3), cursor.getLong(4), cursor.getString(5), cursor.getString(6), cursor.getLong(7));
} }
} }
else else
@ -629,9 +640,10 @@ public class LocalStore extends Store implements Serializable
} }
} }
private void open(int id, int unreadCount, int visibleLimit, long lastChecked, String status, String pushState, long lastPushed) throws MessagingException private void open(int id, String name, int unreadCount, int visibleLimit, long lastChecked, String status, String pushState, long lastPushed) throws MessagingException
{ {
mFolderId = id; mFolderId = id;
mName = name;
mUnreadMessageCount = unreadCount; mUnreadMessageCount = unreadCount;
mVisibleLimit = visibleLimit; mVisibleLimit = visibleLimit;
mPushState = pushState; mPushState = pushState;