优化:部分操作按钮增加倒计时,避免重复点击

This commit is contained in:
pppscn 2022-06-07 16:05:06 +08:00
parent 440235f8f5
commit 0c5268cc46
21 changed files with 363 additions and 33 deletions

View File

@ -30,6 +30,7 @@ import com.xuexiang.xpage.core.PageOption
import com.xuexiang.xpage.model.PageInfo
import com.xuexiang.xrouter.utils.TextUtils
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.utils.DensityUtils
import com.xuexiang.xui.utils.ResUtils
import com.xuexiang.xui.utils.WidgetUtils
@ -45,13 +46,22 @@ class ClientFragment : BaseFragment<FragmentClientBinding?>(),
val TAG: String = ClientFragment::class.java.simpleName
private var appContext: App? = null
private var serverConfig: ConfigData? = null
private var mCountDownHelper: CountDownButtonHelper? = null
override fun initViews() {
appContext = requireActivity().application as App
//val context = requireContext()
//Set Server-Logging for Server
//val serverLogging = ServerLogging(context.filesDir.absolutePath)
//appContext!!.httpServer.serverLogging = serverLogging
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnServerTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnServerTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnServerTest.text = getString(R.string.server_test)
}
})
WidgetUtils.initGridRecyclerView(binding!!.recyclerView, 3, DensityUtils.dp2px(1f))
val widgetItemAdapter = WidgetItemAdapter(CLIENT_FRAGMENT_LIST)
@ -159,6 +169,7 @@ class ClientFragment : BaseFragment<FragmentClientBinding?>(),
val requestMsg: String = Gson().toJson(msgMap)
Log.i(TAG, "requestMsg:$requestMsg")
if (needToast) mCountDownHelper?.start()
XHttp.post(requestUrl)
.upJson(requestMsg)
.keepJson(true)
@ -193,4 +204,9 @@ class ClientFragment : BaseFragment<FragmentClientBinding?>(),
})
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -164,9 +164,7 @@ class LoginFragment : BaseFragment<FragmentLoginBinding?>(), View.OnClickListene
}
override fun onDestroyView() {
if (mCountDownHelper != null) {
mCountDownHelper!!.recycle()
}
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -28,6 +28,7 @@ import com.xuexiang.xhttp2.callback.SimpleCallBack
import com.xuexiang.xhttp2.exception.ApiException
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.utils.TextUtils
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.utils.ResUtils
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xutil.app.AppUtils
@ -44,6 +45,10 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
val TAG: String = SmsQueryFragment::class.java.simpleName
private var backupPath: String? = null
private val backupFile = "SmsForwarder.json"
private var pushCountDownHelper: CountDownButtonHelper? = null
private var pullCountDownHelper: CountDownButtonHelper? = null
private var exportCountDownHelper: CountDownButtonHelper? = null
private var importCountDownHelper: CountDownButtonHelper? = null
override fun viewBindingInflate(
inflater: LayoutInflater,
@ -96,6 +101,48 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
binding!!.layoutOffline.visibility = View.GONE
}
}
//按钮增加倒计时,避免重复点击
pushCountDownHelper = CountDownButtonHelper(binding!!.btnPush, SettingUtils.requestTimeout)
pushCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnPush.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnPush.text = getString(R.string.push)
}
})
pullCountDownHelper = CountDownButtonHelper(binding!!.btnPull, SettingUtils.requestTimeout)
pullCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnPull.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnPull.text = getString(R.string.pull)
}
})
exportCountDownHelper = CountDownButtonHelper(binding!!.btnExport, 3)
exportCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnExport.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnExport.text = getString(R.string.export)
}
})
importCountDownHelper = CountDownButtonHelper(binding!!.btnImport, 3)
importCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnImport.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnImport.text = getString(R.string.imports)
}
})
}
override fun initListeners() {
@ -115,6 +162,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
//导出配置
R.id.btn_export -> {
try {
exportCountDownHelper?.start()
val file = File(backupPath + File.separator + backupFile)
//判断文件是否存在,存在则在创建之前删除
FileUtils.createFileByDeleteOldFile(file)
@ -133,6 +181,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
//导入配置
R.id.btn_import -> {
try {
importCountDownHelper?.start()
val file = File(backupPath + File.separator + backupFile)
//判断文件是否存在
if (!FileUtils.isFileExists(file)) {
@ -171,6 +220,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
//推送配置
private fun pushData() {
pushCountDownHelper?.start()
val requestUrl: String = HttpServerUtils.serverAddress + "/clone/push"
Log.i(TAG, "requestUrl:$requestUrl")
@ -223,6 +273,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
//拉取配置
private fun pullData() {
exportCountDownHelper?.start()
val requestUrl: String = HttpServerUtils.serverAddress + "/clone/pull"
Log.i(TAG, "requestUrl:$requestUrl")
@ -292,4 +343,12 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
})
}
override fun onDestroyView() {
if (pushCountDownHelper != null) pushCountDownHelper!!.recycle()
if (pullCountDownHelper != null) pullCountDownHelper!!.recycle()
if (exportCountDownHelper != null) exportCountDownHelper!!.recycle()
if (importCountDownHelper != null) importCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -19,6 +19,7 @@ import com.xuexiang.xhttp2.callback.SimpleCallBack
import com.xuexiang.xhttp2.exception.ApiException
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.utils.TextUtils
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.utils.ResUtils
import com.xuexiang.xui.widget.actionbar.TitleBar
@ -27,6 +28,7 @@ import com.xuexiang.xui.widget.actionbar.TitleBar
class SmsSendFragment : BaseFragment<FragmentClientSmsSendBinding?>(), View.OnClickListener {
val TAG: String = SmsSendFragment::class.java.simpleName
private var mCountDownHelper: CountDownButtonHelper? = null
override fun viewBindingInflate(
inflater: LayoutInflater,
@ -43,6 +45,17 @@ class SmsSendFragment : BaseFragment<FragmentClientSmsSendBinding?>(), View.OnCl
* 初始化控件
*/
override fun initViews() {
//发送按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnSubmit, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnSubmit.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnSubmit.text = getString(R.string.send)
}
})
}
override fun initListeners() {
@ -93,6 +106,7 @@ class SmsSendFragment : BaseFragment<FragmentClientSmsSendBinding?>(), View.OnCl
val requestMsg: String = Gson().toJson(msgMap)
Log.i(TAG, "requestMsg:$requestMsg")
mCountDownHelper?.start()
XHttp.post(requestUrl)
.upJson(requestMsg)
.keepJson(true)
@ -129,4 +143,9 @@ class SmsSendFragment : BaseFragment<FragmentClientSmsSendBinding?>(), View.OnCl
}
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -23,6 +23,8 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.utils.CountDownButtonHelper.OnCountDownListener
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -40,6 +42,7 @@ class BarkFragment : BaseFragment<FragmentSendersBarkBinding?>(), View.OnClickLi
private val TAG: String = BarkFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
private var barkLevel: String = "active" //通知级别
@JvmField
@ -74,6 +77,18 @@ class BarkFragment : BaseFragment<FragmentSendersBarkBinding?>(), View.OnClickLi
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
binding!!.spLevel.setItems(BARK_LEVEL_MAP.values.toList())
binding!!.spLevel.setOnItemSelectedListener { _: MaterialSpinner?, _: Int, _: Long, item: Any ->
BARK_LEVEL_MAP.forEach {
@ -167,6 +182,7 @@ class BarkFragment : BaseFragment<FragmentSendersBarkBinding?>(), View.OnClickLi
return
}
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -237,4 +253,9 @@ class BarkFragment : BaseFragment<FragmentSendersBarkBinding?>(), View.OnClickLi
return BarkSetting(server, group, icon, sound, badge, url, barkLevel, title)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -23,6 +23,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -39,6 +40,7 @@ class DingtalkFragment : BaseFragment<FragmentSendersDingtalkBinding?>(), View.O
private val TAG: String = DingtalkFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -72,6 +74,18 @@ class DingtalkFragment : BaseFragment<FragmentSendersDingtalkBinding?>(), View.O
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -143,6 +157,7 @@ class DingtalkFragment : BaseFragment<FragmentSendersDingtalkBinding?>(), View.O
try {
when (v.id) {
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -208,4 +223,9 @@ class DingtalkFragment : BaseFragment<FragmentSendersDingtalkBinding?>(), View.O
return DingtalkSetting(token, secret, atAll, atMobiles)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -23,6 +23,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.utils.ResUtils
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
@ -41,6 +42,7 @@ class EmailFragment : BaseFragment<FragmentSendersEmailBinding?>(), View.OnClick
private val TAG: String = EmailFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
private var mailType: String = getString(R.string.other_mail_type) //邮箱类型
@JvmField
@ -75,6 +77,18 @@ class EmailFragment : BaseFragment<FragmentSendersEmailBinding?>(), View.OnClick
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
val mailTypeArray = ResUtils.getStringArray(R.array.MailType)
Log.d(TAG, mailTypeArray.toString())
binding!!.spMailType.setOnItemSelectedListener { _: MaterialSpinner?, position: Int, _: Long, item: Any ->
@ -176,6 +190,7 @@ class EmailFragment : BaseFragment<FragmentSendersEmailBinding?>(), View.OnClick
return
}
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -239,4 +254,9 @@ class EmailFragment : BaseFragment<FragmentSendersEmailBinding?>(), View.OnClick
return EmailSetting(mailType, fromEmail, pwd, nickname, host, port, ssl, startTls, toEmail, title)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -23,6 +23,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -39,6 +40,7 @@ class FeishuFragment : BaseFragment<FragmentSendersFeishuBinding?>(), View.OnCli
private val TAG: String = FeishuFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -72,6 +74,18 @@ class FeishuFragment : BaseFragment<FragmentSendersFeishuBinding?>(), View.OnCli
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -142,6 +156,7 @@ class FeishuFragment : BaseFragment<FragmentSendersFeishuBinding?>(), View.OnCli
return
}
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -204,4 +219,9 @@ class FeishuFragment : BaseFragment<FragmentSendersFeishuBinding?>(), View.OnCli
return FeishuSetting(webhook, secret, msgType, title)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -23,6 +23,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -39,6 +40,7 @@ class GotifyFragment : BaseFragment<FragmentSendersGotifyBinding?>(), View.OnCli
private val TAG: String = GotifyFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -72,6 +74,18 @@ class GotifyFragment : BaseFragment<FragmentSendersGotifyBinding?>(), View.OnCli
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -141,6 +155,7 @@ class GotifyFragment : BaseFragment<FragmentSendersGotifyBinding?>(), View.OnCli
return
}
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -202,4 +217,9 @@ class GotifyFragment : BaseFragment<FragmentSendersGotifyBinding?>(), View.OnCli
return GotifySetting(webServer, title, priority)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -24,6 +24,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -40,6 +41,7 @@ class PushplusFragment : BaseFragment<FragmentSendersPushplusBinding?>(), View.O
private val TAG: String = PushplusFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -73,6 +75,18 @@ class PushplusFragment : BaseFragment<FragmentSendersPushplusBinding?>(), View.O
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -161,6 +175,7 @@ class PushplusFragment : BaseFragment<FragmentSendersPushplusBinding?>(), View.O
return
}
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -232,4 +247,9 @@ class PushplusFragment : BaseFragment<FragmentSendersPushplusBinding?>(), View.O
return PushplusSetting(website, token, topic, template, channel, webhook, callbackUrl, validTime, title)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -16,15 +16,13 @@ import com.idormy.sms.forwarder.database.viewmodel.SenderViewModel
import com.idormy.sms.forwarder.databinding.FragmentSendersServerchanBinding
import com.idormy.sms.forwarder.entity.MsgInfo
import com.idormy.sms.forwarder.entity.setting.ServerchanSetting
import com.idormy.sms.forwarder.utils.KEY_SENDER_CLONE
import com.idormy.sms.forwarder.utils.KEY_SENDER_ID
import com.idormy.sms.forwarder.utils.KEY_SENDER_TYPE
import com.idormy.sms.forwarder.utils.XToastUtils
import com.idormy.sms.forwarder.utils.*
import com.idormy.sms.forwarder.utils.sender.ServerchanUtils
import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -41,6 +39,7 @@ class ServerchanFragment : BaseFragment<FragmentSendersServerchanBinding?>(), Vi
private val TAG: String = ServerchanFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -74,6 +73,18 @@ class ServerchanFragment : BaseFragment<FragmentSendersServerchanBinding?>(), Vi
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -126,6 +137,7 @@ class ServerchanFragment : BaseFragment<FragmentSendersServerchanBinding?>(), Vi
try {
when (v.id) {
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -198,4 +210,9 @@ class ServerchanFragment : BaseFragment<FragmentSendersServerchanBinding?>(), Vi
return ServerchanSetting(sendKey, channel, openid)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -25,6 +25,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -41,6 +42,7 @@ class SmsFragment : BaseFragment<FragmentSendersSmsBinding?>(), View.OnClickList
private val TAG: String = SmsFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -97,6 +99,18 @@ class SmsFragment : BaseFragment<FragmentSendersSmsBinding?>(), View.OnClickList
}
})
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -149,6 +163,7 @@ class SmsFragment : BaseFragment<FragmentSendersSmsBinding?>(), View.OnClickList
try {
when (v.id) {
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -214,4 +229,9 @@ class SmsFragment : BaseFragment<FragmentSendersSmsBinding?>(), View.OnClickList
return SmsSetting(simSlot, mobiles, onlyNoNetwork)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -18,15 +18,13 @@ import com.idormy.sms.forwarder.database.viewmodel.SenderViewModel
import com.idormy.sms.forwarder.databinding.FragmentSendersTelegramBinding
import com.idormy.sms.forwarder.entity.MsgInfo
import com.idormy.sms.forwarder.entity.setting.TelegramSetting
import com.idormy.sms.forwarder.utils.KEY_SENDER_CLONE
import com.idormy.sms.forwarder.utils.KEY_SENDER_ID
import com.idormy.sms.forwarder.utils.KEY_SENDER_TYPE
import com.idormy.sms.forwarder.utils.XToastUtils
import com.idormy.sms.forwarder.utils.*
import com.idormy.sms.forwarder.utils.sender.TelegramUtils
import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -44,6 +42,7 @@ class TelegramFragment : BaseFragment<FragmentSendersTelegramBinding?>(), View.O
private val TAG: String = TelegramFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -77,6 +76,18 @@ class TelegramFragment : BaseFragment<FragmentSendersTelegramBinding?>(), View.O
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -152,6 +163,7 @@ class TelegramFragment : BaseFragment<FragmentSendersTelegramBinding?>(), View.O
try {
when (v.id) {
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -232,4 +244,9 @@ class TelegramFragment : BaseFragment<FragmentSendersTelegramBinding?>(), View.O
return TelegramSetting(method, apiToken, chatId, proxyType, proxyHost, proxyPort, proxyAuthenticator, proxyUsername, proxyPassword)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -25,6 +25,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -41,6 +42,7 @@ class WebhookFragment : BaseFragment<FragmentSendersWebhookBinding?>(), View.OnC
private val TAG: String = WebhookFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
private var headerItemMap = HashMap<Int, LinearLayout>(2)
@JvmField
@ -75,6 +77,18 @@ class WebhookFragment : BaseFragment<FragmentSendersWebhookBinding?>(), View.OnC
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -135,6 +149,7 @@ class WebhookFragment : BaseFragment<FragmentSendersWebhookBinding?>(), View.OnC
try {
when (v.id) {
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -248,4 +263,9 @@ class WebhookFragment : BaseFragment<FragmentSendersWebhookBinding?>(), View.OnC
return headers
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.fragment.senders
import android.annotation.SuppressLint
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
@ -17,15 +18,13 @@ import com.idormy.sms.forwarder.database.viewmodel.SenderViewModel
import com.idormy.sms.forwarder.databinding.FragmentSendersWeworkAgentBinding
import com.idormy.sms.forwarder.entity.MsgInfo
import com.idormy.sms.forwarder.entity.setting.WeworkAgentSetting
import com.idormy.sms.forwarder.utils.KEY_SENDER_CLONE
import com.idormy.sms.forwarder.utils.KEY_SENDER_ID
import com.idormy.sms.forwarder.utils.KEY_SENDER_TYPE
import com.idormy.sms.forwarder.utils.XToastUtils
import com.idormy.sms.forwarder.utils.*
import com.idormy.sms.forwarder.utils.sender.WeworkAgentUtils
import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -42,6 +41,7 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
private val TAG: String = WeworkAgentFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -75,6 +75,18 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -125,6 +137,7 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
binding!!.sbAtAll.setOnCheckedChangeListener(this)
}
@SuppressLint("SetTextI18n")
override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
//TODO: 这里只有一个监听不需要判断id
if (isChecked) {
@ -141,6 +154,7 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
try {
when (v.id) {
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -204,4 +218,9 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
return WeworkAgentSetting(corpID, agentID, secret, atAll, toUser)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -22,6 +22,7 @@ import com.xuexiang.xaop.annotation.SingleClick
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xrouter.annotation.AutoWired
import com.xuexiang.xrouter.launcher.XRouter
import com.xuexiang.xui.utils.CountDownButtonHelper
import com.xuexiang.xui.widget.actionbar.TitleBar
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
@ -38,6 +39,7 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
private val TAG: String = WeworkRobotFragment::class.java.simpleName
var titleBar: TitleBar? = null
private val viewModel by viewModels<SenderViewModel> { BaseViewModelFactory(context) }
private var mCountDownHelper: CountDownButtonHelper? = null
@JvmField
@AutoWired(name = KEY_SENDER_ID)
@ -71,6 +73,18 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
* 初始化控件
*/
override fun initViews() {
//测试按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnTest, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) {
binding!!.btnTest.text = String.format(getString(R.string.seconds_n), time)
}
override fun onFinished() {
binding!!.btnTest.text = getString(R.string.test)
}
})
//新增
if (senderId <= 0) {
titleBar?.setSubTitle(getString(R.string.add_sender))
@ -121,6 +135,7 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
try {
when (v.id) {
R.id.btn_test -> {
mCountDownHelper?.start()
val settingVo = checkSetting()
Log.d(TAG, settingVo.toString())
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
@ -179,4 +194,9 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
return WeworkRobotSetting(webHook)
}
override fun onDestroyView() {
if (mCountDownHelper != null) mCountDownHelper!!.recycle()
super.onDestroyView()
}
}

View File

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#FFFFFF" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
</vector>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -83,21 +82,16 @@
android:layout_marginStart="5dp"
android:layout_weight="1" />
<com.xuexiang.xui.widget.button.shadowbutton.RippleShadowShadowButton
<com.xuexiang.xui.widget.button.ButtonView
android:id="@+id/btn_server_test"
style="@style/ButtonView.Green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:gravity="center"
android:minWidth="70dp"
android:padding="5dp"
android:text="测试接口"
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" />
android:text="@string/server_test" />
</LinearLayout>

View File

@ -123,10 +123,9 @@
<com.xuexiang.xui.widget.textview.supertextview.SuperButton
android:id="@+id/btn_submit"
style="@style/SuperButton.Blue.Icon"
android:drawableStart="@drawable/icon_save"
android:paddingStart="15dp"
android:text="@string/submit"
android:textSize="11sp"
android:drawableStart="@drawable/ic_send_white"
android:paddingStart="20dp"
android:text="@string/send"
tools:ignore="RtlSymmetry" />
</LinearLayout>

View File

@ -158,6 +158,7 @@
<string name="del">Delete</string>
<string name="save">Save</string>
<string name="submit">Submit</string>
<string name="send">Send</string>
<string name="test">Test</string>
<string name="confirm">Confirm</string>
<string name="all">All</string>
@ -506,6 +507,7 @@
<string name="interval">Interval</string>
<string name="timeout">timeout</string>
<string name="seconds">sec</string>
<string name="seconds_n">%s sec</string>
<string name="retry">Retry</string>
<string name="test_sender_sms">[Test Channel] Congratulations, the sending channel test is successful, please continue to add forwarding rules!</string>
<string name="test_sim_info" tools:ignore="Typos">SIM1_TestOperator_18888888888</string>
@ -800,4 +802,5 @@
<string name="battery_status">Status: %s</string>
<string name="battery_health">Health: %s</string>
<string name="battery_plugged">Plugged: %s</string>
<string name="server_test">Server Test</string>
</resources>

View File

@ -159,6 +159,7 @@
<string name="del">删除</string>
<string name="save">保存</string>
<string name="submit">提交</string>
<string name="send">发送</string>
<string name="test">测试</string>
<string name="confirm">确认</string>
<string name="all">全部</string>
@ -507,6 +508,7 @@
<string name="interval">间隔</string>
<string name="timeout">超时</string>
<string name="seconds"></string>
<string name="seconds_n">%s 秒</string>
<string name="retry">重试</string>
<string name="test_sender_sms">【测试通道】恭喜您,该发送通道测试成功,请继续添加转发规则!</string>
<string name="test_sim_info" tools:ignore="Typos">SIM1_测试运营商_18888888888</string>
@ -801,4 +803,5 @@
<string name="battery_status">电池状态:%s</string>
<string name="battery_health">健康度:%s</string>
<string name="battery_plugged">充电器:%s</string>
<string name="server_test">测试接口</string>
</resources>