From a950ebbddbfa4e01abad4b75d2a05c55ca9b667d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 25 Nov 2011 23:34:40 +0300 Subject: [PATCH] implement Parcelable.CREATOR --- AndroidManifest.xml | 4 +- src/org/fox/ttrss/Article.java | 15 ++++++++ src/org/fox/ttrss/ArticleList.java | 47 +++++++++++++++++++++++ src/org/fox/ttrss/Feed.java | 15 ++++++++ src/org/fox/ttrss/FeedList.java | 49 ++++++++++++++++++++++++ src/org/fox/ttrss/FeedsFragment.java | 28 -------------- src/org/fox/ttrss/HeadlinesFragment.java | 25 +----------- 7 files changed, 129 insertions(+), 54 deletions(-) create mode 100644 src/org/fox/ttrss/ArticleList.java create mode 100644 src/org/fox/ttrss/FeedList.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index bed07a1e..34738f4c 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="4" + android:versionName="0.1.3"> diff --git a/src/org/fox/ttrss/Article.java b/src/org/fox/ttrss/Article.java index e9766556..1439416d 100644 --- a/src/org/fox/ttrss/Article.java +++ b/src/org/fox/ttrss/Article.java @@ -18,6 +18,10 @@ public class Article implements Parcelable { List tags; String content; + public Article(Parcel in) { + readFromParcel(in); + } + @Override public int describeContents() { return 0; @@ -51,4 +55,15 @@ public class Article implements Parcelable { in.readStringList(tags); content = in.readString(); } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public Article createFromParcel(Parcel in) { + return new Article(in); + } + + public Article[] newArray(int size) { + return new Article[size]; + } + }; } diff --git a/src/org/fox/ttrss/ArticleList.java b/src/org/fox/ttrss/ArticleList.java new file mode 100644 index 00000000..d09642c9 --- /dev/null +++ b/src/org/fox/ttrss/ArticleList.java @@ -0,0 +1,47 @@ +package org.fox.ttrss; + +import java.util.ArrayList; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ArticleList extends ArrayList
implements Parcelable { + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(this.size()); + for (Article article : this) { + out.writeParcelable(article, flags); + } + } + + public void readFromParcel(Parcel in) { + int length = in.readInt(); + + for (int i = 0; i < length; i++) { + Article article = in.readParcelable(Article.class.getClassLoader()); + this.add(article); + } + } + + public ArticleList() { } + + public ArticleList(Parcel in) { + readFromParcel(in); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public ArticleList createFromParcel(Parcel in) { + return new ArticleList(in); + } + + public ArticleList[] newArray(int size) { + return new ArticleList[size]; + } + }; +} \ No newline at end of file diff --git a/src/org/fox/ttrss/Feed.java b/src/org/fox/ttrss/Feed.java index feed1767..75131938 100644 --- a/src/org/fox/ttrss/Feed.java +++ b/src/org/fox/ttrss/Feed.java @@ -12,6 +12,10 @@ public class Feed implements Comparable, Parcelable { int cat_id; int last_updated; + public Feed(Parcel in) { + readFromParcel(in); + } + @Override public int compareTo(Feed feed) { if (feed.unread != this.unread) @@ -45,4 +49,15 @@ public class Feed implements Comparable, Parcelable { cat_id = in.readInt(); last_updated = in.readInt(); } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public Feed createFromParcel(Parcel in) { + return new Feed(in); + } + + public Feed[] newArray(int size) { + return new Feed[size]; + } + }; } \ No newline at end of file diff --git a/src/org/fox/ttrss/FeedList.java b/src/org/fox/ttrss/FeedList.java new file mode 100644 index 00000000..035edf57 --- /dev/null +++ b/src/org/fox/ttrss/FeedList.java @@ -0,0 +1,49 @@ +package org.fox.ttrss; + +import java.util.ArrayList; + +import android.os.Parcel; +import android.os.Parcelable; + +public class FeedList extends ArrayList implements Parcelable { + + public FeedList() { } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(this.size()); + for (Feed feed : this) { + out.writeParcelable(feed, flags); + } + } + + public void readFromParcel(Parcel in) { + int length = in.readInt(); + + for (int i = 0; i < length; i++) { + Feed feed = in.readParcelable(Feed.class.getClassLoader()); + this.add(feed); + } + + } + + public FeedList(Parcel in) { + readFromParcel(in); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public FeedList createFromParcel(Parcel in) { + return new FeedList(in); + } + + public FeedList[] newArray(int size) { + return new FeedList[size]; + } + }; + } diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index e78ae4f4..9777f9b2 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -10,8 +10,6 @@ import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.view.LayoutInflater; @@ -37,32 +35,6 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { private OnFeedSelectedListener m_feedSelectedListener; private int m_selectedFeedId; - private class FeedList extends ArrayList implements Parcelable { - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeInt(this.size()); - for (Feed feed : this) { - out.writeParcelable(feed, flags); - } - } - - public void readFromParcel(Parcel in) { - int length = in.readInt(); - - for (int i = 0; i < length; i++) { - Feed feed = in.readParcelable(Feed.class.getClassLoader()); - this.add(feed); - } - - } - } - public interface OnFeedSelectedListener { public void onFeedSelected(Feed feed); } diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index c139314d..c8da3371 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -57,30 +57,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { public void onArticleSelected(Article article); } - private class ArticleList extends ArrayList
implements Parcelable { - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeInt(this.size()); - for (Article article : this) { - out.writeParcelable(article, flags); - } - } - - public void readFromParcel(Parcel in) { - int length = in.readInt(); - - for (int i = 0; i < length; i++) { - Article article = in.readParcelable(Article.class.getClassLoader()); - this.add(article); - } - - } - } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {