Fixed & improved linphone's core's timestamps use

This commit is contained in:
Sylvain Berfini 2017-10-31 11:17:35 +01:00
parent 76f31d0744
commit 76cd0f9b42
4 changed files with 10 additions and 24 deletions

View file

@ -164,10 +164,14 @@ public final class LinphoneUtils {
return true;
}
public static String timestampToHumanDate(Context context, long timestamp, int resFormat) {
return LinphoneUtils.timestampToHumanDate(context, timestamp, context.getString(resFormat));
}
public static String timestampToHumanDate(Context context, long timestamp, String format) {
try {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp);
cal.setTimeInMillis(timestamp * 1000); // Core returns timestamps in seconds...
SimpleDateFormat dateFormat;
if (isToday(cal)) {

View file

@ -236,7 +236,7 @@ public class ChatEventsAdapter extends BaseAdapter {
holder.fileTransferAction.setBackgroundResource(R.drawable.resizable_assistant_button);
holder.contactPictureMask.setImageResource(R.drawable.avatar_chat_mask);
}
holder.contactName.setText(timestampToHumanDate(mContext, message.getTime()) + " - " + displayName);
holder.contactName.setText(LinphoneUtils.timestampToHumanDate(mContext, message.getTime(), R.string.messages_date_format) + " - " + displayName);
Spanned text = null;
String msg = message.getText();
@ -252,30 +252,12 @@ public class ChatEventsAdapter extends BaseAdapter {
holder.eventLayout.setVisibility(View.VISIBLE);
holder.eventMessage.setText(""); //TODO
holder.eventTime.setText(timestampToHumanDate(mContext, event.getTime()));
holder.eventTime.setText(LinphoneUtils.timestampToHumanDate(mContext, event.getTime(), R.string.messages_date_format));
}
return view;
}
private String timestampToHumanDate(Context context, long timestamp) {
try {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp);
SimpleDateFormat dateFormat;
if (isToday(cal)) {
dateFormat = new SimpleDateFormat(context.getResources().getString(R.string.today_date_format));
} else {
dateFormat = new SimpleDateFormat(context.getResources().getString(R.string.messages_date_format));
}
return dateFormat.format(cal.getTime());
} catch (NumberFormatException nfe) {
return String.valueOf(timestamp);
}
}
private boolean isToday(Calendar cal) {
return isSameDay(cal, Calendar.getInstance());
}

View file

@ -436,13 +436,13 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
if (msg.getFileTransferInformation() != null || msg.getExternalBodyUrl() != null || msg.getAppdata() != null) {
holder.lastMessageView.setBackgroundResource(R.drawable.chat_file_message);
time = msg.getTime();
holder.date.setText(LinphoneUtils.timestampToHumanDate(getActivity(),time,getString(R.string.messages_list_date_format)));
holder.date.setText(LinphoneUtils.timestampToHumanDate(getActivity(), time, R.string.messages_list_date_format));
holder.lastMessageView.setText("");
} else if (msg.getText() != null && msg.getText().length() > 0 ){
message = msg.getText();
holder.lastMessageView.setBackgroundResource(0);
time = msg.getTime();
holder.date.setText(LinphoneUtils.timestampToHumanDate(getActivity(),time,getString(R.string.messages_list_date_format)));
holder.date.setText(LinphoneUtils.timestampToHumanDate(getActivity(), time, R.string.messages_list_date_format));
holder.lastMessageView.setText(message);
}
}

View file

@ -139,7 +139,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
@Override
public void onClick(View view) {
if (mChatRoom == null) return;
ArrayList<ContactAddress> participants = new ArrayList<ContactAddress>();
ArrayList<ContactAddress> participants = new ArrayList<>();
for (Participant p : mChatRoom.getParticipants()) {
Address a = p.getAddress();
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(a);