Fix crash when status date is null (#1480)
* Fix crash when status date is null * Fix crash when status date is null
This commit is contained in:
parent
c04c51ce41
commit
29ea05a0e5
2 changed files with 30 additions and 15 deletions
|
@ -252,9 +252,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setCreatedAt(@NonNull Date createdAt) {
|
protected void setCreatedAt(Date createdAt) {
|
||||||
if (useAbsoluteTime) {
|
if (useAbsoluteTime) {
|
||||||
timestampInfo.setText(getAbsoluteTime(createdAt));
|
timestampInfo.setText(getAbsoluteTime(createdAt));
|
||||||
|
} else {
|
||||||
|
if(createdAt == null) {
|
||||||
|
timestampInfo.setText("?m");
|
||||||
} else {
|
} else {
|
||||||
long then = createdAt.getTime();
|
long then = createdAt.getTime();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
@ -262,8 +265,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
timestampInfo.setText(readout);
|
timestampInfo.setText(readout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getAbsoluteTime(@NonNull Date createdAt) {
|
private String getAbsoluteTime(Date createdAt) {
|
||||||
|
if(createdAt == null) {
|
||||||
|
return "??:??:??";
|
||||||
|
}
|
||||||
if (DateUtils.isToday(createdAt.getTime())) {
|
if (DateUtils.isToday(createdAt.getTime())) {
|
||||||
return shortSdf.format(createdAt);
|
return shortSdf.format(createdAt);
|
||||||
} else {
|
} else {
|
||||||
|
@ -271,13 +278,16 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getCreatedAtDescription(@NonNull Date createdAt) {
|
private CharSequence getCreatedAtDescription(Date createdAt) {
|
||||||
if (useAbsoluteTime) {
|
if (useAbsoluteTime) {
|
||||||
return getAbsoluteTime(createdAt);
|
return getAbsoluteTime(createdAt);
|
||||||
} else {
|
} else {
|
||||||
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m"
|
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m"
|
||||||
* as 17 meters instead of minutes. */
|
* as 17 meters instead of minutes. */
|
||||||
|
|
||||||
|
if(createdAt == null) {
|
||||||
|
return "? minutes";
|
||||||
|
} else {
|
||||||
long then = createdAt.getTime();
|
long then = createdAt.getTime();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
return DateUtils.getRelativeTimeSpanString(then, now,
|
return DateUtils.getRelativeTimeSpanString(then, now,
|
||||||
|
@ -285,6 +295,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
DateUtils.FORMAT_ABBREV_RELATIVE);
|
DateUtils.FORMAT_ABBREV_RELATIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void setIsReply(boolean isReply) {
|
protected void setIsReply(boolean isReply) {
|
||||||
if (isReply) {
|
if (isReply) {
|
||||||
|
|
|
@ -67,10 +67,14 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setCreatedAt(@NonNull Date createdAt) {
|
protected void setCreatedAt(Date createdAt) {
|
||||||
|
if(createdAt == null) {
|
||||||
|
timestampInfo.setText("");
|
||||||
|
} else {
|
||||||
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT);
|
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT);
|
||||||
timestampInfo.setText(dateFormat.format(createdAt));
|
timestampInfo.setText(dateFormat.format(createdAt));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setReblogAndFavCount(int reblogCount, int favCount, StatusActionListener listener) {
|
private void setReblogAndFavCount(int reblogCount, int favCount, StatusActionListener listener) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue