Fixed readingItem instantiation to prevent rotation issues. Added tags to reading item view. Fixed scrolling to ensure webview scrolls alongside content. Added modified scrollview to ensure focus isn't stolen when load completes.

This commit is contained in:
RyanBateman 2012-07-19 14:07:27 -04:00
parent d1a7c366aa
commit 9edb970c24
16 changed files with 209 additions and 88 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -1,82 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.newsblur.view.NonfocusScrollview xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:background="@color/white" >
<RelativeLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_background"
android:padding="10dp" >
android:orientation="vertical"
>
<TextView
android:id="@+id/reading_item_authors"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center_vertical|right"
android:minWidth="80dp"
android:textColor="@color/lightgray"
android:textSize="11dp" />
android:background="@drawable/list_background"
android:padding="10dp" >
<TextView
android:id="@+id/reading_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/reading_item_title"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="80dp"
android:layout_toLeftOf="@id/reading_item_authors"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/reading_item_authors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center_vertical|right"
android:minWidth="80dp"
android:textColor="@color/lightgray"
android:textSize="11dp" />
<TextView
android:id="@+id/reading_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/reading_item_title"
android:layout_marginRight="10dp"
android:textColor="@color/lightgray"
android:textSize="11dp"
android:textStyle="italic" />
<TextView
android:id="@+id/reading_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="80dp"
android:layout_toLeftOf="@id/reading_item_authors"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/reading_item_comment"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignBottom="@id/reading_item_date"
android:layout_alignParentRight="true"
android:layout_below="@id/reading_item_title"
android:scaleType="fitCenter"
android:src="@drawable/favourite" />
<TextView
android:id="@+id/reading_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/reading_item_title"
android:layout_marginRight="10dp"
android:textColor="@color/lightgray"
android:textSize="11dp"
android:textStyle="italic" />
<TextView
android:id="@+id/reading_item_comment_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/reading_item_date"
android:layout_marginRight="3dp"
android:layout_toLeftOf="@id/reading_item_comment"
android:textSize="12dp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/reading_item_tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/reading_item_date"
android:visibility="invisible" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/darkgray" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/reading_item_date"
android:layout_alignParentRight="true"
android:layout_below="@id/reading_item_title"
android:gravity="center_vertical"
android:orientation="horizontal" >
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/lightgray" />
<TextView
android:id="@+id/reading_item_share_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:textColor="@color/white"
android:textSize="12dp" />
<WebView
android:id="@+id/reading_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/reading_item_share"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginRight="5dp"
android:src="@drawable/newsblur_share" />
</LinearLayout>
<TextView
android:id="@+id/reading_item_comment_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:textColor="@color/white"
android:textSize="12dp" />
<ImageView
android:id="@+id/reading_item_comment"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="@drawable/favourite" />
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/darkgray" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/lightgray" />
<WebView
android:id="@+id/reading_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
</com.newsblur.view.NonfocusScrollview>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:src="@drawable/tag" />
<TextView
android:id="@+id/tag_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="10dp" />
</LinearLayout>

View file

@ -116,7 +116,7 @@ public class Reading extends SherlockFragmentActivity {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.putExtra(Intent.EXTRA_SUBJECT, story.title);
final String shareString = getResources().getString(R.string.share);
intent.putExtra(Intent.EXTRA_TEXT, String.format(shareString, new String[] { story.title, story.permalink }));
intent.putExtra(Intent.EXTRA_TEXT, String.format(shareString, new Object[] { story.title, story.permalink }));
startActivity(Intent.createChooser(intent, "Share using"));
return true;
default:

View file

@ -46,9 +46,12 @@ public class BlurDatabase extends SQLiteOpenHelper {
DatabaseConstants.STORY_FEED_ID + INTEGER + ", " +
DatabaseConstants.STORY_ID + TEXT + " PRIMARY KEY, " +
DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + INTEGER + ", " +
DatabaseConstants.STORY_INTELLIGENCE_FEED + INTEGER + ", " +
DatabaseConstants.STORY_INTELLIGENCE_FEED + INTEGER + ", " +
DatabaseConstants.STORY_INTELLIGENCE_TAGS + INTEGER + ", " +
DatabaseConstants.STORY_INTELLIGENCE_TITLE + INTEGER + ", " +
DatabaseConstants.STORY_COMMENT_COUNT + INTEGER + ", " +
DatabaseConstants.STORY_SHARE_COUNT + INTEGER + ", " +
DatabaseConstants.STORY_TAGS + TEXT + ", " +
DatabaseConstants.STORY_PERMALINK + TEXT + ", " +
DatabaseConstants.STORY_READ + TEXT + ", " +
DatabaseConstants.STORY_TITLE + TEXT +

View file

@ -43,6 +43,8 @@ public class DatabaseConstants {
public static final String STORY_TITLE = "title";
public static final String STORY_DATE = "date";
public static final String STORY_CONTENT = "content";
public static final String STORY_COMMENT_COUNT = "comment_count";
public static final String STORY_SHARE_COUNT = "share_count";
public static final String STORY_PERMALINK = "permalink";
public static final String STORY_AUTHORS = "authors";
public static final String STORY_INTELLIGENCE_AUTHORS = "intelligence_authors";
@ -50,6 +52,7 @@ public class DatabaseConstants {
public static final String STORY_INTELLIGENCE_FEED = "intelligence_feed";
public static final String STORY_INTELLIGENCE_TITLE = "intelligence_title";
public static final String STORY_READ = "read";
public static final String STORY_TAGS = "tags";
public static final String STORY_FEED_ID = "feed_id";
// Aggregated columns

View file

@ -37,7 +37,7 @@ public class ReadingAdapter extends FragmentStatePagerAdapter implements LoaderM
return loadingFragment;
} else {
cursor.moveToPosition(position);
return new ReadingItemFragment(Story.fromCursor(cursor));
return ReadingItemFragment.newInstance(Story.fromCursor(cursor));
}
}

View file

@ -1,13 +1,19 @@
package com.newsblur.domain;
import java.io.Serializable;
import android.content.ContentValues;
import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
import com.newsblur.database.DatabaseConstants;
public class Story {
public class Story implements Serializable {
private static final long serialVersionUID = 7629596752129163308L;
public String id;
@ -15,10 +21,10 @@ public class Story {
public String permalink;
@SerializedName("share_count")
public Integer shareCount;
public String shareCount;
@SerializedName("comment_count")
public Integer commentCount;
public String commentCount;
@SerializedName("read_status")
public int read;
@ -27,7 +33,7 @@ public class Story {
public String[] tags;
@SerializedName("source_user_id")
public Integer sourceUserId;
public String sourceUserId;
@SerializedName("story_title")
public String title;
@ -60,10 +66,12 @@ public class Story {
values.put(DatabaseConstants.STORY_DATE, date);
values.put(DatabaseConstants.STORY_CONTENT, content);
values.put(DatabaseConstants.STORY_PERMALINK, permalink);
values.put(DatabaseConstants.STORY_COMMENT_COUNT, commentCount);
values.put(DatabaseConstants.STORY_SHARE_COUNT, shareCount);
values.put(DatabaseConstants.STORY_AUTHORS, authors);
values.put(DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, intelligenceAuthors);
values.put(DatabaseConstants.STORY_INTELLIGENCE_TAGS, TextUtils.join(",", tags));
values.put(DatabaseConstants.STORY_INTELLIGENCE_FEED, intelligenceFeed);
values.put(DatabaseConstants.STORY_TAGS, TextUtils.join(",", tags));
values.put(DatabaseConstants.STORY_INTELLIGENCE_TITLE, intelligenceTitle);
values.put(DatabaseConstants.STORY_READ, read);
values.put(DatabaseConstants.STORY_FEED_ID, feedId);
@ -76,11 +84,13 @@ public class Story {
story.content = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_CONTENT));
story.title = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_TITLE));
story.date = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_DATE));
story.shareCount = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_SHARE_COUNT));
story.commentCount = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_COMMENT_COUNT));
story.permalink = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_PERMALINK));
story.intelligenceAuthors = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_AUTHORS));
story.tags = TextUtils.split(cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TAGS)), ",");
story.intelligenceFeed = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_FEED));
story.read = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_READ));
story.tags = TextUtils.split(cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_TAGS)), ",");
story.feedId = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_FEED_ID));
story.id = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_ID));
return story;

View file

@ -7,6 +7,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.newsblur.R;
@ -14,19 +15,31 @@ import com.newsblur.domain.Story;
public class ReadingItemFragment extends Fragment {
final Story story;
Story story;
LayoutInflater inflater;
public ReadingItemFragment() {
story = null;
}
public ReadingItemFragment(final Story story) {
this.story = story;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_readingitem, null);
public static ReadingItemFragment newInstance(Story story) {
ReadingItemFragment readingFragment = new ReadingItemFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putSerializable("story", story);
readingFragment.setArguments(args);
return readingFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
story = getArguments() != null ? (Story) getArguments().getSerializable("story") : null;
}
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
this.inflater = inflater;
View view = inflater.inflate(R.layout.fragment_readingitem, null);
WebView web = (WebView) view.findViewById(R.id.reading_webview);
setupWebview(web);
setupItemMetadata(view);
@ -39,11 +52,24 @@ public class ReadingItemFragment extends Fragment {
TextView itemDate = (TextView) view.findViewById(R.id.reading_item_date);
TextView itemAuthors = (TextView) view.findViewById(R.id.reading_item_authors);
TextView itemCommentCount = (TextView) view.findViewById(R.id.reading_item_comment_count);
TextView itemShareCount = (TextView) view.findViewById(R.id.reading_item_share_count);
LinearLayout tagContainer = (LinearLayout) view.findViewById(R.id.reading_item_tags);
if (story.tags != null || story.tags.length > 0) {
tagContainer.setVisibility(View.VISIBLE);
for (String tag : story.tags) {
View v = inflater.inflate(R.layout.tag_view, null);
TextView tagText = (TextView) v.findViewById(R.id.tag_text);
tagText.setText(tag);
tagContainer.addView(v);
}
}
itemDate.setText(story.date);
itemTitle.setText(story.title);
itemAuthors.setText(story.authors);
itemCommentCount.setText(story.commentCount == null ? "0" : story.commentCount.toString());
itemShareCount.setText(story.shareCount == null ? "0" : story.shareCount.toString());
}
private void setupWebview(WebView web) {
@ -55,7 +81,8 @@ public class ReadingItemFragment extends Fragment {
web.getSettings().setAppCachePath("/data/data/com.newsblur/cache");
web.getSettings().setAllowFileAccess(true);
web.getSettings().setAppCacheEnabled(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setVerticalScrollBarEnabled(false);
StringBuilder builder = new StringBuilder();
// TODO: Define a better strategy for rescaling the HTML across device screen sizes and storying this HTML as boilderplate somewhere
builder.append("<html><head><meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"reading.css\" /></head><body>");

View file

@ -9,7 +9,6 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

View file

@ -0,0 +1,26 @@
package com.newsblur.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebView;
import android.widget.ScrollView;
public class NonfocusScrollview extends ScrollView {
public NonfocusScrollview(Context context) {
super(context);
}
public NonfocusScrollview(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void requestChildFocus(View child, View focused) {
if (focused instanceof WebView ) {
return;
}
super.requestChildFocus(child, focused);
}
}