Commit 331e2978 authored by jyx's avatar jyx

添加去重代码

parent 26d3ffac
...@@ -684,6 +684,38 @@ class DeviceInfo private constructor() { ...@@ -684,6 +684,38 @@ class DeviceInfo private constructor() {
return pkg return pkg
} }
/**
*
*
* return:包名
*/
fun isLoadingPkg(pkg: String): Boolean {
var flag = false
try {
val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo =
mContext!!.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null
val count = packageinfo.size
for (i in 0 until count) {
pinfo = packageinfo[i]
val appInfo = pinfo.applicationInfo
if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM > 0) {
//系统程序 忽略
} else {
//非系统程序
if (TextUtils.equals(pkg, pinfo.packageName)) {
return true
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
return flag
}
/** /**
* Android ID * Android ID
* *
......
...@@ -4,6 +4,8 @@ import com.mints.goodmoney.MintsApplication ...@@ -4,6 +4,8 @@ import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.common.DeviceInfo import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.net.CpdService import com.mints.goodmoney.net.CpdService
import com.mints.goodmoney.utils.MD5 import com.mints.goodmoney.utils.MD5
import com.mints.goodmoney.utils.rxutil.CommonRxTask
import com.mints.goodmoney.utils.rxutil.RxjavaUtil
import com.mints.library.net.netstatus.NetUtils import com.mints.library.net.netstatus.NetUtils
import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody import okhttp3.RequestBody
......
...@@ -66,7 +66,8 @@ class TaskPresenter : BasePresenter<TaskView>() { ...@@ -66,7 +66,8 @@ class TaskPresenter : BasePresenter<TaskView>() {
} }
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
LogUtil.d(e.code) LogUtil.d("" + e.code + " -> " + e.message)
view.getCpdModelFail()
} }
override fun onNext(t: JsonObject?) { override fun onNext(t: JsonObject?) {
......
...@@ -10,6 +10,7 @@ import androidx.recyclerview.widget.GridLayoutManager ...@@ -10,6 +10,7 @@ import androidx.recyclerview.widget.GridLayoutManager
import com.mints.goodmoney.R import com.mints.goodmoney.R
import com.mints.goodmoney.ad.download.CoralDownload import com.mints.goodmoney.ad.download.CoralDownload
import com.mints.goodmoney.common.Constant import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.manager.AppTryPlayManager import com.mints.goodmoney.manager.AppTryPlayManager
import com.mints.goodmoney.manager.DownloadApkManager import com.mints.goodmoney.manager.DownloadApkManager
import com.mints.goodmoney.mvp.model.CpdModelBean import com.mints.goodmoney.mvp.model.CpdModelBean
...@@ -25,6 +26,8 @@ import com.mints.goodmoney.ui.widgets.DialogListener ...@@ -25,6 +26,8 @@ import com.mints.goodmoney.ui.widgets.DialogListener
import com.mints.goodmoney.ui.widgets.TaskCpdDialog import com.mints.goodmoney.ui.widgets.TaskCpdDialog
import com.mints.goodmoney.ui.widgets.TaskDialog import com.mints.goodmoney.ui.widgets.TaskDialog
import com.mints.goodmoney.utils.* import com.mints.goodmoney.utils.*
import com.mints.goodmoney.utils.rxutil.CommonRxTask
import com.mints.goodmoney.utils.rxutil.RxjavaUtil
import com.scwang.smartrefresh.layout.api.RefreshLayout import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshListener import com.scwang.smartrefresh.layout.listener.OnRefreshListener
import com.tz.sdk.coral.ad.CoralAD import com.tz.sdk.coral.ad.CoralAD
...@@ -32,6 +35,7 @@ import com.tz.sdk.coral.callback.h5.DownloadProcess ...@@ -32,6 +35,7 @@ import com.tz.sdk.coral.callback.h5.DownloadProcess
import kotlinx.android.synthetic.main.activity_task.* import kotlinx.android.synthetic.main.activity_task.*
import kotlinx.android.synthetic.main.header_layout.* import kotlinx.android.synthetic.main.header_layout.*
/** /**
* *
* 描述:试玩任务 * 描述:试玩任务
...@@ -64,6 +68,9 @@ class TaskActivity : BaseActivity(), TaskView, ...@@ -64,6 +68,9 @@ class TaskActivity : BaseActivity(), TaskView,
// 试完时间不足弹窗 // 试完时间不足弹窗
private var tryTimeOut = false private var tryTimeOut = false
// 第二次拉取重复不拉取
private var isTwiceGetCpd = false
companion object { companion object {
const val TASK_COIN = "task_coin" const val TASK_COIN = "task_coin"
const val TASK_USE_MAX = "task_use_max" const val TASK_USE_MAX = "task_use_max"
...@@ -143,6 +150,8 @@ class TaskActivity : BaseActivity(), TaskView, ...@@ -143,6 +150,8 @@ class TaskActivity : BaseActivity(), TaskView,
shMax = CPD shMax = CPD
cpdMax = CPD_SYD cpdMax = CPD_SYD
isTwiceGetCpd = false
if ((shMax + cpdMax) <= 0) { if ((shMax + cpdMax) <= 0) {
hideLoading() hideLoading()
showToast("今日任务已完成,请明日再试") showToast("今日任务已完成,请明日再试")
...@@ -167,33 +176,102 @@ class TaskActivity : BaseActivity(), TaskView, ...@@ -167,33 +176,102 @@ class TaskActivity : BaseActivity(), TaskView,
mFakeTaskList.add(tzTaskBean) mFakeTaskList.add(tzTaskBean)
} }
LogUtil.d(TAG_LOG, "CPD -> getCpdModelSuc") LogUtil.d(TAG_LOG, "CPD -> getCpdModelSuc CPD-PKG -> " + dataBean.materials[0].app_apk_name)
// 多拉取的CPD广告 // 多拉取的CPD广告
if (cpdLoadCountTime++ == cpdMax - 1) { if (cpdLoadCountTime++ == cpdMax - 1) {
hideLoading() getCpdRepeatPkg()
srl_task.finishRefresh() }
mTaskAdapter?.notifyDataSetChanged() }
for (tzTaskBean in mFakeTaskList) { /**
if (!tzTaskBean.isShCpd) { * 遍历去重APP包名
val trackerBean = tzTaskBean.trackerBean */
if (trackerBean != null) { private fun getCpdRepeatPkg() {
LogUtil.d(TAG_LOG, "CPD -> show") if (isTwiceGetCpd) {
LogUtil.d("isTwiceGetCpd")
notifyDataAndShowAd()
return
}
var thatCpdLoadCountTime = cpdMax
// 上报CPD显示 RxjavaUtil.executeRxTask<MutableList<TzTaskBean>>(object : CommonRxTask<MutableList<TzTaskBean>>() {
taskPresenter.cmtImp(trackerBean.show[0]) override fun doInIOThread() {
val newPkgData = mutableListOf<TzTaskBean>()
for (i in 0 until mFakeTaskList.size) {
if (mFakeTaskList[i].isShCpd) {
newPkgData.add(mFakeTaskList[i])
} else {
for (j in 0 until mFakeTaskList.size) {
if (!mFakeTaskList[j].isShCpd && !mFakeTaskList[i].isShCpd) {
if (mFakeTaskList[j].currentPkgName == mFakeTaskList[i].currentPkgName) {
// 是否已经安装此app
if (!DeviceInfo.instance.isLoadingPkg(mFakeTaskList[j].currentPkgName)) {
newPkgData.add(mFakeTaskList[j])
} else {
thatCpdLoadCountTime--
}
} else {
thatCpdLoadCountTime--
}
}
}
} }
} }
t = newPkgData
}
override fun doInUIThread() {
LogUtil.d("数据源 列表数据" + "-->" + mFakeTaskList.size)
mFakeTaskList.clear()
mFakeTaskList.addAll(t)
LogUtil.d("列表数据" + "-->" + mFakeTaskList.size)
LogUtil.d("thatCpdLoadCountTime" + "-->" + thatCpdLoadCountTime)
// 重新获取数据
if (thatCpdLoadCountTime < cpdMax - 1) {
isTwiceGetCpd = true
for (i in thatCpdLoadCountTime until cpdMax) {
loadCPDData()
}
return
} else {
notifyDataAndShowAd()
}
}
})
}
fun notifyDataAndShowAd() {
hideLoading()
srl_task.finishRefresh()
mTaskAdapter?.notifyDataSetChanged()
for (tzTaskBean in mFakeTaskList) {
if (!tzTaskBean.isShCpd) {
val trackerBean = tzTaskBean.trackerBean
if (trackerBean != null) {
LogUtil.d(TAG_LOG, "CPD -> show")
// 上报CPD显示
taskPresenter.cmtImp(trackerBean.show[0])
}
} }
} }
} }
override fun getCpdModelFail() { override fun getCpdModelFail() {
if (cpdLoadCountTime == cpdMax - 1) { notifyDataAndShowAd()
hideLoading()
srl_task.finishRefresh()
}
} }
override fun onRefresh(refreshLayout: RefreshLayout) { override fun onRefresh(refreshLayout: RefreshLayout) {
...@@ -451,14 +529,14 @@ class TaskActivity : BaseActivity(), TaskView, ...@@ -451,14 +529,14 @@ class TaskActivity : BaseActivity(), TaskView,
val trackerBean = mFakeTaskList[position].trackerBean val trackerBean = mFakeTaskList[position].trackerBean
if (trackerBean != null) { if (trackerBean != null) {
// 上报CPD激活完成 // 上报CPD激活完成
LogUtil.d(TAG_LOG, "CPD -> install_start")
LogUtil.d(TAG_LOG, "CPD -> install_finish")
LogUtil.d(TAG_LOG, "CPD -> activation")
LogUtil.d(TAG_LOG, "CPD -> install_start")
taskPresenter.cmtImp(trackerBean.install_start[0]) taskPresenter.cmtImp(trackerBean.install_start[0])
LogUtil.d(TAG_LOG, "CPD -> install_finish")
taskPresenter.cmtImp(trackerBean.install_finish[0]) taskPresenter.cmtImp(trackerBean.install_finish[0])
LogUtil.d(TAG_LOG, "CPD -> activation")
taskPresenter.cmtImp(trackerBean.activation[0]) taskPresenter.cmtImp(trackerBean.activation[0])
} }
} }
......
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