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 ...@@ -7,6 +7,7 @@ import android.view.View
import android.widget.TextView import android.widget.TextView
class CustomDialog(context: Context, layoutId: Int) : Dialog(context) { class CustomDialog(context: Context, layoutId: Int) : Dialog(context) {
private var countdownText: TextView? = null
init { init {
setContentView(layoutId) setContentView(layoutId)
...@@ -25,4 +26,12 @@ class CustomDialog(context: Context, layoutId: Int) : Dialog(context) { ...@@ -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; package com.test.easy.easycleanerjunk.helps.ads;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import com.test.easy.easycleanerjunk.MyApplication; import com.test.easy.easycleanerjunk.MyApplication;
...@@ -10,27 +9,27 @@ import java.util.Calendar; ...@@ -10,27 +9,27 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; 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 { public class AdDisplayUtils {
private static final int MAX_AD_DISPLAY_COUNT = 5; // 总广告展示次数限制 private static final int DEFAULT_MAX_AD_DISPLAY_COUNT = 45; // 总广告展示次数限制默认值
private static final int MAX_AD_CLICK_COUNT = 2; // 单个广告点击次数限制 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_PREFS_NAME = "ad_prefs"; // SharedPreferences 名称
private static final String AD_DISPLAY_COUNT_KEY = "ad_display_count"; // 广告展示次数的键 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 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 static AdDisplayUtils instance; // 单例对象
private int adDisplayCount = 0; // 当前广告展示次数 private int adDisplayCount = 0; // 当前广告展示次数
private int adClickCount = 0; // 当前广告点击次数 private int adClickCount = 0; // 当前广告点击次数
private int maxAdDisplayCount; // 总广告展示次数限制
private int maxAdClickCount; // 单个广告点击次数限制
private String currentDate; // 当前日期 private String currentDate; // 当前日期
private AdDisplayUtils() { private AdDisplayUtils() {
currentDate = getCurrentDate(); currentDate = getCurrentDate();
SharedPreferences prefs = MyApplication.context.getSharedPreferences(AD_PREFS_NAME, 0); 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); adDisplayCount = prefs.getInt(getAdDisplayCountKey(), 0);
adClickCount = prefs.getInt(getAdClickCountKey(), 0); adClickCount = prefs.getInt(getAdClickCountKey(), 0);
} }
...@@ -43,11 +42,14 @@ public class AdDisplayUtils { ...@@ -43,11 +42,14 @@ public class AdDisplayUtils {
} }
public boolean shouldDisplayAd() { public boolean shouldDisplayAd() {
return adDisplayCount < MAX_AD_DISPLAY_COUNT; return adDisplayCount < getMaxAdDisplayCount();
} }
public boolean shouldIncrementClickCount() { public boolean shouldIncrementClickCount() {
return adClickCount < MAX_AD_CLICK_COUNT; return adClickCount < getMaxAdClickCount();
}
public boolean shouldShowAd() {
return shouldDisplayAd() || shouldIncrementClickCount();
} }
public void incrementAdDisplayCount() { public void incrementAdDisplayCount() {
...@@ -95,5 +97,36 @@ public class AdDisplayUtils { ...@@ -95,5 +97,36 @@ public class AdDisplayUtils {
editor.putInt(getAdClickCountKey(), adClickCount); editor.putInt(getAdClickCountKey(), adClickCount);
editor.apply(); 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 ...@@ -3,6 +3,7 @@ package com.test.easy.easycleanerjunk.helps.ads
import android.app.Activity import android.app.Activity
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.os.CountDownTimer
import android.util.Log import android.util.Log
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
...@@ -31,9 +32,7 @@ import com.test.easy.easycleanerjunk.helps.BaseApplication ...@@ -31,9 +32,7 @@ import com.test.easy.easycleanerjunk.helps.BaseApplication
import com.test.easy.easycleanerjunk.helps.ConfigHelper import com.test.easy.easycleanerjunk.helps.ConfigHelper
import com.test.easy.easycleanerjunk.utils.SPUtils import com.test.easy.easycleanerjunk.utils.SPUtils
import org.json.JSONObject import org.json.JSONObject
import java.util.Calendar
import java.util.UUID import java.util.UUID
import kotlin.system.exitProcess
object AdmobUtils { object AdmobUtils {
...@@ -63,6 +62,10 @@ object AdmobUtils { ...@@ -63,6 +62,10 @@ object AdmobUtils {
onLoad?.invoke() onLoad?.invoke()
return return
} }
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onLoad?.invoke()
return
}
val reqId = UUID.randomUUID().toString() val reqId = UUID.randomUUID().toString()
val obj = JSONObject() val obj = JSONObject()
obj.put("req_id", reqId) obj.put("req_id", reqId)
...@@ -96,6 +99,10 @@ object AdmobUtils { ...@@ -96,6 +99,10 @@ object AdmobUtils {
if (activity.isFinishing || activity.isDestroyed) { if (activity.isFinishing || activity.isDestroyed) {
return return
} }
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onHidden?.invoke()
return
}
val obj = JSONObject() val obj = JSONObject()
obj.put("ad_unit", "openAd") obj.put("ad_unit", "openAd")
// if (mOpenAd == null || skip) { // if (mOpenAd == null || skip) {
...@@ -154,7 +161,9 @@ object AdmobUtils { ...@@ -154,7 +161,9 @@ object AdmobUtils {
fun showNativeAd(activity: Activity?, parent: ViewGroup) { fun showNativeAd(activity: Activity?, parent: ViewGroup) {
val obj = JSONObject() val obj = JSONObject()
obj.put("ad_unit", "NativeAd") obj.put("ad_unit", "NativeAd")
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
return
}
loadingListener = { loadingListener = {
if (System.currentTimeMillis() - nativeLoadTime <= 1000 * 60 * 60) { if (System.currentTimeMillis() - nativeLoadTime <= 1000 * 60 * 60) {
nativeAd?.let { nativeAd?.let {
...@@ -192,6 +201,9 @@ object AdmobUtils { ...@@ -192,6 +201,9 @@ object AdmobUtils {
return return
} }
isLoading = true isLoading = true
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
return
}
val reqId = UUID.randomUUID().toString() val reqId = UUID.randomUUID().toString()
val obj = JSONObject() val obj = JSONObject()
...@@ -224,25 +236,22 @@ object AdmobUtils { ...@@ -224,25 +236,22 @@ object AdmobUtils {
} }
private var interAd: InterstitialAd? = null private var interAd: InterstitialAd? = null
fun isInterLoaded() = interAd != null
fun loadInterstitialAd(activity: Activity, onLoad: (() -> Unit)? = null) { fun loadInterstitialAd(activity: Activity, onLoad: (() -> Unit)? = null) {
if (interAd != null) { if (interAd != null) {
onLoad?.invoke() onLoad?.invoke()
return return
} }
if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onLoad?.invoke()
return
}
val reqId = UUID.randomUUID().toString() 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( InterstitialAd.load(
activity, activity,
ConfigHelper.interAdmobId, ConfigHelper.interAdmobId,
mRequest, mRequest,
object : InterstitialAdLoadCallback() { object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(p0: LoadAdError) { override fun onAdFailedToLoad(p0: LoadAdError) {
Log.d("glc", "广告拉取失败:" + p0.message)
interAd = null interAd = null
onLoad?.invoke() onLoad?.invoke()
pull(p0.responseInfo, "interAd", p0.message, reqId = reqId) pull(p0.responseInfo, "interAd", p0.message, reqId = reqId)
...@@ -254,7 +263,6 @@ object AdmobUtils { ...@@ -254,7 +263,6 @@ object AdmobUtils {
) )
} }
// Log.e("MXL", "InterAdFailedToLoad: " + p0.message)
} }
override fun onAdLoaded(ad: InterstitialAd) { override fun onAdLoaded(ad: InterstitialAd) {
...@@ -263,14 +271,17 @@ object AdmobUtils { ...@@ -263,14 +271,17 @@ object AdmobUtils {
interLoadTime = System.currentTimeMillis() interLoadTime = System.currentTimeMillis()
pull(ad.responseInfo, "interAd", reqId = reqId) pull(ad.responseInfo, "interAd", reqId = reqId)
ad.onPaidEventListener = EventOnPaidEventListener(ad) ad.onPaidEventListener = EventOnPaidEventListener(ad)
// Log.e("MXL", "InteronAdLoaded: ")
} }
}) })
} }
private fun isAdExpired():Boolean{ private fun isAdExpired(): Boolean {
return System.currentTimeMillis() - interLoadTime > 1000 * 60 * 60 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) { fun showInterstitialAd(activity: Activity, isLoadAdNow: Boolean = false, onHidden: (() -> Unit)? = null) {
if (activity.isFinishing || activity.isDestroyed) { if (activity.isFinishing || activity.isDestroyed) {
return return
...@@ -283,24 +294,54 @@ object AdmobUtils { ...@@ -283,24 +294,54 @@ object AdmobUtils {
return return
} }
if(!AdDisplayUtils.getInstance().shouldDisplayAd()){ if (!AdDisplayUtils.getInstance().shouldShowAd()) {
onHidden?.invoke() onHidden?.invoke()
return return
} }
val interval = isTimeElapsed()
if(!AdDisplayUtils.getInstance().shouldIncrementClickCount()){ if (interval <= 0) {
onHidden?.invoke() showCachedInterstitialAd(activity, isLoadAdNow, onHidden)
return } 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) { if (interAd != null) {
displayInterstitialAd(activity,onHidden) displayInterstitialAd(activity, onHidden)
} else { } 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 var mDialog: Dialog? = null
mDialog = CustomDialog(activity, R.layout.dialog_ad_loading) mDialog = CustomDialog(activity, R.layout.dialog_ad_loading)
mDialog.show() mDialog.show()
...@@ -319,7 +360,7 @@ object AdmobUtils { ...@@ -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 val thisInterAd = interAd
interAd = null interAd = null
thisInterAd?.fullScreenContentCallback = object : FullScreenContentCallback() { thisInterAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
...@@ -343,6 +384,7 @@ object AdmobUtils { ...@@ -343,6 +384,7 @@ object AdmobUtils {
override fun onAdShowedFullScreenContent() { override fun onAdShowedFullScreenContent() {
show(thisInterAd?.responseInfo, "interAd", activity) show(thisInterAd?.responseInfo, "interAd", activity)
AdDisplayUtils.getInstance().incrementAdDisplayCount() AdDisplayUtils.getInstance().incrementAdDisplayCount()
adLastDisplayTime = System.currentTimeMillis() / 1000
} }
} }
thisInterAd?.show(activity) thisInterAd?.show(activity)
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<TextView <TextView
android:id="@+id/dialog_ad_loading_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="11dp" android:layout_marginLeft="11dp"
......
...@@ -118,7 +118,8 @@ ...@@ -118,7 +118,8 @@
<androidx.appcompat.widget.LinearLayoutCompat <androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:layout_marginTop="14dp">
<com.noober.background.view.BLLinearLayout <com.noober.background.view.BLLinearLayout
android:id="@+id/id_clean_junk" android:id="@+id/id_clean_junk"
...@@ -264,7 +265,7 @@ ...@@ -264,7 +265,7 @@
<androidx.appcompat.widget.LinearLayoutCompat <androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="6dp"> android:layout_marginTop="10dp">
<com.noober.background.view.BLLinearLayout <com.noober.background.view.BLLinearLayout
android:id="@+id/id_large_file" android:id="@+id/id_large_file"
...@@ -436,7 +437,7 @@ ...@@ -436,7 +437,7 @@
android:id="@+id/id_similar_photos" android:id="@+id/id_similar_photos"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginBottom="13dp"
android:gravity="center_vertical"> android:gravity="center_vertical">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
...@@ -450,7 +451,10 @@ ...@@ -450,7 +451,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp" android:layout_marginHorizontal="6dp"
android:layout_weight="1" 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 <androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -461,11 +465,18 @@ ...@@ -461,11 +465,18 @@
</androidx.appcompat.widget.LinearLayoutCompat> </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 <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/id_screenshot_clean" android:id="@+id/id_screenshot_clean"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginTop="13dp"
android:layout_marginBottom="13dp"
android:gravity="center_vertical"> android:gravity="center_vertical">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
...@@ -479,6 +490,9 @@ ...@@ -479,6 +490,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp" android:layout_marginHorizontal="6dp"
android:layout_weight="1" android:layout_weight="1"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold"
android:text="Screenshot Clean" /> android:text="Screenshot Clean" />
<androidx.appcompat.widget.AppCompatImageView <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