[O] Make Alarm a class

This commit is contained in:
Hykilpikonna
2021-01-17 15:59:25 -05:00
parent ce9cbd7127
commit c54e18ad64
3 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate
{ {
// Init default settings // Init default settings
localStorage.register(defaults: [ localStorage.register(defaults: [
"alarms": JSON.stringify([Alarm(enabled: true, hour: 7, minute: 20, text: "Wake up lol", wakeMethod: wvms[0])])! "alarms": JSON.stringify([Alarm(hour: 7, minute: 20, text: "Wake up lol", wakeMethod: wvms[0])])!
]) ])
return true return true
+11 -3
View File
@@ -36,19 +36,27 @@ let wvms = [
WVM(name: "Smash", desc: "It'll never truns off"), WVM(name: "Smash", desc: "It'll never truns off"),
] ]
struct Alarm: Codable class Alarm: Codable
{ {
var enabled: Bool var enabled: Bool = true
var hour: Int // Hour (24) var hour: Int // Hour (24)
var minute: Int var minute: Int
var text: String var text: String
var wakeMethod: WVM var wakeMethod: WVM
init(hour: Int, minute: Int, text: String, wakeMethod: WVM)
{
self.hour = hour
self.minute = minute
self.text = text
self.wakeMethod = wakeMethod
}
/// What days does it repeat (Sun, Mon, Tue, Wed, Thu, Fri, Sat) /// What days does it repeat (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
var repeats: [Bool] = [false, true, true, true, true, true, false] var repeats: [Bool] = [false, true, true, true, true, true, false]
/// Does it automatically disable after activating once /// Does it automatically disable after activating once
var oneTime = true var oneTime = false
/// When is the last time that the alarm went off /// When is the last time that the alarm went off
var lastActivate: Date = Date() var lastActivate: Date = Date()
+2 -2
View File
@@ -32,7 +32,7 @@ class TestingViewController: UIViewController
//Sends a test notification //Sends a test notification
@IBAction func sendNotification(_ sender: Any) @IBAction func sendNotification(_ sender: Any)
{ {
let alarm = Alarm(enabled: true, hour: 7, minute: 20, text: "Good morning!", wakeMethod: WVM(name: "walking", desc: "Walk")) let alarm = Alarm(hour: 7, minute: 20, text: "Good morning!", wakeMethod: WVM(name: "walking", desc: "Walk"))
let content = UNMutableNotificationContent() let content = UNMutableNotificationContent()
@@ -64,7 +64,7 @@ class TestingViewController: UIViewController
{ {
let (h, m, _) = Date().getHMS() let (h, m, _) = Date().getHMS()
let alarms = Alarms.fromLocal() let alarms = Alarms.fromLocal()
alarms.list.append(Alarm(enabled: true, hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[0])) alarms.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[0]))
alarms.localSave() alarms.localSave()
} }
} }