I am just plugging and playing with a sample code to get a hang of chatting/messaging apps. I am using a function gettimedate such that, in my model class I have the following:
private volatile long mTimedate;
public myclass(....,DateType date,...){
mTimedate = date != null ? date.time : new Date().getTime();
}
public final long getTimedate() {
return mTimedate;
}
public int hashCode() {
if (mId != null) {
return mId.hashCode();
}
int hash = mBody == null ? 0 : mBody.hashCode();
return 31 * hash + (new Long(mTimedate)).hashCode();
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof myclass)) {
return false;
}
myclass other = (myclass) obj;
return mId != null ? mId.equals(other.mId) : other.mId == null
&& (mBody == null ? other.mBody == null : mBody.equals(other.mBody))
&& mTimedate == other.mdate;
}
Now, I wonder, how do I use this time date function, such that I can extract "Month -date, year " for top of my view and for the bottom part "time in 12 hr format" from the same function gettimedate().
Here's my adapter where I am using this function for display:
holder.txtInfo.setText(String.valueOf(new Date(msg.getTimedate())));
which returns the whole package as say "Mon Oct 19 ,13:03:03 EDT 2015" but I only need to use it in pieces for different views. Any clue how I can go about it to use it in 2 different places?
P.S: For a rough working code sample , here's a sample code: http://www.codeproject.com/Tips/897826/Designing-Android-Chat-Bubble-Chat-UI
Also , i would like to modify this test code to see if I can show the date on top for the day of the conversation only once and the just the 12hr time format for each and every conversation ,example( 4:35pm) , just like in any standard chat. Is there anyway to do that with the above code?
Thanks!