fix [私聊消息聊天界面消息时间未按规定设置]
This commit is contained in:
parent
b954e9d451
commit
88e822004f
@ -1,6 +1,9 @@
|
||||
package com.yunbao.live.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@ -9,14 +12,21 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.yunbao.common.message.content.MessageChatTipsContent;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.event.InputPanelViewHolderEvent;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import io.rong.common.RLog;
|
||||
import io.rong.imkit.R.string;
|
||||
import io.rong.imkit.conversation.MessageListAdapter;
|
||||
import io.rong.imkit.model.UiMessage;
|
||||
import io.rong.imkit.utils.language.LangUtils;
|
||||
import io.rong.imkit.utils.language.RongConfigurationManager;
|
||||
import io.rong.imkit.widget.adapter.IViewProviderListener;
|
||||
import io.rong.imkit.widget.adapter.ViewHolder;
|
||||
import io.rong.imlib.model.Message;
|
||||
@ -71,6 +81,182 @@ public class PDLiveMessageListAdapter extends MessageListAdapter {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
TextView tv = holder.getView(R.id.rc_time);
|
||||
long sentTime = mDataList.get(position).getSentTime();
|
||||
tv.setText(getDateTimeString(sentTime,true, holder.getContext()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static String getDateTimeString(long dateMillis, boolean showTime, Context context) {
|
||||
if (dateMillis <= 0L) {
|
||||
return "";
|
||||
} else {
|
||||
String formatDate = null;
|
||||
Date date = new Date(dateMillis);
|
||||
int type = judgeDate(date);
|
||||
long time = java.lang.System.currentTimeMillis();
|
||||
Calendar calendarCur = Calendar.getInstance();
|
||||
Calendar calendardate = Calendar.getInstance();
|
||||
calendardate.setTimeInMillis(dateMillis);
|
||||
calendarCur.setTimeInMillis(time);
|
||||
int month = calendardate.get(2);
|
||||
int year = calendardate.get(1);
|
||||
int weekInMonth = calendardate.get(4);
|
||||
int monthCur = calendarCur.get(2);
|
||||
int yearCur = calendarCur.get(1);
|
||||
int weekInMonthCur = calendarCur.get(4);
|
||||
switch (type) {
|
||||
case 6:
|
||||
formatDate = getTimeString(dateMillis, context);
|
||||
break;
|
||||
case 15:
|
||||
String formatString = context.getResources().getString(string.rc_date_yesterday);
|
||||
if (showTime) {
|
||||
formatDate = formatString + " " + getTimeString(dateMillis, context);
|
||||
} else {
|
||||
formatDate = formatString;
|
||||
}
|
||||
break;
|
||||
case 2014:
|
||||
if (year == yearCur) {
|
||||
if (month == monthCur && weekInMonth == weekInMonthCur) {
|
||||
formatDate = getWeekDay(context, calendardate.get(7));
|
||||
} else {
|
||||
formatDate = formatDate(date, "M/d");
|
||||
}
|
||||
} else {
|
||||
formatDate = formatDate(date, "yyyy/M/d");
|
||||
}
|
||||
|
||||
if (showTime) {
|
||||
formatDate = formatDate + " " + getTimeString(dateMillis, context);
|
||||
}
|
||||
}
|
||||
|
||||
return formatDate;
|
||||
}
|
||||
}
|
||||
public static int judgeDate(Date date) {
|
||||
Calendar calendarToday = Calendar.getInstance();
|
||||
calendarToday.set(11, 0);
|
||||
calendarToday.set(12, 0);
|
||||
calendarToday.set(13, 0);
|
||||
calendarToday.set(14, 0);
|
||||
Calendar calendarYesterday = Calendar.getInstance();
|
||||
calendarYesterday.add(5, -1);
|
||||
calendarYesterday.set(11, 0);
|
||||
calendarYesterday.set(12, 0);
|
||||
calendarYesterday.set(13, 0);
|
||||
calendarYesterday.set(14, 0);
|
||||
Calendar calendarTomorrow = Calendar.getInstance();
|
||||
calendarTomorrow.add(5, 1);
|
||||
calendarTomorrow.set(11, 0);
|
||||
calendarTomorrow.set(12, 0);
|
||||
calendarTomorrow.set(13, 0);
|
||||
calendarTomorrow.set(14, 0);
|
||||
Calendar calendarTarget = Calendar.getInstance();
|
||||
calendarTarget.setTime(date);
|
||||
if (calendarTarget.before(calendarYesterday)) {
|
||||
return 2014;
|
||||
} else if (calendarTarget.before(calendarToday)) {
|
||||
return 15;
|
||||
} else {
|
||||
return calendarTarget.before(calendarTomorrow) ? 6 : 2014;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getWeekDay(Context context, int dayInWeek) {
|
||||
String weekDay = "";
|
||||
switch (dayInWeek) {
|
||||
case 1:
|
||||
weekDay = context.getResources().getString(string.rc_date_sunday);
|
||||
break;
|
||||
case 2:
|
||||
weekDay = context.getResources().getString(string.rc_date_monday);
|
||||
break;
|
||||
case 3:
|
||||
weekDay = context.getResources().getString(string.rc_date_tuesday);
|
||||
break;
|
||||
case 4:
|
||||
weekDay = context.getResources().getString(string.rc_date_wednesday);
|
||||
break;
|
||||
case 5:
|
||||
weekDay = context.getResources().getString(string.rc_date_thursday);
|
||||
break;
|
||||
case 6:
|
||||
weekDay = context.getResources().getString(string.rc_date_friday);
|
||||
break;
|
||||
case 7:
|
||||
weekDay = context.getResources().getString(string.rc_date_saturday);
|
||||
}
|
||||
|
||||
return weekDay;
|
||||
}
|
||||
|
||||
public static boolean isTime24Hour(Context context) {
|
||||
String timeFormat = Settings.System.getString(context.getContentResolver(), "time_12_24");
|
||||
return timeFormat != null && timeFormat.equals("24");
|
||||
}
|
||||
private static String getTimeString(long dateMillis, Context context) {
|
||||
if (dateMillis <= 0L) {
|
||||
return "";
|
||||
} else {
|
||||
Date date = new Date(dateMillis);
|
||||
String formatTime;
|
||||
if (isTime24Hour(context)||true) {
|
||||
formatTime = formatDate(date, "HH:mm");
|
||||
} else {
|
||||
Calendar calendarTime = Calendar.getInstance();
|
||||
calendarTime.setTimeInMillis(dateMillis);
|
||||
int hour = calendarTime.get(10);
|
||||
if (calendarTime.get(9) == 0) {
|
||||
if (hour < 6) {
|
||||
if (hour == 0) {
|
||||
hour = 12;
|
||||
}
|
||||
|
||||
formatTime = context.getResources().getString(string.rc_date_morning);
|
||||
} else {
|
||||
formatTime = context.getResources().getString(string.rc_date_am);
|
||||
}
|
||||
} else if (hour == 0) {
|
||||
formatTime = context.getResources().getString(string.rc_date_noon);
|
||||
hour = 12;
|
||||
} else if (hour <= 5) {
|
||||
formatTime = context.getResources().getString(string.rc_date_pm);
|
||||
} else {
|
||||
formatTime = context.getResources().getString(string.rc_date_night);
|
||||
}
|
||||
|
||||
int minuteInt = calendarTime.get(12);
|
||||
String minuteStr = Integer.toString(minuteInt);
|
||||
if (minuteInt < 10) {
|
||||
minuteStr = "0" + minuteStr;
|
||||
}
|
||||
|
||||
String timeStr = hour + ":" + minuteStr;
|
||||
if (RongConfigurationManager.getInstance().getLanguageLocal(context) == LangUtils.RCLocale.LOCALE_CHINA) {
|
||||
formatTime = formatTime + " " + timeStr;
|
||||
} else {
|
||||
formatTime = timeStr + " " + formatTime;
|
||||
}
|
||||
}
|
||||
|
||||
return formatTime;
|
||||
}
|
||||
}
|
||||
public static String formatDate(Date date, String fromat) {
|
||||
if (TextUtils.isEmpty(fromat)) {
|
||||
return "";
|
||||
} else {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(fromat);
|
||||
return sdf.format(date);
|
||||
} catch (IllegalArgumentException var3) {
|
||||
RLog.e("RLong", "the given pattern is invalid.");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user