Skip to content

Commit

Permalink
add version number
Browse files Browse the repository at this point in the history
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Blame Revision:
  • Loading branch information
simonzhexu committed Aug 30, 2019
1 parent 49b7062 commit 9a4bb5c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Android/app/src/main/assets/contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"name": "Cuppy",
"publisher": "Jane Doe",
"tray_image_file": "tray_Cuppy.png",
"image_data_version":"1",
"avoid_cache":false,
"publisher_email":"",
"publisher_website": "",
"privacy_policy_website": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ private static StickerPack readStickerPack(@NonNull JsonReader reader) throws IO
String publisherWebsite = null;
String privacyPolicyWebsite = null;
String licenseAgreementWebsite = null;
String imageDataVersion = "";
boolean avoidCache = false;
List<Sticker> stickerList = null;
while (reader.hasNext()) {
String key = reader.nextName();
Expand Down Expand Up @@ -106,6 +108,12 @@ private static StickerPack readStickerPack(@NonNull JsonReader reader) throws IO
case "stickers":
stickerList = readStickers(reader);
break;
case "image_data_version":
imageDataVersion = reader.nextString();
break;
case "avoid_cache":
avoidCache = reader.nextBoolean();
break;
default:
reader.skipValue();
}
Expand All @@ -128,8 +136,11 @@ private static StickerPack readStickerPack(@NonNull JsonReader reader) throws IO
if (identifier.contains("..") || identifier.contains("/")) {
throw new IllegalStateException("identifier should not contain .. or / to prevent directory traversal");
}
if (TextUtils.isEmpty(imageDataVersion)) {
throw new IllegalStateException("image_data_version should not be empty");
}
reader.endObject();
final StickerPack stickerPack = new StickerPack(identifier, name, publisher, trayImageFile, publisherEmail, publisherWebsite, privacyPolicyWebsite, licenseAgreementWebsite);
final StickerPack stickerPack = new StickerPack(identifier, name, publisher, trayImageFile, publisherEmail, publisherWebsite, privacyPolicyWebsite, licenseAgreementWebsite, imageDataVersion, avoidCache);
stickerPack.setStickers(stickerList);
return stickerPack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class StickerContentProvider extends ContentProvider {
public static final String PUBLISHER_WEBSITE = "sticker_pack_publisher_website";
public static final String PRIVACY_POLICY_WEBSITE = "sticker_pack_privacy_policy_website";
public static final String LICENSE_AGREENMENT_WEBSITE = "sticker_pack_license_agreement_website";
public static final String IMAGE_DATA_VERSION = "image_data_version";
public static final String AVOID_CACHE = "whatsapp_will_not_cache_stickers";

public static final String STICKER_FILE_NAME_IN_QUERY = "sticker_file_name";
public static final String STICKER_FILE_EMOJI_IN_QUERY = "sticker_emoji";
Expand Down Expand Up @@ -186,7 +188,9 @@ private Cursor getStickerPackInfo(@NonNull Uri uri, @NonNull List<StickerPack> s
PUBLISHER_EMAIL,
PUBLISHER_WEBSITE,
PRIVACY_POLICY_WEBSITE,
LICENSE_AGREENMENT_WEBSITE
LICENSE_AGREENMENT_WEBSITE,
IMAGE_DATA_VERSION,
AVOID_CACHE,
});
for (StickerPack stickerPack : stickerPackList) {
MatrixCursor.RowBuilder builder = cursor.newRow();
Expand All @@ -200,6 +204,8 @@ private Cursor getStickerPackInfo(@NonNull Uri uri, @NonNull List<StickerPack> s
builder.add(stickerPack.publisherWebsite);
builder.add(stickerPack.privacyPolicyWebsite);
builder.add(stickerPack.licenseAgreementWebsite);
builder.add(stickerPack.imageDataVersion);
builder.add(stickerPack.avoidCache ? 1 : 0);
}
cursor.setNotificationUri(Objects.requireNonNull(getContext()).getContentResolver(), uri);
return cursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ class StickerPack implements Parcelable {
final String publisherWebsite;
final String privacyPolicyWebsite;
final String licenseAgreementWebsite;
final String imageDataVersion;
final boolean avoidCache;

String iosAppStoreLink;
private List<Sticker> stickers;
private long totalSize;
String androidPlayStoreLink;
private boolean isWhitelisted;

StickerPack(String identifier, String name, String publisher, String trayImageFile, String publisherEmail, String publisherWebsite, String privacyPolicyWebsite, String licenseAgreementWebsite) {
StickerPack(String identifier, String name, String publisher, String trayImageFile, String publisherEmail, String publisherWebsite, String privacyPolicyWebsite, String licenseAgreementWebsite, String imageDataVersion, boolean avoidCache) {
this.identifier = identifier;
this.name = name;
this.publisher = publisher;
Expand All @@ -38,6 +40,8 @@ class StickerPack implements Parcelable {
this.publisherWebsite = publisherWebsite;
this.privacyPolicyWebsite = privacyPolicyWebsite;
this.licenseAgreementWebsite = licenseAgreementWebsite;
this.imageDataVersion = imageDataVersion;
this.avoidCache = avoidCache;
}

void setIsWhitelisted(boolean isWhitelisted) {
Expand All @@ -62,6 +66,8 @@ protected StickerPack(Parcel in) {
totalSize = in.readLong();
androidPlayStoreLink = in.readString();
isWhitelisted = in.readByte() != 0;
imageDataVersion = in.readString();
avoidCache = in.readByte() != 0;
}

public static final Creator<StickerPack> CREATOR = new Creator<StickerPack>() {
Expand Down Expand Up @@ -120,5 +126,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(totalSize);
dest.writeString(androidPlayStoreLink);
dest.writeByte((byte) (isWhitelisted ? 1 : 0));
dest.writeString(imageDataVersion);
dest.writeByte((byte) (avoidCache ? 1 : 0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

import static com.example.samplestickerapp.StickerContentProvider.ANDROID_APP_DOWNLOAD_LINK_IN_QUERY;
import static com.example.samplestickerapp.StickerContentProvider.AVOID_CACHE;
import static com.example.samplestickerapp.StickerContentProvider.IOS_APP_DOWNLOAD_LINK_IN_QUERY;
import static com.example.samplestickerapp.StickerContentProvider.LICENSE_AGREENMENT_WEBSITE;
import static com.example.samplestickerapp.StickerContentProvider.PRIVACY_POLICY_WEBSITE;
Expand All @@ -35,6 +36,7 @@
import static com.example.samplestickerapp.StickerContentProvider.STICKER_PACK_IDENTIFIER_IN_QUERY;
import static com.example.samplestickerapp.StickerContentProvider.STICKER_PACK_NAME_IN_QUERY;
import static com.example.samplestickerapp.StickerContentProvider.STICKER_PACK_PUBLISHER_IN_QUERY;
import static com.example.samplestickerapp.StickerContentProvider.IMAGE_DATA_VERSION;

class StickerPackLoader {

Expand Down Expand Up @@ -101,7 +103,9 @@ private static ArrayList<StickerPack> fetchFromContentProvider(Cursor cursor) {
final String publisherWebsite = cursor.getString(cursor.getColumnIndexOrThrow(PUBLISHER_WEBSITE));
final String privacyPolicyWebsite = cursor.getString(cursor.getColumnIndexOrThrow(PRIVACY_POLICY_WEBSITE));
final String licenseAgreementWebsite = cursor.getString(cursor.getColumnIndexOrThrow(LICENSE_AGREENMENT_WEBSITE));
final StickerPack stickerPack = new StickerPack(identifier, name, publisher, trayImage, publisherEmail, publisherWebsite, privacyPolicyWebsite, licenseAgreementWebsite);
final String imageDataVersion = cursor.getString(cursor.getColumnIndexOrThrow(IMAGE_DATA_VERSION));
final boolean avoidCache = cursor.getShort(cursor.getColumnIndexOrThrow(AVOID_CACHE)) > 0;
final StickerPack stickerPack = new StickerPack(identifier, name, publisher, trayImage, publisherEmail, publisherWebsite, privacyPolicyWebsite, licenseAgreementWebsite, imageDataVersion, avoidCache);
stickerPack.setAndroidPlayStoreLink(androidPlayStoreLink);
stickerPack.setIosAppStoreLink(iosAppLink);
stickerPackList.add(stickerPack);
Expand Down

0 comments on commit 9a4bb5c

Please sign in to comment.