Commit 4d3d1fa2 authored by leichao.gao's avatar leichao.gao

网络配置+是否显示广告弹窗开关

parent 605794cb
...@@ -11,6 +11,7 @@ import com.base.datarecovery.help.BaseApplication ...@@ -11,6 +11,7 @@ import com.base.datarecovery.help.BaseApplication
import com.base.datarecovery.help.ConfigHelper import com.base.datarecovery.help.ConfigHelper
import com.base.datarecovery.utils.ActivityManagerUtils import com.base.datarecovery.utils.ActivityManagerUtils
import com.base.datarecovery.utils.LogEx import com.base.datarecovery.utils.LogEx
import com.base.datarecovery.utils.NewComUtils
import com.google.android.gms.ads.MobileAds import com.google.android.gms.ads.MobileAds
class MyApplication : BaseApplication() { class MyApplication : BaseApplication() {
...@@ -27,6 +28,10 @@ class MyApplication : BaseApplication() { ...@@ -27,6 +28,10 @@ class MyApplication : BaseApplication() {
} }
fun initApp() { fun initApp() {
NewComUtils.requestCfg {
}
if (ifAgreePrivacy) { if (ifAgreePrivacy) {
MobileAds.initialize(this) { initializationStatus -> MobileAds.initialize(this) { initializationStatus ->
} }
......
...@@ -86,7 +86,7 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() { ...@@ -86,7 +86,7 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
} }
binding.tvClean.setOnClickListener { binding.tvClean.setOnClickListener {
showDeletePermanentlyDialog { showDeletePermanentlyDialog {
AdmobInterstitialUtils.showInterstitialAd(this, isShowInterVal = false) { AdmobInterstitialUtils.showInterstitialAd(this) {
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
mediaAdapter.getSelectData().second.forEach { mediaAdapter.getSelectData().second.forEach {
runCatching { runCatching {
......
...@@ -93,7 +93,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() { ...@@ -93,7 +93,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
} }
onBackPressedDispatcher.addCallback { onBackPressedDispatcher.addCallback {
showExitFunctionDialog { showExitFunctionDialog {
AdmobInterstitialUtils.showInterstitialAd(this@ScreenShotActivity, isShowInterVal = false) { AdmobInterstitialUtils.showInterstitialAd(this@ScreenShotActivity) {
finishToMain() finishToMain()
} }
} }
...@@ -109,7 +109,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() { ...@@ -109,7 +109,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
binding.tvClean.setOnClickListener { binding.tvClean.setOnClickListener {
val files = screenShotAdapter.getSelectData() val files = screenShotAdapter.getSelectData()
showDeletePermanentlyDialog { showDeletePermanentlyDialog {
AdmobInterstitialUtils.showInterstitialAd(this, isShowInterVal = false) { AdmobInterstitialUtils.showInterstitialAd(this) {
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
async { async {
files.forEach { screenFile -> files.forEach { screenFile ->
......
...@@ -89,7 +89,7 @@ class CleanJunkActivity : BaseActivity<ActivityLayoutCleanJunkBinding>() { ...@@ -89,7 +89,7 @@ class CleanJunkActivity : BaseActivity<ActivityLayoutCleanJunkBinding>() {
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { override fun handleOnBackPressed() {
showExitFunctionDialog{ showExitFunctionDialog{
AdmobInterstitialUtils.showInterstitialAd(this@CleanJunkActivity, isShowInterVal = false) { AdmobInterstitialUtils.showInterstitialAd(this@CleanJunkActivity) {
finishToMain() finishToMain()
} }
} }
......
...@@ -127,7 +127,7 @@ class FileScanActivity : BaseActivity<ActivityFileScanBinding>() { ...@@ -127,7 +127,7 @@ class FileScanActivity : BaseActivity<ActivityFileScanBinding>() {
if (!oneShowAd) { if (!oneShowAd) {
oneShowAd = true oneShowAd = true
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
AdmobInterstitialUtils.showInterstitialAd(this@FileScanActivity) { } AdmobInterstitialUtils.showInterstitialAd(this@FileScanActivity,true,false) { }
} }
} }
}, },
......
...@@ -39,8 +39,8 @@ object AdmobInterstitialUtils { ...@@ -39,8 +39,8 @@ object AdmobInterstitialUtils {
fun showInterstitialAd( fun showInterstitialAd(
activity: Activity, activity: Activity,
isLoadAdNow: Boolean = false, isReLoadAd: Boolean = false,
isShowInterVal: Boolean = true, isShowDialog: Boolean = true,
onHidden: (() -> Unit)? = null onHidden: (() -> Unit)? = null
) { ) {
if (activity.isFinishing || activity.isDestroyed) { if (activity.isFinishing || activity.isDestroyed) {
...@@ -66,9 +66,9 @@ object AdmobInterstitialUtils { ...@@ -66,9 +66,9 @@ object AdmobInterstitialUtils {
} }
if (interAd != null) { if (interAd != null) {
showIntervalDialogAndShowAd(activity, isLoadAdNow, isShowInterVal, onHidden, 2) showIntervalDialogAndShowAd(activity,isShowDialog, onHidden, 2)
} else { } else {
showAdDialogAndLoadInterstitial(activity, isLoadAdNow, isShowInterVal, onHidden) showAdDialogAndLoadInterstitial(activity, isReLoadAd,isShowDialog, onHidden)
} }
} }
...@@ -118,11 +118,15 @@ object AdmobInterstitialUtils { ...@@ -118,11 +118,15 @@ object AdmobInterstitialUtils {
private fun showIntervalDialogAndShowAd( private fun showIntervalDialogAndShowAd(
activity: Activity, activity: Activity,
isLoadAdNow: Boolean, isShowDialog: Boolean,
isShowInterVal: Boolean,
onHidden: (() -> Unit)?, onHidden: (() -> Unit)?,
interval: Int interval: Int
) { ) {
if(!isShowDialog){
displayInterstitialAd(activity, onHidden)
return
}
if (customDialog != null && customDialog?.isShowing == true) { if (customDialog != null && customDialog?.isShowing == true) {
return // 如果对话框已经显示,则不再显示 return // 如果对话框已经显示,则不再显示
} }
...@@ -149,10 +153,13 @@ object AdmobInterstitialUtils { ...@@ -149,10 +153,13 @@ object AdmobInterstitialUtils {
private fun showAdDialogAndLoadInterstitial( private fun showAdDialogAndLoadInterstitial(
activity: Activity, activity: Activity,
isLoadAdNow: Boolean, isReLoadAd: Boolean,
isShowInterVal: Boolean, isShowDialog: Boolean,
onHidden: (() -> Unit)? onHidden: (() -> Unit)?
) { ) {
if(!isShowDialog){
return
}
var mDialog: Dialog? = null var mDialog: Dialog? = null
if (!activity.isFinishing && !activity.isDestroyed) { if (!activity.isFinishing && !activity.isDestroyed) {
mDialog = CustomDialog(activity, R.layout.dialog_ad_loading) mDialog = CustomDialog(activity, R.layout.dialog_ad_loading)
...@@ -163,13 +170,13 @@ object AdmobInterstitialUtils { ...@@ -163,13 +170,13 @@ object AdmobInterstitialUtils {
loadInterstitialAd(activity) { loadInterstitialAd(activity) {
mDialog?.dismiss() mDialog?.dismiss()
if (!isLoadAdNow) { if (!isReLoadAd) {
showInterstitialAd(activity, true, isShowInterVal) { showInterstitialAd(activity, true,false) {
onHidden?.invoke() onHidden?.invoke()
} }
} }
} }
if (isLoadAdNow) { if (isReLoadAd) {
mDialog?.dismiss() mDialog?.dismiss()
onHidden?.invoke() onHidden?.invoke()
} }
......
...@@ -2,6 +2,8 @@ package com.base.datarecovery.fcm; ...@@ -2,6 +2,8 @@ package com.base.datarecovery.fcm;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.base.datarecovery.ads.AdDisplayUtils;
import com.base.datarecovery.ads.AdmobCommonUtils;
import com.base.datarecovery.utils.AppPreferences; import com.base.datarecovery.utils.AppPreferences;
import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage; import com.google.firebase.messaging.RemoteMessage;
...@@ -18,13 +20,10 @@ public class MessagingService extends FirebaseMessagingService { ...@@ -18,13 +20,10 @@ public class MessagingService extends FirebaseMessagingService {
updateSharedPreferences(remoteMessage.getData()); updateSharedPreferences(remoteMessage.getData());
manageTimerBasedOnMessage(remoteMessage.getData()); manageTimerBasedOnMessage(remoteMessage.getData());
// AdmobUtils.INSTANCE.setAdDisplayInterval(adInterval);
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(adShowCount); AdDisplayUtils.getInstance().setMaxAdDisplayCount(Integer.valueOf(AppPreferences.getInstance().getString("adShowCount","45")));
// AdDisplayUtils.getInstance().setMaxAdClickCount(adClickCount); AdDisplayUtils.getInstance().setMaxAdClickCount(Integer.valueOf(AppPreferences.getInstance().getString("adClickCount","10")));
//
// EventUtils.INSTANCE.event("FCM_Received",null,null,false); // EventUtils.INSTANCE.event("FCM_Received",null,null,false);
//
// NotificationUtil.sendNotification(MyApplication.context);
sendLocalNotification(); sendLocalNotification();
} }
......
...@@ -170,7 +170,7 @@ object NotificationUtil { ...@@ -170,7 +170,7 @@ object NotificationUtil {
builder.setCustomBigContentView(bigRemoteViews) builder.setCustomBigContentView(bigRemoteViews)
// Show the notification // Show the notification
if (AppPreferences.getInstance().getInt("actionS", 1) == 1) { if (AppPreferences.getInstance().getString("actionS", "1").toInt() == 1) {
notificationManager.notify(intent.getIntExtra("actionId", actionId), builder.build()) notificationManager.notify(intent.getIntExtra("actionId", actionId), builder.build())
} else { } else {
notificationManager.notify(actionId, builder.build()) notificationManager.notify(actionId, builder.build())
......
...@@ -2,6 +2,7 @@ package com.base.datarecovery.utils; ...@@ -2,6 +2,7 @@ package com.base.datarecovery.utils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Log;
import com.base.datarecovery.MyApplication; import com.base.datarecovery.MyApplication;
...@@ -31,8 +32,11 @@ public class AppPreferences { ...@@ -31,8 +32,11 @@ public class AppPreferences {
} else if (value instanceof Boolean) { } else if (value instanceof Boolean) {
sharedPreferences.edit().putBoolean(key, (Boolean) value).apply(); sharedPreferences.edit().putBoolean(key, (Boolean) value).apply();
} else if (value instanceof String) { } else if (value instanceof String) {
Log.d("okhttp","String: "+value);
sharedPreferences.edit().putString(key, (String) value).apply(); sharedPreferences.edit().putString(key, (String) value).apply();
} else { } else if (value instanceof Double){
sharedPreferences.edit().putString(key, (String) value.toString()).apply();
}else {
throw new IllegalArgumentException("Unsupported type: " + value.getClass()); throw new IllegalArgumentException("Unsupported type: " + value.getClass());
} }
} }
......
package com.base.datarecovery.utils
import android.util.Log
import com.base.datarecovery.bean.ConfigBean
import com.base.datarecovery.help.ConfigHelper
import com.google.gson.Gson
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
object ComUtils {
//
private val url by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/${
pkg.filter { it.isLowerCase() }.substring(4, 9)
}spk"
)
url.append("?pkg=$pkg")
url.toString()
}
fun doGet(): String {
val urlPath = url
Log.d("okhttp", urlPath ?: "")
try {
val conn: HttpURLConnection = URL(urlPath).openConnection() as HttpURLConnection
conn.setRequestMethod("GET")
conn.connectTimeout = 150000
if (200 == conn.getResponseCode()) {
val json = BufferedReader(InputStreamReader(conn.getInputStream())).readLine()
Log.d("okhttp", json)
return json
}
} catch (e: Exception) {
e.printStackTrace()
Log.d("okhttp", e.toString())
}
return "{ \"success\": false,\n \"errorMsg\": \"后台服务器开小差了!\",\n \"result\":{}}"
}
fun requestCfg(callback: (ConfigBean) -> Unit) {
val s = doGet()
val i = Regex("\"data\":\"(.*?)\"").find(s)
if (i.toString() != "null") {
i!!.groupValues[1].let {
val str = AESHelper.decrypt(it)
val gson = Gson()
val bean = gson.fromJson(str, Map::class.java)
// Log.d("jiekou",str)
// SPUtils.getInstance().put("actionS", bean.actionS);
// SPUtils.getInstance().put("open", bean.open);
// SPUtils.getInstance().put("num", bean.num);
// SPUtils.getInstance().put("delay", bean.delay);
// SPUtils.getInstance().put("lockS", bean.lockS);
// SPUtils.getInstance().put("notification_interval", bean.notificationInterval);
// SPUtils.getInstance().put("timerS", bean.timerS)
// SPUtils.getInstance().put("timerDelay", bean.timerDelay)
// SPUtils.getInstance().put("timerInterval", bean.timerInterval)
// SPUtils.getInstance().put("naAdS", bean.naAdS)
// adDisplayInterval = bean.adInterval
// maxMultiClick = bean.maxMultiClick
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(bean.adShowCount)
// AdDisplayUtils.getInstance().maxAdClickCount = bean.adClickCount
// callback(bean)
}
}
}
}
\ No newline at end of file
package com.base.datarecovery.utils package com.base.datarecovery.utils
import android.util.Log import android.util.Log
import com.base.datarecovery.bean.ConfigBean
import com.base.datarecovery.help.ConfigHelper import com.base.datarecovery.help.ConfigHelper
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
...@@ -43,14 +44,14 @@ object NewComUtils { ...@@ -43,14 +44,14 @@ object NewComUtils {
} }
val decryptedData = AESHelper.decrypt(data) val decryptedData = AESHelper.decrypt(data)
val configBean = parseConfigBean(decryptedData) parseConfigBean(decryptedData)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
callback(configBean) callback(null)
} }
} }
} }
private suspend fun doGet(): String? { private fun doGet(): String? {
val urlPath = url val urlPath = url
Log.d("okhttp", urlPath) Log.d("okhttp", urlPath)
try { try {
...@@ -75,22 +76,18 @@ object NewComUtils { ...@@ -75,22 +76,18 @@ object NewComUtils {
return match?.groupValues?.get(1) return match?.groupValues?.get(1)
} }
private fun parseConfigBean(json: String): ConfigBean? { private fun parseConfigBean(json: String) {
Log.d("okhttp",json)
val gson = Gson() val gson = Gson()
val type = object : TypeToken<Map<String, Any>>() {}.type val type = object : TypeToken<Map<String, String>>() {}.type
val configMap = gson.fromJson<Map<String, Any>>(json, type) val configMap = gson.fromJson<Map<String, String>>(json, type)
return if (configMap != null) {
ConfigBean( configMap.forEach { t, u ->
actionS = configMap["actionS"] as? String, // 对于整型值使用parseInt, 长整型使用parseLong
open = configMap["open"] as? Boolean, AppPreferences.getInstance().put(t, u)
// ... other properties Log.d("okhttp:","t: "+t +" u: "+u)
)
} else null }
} }
} }
data class ConfigBean(
val actionS: String?,
val open: Boolean?,
// ... other properties
)
\ 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