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:
Konrad Pozniak 2019-09-15 09:10:07 +02:00 committed by GitHub
parent c04c51ce41
commit 29ea05a0e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 15 deletions

View File

@ -252,18 +252,25 @@ 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 { } else {
long then = createdAt.getTime(); if(createdAt == null) {
long now = System.currentTimeMillis(); timestampInfo.setText("?m");
String readout = TimestampUtils.getRelativeTimeSpanString(timestampInfo.getContext(), then, now); } else {
timestampInfo.setText(readout); long then = createdAt.getTime();
long now = System.currentTimeMillis();
String readout = TimestampUtils.getRelativeTimeSpanString(timestampInfo.getContext(), then, now);
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,18 +278,22 @@ 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. */
long then = createdAt.getTime(); if(createdAt == null) {
long now = System.currentTimeMillis(); return "? minutes";
return DateUtils.getRelativeTimeSpanString(then, now, } else {
DateUtils.SECOND_IN_MILLIS, long then = createdAt.getTime();
DateUtils.FORMAT_ABBREV_RELATIVE); long now = System.currentTimeMillis();
return DateUtils.getRelativeTimeSpanString(then, now,
DateUtils.SECOND_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
}
} }
} }

View File

@ -67,9 +67,13 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
} }
@Override @Override
protected void setCreatedAt(@NonNull Date createdAt) { protected void setCreatedAt(Date createdAt) {
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT); if(createdAt == null) {
timestampInfo.setText(dateFormat.format(createdAt)); timestampInfo.setText("");
} else {
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT);
timestampInfo.setText(dateFormat.format(createdAt));
}
} }
private void setReblogAndFavCount(int reblogCount, int favCount, StatusActionListener listener) { private void setReblogAndFavCount(int reblogCount, int favCount, StatusActionListener listener) {