Skip to content

Commit

Permalink
#1 base modularization of app ViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Feb 4, 2022
1 parent 4e4aedb commit 2216734
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 182 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/).
<!-- - All functions have been reduced to a reasonable length (40 lines) where able. -->
<!-- - All functions have been reduced to a reasonable cyclomatic complexity (10 or less) where able. -->
<!-- - All files have been reduced to a reasonable length (400 lines) where able. -->
<!-- - All type bodies have been reduced to a reasonable length (200 lines) where able. -->
<!-- - Scribe has been modularized to be more easily worked with. -->
<!-- - The app screen's text was moved to a new directory where localizations will be stored. -->

Expand Down
32 changes: 28 additions & 4 deletions Scribe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
D190B26827426ACD00705659 /* KeyboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D190B2592742565500705659 /* KeyboardViewController.swift */; };
D190B26927426ACD00705659 /* KeyboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D190B2592742565500705659 /* KeyboardViewController.swift */; };
D19474C42740295300AF6EA5 /* prepositions.json in Resources */ = {isa = PBXBuildFile; fileRef = D19474C32740295300AF6EA5 /* prepositions.json */; };
D196B360279A051000228F3F /* PrivacyPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = D196B35F279A051000228F3F /* PrivacyPolicy.swift */; };
D196B360279A051000228F3F /* ENPrivacyPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = D196B35F279A051000228F3F /* ENPrivacyPolicy.swift */; };
D19E415927A7709D00C18CC3 /* ScribeBtnPadBlack.png in Resources */ = {isa = PBXBuildFile; fileRef = D19E415527A7709C00C18CC3 /* ScribeBtnPadBlack.png */; };
D19E415A27A7709D00C18CC3 /* ScribeBtnPadBlack.png in Resources */ = {isa = PBXBuildFile; fileRef = D19E415527A7709C00C18CC3 /* ScribeBtnPadBlack.png */; };
D19E415B27A7709D00C18CC3 /* ScribeBtnPadBlack.png in Resources */ = {isa = PBXBuildFile; fileRef = D19E415527A7709C00C18CC3 /* ScribeBtnPadBlack.png */; };
Expand All @@ -98,6 +98,8 @@
D19E416E27A7709D00C18CC3 /* ScribeBtnPadWhite.png in Resources */ = {isa = PBXBuildFile; fileRef = D19E415827A7709C00C18CC3 /* ScribeBtnPadWhite.png */; };
D19E416F27A7709D00C18CC3 /* ScribeBtnPadWhite.png in Resources */ = {isa = PBXBuildFile; fileRef = D19E415827A7709C00C18CC3 /* ScribeBtnPadWhite.png */; };
D19E417027A7709D00C18CC3 /* ScribeBtnPadWhite.png in Resources */ = {isa = PBXBuildFile; fileRef = D19E415827A7709C00C18CC3 /* ScribeBtnPadWhite.png */; };
D1A2DCB127AD37BD0057A10D /* ENAppText.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A2DCB027AD37BD0057A10D /* ENAppText.swift */; };
D1A2DCB427AD3EB50057A10D /* AppUISymbols.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A2DCB327AD3EB50057A10D /* AppUISymbols.swift */; };
D1C0ACDA2719E0AA001E11C3 /* Keyboard.xib in Resources */ = {isa = PBXBuildFile; fileRef = D1C0ACD92719E0AA001E11C3 /* Keyboard.xib */; };
D1D880CC27860CFA00407050 /* translations.json in Resources */ = {isa = PBXBuildFile; fileRef = D1D880C927860CFA00407050 /* translations.json */; };
D1D880CD27860CFA00407050 /* verbs.json in Resources */ = {isa = PBXBuildFile; fileRef = D1D880CA27860CFA00407050 /* verbs.json */; };
Expand Down Expand Up @@ -223,11 +225,13 @@
D190B28F27426F4900705659 /* LICENSE.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE.txt; sourceTree = SOURCE_ROOT; };
D190B29027426F4900705659 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; };
D19474C32740295300AF6EA5 /* prepositions.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = prepositions.json; sourceTree = "<group>"; };
D196B35F279A051000228F3F /* PrivacyPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyPolicy.swift; sourceTree = "<group>"; };
D196B35F279A051000228F3F /* ENPrivacyPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENPrivacyPolicy.swift; sourceTree = "<group>"; };
D19E415527A7709C00C18CC3 /* ScribeBtnPadBlack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ScribeBtnPadBlack.png; sourceTree = "<group>"; };
D19E415627A7709C00C18CC3 /* ScribeBtnPhoneBlack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ScribeBtnPhoneBlack.png; sourceTree = "<group>"; };
D19E415727A7709C00C18CC3 /* ScribeBtnPhoneWhite.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ScribeBtnPhoneWhite.png; sourceTree = "<group>"; };
D19E415827A7709C00C18CC3 /* ScribeBtnPadWhite.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ScribeBtnPadWhite.png; sourceTree = "<group>"; };
D1A2DCB027AD37BD0057A10D /* ENAppText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENAppText.swift; sourceTree = "<group>"; };
D1A2DCB327AD3EB50057A10D /* AppUISymbols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUISymbols.swift; sourceTree = "<group>"; };
D1C0ACD92719E0AA001E11C3 /* Keyboard.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Keyboard.xib; sourceTree = "<group>"; };
D1D880C927860CFA00407050 /* translations.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = translations.json; sourceTree = "<group>"; };
D1D880CA27860CFA00407050 /* verbs.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = verbs.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -327,9 +331,10 @@
38BD213222D5907F00C6795D /* Scribe */ = {
isa = PBXGroup;
children = (
D1A2DCAF27AD378F0057A10D /* AppTexts */,
38BD213322D5907F00C6795D /* AppDelegate.swift */,
D1A2DCB327AD3EB50057A10D /* AppUISymbols.swift */,
38BD213522D5907F00C6795D /* ViewController.swift */,
D196B35F279A051000228F3F /* PrivacyPolicy.swift */,
38BD213722D5907F00C6795D /* AppScreen.storyboard */,
38BD213F22D5908100C6795D /* LaunchScreen.storyboard */,
38BD213D22D5908100C6795D /* Assets.xcassets */,
Expand Down Expand Up @@ -486,6 +491,23 @@
path = Data;
sourceTree = "<group>";
};
D1A2DCAF27AD378F0057A10D /* AppTexts */ = {
isa = PBXGroup;
children = (
D1A2DCB227AD37D90057A10D /* English */,
);
path = AppTexts;
sourceTree = "<group>";
};
D1A2DCB227AD37D90057A10D /* English */ = {
isa = PBXGroup;
children = (
D196B35F279A051000228F3F /* ENPrivacyPolicy.swift */,
D1A2DCB027AD37BD0057A10D /* ENAppText.swift */,
);
path = English;
sourceTree = "<group>";
};
D1CCA15B2742B9F700902744 /* LanguageKeyboards */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -827,11 +849,13 @@
buildActionMask = 2147483647;
files = (
38BD213622D5907F00C6795D /* ViewController.swift in Sources */,
D196B360279A051000228F3F /* PrivacyPolicy.swift in Sources */,
D196B360279A051000228F3F /* ENPrivacyPolicy.swift in Sources */,
D1A2DCB427AD3EB50057A10D /* AppUISymbols.swift in Sources */,
38BD213422D5907F00C6795D /* AppDelegate.swift in Sources */,
D1F0367327AAE1B400CD7921 /* CommandVariables.swift in Sources */,
D1F0367227AAE12200CD7921 /* InterfaceVariables.swift in Sources */,
D1362A39274C106A00C00E48 /* ColorVariables.swift in Sources */,
D1A2DCB127AD37BD0057A10D /* ENAppText.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
127 changes: 127 additions & 0 deletions Scribe/AppTexts/English/ENAppText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// ENAppText.swift
//
// The English app text for the Scribe app.
//

import UIKit

/// Formats and returns the text for the installation guidelines.
///
/// - Parameters
/// - fontSize: the size of the font derived for the app text given screen dimensions.
func setAttributedInstallation(fontSize: CGFloat) -> NSMutableAttributedString {
// The down right arrow character as a text attachment.
let arrowAttachment = NSTextAttachment()
let selectArrowIconConfig = UIImage.SymbolConfiguration(pointSize: fontSize, weight: .medium, scale: .medium)
arrowAttachment.image = UIImage(
systemName: "arrow.turn.down.right",
withConfiguration: selectArrowIconConfig
)?.withTintColor(.scribeGrey)

// The globe character as a text attachment.
let globeAttachment = NSTextAttachment()
let selectGlobeIconConfig = UIImage.SymbolConfiguration(pointSize: fontSize, weight: .medium, scale: .medium)
globeAttachment.image = UIImage(
systemName: "globe",
withConfiguration: selectGlobeIconConfig
)?.withTintColor(.scribeGrey)

// Wrap the attachments in their own attributed strings so we can append them.
let arrowString = NSAttributedString(attachment: arrowAttachment)
let globeString = NSAttributedString(attachment: globeAttachment)

// Create components of the installation text, format their font sizes and add them step by step.
let installationTextTitle = NSMutableAttributedString(string: """
Keyboard Installation
""", attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: fontSize * 1.5)])

let startOfBody = NSMutableAttributedString(string: """
\n
1.\u{0020}
""", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize)])

let settingsLink = addHyperLinks(
originalText: "Open Settings",
links: ["Open Settings": "<makeTextLink>"], // placeholder as there's a button over it
fontSize: fontSize
)

let installStart = concatAttributedStrings(left: startOfBody, right: settingsLink)

let installDirections = NSMutableAttributedString(string: """
\n
2. In General do the following:
Keyboard
""", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize)])

installDirections.append(NSAttributedString(string: "\n "))

installDirections.append(arrowString)

installDirections.append(NSMutableAttributedString(string: """
\u{0020} Keyboards
""", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize)]))

installDirections.append(NSMutableAttributedString(
string: "\n ",
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize)]
)
)

installDirections.append(arrowString)

installDirections.append(NSMutableAttributedString(string: """
\u{0020} Add New Keyboard
3. Select Scribe and then activate keyboards
4. When typing press\u{0020}
""", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize)]))

installDirections.append(globeString)

installDirections.append(NSMutableAttributedString(string: """
\u{0020}to select keyboards
""", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize)]))

let installFullDirections = concatAttributedStrings(left: installStart, right: installDirections)

return concatAttributedStrings(
left: installationTextTitle,
right: installFullDirections
) as! NSMutableAttributedString
}

/// Formats and returns the text for a notice about Scribe's GitHub.
///
/// - Parameters
/// - fontSize: the size of the font derived for the app text given screen dimensions.
func setAttributedGitHubText(fontSize: CGFloat) -> NSMutableAttributedString {
let GHTextTitle = NSMutableAttributedString(string: """
Community
""", attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: fontSize * 1.5)])

// Initialize the main body of the text.
let GHInfoText = NSMutableAttributedString(string: """
\n
Scribe is fully open-source. To report issues or contribute please visit us at\u{0020}
""", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize)])

// A second NSAttributedString that includes a link to the GitHub.
let ghLink = addHyperLinks(
originalText: "github.com/scribe-org.",
links: ["github.com/scribe-org": "https://github.com/scribe-org"],
fontSize: fontSize
)

let GHInfoTextToLink = concatAttributedStrings(left: GHTextTitle, right: GHInfoText)

return concatAttributedStrings(
left: GHInfoTextToLink,
right: ghLink
) as! NSMutableAttributedString
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
//
// PrivacyPolicy.swift
//
// The privacy policy for the Scribe app.
// The English privacy policy for the Scribe app.
//
// PRIVACY.txt is formatted for GitHub, and this is formatted for modular sizing.
//

import UIKit

/// Formats and returns the text of the Scribe privacy policy.
func setAttributedPrivacyPolicy(fontSize: CGFloat) -> NSMutableAttributedString {
let privacyTextTitle = NSMutableAttributedString(string: """
Privacy Policy
""", attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: fontSize * 1.5)])

let wikidataDataLicensing: String = "https://www.wikidata.org/wiki/Wikidata:Licensing"
let huggingFaceLicensing: String = "https://github.com/huggingface/transformers/blob/master/LICENSE"
let scribeGitHub: String = "https://github.com/scribe-org"
let scribeEmail: String = "scribe.langauge@gmail.com"
let gitHubLogoLicensing: String = "https://github.com/logos"

let privacyPolicyTextWithLinks = addHyperLinks(
originalText: privacyPolicyText,
links: [
wikidataDataLicensing: wikidataDataLicensing,
huggingFaceLicensing: huggingFaceLicensing,
scribeGitHub: scribeGitHub,
scribeEmail: "mailto:" + scribeEmail,
gitHubLogoLicensing: gitHubLogoLicensing],
fontSize: fontSize
)

return concatAttributedStrings(
left: privacyTextTitle,
right: privacyPolicyTextWithLinks
) as! NSMutableAttributedString
}

// swiftlint:disable all

// Includes a new line so that there is space between it and the page title.
Expand Down
43 changes: 43 additions & 0 deletions Scribe/AppUISymbols.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// TextSymbols.swift
//
// Symbols needed for the app UI.
//

import UIKit

/// Formats and returns the settings symbol for the app text.
///
/// - Parameters
/// - fontSize: the size of the font derived for the app text given screen dimensions.
func getSettingsSymbol(fontSize: CGFloat) -> UIImage {
var settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.2, weight: .medium, scale: .medium)
if DeviceType.isPad {
if UIScreen.main.bounds.height < UIScreen.main.bounds.width {
settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.05, weight: .medium, scale: .medium)
} else {
settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.15, weight: .medium, scale: .medium)
}
}
let settingsSymbol: UIImage = UIImage(systemName: "gear", withConfiguration: settingsSymbolConfig)!

return settingsSymbol
}

/// Formats and returns the privacy symbol for the app text.
///
/// - Parameters
/// - fontSize: the size of the font derived for the app text given screen dimensions.
func getPrivacySymbol(fontSize: CGFloat) -> UIImage {
var privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.25, weight: .medium, scale: .medium)
if DeviceType.isPad {
if UIScreen.main.bounds.height < UIScreen.main.bounds.width {
privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.15, weight: .medium, scale: .medium)
} else {
privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.2, weight: .medium, scale: .medium)
}
}
let privacySymbol: UIImage = UIImage(systemName: "lock.shield", withConfiguration: privacySymbolConfig)!

return privacySymbol
}
Loading

0 comments on commit 2216734

Please sign in to comment.