Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'co.dift.ui.swipetoaction:library:1.1'
implementation 'com.android.support:appcompat-v7:24.2.1'
implementation 'com.android.support:design:24.2.1'
implementation 'com.android.support:support-v4:24.2.1'
implementation 'com.android.support:recyclerview-v7:24.2.1'
testImplementation 'junit:junit:4.12'
implementation 'co.dift.ui.swipetoaction:library:1.1'
}
25 changes: 24 additions & 1 deletion app/src/main/java/com/zv/geochat/model/ChatMessage.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.zv.geochat.model;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class ChatMessage {
private String id;
private String userName;
private String body;
private String date;

public ChatMessage() {
}
Expand All @@ -13,10 +18,12 @@ public ChatMessage(String userName, String body) {
this.body = body;
}

public ChatMessage(String id, String userName, String body) {
public ChatMessage(String id, String userName, String body, String date) { //Assignment 2 - Date defining
this.id = id;
this.userName = userName;
this.body = body;
this.date = date; //Assignment 2 - Date defining
//adding date here might not be necessary
}


Expand All @@ -32,6 +39,21 @@ public String getId() {
return id;
}

//create a getter and setter function for date - Assignment 2
////
public String getDate()
{
DateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Calendar calendar = Calendar.getInstance();
date = simpleDateFormat.format(calendar.getTime());
return date;
}

public String getChatDate() { return date; } //Using to send the exact date of chat from DB

public void setDate(String date) { this.date = date; }
////

public void setId(String id) {
this.id = id;
}
Expand All @@ -50,6 +72,7 @@ public String toString() {
"id='" + id + '\'' +
", userName='" + userName + '\'' +
", body='" + body + '\'' +
", date='" + date + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ private List<ChatMessage> getChatMessageList(Cursor c) {
int indexId = c.getColumnIndex(ChatMessageTableMetaData._ID);
int indexUserName = c.getColumnIndex(ChatMessageTableMetaData.USER_NAME);
int indexMsgBody = c.getColumnIndex(ChatMessageTableMetaData.MSG_BODY);
int indexMsgDate = c.getColumnIndex(ChatMessageTableMetaData.CHAT_MESSAGE_DATE);

//walk through the rows based on indexes
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setId(c.getString(indexId));
chatMessage.setUserName(c.getString(indexUserName));
chatMessage.setBody(c.getString(indexMsgBody));
chatMessage.setDate(c.getString(indexMsgDate));

list.add(chatMessage);

Expand All @@ -97,6 +99,7 @@ public void update(ChatMessage chatMessage) {
ContentValues cv = new ContentValues();
cv.put(ChatMessageTableMetaData.USER_NAME, chatMessage.getUserName());
cv.put(ChatMessageTableMetaData.MSG_BODY, chatMessage.getBody());
cv.put(ChatMessageTableMetaData.CHAT_MESSAGE_DATE, chatMessage.getDate());

Uri uri = ChatMessageTableMetaData.CONTENT_URI;
Log.v(TAG, "{db} insert uri: " + uri);
Expand All @@ -116,6 +119,7 @@ public void insert(ChatMessage chatMessage) {
ContentValues cv = new ContentValues();
cv.put(GeoChatProviderMetadata.ChatMessageTableMetaData.USER_NAME, chatMessage.getUserName());
cv.put(GeoChatProviderMetadata.ChatMessageTableMetaData.MSG_BODY, chatMessage.getBody());
cv.put(ChatMessageTableMetaData.CHAT_MESSAGE_DATE, chatMessage.getDate()); //Inserting date to the Table - getDate() is current date time defined in ChatMessage file

Uri uri = GeoChatProviderMetadata.ChatMessageTableMetaData.CONTENT_URI;
Log.v(TAG, "{db} insert uri: " + uri);
Expand All @@ -133,4 +137,4 @@ public void deleteById(String id) {
Log.v(TAG, "{db} WHERE: " + where);
contentResolver.delete(uri, where, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ private void createTables(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS " + ChatMessageTableMetaData.TABLE_NAME + " ("
+ ChatMessageTableMetaData._ID + " INTEGER PRIMARY KEY,"
+ ChatMessageTableMetaData.USER_NAME + " TEXT,"
+ ChatMessageTableMetaData.MSG_BODY + " TEXT"
+ ChatMessageTableMetaData.MSG_BODY + " TEXT,"
+ ChatMessageTableMetaData.CHAT_MESSAGE_DATE + " INTEGER" //Assignment 2 - Date creating as Text/String
+ ");");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class GeoChatProvider extends ContentProvider {
sGroupsProjectionMap.put(ChatMessageTableMetaData._ID, ChatMessageTableMetaData._ID);
sGroupsProjectionMap.put(ChatMessageTableMetaData.USER_NAME, ChatMessageTableMetaData.USER_NAME);
sGroupsProjectionMap.put(ChatMessageTableMetaData.MSG_BODY, ChatMessageTableMetaData.MSG_BODY);
sGroupsProjectionMap.put(ChatMessageTableMetaData.CHAT_MESSAGE_DATE, ChatMessageTableMetaData.CHAT_MESSAGE_DATE); //Assignment 2 date
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class GeoChatProviderMetadata {

public static final String AUTHORITY = "com.zv.geochat.provider.GeoChatProvider";
public static final String DATABASE_NAME = "geochat.db";
public static final int DATABASE_VERSION = 1;
public static final int DATABASE_VERSION = 4;

private GeoChatProviderMetadata() {
}
Expand All @@ -27,5 +27,8 @@ private ChatMessageTableMetaData() {
// string type
public static final String USER_NAME = "user_name";
public static final String MSG_BODY = "msg_body";
// Assignment 2 additional columns
public static final String CHAT_MESSAGE_DATE = "msg_date";

}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/zv/geochat/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ChatService extends Service {
public static final int CMD_LEAVE_CHAT = 20;
public static final int CMD_SEND_MESSAGE = 30;
public static final int CMD_RECEIVE_MESSAGE = 40;
public static final int CMD_CONNECT_ERROR_00 = 00; //Assignment 1 error code
public static final int CMD_SEND_RANDOM_ID = 50; //Assignment 1 Random ID
public static final String KEY_MESSAGE_TEXT = "message_text";
public static final String KEY_USER_NAME = "user_name";

Expand Down Expand Up @@ -110,6 +112,13 @@ private void handleData(Bundle data) {
String testMessage = "Simulated Message";
notificationDecorator.displaySimpleNotification("New message...: "+ testUser, testMessage);
chatMessageStore.insert(new ChatMessage(testUser, testMessage));
} else if (command == CMD_CONNECT_ERROR_00) { //Assignment 1 error code
String errorCode = "00";
String testMessage = "Simulated Message";
notificationDecorator.displaySimpleNotification("Connect Error:"+ errorCode, testMessage);
} else if (command == CMD_SEND_RANDOM_ID) { //Assignment 1 Random ID
String messageText = (String) data.get(KEY_MESSAGE_TEXT);
notificationDecorator.displaySimpleNotification("ChatService Recieved:", messageText);
} else {
Log.w(TAG, "Ignoring Unknown Command! id=" + command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ public class ChatMessageViewHolder extends SwipeToAction.ViewHolder<ChatMessage>
public TextView userName;
public TextView chatMessageBody;
public ImageView imageView;
//Declaring Message ID and Message Date for Assignment 2
public TextView messageID;
public TextView messageDate;

public ChatMessageViewHolder(View v) {
super(v);

userName = (TextView) v.findViewById(R.id.userName);
chatMessageBody = (TextView) v.findViewById(R.id.body);
imageView = (ImageView) v.findViewById(R.id.image);
//create to map the text view for date field and id here - Assignment 2
messageID = (TextView) v.findViewById(R.id.msgID);
messageDate = (TextView) v.findViewById(R.id.msgDate);
}
}

Expand Down Expand Up @@ -65,5 +71,8 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
vh.userName.setText(item.getUserName());
vh.chatMessageBody.setText(item.getBody());
vh.data = item;
//doing the same for id and date - Assignment 2
vh.messageID.setText(" Message ID: " + item.getId());
vh.messageDate.setText(" " + item.getChatDate());
}
}
Loading