Skip to content

Commit

Permalink
feat(AdMob): native ads according to IAB specs #347
Browse files Browse the repository at this point in the history
Make test for parsing NativeAd.
  • Loading branch information
ValentinPostindustria committed Feb 3, 2022
1 parent f88a158 commit ca22e22
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.prebid.mobile;

import androidx.annotation.NonNull;

public class NativeData {

private final int typeNumber;
private final String value;

public NativeData(int typeNumber, @NonNull String value) {
this.typeNumber = typeNumber;
this.value = value;
}

public NativeData(Type type, @NonNull String value) {
if (type == Type.CUSTOM) {
throw new IllegalArgumentException("For CUSTOM type use constructor with typeNumber parameter.");
}
this.typeNumber = Type.getNumberFromType(type);
this.value = value;
}

public int getTypeNumber() {
return typeNumber;
}

@NonNull
public String getValue() {
return value;
}

@NonNull
public Type getType() {
return Type.getFromTypeNumber(typeNumber);
}

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
NativeData that = (NativeData) object;
return typeNumber == that.typeNumber && value.equals(that.value);
}

enum Type {
SPONSORED_BY,
DESCRIPTION,
CALL_TO_ACTION,
CUSTOM;

public static Type getFromTypeNumber(int typeNumber) {
switch (typeNumber) {
case 1:
return SPONSORED_BY;
case 2:
return DESCRIPTION;
case 12:
return CALL_TO_ACTION;
default:
return CUSTOM;
}
}

public static int getNumberFromType(Type type) {
switch (type) {
case SPONSORED_BY:
return 1;
case DESCRIPTION:
return 2;
case CALL_TO_ACTION:
return 12;
default:
return 0;
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.prebid.mobile;

import androidx.annotation.NonNull;

public class NativeImage {

private final int typeNumber;
private final String url;

public NativeImage(int typeNumber, @NonNull String url) {
this.typeNumber = typeNumber;
this.url = url;
}

public NativeImage(@NonNull Type type, @NonNull String url) {
if (type == Type.CUSTOM) {
throw new IllegalArgumentException("For CUSTOM type use constructor with typeNumber parameter.");
}
this.typeNumber = Type.getNumberFromType(type);
this.url = url;
}

public int getTypeNumber() {
return typeNumber;
}

@NonNull
public String getUrl() {
return url;
}

@NonNull
public Type getType() {
return Type.getTypeFromNumber(typeNumber);
}

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
NativeImage that = (NativeImage) object;
return typeNumber == that.typeNumber && url.equals(that.url);
}

enum Type {
ICON,
MAIN_IMAGE,
CUSTOM;

public static Type getTypeFromNumber(int typeNumber) {
switch (typeNumber) {
case 1:
return Type.ICON;
case 3:
return Type.MAIN_IMAGE;
default:
return Type.CUSTOM;
}
}

public static int getNumberFromType(Type type) {
switch (type) {
case ICON:
return 1;
case MAIN_IMAGE:
return 3;
default:
return 0;
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.prebid.mobile;

import androidx.annotation.NonNull;

public class NativeTitle {

private final String text;

public NativeTitle(@NonNull String text) {
this.text = text;
}

@NonNull
public String getText() {
return text;
}

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
NativeTitle that = (NativeTitle) object;
return text.equals(that.text);
}

}
Loading

0 comments on commit ca22e22

Please sign in to comment.