mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-02 17:07:41 +08:00
新增:免打扰(禁用转发)时间段记录日志(配合自动任务
实现延时发送) #411
This commit is contained in:
parent
c4f298ebe8
commit
06bc7adbe4
@ -127,6 +127,10 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
||||
}
|
||||
//免打扰(禁用转发)时间段
|
||||
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)
|
||||
|
@ -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_SILENT_PERIOD_START = "silent_period_start"
|
||||
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_PLAY_SILENCE_MUSIC = "enable_play_silence_music"
|
||||
|
@ -71,6 +71,9 @@ class SettingUtils private constructor() {
|
||||
//免打扰(禁用转发)时间段——结束
|
||||
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)
|
||||
|
||||
|
@ -6,12 +6,14 @@ import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import androidx.work.workDataOf
|
||||
import com.google.gson.Gson
|
||||
import com.idormy.sms.forwarder.R
|
||||
import com.idormy.sms.forwarder.core.Core
|
||||
import com.idormy.sms.forwarder.database.entity.Logs
|
||||
import com.idormy.sms.forwarder.database.entity.Msg
|
||||
import com.idormy.sms.forwarder.database.entity.Rule
|
||||
import com.idormy.sms.forwarder.entity.MsgInfo
|
||||
import com.idormy.sms.forwarder.utils.*
|
||||
import com.xuexiang.xutil.resource.ResUtils
|
||||
import com.xuexiang.xutil.security.CipherUtils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
@ -30,6 +32,7 @@ class SendWorker(
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
// 免打扰(禁用转发)时间段
|
||||
var isSilentPeriod = false
|
||||
if (SettingUtils.silentPeriodStart != SettingUtils.silentPeriodEnd) {
|
||||
val periodStartDay = Date()
|
||||
var periodStartEnd = Date()
|
||||
@ -52,8 +55,12 @@ class SendWorker(
|
||||
|
||||
val now = System.currentTimeMillis()
|
||||
if (periodStart != null && periodEnd != null && now in periodStart..periodEnd) {
|
||||
Log.e("SendWorker", "免打扰(禁用转发)时间段")
|
||||
return@withContext Result.failure(workDataOf("send" to "failed"))
|
||||
if (SettingUtils.enableSilentPeriodLogs) {
|
||||
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)
|
||||
|
||||
// 过滤重复消息机制
|
||||
var duplicateMessagesLimits = SettingUtils.duplicateMessagesLimits * 1000L
|
||||
// 电池状态监听/网络状态监控 默认开启1秒去重
|
||||
if (duplicateMessagesLimits == 0L && (msgInfo.from == "88888888" || msgInfo.from == "77777777")) duplicateMessagesLimits = 1000L
|
||||
val duplicateMessagesLimits = SettingUtils.duplicateMessagesLimits * 1000L
|
||||
if (duplicateMessagesLimits > 0L) {
|
||||
val key = CipherUtils.md5(msgInfo.type + msgInfo.from + msgInfo.content)
|
||||
val timestamp: Long = System.currentTimeMillis()
|
||||
@ -97,6 +102,11 @@ class SendWorker(
|
||||
val msgId = Core.msg.insert(msg)
|
||||
for (rule in ruleListMatched) {
|
||||
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 logId = Core.logs.insert(log)
|
||||
SendUtils.sendMsgSender(msgInfo, rule, 0, logId, msgId)
|
||||
|
@ -829,13 +829,14 @@
|
||||
style="@style/BarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="RtlSymmetry">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="180dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="TextSizeCheck">
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@ -845,38 +846,64 @@
|
||||
tools:ignore="RelativeOverlap" />
|
||||
|
||||
<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="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:textSize="@dimen/text_size_mini"
|
||||
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>
|
||||
|
||||
<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 style="@style/BarTitleStyle">
|
||||
|
@ -1043,6 +1043,7 @@
|
||||
<string name="select_time_period">Select Time 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_logs">Save Logs</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="appkey">AppKey</string>
|
||||
|
@ -1044,6 +1044,7 @@
|
||||
<string name="select_time_period">时间段选择</string>
|
||||
<string name="silent_time_period">免打扰(禁用转发)时间段</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_tips2">下载成功,是否立即重启加载?</string>
|
||||
<string name="appkey">AppKey</string>
|
||||
|
@ -1044,6 +1044,7 @@
|
||||
<string name="select_time_period">時間段選擇</string>
|
||||
<string name="silent_time_period">免打擾(禁用轉發)時間段</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_tips2">下載成功,是否立即重啟加載?</string>
|
||||
<string name="appkey">AppKey</string>
|
||||
|
@ -1044,6 +1044,7 @@
|
||||
<string name="select_time_period">时间段选择</string>
|
||||
<string name="silent_time_period">免打扰(禁用转发)时间段</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_tips2">下载成功,是否立即重启加载?</string>
|
||||
<string name="appkey">AppKey</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user