Skip to content

Commit

Permalink
add try-catch to handle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed Apr 18, 2020
1 parent f4402d5 commit 3fa27cf
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public ReactNativeView(Context context) {
}

private void createNativeAd(Context context) {
try {



if (unifiedNativeAdView != null) {
unifiedNativeAdView.destroy();
removeAllViews();
Expand All @@ -111,9 +115,17 @@ private void createNativeAd(Context context) {
View viewRoot = layoutInflater.inflate(template, this, true);
unifiedNativeAdView = (UnifiedNativeAdView) viewRoot.findViewById(R.id.native_ad_view);

} catch (Exception e) {

}

}

private void initViews() {

try {


if (unifiedNativeAdView == null || unifiedNativeAd == null) return;

mediaContainer = (LinearLayout) unifiedNativeAdView.findViewById(R.id.ad_media_container);
Expand Down Expand Up @@ -166,6 +178,10 @@ private void initViews() {
unifiedNativeAdView.setBodyView(tagLineWrapper);
}

} catch (Exception e) {

}


}

Expand All @@ -178,6 +194,9 @@ public void requestLayout() {

private void refreshAd() {

try {


AdLoader.Builder builder = new AdLoader.Builder(getContext(), admobAdUnitId);
builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
@Override
Expand Down Expand Up @@ -273,6 +292,11 @@ public void onAdLeftApplication() {

adLoader.loadAd(new AdRequest.Builder().build());


} catch (Exception e) {

}

}


Expand Down Expand Up @@ -455,6 +479,10 @@ protected void onAttachedToWindow() {
public void setBackgroundStyle(@Nullable String backgroundColor, @Nullable String borderColor, @Nullable int borderWidth, @Nullable int borderRadius) {
if (unifiedNativeAdView == null) return;


try {


backroundDrawable = new GradientDrawable();

if (backgroundColor != null) {
Expand All @@ -479,12 +507,19 @@ public void setBackgroundStyle(@Nullable String backgroundColor, @Nullable Strin
}

findViewById(R.id.native_ad_view).setBackground(backroundDrawable);

} catch (Exception e ){

}
}


public void setButtonStyle(@Nullable String textColor, @Nullable String backgroundColor, @Nullable String borderColor, @Nullable int borderWidth, @Nullable int borderRadius) {
if (unifiedNativeAdView == null) return;

try {


gradientDrawableA = new GradientDrawable();
gradientDrawableB = new GradientDrawable();

Expand Down Expand Up @@ -540,6 +575,10 @@ public void setButtonStyle(@Nullable String textColor, @Nullable String backgrou
}
button.setBackground(gradientDrawableA);
text.setBackground(gradientDrawableB);

} catch (Exception e ){

}
}

private void sendEvent(String name, @Nullable WritableMap event) {
Expand Down Expand Up @@ -585,6 +624,9 @@ public void setAdvertiserTextColor(@NonNull int color) {


public void setRatingColor(int color) {
try {


if (unifiedNativeAdView != null) {
if (ratingBar != null) {

Expand All @@ -595,6 +637,9 @@ public void setRatingColor(int color) {

}
}
} catch (Exception e) {

}
}

public void setBgColor(int color) {
Expand Down

0 comments on commit 3fa27cf

Please sign in to comment.