Commit 61cd15b1 authored by jyx's avatar jyx

代码优化

parent dbb6df8f
......@@ -19,6 +19,7 @@ import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.ui.widgets.DownloadProgressDialog
import com.mints.goodmoney.utils.CacheUtil
import com.mints.goodmoney.utils.LogUtil
import com.mints.goodmoney.utils.MD5
import java.io.File
......@@ -58,7 +59,11 @@ object DownloadApkManager {
*/
fun downloadApk(activity: Activity, url: String, name: String) {
this.activity = activity
this.apkName = "$name.apk"
if (name.contains(".apk")) {
this.apkName = name
} else {
this.apkName = "$name.apk"
}
// 判断apk是否存在
if (isFileExist("$name.apk")) {
......@@ -100,17 +105,16 @@ object DownloadApkManager {
downloadProgressDialog!!.show()
val context = MintsApplication.getContext()
// cachePath = context.externalCacheDir?.path + "/Download/"
PRDownloader.download(url, cachePath, apkName)
.build()
.setOnProgressListener { progress ->
if (activity != null && !activity!!.isFinishing()) {
if (activity != null && !activity!!.isFinishing) {
downloadProgressDialog?.setProgress(progress)
}
}
.start(object : OnDownloadListener {
override fun onDownloadComplete() {
if (activity != null && !activity!!.isFinishing()) {
if (activity != null && !activity!!.isFinishing) {
downloadProgressDialog?.dismiss()
try {
mDownloadListener?.onDownloadSuccess(cachePath + apkName)
......@@ -142,7 +146,7 @@ object DownloadApkManager {
val haveInstallPermission = context.packageManager.canRequestPackageInstalls()
if (!haveInstallPermission) {
showAlert(activity!!, "安装权限", "需要打开允许来自此来源,请去设置中开启此权限",
DialogInterface.OnClickListener { dialog, which ->
DialogInterface.OnClickListener { _, _ ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//此方法需要API>=26才能使用
toInstallPermissionSettingIntent()
......
......@@ -74,6 +74,10 @@ class TaskCpdActivity : BaseActivity(), View.OnClickListener {
xtTaskCpd.setupWithViewPager(vpTaskCpd)
}
fun selectTwoFragment() {
vpTaskCpd.setCurrentItem(1, true)
}
private fun backDialog() {
cdaa = CustomDialogAsApple(context, object : DialogListener() {
override fun onClick(v: View) {
......
......@@ -9,6 +9,7 @@ import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.mints.goodmoney.R
import com.mints.goodmoney.ad.download.CoralDownload
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.manager.AppTryPlayManager
......@@ -20,6 +21,7 @@ import com.mints.goodmoney.mvp.presenters.TaskPresenter
import com.mints.goodmoney.mvp.views.TaskView
import com.mints.goodmoney.service.AppInstallService
import com.mints.goodmoney.ui.activitys.AwardActivity
import com.mints.goodmoney.ui.activitys.TaskCpdActivity
import com.mints.goodmoney.ui.adapter.TaskAdapter
import com.mints.goodmoney.ui.adapter.listener.OnItemChildClickListener
import com.mints.goodmoney.ui.fragment.base.BaseFragment
......@@ -70,8 +72,8 @@ class TaskCpdFragment : BaseFragment(), TaskView,
private var mCoin = 0
private var needUseTime = -1// 应用试玩时间
private var shMax = 3 //珊瑚 广告最大填充数
private var cpdMax = 3 //CPD 广告最大填充数
private var shMax = 0 //珊瑚 广告最大填充数
private var cpdMax = 0 //CPD 广告最大填充数
private var shLoadCountTime = 0 // 珊瑚 加载广告次数
private var cpdLoadCountTime = 0 // CPD 加载广告次数
......@@ -142,6 +144,12 @@ class TaskCpdFragment : BaseFragment(), TaskView,
if ((shMax + cpdMax) <= 0) {
hideLoading()
showToast("今日任务已完成,请明日再试")
// 跳转试玩任务
notifyDataAndShowAd()
if (AppConfig.useAppCpdModelShow) {
(activity as TaskCpdActivity).selectTwoFragment()
}
return
}
......@@ -176,7 +184,6 @@ class TaskCpdFragment : BaseFragment(), TaskView,
// 圣于地广告 循环完成后去重
if (cpdLoadCountTime++ >= cpdMax - 1) {
// notifyDataAndShowAd()
getCpdRepeatPkg()
}
}
......@@ -184,9 +191,8 @@ class TaskCpdFragment : BaseFragment(), TaskView,
override fun getCpdModelFail() {
LogUtil.d(TAG, "syd getCpdModelFail")
if (cpdLoadCountTime++ >= cpdMax - 1) {
notifyDataAndShowAd()
getCpdRepeatPkg()
}
}
......@@ -221,7 +227,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
// 数据重复
if (i != j && mFakeTaskList[i].downLoadPkgName == mFakeTaskList[j].downLoadPkgName) {
LogUtil.d(TAG, "syd currentPkgName:"+mFakeTaskList[i].downLoadPkgName)
LogUtil.d(TAG, "syd currentPkgName:" + mFakeTaskList[i].downLoadPkgName)
flag = false
break
......
......@@ -160,7 +160,7 @@ class TaskCpdHistoryFragment : LazyLoadBaseFragment(), TaskCpdHistoryView,
private fun refreshDemoTask() {
mTaskAdapter?.let {
val position = it.getPosition()
if (mFakeTaskList.size == 0 || mFakeTaskList[position].state == 3) return
if (mFakeTaskList.size == 1 || mFakeTaskList[position].state == 3) return
val currentPkgName = mFakeTaskList[position].currentPkgName
if (currentPkgName != null) {
......
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