Commit a0b51d39 authored by jyx's avatar jyx

代码优化

parent 14d42a9b
...@@ -348,7 +348,7 @@ public class VedioAdingManager { ...@@ -348,7 +348,7 @@ public class VedioAdingManager {
// 优量汇 // 优量汇
if (ylhVedioAdManager == null) { if (ylhVedioAdManager == null) {
if (activity == null) { if (activity == null) {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerError(Constant.YLH_VEDIO_AD); vedioAdingListener.vedioAdingListenerError(Constant.YLH_VEDIO_AD);
} }
return; return;
...@@ -359,7 +359,7 @@ public class VedioAdingManager { ...@@ -359,7 +359,7 @@ public class VedioAdingManager {
ylhVedioAdManager.setYlhVedioAdListener(new YlhVedioAdManager.YlhVedioAdListener() { ylhVedioAdManager.setYlhVedioAdListener(new YlhVedioAdManager.YlhVedioAdListener() {
@Override @Override
public void ylhVedioAdFail() { public void ylhVedioAdFail() {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerFail(Constant.YLH_VEDIO_AD); vedioAdingListener.vedioAdingListenerFail(Constant.YLH_VEDIO_AD);
} }
} }
...@@ -367,7 +367,7 @@ public class VedioAdingManager { ...@@ -367,7 +367,7 @@ public class VedioAdingManager {
@Override @Override
public void ylhVedioAdSuccess() { public void ylhVedioAdSuccess() {
AppConfig.ylhAdCount--; AppConfig.ylhAdCount--;
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerSuccess(Constant.YLH_VEDIO_AD); vedioAdingListener.vedioAdingListenerSuccess(Constant.YLH_VEDIO_AD);
} }
} }
...@@ -382,7 +382,7 @@ public class VedioAdingManager { ...@@ -382,7 +382,7 @@ public class VedioAdingManager {
// 穿山甲激励视频 // 穿山甲激励视频
if (csjVedioAdManager == null) { if (csjVedioAdManager == null) {
if (activity == null) { if (activity == null) {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerError(Constant.CSJ_VEDIO_AD); vedioAdingListener.vedioAdingListenerError(Constant.CSJ_VEDIO_AD);
} }
return; return;
...@@ -394,7 +394,7 @@ public class VedioAdingManager { ...@@ -394,7 +394,7 @@ public class VedioAdingManager {
csjVedioAdManager.setCsjVedioAdListener(new CsjVedioAdManager.CsjVedioAdListener() { csjVedioAdManager.setCsjVedioAdListener(new CsjVedioAdManager.CsjVedioAdListener() {
@Override @Override
public void csjVedioAdFail() { public void csjVedioAdFail() {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerFail(Constant.CSJ_VEDIO_AD); vedioAdingListener.vedioAdingListenerFail(Constant.CSJ_VEDIO_AD);
} }
} }
...@@ -402,7 +402,7 @@ public class VedioAdingManager { ...@@ -402,7 +402,7 @@ public class VedioAdingManager {
@Override @Override
public void csjVedioAdSuccess() { public void csjVedioAdSuccess() {
AppConfig.csjVedioAdCount--; AppConfig.csjVedioAdCount--;
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerSuccess(Constant.CSJ_VEDIO_AD); vedioAdingListener.vedioAdingListenerSuccess(Constant.CSJ_VEDIO_AD);
} }
} }
...@@ -417,7 +417,7 @@ public class VedioAdingManager { ...@@ -417,7 +417,7 @@ public class VedioAdingManager {
// 闪电盒子激励视频 // 闪电盒子激励视频
if (wnVedioAdManager == null) { if (wnVedioAdManager == null) {
if (activity == null) { if (activity == null) {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerError(Constant.SDHZ_VEDIO_AD); vedioAdingListener.vedioAdingListenerError(Constant.SDHZ_VEDIO_AD);
} }
return; return;
...@@ -428,14 +428,14 @@ public class VedioAdingManager { ...@@ -428,14 +428,14 @@ public class VedioAdingManager {
@Override @Override
public void wnVedioAdSuccess() { public void wnVedioAdSuccess() {
AppConfig.wnVedioAdCount--; AppConfig.wnVedioAdCount--;
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerSuccess(Constant.SDHZ_VEDIO_AD); vedioAdingListener.vedioAdingListenerSuccess(Constant.SDHZ_VEDIO_AD);
} }
} }
@Override @Override
public void wnVedioAdFail() { public void wnVedioAdFail() {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerFail(Constant.SDHZ_VEDIO_AD); vedioAdingListener.vedioAdingListenerFail(Constant.SDHZ_VEDIO_AD);
} }
} }
...@@ -450,7 +450,7 @@ public class VedioAdingManager { ...@@ -450,7 +450,7 @@ public class VedioAdingManager {
// 枫岚广告激励视频 // 枫岚广告激励视频
if (mhVedioAdManager == null) { if (mhVedioAdManager == null) {
if (activity == null) { if (activity == null) {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerError(Constant.FL_VEDIO_AD); vedioAdingListener.vedioAdingListenerError(Constant.FL_VEDIO_AD);
} }
return; return;
...@@ -461,14 +461,14 @@ public class VedioAdingManager { ...@@ -461,14 +461,14 @@ public class VedioAdingManager {
@Override @Override
public void mhVedioAdSuccess() { public void mhVedioAdSuccess() {
AppConfig.flVedioAdCount--; AppConfig.flVedioAdCount--;
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerSuccess(Constant.FL_VEDIO_AD); vedioAdingListener.vedioAdingListenerSuccess(Constant.FL_VEDIO_AD);
} }
} }
@Override @Override
public void mhVedioAdFail() { public void mhVedioAdFail() {
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerFail(Constant.FL_VEDIO_AD); vedioAdingListener.vedioAdingListenerFail(Constant.FL_VEDIO_AD);
} }
} }
...@@ -483,7 +483,7 @@ public class VedioAdingManager { ...@@ -483,7 +483,7 @@ public class VedioAdingManager {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
if (vedioAdingListener != null) { if (vedioAdingListener != null && !isHighWeight) {
vedioAdingListener.vedioAdingListenerError(bean.getCarrierType()); vedioAdingListener.vedioAdingListenerError(bean.getCarrierType());
} }
} }
......
package com.mints.goodmoney.manager package com.mints.goodmoney.manager
import com.mints.goodmoney.MintsApplication import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.mvp.model.EventMessage
import com.mints.goodmoney.utils.RxBus
import com.mints.goodmoney.utils.AppUtil import com.mints.goodmoney.utils.AppUtil
/** /**
...@@ -12,24 +9,28 @@ import com.mints.goodmoney.utils.AppUtil ...@@ -12,24 +9,28 @@ import com.mints.goodmoney.utils.AppUtil
object AppTryPlayManager { object AppTryPlayManager {
// 第一次打开时间 // 第一次打开时间
private var openTime = 0L // private var openTime = 0L
private var currentPkg = "" private var currentPkg = ""
fun toTryPlay(pkg: String) { fun toTryPlay(pkg: String) {
if (currentPkg != pkg) { if (currentPkg != pkg) {
openTime = AppUtil.getAppUseTime(MintsApplication.getContext(), pkg) // openTime = AppUtil.getAppUseTime(MintsApplication.getContext(), pkg)
AppUtil.openThirdApp(MintsApplication.getContext(), pkg) AppUtil.openThirdApp(MintsApplication.getContext(), pkg)
val eventMessage = EventMessage(Constant.IS_HIGH_TASK, pkg) // val eventMessage = EventMessage(Constant.IS_HIGH_TASK, pkg)
RxBus.getDefault().postSticky(eventMessage) // RxBus.getDefault().postSticky(eventMessage)
currentPkg = pkg currentPkg = pkg
} }
} }
fun getTryPlayIsOK(pkg: String): Boolean { fun getTryPlayIsOK(pkg: String): Boolean {
val currentUseTime = AppUtil.getAppUseTime(MintsApplication.getContext(), pkg) // val currentUseTime = AppUtil.getAppUseTime(MintsApplication.getContext(), pkg)
openTime = 0L // openTime = 0L
currentPkg = "" // currentPkg = ""
return currentUseTime - openTime >= 20 // LogUtil.d("currentUseTime ->" + currentUseTime + "-- openTime ->" + openTime)
// return currentUseTime - openTime >= 100
val timePkgUsed = AppUtil.getTimePkgUsed(MintsApplication.getContext(), pkg)
return timePkgUsed >= 30
} }
} }
\ No newline at end of file
...@@ -260,11 +260,14 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener { ...@@ -260,11 +260,14 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
Constant.CARRIER_HIGH_ACTIVITY -> { Constant.CARRIER_HIGH_ACTIVITY -> {
if (curCoin > 0) { if (curCoin > 0) {
tvAwardContent.setText("试玩奖励${curCoin}金币") tvAwardContent.setText("试玩奖励${curCoin}金币")
}
tvAwardNext.setText("领取金币") tvAwardNext.setText("领取金币")
val vo = HashMap<String, Any>() val vo = HashMap<String, Any>()
vo["carrierType"] = carrierType vo["carrierType"] = carrierType
awardPresenter.reportAddCoinMsg(vo) awardPresenter.reportAddCoinMsg(vo)
} else {
tvAwardContent.setText("很遗憾,试玩不足30秒")
tvAwardNext.setText("我知道了")
}
} }
Constant.CARRIER_SIGNIN_HOMEPAGE_CARD -> { Constant.CARRIER_SIGNIN_HOMEPAGE_CARD -> {
tvAwardContent.text = "奖励金币已发放" tvAwardContent.text = "奖励金币已发放"
......
...@@ -137,20 +137,21 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi ...@@ -137,20 +137,21 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
// 刷新喜马拉雅信息流 // 刷新喜马拉雅信息流
TTPreLoadExpressXmlyManager.getInstance().loadTtFrameLayout() TTPreLoadExpressXmlyManager.getInstance().loadTtFrameLayout()
if (AppConfig.isHighTask) { if (AppConfig.isHighTask && mCurrentPkg != null) {
disposable = RxBus.getDefault().tObservableStick(EventMessage::class.java).subscribe { if (AppTryPlayManager.getTryPlayIsOK(mCurrentPkg!!)) {
if (it.message == Constant.IS_HIGH_TASK) {
if (AppTryPlayManager.getTryPlayIsOK(it.content as String)) {
myPresenter.setHighTaskType("1") myPresenter.setHighTaskType("1")
} else { } else {
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, 0)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_HIGH_ACTIVITY)
readyGo(AwardActivity::class.java, bundle)
myPresenter.setHighTaskType("0") myPresenter.setHighTaskType("0")
} }
}
AppConfig.isHighTask = false AppConfig.isHighTask = false
} }
} }
} }
}
override fun onDestroyView() { override fun onDestroyView() {
item_clock_signview.onDestory() item_clock_signview.onDestory()
...@@ -467,9 +468,11 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi ...@@ -467,9 +468,11 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
} }
3 -> { 3 -> {
if (mCurrentPkg == null) { if (mCurrentPkg == null) {
showToast("网络出小差儿了~")
myPresenter.setHighTaskType("0") myPresenter.setHighTaskType("0")
myPresenter.getAutoUserHallBaseMsg() myPresenter.getAutoUserHallBaseMsg()
} else { } else {
AppConfig.isHighTask = true
AppTryPlayManager.toTryPlay(mCurrentPkg!!) AppTryPlayManager.toTryPlay(mCurrentPkg!!)
} }
} }
...@@ -1059,7 +1062,6 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi ...@@ -1059,7 +1062,6 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
R.id.dialog_btn_right -> { R.id.dialog_btn_right -> {
cdaa!!.dismiss() cdaa!!.dismiss()
AppConfig.isHighTask = true
vedioAdingManager.setIsHighWeight(true) vedioAdingManager.setIsHighWeight(true)
awardVedio(taskBean.otherConfig.coin, Constant.CARRIER_HIGH_ACTIVITY) awardVedio(taskBean.otherConfig.coin, Constant.CARRIER_HIGH_ACTIVITY)
......
package com.mints.goodmoney.utils package com.mints.goodmoney.utils
import android.app.Service import android.app.Service
import android.app.usage.UsageStats
import android.app.usage.UsageStatsManager import android.app.usage.UsageStatsManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
...@@ -8,6 +9,7 @@ import android.content.pm.PackageInfo ...@@ -8,6 +9,7 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import android.provider.Settings import android.provider.Settings
import com.fly.scenemodule.util.StringUtilMy
import com.mints.goodmoney.MintsApplication import com.mints.goodmoney.MintsApplication
...@@ -110,4 +112,19 @@ object AppUtil { ...@@ -110,4 +112,19 @@ object AppUtil {
return packageInfo != null return packageInfo != null
} }
fun getTimePkgUsed(paramContext: Context, paramString: String): Int {
if (StringUtilMy.stringAvalable(paramString) && checkPackInfo(paramContext, paramString) && Build.VERSION.SDK_INT >= 21) {
val usageStatsManager = paramContext.getSystemService("usagestats") as UsageStatsManager
var l = System.currentTimeMillis()
val list = usageStatsManager.queryUsageStats(4, l - 6 * 60 * 1000L, l)
if (list != null && list.size > 0) for (i in list.indices) {
val str = (list[i] as UsageStats).packageName
(list[i] as UsageStats).lastTimeUsed
l = (list[i] as UsageStats).totalTimeInForeground
if (paramString == str) return l.toInt() / 1000
}
}
return -1
}
} }
\ 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