Commit 1b4fadb0 authored by Varun Patil's avatar Varun Patil

Parse timestamps natively fornews and PT blogs

Fixes crash on Marshmallow
parent bd38c2aa
...@@ -54,9 +54,8 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> { ...@@ -54,9 +54,8 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> {
NewsArticle article = newsArticles.get(position); NewsArticle article = newsArticles.get(position);
Markwon.setMarkdown(holder.articleTitle, article.getTitle()); Markwon.setMarkdown(holder.articleTitle, article.getTitle());
holder.articleBody.setText(article.getBody().getBodyName()); holder.articleBody.setText(article.getBody().getBodyName());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US); Date publishedDate = article.getPublished();
Date publishedDate = dateFormat.parse(article.getPublished());
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate); calendar.setTime(publishedDate);
DateFormat displayFormat; DateFormat displayFormat;
...@@ -66,9 +65,7 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> { ...@@ -66,9 +65,7 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> {
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US); displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
} }
holder.articlePublished.setText(displayFormat.format(publishedDate)); holder.articlePublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
e.printStackTrace();
}
Markwon.setMarkdown(holder.articleContent, article.getContent()); Markwon.setMarkdown(holder.articleContent, article.getContent());
} }
......
...@@ -51,9 +51,8 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap ...@@ -51,9 +51,8 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
PlacementBlogPost post = posts.get(position); PlacementBlogPost post = posts.get(position);
Markwon.setMarkdown(holder.postTitle, post.getTitle()); Markwon.setMarkdown(holder.postTitle, post.getTitle());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US); Date publishedDate = post.getPublished();
Date publishedDate = dateFormat.parse(post.getPublished());
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate); calendar.setTime(publishedDate);
DateFormat displayFormat; DateFormat displayFormat;
...@@ -63,9 +62,7 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap ...@@ -63,9 +62,7 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US); displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
} }
holder.postPublished.setText(displayFormat.format(publishedDate)); holder.postPublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
holder.postPublished.setText(post.getPublished());
}
Markwon.setMarkdown(holder.postContent, post.getContent()); Markwon.setMarkdown(holder.postContent, post.getContent());
} }
......
...@@ -51,9 +51,8 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte ...@@ -51,9 +51,8 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
TrainingBlogPost post = posts.get(position); TrainingBlogPost post = posts.get(position);
Markwon.setMarkdown(holder.postTitle, post.getTitle()); Markwon.setMarkdown(holder.postTitle, post.getTitle());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US); Date publishedDate = post.getPublished();
Date publishedDate = dateFormat.parse(post.getPublished());
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate); calendar.setTime(publishedDate);
DateFormat displayFormat; DateFormat displayFormat;
...@@ -63,9 +62,7 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte ...@@ -63,9 +62,7 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US); displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
} }
holder.postPublished.setText(displayFormat.format(publishedDate)); holder.postPublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
holder.postPublished.setText(post.getPublished());
}
Markwon.setMarkdown(holder.postContent, post.getContent()); Markwon.setMarkdown(holder.postContent, post.getContent());
} }
......
...@@ -6,7 +6,7 @@ import android.arch.persistence.room.PrimaryKey; ...@@ -6,7 +6,7 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.Map; import java.sql.Timestamp;
@Entity(tableName = "news") @Entity(tableName = "news")
...@@ -33,13 +33,13 @@ public class NewsArticle { ...@@ -33,13 +33,13 @@ public class NewsArticle {
@ColumnInfo(name = "published") @ColumnInfo(name = "published")
@SerializedName("published") @SerializedName("published")
private String published; private Timestamp published;
@ColumnInfo(name = "body") @ColumnInfo(name = "body")
@SerializedName("body") @SerializedName("body")
private Body body; private Body body;
public NewsArticle(String articleID, String link, String title, String content, String published, Body body) { public NewsArticle(String articleID, String link, String title, String content, Timestamp published, Body body) {
this.articleID = articleID; this.articleID = articleID;
this.link = link; this.link = link;
this.title = title; this.title = title;
...@@ -80,11 +80,11 @@ public class NewsArticle { ...@@ -80,11 +80,11 @@ public class NewsArticle {
this.content = content; this.content = content;
} }
public String getPublished() { public Timestamp getPublished() {
return published; return published;
} }
public void setPublished(String published) { public void setPublished(Timestamp published) {
this.published = published; this.published = published;
} }
......
...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey; ...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
@Entity(tableName = "placementBlogPosts") @Entity(tableName = "placementBlogPosts")
public class PlacementBlogPost { public class PlacementBlogPost {
...@@ -31,9 +33,9 @@ public class PlacementBlogPost { ...@@ -31,9 +33,9 @@ public class PlacementBlogPost {
@ColumnInfo(name = "published") @ColumnInfo(name = "published")
@SerializedName("published") @SerializedName("published")
private String published; private Timestamp published;
public PlacementBlogPost(String postID, String link, String title, String content, String published) { public PlacementBlogPost(String postID, String link, String title, String content, Timestamp published) {
this.postID = postID; this.postID = postID;
this.link = link; this.link = link;
this.title = title; this.title = title;
...@@ -73,11 +75,11 @@ public class PlacementBlogPost { ...@@ -73,11 +75,11 @@ public class PlacementBlogPost {
this.content = content; this.content = content;
} }
public String getPublished() { public Timestamp getPublished() {
return published; return published;
} }
public void setPublished(String published) { public void setPublished(Timestamp published) {
this.published = published; this.published = published;
} }
} }
...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey; ...@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
@Entity(tableName = "trainingBlogPosts") @Entity(tableName = "trainingBlogPosts")
public class TrainingBlogPost { public class TrainingBlogPost {
...@@ -31,9 +33,9 @@ public class TrainingBlogPost { ...@@ -31,9 +33,9 @@ public class TrainingBlogPost {
@ColumnInfo(name = "published") @ColumnInfo(name = "published")
@SerializedName("published") @SerializedName("published")
private String published; private Timestamp published;
public TrainingBlogPost(String postID, String link, String title, String content, String published) { public TrainingBlogPost(String postID, String link, String title, String content, Timestamp published) {
this.postID = postID; this.postID = postID;
this.link = link; this.link = link;
this.title = title; this.title = title;
...@@ -73,11 +75,11 @@ public class TrainingBlogPost { ...@@ -73,11 +75,11 @@ public class TrainingBlogPost {
this.content = content; this.content = content;
} }
public String getPublished() { public Timestamp getPublished() {
return published; return published;
} }
public void setPublished(String published) { public void setPublished(Timestamp published) {
this.published = published; this.published = published;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment