Prechádzať zdrojové kódy

添加鸿途信达 广告

zengjiebin 7 rokov pred
rodič
commit
567fdb1ccd

+ 2 - 0
app/build.gradle

@@ -438,6 +438,8 @@ dependencies {
     implementation 'com.shuyu:GSYVideoPlayer-exo2:6.0.2'
     //https://github.com/koral--/android-gif-drawable
     implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
+    //鸿途信达 广告sdk
+    implementation(name: 'ad-htxd-201901071720', ext: 'aar')
 }
 
 static def releaseTime() {

BIN
app/libs/ad-htxd-201901071720.aar


+ 4 - 1
app/proguard-rules.pro

@@ -508,4 +508,7 @@
     public <init>(android.content.Context, android.util.AttributeSet, int);
 }
 #==================https://github.com/koral--/android-gif-drawable==========================
--keep public class pl.droidsonroids.gif.GifIOException{<init>(int, java.lang.String);}
+-keep public class pl.droidsonroids.gif.GifIOException{<init>(int, java.lang.String);}
+#==================鸿途信达广告sdk==========================
+-keep class com.hc.**{*;}
+-keep class com.hoc.**{*;}

+ 82 - 0
app/src/main/java/com/sheep/gamegroup/module/ad_htxd/model/ArticleAd.java

@@ -0,0 +1,82 @@
+package com.sheep.gamegroup.module.ad_htxd.model;
+
+import com.hoc.hoclib.adlib.HNativeListener;
+import com.hoc.hoclib.adlib.NativeADDataInfo;
+import com.hoc.hoclib.adlib.PNative;
+import com.sheep.gamegroup.model.entity.Article;
+import com.sheep.gamegroup.util.ListUtil;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+import rx.functions.Action1;
+
+/**
+ * Created by realicing on 2019/1/7.
+ * realicing@sina.com
+ * 鸿途信达 广告
+ */
+public class ArticleAd extends Article {
+
+    public static final String FEED = "1D0JLRMA102V277730B60000552042FE";
+    public static final int INDEX = 4;//放在position为4的位置,即第5个
+    public static final boolean showAd = true;//是否显示广告
+
+    private NativeADDataInfo nativeADDataInfo;
+    private PNative pNative;
+
+    public static int ID = -99;
+    public ArticleAd(NativeADDataInfo nativeADDataInfo, PNative pNative) {
+        this.nativeADDataInfo = nativeADDataInfo;
+        this.pNative = pNative;
+        setType(2);//资讯
+        setId(ID--);
+        setTitle(nativeADDataInfo.getTitle());
+        setCreated_at((int) (System.currentTimeMillis() / 1000L));
+        setPictures(nativeADDataInfo.getMainImg());
+    }
+
+    public NativeADDataInfo getNativeADDataInfo() {
+        return nativeADDataInfo;
+    }
+
+    public PNative getpNative() {
+        return pNative;
+    }
+
+    //初始化广告
+    public static void fetchNativeData(ListUtil.CallBack<ArticleAd, Boolean> adAction1, Action1<Boolean> callBack) {
+        final PNative pNative = new PNative(SheepApp.getInstance());
+        pNative.setHTNativeListener(new HNativeListener() {
+            @Override
+            public void onNativeAdIsReady(NativeADDataInfo nativeAdData) {
+                ArticleAd articleAd = new ArticleAd(nativeAdData, pNative);
+                boolean success = adAction1.call(articleAd);
+
+                pNative.handleImp();
+                callBack.call(success);
+            }
+
+            @Override
+            public void onLoadNativeAdFail() {
+                callBack.call(false);
+            }
+        })
+                .setADId(FEED)
+                .fetch();
+    }
+
+    //检查是否是广告
+    public static boolean checkAd(Article item) {
+        if(item instanceof ArticleAd){
+            return true;
+        }
+        return false;
+    }
+    //检查是否是广告 并点击
+    public static boolean checkAdAndClick(Article item) {
+        if(item instanceof ArticleAd){
+            ((ArticleAd) item).getpNative().handleClickToWeb();
+            return true;
+        }
+        return false;
+    }
+}

+ 4 - 4
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -5,7 +5,6 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.net.Uri;
-import android.os.Build;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.view.Gravity;
@@ -51,6 +50,7 @@ import com.sheep.gamegroup.model.entity.WebParams;
 import com.sheep.gamegroup.model.entity.WebviewEntity;
 import com.sheep.gamegroup.model.entity.XianWanEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.module.ad_htxd.model.ArticleAd;
 import com.sheep.gamegroup.module.find.activity.ActMediaChoose;
 import com.sheep.gamegroup.module.login.ChangePasswordAct;
 import com.sheep.gamegroup.module.login.LoginAct;
@@ -159,8 +159,6 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.service.AutoCheckService;
 import com.sheep.jiuyan.samllsheep.service.DownloadService;
 import com.sheep.jiuyan.samllsheep.service.FloatShotScreenService;
-import com.sheep.jiuyan.samllsheep.service.ListenerShotNewService;
-import com.sheep.jiuyan.samllsheep.service.ListenerShotService;
 import com.sheep.jiuyan.samllsheep.ui.activity.SignActivity;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
@@ -218,7 +216,6 @@ import static com.sheep.gamegroup.util.UMConfigUtils.Event.USER_NEW_VERSION;
 import static com.sheep.gamegroup.util.UMConfigUtils.Event.USER_TASK_RECORD;
 import static com.sheep.gamegroup.util.UMConfigUtils.Event.XIAOMI_GAME_LIST;
 import static com.sheep.jiuyan.samllsheep.service.FloatShotScreenService.SET_SHOW_OR_HIDE;
-import static com.sheep.jiuyan.samllsheep.service.ListenerShotService.IS_RECORD_PATH;
 import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
 
 /**
@@ -2173,6 +2170,9 @@ public class Jump2View {
 
     //打开一个发现
     public void goFindItem(Context context, Article item) {
+        if(ArticleAd.showAd && ArticleAd.checkAdAndClick(item)){//检查点击的是否是 广告
+            return;
+        }
         switch (item.getType()) {//类型 1:游戏 2:咨询 3:转跳 4:任务 5:栏目
             case 1:
                 Jump2View.getInstance().goFindGame(context, item);

+ 15 - 0
app/src/main/java/com/sheep/gamegroup/util/ListUtil.java

@@ -37,6 +37,10 @@ public class ListUtil {
         int size = ListUtil.size(list);
         return size > 0 ? list.get(-1 + size) : null;
     }
+    public static <T> T getLast(List<T> list, int index) {
+        int size = ListUtil.size(list);
+        return getItem(list, size - 1 - index);
+    }
 
 
     public static int getTotalPage(int count, int per_page) {
@@ -236,6 +240,17 @@ public class ListUtil {
         return false;
     }
 
+    //插入倒数第几个位置
+    public static <T> boolean addLastIndex(List<T> allList, T item, int index) {
+        int size = size(allList);
+        int position = size - index;
+        if(position < 0){
+            return false;
+        }
+        allList.add(position, item);
+        return true;
+    }
+
     //I 传入的数据, R 返回的结果
     public static interface CallBack<I, R> {
         public R call(I i);

+ 34 - 2
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtFindChild.java

@@ -21,6 +21,7 @@ import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.Applications;
 import com.sheep.gamegroup.model.entity.Article;
 import com.sheep.gamegroup.model.entity.ArticleTag;
+import com.sheep.gamegroup.module.ad_htxd.model.ArticleAd;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DownloadUtil;
 import com.sheep.gamegroup.util.Jump2View;
@@ -37,6 +38,7 @@ import org.afinal.simplecache.ApiKey;
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -57,7 +59,7 @@ public class FgtFindChild extends BaseListFragment5<Article> {
 
     @Override
     protected RecyclerView.Adapter getAdapter() {
-        return new CommonRecycler(list);
+        return new CommonRecycler(ArticleAd.showAd ? allList : list);
     }
 
     @Override
@@ -75,6 +77,36 @@ public class FgtFindChild extends BaseListFragment5<Article> {
         return Article.class;
     }
 
+    private List<Article> allList = new ArrayList<>();
+
+    @Override
+    protected void loadList(List<Article> addList) {
+        if(ArticleAd.showAd) {
+            ListUtil.addAll(allList, addList);
+            if (ListUtil.size(addList) == per_page) {
+                ArticleAd.fetchNativeData(articleAd -> {
+                    if (ListUtil.getLast(allList, per_page - ArticleAd.INDEX) instanceof ArticleAd) {//倒数第几个不是广告的情况下才添加
+                        return false;
+                    } else {
+                        return ListUtil.addLastIndex(allList, articleAd, per_page - ArticleAd.INDEX);
+                    }
+                }, aBoolean -> {
+                    if (aBoolean) {
+                        notifyDataSetChanged();
+                    }
+                });
+            }
+        }
+        super.loadList(addList);
+    }
+
+    @Override
+    public void clear() {
+        if(ArticleAd.showAd)
+            allList.clear();
+        super.clear();
+    }
+
     public static FgtFindChild newInstance(int type) {
         FgtFindChild fgt = new FgtFindChild();
         Bundle bundle = new Bundle();
@@ -292,7 +324,7 @@ public class FgtFindChild extends BaseListFragment5<Article> {
 
         @Override
         public int getItemViewType(int position) {
-            Article article = list.get(position);
+            Article article = (ArticleAd.showAd ? allList : list).get(position);
             return article.getType();
         }
 

+ 12 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -17,12 +17,14 @@ import com.baidu.location.LocationClientOption;
 import com.bumptech.glide.Glide;
 import com.danikula.videocache.HttpProxyCacheServer;
 import com.didi.virtualapk.PluginManager;
+import com.hoc.hoclib.PManager;
 import com.kfzs.cfyl.share_library.util.ContextHolder;
 import com.liulishuo.okdownload.OkDownload;
 import com.liulishuo.okdownload.core.dispatcher.DownloadDispatcher;
 import com.sheep.gamegroup.di.components.DaggerNetComponent;
 import com.sheep.gamegroup.di.components.NetComponent;
 import com.sheep.gamegroup.di.modules.NetModule;
+import com.sheep.gamegroup.module.ad_htxd.model.ArticleAd;
 import com.sheep.gamegroup.module.login.LoginAct;
 import com.sheep.gamegroup.usage.AppUsageManager;
 import com.sheep.gamegroup.util.AppUtil;
@@ -284,6 +286,12 @@ public class SheepApp extends MultiDexApplication {
 //        CacheFactory.setCacheManager(ExoPlayerCacheManager.class);//exo缓存模式,支持m3u8,只支持exo
 //        CacheFactory.setCacheManager(ProxyCacheManager.class);//代理缓存模式,支持所有模式,不支持m3u8等
 
+        //鸿途信达 广告 需要添加 两行代码顺序不能变
+        if(ArticleAd.showAd) {
+            PManager.getInstance().setChannel(this, 18122801);
+            PManager.getInstance().onCreate(this);
+        }
+
     }
 
     private void initBdLocationOption() {
@@ -563,6 +571,10 @@ public class SheepApp extends MultiDexApplication {
         super.attachBaseContext(base);
         MultiDex.install(this);
         PluginManager.getInstance(base).init();//插件化框架
+        //鸿途信达 广告 需要添加
+        if(ArticleAd.showAd) {
+            PManager.getInstance().attachBaseContext(base);
+        }
     }
 
     //应用退出的回调(模拟器才会回调)