Display time of arrival for messages
This commit is contained in:
parent
bde8fdff1a
commit
3bc93a8583
4 changed files with 33 additions and 8 deletions
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
|
<string name="messages_date_format">HH:mm:ss d MMM</string>
|
||||||
|
|
||||||
<string name="app_name">Linphone 2</string>
|
<string name="app_name">Linphone 2</string>
|
||||||
<string name="notification_title">Linphone</string>
|
<string name="notification_title">Linphone</string>
|
||||||
<string name="wait_dialog_text">Starting up</string>
|
<string name="wait_dialog_text">Starting up</string>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<bool name="useFirstLoginActivity">true</bool>
|
<bool name="useFirstLoginActivity">true</bool>
|
||||||
<bool name="disable_animations">false</bool>
|
<bool name="disable_animations">false</bool>
|
||||||
<bool name="show_full_remote_address_on_incoming_call">true</bool>
|
<bool name="show_full_remote_address_on_incoming_call">true</bool>
|
||||||
|
<bool name="display_messages_time">true</bool> <!-- Used to show the time of each message arrival -->
|
||||||
|
|
||||||
<bool name="allow_transfers">true</bool>
|
<bool name="allow_transfers">true</bool>
|
||||||
<bool name="allow_edit_in_dialer">true</bool>
|
<bool name="allow_edit_in_dialer">true</bool>
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
||||||
|
|
||||||
previousMessageID = -1;
|
previousMessageID = -1;
|
||||||
for (ChatMessage msg : messagesList) {
|
for (ChatMessage msg : messagesList) {
|
||||||
displayMessage(msg.getId(), msg.getMessage(), msg.isIncoming(), messagesLayout);
|
displayMessage(msg.getId(), msg.getMessage(), msg.getTimestamp(), msg.isIncoming(), messagesLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
|
@ -89,11 +89,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMessage(final int id, final String message, final boolean isIncoming, final RelativeLayout layout) {
|
private void displayMessage(final int id, final String message, final String time, final boolean isIncoming, final RelativeLayout layout) {
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, isIncoming, previousMessageID);
|
BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, time, isIncoming, previousMessageID);
|
||||||
previousMessageID = id;
|
previousMessageID = id;
|
||||||
layout.addView(bubble.getView());
|
layout.addView(bubble.getView());
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHAT);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHAT);
|
||||||
LinphoneActivity.instance().updateChatFragment(this);
|
LinphoneActivity.instance().updateChatFragment(this);
|
||||||
}
|
}
|
||||||
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,7 +122,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
||||||
LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
|
LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayMessage(previousMessageID + 1, messageToSend, false, messagesLayout);
|
displayMessage(previousMessageID + 1, messageToSend, "", false, messagesLayout);
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +138,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(LinphoneAddress from, String message) {
|
public void onMessageReceived(LinphoneAddress from, String message) {
|
||||||
displayMessage(previousMessageID + 1, message, true, messagesLayout);
|
displayMessage(previousMessageID + 1, message, "", true, messagesLayout);
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -32,7 +35,7 @@ import android.widget.TextView;
|
||||||
public class BubbleChat {
|
public class BubbleChat {
|
||||||
private RelativeLayout view;
|
private RelativeLayout view;
|
||||||
|
|
||||||
public BubbleChat(Context context, int id, String message, boolean isIncoming, int previousID) {
|
public BubbleChat(Context context, int id, String message, String time, boolean isIncoming, int previousID) {
|
||||||
view = new RelativeLayout(context);
|
view = new RelativeLayout(context);
|
||||||
|
|
||||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
@ -50,7 +53,8 @@ public class BubbleChat {
|
||||||
layoutParams.addRule(RelativeLayout.BELOW, previousID);
|
layoutParams.addRule(RelativeLayout.BELOW, previousID);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView messageView = new TextView(context);
|
TextView messageView = new TextView(context);
|
||||||
|
messageView.setId(id);
|
||||||
messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||||
messageView.setText(message);
|
messageView.setText(message);
|
||||||
messageView.setTextColor(Color.BLACK);
|
messageView.setTextColor(Color.BLACK);
|
||||||
|
@ -58,9 +62,27 @@ public class BubbleChat {
|
||||||
view.setId(id);
|
view.setId(id);
|
||||||
view.setLayoutParams(layoutParams);
|
view.setLayoutParams(layoutParams);
|
||||||
view.addView(messageView);
|
view.addView(messageView);
|
||||||
|
|
||||||
|
if (context.getResources().getBoolean(R.bool.display_messages_time)) {
|
||||||
|
TextView timeView = new TextView(context);
|
||||||
|
LayoutParams timeParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
timeParams.addRule(RelativeLayout.BELOW, id);
|
||||||
|
timeView.setLayoutParams(timeParams);
|
||||||
|
timeView.setText(timestampToHumanDate(context, time));
|
||||||
|
timeView.setTextColor(Color.GRAY);
|
||||||
|
timeView.setTextSize(12);
|
||||||
|
view.addView(timeView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView() {
|
public View getView() {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String timestampToHumanDate(Context context, String timestamp) {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat(context.getResources().getString(R.string.messages_date_format));
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTimeInMillis(Long.parseLong(timestamp));
|
||||||
|
return dateFormat.format(cal.getTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue