billyyoyo лет назад: 6
Родитель
Сommit
172d53e25b

+ 29 - 12
app/src/main/java/com/sheep/gamegroup/util/ListUtil.java

@@ -23,25 +23,27 @@ public class ListUtil {
     }
 
     public static <T> void forEach(List<T> list, Action1<T> action1) {
-        if(list != null)
+        if (list != null)
             for (T t : list) {
                 action1.call(t);
             }
     }
+
     public static <T> T findItem(List<T> list, CallBack<T, Boolean> action1) {
-        if(list != null)
+        if (list != null)
             for (T t : list) {
-                if(action1.call(t)){
+                if (action1.call(t)) {
                     return t;
                 }
             }
         return null;
     }
+
     public static <T> List<T> findIList(List<T> list, CallBack<T, Boolean> action1) {
         List<T> findList = new ArrayList<>();
-        if(list != null)
+        if (list != null)
             for (T t : list) {
-                if(action1.call(t)){
+                if (action1.call(t)) {
                     findList.add(t);
                 }
             }
@@ -56,6 +58,7 @@ 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);
@@ -174,8 +177,9 @@ public class ListUtil {
         Collections.addAll(list, items);
         return list;
     }
+
     public static <T> ArrayList<T> asList(List<T> itemList) {
-        if(itemList instanceof ArrayList){
+        if (itemList instanceof ArrayList) {
             return (ArrayList<T>) itemList;
         }
         ArrayList<T> list = emptyList();
@@ -183,6 +187,15 @@ public class ListUtil {
         return list;
     }
 
+    public static String join(List list) {
+        StringBuffer sb = new StringBuffer("");
+        for (Object obj : list) {
+            if (sb.length() != 0) sb.append(",");
+            sb.append(obj.toString());
+        }
+        return sb.toString();
+    }
+
     @SafeVarargs
     public static <T, R> ArrayList<R> asList(CallBack<T, R> callBack, T... items) {
         ArrayList<R> list = emptyList();
@@ -192,11 +205,12 @@ public class ListUtil {
         }
         return list;
     }
+
     public static <T, R> ArrayList<R> asList(CallBack<T, R> callBack, List<T> itemList, CallBack<T, Boolean> filterCallBack) {
         ArrayList<R> list = emptyList();
         for (T t : itemList) {
             R r = callBack.call(t);
-            if(filterCallBack == null || filterCallBack.call(t))
+            if (filterCallBack == null || filterCallBack.call(t))
                 list.add(r);
         }
         return list;
@@ -214,6 +228,7 @@ public class ListUtil {
         list.removeAll(removeList);
         return removeList;
     }
+
     public static <T> T getItem(List<T> list, CallBack<T, Boolean> callBack) {
         if (isEmpty(list)) {
             return null;
@@ -252,7 +267,7 @@ public class ListUtil {
     //是事包含指定字符串
     public static boolean contains(String[] items, String src) {
         for (String item : items) {
-            if(TextUtils.equals(item, src)){
+            if (TextUtils.equals(item, src)) {
                 return true;
             }
         }
@@ -262,17 +277,18 @@ public class ListUtil {
     //插入第几个位置
     public static <T> boolean insertIndex(List<T> allList, T item, int index) {
         int size = size(allList);
-        if(index > size){
+        if (index > size) {
             return false;
         }
         allList.add(index, item);
         return true;
     }
+
     //插入倒数第几个位置
     public static <T> boolean insertLastIndex(List<T> allList, T item, int index) {
         int size = size(allList);
         int position = size - index;
-        if(position < 0){
+        if (position < 0) {
             return false;
         }
         allList.add(position, item);
@@ -283,11 +299,12 @@ public class ListUtil {
     public static interface CallBack<I, R> {
         public R call(I i);
     }
+
     //列表拼接为字符串
-    public static String listToUrls(List<String> list){
+    public static String listToUrls(List<String> list) {
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < list.size(); i++) {
-            if(i != 0)
+            if (i != 0)
                 sb.append(";");
             sb.append(list.get(i));
         }

+ 12 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/helper/AdHelper.java

@@ -19,6 +19,7 @@ import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.FileUtil;
 import com.sheep.gamegroup.util.IDConstant;
 import com.sheep.gamegroup.util.Jump2View;
+import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.view.activity.SplashAct;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -54,7 +55,7 @@ public class AdHelper {
             AdHelper.stat(advertising.getAd_id(), 2);
             return false;
         } else if (advertising.getJump_type() == 2) {
-            if(advertising.getJump_form() == 1) {
+            if (advertising.getJump_form() == 1) {
                 String fileName = FileUtil.getLastSplitEnd(advertising.getJump_url(), '/');
                 String filePath = new File(DIR, fileName).getAbsolutePath();
                 Jump2View.getInstance().startDownloadService(advertising.getJump_url(), filePath);
@@ -69,6 +70,16 @@ public class AdHelper {
         return false;
     }
 
+    public static void stat(List<SheepAd> ads, int type) {
+        if (ListUtil.isEmpty(ads)) return;
+        List<Long> ids = new ArrayList<>();
+        for(SheepAd ad:ads){
+            ids.add(ad.getAd_id());
+        }
+        String idPara= ListUtil.join(ids);
+        stat(idPara, type);
+    }
+
     public static void stat(long adId, int type) {
         JSONObject json = new JSONObject();
         json.put("app_advertising_id", adId);

+ 1 - 11
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtFindChild.java

@@ -249,9 +249,7 @@ public class FgtFindChild extends BaseListFragment5<Article> {
             if (ret) {
                 ads = list;
             }
-            for (SheepAd ad : list) {
-                AdHelper.stat(ad.getAd_id(), 1);
-            }
+            AdHelper.stat(list, 1);
             action.call(null);
         });
     }
@@ -268,14 +266,6 @@ public class FgtFindChild extends BaseListFragment5<Article> {
         }
         if (type == 0) {
             ads = DDProviderHelper.getInstance().listSheepAd(SheepAd.FORM_NEWS);
-            StringBuffer ids = new StringBuffer();
-            for (SheepAd ad : ads) {
-                if (ids.length() > 0) {
-                    ids.append(",");
-                }
-                ids.append(ad.getAd_id());
-            }
-            AdHelper.stat(ids.toString(), 1);
         }
         EventBus.getDefault().register(this);
     }

+ 3 - 4
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtSmallSheep.java

@@ -794,6 +794,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         if (list.size() > 0) {
             barListList.add(list.get(0));
         }
+        AdHelper.stat(list.get(0).getAd_id(), 1);
         ViewUtil.notifyDataSetChanged(bar_list_rv);
         //首页list
         List<HomeListEntity> cacheHomeListEtyList = DataUtil.getInstance().getCacheList(ApiKey.home_list, HomeListEntity.class);
@@ -867,9 +868,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
                     if (list.size() > 0) {
                         barListList.add(list.get(0));
                     }
-                    for (SheepAd ad : barListList) {
-                        AdHelper.stat(ad.getAd_id(), 1);
-                    }
+                    AdHelper.stat(list.get(0).getAd_id(), 1);
                     ViewUtil.notifyDataSetChanged(bar_list_rv);
                 }
             });
@@ -1271,8 +1270,8 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         for (SheepAd ad : list) {
             images.add(ad.getAd_img());
             titles.add(ad.getName());
-            AdHelper.stat(ad.getAd_id(), 1);
         }
+        AdHelper.stat(list, 1);
         //结束轮播
         banner.stopAutoPlay();
         banner.setVisibility(View.VISIBLE);