Commit 1c224f88 authored by wanglei's avatar wanglei

Merge branch 'master' of gitlab.huolea.com:koko/data-recovery-white

parents c5de749d 3833952b
......@@ -11,6 +11,7 @@ import com.base.datarecovery.help.BaseApplication
import com.base.datarecovery.help.ConfigHelper
import com.base.datarecovery.utils.ActivityManagerUtils
import com.base.datarecovery.utils.LogEx
import com.base.datarecovery.utils.NewComUtils
import com.google.android.gms.ads.MobileAds
class MyApplication : BaseApplication() {
......@@ -27,6 +28,10 @@ class MyApplication : BaseApplication() {
}
fun initApp() {
NewComUtils.requestCfg {
}
if (ifAgreePrivacy) {
MobileAds.initialize(this) { initializationStatus ->
}
......
......@@ -86,7 +86,7 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
}
binding.tvClean.setOnClickListener {
showDeletePermanentlyDialog {
AdmobInterstitialUtils.showInterstitialAd(this, isShowInterVal = false) {
AdmobInterstitialUtils.showInterstitialAd(this) {
lifecycleScope.launch(Dispatchers.IO) {
mediaAdapter.getSelectData().second.forEach {
runCatching {
......
......@@ -94,7 +94,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
}
onBackPressedDispatcher.addCallback {
showExitFunctionDialog {
AdmobInterstitialUtils.showInterstitialAd(this@ScreenShotActivity, isShowInterVal = false) {
AdmobInterstitialUtils.showInterstitialAd(this@ScreenShotActivity) {
finishToMain()
}
}
......@@ -110,7 +110,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
binding.tvClean.setOnClickListener {
val files = screenShotAdapter.getSelectData()
showDeletePermanentlyDialog {
AdmobInterstitialUtils.showInterstitialAd(this, isShowInterVal = false) {
AdmobInterstitialUtils.showInterstitialAd(this) {
lifecycleScope.launch(Dispatchers.IO) {
async {
files.forEach { screenFile ->
......
......@@ -89,7 +89,7 @@ class CleanJunkActivity : BaseActivity<ActivityLayoutCleanJunkBinding>() {
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
showExitFunctionDialog{
AdmobInterstitialUtils.showInterstitialAd(this@CleanJunkActivity, isShowInterVal = false) {
AdmobInterstitialUtils.showInterstitialAd(this@CleanJunkActivity) {
finishToMain()
}
}
......
......@@ -128,7 +128,7 @@ class FileScanActivity : BaseActivity<ActivityFileScanBinding>() {
if (!oneShowAd) {
oneShowAd = true
lifecycleScope.launch(Dispatchers.Main) {
AdmobInterstitialUtils.showInterstitialAd(this@FileScanActivity) { }
AdmobInterstitialUtils.showInterstitialAd(this@FileScanActivity,true,false) { }
}
}
},
......
......@@ -39,8 +39,8 @@ object AdmobInterstitialUtils {
fun showInterstitialAd(
activity: Activity,
isLoadAdNow: Boolean = false,
isShowInterVal: Boolean = true,
isReLoadAd: Boolean = false,
isShowDialog: Boolean = true,
onHidden: (() -> Unit)? = null
) {
if (activity.isFinishing || activity.isDestroyed) {
......@@ -66,9 +66,9 @@ object AdmobInterstitialUtils {
}
if (interAd != null) {
showIntervalDialogAndShowAd(activity, isLoadAdNow, isShowInterVal, onHidden, 2)
showIntervalDialogAndShowAd(activity,isShowDialog, onHidden, 2)
} else {
showAdDialogAndLoadInterstitial(activity, isLoadAdNow, isShowInterVal, onHidden)
showAdDialogAndLoadInterstitial(activity, isReLoadAd,isShowDialog, onHidden)
}
}
......@@ -118,11 +118,15 @@ object AdmobInterstitialUtils {
private fun showIntervalDialogAndShowAd(
activity: Activity,
isLoadAdNow: Boolean,
isShowInterVal: Boolean,
isShowDialog: Boolean,
onHidden: (() -> Unit)?,
interval: Int
) {
if(!isShowDialog){
displayInterstitialAd(activity, onHidden)
return
}
if (customDialog != null && customDialog?.isShowing == true) {
return // 如果对话框已经显示,则不再显示
}
......@@ -149,10 +153,13 @@ object AdmobInterstitialUtils {
private fun showAdDialogAndLoadInterstitial(
activity: Activity,
isLoadAdNow: Boolean,
isShowInterVal: Boolean,
isReLoadAd: Boolean,
isShowDialog: Boolean,
onHidden: (() -> Unit)?
) {
if(!isShowDialog){
return
}
var mDialog: Dialog? = null
if (!activity.isFinishing && !activity.isDestroyed) {
mDialog = CustomDialog(activity, R.layout.dialog_ad_loading)
......@@ -163,13 +170,13 @@ object AdmobInterstitialUtils {
loadInterstitialAd(activity) {
mDialog?.dismiss()
if (!isLoadAdNow) {
showInterstitialAd(activity, true, isShowInterVal) {
if (!isReLoadAd) {
showInterstitialAd(activity, true,false) {
onHidden?.invoke()
}
}
}
if (isLoadAdNow) {
if (isReLoadAd) {
mDialog?.dismiss()
onHidden?.invoke()
}
......
......@@ -2,6 +2,8 @@ package com.base.datarecovery.fcm;
import androidx.annotation.NonNull;
import com.base.datarecovery.ads.AdDisplayUtils;
import com.base.datarecovery.ads.AdmobCommonUtils;
import com.base.datarecovery.utils.AppPreferences;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
......@@ -18,13 +20,10 @@ public class MessagingService extends FirebaseMessagingService {
updateSharedPreferences(remoteMessage.getData());
manageTimerBasedOnMessage(remoteMessage.getData());
// AdmobUtils.INSTANCE.setAdDisplayInterval(adInterval);
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(adShowCount);
// AdDisplayUtils.getInstance().setMaxAdClickCount(adClickCount);
//
AdDisplayUtils.getInstance().setMaxAdDisplayCount(Integer.valueOf(AppPreferences.getInstance().getString("adShowCount","45")));
AdDisplayUtils.getInstance().setMaxAdClickCount(Integer.valueOf(AppPreferences.getInstance().getString("adClickCount","10")));
// EventUtils.INSTANCE.event("FCM_Received",null,null,false);
//
// NotificationUtil.sendNotification(MyApplication.context);
sendLocalNotification();
}
......
......@@ -170,7 +170,7 @@ object NotificationUtil {
builder.setCustomBigContentView(bigRemoteViews)
// 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())
} else {
notificationManager.notify(actionId, builder.build())
......
......@@ -2,6 +2,7 @@ package com.base.datarecovery.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import com.base.datarecovery.MyApplication;
......@@ -31,8 +32,11 @@ public class AppPreferences {
} else if (value instanceof Boolean) {
sharedPreferences.edit().putBoolean(key, (Boolean) value).apply();
} else if (value instanceof String) {
Log.d("okhttp","String: "+value);
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());
}
}
......
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
import android.util.Log
import com.base.datarecovery.ads.AdDisplayUtils
import com.base.datarecovery.bean.ConfigBean
import com.base.datarecovery.help.ConfigHelper
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
import java.util.*
import java.util.Locale
object NewComUtils {
private const val API_URL = ConfigHelper.apiUrl
......@@ -43,14 +48,14 @@ object NewComUtils {
}
val decryptedData = AESHelper.decrypt(data)
val configBean = parseConfigBean(decryptedData)
parseConfigBean(decryptedData)
withContext(Dispatchers.Main) {
callback(configBean)
callback(null)
}
}
}
private suspend fun doGet(): String? {
private fun doGet(): String? {
val urlPath = url
Log.d("okhttp", urlPath)
try {
......@@ -75,22 +80,23 @@ object NewComUtils {
return match?.groupValues?.get(1)
}
private fun parseConfigBean(json: String): ConfigBean? {
private fun parseConfigBean(json: String) {
Log.d("okhttp",json)
val gson = Gson()
val type = object : TypeToken<Map<String, Any>>() {}.type
val configMap = gson.fromJson<Map<String, Any>>(json, type)
return if (configMap != null) {
ConfigBean(
actionS = configMap["actionS"] as? String,
open = configMap["open"] as? Boolean,
// ... other properties
)
} else null
val type = object : TypeToken<Map<String, String>>() {}.type
val configMap = gson.fromJson<Map<String, String>>(json, type)
configMap.forEach { t, u ->
// 对于整型值使用parseInt, 长整型使用parseLong
AppPreferences.getInstance().put(t, u)
Log.d("okhttp:","t: "+t +" u: "+u)
}
AdDisplayUtils.getInstance().setMaxAdDisplayCount(
AppPreferences.getInstance().getString("adShowCount", "45").toInt()
)
AdDisplayUtils.getInstance().maxAdClickCount =
AppPreferences.getInstance().getString("adClickCount", "10").toInt()
}
}
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