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 7557f96..5ef197f 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 */ - static final int DATABASE_VERSION = 3; + static final int DATABASE_VERSION = 4; static final String DATABASE_NAME = "database.db"; /* Users info table */ @@ -53,4 +53,16 @@ public final class DatabaseContract { public static final String COLUMN_NAME_CONVERSATION_MEMBERS = "members"; } + /* Conversations messages table */ + public static abstract class ConversationsMessagesSchema implements BaseColumns { + public static final String TABLE_NAME = "conversation_messages"; + + public static final String COLUMN_NAME_MESSAGE_ID = "message_id"; + public static final String COLUMN_NAME_CONVERSATION_ID = "conversation_id"; + public static final String COLUMN_NAME_USER_ID = "user_id"; + public static final String COLUMN_NAME_IMAGE_PATH = "image_path"; + public static final String COLUMN_NAME_MESSAGE = "message"; + public static final String COLUMN_NAME_TIME_INSERT = "time_insert"; + } + } 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 f788336..ca8d44b 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 @@ -7,6 +7,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; +import org.communiquons.android.comunic.client.data.DatabaseContract.ConversationsMessagesSchema; /** * Database helper. This file handles the creation / upgrade of the local database @@ -75,6 +76,24 @@ public class DatabaseHelper extends SQLiteOpenHelper { ConversationsListSchema.TABLE_NAME; + /** + * Creation and deletion of the conversation messages table + */ + private static final String SQL_CREATE_CONVERSATION_MESSAGES_TABLE = + "CREATE TABLE " + ConversationsMessagesSchema.TABLE_NAME + " (" + + ConversationsMessagesSchema._ID + " INTEGER PRIMARY KEY," + + ConversationsMessagesSchema.COLUMN_NAME_MESSAGE_ID + INTEGER_TYPE + COMMA_SEP + + ConversationsMessagesSchema.COLUMN_NAME_CONVERSATION_ID + INTEGER_TYPE + COMMA_SEP + + ConversationsMessagesSchema.COLUMN_NAME_USER_ID + INTEGER_TYPE + COMMA_SEP + + ConversationsMessagesSchema.COLUMN_NAME_IMAGE_PATH + TEXT_TYPE + COMMA_SEP + + ConversationsMessagesSchema.COLUMN_NAME_MESSAGE + TEXT_TYPE + COMMA_SEP + + ConversationsMessagesSchema.COLUMN_NAME_TIME_INSERT + INTEGER_TYPE + + " )"; + + private static final String SQL_DELETE_CONVERSATION_MESSAGES_TABLE = "DROP TABLE IF EXISTS " + + ConversationsMessagesSchema.TABLE_NAME; + + /** * Public constructor * @param context The context where the database is used @@ -98,6 +117,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { //Create conversations list table db.execSQL(SQL_CREATE_CONVERSATIONS_LIST_TABLE); + + //Create messages list table + db.execSQL(SQL_CREATE_CONVERSATION_MESSAGES_TABLE); } /** @@ -114,6 +136,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { //Delete conversations list table db.execSQL(SQL_DELETE_CONVERSATIONS_LIST_TABLE); + + //Delete conversations messages table + db.execSQL(SQL_DELETE_CONVERSATION_MESSAGES_TABLE); } /** diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/conversations/ConversationMessage.java b/app/src/main/java/org/communiquons/android/comunic/client/data/conversations/ConversationMessage.java new file mode 100644 index 0000000..bf720dd --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/conversations/ConversationMessage.java @@ -0,0 +1,137 @@ +package org.communiquons.android.comunic.client.data.conversations; + +import android.support.annotation.Nullable; + +import java.util.Objects; + +/** + * Conversation content object + * + * @author Pierre HUBERT + * Created by pierre on 12/16/17. + */ + +public class ConversationMessage { + + /** + * Message values + */ + private int id; + private int conversation_id; + private int user_id; + private String image_path = null; + private String content; + private int time_insert; + + /** + * Set the ID of a content + * + * @param id The id of the content + */ + public void setId(int id) { + this.id = id; + } + + /** + * Get the content ID + * + * @return The ID of the content + */ + public int getId() { + return id; + } + + /** + * Set the ID of the conversation attached to the content + * + * @param conversation_id The ID of the conversation + */ + public void setConversation_id(int conversation_id) { + this.conversation_id = conversation_id; + } + + /** + * Get the conversation ID attached to a content + * + * @return The ID of the conversation + */ + public int getConversation_id() { + return conversation_id; + } + + /** + * Set the ID of the user who posted the content + * + * @param user_id The ID of the user + */ + public void setUser_id(int user_id) { + this.user_id = user_id; + } + + /** + * Get the ID of the user who posted the content + * + * @return The ID of the user who posted the content + */ + public int getUser_id() { + return user_id; + } + + /** + * Set the path of the image associated to the content + * + * @param image_path The path of the image + */ + public void setImage_path(String image_path) { + if(image_path != null && !Objects.equals(image_path, "null")) + this.image_path = image_path; + else + this.image_path = null; + } + + /** + * Get the path of the image associated with the content + * + * @return The path of the image + */ + @Nullable + public String getImage_path() { + return image_path; + } + + /** + * Set the content of the message + * + * @param content The content of the content + */ + public void setContent(String content) { + this.content = content; + } + + /** + * Get the content of the message + * + * @return The content + */ + public String getContent() { + return content; + } + + /** + * Set the image of insertion of the message + * + * @param time_insert The time of insertion of the message + */ + public void setTime_insert(int time_insert) { + this.time_insert = time_insert; + } + + /** + * Get the time of insertion of the message + * + * @return The time of insertion of the message + */ + public int getTime_insert() { + return time_insert; + } +} diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index e14a9c9..6f1867a 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -31,14 +31,14 @@ android:layout_height="wrap_content" android:orientation="vertical"> - +