Skip to content

Commit

Permalink
AdBanner: Turn offline ads to github cached ads
Browse files Browse the repository at this point in the history
  • Loading branch information
Grarak committed Aug 9, 2016
1 parent 34e80d2 commit ac84ad2
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 86 deletions.
12 changes: 12 additions & 0 deletions ads/ads.json
@@ -0,0 +1,12 @@
[
{
"name": "m5_kernel",
"banner": "https://raw.githubusercontent.com/Grarak/KernelAdiutor/master/ads/banner_m5_kernel.png",
"link": "http://forum.xda-developers.com/z3/orig-development/kernel-m5-kernel-t3045319"
},
{
"name": "om5z_kernel",
"banner": "https://raw.githubusercontent.com/Grarak/KernelAdiutor/master/ads/banner_om5z_kernel.png",
"link": "http://forum.xda-developers.com/xperia-z5/orig-development/kernel-om5z-kernel-t3405660"
}
]
File renamed without changes
File renamed without changes
Expand Up @@ -74,6 +74,7 @@
import com.grarak.kerneladiutor.utils.Prefs;
import com.grarak.kerneladiutor.utils.Utils;
import com.grarak.kerneladiutor.utils.ViewUtils;
import com.grarak.kerneladiutor.utils.WebpageReader;
import com.grarak.kerneladiutor.utils.kernel.cpuhotplug.Hotplug;
import com.grarak.kerneladiutor.utils.kernel.cpuvoltage.Voltage;
import com.grarak.kerneladiutor.utils.kernel.entropy.Entropy;
Expand All @@ -89,6 +90,7 @@
import com.grarak.kerneladiutor.utils.root.RootUtils;
import com.grarak.kerneladiutor.utils.tools.Backup;
import com.grarak.kerneladiutor.utils.tools.SupportedDownloads;
import com.grarak.kerneladiutor.views.AdBanner;
import com.startapp.android.publish.StartAppAd;

import java.util.HashMap;
Expand Down Expand Up @@ -179,6 +181,9 @@ public class NavigationActivity extends BaseActivity
private boolean mShowPirateDialog = true;
private StartAppAd mStartAppAd;

private WebpageReader mAdsFetcher;
private boolean mFetchingAds;

@Override
protected boolean setStatusBarColor() {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M;
Expand Down Expand Up @@ -209,6 +214,8 @@ protected void onCreate(Bundle savedInstanceState) {

if (savedInstanceState != null) {
mSelection = savedInstanceState.getInt("selection");
mShowPirateDialog = savedInstanceState.getBoolean("pirate");
mFetchingAds = savedInstanceState.getBoolean("fetching_ads");
}

if (mSelection == 0 || !sActualFragments.containsKey(mSelection)) {
Expand All @@ -219,9 +226,7 @@ protected void onCreate(Bundle savedInstanceState) {
int result = Prefs.getInt("license", -1, this);
int intentResult = getIntent().getIntExtra("result", -1);
Prefs.saveInt("license", -1, this);
if (savedInstanceState != null) {
mShowPirateDialog = savedInstanceState.getBoolean("pirate");
}

if ((result != intentResult || result == 3) && mShowPirateDialog) {
ViewUtils.dialogBuilder(getString(R.string.pirated), null, new DialogInterface.OnClickListener() {
@Override
Expand All @@ -239,6 +244,27 @@ public void onDismiss(DialogInterface dialog) {
Utils.DONATED = true;
}
}

if (!mFetchingAds && !Utils.DONATED) {
mFetchingAds = true;
mAdsFetcher = new WebpageReader(new WebpageReader.WebpageCallback() {
@Override
public void onCallback(String raw, CharSequence html) {
if (raw == null || raw.isEmpty()) return;
AdBanner.GHAds ghAds = new AdBanner.GHAds(raw);
if (ghAds.readable()) {
ghAds.cache(NavigationActivity.this);
for (int id : sActualFragments.keySet()) {
Fragment fragment = sActualFragments.get(id);
if (fragment instanceof RecyclerViewFragment) {
((RecyclerViewFragment) fragment).ghAdReady();
}
}
}
}
});
mAdsFetcher.execute(AdBanner.ADS_FETCH);
}
}

private int firstTab() {
Expand Down Expand Up @@ -311,13 +337,17 @@ public void finish() {
}
fragmentTransaction.commit();
RootUtils.closeSU();
if (mAdsFetcher != null) {
mAdsFetcher.cancel();
}
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("selection", mSelection);
outState.putBoolean("pirate", mShowPirateDialog);
outState.putBoolean("fetching_ads", mFetchingAds);
}

@Override
Expand Down
Expand Up @@ -616,6 +616,12 @@ public boolean onBackPressed() {
return false;
}

public void ghAdReady() {
if (mAdView != null) {
mAdView.ghReady();
}
}

@Override
public void onResume() {
super.onResume();
Expand Down
Expand Up @@ -73,7 +73,7 @@
public class Utils {

private static final String TAG = Utils.class.getSimpleName();
public static boolean DONATED;
public static boolean DONATED = BuildConfig.DEBUG;
public static boolean DARK_THEME;

private static final Set<CustomTarget> mProtectedFromGarbageCollectorTargets = new HashSet<>();
Expand Down

0 comments on commit ac84ad2

Please sign in to comment.