Skip to content

Commit

Permalink
Merge pull request googleads#17 from msiejak:master
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 374698822
  • Loading branch information
ericleich committed Jun 8, 2021
2 parents 26bb2a1 + 819c781 commit 45b587c
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 204 deletions.
20 changes: 10 additions & 10 deletions nativetemplates/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 30

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
targetSdkVersion 30
versionCode 2
versionName "1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -30,10 +30,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'com.google.android.gms:play-services-ads:18.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.gms:play-services-ads:20.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.google.android.gms.ads.formats.MediaView;
import com.google.android.gms.ads.formats.NativeAd.Image;
import com.google.android.gms.ads.formats.UnifiedNativeAd;
import com.google.android.gms.ads.formats.UnifiedNativeAdView;
import com.google.android.gms.ads.nativead.MediaView;
import com.google.android.gms.ads.nativead.NativeAd;
import com.google.android.gms.ads.nativead.NativeAdView;

/** Base class for a template view. * */
/**
* Base class for a template view. *
*/
public class TemplateView extends FrameLayout {

private int templateType;
private NativeTemplateStyle styles;
private UnifiedNativeAd nativeAd;
private UnifiedNativeAdView nativeAdView;
private NativeAd nativeAd;
private NativeAdView nativeAdView;

private TextView primaryView;
private TextView secondaryView;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void setStyles(NativeTemplateStyle styles) {
this.applyStyles();
}

public UnifiedNativeAdView getNativeAdView() {
public NativeAdView getNativeAdView() {
return nativeAdView;
}

Expand Down Expand Up @@ -181,13 +182,13 @@ private void applyStyles() {
requestLayout();
}

private boolean adHasOnlyStore(UnifiedNativeAd nativeAd) {
private boolean adHasOnlyStore(NativeAd nativeAd) {
String store = nativeAd.getStore();
String advertiser = nativeAd.getAdvertiser();
return !TextUtils.isEmpty(store) && TextUtils.isEmpty(advertiser);
}

public void setNativeAd(UnifiedNativeAd nativeAd) {
public void setNativeAd(NativeAd nativeAd) {
this.nativeAd = nativeAd;

String store = nativeAd.getStore();
Expand All @@ -196,7 +197,7 @@ public void setNativeAd(UnifiedNativeAd nativeAd) {
String body = nativeAd.getBody();
String cta = nativeAd.getCallToAction();
Double starRating = nativeAd.getStarRating();
Image icon = nativeAd.getIcon();
NativeAd.Image icon = nativeAd.getIcon();

String secondaryText;

Expand All @@ -221,7 +222,8 @@ public void setNativeAd(UnifiedNativeAd nativeAd) {
if (starRating != null && starRating > 0) {
secondaryView.setVisibility(GONE);
ratingBar.setVisibility(VISIBLE);
ratingBar.setMax(5);
ratingBar.setRating(starRating.floatValue());

nativeAdView.setStarRatingView(ratingBar);
} else {
secondaryView.setText(secondaryText);
Expand Down Expand Up @@ -282,7 +284,7 @@ private void initView(Context context, AttributeSet attributeSet) {
@Override
public void onFinishInflate() {
super.onFinishInflate();
nativeAdView = (UnifiedNativeAdView) findViewById(R.id.native_ad_view);
nativeAdView = (NativeAdView) findViewById(R.id.native_ad_view);
primaryView = (TextView) findViewById(R.id.primary);
secondaryView = (TextView) findViewById(R.id.secondary);
tertiaryView = (TextView) findViewById(R.id.body);
Expand Down
Loading

0 comments on commit 45b587c

Please sign in to comment.