Skip to content

Instantly share code, notes, and snippets.

@wirasetiawan29
Created May 19, 2016 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wirasetiawan29/66dcbd794dfaddce575ae1155f7c6894 to your computer and use it in GitHub Desktop.
Save wirasetiawan29/66dcbd794dfaddce575ae1155f7c6894 to your computer and use it in GitHub Desktop.
public class ChatModel {
private String name;
private String message;
private long userId;
private long timestamp;
private String formattedTime;
public ChatModel() {
name = "";
message = "";
userId = 32;
timestamp = 0;
}
public ChatModel(String message, String name, long uid, long time, String formattedTime) {
this.name = name;
this.message = message;
this.userId = uid;
this.timestamp = time;
this.formattedTime = formattedTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public void setTime(long time) {
this.timestamp = time;
long oneDayInMillis = 24 * 60 * 60 * 1000;
long timeDifference = System.currentTimeMillis() - time;
if(timeDifference < oneDayInMillis){
formattedTime = DateFormat.format("hh:mm a", time).toString();
}else{
formattedTime = DateFormat.format("dd MMM - hh:mm a", time).toString();
}
}
public void setFormattedTime(String formattedTime) {
this.formattedTime = formattedTime;
}
public String getFormattedTime(){
long oneDayInMillis = 24 * 60 * 60 * 1000;
long timeDifference = System.currentTimeMillis() - timestamp;
if(timeDifference < oneDayInMillis){
return DateFormat.format("hh:mm a", timestamp).toString();
}else{
return DateFormat.format("dd MMM - hh:mm a", timestamp).toString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment