diff --git a/zhuike/build.gradle b/zhuike/build.gradle index 2b8a564..b580727 100644 --- a/zhuike/build.gradle +++ b/zhuike/build.gradle @@ -62,7 +62,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' // versionCode 1 // versionName "v1.0" - applicationVariants.all { variant -> + /*applicationVariants.all { variant -> variant.outputs.all { output -> def outFile = output.outputFile if (outFile != null && outFile.name.endsWith(".apk")) { @@ -72,12 +72,12 @@ android { } } - } + }*/ signingConfig signingConfigs.releaseConfig } } //渠道 - productFlavors { + /* productFlavors { // googleplay {} google { applicationId "com.zhushou.yueshu" @@ -178,7 +178,7 @@ android { flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } - } + }*/ android { lintOptions { abortOnError false @@ -247,5 +247,5 @@ dependencies { implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16' implementation(name: 'open_ad_sdk', ext: 'aar') implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.6' - // implementation 'com.google.android.gms:play-services-ads:17.2.1' + implementation 'com.google.android.gms:play-services-ads:17.2.1' } diff --git a/zhuike/proguard-rules.pro b/zhuike/proguard-rules.pro index 7900d77..a60eb3f 100644 --- a/zhuike/proguard-rules.pro +++ b/zhuike/proguard-rules.pro @@ -282,4 +282,4 @@ -keep class com.ss.sys.ces.* {*;} #GOOGLE MOBAD --keep com.google.android.gms.ads.** { *; } +#-keep com.google.android.gms.ads.** { *; } diff --git a/zhuike/src/main/AndroidManifest.xml b/zhuike/src/main/AndroidManifest.xml index 5601e18..66a28a3 100644 --- a/zhuike/src/main/AndroidManifest.xml +++ b/zhuike/src/main/AndroidManifest.xml @@ -197,13 +197,13 @@ - - + + - + android:value="${MOBAPPID}"/> \ No newline at end of file diff --git a/zhuike/src/main/java/com/novelbook/android/AD/SplashActivity.java b/zhuike/src/main/java/com/novelbook/android/AD/SplashActivity.java index a0799c9..b3cf399 100644 --- a/zhuike/src/main/java/com/novelbook/android/AD/SplashActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/AD/SplashActivity.java @@ -14,29 +14,34 @@ import android.os.Message; import android.provider.Settings; import android.support.annotation.MainThread; import android.support.annotation.Nullable; -import android.text.TextUtils; + import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; -import android.widget.FrameLayout; + import android.widget.TextView; import android.widget.Toast; import com.bytedance.sdk.openadsdk.AdSlot; import com.bytedance.sdk.openadsdk.TTAdNative; import com.bytedance.sdk.openadsdk.TTSplashAd; +import com.google.android.gms.ads.AdListener; +import com.google.android.gms.ads.AdRequest; +import com.google.android.gms.ads.InterstitialAd; +import com.google.android.gms.ads.MobileAds; import com.novelbook.android.AD.toutiao.TTAdManagerHolder; import com.novelbook.android.AD.toutiao.WeakHandler; -import com.novelbook.android.BuildConfig; + import com.novelbook.android.Main2Activity; + import com.novelbook.android.R; import com.novelbook.android.utils.Constants; import com.qq.e.ads.splash.SplashAD; import com.qq.e.ads.splash.SplashADListener; import com.qq.e.comm.util.AdError; -import org.litepal.util.Const; + import java.util.ArrayList; import java.util.HashMap; @@ -54,10 +59,14 @@ import static com.novelbook.android.bean.AdSetting.getAppID; */ public class SplashActivity extends Activity implements WeakHandler.IHandler, SplashADListener { private static final String TAG = SplashActivity.class.getSimpleName(); - + @Nullable @BindView(R.id.splash_container) ViewGroup mSplashContainer; + @Nullable + @BindView(R.id.textTile) + TextView tvTitle; + //--------tencent---> private SplashAD splashAD; @@ -103,9 +112,10 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp //-toutiao---<--- + //---admob---> + private InterstitialAd mInterstitialAd; + - @BindView(R.id.textTile) - TextView tvTitle; @SuppressWarnings("RedundantCast") @Override @@ -125,13 +135,21 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp rid = R.layout.ad_toutiao_activity_splash; splashSource=Constants.AD_TOUTIAO; } + else{ + goToMainActivity();return; + } }else{ if (Constants.AD_SETTING.getSplash2().getSource() == Constants.AD_TENCENT_QQ) { rid = R.layout.ad_qq_activity_splash; } else if (Constants.AD_SETTING.getSplash2().getSource() == Constants.AD_TOUTIAO) { // rid = R.layout.ad_toutiao_activity_splash; - goToMainActivity(); + // goToMainActivity(); return; + }else if (Constants.AD_SETTING.getSplash2() .getSource() == Constants.AD_MOB) { + // goToMainActivity(); + // return; + rid = R.layout.activity_blank; + splashSource=Constants.AD_MOB; } } @@ -152,6 +170,7 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY // | View.SYSTEM_UI_FLAG_IMMERSIVE ); + if(tvTitle!=null) tvTitle.setText(R.string.app_name); //加载开屏广告 if(splashSource == Constants.AD_TOUTIAO ) { @@ -171,6 +190,14 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp // 如果是Android6.0以下的机器,默认在安装时获得了所有权限,可以直接调用SDK fetchSplashAD(this, mSplashContainer, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0); } + }else if(splashSource == Constants.AD_MOB ){ + getAdMob(); + /* if (Build.VERSION.SDK_INT >= 23) { + checkAndRequestPermissionAdmob(); + } else { + // 如果是Android6.0以下的机器,默认在安装时获得了所有权限,可以直接调用SDK + getAdMob(); + }*/ } } /** @@ -352,10 +379,12 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp if (!(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) { lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } - - if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { - lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION); + if (!(checkSelfPermission(Manifest.permission.REQUEST_INSTALL_PACKAGES) == PackageManager.PERMISSION_GRANTED)) { + lackedPermission.add(Manifest.permission.REQUEST_INSTALL_PACKAGES); } + /*if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { + lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION); + }*/ // 权限都已经有了,那么直接调用SDK if (lackedPermission.size() == 0) { @@ -496,4 +525,85 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp } //----qq ad end <--- + + void getAdMob(){ + MobileAds.initialize(this,"ca-app-pub-3940256099942544~3347511713"); + + mInterstitialAd = new InterstitialAd(this); + mInterstitialAd.setAdListener(new AdListener() { + @Override + public void onAdLoaded() { + // Code to be executed when an ad finishes loading. + Log.d(TAG, "onAdLoaded: "); + SplashAdManager.setSplashTime(); + mInterstitialAd.show(); + } + + @Override + public void onAdFailedToLoad(int errorCode) { + // Code to be executed when an ad request fails. + Log.d(TAG, "onAdFailedToLoad: "); + goToMainActivity(); + } + + @Override + public void onAdOpened() { + // Code to be executed when the ad is displayed. + Log.d(TAG, "onAdOpened: "); + } + + @Override + public void onAdClicked() { + // Code to be executed when the user clicks on an ad. + Log.d(TAG, "onAdClicked: "); + } + + @Override + public void onAdLeftApplication() { + // Code to be executed when the user has left the app. + Log.d(TAG, "onAdLeftApplication: "); + } + + @Override + public void onAdClosed() { + // Code to be executed when the interstitial ad is closed. + Log.d(TAG, "onAdClosed: "); + goToMainActivity(); + } + }); + mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); + + mInterstitialAd.loadAd(new AdRequest.Builder().build()); + + + } + + @TargetApi(Build.VERSION_CODES.M) + private void checkAndRequestPermissionAdmob() { + List lackedPermission = new ArrayList(); + if (!(checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)) { + lackedPermission.add(Manifest.permission.READ_PHONE_STATE); + } + + if (!(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) { + lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); + } + if (!(checkSelfPermission(Manifest.permission.REQUEST_INSTALL_PACKAGES) == PackageManager.PERMISSION_GRANTED)) { + lackedPermission.add(Manifest.permission.REQUEST_INSTALL_PACKAGES); + } + /*if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { + lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION); + }*/ + + // 权限都已经有了,那么直接调用SDK + if (lackedPermission.size() == 0) { + getAdMob(); + } else { + // 请求所缺少的权限,在onRequestPermissionsResult中再看是否获得权限,如果获得权限就可以调用SDK,否则不要调用SDK。 + String[] requestPermissions = new String[lackedPermission.size()]; + lackedPermission.toArray(requestPermissions); + requestPermissions(requestPermissions, 1024); + } + } + } diff --git a/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java b/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java index fc8f28e..0672377 100644 --- a/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java +++ b/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java @@ -8,9 +8,16 @@ import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; import android.util.Log; +import android.view.View; +import com.google.android.gms.ads.AdListener; +import com.google.android.gms.ads.AdRequest; +import com.google.android.gms.ads.InterstitialAd; +import com.google.android.gms.ads.MobileAds; import com.novelbook.android.Main2Activity; +import com.novelbook.android.MyApp; +import com.novelbook.android.bean.AdSetting; import com.novelbook.android.utils.Constants; import java.util.Date; @@ -19,12 +26,13 @@ import static com.novelbook.android.utils.Constants.AD_TENCENT_QQ; import static com.novelbook.android.utils.Constants.AD_TOUTIAO; public class SplashAdManager implements Application.ActivityLifecycleCallbacks, ComponentCallbacks2 { + final static String TAG= SplashAdManager.class.getSimpleName(); private boolean mIsBackground; private static long lastAd =0; //private static long interVal = 5000;//Constants.AD_SPLASH_INVTERVAL; private static int pages =0; - + private static InterstitialAd mInterstitialAd ; /****** * 使用方式:在Application中直接构造即可 * @param application @@ -49,6 +57,10 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks, @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { + if(Constants.AD_SETTING.getSplash2() .getSource() == Constants.AD_MOB) { + getAdMob(activity); + } + Log.d(TAG, "onActivityCreated:mInterstitialAd initialized "); if(activity instanceof Main2Activity){ //showAd(activity); @@ -117,16 +129,29 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks, static void showSplashAd(Activity activity){ if(canShowAd()) { lastAd = new Date().getTime(); + + if(Constants.AD_SETTING.getSplash2() .getSource() == Constants.AD_MOB){ + + Log.d(TAG, "showSplashAd:mInterstitialAd.isLoaded() " +mInterstitialAd.isLoaded()); + if(mInterstitialAd!=null && mInterstitialAd.isLoaded()) { + SplashAdManager.setSplashTime(); + activity.getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar + | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + // | View.SYSTEM_UI_FLAG_IMMERSIVE + ); + mInterstitialAd.show(); + mInterstitialAd.loadAd(new AdRequest.Builder().build()); + } + return; + } + Intent intent = new Intent(activity, SplashActivity.class); intent.putExtra(SplashActivity.EXTR_LUNCHER, false); - - - /* if(Constants.AD_SPLASH_SOURCE ==AD_TENCENT_QQ) { - intent = new Intent(activity, com.novelbook.android.AD.qq.SplashActivity.class); - }else if(Constants.AD_SPLASH_SOURCE ==AD_TOUTIAO){ - intent = new Intent(activity, SplashActivity.class); - intent.putExtra(SplashActivity.EXTR_LUNCHER, false); - }*/ activity.startActivity(intent); } } @@ -135,7 +160,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks, return false; } long in = new Date().getTime() -lastAd; - int interVal = Constants.AD_SETTING.getSplash2().getInterval4Display()*1000; + int interVal = Constants.AD_SETTING.getSplash2().getInterval4Display()*1000; Log.d("zzr", "canShowAd: interval is, " +in + ", canshow? "+ (in >interVal)); return in >interVal; } @@ -145,10 +170,66 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks, } public static void plusPage(Activity activity){ pages++; - if(pages >Constants.AD_SETTING.getSplash2().getPageCount4Display()){ + int pcnt =Constants.AD_SETTING.getSplash2().getPageCount4Display();; + + if(pages > pcnt){ clearPages(); showSplashAd(activity); } } + + + void getAdMob(Activity activity){ + mInterstitialAd = new InterstitialAd(activity); + Log.d(TAG, "getAdMob: mIntersititiaAd is null ?" + (mInterstitialAd==null)); + if(mInterstitialAd!=null) + mInterstitialAd.setAdListener(new AdListener() { + + @Override + public void onAdLoaded() { + // Code to be executed when an ad finishes loading. + Log.d(TAG, "onAdLoaded: "); + + } + + @Override + public void onAdFailedToLoad(int errorCode) { + // Code to be executed when an ad request fails. + Log.d(TAG, "onAdFailedToLoad: "); + + } + + @Override + public void onAdOpened() { + // Code to be executed when the ad is displayed. + Log.d(TAG, "onAdOpened: "); + } + + @Override + public void onAdClicked() { + // Code to be executed when the user clicks on an ad. + Log.d(TAG, "onAdClicked: "); + } + + @Override + public void onAdLeftApplication() { + // Code to be executed when the user has left the app. + Log.d(TAG, "onAdLeftApplication: "); + } + + @Override + public void onAdClosed() { + // Code to be executed when the interstitial ad is closed. + Log.d(TAG, "onAdClosed: "); + + } + }); + + + mInterstitialAd.setAdUnitId( Constants.AD_SETTING.getSplash2().getSlotId(Constants.AD_MOB)); + mInterstitialAd.loadAd(new AdRequest.Builder().build()); + + } + } diff --git a/zhuike/src/main/java/com/novelbook/android/Activity_base.java b/zhuike/src/main/java/com/novelbook/android/Activity_base.java index 7b24a35..0a10cb7 100644 --- a/zhuike/src/main/java/com/novelbook/android/Activity_base.java +++ b/zhuike/src/main/java/com/novelbook/android/Activity_base.java @@ -42,10 +42,10 @@ import com.bytedance.sdk.openadsdk.TTImage; import com.bytedance.sdk.openadsdk.TTInteractionAd; import com.bytedance.sdk.openadsdk.TTNativeAd; import com.google.android.gms.ads.AdListener; -/*import com.google.android.gms.ads.AdRequest; +import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdSize; import com.google.android.gms.ads.AdView; -import com.google.android.gms.ads.MobileAds;*/ +import com.google.android.gms.ads.MobileAds; import com.google.gson.Gson; import com.novelbook.android.AD.toutiao.TTAdManagerHolder; @@ -423,6 +423,8 @@ public abstract class Activity_base extends AppCompatActivity implements Native loadNativeBanner_qq(-1, 388); }else if(Constants.AD_SETTING.getChapterContentBanner().getSource() == AD_TOUTIAO) { loadNativeBanner_toutiao(mBannerContainer ,690,388); + }else if(Constants.AD_SETTING.getChapterContentBanner().getSource() == AD_MOB) { + loadBanner_Mob(mBannerContainer, 699,388); } } @@ -446,7 +448,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native loadBanner_toutiao(mBannerContainer, width,height); }else if(Constants.AD_SETTING.getChapterBanner().getSource()== AD_MOB){ - //loadBanner_Mob(mBannerContainer, width,height); + loadBanner_Mob(mBannerContainer, width,height); } } @@ -454,7 +456,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native void initializeAd(){ if(Constants.AD_SETTING.isShowAdsense()) { initAD_TouTiao(); - initialMobileAd(); + // initialMobileAd(); } } @@ -1332,21 +1334,21 @@ public abstract class Activity_base extends AppCompatActivity implements Native //------------------------AD Google MobileAds--------------- // MobileAds.initialize(this, "YOUR_ADMOB_APP_ID"); - /* boolean isMobleAdInitialize =false; - AdView mAdView; + boolean isMobleAdInitialize =false; + //AdView mAdView; void initialMobileAd(){ // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 String appID = AdSetting.getAppID(Constants.AD_MOB); - appID ="ca-app-pub-3940256099942544~3347511713"; + appID =AdSetting.getAppID(Constants.AD_MOB); MobileAds.initialize(this, appID); isMobleAdInitialize =true; Log.d(TAG, "onAdLoaded: initialMobileAd "); } AdView getAdView(){ - if(mAdView ==null){ - mAdView = new AdView(this); - mAdView.setAdSize(AdSize.BANNER); - String codeId = "ca-app-pub-3940256099942544/6300978111";//Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_MOB) ; + // if(mAdView ==null){ + AdView mAdView = new AdView(this); + + String codeId = Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_MOB);//Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_MOB) ; mAdView.setAdUnitId(codeId); mAdView.setAdListener(new AdListener() { @Override @@ -1359,7 +1361,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native @Override public void onAdFailedToLoad(int errorCode) { // Code to be executed when an ad request fails. - Log.d(TAG, "onAdLoaded: Code to be executed when an ad request fails."); + Log.d(TAG, "onAdLoaded: Code to be executed when an ad request fails." +errorCode); } @Override @@ -1388,7 +1390,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native Log.d(TAG, "onAdLoaded: Code to be executed when the user is about to return to the app after tapping on an ad."); } }); - } + // } return mAdView; } private void loadBanner_Mob(FrameLayout bannerContainer, int width, int height) { @@ -1397,16 +1399,20 @@ public abstract class Activity_base extends AppCompatActivity implements Native if(!isMobleAdInitialize){ initialMobileAd(); } - Log.d(TAG, "onAdLoaded: 2 loadBanner_Mob "); - - + Log.d(TAG, "onAdLoaded: 2 loadBanner_Mob height:" +height); + AdSize adsize = new AdSize(width,height); + AdView adView = getAdView(); + if(height<250){ + adView.setAdSize(AdSize.BANNER); + }else { + adView.setAdSize(AdSize.MEDIUM_RECTANGLE); + } AdRequest adRequest = new AdRequest.Builder().build(); - getAdView().loadAd(adRequest); + adView.loadAd(adRequest); bannerContainer.removeAllViews(); - bannerContainer.addView( getAdView()); - - }*/ + bannerContainer.addView( adView); + } @Override protected void onResume() { diff --git a/zhuike/src/main/java/com/novelbook/android/MyApp.java b/zhuike/src/main/java/com/novelbook/android/MyApp.java index 1bff797..037c94f 100644 --- a/zhuike/src/main/java/com/novelbook/android/MyApp.java +++ b/zhuike/src/main/java/com/novelbook/android/MyApp.java @@ -9,6 +9,7 @@ import android.util.Log; import com.bytedance.sdk.openadsdk.TTAdConfig; import com.bytedance.sdk.openadsdk.TTAdConstant; import com.bytedance.sdk.openadsdk.TTAdSdk; +import com.google.android.gms.ads.MobileAds; import com.google.gson.Gson; import com.novelbook.android.AD.toutiao.TTAdManagerHolder; import com.novelbook.android.bean.AdSetting; @@ -67,10 +68,17 @@ public class MyApp extends Application { } private void initAD(){ initAD_ChuanShanJia(); + initAD_AdMob(); } private void initAD_ChuanShanJia(){ TTAdManagerHolder.init(applicationContext); } + private void initAD_AdMob(){ + if(AdSetting.getAppID(Constants.AD_MOB).length()>0){ + MobileAds.initialize(MyApp.applicationContext, AdSetting.getAppID(Constants.AD_MOB)); + } + + } public boolean exit() { diff --git a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java index 14afd3c..eee488e 100644 --- a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java @@ -545,8 +545,10 @@ public class ReadActivity extends Activity_base implements AdInterface { }*/ hideReadSetting(); - pageFactory.updateTime(); - pageFactory.showAd(); + if( pageFactory.isReady()) { + pageFactory.updateTime(); + pageFactory.showAd(); + } } diff --git a/zhuike/src/main/java/com/novelbook/android/bean/AdSetting.java b/zhuike/src/main/java/com/novelbook/android/bean/AdSetting.java index bb73740..cf75e96 100644 --- a/zhuike/src/main/java/com/novelbook/android/bean/AdSetting.java +++ b/zhuike/src/main/java/com/novelbook/android/bean/AdSetting.java @@ -16,7 +16,8 @@ public class AdSetting { private slot fixBanner = new slot(); private slot bigBanner = new slot(); public boolean isShowAdsense() { - return showAdsense && NetUtil.isNetworkConnected(); + // return true; + return showAdsense && NetUtil.isNetworkConnected(); } public void setShowAdsense(boolean showAdsense) { @@ -90,7 +91,8 @@ public class AdSetting { } public boolean isShow() { - return show && NetUtil.isNetworkConnected(); + // return true; + return show && NetUtil.isNetworkConnected(); } public void setShow(boolean show) { @@ -98,8 +100,8 @@ public class AdSetting { } public int getSource() { - return source; - // return 1; + return source; + // return 3 ; } public void setSource(int source) { diff --git a/zhuike/src/main/java/com/novelbook/android/db/Novel.java b/zhuike/src/main/java/com/novelbook/android/db/Novel.java index 0d74c86..1265795 100644 --- a/zhuike/src/main/java/com/novelbook/android/db/Novel.java +++ b/zhuike/src/main/java/com/novelbook/android/db/Novel.java @@ -111,6 +111,7 @@ public class Novel extends LitePalSupport implements Serializable{ } public String getChapterName() { + return chapterName; } @@ -331,12 +332,17 @@ public void testUpdate(){ /* if(lastUpdateTime > nv.lastVisit && lastUpdateTime > nv.lastUpdateTime){ isUpdated =true; }*/ - isUpdated =lastUpdateTime > nv.lastVisit || lastUpdateTime > nv.lastUpdateTime; + isUpdated = lastUpdateTime > nv.lastVisit && lastUpdateTime > nv.lastUpdateTime; Log.d("Novel", String.format("book %s server lastUpdateTime %s, local lastupdatetime %s, local lastvist %s" + - "is updated %s,diff1 %s,diff2 %s" - ,name ,lastUpdateTime,nv.lastUpdateTime,nv.lastVisit,isUpdated, + "is updated %s,diff1 %s,diff2 %s " + ,name ,lastUpdateTime,nv.lastUpdateTime,nv.lastVisit,isUpdated, lastUpdateTime - nv.lastVisit, - lastUpdateTime - nv.lastUpdateTime) ); + lastUpdateTime - nv.lastUpdateTime + + ) ); + isUpdated = isUpdated && !(!TextUtils.isEmpty(chapterName) && !TextUtils.isEmpty(nv.chapterName) && (chapterName.equals(nv.chapterName) || chapterName.equals(nv.lastReadChapt))); + + Log.d("Novel", String.format( " isupdated %s, server lastUpdateTime ,server chaptername %s,chaptername %s,lastreadchapt %s" ,isUpdated,chapterName,nv.chapterName,nv.lastReadChapt ) ); if(!isUpdated){ setToDefault("isUpdated"); diff --git a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java index 4ee7391..e7b2ec6 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java @@ -121,8 +121,23 @@ public class BookUtil { private Novel mNovel; + private void clearBook() { + charPosition.clear(); + this.muluRetryCount=0; + this.downloadStatus = DownloadStatus.notStart; + chaptDownStatus.clear(); + chaptCache.clear(); + fileRetryCnt.clear(); + siteRuleRetryCnt=0; + isChangeSource=false; + mChapters.clear(); + myArray.clear(); + + } public void setNovel(Novel novel) { + clearBook(); this.mNovel = novel; + } public Novel getNovel( ) { return mNovel ; @@ -299,6 +314,9 @@ public class BookUtil { int siteRuleRetryCnt =0; public void getSiteRule() { + getSiteRule(false); + } + public void getSiteRule(boolean isForceRefresh) { mSiteRule = null; if(mSite==null){ return; @@ -334,10 +352,11 @@ public class BookUtil { Log.d(TAG, String.format("目录正则表达式下载完成,开始读取章节信息") ); + int maxAge = isForceRefresh? 0:mNovel.getMaxAge() ; if(mSiteRule.getChapterUrlRegexOnMulu().length>0) { mMuluStatus = MuluStatus.isDownloading; long startTime= new Date().getTime(); - Log.d(TAG,String.format("prepare book loadChapts----start download %s,maxAge %s, 目录 from %s", mNovel.getName() ,mNovel.getMaxAge() ,mSite.getMuluUrl() )); + Log.d(TAG,String.format("prepare book loadChapts----start download %s,maxAge %s, 目录 from %s", mNovel.getName() ,maxAge ,mSite.getMuluUrl() )); new Thread(){ @Override public void run() { @@ -348,7 +367,7 @@ public class BookUtil { try { JSONObject siteJson = new JSONObject(result); - mChapters = NovelParseUtil.getChapters(mSite.getMuluUrl(), siteJson,mSite.getDomain(),mNovel.getMaxAge(),mSiteRule); + mChapters = NovelParseUtil.getChapters(mSite.getMuluUrl(), siteJson,mSite.getDomain(),maxAge,mSiteRule); /* if (mChapters != null){ for (Chapter chapter:mChapters) { @@ -489,17 +508,7 @@ public class BookUtil { } - private void clearBook() { - charPosition.clear(); - this.muluRetryCount=0; - this.downloadStatus = DownloadStatus.notStart; - chaptDownStatus.clear(); - chaptCache.clear(); - fileRetryCnt.clear(); - siteRuleRetryCnt=0; - isChangeSource=false; - } public Site getSite() { return mSite !=null? mSite :new Site(); @@ -787,13 +796,17 @@ public class BookUtil { int muluRetryCount =0; - void readChaptersAsync( ) { + void readChaptersAsync(){ + readChaptersAsync(false); + } + void readChaptersAsync(boolean isForceRefresh ) { if(mSite==null ||mSiteRule ==null){ Log.d(TAG,String.format("prepare book loadChapts failed---- %s ,mSite is null? %s ,mSiteRule ==null ? %s", mNovel.getName() ,mSite==null,mSiteRule ==null )); return; } String url = mSite.getMuluUrl(); - Request request = getTagRequest(url,REUtil.getDomain(url), mNovel.getMaxAge()); + int maxAge= isForceRefresh ?0 : mNovel.getMaxAge(); + Request request = getTagRequest(url,REUtil.getDomain(url),maxAge); mMuluStatus = MuluStatus.isDownloading; long startTime= new Date().getTime(); diff --git a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java index cb1687d..db85ec0 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java @@ -30,6 +30,7 @@ import android.widget.Toast; import com.novelbook.android.MyApp; import com.novelbook.android.R; +import com.novelbook.android.bean.AdSetting; import com.novelbook.android.bean.NovelSites; import com.novelbook.android.bean.Site; import com.novelbook.android.db.Chapter; @@ -626,7 +627,7 @@ public class PageFactory implements ChangeSource{ if(!TextUtils.isEmpty(domainName)) { statusChangeSource = "前往 " + domainName.substring(0,domainName.length()>5?5:domainName.length()) + "..."; } - + // drawChangeSourceStatus(); drawStatus(); mBookUtil.pagefactory=this; mBookUtil.changeSource(domain, chapId, chapTitle); @@ -713,7 +714,7 @@ private void hideSysUI(){ } private PageFactory(Context context) { - // mBookUtil = new BookUtil(); + mBookUtil = new BookUtil(); mContext = context.getApplicationContext(); config = Config.getInstance(); //获取屏幕宽高 @@ -818,10 +819,15 @@ private void hideSysUI(){ } private void drawStatus(){ if(mBookPageWidget!=null) { - // drawStatus(mBookPageWidget.getCurPage()); + // drawStatus(mBookPageWidget.getCurPage()); drawStatus(mBookPageWidget.getNextPage()); } } + + public boolean isChangingSource(){ + return mStatus == Status.CHANGESOURCE; + } + private String loadingTxt =""; private String statusChangeSource ="正在换源..."; private boolean showingStatusAd =false; @@ -832,7 +838,7 @@ private void hideSysUI(){ mAd.hideProgressbar(); // mAd.showLoading(false); String status = ""; - boolean showAd =true; + boolean showAd =false; switch (mStatus){ case OPENING: status = "正在拼命加载" + loadingTxt; @@ -909,6 +915,7 @@ private void hideSysUI(){ // 下面这行是实现水平居中,drawText对应改为传入targetRect.centerX() waitPaint.setTextAlign(Paint.Align.CENTER); c.drawText(status, targetRect.centerX(), baseline, waitPaint); + Log.d(TAG, "changing Source showloading: drawing status :" +status ); // c.drawText("正在打开书本...", mHeight / 2, 0, waitPaint); /* TextPaint tp = new TextPaint(); tp.setColor(getTextColor()); @@ -988,15 +995,15 @@ private void hideSysUI(){ // mAd.showRefresh(View.GONE); Log.d(TAG, String.format("onDraw: trPage pageno %s,showAd %s",trPage.getPageNo(),showAd)); - + // Log.d(TAG, "changing Source onDraw showloading: drawing status :" ); if(m_lines.size()==0 ){ return; } - /* try { + /* try { throw new Exception("who's ad"); }catch (Exception e){ - Log.e(TAG, "onDraw:showTopBanner ",e ); + Log.e(TAG, "onDraw:changing Source ",e ); }*/ /* Log.d(TAG, "showloading: ondraw showAd: " +showAd ); try{ @@ -1280,7 +1287,7 @@ private void hideSysUI(){ public void showAd(){ Log.d(TAG, String.format("loadBannerAd showAd: mAdType %s ",mAdType )); - if(mStatus == Status.LASTPAGE || mAd==null ||currentPage==null){ + if(mStatus == Status.LASTPAGE || mAd==null ||currentPage==null || !Constants.AD_SETTING.isShowAdsense()){ return; } Log.d(TAG, String.format("loadBannerAd showAd: mAdType %s, pageNo %s",mAdType, currentPage.getPageNo())); @@ -2127,8 +2134,11 @@ private void hideSysUI(){ public void clear(){ // Log.d(TAG, String .format("prepare Book: clearing book info %s" , getNovle().getName())); - mBookUtil.clear(); - mBookUtil=null; + if(mBookUtil!=null) { + mBookUtil.clear(); + // mBookUtil=null; + } + fileRetryCnt.clear(); lastPageTime=0; if(chaptMap!=null){ @@ -2143,7 +2153,7 @@ private void hideSysUI(){ cancelPage = null; prePage = null; currentPage = null; - mAd=null; + // mAd=null; currentChaptPages =null; preChaptPages=null; nextChaptPages=null; @@ -2220,7 +2230,7 @@ private void hideSysUI(){ public void refreshCate(){ mBookUtil.getChapters().clear(); - mBookUtil.getSiteRule(); + mBookUtil.getSiteRule(true); } public long getChapterLen(){ return mBookUtil.getChapterLen(); diff --git a/zhuike/src/main/res/layout/activity_blank.xml b/zhuike/src/main/res/layout/activity_blank.xml new file mode 100644 index 0000000..806545c --- /dev/null +++ b/zhuike/src/main/res/layout/activity_blank.xml @@ -0,0 +1,19 @@ + + + + + + + + + + diff --git a/zhuike/zhuike.iml b/zhuike/zhuike.iml index 0a919f9..a959b37 100644 --- a/zhuike/zhuike.iml +++ b/zhuike/zhuike.iml @@ -8,80 +8,38 @@ - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -129,33 +87,42 @@ + + + + + + + + - + + - - + + + -