Files
suixinkan_uikit/suixinkan/UI/LocationReport/LocationReportDialogPresenter.swift

74 lines
2.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LocationReportDialogPresenter.swift
// suixinkan
//
import UIKit
/// Android
enum LocationReportDialogPresenter {
/// 线
@MainActor
static func presentOnlineStatusSwitch(
from viewController: UIViewController,
isOnline: Bool,
onConfirm: @escaping () -> Void,
onCancel: (() -> Void)? = nil
) {
let message = isOnline
? "是否确认切换为离线状态?\n离线后将暂停位置上报,直到下次手动切换为在线状态"
: "是否确认切换为在线状态?\n在线后将开始位置上报和计时"
let alert = UIAlertController(title: "切换在线状态", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "取消", style: .cancel) { _ in onCancel?() })
alert.addAction(UIAlertAction(title: "确定", style: .default) { _ in onConfirm() })
viewController.present(alert, animated: true)
}
///
@MainActor
static func presentReportSuccess(
from viewController: UIViewController,
reportTime: String,
countdown: String,
onDismiss: (() -> Void)? = nil
) {
let message = "上报已成功,上报时间为\(reportTime)\n距离下次上报时间\(countdown)"
let alert = UIAlertController(title: "上报成功", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "确定", style: .default) { _ in onDismiss?() })
viewController.present(alert, animated: true)
}
///
@MainActor
static func presentLocationTimeout(
from viewController: UIViewController,
onReport: @escaping () -> Void,
onLater: (() -> Void)? = nil
) {
let alert = UIAlertController(
title: "位置上报提醒",
message: "倒计时即将结束,请立即上报位置",
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: "稍后", style: .cancel) { _ in onLater?() })
alert.addAction(UIAlertAction(title: "立即上报", style: .default) { _ in onReport() })
viewController.present(alert, animated: true)
}
///
@MainActor
static func presentReminderPicker(
from viewController: UIViewController,
onSelect: @escaping (Int) -> Void
) {
let alert = UIAlertController(title: "提醒设置", message: "提前提醒时间", preferredStyle: .actionSheet)
[0, 5, 10, 15, 30].forEach { minutes in
let title = minutes == 0 ? "不提醒" : "提前\(minutes)分钟"
alert.addAction(UIAlertAction(title: title, style: .default) { _ in onSelect(minutes) })
}
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
viewController.present(alert, animated: true)
}
}