rework list serialization

This commit is contained in:
Andrew Dolgov 2013-10-24 15:31:47 +04:00
parent 3fa0b2591a
commit e65c943dd8
3 changed files with 8 additions and 33 deletions

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.util.Log;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ArticleList extends ArrayList<Article> implements Parcelable { public class ArticleList extends ArrayList<Article> implements Parcelable {
@ -15,10 +16,7 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeInt(this.size()); out.writeList(this);
for (Article article : this) {
out.writeParcelable(article, flags);
}
} }
public Article findById(int id) { public Article findById(int id) {
@ -30,17 +28,12 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
} }
public void readFromParcel(Parcel in) { public void readFromParcel(Parcel in) {
int length = in.readInt(); in.readList(this, getClass().getClassLoader());
for (int i = 0; i < length; i++) {
Article article = in.readParcelable(Article.class.getClassLoader());
this.add(article);
}
} }
public ArticleList() { } public ArticleList() { }
public ArticleList(Parcel in) { public ArticleList(Parcel in) {
readFromParcel(in); readFromParcel(in);
} }

View File

@ -18,20 +18,11 @@ public class FeedCategoryList extends ArrayList<FeedCategory> implements Parcela
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeInt(this.size()); out.writeList(this);
for (FeedCategory feed : this) {
out.writeParcelable(feed, flags);
}
} }
public void readFromParcel(Parcel in) { public void readFromParcel(Parcel in) {
int length = in.readInt(); in.readList(this, getClass().getClassLoader());
for (int i = 0; i < length; i++) {
FeedCategory feed = in.readParcelable(FeedCategory.class.getClassLoader());
this.add(feed);
}
} }
public FeedCategoryList(Parcel in) { public FeedCategoryList(Parcel in) {

View File

@ -18,20 +18,11 @@ public class FeedList extends ArrayList<Feed> implements Parcelable {
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeInt(this.size()); out.writeList(this);
for (Feed feed : this) {
out.writeParcelable(feed, flags);
}
} }
public void readFromParcel(Parcel in) { public void readFromParcel(Parcel in) {
int length = in.readInt(); in.readList(this, getClass().getClassLoader());
for (int i = 0; i < length; i++) {
Feed feed = in.readParcelable(Feed.class.getClassLoader());
this.add(feed);
}
} }
public FeedList(Parcel in) { public FeedList(Parcel in) {