-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AdMob): native ads according to IAB specs #347
Make test for parsing NativeAd.
- Loading branch information
1 parent
f88a158
commit ca22e22
Showing
6 changed files
with
403 additions
and
64 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeTitle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.