From 3fa27cffbf7875bf7efcbced5e5ce64ba0703b1e Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Sat, 18 Apr 2020 16:21:14 +0500 Subject: [PATCH] add try-catch to handle exceptions --- .../rnadmob/nativeads/ReactNativeView.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/ReactNativeView.java b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/ReactNativeView.java index 84ca7c1d..5afecf3e 100644 --- a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/ReactNativeView.java +++ b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/ReactNativeView.java @@ -92,6 +92,10 @@ public ReactNativeView(Context context) { } private void createNativeAd(Context context) { + try { + + + if (unifiedNativeAdView != null) { unifiedNativeAdView.destroy(); removeAllViews(); @@ -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); @@ -166,6 +178,10 @@ private void initViews() { unifiedNativeAdView.setBodyView(tagLineWrapper); } + } catch (Exception e) { + + } + } @@ -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 @@ -273,6 +292,11 @@ public void onAdLeftApplication() { adLoader.loadAd(new AdRequest.Builder().build()); + + } catch (Exception e) { + + } + } @@ -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) { @@ -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(); @@ -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) { @@ -585,6 +624,9 @@ public void setAdvertiserTextColor(@NonNull int color) { public void setRatingColor(int color) { + try { + + if (unifiedNativeAdView != null) { if (ratingBar != null) { @@ -595,6 +637,9 @@ public void setRatingColor(int color) { } } + } catch (Exception e) { + + } } public void setBgColor(int color) {