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 e4090ca..fd8b6d7 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,7 +15,7 @@ public final class DatabaseContract { public DatabaseContract(){} /* Database basic information */ - public static final int DATABASE_VERSION = 1; + public static final int DATABASE_VERSION = 2; public static final String DATABASE_NAME = "database.db"; /* Users info table */ @@ -29,4 +29,15 @@ public final class DatabaseContract { } + /* Friends list table */ + public static abstract class FriendsListSchema implements BaseColumns { + public static final String TABLE_NAME = "friends_list"; + + public static final String COLUMN_NAME_FRIEND_ID = "friend_id"; + public static final String COLUMN_NAME_FRIEND_ACCEPTED = "accepted"; + public static final String COLUMN_NAME_FRIEND_FOLLOWING = "following"; + public static final String COLUMN_NAME_FRIEND_LAST_ACTIVITY = "last_activity"; + + } + } 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 4f8b365..d20c4ee 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 @@ -4,6 +4,7 @@ import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import org.communiquons.android.comunic.client.data.DatabaseContract.FriendsListSchema; import org.communiquons.android.comunic.client.data.DatabaseContract.UsersInfoSchema; /** @@ -38,8 +39,20 @@ public class DatabaseHelper extends SQLiteOpenHelper { UsersInfoSchema.TABLE_NAME; + /** + * Creation and deletion of the friends table + */ + private static final String SQL_CREATE_FRIENDS_LIST_TABLE = + "CREATE TABLE " + FriendsListSchema.TABLE_NAME + " (" + + FriendsListSchema._ID + " INTEGER PRIMARY KEY," + + FriendsListSchema.COLUMN_NAME_FRIEND_ID + INTEGER_TYPE + COMMA_SEP + + FriendsListSchema.COLUMN_NAME_FRIEND_ACCEPTED + INTEGER_TYPE + COMMA_SEP + + FriendsListSchema.COLUMN_NAME_FRIEND_FOLLOWING + INTEGER_TYPE + COMMA_SEP + + FriendsListSchema.COLUMN_NAME_FRIEND_LAST_ACTIVITY + INTEGER_TYPE + + " )"; - + private static final String SQL_DELETE_FRIENDS_LIST_TABLE = "DROP TABLE IF EXISTS " + + FriendsListSchema.TABLE_NAME; /** * Public constructor @@ -57,12 +70,20 @@ public class DatabaseHelper extends SQLiteOpenHelper { public void onCreate(SQLiteDatabase db) { //Create user informations table db.execSQL(SQL_CREATE_USERS_INFOS_TABLE); + + //Create friends list table + db.execSQL(SQL_CREATE_FRIENDS_LIST_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { //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 onCreate(db); }