Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added serialized size to Image and Media (Issue #5) #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/tenor/android/core/model/ContentFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tenor.android.core.model;

public enum ContentFilter {
high, medium, low, off
}
11 changes: 11 additions & 0 deletions src/main/java/com/tenor/android/core/model/impl/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class Image implements Serializable {
private static final long serialVersionUID = -8616498739266612929L;
private String url;

@SerializedName("size")
private long size;

@SerializedName("dims")
private int[] dimensions;

Expand All @@ -26,6 +29,7 @@ public String getUrl() {
return StringConstant.getOrEmpty(url);
}


public int getWidth() {
return dimensions != null && dimensions.length == 2 ? dimensions[0] : -1;
}
Expand All @@ -42,4 +46,11 @@ public float getAspectRatio() {
final float aspectRatio = (float) getWidth() / getHeight();
return aspectRatio >= 0.01f && aspectRatio <= 5.01f ? aspectRatio : 1.778f;
}

/**
* @return size of this {@link Image} or -1 if it doesn't exist
*/
public long getSize() {
return size != 0 ? size : -1;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/tenor/android/core/model/impl/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Media extends Image {
private static final long serialVersionUID = -8616498739266612929L;
private String preview;
private double duration;
private long size;

/**
* @return url of a static image preview
Expand All @@ -26,4 +27,11 @@ public String getPreviewUrl() {
public double getDuration() {
return duration;
}

/**
* @return size of this {@link Image} or -1 if it doesn't exist
*/
public long getSize() {
return size != 0 ? size : -1;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/tenor/android/core/network/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.tenor.android.core.constant.StringConstant;
import com.tenor.android.core.constant.ViewAction;
import com.tenor.android.core.measurable.MeasurableViewHolderEvent;
import com.tenor.android.core.model.ContentFilter;
import com.tenor.android.core.model.impl.Result;
import com.tenor.android.core.response.WeakRefCallback;
import com.tenor.android.core.response.impl.AnonIdResponse;
Expand Down Expand Up @@ -98,6 +99,18 @@ public static synchronized IApiClient getInstance(@NonNull Context context) {
* content delivery experience
*/
public static Map<String, String> getServiceIds(@NonNull final Context context) {
return getServiceIds(context, ContentFilter.off);
}

/**
* Get service ids that can delivery a more accurate and better experience
* Allows for content filtering
*
* @return a {@link Map} with {@code key} (API Key), {@code anon_id},
* {@code aaid} (Android Advertise Id) and {@code locale } for authentication and better
* content delivery experience
*/
public static Map<String, String> getServiceIds(@NonNull final Context context, @NonNull final ContentFilter contentFilter) {
final ArrayMap<String, String> map = new ArrayMap<>(4);

// API Key
Expand All @@ -110,6 +123,7 @@ public static Map<String, String> getServiceIds(@NonNull final Context context)
* 2. `aaid`, Android Advertise Id, is also used in case "keyboardid" or "anon_id" mutates
* 3. `locale` is used to deliver curated language/regional specific contents to users
* 4. `screen_density` is used to optimize the content size to the device
* 5. 'contentfilter' is used to specify the content safety filter level
*/
final String id = AbstractSessionUtils.getAnonId(context);
map.put(id.length() <= 20 ? "keyboardid" : "anon_id", id);
Expand All @@ -119,6 +133,7 @@ public static Map<String, String> getServiceIds(@NonNull final Context context)
map.put("aaid", AbstractSessionUtils.getAndroidAdvertiseId(context));
map.put("locale", AbstractLocaleUtils.getCurrentLocaleName(context));
map.put("screen_density", ScreenDensity.get(context));
map.put("contentfilter", contentFilter.name());
return map;
}

Expand Down