Merge pull request #18 from tootsuite/feature/server-rule

Add server rules scene. Update sign up UX
This commit is contained in:
CMK 2021-02-22 18:20:01 +08:00 committed by GitHub
commit 74b08974fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 1347 additions and 198 deletions

8
Localization/README.md Normal file
View File

@ -0,0 +1,8 @@
# Localization
Mastodon localization template file
## How to contribute?
TBD

View File

@ -0,0 +1,25 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "StringsConvertor",
platforms: [
.macOS(.v10_15)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "StringsConvertor",
dependencies: []),
.testTarget(
name: "StringsConvertorTests",
dependencies: ["StringsConvertor"]),
]
)

View File

@ -0,0 +1,12 @@
# StringsConvertor
Convert i18n JSON file to Stings file.
## Usage
```
chmod +x scripts/build.sh
./scripts/build.sh
# lproj files will locate in output/ directory
```

View File

@ -0,0 +1,100 @@
//
// File.swift
//
//
// Created by Cirno MainasuK on 2020-7-7.
//
import Foundation
class Parser {
let json: [String: Any]
init(data: Data) throws {
let dict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
self.json = dict ?? [:]
}
}
extension Parser {
enum KeyStyle {
case infoPlist
case swiftgen
}
}
extension Parser {
func generateStrings(keyStyle: KeyStyle = .swiftgen) -> String {
let pairs = traval(dictionary: json, prefixKeys: [])
var lines: [String] = []
for pair in pairs {
let key = [
"\"",
pair.prefix
.map { segment in
segment
.split(separator: "_")
.map { String($0) }
.map {
switch keyStyle {
case .infoPlist: return $0
case .swiftgen: return $0.capitalized
}
}
.joined()
}
.joined(separator: "."),
"\""
].joined()
let value = [
"\"",
pair.value.replacingOccurrences(of: "%s", with: "%@"),
"\""
].joined()
let line = [
[key, value].joined(separator: " = "),
";"
].joined()
lines.append(line)
}
let strings = lines
.sorted()
.joined(separator: "\n")
return strings
}
}
extension Parser {
typealias PrefixKeys = [String]
typealias LocalizationPair = (prefix: PrefixKeys, value: String)
private func traval(dictionary: [String: Any], prefixKeys: PrefixKeys) -> [LocalizationPair] {
var pairs: [LocalizationPair] = []
for (key, any) in dictionary {
let prefix = prefixKeys + [key]
// if leaf node of dict tree
if let value = any as? String {
pairs.append(LocalizationPair(prefix: prefix, value: value))
continue
}
// if not leaf node of dict tree
if let dict = any as? [String: Any] {
let innerPairs = traval(dictionary: dict, prefixKeys: prefix)
pairs.append(contentsOf: innerPairs)
}
}
return pairs
}
}

View File

@ -0,0 +1,74 @@
import os.log
import Foundation
let currentFileURL = URL(fileURLWithPath: "\(#file)", isDirectory: false)
let packageRootURL = currentFileURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
let inputDirectoryURL = packageRootURL.appendingPathComponent("input", isDirectory: true)
let outputDirectoryURL = packageRootURL.appendingPathComponent("output", isDirectory: true)
private func convert(from inputDirectory: URL, to outputDirectory: URL) {
do {
let inputLanguageDirectoryURLs = try FileManager.default.contentsOfDirectory(
at: inputDirectoryURL,
includingPropertiesForKeys: [.nameKey, .isDirectoryKey],
options: []
)
for inputLanguageDirectoryURL in inputLanguageDirectoryURLs {
let language = inputLanguageDirectoryURL.lastPathComponent
guard let mappedLanguage = map(language: language) else { continue }
let outputDirectoryURL = outputDirectory.appendingPathComponent(mappedLanguage + ".lproj", isDirectory: true)
os_log("%{public}s[%{public}ld], %{public}s: process %s -> %s", ((#file as NSString).lastPathComponent), #line, #function, language, mappedLanguage)
let fileURLs = try FileManager.default.contentsOfDirectory(
at: inputLanguageDirectoryURL,
includingPropertiesForKeys: [.nameKey, .isDirectoryKey],
options: []
)
for jsonURL in fileURLs where jsonURL.pathExtension == "json" {
os_log("%{public}s[%{public}ld], %{public}s: process %s", ((#file as NSString).lastPathComponent), #line, #function, jsonURL.debugDescription)
let filename = jsonURL.deletingPathExtension().lastPathComponent
guard let (mappedFilename, keyStyle) = map(filename: filename) else { continue }
let outputFileURL = outputDirectoryURL.appendingPathComponent(mappedFilename).appendingPathExtension("strings")
let strings = try process(url: jsonURL, keyStyle: keyStyle)
try? FileManager.default.createDirectory(at: outputDirectoryURL, withIntermediateDirectories: true, attributes: nil)
try strings.write(to: outputFileURL, atomically: true, encoding: .utf8)
}
}
} catch {
os_log("%{public}s[%{public}ld], %{public}s: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
exit(1)
}
}
private func map(language: String) -> String? {
switch language {
case "en_US": return "en"
case "zh_CN": return "zh-Hans"
case "ja_JP": return "ja"
case "de_DE": return "de"
case "pt_BR": return "pt-BR"
default: return nil
}
}
private func map(filename: String) -> (filename: String, keyStyle: Parser.KeyStyle)? {
switch filename {
case "app": return ("Localizable", .swiftgen)
case "ios-infoPlist": return ("infoPlist", .infoPlist)
default: return nil
}
}
private func process(url: URL, keyStyle: Parser.KeyStyle) throws -> String {
do {
let data = try Data(contentsOf: url)
let parser = try Parser(data: data)
let strings = parser.generateStrings(keyStyle: keyStyle)
return strings
} catch {
os_log("%{public}s[%{public}ld], %{public}s: error: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
throw error
}
}
convert(from: inputDirectoryURL, to: outputDirectoryURL)

View File

@ -0,0 +1,7 @@
import XCTest
import StringsConvertorTests
var tests = [XCTestCaseEntry]()
tests += StringsConvertorTests.allTests()
XCTMain(tests)

View File

@ -0,0 +1,47 @@
import XCTest
import class Foundation.Bundle
final class StringsConvertorTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
// Some of the APIs that we use below are available in macOS 10.13 and above.
guard #available(macOS 10.13, *) else {
return
}
let fooBinary = productsDirectory.appendingPathComponent("StringsConvertor")
let process = Process()
process.executableURL = fooBinary
let pipe = Pipe()
process.standardOutput = pipe
try process.run()
process.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)
XCTAssertEqual(output, "Hello, world!\n")
}
/// Returns path to the built products directory.
var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
}
static var allTests = [
("testExample", testExample),
]
}

View File

@ -0,0 +1,9 @@
import XCTest
#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(StringsConvertorTests.allTests),
]
}
#endif

View File

@ -0,0 +1,78 @@
{
"common": {
"alerts": {},
"controls": {
"actions": {
"add": "Add",
"remove": "Remove",
"edit": "Edit",
"save": "Save",
"ok": "OK",
"confirm": "Confirm",
"continue": "Continue",
"cancel": "Cancel",
"take_photo": "Take photo",
"save_photo": "Save photo",
"sign_in": "Sign in",
"sign_up": "Sign up",
"see_more": "See More",
"preview": "Preview",
"open_in_safari": "Open in Safari"
},
"timeline": {
"load_more": "Load More"
}
},
"countable": {
"photo": {
"single": "photo",
"multiple": "photos"
}
}
},
"scene": {
"welcome": {
"slogan": "Social networking\nback in your hands."
},
"server_picker": {
"title": "Pick a Server,\nany server.",
"input": {
"placeholder": "Find a server or join your own..."
}
},
"register": {
"title": "Tell us about you.",
"input": {
"username": {
"placeholder": "username",
"duplicate_prompt": "This username is taken."
},
"display_name": {
"placeholder": "display name"
},
"email": {
"placeholder": "email"
},
"password": {
"placeholder": "password",
"prompt": "Your password needs at least:",
"prompt_eight_characters": "Eight characters"
}
}
},
"server_rules": {
"title": "Some ground rules.",
"subtitle": "These rules are set by the admins of %s.",
"prompt": "By continuing, you're subject to the terms of service and privacy policy for %s.",
"button": {
"confirm": "I Agree"
}
},
"home_timeline": {
"title": "Home"
},
"public_timeline": {
"title": "Public"
}
}
}

View File

@ -0,0 +1,4 @@
{
"NSCameraUsageDescription": "Used to take photo for toot",
"NSPhotoLibraryAddUsageDescription": "Used to save photo into the Photo Library"
}

View File

@ -0,0 +1,37 @@
"Common.Controls.Actions.Add" = "Add";
"Common.Controls.Actions.Cancel" = "Cancel";
"Common.Controls.Actions.Confirm" = "Confirm";
"Common.Controls.Actions.Continue" = "Continue";
"Common.Controls.Actions.Edit" = "Edit";
"Common.Controls.Actions.Ok" = "OK";
"Common.Controls.Actions.OpenInSafari" = "Open in Safari";
"Common.Controls.Actions.Preview" = "Preview";
"Common.Controls.Actions.Remove" = "Remove";
"Common.Controls.Actions.Save" = "Save";
"Common.Controls.Actions.SavePhoto" = "Save photo";
"Common.Controls.Actions.SeeMore" = "See More";
"Common.Controls.Actions.SignIn" = "Sign in";
"Common.Controls.Actions.SignUp" = "Sign up";
"Common.Controls.Actions.TakePhoto" = "Take photo";
"Common.Controls.Timeline.LoadMore" = "Load More";
"Common.Countable.Photo.Multiple" = "photos";
"Common.Countable.Photo.Single" = "photo";
"Scene.HomeTimeline.Title" = "Home";
"Scene.PublicTimeline.Title" = "Public";
"Scene.Register.Input.DisplayName.Placeholder" = "display name";
"Scene.Register.Input.Email.Placeholder" = "email";
"Scene.Register.Input.Password.Placeholder" = "password";
"Scene.Register.Input.Password.Prompt" = "Your password needs at least:";
"Scene.Register.Input.Password.PromptEightCharacters" = "Eight characters";
"Scene.Register.Input.Username.DuplicatePrompt" = "This username is taken.";
"Scene.Register.Input.Username.Placeholder" = "username";
"Scene.Register.Title" = "Tell us about you.";
"Scene.ServerPicker.Input.Placeholder" = "Find a server or join your own...";
"Scene.ServerPicker.Title" = "Pick a Server,
any server.";
"Scene.ServerRules.Button.Confirm" = "I Agree";
"Scene.ServerRules.Prompt" = "By continuing, you're subject to the terms of service and privacy policy for %@.";
"Scene.ServerRules.Subtitle" = "These rules are set by the admins of %@.";
"Scene.ServerRules.Title" = "Some ground rules.";
"Scene.Welcome.Slogan" = "Social networking
back in your hands.";

View File

@ -0,0 +1,2 @@
"NSCameraUsageDescription" = "Used to take photo for toot";
"NSPhotoLibraryAddUsageDescription" = "Used to save photo into the Photo Library";

View File

@ -0,0 +1,28 @@
#!/bin/zsh
set -ev
# Crowin_Latest_Build="https://crowdin.com/backend/download/project/<TBD>.zip"
if [[ -d input ]]; then
rm -rf input
fi
if [[ -d output ]]; then
rm -rf output
fi
mkdir output
# FIXME: temporary use local json for i18n
# replace by the Crowdin remote template later
mkdir -p input/en_US
cp ../app.json ./input/en_US
cp ../ios-infoPlist.json ./input/en_US
# curl -o <TBD>.zip -L ${Crowin_Latest_Build}
# unzip -o -q <TBD>.zip -d input
# rm -rf <TBD>.zip
swift run

78
Localization/app.json Normal file
View File

@ -0,0 +1,78 @@
{
"common": {
"alerts": {},
"controls": {
"actions": {
"add": "Add",
"remove": "Remove",
"edit": "Edit",
"save": "Save",
"ok": "OK",
"confirm": "Confirm",
"continue": "Continue",
"cancel": "Cancel",
"take_photo": "Take photo",
"save_photo": "Save photo",
"sign_in": "Sign in",
"sign_up": "Sign up",
"see_more": "See More",
"preview": "Preview",
"open_in_safari": "Open in Safari"
},
"timeline": {
"load_more": "Load More"
}
},
"countable": {
"photo": {
"single": "photo",
"multiple": "photos"
}
}
},
"scene": {
"welcome": {
"slogan": "Social networking\nback in your hands."
},
"server_picker": {
"title": "Pick a Server,\nany server.",
"input": {
"placeholder": "Find a server or join your own..."
}
},
"register": {
"title": "Tell us about you.",
"input": {
"username": {
"placeholder": "username",
"duplicate_prompt": "This username is taken."
},
"display_name": {
"placeholder": "display name"
},
"email": {
"placeholder": "email"
},
"password": {
"placeholder": "password",
"prompt": "Your password needs at least:",
"prompt_eight_characters": "Eight characters"
}
}
},
"server_rules": {
"title": "Some ground rules.",
"subtitle": "These rules are set by the admins of %s.",
"prompt": "By continuing, you're subject to the terms of service and privacy policy for %s.",
"button": {
"confirm": "I Agree"
}
},
"home_timeline": {
"title": "Home"
},
"public_timeline": {
"title": "Public"
}
}
}

View File

@ -0,0 +1,4 @@
{
"NSCameraUsageDescription": "Used to take photo for toot",
"NSPhotoLibraryAddUsageDescription": "Used to save photo into the Photo Library"
}

View File

@ -74,6 +74,8 @@
DB0140CF25C42AEE00F9F3CF /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0140CE25C42AEE00F9F3CF /* OSLog.swift */; }; DB0140CF25C42AEE00F9F3CF /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0140CE25C42AEE00F9F3CF /* OSLog.swift */; };
DB084B5725CBC56C00F898ED /* Toot.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB084B5625CBC56C00F898ED /* Toot.swift */; }; DB084B5725CBC56C00F898ED /* Toot.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB084B5625CBC56C00F898ED /* Toot.swift */; };
DB0AC6FC25CD02E600D75117 /* APIService+Instance.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0AC6FB25CD02E600D75117 /* APIService+Instance.swift */; }; DB0AC6FC25CD02E600D75117 /* APIService+Instance.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0AC6FB25CD02E600D75117 /* APIService+Instance.swift */; };
DB2B3ABC25E37E15007045F9 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = DB2B3ABE25E37E15007045F9 /* InfoPlist.strings */; };
DB2B3AE925E38850007045F9 /* UIViewPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB2B3AE825E38850007045F9 /* UIViewPreview.swift */; };
DB3D0FF325BAA61700EAA174 /* AlamofireImage in Frameworks */ = {isa = PBXBuildFile; productRef = DB3D0FF225BAA61700EAA174 /* AlamofireImage */; }; DB3D0FF325BAA61700EAA174 /* AlamofireImage in Frameworks */ = {isa = PBXBuildFile; productRef = DB3D0FF225BAA61700EAA174 /* AlamofireImage */; };
DB3D100D25BAA75E00EAA174 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = DB3D100F25BAA75E00EAA174 /* Localizable.strings */; }; DB3D100D25BAA75E00EAA174 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = DB3D100F25BAA75E00EAA174 /* Localizable.strings */; };
DB427DD625BAA00100D1B89D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB427DD525BAA00100D1B89D /* AppDelegate.swift */; }; DB427DD625BAA00100D1B89D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB427DD525BAA00100D1B89D /* AppDelegate.swift */; };
@ -96,6 +98,8 @@
DB5086AB25CC0BBB00C2C187 /* AvatarConfigurableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5086AA25CC0BBB00C2C187 /* AvatarConfigurableView.swift */; }; DB5086AB25CC0BBB00C2C187 /* AvatarConfigurableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5086AA25CC0BBB00C2C187 /* AvatarConfigurableView.swift */; };
DB5086B825CC0D6400C2C187 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = DB5086B725CC0D6400C2C187 /* Kingfisher */; }; DB5086B825CC0D6400C2C187 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = DB5086B725CC0D6400C2C187 /* Kingfisher */; };
DB5086BE25CC0D9900C2C187 /* SplashPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5086BD25CC0D9900C2C187 /* SplashPreference.swift */; }; DB5086BE25CC0D9900C2C187 /* SplashPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5086BD25CC0D9900C2C187 /* SplashPreference.swift */; };
DB72601C25E36A2100235243 /* MastodonServerRulesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB72601B25E36A2100235243 /* MastodonServerRulesViewController.swift */; };
DB72602725E36A6F00235243 /* MastodonServerRulesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB72602625E36A6F00235243 /* MastodonServerRulesViewModel.swift */; };
DB89B9F725C10FD0008580ED /* CoreDataStack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB89B9EE25C10FD0008580ED /* CoreDataStack.framework */; }; DB89B9F725C10FD0008580ED /* CoreDataStack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB89B9EE25C10FD0008580ED /* CoreDataStack.framework */; };
DB89B9FE25C10FD0008580ED /* CoreDataStackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB89B9FD25C10FD0008580ED /* CoreDataStackTests.swift */; }; DB89B9FE25C10FD0008580ED /* CoreDataStackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB89B9FD25C10FD0008580ED /* CoreDataStackTests.swift */; };
DB89BA0025C10FD0008580ED /* CoreDataStack.h in Headers */ = {isa = PBXBuildFile; fileRef = DB89B9F025C10FD0008580ED /* CoreDataStack.h */; settings = {ATTRIBUTES = (Public, ); }; }; DB89BA0025C10FD0008580ED /* CoreDataStack.h in Headers */ = {isa = PBXBuildFile; fileRef = DB89B9F025C10FD0008580ED /* CoreDataStack.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -252,6 +256,8 @@
DB0140CE25C42AEE00F9F3CF /* OSLog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OSLog.swift; sourceTree = "<group>"; }; DB0140CE25C42AEE00F9F3CF /* OSLog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OSLog.swift; sourceTree = "<group>"; };
DB084B5625CBC56C00F898ED /* Toot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toot.swift; sourceTree = "<group>"; }; DB084B5625CBC56C00F898ED /* Toot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toot.swift; sourceTree = "<group>"; };
DB0AC6FB25CD02E600D75117 /* APIService+Instance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Instance.swift"; sourceTree = "<group>"; }; DB0AC6FB25CD02E600D75117 /* APIService+Instance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Instance.swift"; sourceTree = "<group>"; };
DB2B3ABD25E37E15007045F9 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
DB2B3AE825E38850007045F9 /* UIViewPreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewPreview.swift; sourceTree = "<group>"; };
DB3D0FED25BAA42200EAA174 /* MastodonSDK */ = {isa = PBXFileReference; lastKnownFileType = folder; path = MastodonSDK; sourceTree = "<group>"; }; DB3D0FED25BAA42200EAA174 /* MastodonSDK */ = {isa = PBXFileReference; lastKnownFileType = folder; path = MastodonSDK; sourceTree = "<group>"; };
DB3D100E25BAA75E00EAA174 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; }; DB3D100E25BAA75E00EAA174 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
DB427DD225BAA00100D1B89D /* Mastodon.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mastodon.app; sourceTree = BUILT_PRODUCTS_DIR; }; DB427DD225BAA00100D1B89D /* Mastodon.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mastodon.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -279,6 +285,8 @@
DB5086A425CC0B7000C2C187 /* AvatarBarButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarBarButtonItem.swift; sourceTree = "<group>"; }; DB5086A425CC0B7000C2C187 /* AvatarBarButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarBarButtonItem.swift; sourceTree = "<group>"; };
DB5086AA25CC0BBB00C2C187 /* AvatarConfigurableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarConfigurableView.swift; sourceTree = "<group>"; }; DB5086AA25CC0BBB00C2C187 /* AvatarConfigurableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarConfigurableView.swift; sourceTree = "<group>"; };
DB5086BD25CC0D9900C2C187 /* SplashPreference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplashPreference.swift; sourceTree = "<group>"; }; DB5086BD25CC0D9900C2C187 /* SplashPreference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplashPreference.swift; sourceTree = "<group>"; };
DB72601B25E36A2100235243 /* MastodonServerRulesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonServerRulesViewController.swift; sourceTree = "<group>"; };
DB72602625E36A6F00235243 /* MastodonServerRulesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonServerRulesViewModel.swift; sourceTree = "<group>"; };
DB89B9EE25C10FD0008580ED /* CoreDataStack.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreDataStack.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DB89B9EE25C10FD0008580ED /* CoreDataStack.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreDataStack.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DB89B9F025C10FD0008580ED /* CoreDataStack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreDataStack.h; sourceTree = "<group>"; }; DB89B9F025C10FD0008580ED /* CoreDataStack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreDataStack.h; sourceTree = "<group>"; };
DB89B9F125C10FD0008580ED /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; DB89B9F125C10FD0008580ED /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -437,6 +445,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
2D5A3D0225CF8742002347D6 /* ControlContainableScrollViews.swift */, 2D5A3D0225CF8742002347D6 /* ControlContainableScrollViews.swift */,
DB2B3AE825E38850007045F9 /* UIViewPreview.swift */,
); );
path = Vender; path = Vender;
sourceTree = "<group>"; sourceTree = "<group>";
@ -564,6 +573,7 @@
children = ( children = (
DB0140A625C40C0900F9F3CF /* PinBased */, DB0140A625C40C0900F9F3CF /* PinBased */,
DBE0821A25CD382900FD6BBD /* Register */, DBE0821A25CD382900FD6BBD /* Register */,
DB72602125E36A2500235243 /* ServerRules */,
DB01409525C40B6700F9F3CF /* AuthenticationViewController.swift */, DB01409525C40B6700F9F3CF /* AuthenticationViewController.swift */,
DB98334625C8056600AD9700 /* AuthenticationViewModel.swift */, DB98334625C8056600AD9700 /* AuthenticationViewModel.swift */,
); );
@ -605,6 +615,7 @@
children = ( children = (
DB427DDE25BAA00100D1B89D /* Assets.xcassets */, DB427DDE25BAA00100D1B89D /* Assets.xcassets */,
DB3D100F25BAA75E00EAA174 /* Localizable.strings */, DB3D100F25BAA75E00EAA174 /* Localizable.strings */,
DB2B3ABE25E37E15007045F9 /* InfoPlist.strings */,
); );
path = Resources; path = Resources;
sourceTree = "<group>"; sourceTree = "<group>";
@ -644,13 +655,13 @@
children = ( children = (
DB427DE325BAA00100D1B89D /* Info.plist */, DB427DE325BAA00100D1B89D /* Info.plist */,
DB89BA1025C10FF5008580ED /* Mastodon.entitlements */, DB89BA1025C10FF5008580ED /* Mastodon.entitlements */,
2D5A3D0125CF8640002347D6 /* Vender */,
2D76319C25C151DE00929FB9 /* Diffiable */, 2D76319C25C151DE00929FB9 /* Diffiable */,
DB8AF52A25C13561002E6C99 /* State */, DB8AF52A25C13561002E6C99 /* State */,
2D61335525C1886800CAE157 /* Service */, 2D61335525C1886800CAE157 /* Service */,
DB8AF55525C1379F002E6C99 /* Scene */, DB8AF55525C1379F002E6C99 /* Scene */,
DB8AF54125C13647002E6C99 /* Coordinator */, DB8AF54125C13647002E6C99 /* Coordinator */,
DB8AF56225C138BC002E6C99 /* Extension */, DB8AF56225C138BC002E6C99 /* Extension */,
2D5A3D0125CF8640002347D6 /* Vender */,
DB5086CB25CC0DB400C2C187 /* Preference */, DB5086CB25CC0DB400C2C187 /* Preference */,
2D69CFF225CA9E2200C3A1B2 /* Protocol */, 2D69CFF225CA9E2200C3A1B2 /* Protocol */,
DB98338425C945ED00AD9700 /* Generated */, DB98338425C945ED00AD9700 /* Generated */,
@ -715,6 +726,15 @@
path = Preference; path = Preference;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
DB72602125E36A2500235243 /* ServerRules */ = {
isa = PBXGroup;
children = (
DB72601B25E36A2100235243 /* MastodonServerRulesViewController.swift */,
DB72602625E36A6F00235243 /* MastodonServerRulesViewModel.swift */,
);
path = ServerRules;
sourceTree = "<group>";
};
DB89B9EF25C10FD0008580ED /* CoreDataStack */ = { DB89B9EF25C10FD0008580ED /* CoreDataStack */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -805,12 +825,11 @@
DB8AF55525C1379F002E6C99 /* Scene */ = { DB8AF55525C1379F002E6C99 /* Scene */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
2D38F1D325CD463600561493 /* HomeTimeline */,
2D7631A425C1532200929FB9 /* Share */, 2D7631A425C1532200929FB9 /* Share */,
DB8AF54E25C13703002E6C99 /* MainTab */, DB8AF54E25C13703002E6C99 /* MainTab */,
DB01409B25C40BB600F9F3CF /* Authentication */, DB01409B25C40BB600F9F3CF /* Authentication */,
2D38F1D325CD463600561493 /* HomeTimeline */,
2D76316325C14BAC00929FB9 /* PublicTimeline */, 2D76316325C14BAC00929FB9 /* PublicTimeline */,
DBD4ED0B25CC0FD40041B741 /* HomeTimeline */,
); );
path = Scene; path = Scene;
sourceTree = "<group>"; sourceTree = "<group>";
@ -852,13 +871,6 @@
path = Generated; path = Generated;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
DBD4ED0B25CC0FD40041B741 /* HomeTimeline */ = {
isa = PBXGroup;
children = (
);
path = HomeTimeline;
sourceTree = "<group>";
};
DBE0821A25CD382900FD6BBD /* Register */ = { DBE0821A25CD382900FD6BBD /* Register */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -1057,6 +1069,7 @@
DB3D100D25BAA75E00EAA174 /* Localizable.strings in Resources */, DB3D100D25BAA75E00EAA174 /* Localizable.strings in Resources */,
DB427DDF25BAA00100D1B89D /* Assets.xcassets in Resources */, DB427DDF25BAA00100D1B89D /* Assets.xcassets in Resources */,
DB427DDD25BAA00100D1B89D /* Main.storyboard in Resources */, DB427DDD25BAA00100D1B89D /* Main.storyboard in Resources */,
DB2B3ABC25E37E15007045F9 /* InfoPlist.strings in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -1222,10 +1235,12 @@
2D38F1F725CD47AC00561493 /* HomeTimelineViewModel+LoadOldestState.swift in Sources */, 2D38F1F725CD47AC00561493 /* HomeTimelineViewModel+LoadOldestState.swift in Sources */,
2D5A3D3825CF8D9F002347D6 /* ScrollViewContainer.swift in Sources */, 2D5A3D3825CF8D9F002347D6 /* ScrollViewContainer.swift in Sources */,
DB8AF53025C13561002E6C99 /* AppContext.swift in Sources */, DB8AF53025C13561002E6C99 /* AppContext.swift in Sources */,
DB72602725E36A6F00235243 /* MastodonServerRulesViewModel.swift in Sources */,
2D38F1F125CD477D00561493 /* HomeTimelineViewModel+LoadMiddleState.swift in Sources */, 2D38F1F125CD477D00561493 /* HomeTimelineViewModel+LoadMiddleState.swift in Sources */,
DB45FAD725CA6C76005A8AC7 /* UIBarButtonItem.swift in Sources */, DB45FAD725CA6C76005A8AC7 /* UIBarButtonItem.swift in Sources */,
2D152A8C25C295CC009AA50C /* TimelinePostView.swift in Sources */, 2D152A8C25C295CC009AA50C /* TimelinePostView.swift in Sources */,
2D42FF8525C8224F004A627A /* HitTestExpandedButton.swift in Sources */, 2D42FF8525C8224F004A627A /* HitTestExpandedButton.swift in Sources */,
DB72601C25E36A2100235243 /* MastodonServerRulesViewController.swift in Sources */,
2D42FF8F25C8228A004A627A /* UIButton.swift in Sources */, 2D42FF8F25C8228A004A627A /* UIButton.swift in Sources */,
2D61335825C188A000CAE157 /* APIService+Persist+Timeline.swift in Sources */, 2D61335825C188A000CAE157 /* APIService+Persist+Timeline.swift in Sources */,
DB45FAE325CA7181005A8AC7 /* MastodonUser.swift in Sources */, DB45FAE325CA7181005A8AC7 /* MastodonUser.swift in Sources */,
@ -1266,6 +1281,7 @@
2D76319F25C1521200929FB9 /* TimelineSection.swift in Sources */, 2D76319F25C1521200929FB9 /* TimelineSection.swift in Sources */,
DB084B5725CBC56C00F898ED /* Toot.swift in Sources */, DB084B5725CBC56C00F898ED /* Toot.swift in Sources */,
DB0140A825C40C1500F9F3CF /* MastodonPinBasedAuthenticationViewModelNavigationDelegateShim.swift in Sources */, DB0140A825C40C1500F9F3CF /* MastodonPinBasedAuthenticationViewModelNavigationDelegateShim.swift in Sources */,
DB2B3AE925E38850007045F9 /* UIViewPreview.swift in Sources */,
DB427DD625BAA00100D1B89D /* AppDelegate.swift in Sources */, DB427DD625BAA00100D1B89D /* AppDelegate.swift in Sources */,
DB98338725C945ED00AD9700 /* Strings.swift in Sources */, DB98338725C945ED00AD9700 /* Strings.swift in Sources */,
DB45FAB625CA5485005A8AC7 /* UIAlertController.swift in Sources */, DB45FAB625CA5485005A8AC7 /* UIAlertController.swift in Sources */,
@ -1380,6 +1396,14 @@
/* End PBXTargetDependency section */ /* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */ /* Begin PBXVariantGroup section */
DB2B3ABE25E37E15007045F9 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
DB2B3ABD25E37E15007045F9 /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
DB3D100F25BAA75E00EAA174 /* Localizable.strings */ = { DB3D100F25BAA75E00EAA174 /* Localizable.strings */ = {
isa = PBXVariantGroup; isa = PBXVariantGroup;
children = ( children = (

View File

@ -40,6 +40,7 @@ extension SceneCoordinator {
case authentication(viewModel: AuthenticationViewModel) case authentication(viewModel: AuthenticationViewModel)
case mastodonPinBasedAuthentication(viewModel: MastodonPinBasedAuthenticationViewModel) case mastodonPinBasedAuthentication(viewModel: MastodonPinBasedAuthenticationViewModel)
case mastodonRegister(viewModel: MastodonRegisterViewModel) case mastodonRegister(viewModel: MastodonRegisterViewModel)
case mastodonServerRules(viewModel: MastodonServerRulesViewModel)
case alertController(alertController: UIAlertController) case alertController(alertController: UIAlertController)
} }
@ -125,6 +126,10 @@ private extension SceneCoordinator {
let _viewController = MastodonRegisterViewController() let _viewController = MastodonRegisterViewController()
_viewController.viewModel = viewModel _viewController.viewModel = viewModel
viewController = _viewController viewController = _viewController
case .mastodonServerRules(let viewModel):
let _viewController = MastodonServerRulesViewController()
_viewController.viewModel = viewModel
viewController = _viewController
case .alertController(let alertController): case .alertController(let alertController):
if let popoverPresentationController = alertController.popoverPresentationController { if let popoverPresentationController = alertController.popoverPresentationController {
assert( assert(

View File

@ -27,8 +27,8 @@ internal enum Asset {
} }
internal enum Colors { internal enum Colors {
internal enum Background { internal enum Background {
internal static let onboardingBackground = ColorAsset(name: "Colors/Background/onboarding.background")
internal static let secondarySystemBackground = ColorAsset(name: "Colors/Background/secondary.system.background") internal static let secondarySystemBackground = ColorAsset(name: "Colors/Background/secondary.system.background")
internal static let signUpSystemBackground = ColorAsset(name: "Colors/Background/signUp.system.background")
internal static let systemBackground = ColorAsset(name: "Colors/Background/system.background") internal static let systemBackground = ColorAsset(name: "Colors/Background/system.background")
internal static let tertiarySystemBackground = ColorAsset(name: "Colors/Background/tertiary.system.background") internal static let tertiarySystemBackground = ColorAsset(name: "Colors/Background/tertiary.system.background")
} }
@ -45,7 +45,9 @@ internal enum Asset {
internal static let secondary = ColorAsset(name: "Colors/Label/secondary") internal static let secondary = ColorAsset(name: "Colors/Label/secondary")
} }
internal enum TextField { internal enum TextField {
internal static let successGreen = ColorAsset(name: "Colors/TextField/successGreen") internal static let highlight = ColorAsset(name: "Colors/TextField/highlight")
internal static let invalid = ColorAsset(name: "Colors/TextField/invalid")
internal static let valid = ColorAsset(name: "Colors/TextField/valid")
} }
internal static let lightAlertYellow = ColorAsset(name: "Colors/lightAlertYellow") internal static let lightAlertYellow = ColorAsset(name: "Colors/lightAlertYellow")
internal static let lightBackground = ColorAsset(name: "Colors/lightBackground") internal static let lightBackground = ColorAsset(name: "Colors/lightBackground")

View File

@ -13,11 +13,118 @@ internal enum L10n {
internal enum Common { internal enum Common {
internal enum Controls { internal enum Controls {
internal enum Actions {
/// Add
internal static let add = L10n.tr("Localizable", "Common.Controls.Actions.Add")
/// Cancel
internal static let cancel = L10n.tr("Localizable", "Common.Controls.Actions.Cancel")
/// Confirm
internal static let confirm = L10n.tr("Localizable", "Common.Controls.Actions.Confirm")
/// Continue
internal static let `continue` = L10n.tr("Localizable", "Common.Controls.Actions.Continue")
/// Edit
internal static let edit = L10n.tr("Localizable", "Common.Controls.Actions.Edit")
/// OK
internal static let ok = L10n.tr("Localizable", "Common.Controls.Actions.Ok")
/// Open in Safari
internal static let openInSafari = L10n.tr("Localizable", "Common.Controls.Actions.OpenInSafari")
/// Preview
internal static let preview = L10n.tr("Localizable", "Common.Controls.Actions.Preview")
/// Remove
internal static let remove = L10n.tr("Localizable", "Common.Controls.Actions.Remove")
/// Save
internal static let save = L10n.tr("Localizable", "Common.Controls.Actions.Save")
/// Save photo
internal static let savePhoto = L10n.tr("Localizable", "Common.Controls.Actions.SavePhoto")
/// See More
internal static let seeMore = L10n.tr("Localizable", "Common.Controls.Actions.SeeMore")
/// Sign in
internal static let signIn = L10n.tr("Localizable", "Common.Controls.Actions.SignIn")
/// Sign up
internal static let signUp = L10n.tr("Localizable", "Common.Controls.Actions.SignUp")
/// Take photo
internal static let takePhoto = L10n.tr("Localizable", "Common.Controls.Actions.TakePhoto")
}
internal enum Timeline { internal enum Timeline {
/// Load More /// Load More
internal static let loadMore = L10n.tr("Localizable", "Common.Controls.Timeline.LoadMore") internal static let loadMore = L10n.tr("Localizable", "Common.Controls.Timeline.LoadMore")
} }
} }
internal enum Countable {
internal enum Photo {
/// photos
internal static let multiple = L10n.tr("Localizable", "Common.Countable.Photo.Multiple")
/// photo
internal static let single = L10n.tr("Localizable", "Common.Countable.Photo.Single")
}
}
}
internal enum Scene {
internal enum HomeTimeline {
/// Home
internal static let title = L10n.tr("Localizable", "Scene.HomeTimeline.Title")
}
internal enum PublicTimeline {
/// Public
internal static let title = L10n.tr("Localizable", "Scene.PublicTimeline.Title")
}
internal enum Register {
/// Tell us about you.
internal static let title = L10n.tr("Localizable", "Scene.Register.Title")
internal enum Input {
internal enum DisplayName {
/// display name
internal static let placeholder = L10n.tr("Localizable", "Scene.Register.Input.DisplayName.Placeholder")
}
internal enum Email {
/// email
internal static let placeholder = L10n.tr("Localizable", "Scene.Register.Input.Email.Placeholder")
}
internal enum Password {
/// password
internal static let placeholder = L10n.tr("Localizable", "Scene.Register.Input.Password.Placeholder")
/// Your password needs at least:
internal static let prompt = L10n.tr("Localizable", "Scene.Register.Input.Password.Prompt")
/// Eight characters
internal static let promptEightCharacters = L10n.tr("Localizable", "Scene.Register.Input.Password.PromptEightCharacters")
}
internal enum Username {
/// This username is taken.
internal static let duplicatePrompt = L10n.tr("Localizable", "Scene.Register.Input.Username.DuplicatePrompt")
/// username
internal static let placeholder = L10n.tr("Localizable", "Scene.Register.Input.Username.Placeholder")
}
}
}
internal enum ServerPicker {
/// Pick a Server,\nany server.
internal static let title = L10n.tr("Localizable", "Scene.ServerPicker.Title")
internal enum Input {
/// Find a server or join your own...
internal static let placeholder = L10n.tr("Localizable", "Scene.ServerPicker.Input.Placeholder")
}
}
internal enum ServerRules {
/// By continuing, you're subject to the terms of service and privacy policy for %@.
internal static func prompt(_ p1: Any) -> String {
return L10n.tr("Localizable", "Scene.ServerRules.Prompt", String(describing: p1))
}
/// These rules are set by the admins of %@.
internal static func subtitle(_ p1: Any) -> String {
return L10n.tr("Localizable", "Scene.ServerRules.Subtitle", String(describing: p1))
}
/// Some ground rules.
internal static let title = L10n.tr("Localizable", "Scene.ServerRules.Title")
internal enum Button {
/// I Agree
internal static let confirm = L10n.tr("Localizable", "Scene.ServerRules.Button.Confirm")
}
}
internal enum Welcome {
/// Social networking\nback in your hands.
internal static let slogan = L10n.tr("Localizable", "Scene.Welcome.Slogan")
}
} }
} }
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length // swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length

View File

@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>UIUserInterfaceStyle</key>
<string>Dark</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string> <string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>

View File

@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "217",
"green" : "144",
"red" : "43"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.353",
"green" : "0.251",
"red" : "0.875"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,2 @@
"NSCameraUsageDescription" = "Used to take photo for toot";
"NSPhotoLibraryAddUsageDescription" = "Used to save photo into the Photo Library";

View File

@ -1,8 +1,37 @@
/* "Common.Controls.Actions.Add" = "Add";
Localizable.strings "Common.Controls.Actions.Cancel" = "Cancel";
Mastodon "Common.Controls.Actions.Confirm" = "Confirm";
"Common.Controls.Actions.Continue" = "Continue";
Created by MainasuK Cirno on 2021/1/22. "Common.Controls.Actions.Edit" = "Edit";
"Common.Controls.Actions.Ok" = "OK";
*/ "Common.Controls.Actions.OpenInSafari" = "Open in Safari";
"Common.Controls.Actions.Preview" = "Preview";
"Common.Controls.Actions.Remove" = "Remove";
"Common.Controls.Actions.Save" = "Save";
"Common.Controls.Actions.SavePhoto" = "Save photo";
"Common.Controls.Actions.SeeMore" = "See More";
"Common.Controls.Actions.SignIn" = "Sign in";
"Common.Controls.Actions.SignUp" = "Sign up";
"Common.Controls.Actions.TakePhoto" = "Take photo";
"Common.Controls.Timeline.LoadMore" = "Load More"; "Common.Controls.Timeline.LoadMore" = "Load More";
"Common.Countable.Photo.Multiple" = "photos";
"Common.Countable.Photo.Single" = "photo";
"Scene.HomeTimeline.Title" = "Home";
"Scene.PublicTimeline.Title" = "Public";
"Scene.Register.Input.DisplayName.Placeholder" = "display name";
"Scene.Register.Input.Email.Placeholder" = "email";
"Scene.Register.Input.Password.Placeholder" = "password";
"Scene.Register.Input.Password.Prompt" = "Your password needs at least:";
"Scene.Register.Input.Password.PromptEightCharacters" = "Eight characters";
"Scene.Register.Input.Username.DuplicatePrompt" = "This username is taken.";
"Scene.Register.Input.Username.Placeholder" = "username";
"Scene.Register.Title" = "Tell us about you.";
"Scene.ServerPicker.Input.Placeholder" = "Find a server or join your own...";
"Scene.ServerPicker.Title" = "Pick a Server,
any server.";
"Scene.ServerRules.Button.Confirm" = "I Agree";
"Scene.ServerRules.Prompt" = "By continuing, you're subject to the terms of service and privacy policy for %@.";
"Scene.ServerRules.Subtitle" = "These rules are set by the admins of %@.";
"Scene.ServerRules.Title" = "Some ground rules.";
"Scene.Welcome.Slogan" = "Social networking
back in your hands.";

View File

@ -77,6 +77,7 @@ extension AuthenticationViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
overrideUserInterfaceStyle = .dark // FIXME:
title = "Authentication" title = "Authentication"
view.backgroundColor = Asset.Colors.Background.systemBackground.color view.backgroundColor = Asset.Colors.Background.systemBackground.color
@ -265,6 +266,22 @@ extension AuthenticationViewController {
.store(in: &disposeBag) .store(in: &disposeBag)
} }
private struct SignUpResponseFirst {
let instance: Mastodon.Response.Content<Mastodon.Entity.Instance>
let application: Mastodon.Response.Content<Mastodon.Entity.Application>
}
private struct SignUpResponseSecond {
let instance: Mastodon.Response.Content<Mastodon.Entity.Instance>
let authenticateInfo: AuthenticationViewModel.AuthenticateInfo
}
private struct SignUpResponseThird {
let instance: Mastodon.Response.Content<Mastodon.Entity.Instance>
let authenticateInfo: AuthenticationViewModel.AuthenticateInfo
let applicationToken: Mastodon.Response.Content<Mastodon.Entity.Token>
}
@objc private func signUpButtonPressed(_ sender: UIButton) { @objc private func signUpButtonPressed(_ sender: UIButton) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function) os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
guard viewModel.isDomainValid.value, let domain = viewModel.domain.value else { guard viewModel.isDomainValid.value, let domain = viewModel.domain.value else {
@ -275,26 +292,34 @@ extension AuthenticationViewController {
viewModel.isRegistering.value = true viewModel.isRegistering.value = true
context.apiService.instance(domain: domain) context.apiService.instance(domain: domain)
.compactMap { [weak self] response -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Application>, Error>? in .compactMap { [weak self] response -> AnyPublisher<SignUpResponseFirst, Error>? in
guard let self = self else { return nil } guard let self = self else { return nil }
guard response.value.registrations != false else { guard response.value.registrations != false else {
return Fail(error: AuthenticationViewModel.AuthenticationError.registrationClosed).eraseToAnyPublisher() return Fail(error: AuthenticationViewModel.AuthenticationError.registrationClosed).eraseToAnyPublisher()
} }
return self.context.apiService.createApplication(domain: domain) return self.context.apiService.createApplication(domain: domain)
.map { SignUpResponseFirst(instance: response, application: $0) }
.eraseToAnyPublisher()
} }
.switchToLatest() .switchToLatest()
.tryMap { response -> AuthenticationViewModel.AuthenticateInfo in .tryMap { response -> SignUpResponseSecond in
let application = response.value let application = response.application.value
guard let authenticateInfo = AuthenticationViewModel.AuthenticateInfo(domain: domain, application: application) else { guard let authenticateInfo = AuthenticationViewModel.AuthenticateInfo(domain: domain, application: application) else {
throw APIService.APIError.explicit(.badResponse) throw APIService.APIError.explicit(.badResponse)
} }
return authenticateInfo return SignUpResponseSecond(instance: response.instance, authenticateInfo: authenticateInfo)
} }
.compactMap { [weak self] authenticateInfo -> AnyPublisher<(Mastodon.Response.Content<Mastodon.Entity.Token>, AuthenticationViewModel.AuthenticateInfo), Error>? in .compactMap { [weak self] response -> AnyPublisher<SignUpResponseThird, Error>? in
guard let self = self else { return nil } guard let self = self else { return nil }
return self.context.apiService.applicationAccessToken(domain: domain, clientID: authenticateInfo.clientID, clientSecret: authenticateInfo.clientSecret) let instance = response.instance
.map { ($0, authenticateInfo) } let authenticateInfo = response.authenticateInfo
.eraseToAnyPublisher() return self.context.apiService.applicationAccessToken(
domain: domain,
clientID: authenticateInfo.clientID,
clientSecret: authenticateInfo.clientSecret
)
.map { SignUpResponseThird(instance: instance, authenticateInfo: authenticateInfo, applicationToken: $0) }
.eraseToAnyPublisher()
} }
.switchToLatest() .switchToLatest()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
@ -308,12 +333,13 @@ extension AuthenticationViewController {
case .finished: case .finished:
break break
} }
} receiveValue: { [weak self] response, authenticateInfo in } receiveValue: { [weak self] response in
guard let self = self else { return } guard let self = self else { return }
let mastodonRegisterViewModel = MastodonRegisterViewModel( let mastodonRegisterViewModel = MastodonRegisterViewModel(
domain: domain, domain: domain,
authenticateInfo: authenticateInfo, authenticateInfo: response.authenticateInfo,
applicationToken: response.value instance: response.instance.value,
applicationToken: response.applicationToken.value
) )
self.coordinator.present(scene: .mastodonRegister(viewModel: mastodonRegisterViewModel), from: self, transition: .show) self.coordinator.present(scene: .mastodonRegister(viewModel: mastodonRegisterViewModel), from: self, transition: .show)
} }

View File

@ -20,13 +20,19 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
var viewModel: MastodonRegisterViewModel! var viewModel: MastodonRegisterViewModel!
let tapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer let tapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
let stackViewTopDistance: CGFloat = 16
var scrollview: UIScrollView = { let statusBarBackground: UIView = {
let view = UIView()
view.backgroundColor = Asset.Colors.Background.onboardingBackground.color
return view
}()
let scrollView: UIScrollView = {
let scrollview = UIScrollView() let scrollview = UIScrollView()
scrollview.showsVerticalScrollIndicator = false scrollview.showsVerticalScrollIndicator = false
scrollview.translatesAutoresizingMaskIntoConstraints = false scrollview.translatesAutoresizingMaskIntoConstraints = false
scrollview.keyboardDismissMode = .interactive scrollview.keyboardDismissMode = .interactive
scrollview.clipsToBounds = false // make content could display over bleeding
return scrollview return scrollview
}() }()
@ -34,7 +40,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
let label = UILabel() let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: UIFont.boldSystemFont(ofSize: 34)) label.font = UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: UIFont.boldSystemFont(ofSize: 34))
label.textColor = Asset.Colors.Label.black.color label.textColor = Asset.Colors.Label.black.color
label.text = "Tell us about you." label.text = L10n.Scene.Register.title
return label return label
}() }()
@ -92,7 +98,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
textField.autocorrectionType = .no textField.autocorrectionType = .no
textField.backgroundColor = .white textField.backgroundColor = .white
textField.textColor = .black textField.textColor = .black
textField.attributedPlaceholder = NSAttributedString(string: "username", textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Username.placeholder,
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
textField.borderStyle = UITextField.BorderStyle.roundedRect textField.borderStyle = UITextField.BorderStyle.roundedRect
@ -113,7 +119,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
textField.autocorrectionType = .no textField.autocorrectionType = .no
textField.backgroundColor = .white textField.backgroundColor = .white
textField.textColor = .black textField.textColor = .black
textField.attributedPlaceholder = NSAttributedString(string: "display name", textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.DisplayName.placeholder,
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
textField.borderStyle = UITextField.BorderStyle.roundedRect textField.borderStyle = UITextField.BorderStyle.roundedRect
@ -130,7 +136,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
textField.keyboardType = .emailAddress textField.keyboardType = .emailAddress
textField.backgroundColor = .white textField.backgroundColor = .white
textField.textColor = .black textField.textColor = .black
textField.attributedPlaceholder = NSAttributedString(string: "email", textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Email.placeholder,
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
textField.borderStyle = UITextField.BorderStyle.roundedRect textField.borderStyle = UITextField.BorderStyle.roundedRect
@ -154,7 +160,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
textField.isSecureTextEntry = true textField.isSecureTextEntry = true
textField.backgroundColor = .white textField.backgroundColor = .white
textField.textColor = .black textField.textColor = .black
textField.attributedPlaceholder = NSAttributedString(string: "password", textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Password.placeholder,
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
textField.borderStyle = UITextField.BorderStyle.roundedRect textField.borderStyle = UITextField.BorderStyle.roundedRect
@ -171,7 +177,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
button.setBackgroundImage(UIImage.placeholder(color: Asset.Colors.lightDisabled.color), for: .disabled) button.setBackgroundImage(UIImage.placeholder(color: Asset.Colors.lightDisabled.color), for: .disabled)
button.isEnabled = false button.isEnabled = false
button.setTitleColor(Asset.Colors.Label.primary.color, for: .normal) button.setTitleColor(Asset.Colors.Label.primary.color, for: .normal)
button.setTitle("Continue", for: .normal) button.setTitle(L10n.Common.Controls.Actions.continue, for: .normal)
button.layer.masksToBounds = true button.layer.masksToBounds = true
button.layer.cornerRadius = 8 button.layer.cornerRadius = 8
button.layer.cornerCurve = .continuous button.layer.cornerCurve = .continuous
@ -186,11 +192,12 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency {
} }
extension MastodonRegisterViewController { extension MastodonRegisterViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
navigationController?.navigationBar.isHidden = true overrideUserInterfaceStyle = .light
view.backgroundColor = Asset.Colors.Background.signUpSystemBackground.color view.backgroundColor = Asset.Colors.Background.onboardingBackground.color
domainLabel.text = "@" + viewModel.domain + " " domainLabel.text = "@" + viewModel.domain + " "
domainLabel.sizeToFit() domainLabel.sizeToFit()
passwordCheckLabel.attributedText = viewModel.attributeStringForPassword() passwordCheckLabel.attributedText = viewModel.attributeStringForPassword()
@ -203,14 +210,14 @@ extension MastodonRegisterViewController {
// gesture // gesture
view.addGestureRecognizer(tapGestureRecognizer) view.addGestureRecognizer(tapGestureRecognizer)
tapGestureRecognizer.addTarget(self, action: #selector(_resignFirstResponder)) tapGestureRecognizer.addTarget(self, action: #selector(tapGestureRecognizerHandler))
// stackview // stackview
let stackView = UIStackView() let stackView = UIStackView()
stackView.axis = .vertical stackView.axis = .vertical
stackView.distribution = .fill stackView.distribution = .fill
stackView.spacing = 40 stackView.spacing = 40
stackView.layoutMargins = UIEdgeInsets(top: 0, left: 4, bottom: 26, right: 4) stackView.layoutMargins = UIEdgeInsets(top: 20, left: 0, bottom: 26, right: 0)
stackView.isLayoutMarginsRelativeArrangement = true stackView.isLayoutMarginsRelativeArrangement = true
stackView.addArrangedSubview(largeTitleLabel) stackView.addArrangedSubview(largeTitleLabel)
stackView.addArrangedSubview(photoView) stackView.addArrangedSubview(photoView)
@ -220,25 +227,34 @@ extension MastodonRegisterViewController {
stackView.addArrangedSubview(passwordTextField) stackView.addArrangedSubview(passwordTextField)
stackView.addArrangedSubview(passwordCheckLabel) stackView.addArrangedSubview(passwordCheckLabel)
// scrollview // scrollView
view.addSubview(scrollview) view.addSubview(scrollView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
scrollview.frameLayoutGuide.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor), scrollView.frameLayoutGuide.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
scrollview.frameLayoutGuide.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor), scrollView.frameLayoutGuide.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
view.readableContentGuide.trailingAnchor.constraint(equalTo: scrollview.frameLayoutGuide.trailingAnchor), view.readableContentGuide.trailingAnchor.constraint(equalTo: scrollView.frameLayoutGuide.trailingAnchor),
scrollview.frameLayoutGuide.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor), scrollView.frameLayoutGuide.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor),
scrollview.frameLayoutGuide.widthAnchor.constraint(equalTo: scrollview.contentLayoutGuide.widthAnchor), scrollView.frameLayoutGuide.widthAnchor.constraint(equalTo: scrollView.contentLayoutGuide.widthAnchor),
]) ])
// stackview // stackview
scrollview.addSubview(stackView) scrollView.addSubview(stackView)
stackView.translatesAutoresizingMaskIntoConstraints = false stackView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: scrollview.contentLayoutGuide.topAnchor, constant: stackViewTopDistance), stackView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor),
stackView.leadingAnchor.constraint(equalTo: scrollview.contentLayoutGuide.leadingAnchor), stackView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: scrollview.contentLayoutGuide.trailingAnchor), stackView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor),
stackView.widthAnchor.constraint(equalTo: scrollview.frameLayoutGuide.widthAnchor), stackView.widthAnchor.constraint(equalTo: scrollView.contentLayoutGuide.widthAnchor),
scrollview.contentLayoutGuide.bottomAnchor.constraint(equalTo: stackView.bottomAnchor), scrollView.contentLayoutGuide.bottomAnchor.constraint(equalTo: stackView.bottomAnchor),
])
statusBarBackground.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(statusBarBackground)
NSLayoutConstraint.activate([
statusBarBackground.topAnchor.constraint(equalTo: view.topAnchor),
statusBarBackground.leadingAnchor.constraint(equalTo: view.leadingAnchor),
statusBarBackground.trailingAnchor.constraint(equalTo: view.trailingAnchor),
statusBarBackground.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
]) ])
// photoview // photoview
@ -283,11 +299,11 @@ extension MastodonRegisterViewController {
signUpButton.translatesAutoresizingMaskIntoConstraints = false signUpButton.translatesAutoresizingMaskIntoConstraints = false
stackView.addArrangedSubview(signUpButton) stackView.addArrangedSubview(signUpButton)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
signUpButton.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh), signUpButton.heightAnchor.constraint(equalToConstant: 46).priority(.defaultHigh),
]) ])
signUpActivityIndicatorView.translatesAutoresizingMaskIntoConstraints = false signUpActivityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
scrollview.addSubview(signUpActivityIndicatorView) scrollView.addSubview(signUpActivityIndicatorView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
signUpActivityIndicatorView.centerXAnchor.constraint(equalTo: signUpButton.centerXAnchor), signUpActivityIndicatorView.centerXAnchor.constraint(equalTo: signUpButton.centerXAnchor),
signUpActivityIndicatorView.centerYAnchor.constraint(equalTo: signUpButton.centerYAnchor), signUpActivityIndicatorView.centerYAnchor.constraint(equalTo: signUpButton.centerYAnchor),
@ -301,21 +317,30 @@ extension MastodonRegisterViewController {
guard let self = self else { return } guard let self = self else { return }
guard state == .dock else { guard state == .dock else {
self.scrollview.contentInset.bottom = 0.0 self.scrollView.contentInset.bottom = 0.0
self.scrollview.verticalScrollIndicatorInsets.bottom = 0.0 self.scrollView.verticalScrollIndicatorInsets.bottom = 0.0
return return
} }
let contentFrame = self.view.convert(self.scrollview.frame, to: nil) let contentFrame = self.view.convert(self.scrollView.frame, to: nil)
let padding = contentFrame.maxY - endFrame.minY let padding = contentFrame.maxY - endFrame.minY
guard padding > 0 else { guard padding > 0 else {
self.scrollview.contentInset.bottom = 0.0 self.scrollView.contentInset.bottom = 0.0
self.scrollview.verticalScrollIndicatorInsets.bottom = 0.0 self.scrollView.verticalScrollIndicatorInsets.bottom = 0.0
return return
} }
self.scrollview.contentInset.bottom = padding + 16 self.scrollView.contentInset.bottom = padding + 16
self.scrollview.verticalScrollIndicatorInsets.bottom = padding + 16 self.scrollView.verticalScrollIndicatorInsets.bottom = padding + 16
if self.passwordTextField.isFirstResponder {
let contentFrame = self.scrollView.convert(self.signUpButton.frame, to: nil)
let labelPadding = contentFrame.maxY - endFrame.minY
let contentOffsetY = self.scrollView.contentOffset.y
DispatchQueue.main.async {
self.scrollView.setContentOffset(CGPoint(x: 0, y: contentOffsetY + labelPadding + 16.0), animated: true)
}
}
}) })
.store(in: &disposeBag) .store(in: &disposeBag)
@ -324,50 +349,47 @@ extension MastodonRegisterViewController {
.sink { [weak self] isRegistering in .sink { [weak self] isRegistering in
guard let self = self else { return } guard let self = self else { return }
isRegistering ? self.signUpActivityIndicatorView.startAnimating() : self.signUpActivityIndicatorView.stopAnimating() isRegistering ? self.signUpActivityIndicatorView.startAnimating() : self.signUpActivityIndicatorView.stopAnimating()
self.signUpButton.setTitle(isRegistering ? "" : "Continue", for: .normal) self.signUpButton.setTitle(isRegistering ? "" : L10n.Common.Controls.Actions.continue, for: .normal)
self.signUpButton.isEnabled = !isRegistering self.signUpButton.isEnabled = !isRegistering
} }
.store(in: &disposeBag) .store(in: &disposeBag)
viewModel.isUsernameValid viewModel.usernameValidateState
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] isValid in .sink { [weak self] validateState in
guard let self = self else { return } guard let self = self else { return }
self.setTextFieldValidAppearance(self.usernameTextField, isValid: isValid) self.setTextFieldValidAppearance(self.usernameTextField, validateState: validateState)
} }
.store(in: &disposeBag) .store(in: &disposeBag)
viewModel.isDisplaynameValid viewModel.displayNameValidateState
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] isValid in .sink { [weak self] validateState in
guard let self = self else { return } guard let self = self else { return }
self.setTextFieldValidAppearance(self.displayNameTextField, isValid: isValid) self.setTextFieldValidAppearance(self.displayNameTextField, validateState: validateState)
} }
.store(in: &disposeBag) .store(in: &disposeBag)
viewModel.isEmailValid viewModel.emailValidateState
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] isValid in .sink { [weak self] validateState in
guard let self = self else { return } guard let self = self else { return }
self.setTextFieldValidAppearance(self.emailTextField, isValid: isValid) self.setTextFieldValidAppearance(self.emailTextField, validateState: validateState)
} }
.store(in: &disposeBag) .store(in: &disposeBag)
viewModel.isPasswordValid viewModel.passwordValidateState
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] isValid in .sink { [weak self] validateState in
guard let self = self else { return } guard let self = self else { return }
self.setTextFieldValidAppearance(self.passwordTextField, isValid: isValid) self.setTextFieldValidAppearance(self.passwordTextField, validateState: validateState)
self.passwordCheckLabel.attributedText = self.viewModel.attributeStringForPassword(eightCharacters: validateState == .valid)
} }
.store(in: &disposeBag) .store(in: &disposeBag)
Publishers.CombineLatest4( viewModel.isAllValid
viewModel.isUsernameValid,
viewModel.isDisplaynameValid,
viewModel.isEmailValid,
viewModel.isPasswordValid
)
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] isUsernameValid, isDisplaynameValid, isEmailValid, isPasswordValid in .sink { [weak self] isAllValid in
guard let self = self else { return } guard let self = self else { return }
self.signUpButton.isEnabled = isUsernameValid ?? false && isDisplaynameValid ?? false && isEmailValid ?? false && isPasswordValid ?? false self.signUpButton.isEnabled = isAllValid
} }
.store(in: &disposeBag) .store(in: &disposeBag)
@ -377,7 +399,7 @@ extension MastodonRegisterViewController {
.sink { [weak self] error in .sink { [weak self] error in
guard let self = self else { return } guard let self = self else { return }
let alertController = UIAlertController(error, preferredStyle: .alert) let alertController = UIAlertController(error, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) let okAction = UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default, handler: nil)
alertController.addAction(okAction) alertController.addAction(okAction)
self.coordinator.present( self.coordinator.present(
scene: .alertController(alertController: alertController), scene: .alertController(alertController: alertController),
@ -387,51 +409,87 @@ extension MastodonRegisterViewController {
} }
.store(in: &disposeBag) .store(in: &disposeBag)
NotificationCenter.default
.publisher(for: UITextField.textDidChangeNotification, object: usernameTextField)
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self = self else { return }
self.viewModel.username.value = self.usernameTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
}
.store(in: &disposeBag)
NotificationCenter.default
.publisher(for: UITextField.textDidChangeNotification, object: displayNameTextField)
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self = self else { return }
self.viewModel.displayName.value = self.displayNameTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
}
.store(in: &disposeBag)
NotificationCenter.default
.publisher(for: UITextField.textDidChangeNotification, object: emailTextField)
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self = self else { return }
self.viewModel.email.value = self.emailTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
}
.store(in: &disposeBag)
NotificationCenter.default NotificationCenter.default
.publisher(for: UITextField.textDidChangeNotification, object: passwordTextField) .publisher(for: UITextField.textDidChangeNotification, object: passwordTextField)
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] _ in .sink { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
guard let text = self.passwordTextField.text else { return } self.viewModel.password.value = self.passwordTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
let validations = self.viewModel.validatePassword(text: text)
self.passwordCheckLabel.attributedText = self.viewModel.attributeStringForPassword(eightCharacters: validations.0, oneNumber: validations.1, oneSpecialCharacter: validations.2)
} }
.store(in: &disposeBag) .store(in: &disposeBag)
signUpButton.addTarget(self, action: #selector(MastodonRegisterViewController.signUpButtonPressed(_:)), for: .touchUpInside) signUpButton.addTarget(self, action: #selector(MastodonRegisterViewController.signUpButtonPressed(_:)), for: .touchUpInside)
} }
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
} }
extension MastodonRegisterViewController: UITextFieldDelegate { extension MastodonRegisterViewController: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
// align to password label when overlap
if textField === passwordTextField,
KeyboardResponderService.shared.isShow.value,
KeyboardResponderService.shared.state.value == .dock
{
let endFrame = KeyboardResponderService.shared.willEndFrame.value
let contentFrame = scrollview.convert(passwordCheckLabel.frame, to: nil)
let padding = contentFrame.maxY - endFrame.minY
if padding > 0 {
let contentOffsetY = scrollview.contentOffset.y
DispatchQueue.main.async {
self.scrollview.setContentOffset(CGPoint(x: 0, y: contentOffsetY + padding + 16.0), animated: true)
}
}
}
}
func textFieldDidEndEditing(_ textField: UITextField) { // FIXME: keyboard listener trigger when switch between text fields. Maybe could remove it
// func textFieldDidBeginEditing(_ textField: UITextField) {
// // align to password label when overlap
// if textField === passwordTextField,
// KeyboardResponderService.shared.isShow.value,
// KeyboardResponderService.shared.state.value == .dock
// {
// let endFrame = KeyboardResponderService.shared.willEndFrame.value
// let contentFrame = scrollView.convert(signUpButton.frame, to: nil)
// let padding = contentFrame.maxY - endFrame.minY
// if padding > 0 {
// let contentOffsetY = scrollView.contentOffset.y
// DispatchQueue.main.async {
// self.scrollView.setContentOffset(CGPoint(x: 0, y: contentOffsetY + padding + 16.0), animated: true)
// }
// }
// }
// }
func textFieldDidBeginEditing(_ textField: UITextField) {
let text = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
switch textField { switch textField {
case usernameTextField: case usernameTextField:
viewModel.username.value = textField.text viewModel.username.value = text
case displayNameTextField: case displayNameTextField:
viewModel.displayname.value = textField.text viewModel.displayName.value = text
case emailTextField: case emailTextField:
viewModel.email.value = textField.text viewModel.email.value = text
case passwordTextField: case passwordTextField:
viewModel.password.value = textField.text viewModel.password.value = text
default: break default:
break
} }
} }
@ -444,45 +502,45 @@ extension MastodonRegisterViewController: UITextFieldDelegate {
textField.layer.shadowPath = UIBezierPath(roundedRect: textField.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 2.0, height: 2.0)).cgPath textField.layer.shadowPath = UIBezierPath(roundedRect: textField.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 2.0, height: 2.0)).cgPath
} }
func validateAllTextField() -> Bool { private func setTextFieldValidAppearance(_ textField: UITextField, validateState: MastodonRegisterViewModel.ValidateState) {
return viewModel.isUsernameValid.value ?? false && viewModel.isDisplaynameValid.value ?? false && viewModel.isEmailValid.value ?? false && viewModel.isPasswordValid.value ?? false switch validateState {
} case .empty:
showShadowWithColor(color: textField.isFirstResponder ? Asset.Colors.TextField.highlight.color : .clear, textField: textField)
private func setTextFieldValidAppearance(_ textField: UITextField, isValid: Bool?) { case .valid:
guard let isValid = isValid else { showShadowWithColor(color: Asset.Colors.TextField.valid.color, textField: textField)
showShadowWithColor(color: .clear, textField: textField) case .invalid:
return showShadowWithColor(color: Asset.Colors.TextField.invalid.color, textField: textField)
}
if isValid {
showShadowWithColor(color: Asset.Colors.TextField.successGreen.color, textField: textField)
} else {
textField.shake()
showShadowWithColor(color: Asset.Colors.lightDangerRed.color, textField: textField)
} }
} }
} }
extension MastodonRegisterViewController { extension MastodonRegisterViewController {
@objc private func _resignFirstResponder() {
usernameTextField.resignFirstResponder() @objc private func tapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
displayNameTextField.resignFirstResponder() view.endEditing(true)
emailTextField.resignFirstResponder()
passwordTextField.resignFirstResponder()
} }
@objc private func signUpButtonPressed(_ sender: UIButton) { @objc private func signUpButtonPressed(_ sender: UIButton) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", (#file as NSString).lastPathComponent, #line, #function) os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", (#file as NSString).lastPathComponent, #line, #function)
guard validateAllTextField(), guard viewModel.isAllValid.value else { return }
let username = viewModel.username.value,
let email = viewModel.email.value,
let password = viewModel.password.value else {
return
}
guard !viewModel.isRegistering.value else { return } guard !viewModel.isRegistering.value else { return }
viewModel.isRegistering.value = true viewModel.isRegistering.value = true
let username = viewModel.username.value
let email = viewModel.email.value
let password = viewModel.password.value
if let rules = viewModel.instance.rules, !rules.isEmpty {
let mastodonServerRulesViewModel = MastodonServerRulesViewModel(
context: context,
domain: viewModel.domain,
rules: rules
)
coordinator.present(scene: .mastodonServerRules(viewModel: mastodonServerRulesViewModel), from: self, transition: .show)
return
}
let query = Mastodon.API.Account.RegisterQuery( let query = Mastodon.API.Account.RegisterQuery(
reason: nil, reason: nil,
username: username, username: username,
@ -512,7 +570,7 @@ extension MastodonRegisterViewController {
_ = response.value _ = response.value
// TODO: // TODO:
let alertController = UIAlertController(title: "Success", message: "Regsiter request sent. Please check your email.\n(Auto sign in not implement yet.)", preferredStyle: .alert) let alertController = UIAlertController(title: "Success", message: "Regsiter request sent. Please check your email.\n(Auto sign in not implement yet.)", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default) { [weak self] _ in let okAction = UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default) { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} }
@ -521,4 +579,5 @@ extension MastodonRegisterViewController {
} }
.store(in: &disposeBag) .store(in: &disposeBag)
} }
} }

View File

@ -11,97 +11,122 @@ import MastodonSDK
import UIKit import UIKit
final class MastodonRegisterViewModel { final class MastodonRegisterViewModel {
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
// input // input
let domain: String let domain: String
let authenticateInfo: AuthenticationViewModel.AuthenticateInfo let authenticateInfo: AuthenticationViewModel.AuthenticateInfo
let instance: Mastodon.Entity.Instance
let applicationToken: Mastodon.Entity.Token let applicationToken: Mastodon.Entity.Token
let username = CurrentValueSubject<String, Never>("")
let displayName = CurrentValueSubject<String, Never>("")
let email = CurrentValueSubject<String, Never>("")
let password = CurrentValueSubject<String, Never>("")
let isUsernameValidateDalay = CurrentValueSubject<Bool, Never>(true)
let isDisplayNameValidateDalay = CurrentValueSubject<Bool, Never>(true)
let isEmailValidateDalay = CurrentValueSubject<Bool, Never>(true)
let isPasswordValidateDalay = CurrentValueSubject<Bool, Never>(true)
let isRegistering = CurrentValueSubject<Bool, Never>(false) let isRegistering = CurrentValueSubject<Bool, Never>(false)
let username = CurrentValueSubject<String?, Never>(nil)
let displayname = CurrentValueSubject<String?, Never>(nil)
let email = CurrentValueSubject<String?, Never>(nil)
let password = CurrentValueSubject<String?, Never>(nil)
// output // output
let applicationAuthorization: Mastodon.API.OAuth.Authorization let applicationAuthorization: Mastodon.API.OAuth.Authorization
let isUsernameValid = CurrentValueSubject<Bool?, Never>(nil) let usernameValidateState = CurrentValueSubject<ValidateState, Never>(.empty)
let isDisplaynameValid = CurrentValueSubject<Bool?, Never>(nil) let displayNameValidateState = CurrentValueSubject<ValidateState, Never>(.empty)
let isEmailValid = CurrentValueSubject<Bool?, Never>(nil) let emailValidateState = CurrentValueSubject<ValidateState, Never>(.empty)
let isPasswordValid = CurrentValueSubject<Bool?, Never>(nil) let passwordValidateState = CurrentValueSubject<ValidateState, Never>(.empty)
let isAllValid = CurrentValueSubject<Bool, Never>(false)
let error = CurrentValueSubject<Error?, Never>(nil) let error = CurrentValueSubject<Error?, Never>(nil)
init( init(
domain: String, domain: String,
authenticateInfo: AuthenticationViewModel.AuthenticateInfo, authenticateInfo: AuthenticationViewModel.AuthenticateInfo,
instance: Mastodon.Entity.Instance,
applicationToken: Mastodon.Entity.Token applicationToken: Mastodon.Entity.Token
) { ) {
self.domain = domain self.domain = domain
self.authenticateInfo = authenticateInfo self.authenticateInfo = authenticateInfo
self.instance = instance
self.applicationToken = applicationToken self.applicationToken = applicationToken
self.applicationAuthorization = Mastodon.API.OAuth.Authorization(accessToken: applicationToken.accessToken) self.applicationAuthorization = Mastodon.API.OAuth.Authorization(accessToken: applicationToken.accessToken)
username username
.map { username in .map { username in
guard let username = username else { guard !username.isEmpty else { return .empty }
return nil var isValid = true
// regex opt-out way to check validation
// allowed:
// a-z (isASCII && isLetter)
// A-Z (isASCII && isLetter)
// 0-9 (isASCII && isNumber)
// _ ("_")
for char in username {
guard char.isASCII, (char.isLetter || char.isNumber || char == "_") else {
isValid = false
break
}
} }
return !username.isEmpty return isValid ? .valid : .invalid
} }
.assign(to: \.value, on: isUsernameValid) .assign(to: \.value, on: usernameValidateState)
.store(in: &disposeBag) .store(in: &disposeBag)
displayname displayName
.map { displayname in .map { displayname in
guard let displayname = displayname else { guard !displayname.isEmpty else { return .empty }
return nil return .valid
}
return !displayname.isEmpty
} }
.assign(to: \.value, on: isDisplaynameValid) .assign(to: \.value, on: displayNameValidateState)
.store(in: &disposeBag) .store(in: &disposeBag)
email email
.map { [weak self] email in .map { email in
guard let self = self else { return nil } guard !email.isEmpty else { return .empty }
guard let email = email else { return MastodonRegisterViewModel.isValidEmail(email) ? .valid : .invalid
return nil
}
return !email.isEmpty && self.isValidEmail(email)
} }
.assign(to: \.value, on: isEmailValid) .assign(to: \.value, on: emailValidateState)
.store(in: &disposeBag) .store(in: &disposeBag)
password password
.map { [weak self] password in .map { password in
guard let self = self else { return nil } guard !password.isEmpty else { return .empty }
guard let password = password else { return password.count >= 8 ? .valid : .invalid
return nil
}
let result = self.validatePassword(text: password)
return !password.isEmpty && result.0 && result.1 && result.2
} }
.assign(to: \.value, on: isPasswordValid) .assign(to: \.value, on: passwordValidateState)
.store(in: &disposeBag) .store(in: &disposeBag)
Publishers.CombineLatest4(
usernameValidateState.eraseToAnyPublisher(),
displayNameValidateState.eraseToAnyPublisher(),
emailValidateState.eraseToAnyPublisher(),
passwordValidateState.eraseToAnyPublisher()
)
.map { $0.0 == .valid && $0.1 == .valid && $0.2 == .valid && $0.3 == .valid }
.assign(to: \.value, on: isAllValid)
.store(in: &disposeBag)
}
}
extension MastodonRegisterViewModel {
enum ValidateState {
case empty
case invalid
case valid
} }
} }
extension MastodonRegisterViewModel { extension MastodonRegisterViewModel {
func isValidEmail(_ email: String) -> Bool { static func isValidEmail(_ email: String) -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailPred = NSPredicate(format: "SELF MATCHES %@", emailRegEx) let emailPred = NSPredicate(format: "SELF MATCHES %@", emailRegEx)
return emailPred.evaluate(with: email) return emailPred.evaluate(with: email)
} }
func validatePassword(text: String) -> (Bool, Bool, Bool) {
let trimmedText = text.trimmingCharacters(in: .whitespaces)
let isEightCharacters = trimmedText.count >= 8
let isOneNumber = trimmedText.range(of: ".*[0-9]", options: .regularExpression) != nil
let isOneSpecialCharacter = trimmedText.trimmingCharacters(in: .decimalDigits).trimmingCharacters(in: .letters).count > 0
return (isEightCharacters, isOneNumber, isOneSpecialCharacter)
}
func attributeStringForUsername() -> NSAttributedString { func attributeStringForUsername() -> NSAttributedString {
let resultAttributeString = NSMutableAttributedString() let resultAttributeString = NSMutableAttributedString()
let redImage = NSTextAttachment() let redImage = NSTextAttachment()
@ -115,7 +140,7 @@ extension MastodonRegisterViewModel {
return resultAttributeString return resultAttributeString
} }
func attributeStringForPassword(eightCharacters: Bool = false, oneNumber: Bool = false, oneSpecialCharacter: Bool = false) -> NSAttributedString { func attributeStringForPassword(eightCharacters: Bool = false) -> NSAttributedString {
let font = UIFont.preferredFont(forTextStyle: .caption1) let font = UIFont.preferredFont(forTextStyle: .caption1)
let color = UIColor.black let color = UIColor.black
let falseColor = UIColor.clear let falseColor = UIColor.clear
@ -125,17 +150,9 @@ extension MastodonRegisterViewModel {
attributeString.append(start) attributeString.append(start)
attributeString.append(checkmarkImage(color: eightCharacters ? color : falseColor)) attributeString.append(checkmarkImage(color: eightCharacters ? color : falseColor))
let eightCharactersDescription = NSAttributedString(string: "Eight characters\n", attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: color]) let eightCharactersDescription = NSAttributedString(string: " Eight characters\n", attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: color])
attributeString.append(eightCharactersDescription) attributeString.append(eightCharactersDescription)
attributeString.append(checkmarkImage(color: oneNumber ? color : falseColor))
let oneNumberDescription = NSAttributedString(string: "One number\n", attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: color])
attributeString.append(oneNumberDescription)
attributeString.append(checkmarkImage(color: oneSpecialCharacter ? color : falseColor))
let oneSpecialCharacterDescription = NSAttributedString(string: "One special character\n", attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: color])
attributeString.append(oneSpecialCharacterDescription)
return attributeString return attributeString
} }

View File

@ -0,0 +1,174 @@
//
// MastodonServerRulesViewController.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-2-22.
//
import os.log
import UIKit
final class MastodonServerRulesViewController: UIViewController, NeedsDependency {
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
var viewModel: MastodonServerRulesViewModel!
let largeTitleLabel: UILabel = {
let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: UIFont.boldSystemFont(ofSize: 34))
label.textColor = .label
label.text = L10n.Scene.ServerRules.title
return label
}()
private(set) lazy var subtitleLabel: UILabel = {
let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .title1).scaledFont(for: UIFont.systemFont(ofSize: 20))
label.textColor = .secondaryLabel
label.text = L10n.Scene.ServerRules.subtitle(viewModel.domain)
label.numberOfLines = 0
return label
}()
let rulesLabel: UILabel = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .body)
label.textColor = Asset.Colors.Label.black.color
label.text = "Rules"
label.numberOfLines = 0
return label
}()
let bottonContainerView: UIView = {
let view = UIView()
view.backgroundColor = Asset.Colors.Background.onboardingBackground.color
return view
}()
private(set) lazy var bottomPromptLabel: UILabel = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .body)
label.textColor = .label
label.text = L10n.Scene.ServerRules.prompt(viewModel.domain)
label.numberOfLines = 0
return label
}()
let confirmButton: UIButton = {
let button = UIButton(type: .system)
button.titleLabel?.font = .preferredFont(forTextStyle: .headline)
button.setBackgroundImage(UIImage.placeholder(color: Asset.Colors.lightBrandBlue.color), for: .normal)
button.setBackgroundImage(UIImage.placeholder(color: Asset.Colors.lightDisabled.color), for: .disabled)
button.setTitleColor(Asset.Colors.Label.primary.color, for: .normal)
button.setTitle(L10n.Scene.ServerRules.Button.confirm, for: .normal)
button.layer.masksToBounds = true
button.layer.cornerRadius = 8
button.layer.cornerCurve = .continuous
return button
}()
let scrollView = UIScrollView()
}
extension MastodonServerRulesViewController {
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
view.backgroundColor = Asset.Colors.Background.onboardingBackground.color
bottonContainerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bottonContainerView)
NSLayoutConstraint.activate([
view.bottomAnchor.constraint(equalTo: bottonContainerView.bottomAnchor),
bottonContainerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
bottonContainerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])
bottonContainerView.preservesSuperviewLayoutMargins = true
confirmButton.translatesAutoresizingMaskIntoConstraints = false
bottonContainerView.addSubview(confirmButton)
NSLayoutConstraint.activate([
bottonContainerView.bottomAnchor.constraint(greaterThanOrEqualTo: confirmButton.bottomAnchor, constant: 16),
bottonContainerView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: confirmButton.bottomAnchor).priority(.defaultHigh),
confirmButton.leadingAnchor.constraint(equalTo: bottonContainerView.readableContentGuide.leadingAnchor),
confirmButton.trailingAnchor.constraint(equalTo: bottonContainerView.readableContentGuide.trailingAnchor),
confirmButton.heightAnchor.constraint(equalToConstant: 46).priority(.defaultHigh),
])
bottomPromptLabel.translatesAutoresizingMaskIntoConstraints = false
bottonContainerView.addSubview(bottomPromptLabel)
NSLayoutConstraint.activate([
bottomPromptLabel.topAnchor.constraint(equalTo: bottonContainerView.topAnchor, constant: 20),
bottomPromptLabel.leadingAnchor.constraint(equalTo: bottonContainerView.readableContentGuide.leadingAnchor),
bottomPromptLabel.trailingAnchor.constraint(equalTo: bottonContainerView.readableContentGuide.trailingAnchor),
confirmButton.topAnchor.constraint(equalTo: bottomPromptLabel.bottomAnchor, constant: 20),
])
scrollView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.frameLayoutGuide.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
scrollView.frameLayoutGuide.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
view.readableContentGuide.trailingAnchor.constraint(equalTo: scrollView.frameLayoutGuide.trailingAnchor),
scrollView.frameLayoutGuide.widthAnchor.constraint(equalTo: scrollView.contentLayoutGuide.widthAnchor),
bottonContainerView.topAnchor.constraint(equalTo: scrollView.frameLayoutGuide.bottomAnchor),
])
let stackView = UIStackView()
stackView.axis = .vertical
stackView.distribution = .fill
stackView.spacing = 10
stackView.layoutMargins = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
stackView.addArrangedSubview(largeTitleLabel)
stackView.addArrangedSubview(subtitleLabel)
stackView.addArrangedSubview(rulesLabel)
stackView.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(stackView)
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor),
stackView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor),
scrollView.contentLayoutGuide.bottomAnchor.constraint(equalTo: stackView.bottomAnchor),
])
rulesLabel.attributedText = viewModel.rulesAttributedString
confirmButton.addTarget(self, action: #selector(MastodonServerRulesViewController.confirmButtonPressed(_:)), for: .touchUpInside)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
}
extension MastodonServerRulesViewController {
@objc private func confirmButtonPressed(_ sender: UIButton) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
}
}
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct ServerRulesViewController_Previews: PreviewProvider {
static var previews: some View {
UIViewControllerPreview {
let viewController = MastodonServerRulesViewController()
return viewController
}
.previewLayout(.fixed(width: 375, height: 800))
}
}
#endif

View File

@ -0,0 +1,41 @@
//
// MastodonServerRulesViewModel.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-2-22.
//
import UIKit
import MastodonSDK
final class MastodonServerRulesViewModel {
// input
let context: AppContext
let domain: String
let rules: [Mastodon.Entity.Instance.Rule]
init(context: AppContext, domain: String, rules: [Mastodon.Entity.Instance.Rule]) {
self.context = context
self.domain = domain
self.rules = rules
}
var rulesAttributedString: NSAttributedString {
let attributedString = NSMutableAttributedString(string: "\n")
for (i, rule) in rules.enumerated() {
let index = String(i + 1)
let indexString = NSAttributedString(string: index + ". ", attributes: [
NSAttributedString.Key.foregroundColor: UIColor.secondaryLabel
])
let ruleString = NSAttributedString(string: rule.text + "\n\n")
attributedString.append(indexString)
attributedString.append(ruleString)
}
// let paragraphStyle = NSMutableParagraphStyle()
// paragraphStyle.lineSpacing = 20
// attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
return attributedString
}
}

View File

@ -50,7 +50,7 @@ extension HomeTimelineViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
title = "Home" title = L10n.Scene.HomeTimeline.title
view.backgroundColor = Asset.Colors.Background.systemBackground.color view.backgroundColor = Asset.Colors.Background.systemBackground.color
navigationItem.leftBarButtonItem = avatarBarButtonItem navigationItem.leftBarButtonItem = avatarBarButtonItem
avatarBarButtonItem.avatarButton.addTarget(self, action: #selector(HomeTimelineViewController.avatarButtonPressed(_:)), for: .touchUpInside) avatarBarButtonItem.avatarButton.addTarget(self, action: #selector(HomeTimelineViewController.avatarButtonPressed(_:)), for: .touchUpInside)

View File

@ -0,0 +1,49 @@
// https://github.com/bielikb/UIViewPreview/blob/master/Sources/UIViewPreview/UIViewPreview.swift
#if canImport(SwiftUI) && DEBUG
import SwiftUI
public struct UIViewPreview<View: UIView>: UIViewRepresentable {
public let view: View
public let width: CGFloat?
public init(width: CGFloat? = nil, _ builder: @escaping () -> View) {
self.view = builder()
self.width = width
}
// MARK: - UIViewRepresentable
public func makeUIView(context: Context) -> UIView {
return view
}
public func updateUIView(_ view: UIView, context: Context) {
view.translatesAutoresizingMaskIntoConstraints = false
view.setContentHuggingPriority(.defaultHigh, for: .horizontal)
view.setContentHuggingPriority(.defaultHigh, for: .vertical)
if let width = width {
NSLayoutConstraint.activate([
view.widthAnchor.constraint(equalToConstant: width),
])
}
}
}
public struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
public let viewController: ViewController
public init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
// MARK: - UIViewControllerRepresentable
public func makeUIViewController(context: Context) -> ViewController {
viewController
}
@available(iOS 13.0, tvOS 13.0, *)
@available(OSX, unavailable)
@available(watchOS, unavailable)
public func updateUIViewController(_ uiViewController: ViewController, context: UIViewControllerRepresentableContext<UIViewControllerPreview<ViewController>>) {
return
}
}
#endif

View File

@ -47,6 +47,18 @@
} }
] ]
} }
},
{
"id" : "C229D9A6-6A83-4AF9-8A71-ADD1AD2AD9D8",
"name" : "mastodon.online",
"options" : {
"environmentVariableEntries" : [
{
"key" : "domain",
"value" : "mastodon.online"
}
]
}
} }
], ],
"defaultOptions" : { "defaultOptions" : {
@ -54,8 +66,18 @@
}, },
"testTargets" : [ "testTargets" : [
{ {
"skippedTests" : [
"MastodonSDKTests\/testCreateAnAnpplication()",
"MastodonSDKTests\/testHomeTimeline()",
"MastodonSDKTests\/testOAuthAuthorize()",
"MastodonSDKTests\/testRetrieveAccountInfo()",
"MastodonSDKTests\/testRevokeToken()",
"MastodonSDKTests\/testUpdateCredentials()",
"MastodonSDKTests\/testVerifyAppCredentials()",
"MastodonSDKTests\/testVerifyCredentials()"
],
"target" : { "target" : {
"containerPath" : "container:", "containerPath" : "container:MastodonSDK",
"identifier" : "MastodonSDKTests", "identifier" : "MastodonSDKTests",
"name" : "MastodonSDKTests" "name" : "MastodonSDKTests"
} }

View File

@ -13,7 +13,7 @@ extension Mastodon.Entity {
/// - Since: 1.1.0 /// - Since: 1.1.0
/// - Version: 3.3.0 /// - Version: 3.3.0
/// # Last Update /// # Last Update
/// 2021/2/5 /// 2021/2/22
/// # Reference /// # Reference
/// [Document](https://docs.joinmastodon.org/entities/instance/) /// [Document](https://docs.joinmastodon.org/entities/instance/)
public struct Instance: Codable { public struct Instance: Codable {
@ -33,6 +33,7 @@ extension Mastodon.Entity {
public let thumbnail: String? public let thumbnail: String?
public let contactAccount: Account? public let contactAccount: Account?
public let rules: [Rule]?
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case uri case uri
@ -48,8 +49,9 @@ extension Mastodon.Entity {
case urls case urls
case statistics case statistics
case thumbnail = "thumbnail" case thumbnail
case contactAccount = "contact_account" case contactAccount = "contact_account"
case rules
} }
} }
} }
@ -77,3 +79,10 @@ extension Mastodon.Entity.Instance {
} }
} }
} }
extension Mastodon.Entity.Instance {
public struct Rule: Codable {
public let id: String
public let text: String
}
}

View File

@ -38,4 +38,36 @@ extension MastodonSDKTests {
wait(for: [theExpectation], timeout: 10.0) wait(for: [theExpectation], timeout: 10.0)
} }
func testInstanceRules() throws {
switch domain {
case "mastodon.online": break
default: return
}
try _testInstanceRules(domain: domain)
}
func _testInstanceRules(domain: String) throws {
let theExpectation = expectation(description: "Fetch Instance Infomation")
Mastodon.API.Instance.instance(session: session, domain: domain)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssertNotEqual(response.value.uri, "")
XCTAssert(!(response.value.rules ?? []).isEmpty)
print(response.value.rules?.sorted(by: { $0.id < $1.id }) ?? "")
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 10.0)
}
} }