Skip to content

Commit

Permalink
Fix crash with link preview date formatting on Android < 7.
Browse files Browse the repository at this point in the history
The 'X' wasn't supported until Android 7.
  • Loading branch information
greyson-signal committed Aug 28, 2020
1 parent 2d2395a commit ba712ce
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import android.annotation.SuppressLint;
import android.os.Build;
import android.text.Html;
import android.text.SpannableString;
import android.text.TextUtils;
Expand Down Expand Up @@ -199,8 +201,14 @@ public OpenGraph(@NonNull Map<String, String> values, @Nullable String htmlTitle
return OptionalUtil.absentIfEmpty(Util.getFirstNonEmpty(values.get(KEY_IMAGE_URL), faviconUrl));
}

@SuppressLint("ObsoleteSdkInt")
public long getDate() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.getDefault());
SimpleDateFormat format;
if (Build.VERSION.SDK_INT == 0 || Build.VERSION.SDK_INT >= 24) {
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.getDefault());
} else {
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault());
}

return Stream.of(values.get(KEY_PUBLISHED_TIME_1),
values.get(KEY_PUBLISHED_TIME_2),
Expand Down

0 comments on commit ba712ce

Please sign in to comment.