Fixed & improved linphone's core's timestamps use
This commit is contained in:
parent
76f31d0744
commit
76cd0f9b42
4 changed files with 10 additions and 24 deletions
|
@ -164,10 +164,14 @@ public final class LinphoneUtils {
|
||||||
return true;
|
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) {
|
public static String timestampToHumanDate(Context context, long timestamp, String format) {
|
||||||
try {
|
try {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTimeInMillis(timestamp);
|
cal.setTimeInMillis(timestamp * 1000); // Core returns timestamps in seconds...
|
||||||
|
|
||||||
SimpleDateFormat dateFormat;
|
SimpleDateFormat dateFormat;
|
||||||
if (isToday(cal)) {
|
if (isToday(cal)) {
|
||||||
|
|
|
@ -236,7 +236,7 @@ public class ChatEventsAdapter extends BaseAdapter {
|
||||||
holder.fileTransferAction.setBackgroundResource(R.drawable.resizable_assistant_button);
|
holder.fileTransferAction.setBackgroundResource(R.drawable.resizable_assistant_button);
|
||||||
holder.contactPictureMask.setImageResource(R.drawable.avatar_chat_mask);
|
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;
|
Spanned text = null;
|
||||||
String msg = message.getText();
|
String msg = message.getText();
|
||||||
|
@ -252,30 +252,12 @@ public class ChatEventsAdapter extends BaseAdapter {
|
||||||
holder.eventLayout.setVisibility(View.VISIBLE);
|
holder.eventLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
holder.eventMessage.setText(""); //TODO
|
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;
|
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) {
|
private boolean isToday(Calendar cal) {
|
||||||
return isSameDay(cal, Calendar.getInstance());
|
return isSameDay(cal, Calendar.getInstance());
|
||||||
}
|
}
|
||||||
|
|
|
@ -436,13 +436,13 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
if (msg.getFileTransferInformation() != null || msg.getExternalBodyUrl() != null || msg.getAppdata() != null) {
|
if (msg.getFileTransferInformation() != null || msg.getExternalBodyUrl() != null || msg.getAppdata() != null) {
|
||||||
holder.lastMessageView.setBackgroundResource(R.drawable.chat_file_message);
|
holder.lastMessageView.setBackgroundResource(R.drawable.chat_file_message);
|
||||||
time = msg.getTime();
|
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("");
|
holder.lastMessageView.setText("");
|
||||||
} else if (msg.getText() != null && msg.getText().length() > 0 ){
|
} else if (msg.getText() != null && msg.getText().length() > 0 ){
|
||||||
message = msg.getText();
|
message = msg.getText();
|
||||||
holder.lastMessageView.setBackgroundResource(0);
|
holder.lastMessageView.setBackgroundResource(0);
|
||||||
time = msg.getTime();
|
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);
|
holder.lastMessageView.setText(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (mChatRoom == null) return;
|
if (mChatRoom == null) return;
|
||||||
ArrayList<ContactAddress> participants = new ArrayList<ContactAddress>();
|
ArrayList<ContactAddress> participants = new ArrayList<>();
|
||||||
for (Participant p : mChatRoom.getParticipants()) {
|
for (Participant p : mChatRoom.getParticipants()) {
|
||||||
Address a = p.getAddress();
|
Address a = p.getAddress();
|
||||||
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(a);
|
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(a);
|
||||||
|
|
Loading…
Reference in a new issue