Skip to content

Commit 7189239

Browse files
committed
Updated a structure of the local database.
1 parent 22a63f7 commit 7189239

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptSQLiteOpenHelper.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,25 @@ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVers
8181
}
8282

8383
private void upgradeDatabaseFrom1To2Version(SQLiteDatabase sqLiteDatabase) {
84-
sqLiteDatabase.execSQL(AttachmentDaoSource.ATTACHMENT_TABLE_SQL_CREATE);
85-
sqLiteDatabase.execSQL(AttachmentDaoSource.CREATE_INDEX_EMAIL_UID_FOLDER_IN_MESSAGES);
86-
87-
sqLiteDatabase.execSQL("ALTER TABLE " + MessageDaoSource.TABLE_NAME_MESSAGES +
88-
" ADD COLUMN " + MessageDaoSource.COL_IS_MESSAGE_HAS_ATTACHMENTS
89-
+ " INTEGER DEFAULT 0;");
84+
sqLiteDatabase.beginTransaction();
85+
try {
86+
sqLiteDatabase.execSQL(AttachmentDaoSource.ATTACHMENT_TABLE_SQL_CREATE);
87+
sqLiteDatabase.execSQL(AttachmentDaoSource.CREATE_INDEX_EMAIL_UID_FOLDER_IN_MESSAGES);
88+
89+
sqLiteDatabase.execSQL("ALTER TABLE " + MessageDaoSource.TABLE_NAME_MESSAGES +
90+
" ADD COLUMN " + MessageDaoSource.COL_IS_MESSAGE_HAS_ATTACHMENTS
91+
+ " INTEGER DEFAULT 0;");
92+
93+
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
94+
" ADD COLUMN " + AccountDaoSource.COL_IS_ENABLE
95+
+ " INTEGER DEFAULT 1;");
96+
97+
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
98+
" ADD COLUMN " + AccountDaoSource.COL_IS_ACTIVE
99+
+ " INTEGER DEFAULT 0;");
100+
sqLiteDatabase.setTransactionSuccessful();
101+
} finally {
102+
sqLiteDatabase.endTransaction();
103+
}
90104
}
91105
}

FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/source/AccountDaoSource.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class AccountDaoSource extends BaseDaoSource {
3636
public static final String COL_GIVEN_NAME = "given_name";
3737
public static final String COL_FAMILY_NAME = "family_name";
3838
public static final String COL_PHOTO_URL = "photo_url";
39+
public static final String COL_IS_ENABLE = "is_enable";
40+
public static final String COL_IS_ACTIVE = "is_active";
3941

4042
public static final String ACCOUNTS_TABLE_SQL_CREATE = "CREATE TABLE IF NOT EXISTS " +
4143
TABLE_NAME_ACCOUNTS + " (" +
@@ -45,7 +47,9 @@ public class AccountDaoSource extends BaseDaoSource {
4547
COL_DISPLAY_NAME + " VARCHAR(100) DEFAULT NULL, " +
4648
COL_GIVEN_NAME + " VARCHAR(100) DEFAULT NULL, " +
4749
COL_FAMILY_NAME + " VARCHAR(100) DEFAULT NULL, " +
48-
COL_PHOTO_URL + " TEXT DEFAULT NULL " + ");";
50+
COL_PHOTO_URL + " TEXT DEFAULT NULL, " +
51+
COL_IS_ENABLE + " INTEGER DEFAULT 1, " +
52+
COL_IS_ACTIVE + " INTEGER DEFAULT 0 " + ");";
4953

5054
public static final String CREATE_INDEX_EMAIL_TYPE_IN_ACCOUNTS =
5155
"CREATE UNIQUE INDEX IF NOT EXISTS " + COL_EMAIL + "_" + COL_ACCOUNT_TYPE +
@@ -91,6 +95,28 @@ public Uri addRow(Context context, GoogleSignInAccount googleSignInAccount) {
9195
} else return null;
9296
}
9397

98+
/**
99+
* Get an active {@link AccountDao} object from the local database.
100+
*
101+
* @param context Interface to global information about an application environment.
102+
* @return The {@link AccountDao};
103+
*/
104+
public AccountDao getActiveAccountInformation(Context context) {
105+
Cursor cursor = context.getContentResolver().query(
106+
getBaseContentUri(), null, AccountDaoSource.COL_IS_ACTIVE +
107+
" = ?", new String[]{"1"}, null);
108+
109+
if (cursor != null && cursor.moveToFirst()) {
110+
return getCurrentAccountDao(cursor);
111+
}
112+
113+
if (cursor != null) {
114+
cursor.close();
115+
}
116+
117+
return null;
118+
}
119+
94120
/**
95121
* Get a {@link AccountDao} object from the local database.
96122
*
@@ -104,8 +130,8 @@ public AccountDao getAccountInformation(Context context, String email) {
104130
}
105131

106132
Cursor cursor = context.getContentResolver().query(
107-
getBaseContentUri(), null, ContactsDaoSource.COL_EMAIL +
108-
" = ?", new String[]{email}, null);
133+
getBaseContentUri(), null, AccountDaoSource.COL_EMAIL + " = ?",
134+
new String[]{email}, null);
109135

110136
if (cursor != null && cursor.moveToFirst()) {
111137
return getCurrentAccountDao(cursor);
@@ -215,6 +241,7 @@ private ContentValues generateContentValues(GoogleSignInAccount googleSignInAcco
215241
contentValues.put(COL_DISPLAY_NAME, googleSignInAccount.getDisplayName());
216242
contentValues.put(COL_GIVEN_NAME, googleSignInAccount.getGivenName());
217243
contentValues.put(COL_FAMILY_NAME, googleSignInAccount.getFamilyName());
244+
contentValues.put(COL_IS_ACTIVE, true);
218245
if (googleSignInAccount.getPhotoUrl() != null) {
219246
contentValues.put(COL_PHOTO_URL, googleSignInAccount.getPhotoUrl().toString());
220247
}

0 commit comments

Comments
 (0)