Commit f807e383 authored by wanglei's avatar wanglei

Merge branch 'free-master' of gitlab.huolea.com:koko/easy-junk-cleaner-6-18 into free-master

parents 89ec2e83 72d49069
......@@ -7,6 +7,7 @@ import android.view.View
import android.widget.TextView
class CustomDialog(context: Context, layoutId: Int) : Dialog(context) {
private var countdownText: TextView? = null
init {
setContentView(layoutId)
......@@ -25,4 +26,12 @@ class CustomDialog(context: Context, layoutId: Int) : Dialog(context) {
}
}
fun setCountdownText(viewId: Int) {
countdownText = findViewById(viewId)
}
fun updateCountdownText(seconds: String) {
countdownText?.text = seconds
}
}
package com.test.easy.easycleanerjunk.helps.ads;
import android.content.Context;
import android.content.SharedPreferences;
import com.test.easy.easycleanerjunk.MyApplication;
......@@ -10,27 +9,27 @@ import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import android.content.SharedPreferences;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class AdDisplayUtils {
private static final int MAX_AD_DISPLAY_COUNT = 5; // 总广告展示次数限制
private static final int MAX_AD_CLICK_COUNT = 2; // 单个广告点击次数限制
private static final int DEFAULT_MAX_AD_DISPLAY_COUNT = 45; // 总广告展示次数限制默认值
private static final int DEFAULT_MAX_AD_CLICK_COUNT = 10; // 单个广告点击次数限制默认值
private static final String AD_PREFS_NAME = "ad_prefs"; // SharedPreferences 名称
private static final String AD_DISPLAY_COUNT_KEY = "ad_display_count"; // 广告展示次数的键
private static final String AD_CLICK_COUNT_KEY = "ad_click_count"; // 广告点击次数的键
private static final String MAX_AD_DISPLAY_COUNT_KEY = "max_ad_display_count"; // 总广告展示次数限制的键
private static final String MAX_AD_CLICK_COUNT_KEY = "max_ad_click_count"; // 单个广告点击次数限制的键
private static AdDisplayUtils instance; // 单例对象
private int adDisplayCount = 0; // 当前广告展示次数
private int adClickCount = 0; // 当前广告点击次数
private int maxAdDisplayCount; // 总广告展示次数限制
private int maxAdClickCount; // 单个广告点击次数限制
private String currentDate; // 当前日期
private AdDisplayUtils() {
currentDate = getCurrentDate();
SharedPreferences prefs = MyApplication.context.getSharedPreferences(AD_PREFS_NAME, 0);
maxAdDisplayCount = prefs.getInt(MAX_AD_DISPLAY_COUNT_KEY, DEFAULT_MAX_AD_DISPLAY_COUNT);
maxAdClickCount = prefs.getInt(MAX_AD_CLICK_COUNT_KEY, DEFAULT_MAX_AD_CLICK_COUNT);
adDisplayCount = prefs.getInt(getAdDisplayCountKey(), 0);
adClickCount = prefs.getInt(getAdClickCountKey(), 0);
}
......@@ -43,11 +42,14 @@ public class AdDisplayUtils {
}
public boolean shouldDisplayAd() {
return adDisplayCount < MAX_AD_DISPLAY_COUNT;
return adDisplayCount < getMaxAdDisplayCount();
}
public boolean shouldIncrementClickCount() {
return adClickCount < MAX_AD_CLICK_COUNT;
return adClickCount < getMaxAdClickCount();
}
public boolean shouldShowAd() {
return shouldDisplayAd() || shouldIncrementClickCount();
}
public void incrementAdDisplayCount() {
......@@ -95,5 +97,36 @@ public class AdDisplayUtils {
editor.putInt(getAdClickCountKey(), adClickCount);
editor.apply();
}
}
private int getMaxAdDisplayCount() {
return maxAdDisplayCount;
}
public void setMaxAdDisplayCount(int maxAdDisplayCount) {
this.maxAdDisplayCount = maxAdDisplayCount;
saveMaxAdDisplayCount();
}
private int getMaxAdClickCount() {
return maxAdClickCount;
}
public void setMaxAdClickCount(int maxAdClickCount) {
this.maxAdClickCount = maxAdClickCount;
saveMaxAdClickCount();
}
private void saveMaxAdDisplayCount() {
SharedPreferences prefs = MyApplication.context.getSharedPreferences(AD_PREFS_NAME, 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(MAX_AD_DISPLAY_COUNT_KEY, maxAdDisplayCount);
editor.apply();
}
private void saveMaxAdClickCount() {
SharedPreferences prefs = MyApplication.context.getSharedPreferences(AD_PREFS_NAME, 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(MAX_AD_CLICK_COUNT_KEY, maxAdClickCount);
editor.apply();
}
}
......@@ -3,6 +3,7 @@ package com.test.easy.easycleanerjunk.helps.ads
import android.app.Activity
import android.app.Dialog
import android.os.Bundle
import android.os.CountDownTimer
import android.util.Log
import android.view.ViewGroup
import android.widget.Toast
......@@ -31,9 +32,7 @@ import com.test.easy.easycleanerjunk.helps.BaseApplication
import com.test.easy.easycleanerjunk.helps.ConfigHelper
import com.test.easy.easycleanerjunk.utils.SPUtils
import org.json.JSONObject
import java.util.Calendar
import java.util.UUID
import kotlin.system.exitProcess
object AdmobUtils {
......@@ -63,31 +62,35 @@ object AdmobUtils {
onLoad?.invoke()
return
}
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onLoad?.invoke()
return
}
val reqId = UUID.randomUUID().toString()
val obj = JSONObject()
obj.put("req_id", reqId)
obj.put("ad_type", "openAd")
AppOpenAd.load(
BaseApplication.context,
ConfigHelper.openAdmobId,
mRequest,
object : AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(ad: AppOpenAd) {
openLoadTime = System.currentTimeMillis()
mOpenAd = ad
onLoad?.invoke()
pull(ad.responseInfo, "openAd", reqId = reqId)
ad.onPaidEventListener = EventOnPaidEventListener(ad)
// Log.e("MXL", "拉取成功: ", )
}
BaseApplication.context,
ConfigHelper.openAdmobId,
mRequest,
object : AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(ad: AppOpenAd) {
openLoadTime = System.currentTimeMillis()
mOpenAd = ad
onLoad?.invoke()
pull(ad.responseInfo, "openAd", reqId = reqId)
ad.onPaidEventListener = EventOnPaidEventListener(ad)
// Log.e("MXL", "拉取成功: ", )
}
override fun onAdFailedToLoad(p0: LoadAdError) {
mOpenAd = null
onLoad?.invoke()
pull(p0.responseInfo, "openAd", p0.message, reqId = reqId)
// Log.e("MXL", "onAdFailedToLoad: " + p0.message)
}
})
override fun onAdFailedToLoad(p0: LoadAdError) {
mOpenAd = null
onLoad?.invoke()
pull(p0.responseInfo, "openAd", p0.message, reqId = reqId)
// Log.e("MXL", "onAdFailedToLoad: " + p0.message)
}
})
}
fun isOpenAdLoaded() = mOpenAd != null
......@@ -96,6 +99,10 @@ object AdmobUtils {
if (activity.isFinishing || activity.isDestroyed) {
return
}
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onHidden?.invoke()
return
}
val obj = JSONObject()
obj.put("ad_unit", "openAd")
// if (mOpenAd == null || skip) {
......@@ -154,7 +161,9 @@ object AdmobUtils {
fun showNativeAd(activity: Activity?, parent: ViewGroup) {
val obj = JSONObject()
obj.put("ad_unit", "NativeAd")
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
return
}
loadingListener = {
if (System.currentTimeMillis() - nativeLoadTime <= 1000 * 60 * 60) {
nativeAd?.let {
......@@ -192,6 +201,9 @@ object AdmobUtils {
return
}
isLoading = true
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
return
}
val reqId = UUID.randomUUID().toString()
val obj = JSONObject()
......@@ -199,7 +211,7 @@ object AdmobUtils {
obj.put("ad_type", "nativeAd")
val adLoader = AdLoader.Builder(
BaseApplication.context, ConfigHelper.nativeAdmobId
BaseApplication.context, ConfigHelper.nativeAdmobId
).forNativeAd {
nativeLoadTime = System.currentTimeMillis()
nativeAd = it
......@@ -224,53 +236,52 @@ object AdmobUtils {
}
private var interAd: InterstitialAd? = null
fun isInterLoaded() = interAd != null
fun loadInterstitialAd(activity: Activity, onLoad: (() -> Unit)? = null) {
if (interAd != null) {
onLoad?.invoke()
return
}
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onLoad?.invoke()
return
}
val reqId = UUID.randomUUID().toString()
val obj = JSONObject()
obj.put("req_id", reqId)
obj.put("ad_type", "interAd")
obj.put("from", activity.javaClass.simpleName)
InterstitialAd.load(
activity,
ConfigHelper.interAdmobId,
mRequest,
object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(p0: LoadAdError) {
Log.d("glc", "广告拉取失败:" + p0.message)
interAd = null
onLoad?.invoke()
pull(p0.responseInfo, "interAd", p0.message, reqId = reqId)
if (BuildConfig.DEBUG) {
Toast.makeText(
BaseApplication.context,
"拉取失败" + p0.message,
Toast.LENGTH_SHORT
)
}
activity,
ConfigHelper.interAdmobId,
mRequest,
object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(p0: LoadAdError) {
interAd = null
onLoad?.invoke()
pull(p0.responseInfo, "interAd", p0.message, reqId = reqId)
if (BuildConfig.DEBUG) {
Toast.makeText(
BaseApplication.context,
"拉取失败" + p0.message,
Toast.LENGTH_SHORT
)
}
// Log.e("MXL", "InterAdFailedToLoad: " + p0.message)
}
}
override fun onAdLoaded(ad: InterstitialAd) {
interAd = ad
onLoad?.invoke()
interLoadTime = System.currentTimeMillis()
pull(ad.responseInfo, "interAd", reqId = reqId)
ad.onPaidEventListener = EventOnPaidEventListener(ad)
// Log.e("MXL", "InteronAdLoaded: ")
}
})
override fun onAdLoaded(ad: InterstitialAd) {
interAd = ad
onLoad?.invoke()
interLoadTime = System.currentTimeMillis()
pull(ad.responseInfo, "interAd", reqId = reqId)
ad.onPaidEventListener = EventOnPaidEventListener(ad)
}
})
}
private fun isAdExpired():Boolean{
private fun isAdExpired(): Boolean {
return System.currentTimeMillis() - interLoadTime > 1000 * 60 * 60
}
var adDisplayInterval: Int = 10
var adLastDisplayTime: Long = 0
fun showInterstitialAd(activity: Activity, isLoadAdNow: Boolean = false, onHidden: (() -> Unit)? = null) {
if (activity.isFinishing || activity.isDestroyed) {
return
......@@ -283,24 +294,54 @@ object AdmobUtils {
return
}
if(!AdDisplayUtils.getInstance().shouldDisplayAd()){
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onHidden?.invoke()
return
}
val interval = isTimeElapsed()
if(!AdDisplayUtils.getInstance().shouldIncrementClickCount()){
onHidden?.invoke()
return
if (interval <= 0) {
showCachedInterstitialAd(activity, isLoadAdNow, onHidden)
} else {
showIntervalDialogAndShowAd(activity, isLoadAdNow, onHidden, interval)
}
}
private fun showIntervalDialogAndShowAd(activity: Activity, isLoadAdNow: Boolean, onHidden: (() -> Unit)?, interval: Int) {
val customDialog = CustomDialog(activity, R.layout.dialog_ad_loading)
customDialog.setCountdownText(R.id.dialog_ad_loading_text)
val countdownTimer = object : CountDownTimer((interval * 1000).toLong(), 1000) {
override fun onTick(millisUntilFinished: Long) {
val seconds = (millisUntilFinished / 1000).toInt()
customDialog.updateCountdownText("Advertising in preparation ($seconds" + "s)...")
}
override fun onFinish() {
showCachedInterstitialAd(activity, isLoadAdNow, onHidden)
customDialog?.dismiss()
customDialog.dismiss()
}
}
countdownTimer.start()
customDialog.show()
}
private fun showCachedInterstitialAd(activity: Activity, isLoadAdNow: Boolean, onHidden: (() -> Unit)?) {
if (interAd != null) {
displayInterstitialAd(activity,onHidden)
displayInterstitialAd(activity, onHidden)
} else {
showAdDialogAndLoadInterstitial(activity,isLoadAdNow, onHidden)
showAdDialogAndLoadInterstitial(activity, isLoadAdNow, onHidden)
}
}
private fun showAdDialogAndLoadInterstitial(activity: Activity,isLoadAdNow: Boolean,onHidden: (() -> Unit)?){
private fun isTimeElapsed(): Int {
val nowTime = System.currentTimeMillis() / 1000
return (adDisplayInterval - (nowTime - adLastDisplayTime).toInt())
}
private fun showAdDialogAndLoadInterstitial(activity: Activity, isLoadAdNow: Boolean, onHidden: (() -> Unit)?) {
var mDialog: Dialog? = null
mDialog = CustomDialog(activity, R.layout.dialog_ad_loading)
mDialog.show()
......@@ -319,7 +360,7 @@ object AdmobUtils {
}
}
private fun displayInterstitialAd(activity: Activity,onHidden: (() -> Unit)? = null){
private fun displayInterstitialAd(activity: Activity, onHidden: (() -> Unit)? = null) {
val thisInterAd = interAd
interAd = null
thisInterAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
......@@ -343,16 +384,17 @@ object AdmobUtils {
override fun onAdShowedFullScreenContent() {
show(thisInterAd?.responseInfo, "interAd", activity)
AdDisplayUtils.getInstance().incrementAdDisplayCount()
adLastDisplayTime = System.currentTimeMillis() / 1000
}
}
thisInterAd?.show(activity)
}
private fun pull(
responseInfo: ResponseInfo?,
adUnit: String,
error: String? = null,
reqId: String? = null
responseInfo: ResponseInfo?,
adUnit: String,
error: String? = null,
reqId: String? = null
) {
val obj = JSONObject()
if (responseInfo != null) {
......@@ -361,9 +403,9 @@ object AdmobUtils {
obj.put("source", response.adSourceName)
val credentials = mapOf(
"placementid" to response.credentials.get("placementid"),
"appid" to response.credentials.get("appid"),
"pubid" to response.credentials.get("pubid")
"placementid" to response.credentials.get("placementid"),
"appid" to response.credentials.get("appid"),
"pubid" to response.credentials.get("pubid")
)
obj.put("credentials", credentials.toString())
}
......@@ -387,9 +429,9 @@ object AdmobUtils {
obj.put("ad_unit", adUnit)
obj.put("networkname", responseInfo?.mediationAdapterClassName)
val credentials = mapOf(
"placementid" to response?.credentials?.get("placementid"),
"appid" to response?.credentials?.get("appid"),
"pubid" to response?.credentials?.get("pubid")
"placementid" to response?.credentials?.get("placementid"),
"appid" to response?.credentials?.get("appid"),
"pubid" to response?.credentials?.get("pubid")
)
obj.put("credentials", credentials.toString())
obj.put("session_id", responseInfo?.responseId)
......@@ -406,9 +448,9 @@ object AdmobUtils {
obj.put("ad_unit", adUnit)
val credentials = mapOf(
"placementid" to response?.credentials?.get("placementid"),
"appid" to response?.credentials?.get("appid"),
"pubid" to response?.credentials?.get("pubid")
"placementid" to response?.credentials?.get("placementid"),
"appid" to response?.credentials?.get("appid"),
"pubid" to response?.credentials?.get("pubid")
)
obj.put("credentials", credentials.toString())
obj.put("session_id", responseInfo?.responseId)
......@@ -456,8 +498,8 @@ object AdmobUtils {
if (currentTaichiTroasCache >= 0.01) {//如果超过0.01就触发一次tROAS taichi事件
val roasbundle = Bundle()
roasbundle.putDouble(
FirebaseAnalytics.Param.VALUE,
currentTaichiTroasCache.toDouble()
FirebaseAnalytics.Param.VALUE,
currentTaichiTroasCache.toDouble()
)
roasbundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
Firebase.analytics.logEvent("Total_Ads_Revenue_001", roasbundle)
......
......@@ -22,6 +22,7 @@
<TextView
android:id="@+id/dialog_ad_loading_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="11dp"
......
......@@ -118,7 +118,8 @@
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginTop="14dp">
<com.noober.background.view.BLLinearLayout
android:id="@+id/id_clean_junk"
......@@ -264,7 +265,7 @@
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp">
android:layout_marginTop="10dp">
<com.noober.background.view.BLLinearLayout
android:id="@+id/id_large_file"
......@@ -436,7 +437,7 @@
android:id="@+id/id_similar_photos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginBottom="13dp"
android:gravity="center_vertical">
<androidx.appcompat.widget.AppCompatImageView
......@@ -450,7 +451,10 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp"
android:layout_weight="1"
android:text="Similar Photos" />
android:text="Similar Photos"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
......@@ -461,11 +465,18 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginHorizontal="14dp"
android:background="#F8F8F8" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/id_screenshot_clean"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="13dp"
android:layout_marginBottom="13dp"
android:gravity="center_vertical">
<androidx.appcompat.widget.AppCompatImageView
......@@ -479,6 +490,9 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold"
android:text="Screenshot Clean" />
<androidx.appcompat.widget.AppCompatImageView
......
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