diff --git a/.idea/misc.xml b/.idea/misc.xml
index 33952c6..503aca7 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -55,7 +55,7 @@
-
+
diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseContract.java b/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseContract.java
index fd8b6d7..7557f96 100644
--- a/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseContract.java
+++ b/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseContract.java
@@ -15,8 +15,8 @@ public final class DatabaseContract {
public DatabaseContract(){}
/* Database basic information */
- public static final int DATABASE_VERSION = 2;
- public static final String DATABASE_NAME = "database.db";
+ static final int DATABASE_VERSION = 3;
+ static final String DATABASE_NAME = "database.db";
/* Users info table */
public static abstract class UsersInfoSchema implements BaseColumns {
@@ -40,4 +40,17 @@ public final class DatabaseContract {
}
+ /* Conversations list table */
+ public static abstract class ConversationsListSchema implements BaseColumns {
+ public static final String TABLE_NAME = "conversations_list";
+
+ public static final String COLUMN_NAME_CONVERSATION_ID = "conversation_id";
+ public static final String COLUMN_NAME_CONVERSATION_ID_OWNER = "id_owner";
+ public static final String COLUMN_NAME_CONVERSATION_LAST_ACTIVE = "last_active";
+ public static final String COLUMN_NAME_CONVERSATION_NAME = "name";
+ public static final String COLUMN_NAME_CONVERSATION_FOLLOWING = "following";
+ public static final String COLUMN_NAME_CONVERSATION_SAW_LAST_MESSAGES = "saw_last_message";
+ public static final String COLUMN_NAME_CONVERSATION_MEMBERS = "members";
+ }
+
}
diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseHelper.java
index d20c4ee..df62ba0 100644
--- a/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseHelper.java
+++ b/app/src/main/java/org/communiquons/android/comunic/client/data/DatabaseHelper.java
@@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import org.communiquons.android.comunic.client.data.DatabaseContract.FriendsListSchema;
import org.communiquons.android.comunic.client.data.DatabaseContract.UsersInfoSchema;
+import org.communiquons.android.comunic.client.data.DatabaseContract.ConversationsListSchema;
/**
* Database helper. This file handles the creation / upgrade of the local database
@@ -54,6 +55,26 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private static final String SQL_DELETE_FRIENDS_LIST_TABLE = "DROP TABLE IF EXISTS " +
FriendsListSchema.TABLE_NAME;
+
+ /**
+ * Creation and deletion of the conversations list table
+ */
+ private static final String SQL_CREATE_CONVERSATIONS_LIST_TABLE =
+ "CREATE TABLE " + ConversationsListSchema.TABLE_NAME + " (" +
+ ConversationsListSchema._ID + " INTEGER PRIMARY KEY," +
+ ConversationsListSchema.COLUMN_NAME_CONVERSATION_ID + INTEGER_TYPE + COMMA_SEP +
+ ConversationsListSchema.COLUMN_NAME_CONVERSATION_ID_OWNER + INTEGER_TYPE + COMMA_SEP +
+ ConversationsListSchema.COLUMN_NAME_CONVERSATION_LAST_ACTIVE + INTEGER_TYPE + COMMA_SEP +
+ ConversationsListSchema.COLUMN_NAME_CONVERSATION_NAME + TEXT_TYPE + COMMA_SEP +
+ ConversationsListSchema.COLUMN_NAME_CONVERSATION_FOLLOWING + INTEGER_TYPE + COMMA_SEP +
+ ConversationsListSchema.COLUMN_NAME_CONVERSATION_SAW_LAST_MESSAGES + INTEGER_TYPE + COMMA_SEP +
+ ConversationsListSchema.COLUMN_NAME_CONVERSATION_MEMBERS + TEXT_TYPE + COMMA_SEP +
+ " )";
+
+ private static final String SQL_DELETE_CONVERSATIONS_LIST_TABLE = "DROP TABLE IF EXISTS " +
+ ConversationsListSchema.TABLE_NAME;
+
+
/**
* Public constructor
* @param context The context where the database is used
@@ -63,27 +84,54 @@ public class DatabaseHelper extends SQLiteOpenHelper {
}
/**
- * Handles database creation
- * @param db The database
+ * Initialize the database
+ *
+ * @param db Database object
*/
- @Override
- public void onCreate(SQLiteDatabase db) {
+ public void init_db(SQLiteDatabase db){
+
//Create user informations table
db.execSQL(SQL_CREATE_USERS_INFOS_TABLE);
//Create friends list table
db.execSQL(SQL_CREATE_FRIENDS_LIST_TABLE);
+
+ //Create conversations list table
+ db.execSQL(SQL_CREATE_CONVERSATIONS_LIST_TABLE);
}
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ /**
+ * Clear the whole content of the database
+ *
+ * @param db The database
+ */
+ public void clear_db(SQLiteDatabase db){
//Delete users informations table
db.execSQL(SQL_DELETE_USERS_INFOS_TABLE);
//Delete friends list table
db.execSQL(SQL_DELETE_FRIENDS_LIST_TABLE);
- //Perform creation table
+ //Delete conversations list table
+ db.execSQL(SQL_DELETE_CONVERSATIONS_LIST_TABLE);
+ }
+
+ /**
+ * Handles database creation
+ * @param db The database
+ */
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ init_db(db);
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+
+ //Clear the database
+ clear_db(db);
+
+ //Perform tables creation
onCreate(db);
}