新增:免打扰(禁用转发)时间段记录日志(配合自动任务实现延时发送) #411

This commit is contained in:
pppscn 2024-02-25 10:47:08 +08:00
parent c4f298ebe8
commit 06bc7adbe4
9 changed files with 81 additions and 32 deletions

View File

@ -127,6 +127,10 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
} }
//免打扰(禁用转发)时间段 //免打扰(禁用转发)时间段
binding!!.tvSilentPeriod.text = mTimeOption[SettingUtils.silentPeriodStart] + " ~ " + mTimeOption[SettingUtils.silentPeriodEnd] binding!!.tvSilentPeriod.text = mTimeOption[SettingUtils.silentPeriodStart] + " ~ " + mTimeOption[SettingUtils.silentPeriodEnd]
binding!!.scbSilentPeriodLogs.isChecked = SettingUtils.enableSilentPeriodLogs
binding!!.scbSilentPeriodLogs.setOnCheckedChangeListener { _: SmoothCheckBox, isChecked: Boolean ->
SettingUtils.enableSilentPeriodLogs = isChecked
}
//开机启动 //开机启动
checkWithReboot(binding!!.sbWithReboot, binding!!.tvAutoStartup) checkWithReboot(binding!!.sbWithReboot, binding!!.tvAutoStartup)

View File

@ -56,6 +56,7 @@ const val ENABLE_LOAD_SYSTEM_APP_LIST = "enable_load_system_app_list"
const val SP_DUPLICATE_MESSAGES_LIMITS = "duplicate_messages_limits" const val SP_DUPLICATE_MESSAGES_LIMITS = "duplicate_messages_limits"
const val SP_SILENT_PERIOD_START = "silent_period_start" const val SP_SILENT_PERIOD_START = "silent_period_start"
const val SP_SILENT_PERIOD_END = "silent_period_end" const val SP_SILENT_PERIOD_END = "silent_period_end"
const val SP_ENABLE_SILENT_PERIOD_LOGS = "enable_silent_period_logs"
const val SP_ENABLE_EXCLUDE_FROM_RECENTS = "enable_exclude_from_recents" const val SP_ENABLE_EXCLUDE_FROM_RECENTS = "enable_exclude_from_recents"
const val SP_ENABLE_PLAY_SILENCE_MUSIC = "enable_play_silence_music" const val SP_ENABLE_PLAY_SILENCE_MUSIC = "enable_play_silence_music"

View File

@ -71,6 +71,9 @@ class SettingUtils private constructor() {
//免打扰(禁用转发)时间段——结束 //免打扰(禁用转发)时间段——结束
var silentPeriodEnd: Int by SharedPreference(SP_SILENT_PERIOD_END, 0) var silentPeriodEnd: Int by SharedPreference(SP_SILENT_PERIOD_END, 0)
//免打扰(禁用转发)时间段——记录日志
var enableSilentPeriodLogs: Boolean by SharedPreference(SP_ENABLE_SILENT_PERIOD_LOGS, false)
//是否不在最近任务列表中显示 //是否不在最近任务列表中显示
var enableExcludeFromRecents: Boolean by SharedPreference(SP_ENABLE_EXCLUDE_FROM_RECENTS, false) var enableExcludeFromRecents: Boolean by SharedPreference(SP_ENABLE_EXCLUDE_FROM_RECENTS, false)

View File

@ -6,12 +6,14 @@ import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import com.google.gson.Gson import com.google.gson.Gson
import com.idormy.sms.forwarder.R
import com.idormy.sms.forwarder.core.Core import com.idormy.sms.forwarder.core.Core
import com.idormy.sms.forwarder.database.entity.Logs import com.idormy.sms.forwarder.database.entity.Logs
import com.idormy.sms.forwarder.database.entity.Msg import com.idormy.sms.forwarder.database.entity.Msg
import com.idormy.sms.forwarder.database.entity.Rule import com.idormy.sms.forwarder.database.entity.Rule
import com.idormy.sms.forwarder.entity.MsgInfo import com.idormy.sms.forwarder.entity.MsgInfo
import com.idormy.sms.forwarder.utils.* import com.idormy.sms.forwarder.utils.*
import com.xuexiang.xutil.resource.ResUtils
import com.xuexiang.xutil.security.CipherUtils import com.xuexiang.xutil.security.CipherUtils
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -30,6 +32,7 @@ class SendWorker(
return withContext(Dispatchers.IO) { return withContext(Dispatchers.IO) {
try { try {
// 免打扰(禁用转发)时间段 // 免打扰(禁用转发)时间段
var isSilentPeriod = false
if (SettingUtils.silentPeriodStart != SettingUtils.silentPeriodEnd) { if (SettingUtils.silentPeriodStart != SettingUtils.silentPeriodEnd) {
val periodStartDay = Date() val periodStartDay = Date()
var periodStartEnd = Date() var periodStartEnd = Date()
@ -52,8 +55,12 @@ class SendWorker(
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
if (periodStart != null && periodEnd != null && now in periodStart..periodEnd) { if (periodStart != null && periodEnd != null && now in periodStart..periodEnd) {
Log.e("SendWorker", "免打扰(禁用转发)时间段") if (SettingUtils.enableSilentPeriodLogs) {
return@withContext Result.failure(workDataOf("send" to "failed")) isSilentPeriod = true
} else {
Log.e("SendWorker", "免打扰(禁用转发)时间段")
return@withContext Result.failure(workDataOf("send" to "failed"))
}
} }
} }
@ -61,9 +68,7 @@ class SendWorker(
val msgInfo = Gson().fromJson(msgInfoJson, MsgInfo::class.java) val msgInfo = Gson().fromJson(msgInfoJson, MsgInfo::class.java)
// 过滤重复消息机制 // 过滤重复消息机制
var duplicateMessagesLimits = SettingUtils.duplicateMessagesLimits * 1000L val duplicateMessagesLimits = SettingUtils.duplicateMessagesLimits * 1000L
// 电池状态监听/网络状态监控 默认开启1秒去重
if (duplicateMessagesLimits == 0L && (msgInfo.from == "88888888" || msgInfo.from == "77777777")) duplicateMessagesLimits = 1000L
if (duplicateMessagesLimits > 0L) { if (duplicateMessagesLimits > 0L) {
val key = CipherUtils.md5(msgInfo.type + msgInfo.from + msgInfo.content) val key = CipherUtils.md5(msgInfo.type + msgInfo.from + msgInfo.content)
val timestamp: Long = System.currentTimeMillis() val timestamp: Long = System.currentTimeMillis()
@ -97,6 +102,11 @@ class SendWorker(
val msgId = Core.msg.insert(msg) val msgId = Core.msg.insert(msg)
for (rule in ruleListMatched) { for (rule in ruleListMatched) {
val sender = rule.senderList[0] val sender = rule.senderList[0]
if (isSilentPeriod) {
val log = Logs(0, msgInfo.type, msgId, rule.id, sender.id, 0, ResUtils.getString(R.string.silent_time_period))
Core.logs.insert(log)
continue
}
val log = Logs(0, msgInfo.type, msgId, rule.id, sender.id) val log = Logs(0, msgInfo.type, msgId, rule.id, sender.id)
val logId = Core.logs.insert(log) val logId = Core.logs.insert(log)
SendUtils.sendMsgSender(msgInfo, rule, 0, logId, msgId) SendUtils.sendMsgSender(msgInfo, rule, 0, logId, msgId)

View File

@ -829,13 +829,14 @@
style="@style/BarStyle" style="@style/BarStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="RtlSymmetry"> tools:ignore="RtlSymmetry">
<LinearLayout <LinearLayout
android:layout_width="180dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:gravity="center_vertical"
tools:ignore="TextSizeCheck"> android:orientation="horizontal">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -845,38 +846,64 @@
tools:ignore="RelativeOverlap" /> tools:ignore="RelativeOverlap" />
<TextView <TextView
android:id="@+id/tv_silent_period"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:gravity="center" />
<com.xuexiang.xui.widget.button.shadowbutton.RippleShadowShadowButton
android:id="@+id/btn_silent_period"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:gravity="center"
android:padding="3dp"
android:text="@string/select"
android:textColor="@color/white"
android:textSize="@dimen/text_size_mini"
app:sb_color_unpressed="@color/colorPrimary"
app:sb_ripple_color="@color/white"
app:sb_ripple_duration="500"
app:sb_shape_type="rectangle"
tools:ignore="PrivateResource,SmallSp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/silent_time_period_tips" android:text="@string/silent_time_period_tips"
android:textSize="@dimen/text_size_mini" android:textSize="@dimen/text_size_mini"
tools:ignore="SmallSp" /> tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_silent_period_logs"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginStart="@dimen/config_margin_10dp"
app:scb_color_checked="@color/colorPrimary"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:singleLine="true"
android:text="@string/silent_time_period_logs"
android:textSize="@dimen/text_size_small"
tools:ignore="SmallSp" />
</LinearLayout> </LinearLayout>
<TextView
android:id="@+id/tv_silent_period"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:gravity="center" />
<com.xuexiang.xui.widget.button.shadowbutton.RippleShadowShadowButton
android:id="@+id/btn_silent_period"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:gravity="center"
android:padding="5dp"
android:text="@string/select"
android:textColor="@color/white"
android:textSize="@dimen/text_size_small"
app:sb_color_unpressed="@color/colorPrimary"
app:sb_ripple_color="@color/white"
app:sb_ripple_duration="500"
app:sb_shape_type="rectangle"
tools:ignore="SmallSp,TextContrastCheck,TouchTargetSizeCheck" />
</LinearLayout> </LinearLayout>
<LinearLayout style="@style/BarTitleStyle"> <LinearLayout style="@style/BarTitleStyle">

View File

@ -1043,6 +1043,7 @@
<string name="select_time_period">Select Time Period</string> <string name="select_time_period">Select Time Period</string>
<string name="silent_time_period">Disable FW. Period</string> <string name="silent_time_period">Disable FW. Period</string>
<string name="silent_time_period_tips">If the end time is less than the start time, it will span days; if it is equal, it will be disabled</string> <string name="silent_time_period_tips">If the end time is less than the start time, it will span days; if it is equal, it will be disabled</string>
<string name="silent_time_period_logs">Save Logs</string>
<string name="download_frpc_tips">Do you want to download and restart to load!</string> <string name="download_frpc_tips">Do you want to download and restart to load!</string>
<string name="download_frpc_tips2">Download successful, do you want to restart the loading now?</string> <string name="download_frpc_tips2">Download successful, do you want to restart the loading now?</string>
<string name="appkey">AppKey</string> <string name="appkey">AppKey</string>

View File

@ -1044,6 +1044,7 @@
<string name="select_time_period">时间段选择</string> <string name="select_time_period">时间段选择</string>
<string name="silent_time_period">免打扰(禁用转发)时间段</string> <string name="silent_time_period">免打扰(禁用转发)时间段</string>
<string name="silent_time_period_tips">结束时间小于开始则跨天;相等则禁用</string> <string name="silent_time_period_tips">结束时间小于开始则跨天;相等则禁用</string>
<string name="silent_time_period_logs">记录日志</string>
<string name="download_frpc_tips">是否立即下载,并重启加载?</string> <string name="download_frpc_tips">是否立即下载,并重启加载?</string>
<string name="download_frpc_tips2">下载成功,是否立即重启加载?</string> <string name="download_frpc_tips2">下载成功,是否立即重启加载?</string>
<string name="appkey">AppKey</string> <string name="appkey">AppKey</string>

View File

@ -1044,6 +1044,7 @@
<string name="select_time_period">時間段選擇</string> <string name="select_time_period">時間段選擇</string>
<string name="silent_time_period">免打擾(禁用轉發)時間段</string> <string name="silent_time_period">免打擾(禁用轉發)時間段</string>
<string name="silent_time_period_tips">結束時間小於開始則跨天;相等則禁用</string> <string name="silent_time_period_tips">結束時間小於開始則跨天;相等則禁用</string>
<string name="silent_time_period_logs">記錄日誌</string>
<string name="download_frpc_tips">是否立即下載,並重啟加載?</string> <string name="download_frpc_tips">是否立即下載,並重啟加載?</string>
<string name="download_frpc_tips2">下載成功,是否立即重啟加載?</string> <string name="download_frpc_tips2">下載成功,是否立即重啟加載?</string>
<string name="appkey">AppKey</string> <string name="appkey">AppKey</string>

View File

@ -1044,6 +1044,7 @@
<string name="select_time_period">时间段选择</string> <string name="select_time_period">时间段选择</string>
<string name="silent_time_period">免打扰(禁用转发)时间段</string> <string name="silent_time_period">免打扰(禁用转发)时间段</string>
<string name="silent_time_period_tips">结束时间小于开始则跨天;相等则禁用</string> <string name="silent_time_period_tips">结束时间小于开始则跨天;相等则禁用</string>
<string name="silent_time_period_logs">记录日志</string>
<string name="download_frpc_tips">是否立即下载,并重启加载?</string> <string name="download_frpc_tips">是否立即下载,并重启加载?</string>
<string name="download_frpc_tips2">下载成功,是否立即重启加载?</string> <string name="download_frpc_tips2">下载成功,是否立即重启加载?</string>
<string name="appkey">AppKey</string> <string name="appkey">AppKey</string>