Commit 48634236 authored by jyx's avatar jyx

代码优化

parent 87093394
......@@ -7,6 +7,7 @@ import com.mints.goodmoney.R
import com.mints.goodmoney.ui.widgets.CustomDialogAsApple
import com.mints.goodmoney.ui.widgets.DialogListener
import com.mints.goodmoney.utils.AppUtil
import com.mints.goodmoney.utils.LogUtil
/**
* APP试玩管理类
......@@ -17,8 +18,10 @@ object AppTryPlayManager {
AppUtil.openThirdApp(MintsApplication.getContext(), pkg)
}
fun getTryPlayIsOK(pkg: String, useTime :Int): Boolean {
fun getTryPlayIsOK(pkg: String, useTime: Int): Boolean {
val timePkgUsed = AppUtil.getTimePkgUsed(MintsApplication.getContext(), pkg)
LogUtil.d("AAAAAAAAA" + timePkgUsed)
return timePkgUsed >= useTime
}
......
......@@ -19,7 +19,6 @@ 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.ForegroundOrBackground
import com.mints.goodmoney.utils.MD5
import java.io.File
......@@ -134,7 +133,7 @@ object DownloadApkManager {
val context = MintsApplication.getContext()
// 8.0以上系统设置安装未知来源权限
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val haveInstallPermission = context.getPackageManager().canRequestPackageInstalls()
val haveInstallPermission = context.packageManager.canRequestPackageInstalls()
if (!haveInstallPermission) {
showAlert(activity!!, "安装权限", "需要打开允许来自此来源,请去设置中开启此权限",
DialogInterface.OnClickListener { dialog, which ->
......@@ -172,7 +171,7 @@ object DownloadApkManager {
if (activity == null) return
canOnceInstallApk = true
val context = activity!!
val packageURI = Uri.parse("package:" + context.getPackageName())
val packageURI = Uri.parse("package:" + context.packageName)
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI)
context.startActivity(intent)
}
......
......@@ -54,6 +54,9 @@ 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"
......@@ -111,27 +114,41 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
* 刷新高额任务
*/
private fun refreshDemoTask() {
if (isRefreshState) {
isRefreshState = !isRefreshState
return
}
isRefreshState = !isRefreshState
mTaskAdapter?.let {
if (mFakeTaskList.size == 0 || mFakeTaskList[it.getPosition()].state == 3) return
if (mFakeTaskList.size == 0) return
val position = it.getPosition()
val currentPkgName = mFakeTaskList[position].currentPkgName
val currentPkgName = mFakeTaskList[it.getPosition()].currentPkgName
if (currentPkgName != null) {
if (AppTryPlayManager.getTryPlayIsOK(currentPkgName, needUseTime)) {
// 完成试玩任务
mFakeTaskList[it.getPosition()].state = 2
it.notifyItemChanged(it.getPosition())
mFakeTaskList[position].state = 2
it.notifyItemChanged(position)
// 上报激活完成
mDownloadProcess?.reportAppActivated()
} else {
// 试玩时间不足
mFakeTaskList[it.getPosition()].state = 0
it.notifyItemChanged(it.getPosition())
if (AppTryPlayManager.getTryPlayIsOK(currentPkgName, 5)) {
// 试玩时间不足
mFakeTaskList[position].state = 4
it.notifyItemChanged(it.getPosition())
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, 0)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_CPD)
readyGo(AwardActivity::class.java, bundle)
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, 0)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_CPD)
readyGo(AwardActivity::class.java, bundle)
} else {
// 试玩时间不足5秒
mFakeTaskList[position].state = 1
it.notifyItemChanged(it.getPosition())
}
}
}
}
......@@ -154,6 +171,7 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
}
override fun onRefresh(refreshLayout: RefreshLayout) {
isRefreshState = false
loadData()
}
......@@ -181,6 +199,8 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
}
override fun onGetDownloadProcess(downloadProcess: DownloadProcess?) {
isRefreshState = false
// 点击之后回调下载数据
mDownloadProcess = downloadProcess
......@@ -188,7 +208,7 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
val downloadUrl = downloadProcess!!.downloadUrl
val packageName = downloadProcess.packageName
DownloadApkManager.setOnMyDownloadListener(this)
DownloadApkManager.downloadApk(this,downloadUrl, packageName)
DownloadApkManager.downloadApk(this, downloadUrl, packageName)
}
override fun onDestroy() {
......@@ -222,6 +242,8 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
if (intent == null) return
try {
taskDialog?.dismiss()
val pkg = intent.getStringExtra("pkg")
mTaskAdapter?.let {
mFakeTaskList[it.getPosition()].currentPkgName = pkg
......@@ -230,6 +252,7 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
// 上报安装完成
mDownloadProcess?.reportInstallSuccess(false)
isRefreshState = false
}
} catch (e: Exception) {
e.printStackTrace()
......@@ -261,7 +284,7 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
showToast("跳转去试玩")
isRefreshState = false
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
......@@ -289,6 +312,28 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
3 -> {
showToast("当前任务已完成,试试其他任务吧!")
}
4 -> {
mTaskAdapter?.let {
val currentPkgName = mFakeTaskList[it.getPosition()].currentPkgName
if (currentPkgName == null) {
showToast("任务异常,请重试~")
mFakeTaskList[it.getPosition()].state = 0
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
isRefreshState = false
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
showToast("未找到当前APP、可能被卸载,请重试~")
// 重置当前列表状态
mFakeTaskList[it.getPosition()].state = 0
it.notifyItemChanged(it.getPosition())
}
}
}
}
}
}
......
......@@ -49,7 +49,7 @@ class WrapperActivity : BaseActivity(), View.OnClickListener {
Constant.WRAPPER_TYPE_NEWS -> {
tv_title.text = "新闻"
val rsNewsFragment = RsNewsFragment()
if (!rsNewsFragment.isAdded()) {
if (!rsNewsFragment.isAdded) {
// 提交事务
supportFragmentManager.beginTransaction()
.add(R.id.flWrapper, rsNewsFragment).commitAllowingStateLoss()
......@@ -58,7 +58,7 @@ class WrapperActivity : BaseActivity(), View.OnClickListener {
Constant.WRAPPER_TYPE_BOOK -> {
tv_title.text = "书城"
val zhangyueFragment = MyZhangyueFragment()
if (!zhangyueFragment.isAdded()) {
if (!zhangyueFragment.isAdded) {
// 提交事务
supportFragmentManager.beginTransaction()
.add(R.id.flWrapper, zhangyueFragment).commit()
......
......@@ -174,7 +174,7 @@ class XmlyPlayActivity : BaseActivity(), View.OnClickListener, XmlyPlayAdapter.O
override fun onRefresh(refreshLayout: RefreshLayout) {
xmlyPage = 1
xmlyData.clear()
// xmlyData.clear()
loadData()
}
......@@ -197,6 +197,7 @@ class XmlyPlayActivity : BaseActivity(), View.OnClickListener, XmlyPlayAdapter.O
*/
private fun getDataSuc(list: List<Track>) {
if (::xmlyPlayAdapter.isInitialized) {
xmlyData.clear()
xmlyData.addAll(list)
if (xmlyPage == 1) {
srl_xmly.finishRefresh(true)
......
......@@ -25,7 +25,8 @@ class TaskAdapter(val dataList: List<TzTaskBean>, val context: Context) : Recycl
val ivAvatar: ImageView = view.findViewById(R.id.item_iv_avatar)
val tvTitle: TextView = view.findViewById(R.id.item_tv_title)
val tvCoin: TextView = view.findViewById(R.id.item_tv_coin)
// val tvText: TextView = view.findViewById(R.id.item_tv_text)
// val tvText: TextView = view.findViewById(R.id.item_tv_text)
val btnSubmit: Button = view.findViewById(R.id.item_btn_submit)
}
......@@ -46,6 +47,7 @@ class TaskAdapter(val dataList: List<TzTaskBean>, val context: Context) : Recycl
1 -> holder.btnSubmit.text = "去试玩"
2 -> holder.btnSubmit.text = "立即领取"
3 -> holder.btnSubmit.text = "已完成"
4 -> holder.btnSubmit.text = "继续试玩"
}
//当前选中
......
package com.mints.goodmoney.ui.widgets
import android.app.Activity
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.content.Context
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.wechat.friends.Wechat
import com.downloader.Progress
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.login.LoginApi
import com.mints.goodmoney.login.OnLoginListener
import com.mints.goodmoney.mvp.model.DrawcashBean
import com.mints.goodmoney.mvp.model.WXInfo
import com.mints.goodmoney.mvp.presenters.SettingsPresenter
import com.mints.goodmoney.mvp.views.SettingsView
import com.mints.goodmoney.ui.activitys.AccountMergeActivity
import com.mints.goodmoney.ui.activitys.AwardActivity
import com.mints.goodmoney.utils.ToastUtil
import com.mints.goodmoney.utils.Utils
import com.mints.library.utils.json.JsonUtil
import com.mints.library.utils.nodoubleclick.AntiShake
import java.util.*
/**
* 下载进度弹窗
*/
class DownloadProgressDialog(context: Activity) :
class DownloadProgressDialog(context: Context) :
Dialog(context, R.style.dialog), View.OnClickListener {
private var tvDownloadProgress: TextView? = null
......@@ -55,7 +38,7 @@ class DownloadProgressDialog(context: Activity) :
}
findViewById<ImageView>(R.id.iv_download_quit).setOnClickListener(this)
tvDownloadProgress = findViewById<TextView>(R.id.tv_download_progress)
tvDownloadProgress = findViewById(R.id.tv_download_progress)
}
override fun onClick(v: View) {
......
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