Skip to content

Commit

Permalink
Improvements to model caching lists and transaction memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelengland authored and mttkay committed Mar 30, 2011
1 parent e603666 commit 808f14d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/main/java/com/github/droidfu/cachefu/CachedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public CachedList(Class<? extends CachedModel> clazz, int initialLength) {
list = new ArrayList<CO>(initialLength);
}

public CachedList(Class<? extends CachedModel> clazz, Parcel source) throws IOException {
public CachedList(Parcel source) throws IOException {
super(source);
initList(clazz);
list = new ArrayList<CO>();
}

public CachedList(Class<? extends CachedModel> clazz, String id) {
Expand Down Expand Up @@ -72,17 +70,11 @@ public boolean reloadFromCachedModel(ModelCache modelCache, CachedModel cachedMo

public static final Creator<CachedList<CachedModel>> CREATOR = new Parcelable.Creator<CachedList<CachedModel>>() {

@SuppressWarnings("unchecked")
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public CachedList<CachedModel> createFromParcel(Parcel source) {
String className = source.readString();
Class<? extends CachedModel> clazz;
try {
clazz = (Class<? extends CachedModel>) Class.forName(className);
return new CachedList<CachedModel>(clazz, source);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
return new CachedList(source);
} catch (IOException e) {
e.printStackTrace();
return null;
Expand All @@ -97,11 +89,17 @@ public CachedList<CachedModel>[] newArray(int size) {

};

@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void readFromParcel(Parcel source) throws IOException {
super.readFromParcel(source);
list = source.readArrayList(clazz.getClassLoader());
String className = source.readString();
try {
clazz = (Class<? extends CachedModel>) Class.forName(className);
list = source.createTypedArrayList((Creator) clazz.getField("CREATOR").get(this));
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/droidfu/cachefu/CachedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeLong(transactionId);
}

@SuppressWarnings("unused")
public void readFromParcel(Parcel source) throws IOException {
id = source.readString();
transactionId = source.readLong();
}

}

0 comments on commit 808f14d

Please sign in to comment.