Skip to content

Commit

Permalink
fix UserInfo to accept null values when looking at other profiles
Browse files Browse the repository at this point in the history
also complete the implementation of Parcelable for UserInfo
  • Loading branch information
talklittle committed Dec 4, 2011
1 parent 17c39f6 commit 62f0667
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/com/andrewshu/android/reddit/mail/PeekEnvelopeTask.java
Expand Up @@ -76,16 +76,16 @@ protected void onPreExecute() {

@Override
public void onPostExecute(Object countObject) {
Integer count = (Integer) countObject;

// reset the alarm
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
EnvelopeService.resetAlarm(mContext, Util.getMillisFromMailNotificationPref(
prefs.getString(Constants.PREF_MAIL_NOTIFICATION_SERVICE, Constants.PREF_MAIL_NOTIFICATION_SERVICE_OFF)));

// null means error. Don't do anything.
if (countObject == null)
if (count == null)
return;

int count = (Integer) countObject;
if (count > 0) {
Common.newMailNotification(mContext, mMailNotificationStyle, count);
} else {
Expand Down
68 changes: 34 additions & 34 deletions src/com/andrewshu/android/reddit/things/ThingInfo.java
Expand Up @@ -521,46 +521,46 @@ public void writeToParcel(Parcel out, int flags) {
}

private ThingInfo(Parcel in) {
author = (String) in.readValue(null);
body = (String) in.readValue(null);
body_html = (String) in.readValue(null);
context = (String) in.readValue(null);
created = in.readDouble();
created_utc = in.readDouble();
dest = (String) in.readValue(null);
domain = (String) in.readValue(null);
downs = in.readInt();
author = (String) in.readValue(null);
body = (String) in.readValue(null);
body_html = (String) in.readValue(null);
context = (String) in.readValue(null);
created = in.readDouble();
created_utc = in.readDouble();
dest = (String) in.readValue(null);
domain = (String) in.readValue(null);
downs = in.readInt();
first_message = (Long) in.readValue(null);
id = (String) in.readValue(null);
link_id = (String) in.readValue(null);
name = (String) in.readValue(null);
num_comments = in.readInt();
parent_id = (String) in.readValue(null);
permalink = (String) in.readValue(null);
score = in.readInt();
selftext = (String) in.readValue(null);
id = (String) in.readValue(null);
link_id = (String) in.readValue(null);
name = (String) in.readValue(null);
num_comments = in.readInt();
parent_id = (String) in.readValue(null);
permalink = (String) in.readValue(null);
score = in.readInt();
selftext = (String) in.readValue(null);
selftext_html = (String) in.readValue(null);
subject = (String) in.readValue(null);
subreddit = (String) in.readValue(null);
subreddit_id = (String) in.readValue(null);
thumbnail = (String) in.readValue(null);
title = (String) in.readValue(null);
ups = in.readInt();
url = (String) in.readValue(null);
likes = (Boolean) in.readValue(null);
subject = (String) in.readValue(null);
subreddit = (String) in.readValue(null);
subreddit_id = (String) in.readValue(null);
thumbnail = (String) in.readValue(null);
title = (String) in.readValue(null);
ups = in.readInt();
url = (String) in.readValue(null);
likes = (Boolean) in.readValue(null);

boolean booleans[] = new boolean[10];
in.readBooleanArray(booleans);
clicked = booleans[0];
hidden = booleans[1];
is_self = booleans[2];
new_ = booleans[3];
over_18 = booleans[4];
saved = booleans[5];
was_comment = booleans[6];
clicked = booleans[0];
hidden = booleans[1];
is_self = booleans[2];
new_ = booleans[3];
over_18 = booleans[4];
saved = booleans[5];
was_comment = booleans[6];
mIsLoadMoreCommentsPlaceholder = booleans[7];
mIsHiddenCommentHead = booleans[8];
mIsHiddenCommentDescendant = booleans[9];
mIsHiddenCommentHead = booleans[8];
mIsHiddenCommentDescendant = booleans[9];
}

public static final Parcelable.Creator<ThingInfo> CREATOR
Expand Down
10 changes: 6 additions & 4 deletions src/com/andrewshu/android/reddit/user/ProfileActivity.java
Expand Up @@ -566,10 +566,12 @@ public Void doInBackground(Integer... maxComments) {
mKarma = getKarma();

String url;
StringBuilder sb = new StringBuilder(Constants.REDDIT_BASE_URL + "/user/")
.append(mUsername.trim())
.append("/.json?").append(mSortByUrl).append("&")
.append(mSortByUrlExtra).append("&");
StringBuilder sb = new StringBuilder(Constants.REDDIT_BASE_URL).append("/user/").append(mUsername.trim()).append("/.json?");

if (mSortByUrl != null)
sb = sb.append(mSortByUrl).append("&");
if (mSortByUrlExtra != null)
sb = sb.append(mSortByUrlExtra).append("&");

// "before" always comes back null unless you provide correct "count"
if (mAfter != null) {
Expand Down
50 changes: 42 additions & 8 deletions src/com/andrewshu/android/reddit/user/UserInfo.java
Expand Up @@ -9,7 +9,7 @@ public class UserInfo implements Serializable, Parcelable {

private static final long serialVersionUID = 1L;

private boolean has_mail;
private Boolean has_mail;
private String name;
private long created;
private String modhash;
Expand All @@ -19,30 +19,64 @@ public class UserInfo implements Serializable, Parcelable {
private boolean is_gold;
private boolean is_mod;
private String id;
private boolean has_mod_mail;
private Boolean has_mod_mail;

public UserInfo() {
super();
}

@Override
public int describeContents() {
return 0;
}

/**
* Use dest.writeValue for fields that may be null
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(has_mail);
dest.writeString(name);
dest.writeLong(created);
dest.writeString(modhash);
dest.writeValue(modhash);
dest.writeLong(created_utc);
dest.writeInt(link_karma);
dest.writeInt(comment_karma);
dest.writeString(id);
dest.writeValue(has_mod_mail);

boolean booleans[] = new boolean[4];
booleans[0] = has_mail;
booleans[1] = is_gold;
booleans[2] = is_mod;
booleans[3] = has_mod_mail;
boolean booleans[] = new boolean[2];
booleans[0] = is_gold;
booleans[1] = is_mod;
dest.writeBooleanArray(booleans);
}

public static final Parcelable.Creator<UserInfo> CREATOR = new Parcelable.Creator<UserInfo>() {
public UserInfo createFromParcel(Parcel in) {
return new UserInfo(in);
}

public UserInfo[] newArray(int size) {
return new UserInfo[size];
}
};

private UserInfo(Parcel in) {
has_mail = (Boolean) in.readValue(null);
name = in.readString();
created = in.readLong();
modhash = (String) in.readValue(null);
created_utc = in.readLong();
link_karma = in.readInt();
comment_karma = in.readInt();
id = in.readString();
has_mod_mail = (Boolean) in.readValue(null);

boolean booleans[] = new boolean[2];
in.readBooleanArray(booleans);
is_gold = booleans[0];
is_mod = booleans[1];
}

public boolean isHas_mail() {
return has_mail;
Expand Down
2 changes: 1 addition & 1 deletion src/com/andrewshu/android/reddit/user/UserInfoParser.java
Expand Up @@ -20,7 +20,7 @@ public static UserInfo parseJSON(InputStream in) {
meListing = Common.getObjectMapper().readValue(in, UserListing.class);
} catch (JsonMappingException ex) {
// it is not a Listing. user is not logged in.
if (Constants.LOGGING) Log.i(TAG, "InputStream is not UserListing JSON; user is not logged in?");
if (Constants.LOGGING) Log.i(TAG, "InputStream is not UserListing JSON; user is not logged in?", ex);
return null;
}

Expand Down

0 comments on commit 62f0667

Please sign in to comment.