Skip to content

Commit

Permalink
Add settings for bolder content font
Browse files Browse the repository at this point in the history
  • Loading branch information
hartlco committed Feb 16, 2020
1 parent 6d562d7 commit 089cad1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Icro/View/Settings/SettingsContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct SettingsContentView: View {
var body: some View {
NavigationView {
Form {
AppearanceSection(store: store)
WordpressSection(store: store)
MicropubSection(store: store, settingsNavigator: settingsNavigator)
AccountSection(settingsNavigator: settingsNavigator)
Expand Down Expand Up @@ -150,6 +151,20 @@ struct AccountSection: View {
}
}

struct AppearanceSection: View {
@ObservedObject var store: SettingsViewModel

var body: some View {
return Section(header: Text("Appearance")
.font(.headline)
.fontWeight(.bold)) {
Toggle(isOn: $store.useMediumContentFont) {
Text("Use bolder content font")
}
}
}
}

struct TipJarSection: View {
@ObservedObject var tipJarViewModel = TipJarViewModel()

Expand Down
10 changes: 10 additions & 0 deletions Icro/ViewModel/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class SettingsViewModel: ObservableObject {
self.notificationCenter = notificationCenter
self.indieAuthMeURLString = userSettings.indieAuthMeURLString
self.canSendMail = canSendMail
self.useMediumContentFont = userSettings.useMediumContentFont

if isWordpressBlog {
isMicropubBlog = false
Expand Down Expand Up @@ -115,6 +116,14 @@ final class SettingsViewModel: ObservableObject {
let wordpressSubTitle = NSLocalizedString("SETTINGSVIEWCONTROLLER_BLOGINFO_TEXT", comment: "")
let wordpressSwitchTitle = NSLocalizedString("SETTINGSVIEWCONTROLLER_BLOGSETUPSWITCH_TEXT", comment: "")

// MARK: - Appearance

var useMediumContentFont: Bool {
didSet {
updateSetup()
}
}

private func updateSetup() {
objectWillChange.send()

Expand All @@ -141,5 +150,6 @@ final class SettingsViewModel: ObservableObject {
}

userSettings.indieAuthMeURLString = indieAuthMeURLString
userSettings.useMediumContentFont = useMediumContentFont
}
}
14 changes: 11 additions & 3 deletions IcroKit/Helper/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Copyright © 2018 Martin Hartl. All rights reserved.
//

import Settings

#if os(iOS)
import UIKit
public typealias XFont = UIFont
Expand All @@ -11,16 +13,22 @@ public typealias XFont = NSFont
#endif

public struct Font {
private let userSettings: UserSettings

public init(userSettings: UserSettings = .shared) {
self.userSettings = userSettings
}

#if os(iOS)
let bodySize: CGFloat = 17
#elseif os(OSX)
let bodySize: CGFloat = 13
#endif

public init() { }

public var body: XFont {
let font = XFont.systemFont(ofSize: bodySize, weight: .medium)
let useMedium = userSettings.useMediumContentFont
let font = XFont.systemFont(ofSize: bodySize,
weight: useMedium ? .medium : .regular)
let fontMetrics = UIFontMetrics(forTextStyle: .body)
return fontMetrics.scaledFont(for: font)
}
Expand Down
12 changes: 12 additions & 0 deletions Settings/Sources/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ public final class UserSettings {
}
}

// MARK: - Appearance

public var useMediumContentFont: Bool {
set {
userDefaults.set(newValue, forKey: #function)
}
get {
guard let data = userDefaults.value(forKey: #function) as? Bool else { return true }
return data
}
}

public func logout() {
token = ""
username = ""
Expand Down

0 comments on commit 089cad1

Please sign in to comment.