implement Parcelable.CREATOR
This commit is contained in:
parent
fe15fa86a1
commit
a950ebbddb
@ -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" />
|
||||
|
||||
|
@ -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];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
47
src/org/fox/ttrss/ArticleList.java
Normal file
47
src/org/fox/ttrss/ArticleList.java
Normal 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];
|
||||
}
|
||||
};
|
||||
}
|
@ -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];
|
||||
}
|
||||
};
|
||||
}
|
49
src/org/fox/ttrss/FeedList.java
Normal file
49
src/org/fox/ttrss/FeedList.java
Normal 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];
|
||||
}
|
||||
};
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user