mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-04 01:47:40 +08:00
新增:免打扰(禁用转发)时间段
This commit is contained in:
parent
0b27e2a8ee
commit
2d787fbdc0
@ -41,7 +41,9 @@ import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
|
|||||||
import com.xuexiang.xui.widget.picker.XRangeSlider
|
import com.xuexiang.xui.widget.picker.XRangeSlider
|
||||||
import com.xuexiang.xui.widget.picker.XRangeSlider.OnRangeSliderListener
|
import com.xuexiang.xui.widget.picker.XRangeSlider.OnRangeSliderListener
|
||||||
import com.xuexiang.xui.widget.picker.XSeekBar
|
import com.xuexiang.xui.widget.picker.XSeekBar
|
||||||
|
import com.xuexiang.xui.widget.picker.widget.builder.OptionsPickerBuilder
|
||||||
import com.xuexiang.xui.widget.picker.widget.builder.TimePickerBuilder
|
import com.xuexiang.xui.widget.picker.widget.builder.TimePickerBuilder
|
||||||
|
import com.xuexiang.xui.widget.picker.widget.listener.OnOptionsSelectListener
|
||||||
import com.xuexiang.xutil.XUtil
|
import com.xuexiang.xutil.XUtil
|
||||||
import com.xuexiang.xutil.XUtil.getPackageManager
|
import com.xuexiang.xutil.XUtil.getPackageManager
|
||||||
import com.xuexiang.xutil.app.AppUtils.getAppPackageName
|
import com.xuexiang.xutil.app.AppUtils.getAppPackageName
|
||||||
@ -54,6 +56,7 @@ import java.util.*
|
|||||||
class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickListener {
|
class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickListener {
|
||||||
|
|
||||||
val TAG: String = SettingsFragment::class.java.simpleName
|
val TAG: String = SettingsFragment::class.java.simpleName
|
||||||
|
private val mTimeOption = DataProvider.timePeriodOption
|
||||||
|
|
||||||
override fun viewBindingInflate(
|
override fun viewBindingInflate(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@ -85,6 +88,8 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
|||||||
binding!!.xsbDuplicateMessagesLimits.setOnSeekBarListener { _: XSeekBar?, newValue: Int ->
|
binding!!.xsbDuplicateMessagesLimits.setOnSeekBarListener { _: XSeekBar?, newValue: Int ->
|
||||||
SettingUtils.duplicateMessagesLimits = newValue
|
SettingUtils.duplicateMessagesLimits = newValue
|
||||||
}
|
}
|
||||||
|
//免打扰(禁用转发)时间段
|
||||||
|
binding!!.tvSilentPeriod.text = mTimeOption[SettingUtils.silentPeriodStart] + " ~ " + mTimeOption[SettingUtils.silentPeriodEnd]
|
||||||
|
|
||||||
//监听电池状态变化
|
//监听电池状态变化
|
||||||
switchBatteryReceiver(binding!!.sbBatteryReceiver)
|
switchBatteryReceiver(binding!!.sbBatteryReceiver)
|
||||||
@ -130,6 +135,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun initListeners() {
|
override fun initListeners() {
|
||||||
|
binding!!.btnSilentPeriod.setOnClickListener(this)
|
||||||
binding!!.btnExtraDeviceMark.setOnClickListener(this)
|
binding!!.btnExtraDeviceMark.setOnClickListener(this)
|
||||||
binding!!.btnExtraSim1.setOnClickListener(this)
|
binding!!.btnExtraSim1.setOnClickListener(this)
|
||||||
binding!!.btnExtraSim2.setOnClickListener(this)
|
binding!!.btnExtraSim2.setOnClickListener(this)
|
||||||
@ -145,6 +151,21 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
|||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) {
|
||||||
val etSmsTemplate: EditText = binding!!.etSmsTemplate
|
val etSmsTemplate: EditText = binding!!.etSmsTemplate
|
||||||
when (v.id) {
|
when (v.id) {
|
||||||
|
R.id.btn_silent_period -> {
|
||||||
|
OptionsPickerBuilder(context, OnOptionsSelectListener { _: View?, options1: Int, options2: Int, _: Int ->
|
||||||
|
SettingUtils.silentPeriodStart = options1
|
||||||
|
SettingUtils.silentPeriodEnd = options2
|
||||||
|
val txt = mTimeOption[options1] + " ~ " + mTimeOption[options2]
|
||||||
|
binding!!.tvSilentPeriod.text = txt
|
||||||
|
XToastUtils.toast(txt)
|
||||||
|
return@OnOptionsSelectListener false
|
||||||
|
}).setTitleText(getString(R.string.select_time_period))
|
||||||
|
.setSelectOptions(SettingUtils.silentPeriodStart, SettingUtils.silentPeriodEnd)
|
||||||
|
.build<Any>().also {
|
||||||
|
it.setNPicker(mTimeOption, mTimeOption)
|
||||||
|
it.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
R.id.btn_extra_device_mark -> {
|
R.id.btn_extra_device_mark -> {
|
||||||
binding!!.etExtraDeviceMark.setText(PhoneUtils.getDeviceName())
|
binding!!.etExtraDeviceMark.setText(PhoneUtils.getDeviceName())
|
||||||
return
|
return
|
||||||
|
@ -39,6 +39,8 @@ const val ENABLE_LOAD_USER_APP_LIST = "enable_load_user_app_list"
|
|||||||
const val ENABLE_LOAD_SYSTEM_APP_LIST = "enable_load_system_app_list"
|
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_END = "silent_period_end"
|
||||||
|
|
||||||
const val SP_BATTERY_RECEIVER = "enable_battery_receiver"
|
const val SP_BATTERY_RECEIVER = "enable_battery_receiver"
|
||||||
const val SP_BATTERY_STATUS = "battery_status"
|
const val SP_BATTERY_STATUS = "battery_status"
|
||||||
|
@ -42,4 +42,33 @@ object DataProvider {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取时间段
|
||||||
|
@JvmStatic
|
||||||
|
@get:MemoryCache
|
||||||
|
val timePeriodOption: List<String>
|
||||||
|
get() {
|
||||||
|
return getTimePeriod(24, 10) //修改时请注意会不会造成旧版下标越界
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取时间段
|
||||||
|
*
|
||||||
|
* @param interval 时间间隔(分钟)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
fun getTimePeriod(totalHour: Int, interval: Int): List<String> {
|
||||||
|
val list: MutableList<String> = ArrayList()
|
||||||
|
var point: Int
|
||||||
|
var hour: Int
|
||||||
|
var min: Int
|
||||||
|
for (i in 0..totalHour * 60 / interval) {
|
||||||
|
point = i * interval
|
||||||
|
hour = point / 60
|
||||||
|
min = point - hour * 60
|
||||||
|
list.add((if (hour <= 9) "0$hour" else "" + hour) + ":" + if (min <= 9) "0$min" else "" + min)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
}
|
}
|
@ -117,6 +117,22 @@ class SettingUtils private constructor() {
|
|||||||
MMKVUtils.put(SP_DUPLICATE_MESSAGES_LIMITS, duplicateMessagesLimits)
|
MMKVUtils.put(SP_DUPLICATE_MESSAGES_LIMITS, duplicateMessagesLimits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//免打扰(禁用转发)时间段——开始
|
||||||
|
@JvmStatic
|
||||||
|
var silentPeriodStart: Int
|
||||||
|
get() = MMKVUtils.getInt(SP_SILENT_PERIOD_START, 0)
|
||||||
|
set(silentPeriodStart) {
|
||||||
|
MMKVUtils.put(SP_SILENT_PERIOD_START, silentPeriodStart)
|
||||||
|
}
|
||||||
|
|
||||||
|
//免打扰(禁用转发)时间段——结束
|
||||||
|
@JvmStatic
|
||||||
|
var silentPeriodEnd: Int
|
||||||
|
get() = MMKVUtils.getInt(SP_SILENT_PERIOD_END, 0)
|
||||||
|
set(silentPeriodEnd) {
|
||||||
|
MMKVUtils.put(SP_SILENT_PERIOD_END, silentPeriodEnd)
|
||||||
|
}
|
||||||
|
|
||||||
//是否监听电池状态变化
|
//是否监听电池状态变化
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
var enableBatteryReceiver: Boolean
|
var enableBatteryReceiver: Boolean
|
||||||
|
@ -10,13 +10,13 @@ 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.RuleAndSender
|
import com.idormy.sms.forwarder.database.entity.RuleAndSender
|
||||||
import com.idormy.sms.forwarder.entity.MsgInfo
|
import com.idormy.sms.forwarder.entity.MsgInfo
|
||||||
import com.idormy.sms.forwarder.utils.HistoryUtils
|
import com.idormy.sms.forwarder.utils.*
|
||||||
import com.idormy.sms.forwarder.utils.SendUtils
|
|
||||||
import com.idormy.sms.forwarder.utils.SettingUtils
|
|
||||||
import com.idormy.sms.forwarder.utils.Worker
|
|
||||||
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
|
||||||
|
import java.text.ParsePosition
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class SendWorker(
|
class SendWorker(
|
||||||
context: Context,
|
context: Context,
|
||||||
@ -27,6 +27,35 @@ class SendWorker(
|
|||||||
|
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
|
// 免打扰(禁用转发)时间段
|
||||||
|
if (SettingUtils.silentPeriodStart != SettingUtils.silentPeriodEnd) {
|
||||||
|
val periodStartDay = Date()
|
||||||
|
var periodStartEnd = Date()
|
||||||
|
//跨天了
|
||||||
|
if (SettingUtils.silentPeriodStart > SettingUtils.silentPeriodEnd) {
|
||||||
|
val c: Calendar = Calendar.getInstance()
|
||||||
|
c.time = periodStartEnd
|
||||||
|
c.add(Calendar.DAY_OF_MONTH, 1)
|
||||||
|
periodStartEnd = c.time
|
||||||
|
}
|
||||||
|
|
||||||
|
val dateFmt = SimpleDateFormat("yyyy-MM-dd")
|
||||||
|
val mTimeOption = DataProvider.timePeriodOption
|
||||||
|
val periodStartStr = dateFmt.format(periodStartDay) + " " + mTimeOption[SettingUtils.silentPeriodStart] + ":00"
|
||||||
|
val periodEndStr = dateFmt.format(periodStartEnd) + " " + mTimeOption[SettingUtils.silentPeriodEnd] + ":00"
|
||||||
|
|
||||||
|
val timeFmt = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||||
|
val periodStart = timeFmt.parse(periodStartStr, ParsePosition(0)).time
|
||||||
|
val periodEnd = timeFmt.parse(periodEndStr, ParsePosition(0)).time
|
||||||
|
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
if (now in periodStart..periodEnd) {
|
||||||
|
Log.e("SendWorker", "免打扰(禁用转发)时间段")
|
||||||
|
return@withContext Result.failure(workDataOf("send" to "failed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
val msgInfoJson = inputData.getString(Worker.sendMsgInfo)
|
val msgInfoJson = inputData.getString(Worker.sendMsgInfo)
|
||||||
val msgInfo = Gson().fromJson(msgInfoJson, MsgInfo::class.java)
|
val msgInfo = Gson().fromJson(msgInfoJson, MsgInfo::class.java)
|
||||||
|
|
||||||
|
@ -371,6 +371,60 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
style="@style/settingBarStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingEnd="15dp"
|
||||||
|
tools:ignore="RtlSymmetry">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/silent_time_period"
|
||||||
|
android:textStyle="bold"
|
||||||
|
tools:ignore="RelativeOverlap" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/silent_time_period_tips"
|
||||||
|
android:textSize="9sp"
|
||||||
|
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="10sp"
|
||||||
|
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" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -869,4 +869,7 @@
|
|||||||
<string name="load_app_list_tips">Used to speed up entering the application list/editing forwarding rules drop-down selection/replacement {{APP_NAME}}</string>
|
<string name="load_app_list_tips">Used to speed up entering the application list/editing forwarding rules drop-down selection/replacement {{APP_NAME}}</string>
|
||||||
<string name="load_app_list_toast">A type must be selected when enabling asynchronous loading of the list of installed apps</string>
|
<string name="load_app_list_toast">A type must be selected when enabling asynchronous loading of the list of installed apps</string>
|
||||||
<string name="no_server_history">There is no history record, it will be added automatically after the interface test is passed</string>
|
<string name="no_server_history">There is no history record, it will be added automatically after the interface test is passed</string>
|
||||||
|
<string name="select_time_period">Select Time Period</string>
|
||||||
|
<string name="silent_time_period">Silent (disable forwarding) time 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>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -870,4 +870,7 @@
|
|||||||
<string name="load_app_list_tips">用于加速进入应用列表/编辑转发规则下拉选择/替换{{APP名称}}</string>
|
<string name="load_app_list_tips">用于加速进入应用列表/编辑转发规则下拉选择/替换{{APP名称}}</string>
|
||||||
<string name="load_app_list_toast">开启异步获取已安装App列表时必选一个类型</string>
|
<string name="load_app_list_toast">开启异步获取已安装App列表时必选一个类型</string>
|
||||||
<string name="no_server_history">暂无历史记录,接口测试通过后自动加入</string>
|
<string name="no_server_history">暂无历史记录,接口测试通过后自动加入</string>
|
||||||
|
<string name="select_time_period">时间段选择</string>
|
||||||
|
<string name="silent_time_period">免打扰(禁用转发)时间段</string>
|
||||||
|
<string name="silent_time_period_tips">结束时间小于开始时间则跨天;相等则禁用</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user