Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Merged dev into master
  • Loading branch information
masich committed Apr 11, 2020
2 parents b270627 + 314b03e commit b0a49d3
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 16 deletions.
8 changes: 4 additions & 4 deletions SaveMyEyes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 15;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_ASSET_PATHS = "\"SaveMyEyes/Preview Content\"";
DEVELOPMENT_TEAM = 5PYHR2J538;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -369,7 +369,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.25;
MARKETING_VERSION = 0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.masich.SaveMyEyes;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -384,7 +384,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 15;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_ASSET_PATHS = "\"SaveMyEyes/Preview Content\"";
DEVELOPMENT_TEAM = 5PYHR2J538;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -395,7 +395,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.25;
MARKETING_VERSION = 0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.masich.SaveMyEyes;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
9 changes: 7 additions & 2 deletions SaveMyEyes/Source/Common/AppNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import Foundation
import UserNotifications

class AppNotification {
public static let defaultSound = UNNotificationSound.default
public static let withoutSound: UNNotificationSound? = nil

private let title: String
private let subtitle: String
private let sound: UNNotificationSound?

struct Action {
static let pause = "pause.action"
Expand All @@ -21,16 +25,17 @@ class AppNotification {
static let reminder = "sme.reminder"
}

init(title: String, subtitle: String) {
init(title: String, subtitle: String, sound: UNNotificationSound? = defaultSound) {
self.title = title
self.subtitle = subtitle
self.sound = sound
}

func getNotificationContent() -> UNMutableNotificationContent {
let content = UNMutableNotificationContent()
content.title = title
content.subtitle = subtitle
content.sound = UNNotificationSound.default
content.sound = sound
content.categoryIdentifier = Category.reminder

return content
Expand Down
2 changes: 1 addition & 1 deletion SaveMyEyes/Source/Common/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

struct Constants {
// TODO: make it possible to take these values from user
// TODO: make it possible to take these values from the user input
public static let workIntervals = [15, 20, 30, 40, 60, 90, 120]
public static let breakIntervals = [1, 2, 5, 10, 15, 20, 30]

Expand Down
1 change: 1 addition & 0 deletions SaveMyEyes/Source/Common/Extentions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import SwiftUI

extension String {
/// Returns localized string value.
var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}
Expand Down
32 changes: 25 additions & 7 deletions SaveMyEyes/Source/Common/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,52 @@
import Foundation

class Preferences{
private static let selectedTimeIntervalKey = "SelectedTimeInterval";
private static let selectedBreakTimeKey = "SelectedBreakTime";
private static let isSoundEnabledKey = "IsSoundEnabled";

private static let defaults = UserDefaults.standard

/**
Returns selected time interval index retrieved from the local storage

returns `Int?`: Localy saved user selected time interval or nil when there is no
returns `Int`: Localy saved user selected time interval or `0` when there is no
saved time interval
*/
public static func getWorkIntervalIndexValue() -> Int {
return defaults.integer(forKey: "SelectedTimeInterval")
return defaults.integer(forKey: selectedTimeIntervalKey)
}

/**
Returns selected break time index retrieved from the local storage
Returns selected break time index retrieved from the local storage

returns `Int?`: Localy saved user selected break time index or nil when there is
returns `Int`: Localy saved user selected break time index or `0` when there is
no saved break time index
*/
public static func getBreakIntervalIndexValue() -> Int {
return defaults.integer(forKey: "SelectedBreakTime")
return defaults.integer(forKey: selectedBreakTimeKey)
}

/**
Returns is sound enabled value retrieved from the local storage

returns `Bool`: Localy saved is sound enabled value or `false` when there is
no saved is sound enabled value
*/
public static func isSoundEnabled() -> Bool {
return defaults.bool(forKey: isSoundEnabledKey)
}

public static func setWorkTimeIntervalIndexValue(_ value: Int) {
defaults.set(value, forKey: "SelectedTimeInterval")
defaults.set(value, forKey: selectedTimeIntervalKey)
}

public static func setBreakIntervalIndexValue(_ value: Int) {
defaults.set(value, forKey: "SelectedBreakTime")
defaults.set(value, forKey: selectedBreakTimeKey)
}

public static func setSoundEnabled(_ value: Bool) {
defaults.set(value, forKey: isSoundEnabledKey)
}
}

Expand Down
5 changes: 5 additions & 0 deletions SaveMyEyes/Source/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ struct MainView: View {
Spacer()
Toggle("Run timer toggle", isOn: self.$mainViewModel.shouldTimerRun.value).labelsHidden()
}.scaledToFill()
HStack(spacing: 20) {
Text("Enable sound")
Spacer()
Toggle("Enable sound toggle", isOn: self.$mainViewModel.isSoundEnabled.value).labelsHidden()
}.scaledToFill()
HStack(spacing: 20) {
Text("Work interval")
Spacer()
Expand Down
7 changes: 5 additions & 2 deletions SaveMyEyes/Source/Main/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MainViewModel: ObservableObject {
@Published private(set) var remainingMins: Int = 0

@Published var shouldTimerRun = Observable<Bool>(false)
@Published var isSoundEnabled = Observable<Bool>(Preferences.isSoundEnabled())
@Published var workIntervalIndex = Observable<Int>(Preferences.getWorkIntervalIndexValue())
@Published var breakIntervalIndex = Observable<Int>(Preferences.getBreakIntervalIndexValue())

Expand Down Expand Up @@ -83,6 +84,7 @@ class MainViewModel: ObservableObject {

cancellables = [
shouldTimerRun.subject.sink(receiveValue: timerWorker.toggleInternalTimer),
isSoundEnabled.subject.sink(receiveValue: Preferences.setSoundEnabled),
workIntervalIndex.subject.sink(receiveValue: onWorkIntervalChanged),
workIntervalIndex.subject.sink(receiveValue: Preferences.setWorkTimeIntervalIndexValue),
breakIntervalIndex.subject.sink(receiveValue: onBreakIntervalChanged),
Expand Down Expand Up @@ -141,10 +143,11 @@ class MainViewModel: ObservableObject {
*/
public func sendNotification() {
let notification: AppNotification
let notificationSound = isSoundEnabled.value ? AppNotification.defaultSound : AppNotification.withoutSound
if isBreakTimeNow {
notification = AppNotification(title: "It's time for break".localized, subtitle: String(format: "Relax from your computer for %d minutes.".localized, breakIntervals[breakIntervalIndex.value]))
notification = AppNotification(title: "It's time for break".localized, subtitle: String(format: "Relax from your computer for %d minutes.".localized, breakIntervals[breakIntervalIndex.value]), sound: notificationSound)
} else {
notification = AppNotification(title: "It's time to work".localized, subtitle: "Let's continue to do amazing things!".localized)
notification = AppNotification(title: "It's time to work".localized, subtitle: "Let's continue to do amazing things!".localized, sound: notificationSound)
}
AppNotificationManager.sendSingle(notification)
}
Expand Down
1 change: 1 addition & 0 deletions SaveMyEyes/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
"Relax from your computer for %d minutes." = "Relax from your computer for %d minutes.";
"Let's continue to do amazing things!" = "Let's continue to do amazing things!";
"Pause" = "Pause";
"Enable sound" = "Enable sound";
1 change: 1 addition & 0 deletions SaveMyEyes/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
"Relax from your computer for %d minutes." = "Відпочинь від компьютера на %d хвилин.";
"Let's continue to do amazing things!" = "Давай продовжимо робити круті речі!";
"Pause" = "Пауза";
"Enable sound" = "Увімкнути звук";

0 comments on commit b0a49d3

Please sign in to comment.