Fix inline story content. (#497)

This commit is contained in:
dosiecki 2014-03-24 00:45:18 -07:00
parent da94c64e08
commit 89a53e4c1d
9 changed files with 57 additions and 37 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.newsblur" package="com.newsblur"
android:versionCode="62" android:versionCode="63"
android:versionName="3.6.4" > android:versionName="3.6.5" >
<uses-sdk <uses-sdk
android:minSdkVersion="11" android:minSdkVersion="11"

View file

@ -65,8 +65,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/row_item_sidebar" android:layout_toRightOf="@+id/row_item_sidebar"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:paddingTop="8dp" android:paddingTop="4dp"
android:paddingBottom="8dp" android:paddingBottom="2dp"
android:maxLines="2" android:maxLines="2"
android:ellipsize="end" android:ellipsize="end"
android:textSize="14sp"/> android:textSize="14sp"/>
@ -78,8 +78,8 @@
android:layout_toRightOf="@+id/row_item_sidebar" android:layout_toRightOf="@+id/row_item_sidebar"
android:layout_below="@+id/row_item_title" android:layout_below="@+id/row_item_title"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:paddingTop="8dp" android:paddingTop="2dp"
android:paddingBottom="8dp" android:paddingBottom="4dp"
android:maxLines="2" android:maxLines="2"
android:ellipsize="end" android:ellipsize="end"
android:textSize="14sp"/> android:textSize="14sp"/>
@ -93,8 +93,7 @@
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_below="@+id/row_item_title_container" android:layout_below="@+id/row_item_title_container"
android:layout_marginRight="12dp" android:layout_marginRight="12dp"
android:paddingTop="2dp" android:paddingBottom="4dp"
android:paddingBottom="6dp"
android:textColor="@color/darkgray" android:textColor="@color/darkgray"
android:textSize="11dp" /> android:textSize="11dp" />
@ -103,8 +102,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/row_item_title_container" android:layout_below="@+id/row_item_title_container"
android:paddingTop="2dp" android:paddingBottom="4dp"
android:paddingBottom="6dp"
android:layout_toLeftOf="@id/row_item_date" android:layout_toLeftOf="@id/row_item_date"
android:layout_toRightOf="@id/row_item_favicon_borderbar_2" android:layout_toRightOf="@id/row_item_favicon_borderbar_2"
android:layout_marginLeft="22dp" android:layout_marginLeft="22dp"

View file

@ -44,8 +44,8 @@
android:maxLines="2" android:maxLines="2"
android:ellipsize="end" android:ellipsize="end"
android:gravity="left" android:gravity="left"
android:paddingBottom="8dp" android:paddingBottom="2dp"
android:paddingTop="8dp" android:paddingTop="4dp"
android:textSize="14sp"/> android:textSize="14sp"/>
<TextView <TextView
@ -58,11 +58,10 @@
android:maxLines="2" android:maxLines="2"
android:ellipsize="end" android:ellipsize="end"
android:gravity="left" android:gravity="left"
android:paddingBottom="8dp" android:paddingBottom="4dp"
android:paddingTop="8dp" android:paddingTop="2dp"
android:textSize="14sp"/> android:textSize="14sp"/>
</RelativeLayout> </RelativeLayout>
<TextView <TextView
@ -72,7 +71,7 @@
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_below="@id/row_item_title_container" android:layout_below="@id/row_item_title_container"
android:layout_marginRight="12dp" android:layout_marginRight="12dp"
android:paddingBottom="2dp" android:paddingBottom="4dp"
android:textColor="@color/darkgray" android:textColor="@color/darkgray"
android:textSize="11dp" /> android:textSize="11dp" />
@ -81,7 +80,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/row_item_title_container" android:layout_below="@id/row_item_title_container"
android:paddingBottom="2dp" android:paddingBottom="4dp"
android:layout_marginLeft="24dp" android:layout_marginLeft="24dp"
android:layout_toLeftOf="@id/row_item_date" android:layout_toLeftOf="@id/row_item_date"
android:layout_alignLeft="@id/row_item_title_container" android:layout_alignLeft="@id/row_item_title_container"

View file

@ -55,8 +55,8 @@
android:layout_alignLeft="@id/row_item_feedicon" android:layout_alignLeft="@id/row_item_feedicon"
android:layout_below="@id/row_item_feedicon" android:layout_below="@id/row_item_feedicon"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:paddingTop="8dp" android:paddingTop="4dp"
android:paddingBottom="12dp" android:paddingBottom="2dp"
android:textColor="@color/darkgray" android:textColor="@color/darkgray"
android:textSize="14sp"/> android:textSize="14sp"/>
@ -67,8 +67,10 @@
android:layout_alignLeft="@id/row_item_feedicon" android:layout_alignLeft="@id/row_item_feedicon"
android:layout_below="@id/row_item_title" android:layout_below="@id/row_item_title"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:paddingTop="8dp" android:paddingTop="2dp"
android:paddingBottom="12dp" android:paddingBottom="4dp"
android:maxLines="2"
android:ellipsize="end"
android:textColor="@color/darkgray" android:textColor="@color/darkgray"
android:textSize="14sp"/> android:textSize="14sp"/>
@ -79,7 +81,7 @@
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_below="@+id/row_item_content" android:layout_below="@+id/row_item_content"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:paddingBottom="12dp" android:paddingBottom="4dp"
android:textColor="@color/darkgray" android:textColor="@color/darkgray"
android:textSize="11dp" /> android:textSize="11dp" />
@ -88,7 +90,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/row_item_content" android:layout_below="@+id/row_item_content"
android:paddingBottom="12dp" android:paddingBottom="4dp"
android:layout_toLeftOf="@id/row_item_date" android:layout_toLeftOf="@id/row_item_date"
android:layout_toRightOf="@id/row_item_sidebar" android:layout_toRightOf="@id/row_item_sidebar"
android:ellipsize="end" android:ellipsize="end"

View file

@ -25,7 +25,7 @@
<color name="story_title_unread">#333333</color> <color name="story_title_unread">#333333</color>
<color name="story_title_read">#808080</color> <color name="story_title_read">#808080</color>
<color name="story_content_unread">#404040</color> <color name="story_content_unread">#404040</color>
<color name="story_content_read">#848484</color> <color name="story_content_read">#909090</color>
<color name="story_feed_unread">#606060</color> <color name="story_feed_unread">#606060</color>
<color name="story_feed_read">#A0A0A0</color> <color name="story_feed_read">#A0A0A0</color>
<color name="story_author_unread">#959595</color> <color name="story_author_unread">#959595</color>

View file

@ -86,6 +86,7 @@ public class BlurDatabase extends SQLiteOpenHelper {
DatabaseConstants.STORY_HASH + TEXT + ", " + DatabaseConstants.STORY_HASH + TEXT + ", " +
DatabaseConstants.STORY_AUTHORS + TEXT + ", " + DatabaseConstants.STORY_AUTHORS + TEXT + ", " +
DatabaseConstants.STORY_CONTENT + TEXT + ", " + DatabaseConstants.STORY_CONTENT + TEXT + ", " +
DatabaseConstants.STORY_SHORT_CONTENT + TEXT + ", " +
DatabaseConstants.STORY_TIMESTAMP + INTEGER + ", " + DatabaseConstants.STORY_TIMESTAMP + INTEGER + ", " +
DatabaseConstants.STORY_SHARED_DATE + INTEGER + ", " + DatabaseConstants.STORY_SHARED_DATE + INTEGER + ", " +
DatabaseConstants.STORY_SHORTDATE + TEXT + ", " + DatabaseConstants.STORY_SHORTDATE + TEXT + ", " +

View file

@ -77,7 +77,7 @@ public class DatabaseConstants {
public static final String STORY_TIMESTAMP = "timestamp"; public static final String STORY_TIMESTAMP = "timestamp";
public static final String STORY_SHARED_DATE = "sharedDate"; public static final String STORY_SHARED_DATE = "sharedDate";
public static final String STORY_CONTENT = "content"; public static final String STORY_CONTENT = "content";
public static final String STORY_SHORT_CONTENT = "content"; public static final String STORY_SHORT_CONTENT = "short_content";
public static final String STORY_COMMENT_COUNT = "comment_count"; public static final String STORY_COMMENT_COUNT = "comment_count";
public static final String STORY_FEED_ID = "feed_id"; public static final String STORY_FEED_ID = "feed_id";
public static final String STORY_INTELLIGENCE_AUTHORS = "intelligence_authors"; public static final String STORY_INTELLIGENCE_AUTHORS = "intelligence_authors";
@ -172,12 +172,16 @@ public class DatabaseConstants {
private static final String STORY_INTELLIGENCE_ALL = DatabaseConstants.SUM_STORY_TOTAL + " >= 0 "; private static final String STORY_INTELLIGENCE_ALL = DatabaseConstants.SUM_STORY_TOTAL + " >= 0 ";
public static final String[] STORY_COLUMNS = { public static final String[] STORY_COLUMNS = {
STORY_AUTHORS, STORY_COMMENT_COUNT, STORY_CONTENT, STORY_TIMESTAMP, STORY_SHARED_DATE, STORY_SHORTDATE, STORY_LONGDATE, STORY_TABLE + "." + STORY_FEED_ID, STORY_TABLE + "." + STORY_ID, STORY_INTELLIGENCE_AUTHORS, STORY_INTELLIGENCE_FEED, STORY_INTELLIGENCE_TAGS, STORY_INTELLIGENCE_TITLE, STORY_AUTHORS, STORY_COMMENT_COUNT, STORY_CONTENT, STORY_SHORT_CONTENT, STORY_TIMESTAMP, STORY_SHARED_DATE, STORY_SHORTDATE, STORY_LONGDATE,
STORY_PERMALINK, STORY_READ, STORY_STARRED, STORY_STARRED_DATE, STORY_SHARE_COUNT, STORY_TAGS, STORY_TITLE, STORY_SOCIAL_USER_ID, STORY_SOURCE_USER_ID, STORY_SHARED_USER_IDS, STORY_FRIEND_USER_IDS, STORY_PUBLIC_USER_IDS, STORY_SUM_TOTAL, STORY_HASH STORY_TABLE + "." + STORY_FEED_ID, STORY_TABLE + "." + STORY_ID, STORY_INTELLIGENCE_AUTHORS, STORY_INTELLIGENCE_FEED, STORY_INTELLIGENCE_TAGS,
STORY_INTELLIGENCE_TITLE, STORY_PERMALINK, STORY_READ, STORY_STARRED, STORY_STARRED_DATE, STORY_SHARE_COUNT, STORY_TAGS, STORY_TITLE,
STORY_SOCIAL_USER_ID, STORY_SOURCE_USER_ID, STORY_SHARED_USER_IDS, STORY_FRIEND_USER_IDS, STORY_PUBLIC_USER_IDS, STORY_SUM_TOTAL, STORY_HASH
}; };
public static final String[] STARRED_STORY_COLUMNS = { public static final String[] STARRED_STORY_COLUMNS = {
STORY_AUTHORS, STORY_COMMENT_COUNT, STORY_CONTENT, STORY_TIMESTAMP, STORY_SHARED_DATE, STORY_SHORTDATE, STORY_LONGDATE, STARRED_STORIES_TABLE + "." + STORY_FEED_ID, STARRED_STORIES_TABLE + "." + STORY_ID, STORY_INTELLIGENCE_AUTHORS, STORY_INTELLIGENCE_FEED, STORY_INTELLIGENCE_TAGS, STORY_INTELLIGENCE_TITLE, STORY_AUTHORS, STORY_COMMENT_COUNT, STORY_CONTENT, STORY_SHORT_CONTENT, STORY_TIMESTAMP, STORY_SHARED_DATE, STORY_SHORTDATE, STORY_LONGDATE,
STORY_PERMALINK, STORY_READ, STORY_STARRED, STORY_STARRED_DATE, STORY_SHARE_COUNT, STORY_TAGS, STORY_TITLE, STORY_SOCIAL_USER_ID, STORY_SOURCE_USER_ID, STORY_SHARED_USER_IDS, STORY_FRIEND_USER_IDS, STORY_PUBLIC_USER_IDS, STORY_SUM_TOTAL, STORY_HASH STARRED_STORIES_TABLE + "." + STORY_FEED_ID, STARRED_STORIES_TABLE + "." + STORY_ID, STORY_INTELLIGENCE_AUTHORS, STORY_INTELLIGENCE_FEED, STORY_INTELLIGENCE_TAGS,
STORY_INTELLIGENCE_TITLE, STORY_PERMALINK, STORY_READ, STORY_STARRED, STORY_STARRED_DATE, STORY_SHARE_COUNT, STORY_TAGS, STORY_TITLE,
STORY_SOCIAL_USER_ID, STORY_SOURCE_USER_ID, STORY_SHARED_USER_IDS, STORY_FRIEND_USER_IDS, STORY_PUBLIC_USER_IDS, STORY_SUM_TOTAL, STORY_HASH
}; };
public static final String STARRED_STORY_ORDER = STORY_STARRED_DATE + " ASC"; public static final String STARRED_STORY_ORDER = STORY_STARRED_DATE + " ASC";

View file

@ -8,7 +8,6 @@ import java.util.List;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -68,7 +67,7 @@ public class Story implements Serializable {
@SerializedName("story_content") @SerializedName("story_content")
public String content; public String content;
@SerializedName("story_short_content") // this isn't actually a serialized feed, but created client-size in StoryTypeAdapter
public String shortContent; public String shortContent;
@SerializedName("story_authors") @SerializedName("story_authors")
@ -104,6 +103,7 @@ public class Story implements Serializable {
values.put(DatabaseConstants.STORY_SHORTDATE, shortDate); values.put(DatabaseConstants.STORY_SHORTDATE, shortDate);
values.put(DatabaseConstants.STORY_LONGDATE, longDate); values.put(DatabaseConstants.STORY_LONGDATE, longDate);
values.put(DatabaseConstants.STORY_CONTENT, content); values.put(DatabaseConstants.STORY_CONTENT, content);
values.put(DatabaseConstants.STORY_SHORT_CONTENT, shortContent);
values.put(DatabaseConstants.STORY_PERMALINK, permalink); values.put(DatabaseConstants.STORY_PERMALINK, permalink);
values.put(DatabaseConstants.STORY_COMMENT_COUNT, commentCount); values.put(DatabaseConstants.STORY_COMMENT_COUNT, commentCount);
values.put(DatabaseConstants.STORY_SHARE_COUNT, shareCount); values.put(DatabaseConstants.STORY_SHARE_COUNT, shareCount);
@ -133,12 +133,7 @@ public class Story implements Serializable {
Story story = new Story(); Story story = new Story();
story.authors = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_AUTHORS)); story.authors = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_AUTHORS));
story.content = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_CONTENT)); story.content = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_CONTENT));
if (story.content != null) { story.shortContent = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_SHORT_CONTENT));
String shortContent = Html.fromHtml(story.content).toString();
if (shortContent.length() >= 200) {
story.shortContent = shortContent.substring(0, 200);
}
}
story.title = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_TITLE)); story.title = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_TITLE));
story.timestamp = cursor.getLong(cursor.getColumnIndex(DatabaseConstants.STORY_TIMESTAMP)); story.timestamp = cursor.getLong(cursor.getColumnIndex(DatabaseConstants.STORY_TIMESTAMP));
story.sharedDate = new Date(cursor.getLong(cursor.getColumnIndex(DatabaseConstants.STORY_SHARED_DATE))); story.sharedDate = new Date(cursor.getLong(cursor.getColumnIndex(DatabaseConstants.STORY_SHARED_DATE)));

View file

@ -10,6 +10,11 @@ import com.newsblur.domain.Story;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Date; import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.text.Html;
import android.util.Log;
/** /**
* Created by mark on 15/03/2014. * Created by mark on 15/03/2014.
@ -18,6 +23,10 @@ public class StoryTypeAdapter implements JsonDeserializer<Story> {
private Gson gson; private Gson gson;
// the HTML parser puts placeholders for images and other content when parsing to text, but we
// want to remove them.
private final static Pattern HtmlPlaceholders = Pattern.compile("\\uFFFC");
public StoryTypeAdapter() { public StoryTypeAdapter() {
this.gson = new GsonBuilder() this.gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateStringTypeAdapter()) .registerTypeAdapter(Date.class, new DateStringTypeAdapter())
@ -29,8 +38,20 @@ public class StoryTypeAdapter implements JsonDeserializer<Story> {
@Override @Override
public Story deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { public Story deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
Story story = gson.fromJson(jsonElement, Story.class); Story story = gson.fromJson(jsonElement, Story.class);
// Convert story_timestamp to milliseconds // Convert story_timestamp to milliseconds
story.timestamp = story.timestamp * 1000; story.timestamp = story.timestamp * 1000;
// populate the shortContent field
if (story.content != null) {
CharSequence parsed = Html.fromHtml(story.content).toString();
int length = 200;
if (parsed.length() < 200) { length = parsed.length(); }
story.shortContent = parsed.subSequence(0, length).toString();
Matcher m = HtmlPlaceholders.matcher(story.shortContent);
story.shortContent = m.replaceAll("");
}
return story; return story;
} }
} }