1010import android .view .Menu ;
1111import android .view .SubMenu ;
1212import android .view .View ;
13+ import android .view .ViewGroup ;
1314
1415import androidx .annotation .Nullable ;
1516import androidx .appcompat .app .AlertDialog ;
2122import androidx .cardview .widget .CardView ;
2223import androidx .viewpager .widget .ViewPager ;
2324
25+ import com .google .android .gms .ads .AdListener ;
2426import com .google .android .gms .ads .AdRequest ;
2527import com .google .android .gms .ads .AdView ;
28+ import com .google .android .gms .ads .LoadAdError ;
2629import com .smartpack .kernelprofiler .fragments .KPFragment ;
2730import com .smartpack .kernelprofiler .utils .CreateConfigActivity ;
2831import com .smartpack .kernelprofiler .utils .CreateProfileActivity ;
@@ -44,6 +47,7 @@ public class MainActivity extends AppCompatActivity {
4447 private boolean mExit ;
4548 private Handler mHandler = new Handler ();
4649 private ViewPager mViewPager ;
50+ private ViewGroup .MarginLayoutParams mLayoutParams ;
4751
4852 private AppCompatImageButton mBack ;
4953 private AppCompatImageView mAppIcon ;
@@ -94,15 +98,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
9498 Utils .launchUrl ("https://github.com/sunilpaulmathew" , this );
9599 });
96100
97- if (Utils .isNotDonated (this )) {
98- AdView mAdView = findViewById (R .id .adView );
99- AdRequest adRequest = new AdRequest .Builder ()
100- .build ();
101- mAdView .loadAd (adRequest );
102- }
103-
104101 mSettings = findViewById (R .id .settings_menu );
105102 mViewPager = findViewById (R .id .viewPagerID );
103+ mLayoutParams = (ViewGroup .MarginLayoutParams ) mViewPager .getLayoutParams ();
104+ AdView mAdView = findViewById (R .id .adView );
106105 AppCompatTextView textView = findViewById (R .id .unsupported_Text );
107106 AppCompatImageView helpIcon = findViewById (R .id .help_Image );
108107 AppCompatTextView copyRightText = findViewById (R .id .copyright_Text );
@@ -139,6 +138,26 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
139138 return ;
140139 }
141140
141+ if (Utils .isNotDonated (this )) {
142+ mAdView .setAdListener (new AdListener () {
143+ @ Override
144+ public void onAdLoaded () {
145+ copyRightText .setVisibility (View .GONE );
146+ }
147+ @ Override
148+ public void onAdFailedToLoad (LoadAdError adError ) {
149+ mAdView .setVisibility (View .GONE );
150+ mLayoutParams .bottomMargin = 0 ;
151+ }
152+ });
153+ AdRequest adRequest = new AdRequest .Builder ()
154+ .build ();
155+ mAdView .loadAd (adRequest );
156+ } else {
157+ mAdView .setVisibility (View .GONE );
158+ mLayoutParams .bottomMargin = 0 ;
159+ }
160+
142161 PagerAdapter adapter = new PagerAdapter (getSupportFragmentManager ());
143162 adapter .AddFragment (new KPFragment (), getString (R .string .app_name ));
144163
0 commit comments