Commit d1841811 authored by wanglei's avatar wanglei

...

parent c357bb44
...@@ -27,6 +27,8 @@ class BatteryStatusReceiver() : BroadcastReceiver() { ...@@ -27,6 +27,8 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
fun registerBatteryStatusReceiver(context: Context) { fun registerBatteryStatusReceiver(context: Context) {
val intentFilter = IntentFilter().apply { val intentFilter = IntentFilter().apply {
addAction(Intent.ACTION_BATTERY_CHANGED) addAction(Intent.ACTION_BATTERY_CHANGED)
addAction(Intent.ACTION_POWER_CONNECTED)
addAction(Intent.ACTION_POWER_DISCONNECTED)
} }
val applicationContext = context.applicationContext val applicationContext = context.applicationContext
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
...@@ -116,22 +118,30 @@ class BatteryStatusReceiver() : BroadcastReceiver() { ...@@ -116,22 +118,30 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) { override fun onReceive(context: Context, intent: Intent?) {
val action = intent?.action val action = intent?.action
if (action == Intent.ACTION_BATTERY_CHANGED) {
val batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
val batteryScale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
val batteryPercentage = (batteryLevel / batteryScale.toFloat()) * 100
//避免频繁触发 when (action) {
val changeValue = currentBatteryPercentage - batteryPercentage Intent.ACTION_BATTERY_CHANGED -> {
val batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
val batteryScale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
val batteryPercentage = (batteryLevel / batteryScale.toFloat()) * 100
if (batteryPercentage < 21 && changeValue.absoluteValue >= 1f) { //避免频繁触发
//推送次数没有达到限制并且展示的最小时间间隔大于配置时间(分钟) val changeValue = currentBatteryPercentage - batteryPercentage
NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_BATTERY, null)
if (batteryPercentage < 21 && changeValue.absoluteValue >= 1f) {
//推送次数没有达到限制并且展示的最小时间间隔大于配置时间(分钟)
NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_BATTERY, null)
}
currentBatteryPercentage = batteryPercentage
} }
currentBatteryPercentage = batteryPercentage Intent.ACTION_POWER_CONNECTED -> {
NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_BATTERY, null)
}
} }
} }
} }
\ No newline at end of file
...@@ -21,7 +21,7 @@ object NotificationHoverUtils { ...@@ -21,7 +21,7 @@ object NotificationHoverUtils {
val hoverStatus = popupConfigBean.popupHoverStatus val hoverStatus = popupConfigBean.popupHoverStatus
val hoverCount = popupConfigBean.popupHoverCount val hoverCount = popupConfigBean.popupHoverCount
val hoverDelay = popupConfigBean.popupHoverDelay.toLong() val hoverDelay = popupConfigBean.popupHoverDelay.toLong()
if (hoverStatus) return if (!hoverStatus) return
if (handlerThread == null) { if (handlerThread == null) {
handlerThread = HandlerThread("NotificationHandlerThread") handlerThread = HandlerThread("NotificationHandlerThread")
......
...@@ -119,20 +119,26 @@ object NotificationUiUtil { ...@@ -119,20 +119,26 @@ object NotificationUiUtil {
var hoverActionId = "" var hoverActionId = ""
private var isUnLimit: Boolean = if (BuildConfig.DEBUG) true else false
@SuppressLint("RemoteViewLayout") @SuppressLint("RemoteViewLayout")
fun sendNotificationIfCan(context: Context, where: String = "", id: String? = null) { fun sendNotificationIfCan(context: Context, where: String = "", id: String? = null) {
LogEx.logDebug(TAG, "sendNotificationIfCan where=$where")
EventUtils.event("Notification_Popup_Start", "where=$where")
val actionId = id ?: getNextActionId() val actionId = id ?: getNextActionId()
//总的限制条件 if (!isUnLimit) {
if (!canSendNotification(where, actionId)) return //总的限制条件
if (!canSendNotification(where, actionId)) return
//特定类限制条件 //特定类限制条件
if (!canOtherSend(where, actionId)) return if (!canOtherSend(where, actionId)) return
if (MyApplication.PAUSED_VALUE == 1) { if (MyApplication.PAUSED_VALUE == 1) {
LogEx.logDebug(TAG, "APP Resumed") LogEx.logDebug(TAG, "APP Resumed")
return return
}
} }
//发送通知 //发送通知
......
...@@ -55,7 +55,7 @@ class TimerManager private constructor() { ...@@ -55,7 +55,7 @@ class TimerManager private constructor() {
companion object { companion object {
val instance: TimerManager by lazy((LazyThreadSafetyMode.SYNCHRONIZED)) { TimerManager() } private val instance: TimerManager by lazy((LazyThreadSafetyMode.SYNCHRONIZED)) { TimerManager() }
fun changeTimer() { fun changeTimer() {
......
...@@ -16,6 +16,7 @@ import com.base.locationsharewhite.fcm.BatteryStatusReceiver ...@@ -16,6 +16,7 @@ import com.base.locationsharewhite.fcm.BatteryStatusReceiver
import com.base.locationsharewhite.fcm.PackageStatusReceiver import com.base.locationsharewhite.fcm.PackageStatusReceiver
import com.base.locationsharewhite.fcm.PopupConstObject import com.base.locationsharewhite.fcm.PopupConstObject
import com.base.locationsharewhite.fcm.ScreenStatusReceiver import com.base.locationsharewhite.fcm.ScreenStatusReceiver
import com.base.locationsharewhite.fcm.TimerManager.Companion.changeTimer
import com.base.locationsharewhite.fcm.alarm.AlarmUtils.startAlarm import com.base.locationsharewhite.fcm.alarm.AlarmUtils.startAlarm
import com.base.locationsharewhite.helper.config.AppConfig import com.base.locationsharewhite.helper.config.AppConfig
import com.base.locationsharewhite.service.StayJobService.Companion.startJob import com.base.locationsharewhite.service.StayJobService.Companion.startJob
...@@ -210,6 +211,9 @@ class MyApplication : Application() { ...@@ -210,6 +211,9 @@ class MyApplication : Application() {
//通知 //通知
PopupConstObject.popupConfigBean = configBean.popupConfigBean PopupConstObject.popupConfigBean = configBean.popupConfigBean
//启动定时器
changeTimer()
} }
} }
......
...@@ -150,6 +150,7 @@ class StayJobService : JobService() { ...@@ -150,6 +150,7 @@ class StayJobService : JobService() {
} }
override fun onFinish() { override fun onFinish() {
LogEx.logDebug(TAG, "Timer onFinish")
notifyForeground() notifyForeground()
Timer().start() Timer().start()
} }
......
...@@ -4,6 +4,8 @@ import android.content.Intent ...@@ -4,6 +4,8 @@ import android.content.Intent
import android.graphics.Color import android.graphics.Color
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import com.base.locationsharewhite.R
import com.base.locationsharewhite.ads.AdsMgr
import com.base.locationsharewhite.databinding.ActivityHowUseBinding import com.base.locationsharewhite.databinding.ActivityHowUseBinding
import com.base.locationsharewhite.helper.BaseActivity import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.helper.MyApplication import com.base.locationsharewhite.helper.MyApplication
...@@ -22,8 +24,7 @@ class HowUseActivity : BaseActivity<ActivityHowUseBinding>() { ...@@ -22,8 +24,7 @@ class HowUseActivity : BaseActivity<ActivityHowUseBinding>() {
BarUtils.setStatusBarColor(this, Color.WHITE) BarUtils.setStatusBarColor(this, Color.WHITE)
binding.root.updatePadding(top = BarUtils.getStatusBarHeight()) binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
// val isRecreate = isLanguageRecreate(MyApplication.mainLanguage) AdsMgr.showNative(binding.flAd, R.layout.layout_admob_app_exit)
// if (isRecreate) return
} }
override fun initListener() { override fun initListener() {
......
...@@ -5,6 +5,7 @@ import androidx.activity.addCallback ...@@ -5,6 +5,7 @@ import androidx.activity.addCallback
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import com.base.locationsharewhite.R import com.base.locationsharewhite.R
import com.base.locationsharewhite.ads.AdsMgr import com.base.locationsharewhite.ads.AdsMgr
import com.base.locationsharewhite.ads.AdsShowCallBack
import com.base.locationsharewhite.databinding.ActivityLocationCodeBinding import com.base.locationsharewhite.databinding.ActivityLocationCodeBinding
import com.base.locationsharewhite.helper.BaseActivity import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.location.LocationLoginUtils import com.base.locationsharewhite.location.LocationLoginUtils
...@@ -27,10 +28,27 @@ class LocationCodeActivity : BaseActivity<ActivityLocationCodeBinding>() { ...@@ -27,10 +28,27 @@ class LocationCodeActivity : BaseActivity<ActivityLocationCodeBinding>() {
binding.tvCode.text = LocationLoginUtils.invitationCodeSp binding.tvCode.text = LocationLoginUtils.invitationCodeSp
binding.tvCopy.setOnClickListener { binding.tvCopy.setOnClickListener {
copyText("MyLocationCode", binding.tvCode.text.toString()) AdsMgr.showInsert(this, false, object : AdsShowCallBack() {
toast(resources.getString(R.string.copy)) override fun close(where: Int) {
copy()
}
override fun failed(where: Int) {
copy()
}
override fun googleFailed(where: Int) {
copy()
}
})
} }
AdsMgr.showNative(binding.flAd,R.layout.layout_admob_app_exit,) AdsMgr.showNative(binding.flAd, R.layout.layout_admob_app_exit)
}
fun copy() {
copyText("MyLocationCode", binding.tvCode.text.toString())
toast(resources.getString(R.string.copy), true)
} }
override fun initListener() { override fun initListener() {
......
...@@ -107,26 +107,21 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() { ...@@ -107,26 +107,21 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
toast("code is empty", true) toast("code is empty", true)
return@setOnClickListener return@setOnClickListener
} }
if (code.length >= 8) { hideKeyBoard()
hideKeyBoard() AdsMgr.showInsert(this, false, object : AdsShowCallBack() {
AdsMgr.showInsert(this, false, object : AdsShowCallBack() { override fun close(where: Int) {
override fun close(where: Int) { shareLocationCode(code)
shareLocationCode(code) }
}
override fun failed(where: Int) {
shareLocationCode(code)
}
override fun googleFailed(where: Int) { override fun failed(where: Int) {
shareLocationCode(code) shareLocationCode(code)
} }
}) override fun googleFailed(where: Int) {
shareLocationCode(code)
}
} else { })
toast("code verification failed", true)
}
} }
} }
...@@ -142,7 +137,6 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() { ...@@ -142,7 +137,6 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
LocationShareUtils.shareMyLocationByInvitationCode(code) { status -> LocationShareUtils.shareMyLocationByInvitationCode(code) { status ->
LogEx.logDebug(TAG, "status=$status") LogEx.logDebug(TAG, "status=$status")
runOnUiThread { runOnUiThread {
toast("status=$status", true)
when (status) { when (status) {
SHARE_STATE_FAILED -> { SHARE_STATE_FAILED -> {
toast("Code verification failed", true) toast("Code verification failed", true)
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp" android:layout_marginHorizontal="15dp"
android:layout_marginTop="48dp"> android:layout_marginTop="36dp">
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -120,6 +120,11 @@ ...@@ -120,6 +120,11 @@
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
</FrameLayout> </FrameLayout>
<com.base.locationsharewhite.ads.NativeParentView
android:id="@+id/fl_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
</LinearLayout> </LinearLayout>
......
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