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> {
NewsArticle article = newsArticles.get(position);
Markwon.setMarkdown(holder.articleTitle, article.getTitle());
holder.articleBody.setText(article.getBody().getBodyName());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US);
Date publishedDate = dateFormat.parse(article.getPublished());
Date publishedDate = article.getPublished();
Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate);
DateFormat displayFormat;
......@@ -66,9 +65,7 @@ public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> {
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
}
holder.articlePublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
e.printStackTrace();
}
Markwon.setMarkdown(holder.articleContent, article.getContent());
}
......
......@@ -51,9 +51,8 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap
public void onBindViewHolder(ViewHolder holder, int position) {
PlacementBlogPost post = posts.get(position);
Markwon.setMarkdown(holder.postTitle, post.getTitle());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US);
Date publishedDate = dateFormat.parse(post.getPublished());
Date publishedDate = post.getPublished();
Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate);
DateFormat displayFormat;
......@@ -63,9 +62,7 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<PlacementBlogAdap
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
}
holder.postPublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
holder.postPublished.setText(post.getPublished());
}
Markwon.setMarkdown(holder.postContent, post.getContent());
}
......
......@@ -51,9 +51,8 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte
public void onBindViewHolder(ViewHolder holder, int position) {
TrainingBlogPost post = posts.get(position);
Markwon.setMarkdown(holder.postTitle, post.getTitle());
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US);
Date publishedDate = dateFormat.parse(post.getPublished());
Date publishedDate = post.getPublished();
Calendar calendar = Calendar.getInstance();
calendar.setTime(publishedDate);
DateFormat displayFormat;
......@@ -63,9 +62,7 @@ public class TrainingBlogAdapter extends RecyclerView.Adapter<TrainingBlogAdapte
displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
}
holder.postPublished.setText(displayFormat.format(publishedDate));
} catch (ParseException e) {
holder.postPublished.setText(post.getPublished());
}
Markwon.setMarkdown(holder.postContent, post.getContent());
}
......
......@@ -6,7 +6,7 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName;
import java.util.Map;
import java.sql.Timestamp;
@Entity(tableName = "news")
......@@ -33,13 +33,13 @@ public class NewsArticle {
@ColumnInfo(name = "published")
@SerializedName("published")
private String published;
private Timestamp published;
@ColumnInfo(name = "body")
@SerializedName("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.link = link;
this.title = title;
......@@ -80,11 +80,11 @@ public class NewsArticle {
this.content = content;
}
public String getPublished() {
public Timestamp getPublished() {
return published;
}
public void setPublished(String published) {
public void setPublished(Timestamp published) {
this.published = published;
}
......
......@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
@Entity(tableName = "placementBlogPosts")
public class PlacementBlogPost {
......@@ -31,9 +33,9 @@ public class PlacementBlogPost {
@ColumnInfo(name = "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.link = link;
this.title = title;
......@@ -73,11 +75,11 @@ public class PlacementBlogPost {
this.content = content;
}
public String getPublished() {
public Timestamp getPublished() {
return published;
}
public void setPublished(String published) {
public void setPublished(Timestamp published) {
this.published = published;
}
}
......@@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey;
import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
@Entity(tableName = "trainingBlogPosts")
public class TrainingBlogPost {
......@@ -31,9 +33,9 @@ public class TrainingBlogPost {
@ColumnInfo(name = "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.link = link;
this.title = title;
......@@ -73,11 +75,11 @@ public class TrainingBlogPost {
this.content = content;
}
public String getPublished() {
public Timestamp getPublished() {
return published;
}
public void setPublished(String published) {
public void setPublished(Timestamp 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