Commit 544333b1 authored by jyx's avatar jyx

修复珊瑚自有CPD下载问题

parent 4a5b6586
......@@ -2,10 +2,10 @@ package com.mints.goodmoney.ad.download;
import androidx.annotation.Nullable;
import com.mints.goodmoney.BuildConfig;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.common.Constant;
import com.mints.goodmoney.manager.UserManager;
import com.mints.goodmoney.utils.LogUtil;
import com.mints.library.utils.json.JsonUtil;
import com.tz.sdk.coral.ad.CoralAD;
import com.tz.sdk.coral.callback.CoralADListener;
......@@ -16,8 +16,10 @@ import com.tz.sdk.core.ad.ADSource;
import com.tz.sdk.core.ad.ADType;
import com.tz.sdk.core.loader.ADLoader;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
/**
* 珊瑚CPD下载安装试玩
......@@ -99,6 +101,7 @@ public final class CoralDownload {
*/
@Override
public boolean download(DownloadProcess downloadProcess) {
LogUtil.d("download");
if (mOnAdLoadListener != null) {
mOnAdLoadListener.onGetDownloadProcess(downloadProcess);
}
......@@ -113,6 +116,7 @@ public final class CoralDownload {
@Override
public void onAdFailed(ADError adError) {
super.onAdFailed(adError);
LogUtil.d("onAdFailed");
if (mOnAdLoadListener != null) {
mOnAdLoadListener.onLoadFail();
}
......@@ -127,7 +131,13 @@ public final class CoralDownload {
public void onAdLoaded(List<CoralAD> adList) {
if (adList != null && adList.size() > 0) {
if (mOnAdLoadListener != null) {
mOnAdLoadListener.onLoadSuccess(adList);
try {
Random r = new Random();
int randomWeight = r.nextInt(adList.size());
mOnAdLoadListener.onLoadSuccess(Collections.singletonList(adList.get(randomWeight)));
} catch (Exception e) {
mOnAdLoadListener.onLoadSuccess(Collections.singletonList(adList.get(0)));
}
}
} else {
if (mOnAdLoadListener != null) {
......@@ -146,6 +156,7 @@ public final class CoralDownload {
*/
@Override
public boolean onAdShow(@Nullable CoralAD ad) {
LogUtil.d("onAdShow");
return false;
}
......@@ -159,6 +170,7 @@ public final class CoralDownload {
*/
@Override
public boolean onAdClicked(@Nullable CoralAD ad) {
LogUtil.d("onAdClicked");
if (mOnAdLoadListener != null) {
mOnAdLoadListener.onSDKDownloadStart();
}
......@@ -176,6 +188,7 @@ public final class CoralDownload {
*/
@Override
public boolean onAppDownloading(@Nullable CoralAD ad, @Nullable String downloadUrl) {
LogUtil.d("onAppDownloading");
if (mOnAdLoadListener != null) {
mOnAdLoadListener.onSDKDownloadStart();
}
......@@ -194,8 +207,9 @@ public final class CoralDownload {
*/
@Override
public boolean onAppDownloaded(@Nullable CoralAD ad, @Nullable String downloadUrl, @Nullable String localFile) {
LogUtil.d("onAppDownloaded");
if (mOnAdLoadListener != null) {
mOnAdLoadListener.onSDKDownloaded();
mOnAdLoadListener.onSDKDownloaded(localFile);
}
return false;
}
......@@ -212,6 +226,8 @@ public final class CoralDownload {
*/
@Override
public boolean onAppInstalled(@Nullable CoralAD ad, @Nullable String downloadUrl, @Nullable String localFile) {
LogUtil.d("onAppInstalled");
if (mOnAdLoadListener != null) {
mOnAdLoadListener.onSDKInstalled();
}
......@@ -230,6 +246,7 @@ public final class CoralDownload {
*/
@Override
public boolean onAppActivated(CoralAD ad, String downloadUrl, String localFile) {
LogUtil.d("onAppActivated");
return false;
}
});
......@@ -253,7 +270,7 @@ public final class CoralDownload {
void onSDKDownloadStart();
void onSDKDownloaded();
void onSDKDownloaded(String localFilePath);
void onSDKInstalled();
......
......@@ -70,6 +70,8 @@ class TaskActivity : BaseActivity(), TaskView,
// 第二次拉取重复不拉取
private var isTwiceGetCpd = false
private val outNetIp by lazy { SPUtil.getInstance().getString(Constant.OUT_NET_IP) }
companion object {
const val TASK_COIN = "task_coin"
const val TASK_USE_MAX = "task_use_max"
......@@ -110,7 +112,7 @@ class TaskActivity : BaseActivity(), TaskView,
}
private fun loadCPDData() {
taskPresenter.getCpdDetail(SPUtil.getInstance().getString(Constant.OUT_NET_IP))
taskPresenter.getCpdDetail(outNetIp)
}
private fun initView() {
......@@ -163,7 +165,6 @@ class TaskActivity : BaseActivity(), TaskView,
mFakeTaskList.clear()
if (shMax > 0 && (cpdMax > 0 || cpdMax == 0)) {
for (i in 0 until shMax) {
mCoralDownload?.pull()
......@@ -183,9 +184,6 @@ class TaskActivity : BaseActivity(), TaskView,
mFakeTaskList.add(tzTaskBean)
}
LogUtil.d(TAG_LOG, "CPD -> getCpdModelSuc CPD-PKG -> " + dataBean.materials[0].app_apk_name)
LogUtil.d(TAG_LOG, "CPD -> getCpdModelSuc cpdLoadCountTime -> " + cpdLoadCountTime)
// 多拉取的CPD广告
if (cpdLoadCountTime++ >= cpdMax - 1) {
getCpdRepeatPkg()
......@@ -198,7 +196,6 @@ class TaskActivity : BaseActivity(), TaskView,
private fun getCpdRepeatPkg() {
if (isTwiceGetCpd) {
if (cpdLoadCountTime >= cpdMax) {
LogUtil.d("BBBBBB")
notifyDataAndShowAd()
}
return
......@@ -215,7 +212,6 @@ class TaskActivity : BaseActivity(), TaskView,
if (mFakeTaskList[i].isShCpd) {
newPkgData.add(mFakeTaskList[i])
} else {
var flag = true
for (j in 0 until mFakeTaskList.size) {
......@@ -243,15 +239,9 @@ class TaskActivity : BaseActivity(), TaskView,
}
override fun doInUIThread() {
LogUtil.d("数据源 列表数据" + "-->" + mFakeTaskList.size)
mFakeTaskList.clear()
mFakeTaskList.addAll(t)
LogUtil.d("列表数据" + "-->" + t.size)
LogUtil.d("thatCpdLoadCountTime-->$cpdLoadCountTime")
// 重新获取数据
if (cpdLoadCountTime in 1..cpdMax) {
isTwiceGetCpd = true
......@@ -276,14 +266,18 @@ class TaskActivity : BaseActivity(), TaskView,
srl_task.finishRefresh()
mTaskAdapter?.notifyDataSetChanged()
if (mFakeTaskList.size == 0) {
iv_empty.visibility = View.VISIBLE
return
} else {
iv_empty.visibility = View.GONE
}
for (tzTaskBean in mFakeTaskList) {
if (!tzTaskBean.isShCpd) {
val trackerBean = tzTaskBean.trackerBean
if (trackerBean != null) {
LogUtil.d("AAAAA")
LogUtil.d(TAG_LOG, "CPD -> show")
// 上报CPD显示
......@@ -342,20 +336,18 @@ class TaskActivity : BaseActivity(), TaskView,
override fun onSDKDownloadStart() {
taskDialog?.dismiss()
// SDK上报开始下载
mDownloadProcess?.reportDownloadStart(false)
registerBroad()
}
override fun onSDKDownloaded() {
override fun onSDKDownloaded(localFilePath: String) {
// SDK上报下载完成
mDownloadProcess?.reportInstallSuccess(false)
// mDownloadProcess?.reportDownloadSuccess(localFilePath, false)
}
override fun onSDKInstalled() {
// SDK上报安装完成
mDownloadProcess?.reportInstallSuccess(false)
// mDownloadProcess?.reportInstallSuccess(false)
}
override fun onGetDownloadProcess(downloadProcess: DownloadProcess?) {
......
......@@ -12,7 +12,6 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import com.component.dly.xzzq_ywsdk.YwSDK_WebActivity.Companion.open
import com.fly.scenemodule.SceneUtil
import com.mints.goodmoney.BuildConfig
import com.mints.goodmoney.R
import com.mints.goodmoney.ad.banner.BannerManager
import com.mints.goodmoney.ad.express.TTPreLoadCarrierExpressManager
......@@ -249,8 +248,8 @@ class MyFragment : BaseFragment(),
return
}
if (data?.shareNews != null) {
AppConfig.wzReadCoin = data!!.shareNews.readCoin
if (data.shareNews != null) {
AppConfig.wzReadCoin = data.shareNews.readCoin
}
// 更新权重
......
......@@ -66,7 +66,7 @@ class TaskDialog(context: Context) : Dialog(context, R.style.dialog) {
override fun dismiss() {
super.dismiss()
adContainer?.removeAllViews()
// adContainer?.removeAllViews()
adContainer = null
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment