implement Parcelable.CREATOR

This commit is contained in:
Andrew Dolgov 2011-11-25 23:34:40 +03:00
parent fe15fa86a1
commit a950ebbddb
7 changed files with 129 additions and 54 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss"
android:versionCode="3"
android:versionName="0.1.2">
android:versionCode="4"
android:versionName="0.1.3">
<uses-sdk android:minSdkVersion="10" />
<supports-screens android:smallScreens="false" android:normalScreens="false" />

View File

@ -18,6 +18,10 @@ public class Article implements Parcelable {
List<String> 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];
}
};
}

View File

@ -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<Article> 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];
}
};
}

View File

@ -12,6 +12,10 @@ public class Feed implements Comparable<Feed>, 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<Feed>, 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];
}
};
}

View File

@ -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<Feed> 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];
}
};
}

View File

@ -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<Feed> 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);
}

View File

@ -57,30 +57,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
public void onArticleSelected(Article article);
}
private class ArticleList extends ArrayList<Article> 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) {