Commit f90d6b51 authored by wanglei's avatar wanglei

[新增]电池触发通知

parent 0ce876e5
...@@ -22,6 +22,9 @@ class PopupConfigBean( ...@@ -22,6 +22,9 @@ class PopupConfigBean(
val alarmS: Boolean = true,//是否闹钟触发推送 val alarmS: Boolean = true,//是否闹钟触发推送
val workS: Boolean = true,//workManager触发推送 val workS: Boolean = true,//workManager触发推送
val batteryS: Boolean = true,//电池触发通知开关
var batteryInterval: Int = 180,//电池推送间隔 秒(推送间隔一般大于总间隔才有意义)
val notifyForegroundInterval: Long = 30000L//常驻通知栏刷新通知间隔 val notifyForegroundInterval: Long = 30000L//常驻通知栏刷新通知间隔
) { ) {
companion object { companion object {
......
...@@ -6,6 +6,23 @@ import android.content.Intent ...@@ -6,6 +6,23 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.os.BatteryManager import android.os.BatteryManager
import android.os.Build import android.os.Build
import com.base.appzxhy.bean.FeatureBean.Companion.BATTERY_INFO
import com.base.appzxhy.bean.config.PopupConfigBean
import com.base.appzxhy.bean.push.NotificationSendBean
import com.base.appzxhy.bean.push.NotificationSendBean.Companion.POPUP_WHERE_BATTERY
import com.base.appzxhy.business.push.notification.MyNotificationManager
import com.base.appzxhy.utils.AppPreferences
//电池上次推送时间
var batteryLastPushTime = 0L
get() {
return AppPreferences.getInstance().getLong("batteryLastPushTime", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("batteryLastPushTime", value, true)
}
class BatteryReceiver( class BatteryReceiver(
private val block: (() -> Unit?)? = null private val block: (() -> Unit?)? = null
...@@ -71,6 +88,25 @@ class BatteryReceiver( ...@@ -71,6 +88,25 @@ class BatteryReceiver(
private fun uiHandle(context: Context) { private fun uiHandle(context: Context) {
val batteryPct = level * 100 / scale.toFloat()
if (batteryPct.toInt() > 21 && !isCharging) return
if (!PopupConfigBean.popupConfigBean.batteryS) return
val canSend = ((System.currentTimeMillis() - batteryLastPushTime) / 1000) >
PopupConfigBean.popupConfigBean.batteryInterval
MyNotificationManager.submitSendBean(
NotificationSendBean(
context,
where = POPUP_WHERE_BATTERY,
canSend = { canSend },
sendSuccess = {
batteryLastPushTime = System.currentTimeMillis()
},
).apply {
actionId = BATTERY_INFO
}
)
} }
} }
\ No newline at end of file
...@@ -49,12 +49,14 @@ class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>(A ...@@ -49,12 +49,14 @@ class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>(A
binding.ivBack.setOnClickListener { binding.ivBack.setOnClickListener {
binding.v.visibility = View.VISIBLE binding.v.visibility = View.VISIBLE
onBackPressedDispatcher.onBackPressed() onBackPressedDispatcher.onBackPressed()
finish()
} }
binding.ivDelete.setOnClickListener { binding.ivDelete.setOnClickListener {
lifecycleScope.launch { lifecycleScope.launch {
recycleBinFile.deleteIfExists() recycleBinFile.deleteIfExists()
} }
onBackPressedDispatcher.onBackPressed() onBackPressedDispatcher.onBackPressed()
finish()
} }
binding.tvRestore.setOnClickListener { binding.tvRestore.setOnClickListener {
lifecycleScope.launch { lifecycleScope.launch {
...@@ -71,6 +73,7 @@ class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>(A ...@@ -71,6 +73,7 @@ class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>(A
putExtra("Number", 1) putExtra("Number", 1)
putExtra("ScanType", recycleBinFile.getType()) putExtra("ScanType", recycleBinFile.getType())
}) })
finish()
} }
}) })
......
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