Commit 87093394 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 5ca5f65d
......@@ -263,18 +263,16 @@ dependencies {
// 喜马拉雅 已集成
// 微转阅读
implementation (name:'articlesdk-v1.0.6.202012121917-x',ext:'aar')
//天卓SDK的珊瑚2.1组件
//快手SDK 2.6.5之后的版本,SDK有依赖appcompat-v7
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
// implementation 'com.android.support:appcompat-v7:28.0.0'
// implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation(name: 'tzsdk_coral-2.1.0-20200807130815-release', ext: 'aar')
implementation(name: 'adapt-1.3.3', ext: 'aar')
implementation(name: 'commonbase-1.0.2', ext: 'aar')
implementation(name: 'discovery-2.0.17', ext: 'aar')
implementation(name: 'shanhuAD-1.3.1', ext: 'aar')
implementation(name: 'tzsdk_core-3.0.0-20200807130815-release', ext: 'aar')
//天卓SDK的珊瑚2.1组件
implementation(name: 'tzsdk_coral-2.1.0-20200807130815-release', ext: 'aar')
implementation(name: 'tzsdk_reporter-3.0.0-20200807130815-release', ext: 'aar')
......
......@@ -22,6 +22,7 @@ object BxmManager {
private const val APP_ID = "3b08a06c36a04eb7ad31ee31547b9e69"
private const val BUTTON_AD_SPOT_ID = "807020001003"
// private const val BUTTON_AD_SPOT_ID = "807020001004"
private var bdAdvanceButtonAd: BDAdvanceButtonAd? = null
......
package com.mints.goodmoney.manager
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface
......@@ -35,12 +36,15 @@ object DownloadApkManager {
private var cachePath = MintsApplication.getContext().externalCacheDir?.path + "/Download/"
private var canOnceInstallApk = false//8.0以上系统 防止首次授权时 未安装apk调用
private var activity: Activity? = null
/**
* 下载apk
*
* url:下载地址
*/
fun downloadApk(url: String) {
fun downloadApk(activity: Activity, url: String) {
this.activity = activity
apkName = MD5.GetMD5Code(System.currentTimeMillis().toString() + UserManager.getInstance().userID) + ".apk"
mDownloadListener?.onDownloadStart()
......@@ -53,7 +57,8 @@ object DownloadApkManager {
* url:下载地址
* name:应用名称
*/
fun downloadApk(url: String, name: String) {
fun downloadApk(activity: Activity, url: String, name: String) {
this.activity = activity
this.apkName = "$name.apk"
// 判断apk是否存在
......@@ -90,7 +95,9 @@ object DownloadApkManager {
}
private fun download(url: String) {
downloadProgressDialog = DownloadProgressDialog(ForegroundOrBackground.getApp_activity())
if (activity == null) return
downloadProgressDialog = DownloadProgressDialog(activity!!)
downloadProgressDialog!!.show()
val context = MintsApplication.getContext()
......@@ -123,12 +130,13 @@ object DownloadApkManager {
* 预安装,授权校验
*/
private fun preInstallApk() {
if (activity == null) return
val context = MintsApplication.getContext()
// 8.0以上系统设置安装未知来源权限
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val haveInstallPermission = context.getPackageManager().canRequestPackageInstalls()
if (!haveInstallPermission) {
showAlert(ForegroundOrBackground.getApp_activity(), "安装权限", "需要打开允许来自此来源,请去设置中开启此权限",
showAlert(activity!!, "安装权限", "需要打开允许来自此来源,请去设置中开启此权限",
DialogInterface.OnClickListener { dialog, which ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//此方法需要API>=26才能使用
......@@ -161,8 +169,9 @@ object DownloadApkManager {
*/
@RequiresApi(api = Build.VERSION_CODES.O)
private fun toInstallPermissionSettingIntent() {
if (activity == null) return
canOnceInstallApk = true
val context = ForegroundOrBackground.getApp_activity()
val context = activity!!
val packageURI = Uri.parse("package:" + context.getPackageName())
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI)
context.startActivity(intent)
......@@ -172,8 +181,9 @@ object DownloadApkManager {
* 安装apk包
*/
private fun installApk() {
if (activity == null) return
try {
val context = ForegroundOrBackground.getApp_activity()
val context = activity!!
val intent = Intent(Intent.ACTION_VIEW)
val file = File(cachePath + apkName)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
......@@ -203,6 +213,7 @@ object DownloadApkManager {
fun destroy() {
this.downloadProgressDialog = null
this.mDownloadListener = null
this.activity = null
}
fun setOnMyDownloadListener(onMyDownloadListener: OnMyDownloadListener?) {
......
package com.mints.goodmoney.manager
import android.app.Application
import com.mints.goodmoney.BuildConfig
import com.mints.goodmoney.MintsApplication
import com.mints.library.utils.CommonUtils
import com.tz.sdk.core.engine.ADEngine
......@@ -22,7 +23,7 @@ object TzManager {
.appKey("547ffff6446c5a8acd4175fb7a71a0d1")
.appSecret("1c00e59f2257bdfdd4ad9363b41621b5")
.appChannel(td_channel_id)
.forTest(true)
.forTest(BuildConfig.DEBUG)
.build(),
object : IADEngineState {
override fun onIdle() {}
......
......@@ -22,6 +22,7 @@ import com.mints.goodmoney.ui.widgets.CustomDialogAsApple
import com.mints.goodmoney.ui.widgets.DialogListener
import com.mints.goodmoney.ui.widgets.TaskDialog
import com.mints.goodmoney.utils.AppUtil
import com.mints.goodmoney.utils.CacheUtil
import com.mints.goodmoney.utils.SpacesItemDecoration
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshListener
......@@ -53,9 +54,6 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
// APP下载回调广播
private var mReceiverBroadcastReceiver: BroadcastReceiver? = null
// 是否刷新按钮状态
private var isRefreshState = false
companion object {
const val TASK_COIN = "task_coin"
const val TASK_USE_TIME = "task_use_time"
......@@ -103,6 +101,9 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
override fun onResume() {
super.onResume()
DownloadApkManager.tryOnceInstallApk()
refreshDemoTask()
}
......@@ -110,15 +111,10 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
* 刷新高额任务
*/
private fun refreshDemoTask() {
if (isRefreshState) {
isRefreshState = !isRefreshState
return
}
mTaskAdapter?.let {
if (mFakeTaskList.size == 0) return
val currentPkgName = mFakeTaskList[it.getPosition()].currentPkgName
if (mFakeTaskList.size == 0 || mFakeTaskList[it.getPosition()].state == 3) return
val currentPkgName = mFakeTaskList[it.getPosition()].currentPkgName
if (currentPkgName != null) {
if (AppTryPlayManager.getTryPlayIsOK(currentPkgName, needUseTime)) {
// 完成试玩任务
......@@ -178,7 +174,7 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
}
override fun onLoadFail() {
showToast("加载失败,请刷新重试")
showToast("加载失败,请下拉刷新重试")
hideLoading()
srl_task.finishRefresh(false)
......@@ -186,20 +182,20 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
override fun onGetDownloadProcess(downloadProcess: DownloadProcess?) {
// 点击之后回调下载数据
isRefreshState = false
mDownloadProcess = downloadProcess
// 跳转去下载
val downloadUrl = downloadProcess!!.downloadUrl
val packageName = downloadProcess.packageName
DownloadApkManager.setOnMyDownloadListener(this)
DownloadApkManager.downloadApk(downloadUrl, packageName)
DownloadApkManager.downloadApk(this,downloadUrl, packageName)
}
override fun onDestroy() {
mCoralDownload?.destroy()
mDownloadProcess = null
DownloadApkManager.destroy()
CacheUtil.clearAllCache(context)
if (mReceiverBroadcastReceiver != null) {
mContext.stopService(Intent(context, AppInstallService::class.java))
mContext.unregisterReceiver(mReceiverBroadcastReceiver)
......@@ -234,8 +230,6 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
// 上报安装完成
mDownloadProcess?.reportInstallSuccess(false)
isRefreshState = true
}
} catch (e: Exception) {
e.printStackTrace()
......@@ -281,7 +275,6 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
}
}
2 -> {
isRefreshState = true
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, mCoin)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_CPD)
......
......@@ -39,7 +39,7 @@ class WebActivity : BaseActivity(), View.OnClickListener {
if (!TextUtils.isEmpty(url)
&& url!!.contains(".apk")) {
DownloadApkManager.downloadApk(url!!)
DownloadApkManager.downloadApk(this,url!!)
return
}
......@@ -59,7 +59,7 @@ class WebActivity : BaseActivity(), View.OnClickListener {
url: String
): Boolean {
if (url.contains(".apk")) {
DownloadApkManager.downloadApk(url!!)
DownloadApkManager.downloadApk(this@WebActivity,url!!)
return true
}
......
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