Skip to content

Commit

Permalink
Detect when posts are locked (no UI yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Jun 30, 2021
1 parent 616ac42 commit df0910d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 40 deletions.
52 changes: 52 additions & 0 deletions src/main/java/org/quantumbadger/redreader/common/ParcelUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* This file is part of RedReader.
*
* RedReader is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RedReader is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RedReader. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

package org.quantumbadger.redreader.common;

import android.os.Parcel;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class ParcelUtils {

public static void writeNullableBoolean(
@NonNull final Parcel parcel,
@Nullable final Boolean value) {

if(value == null) {
parcel.writeInt(0);
} else if(value) {
parcel.writeInt(1);
} else {
parcel.writeInt(-1);
}
}

@Nullable
public static Boolean readNullableBoolean(@NonNull final Parcel parcel) {

final int value = parcel.readInt();

switch(value) {
case -1: return false;
case 0: return null;
case 1: return true;
}

throw new RuntimeException("Invalid value " + value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.os.Parcelable;
import androidx.annotation.Nullable;
import org.quantumbadger.redreader.common.Optional;
import org.quantumbadger.redreader.common.ParcelUtils;
import org.quantumbadger.redreader.jsonwrap.JsonBoolean;
import org.quantumbadger.redreader.jsonwrap.JsonLong;
import org.quantumbadger.redreader.jsonwrap.JsonObject;
Expand All @@ -34,9 +35,10 @@ public final class RedditPost implements Parcelable, RedditThingWithIdAndType {
public String title, author, domain, subreddit, subreddit_id;
public int num_comments, score, ups, downs, gilded;
public boolean archived, over_18, hidden, saved, is_self, clicked, stickied;
public JsonValue edited;
public Boolean likes;
public Boolean spoiler;
@Nullable public JsonValue edited;
@Nullable public Boolean likes;
@Nullable public Boolean spoiler;
@Nullable public Boolean locked;

public long created, created_utc;

Expand Down Expand Up @@ -121,18 +123,7 @@ private RedditPost(final Parcel in) {
edited = new JsonLong(in_edited);
}

switch(in.readInt()) {
case -1:
likes = false;
break;
case 0:
likes = null;
break;
case 1:
likes = true;
break;
}

likes = ParcelUtils.readNullableBoolean(in);
created = in.readLong();
created_utc = in.readLong();
selftext = in.readString();
Expand All @@ -141,19 +132,8 @@ private RedditPost(final Parcel in) {
link_flair_text = in.readString();
author_flair_text = in.readString();
thumbnail = in.readString();

switch(in.readInt()) {
case -1:
spoiler = false;
break;
case 0:
spoiler = null;
break;
case 1:
spoiler = true;
break;
}

spoiler = ParcelUtils.readNullableBoolean(in);
locked = ParcelUtils.readNullableBoolean(in);
rr_internal_dash_url = in.readString();
}

Expand Down Expand Up @@ -192,12 +172,7 @@ public void writeToParcel(final Parcel parcel, final int flags) {
parcel.writeLong(-1);
}

if(likes == null) {
parcel.writeInt(0);
} else {
parcel.writeInt(likes ? 1 : -1);
}

ParcelUtils.writeNullableBoolean(parcel, likes);
parcel.writeLong(created);
parcel.writeLong(created_utc);
parcel.writeString(selftext);
Expand All @@ -206,12 +181,8 @@ public void writeToParcel(final Parcel parcel, final int flags) {
parcel.writeString(link_flair_text);
parcel.writeString(author_flair_text);
parcel.writeString(thumbnail);

if(spoiler == null) {
parcel.writeInt(0);
} else {
parcel.writeInt(spoiler ? 1 : -1);
}
ParcelUtils.writeNullableBoolean(parcel, spoiler);
ParcelUtils.writeNullableBoolean(parcel, locked);

getDashUrl();
parcel.writeString(rr_internal_dash_url);
Expand Down

0 comments on commit df0910d

Please sign in to comment.