Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

redesign/onboarding #541

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
"username" = "Username";
"display_name" = "Display Name";

"email_login" = "Enter email";
"enter_your_pin_received_by_mail" = "Enter pin sent to email";
"check_spam" = "Didn’t receive the email? Check spam";
"pin" = "Pin";

"invalid_email" = "Please enter a valid email";
Expand Down Expand Up @@ -287,3 +285,29 @@
"FollowRecommendations.YouMayKnow" = "You may know";

"Notifications.FollowRecommendations" = "We found some people you may know, add them and get chatting today.";

"Authentication.Skip" = "Skip";

"Authentication.Email" = "Email";
"Authentication.Pin" = "Login Code";
"Authentication.Pin.Description" = "Didn't receive the email? Check spam";

"Authentication.Name" = "Name";
"Authentication.Name.Description" = "What's your name?";

"Authentication.Username" = "Username";
"Authentication.Username.Description" = "Choose a username for people to find you on Soapbox.";

"Authentication.Error.InvalidName" = "Please enter a name.";

"Authentication.ProfilePhoto" = "Profile Photo";
"Authentication.ProfilePhoto.Description" = "Set your profile photo so your friends will recognize you.";

"Authentication.Permissions" = "Permissions";
"Authentication.Permissions.Description" = "Soapbox is an audio-first app, we'll need few permissions from you.";

"Authentication.Permissions.Microphone" = "Microphone";
"Authentication.Permissions.Microphone.Description" = "So your friends can hear your beautiful voice.";

"Authentication.Permissions.Notifications" = "Notifications";
"Authentication.Permissions.Notifications.Description" = "So you'll know when your friends are online and chatting.";
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ target 'Soapbox' do
pod 'DrawerView', git: '[email protected]:SoapboxSocial/DrawerView.git', commit: 'b0f4ad7ac60e0a5cfe089e55995115ccb7893d01'
pod 'NotificationBannerSwift'
pod 'KeychainAccess'
pod 'SwiftConfettiView'
pod 'UIWindowTransitions'
pod 'AlamofireImage'
pod 'GSImageViewerController'
Expand Down
6 changes: 1 addition & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ PODS:
- SnapKit (~> 5.0.1)
- Siren (5.8.1)
- SnapKit (5.0.1)
- SwiftConfettiView (0.1.0)
- Swifter (2.5.0)
- SwiftProtobuf (1.17.0)
- UIWindowTransitions (1.0.0)
Expand All @@ -32,7 +31,6 @@ DEPENDENCIES:
- KeychainAccess
- NotificationBannerSwift
- Siren
- SwiftConfettiView
- "Swifter (from `[email protected]:mattdonnelly/Swifter.git`)"
- SwiftProtobuf
- UIWindowTransitions
Expand All @@ -51,7 +49,6 @@ SPEC REPOS:
- NotificationBannerSwift
- Siren
- SnapKit
- SwiftConfettiView
- SwiftProtobuf
- UIWindowTransitions

Expand Down Expand Up @@ -84,11 +81,10 @@ SPEC CHECKSUMS:
NotificationBannerSwift: 7021be2338f8f29cf424b0aca43da462bf9e2a1a
Siren: de768099aff1f1c9acda4247064788a4940b4bf3
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
SwiftConfettiView: 1bdbc2e6913b6b1c76d8070802b212508ad5c352
Swifter: 4c2f8cf320c2f751c10128f841d8e9bd8609d988
SwiftProtobuf: 9c85136c6ba74b0a1b84279dbf0f6db8efb714e0
UIWindowTransitions: 2237083382e11f100db7de934041bba0c4669c86

PODFILE CHECKSUM: a3326625314027ca9400b4e1af13d652f700ef54
PODFILE CHECKSUM: c10badbc8db03cfc239205760cb09131995a79fe

COCOAPODS: 1.10.1
31 changes: 0 additions & 31 deletions Resources/Settings.bundle/Acknowledgements.plist
Original file line number Diff line number Diff line change
Expand Up @@ -404,37 +404,6 @@ THE SOFTWARE.
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string>MIT License

Copyright (c) 2019 Uğur Ethem AYDIN

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
</string>
<key>License</key>
<string>MIT</string>
<key>Title</key>
<string>SwiftConfettiView</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string> Apache License
Expand Down
42 changes: 28 additions & 14 deletions Sources/API/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,12 @@ class APIClient: Client {
}
}

func register(token: String, username: String, displayName: String, image: UIImage, callback: @escaping (Result<(User, Int), Error>) -> Void) {
AF.upload(
multipartFormData: { multipartFormData in
guard let imgData = image.jpegData(compressionQuality: 0.5) else {
return callback(.failure(.preprocessing))
}

multipartFormData.append(imgData, withName: "profile", fileName: "profile", mimeType: "image/jpg")

multipartFormData.append(displayName.data(using: String.Encoding.utf8)!, withName: "display_name")
multipartFormData.append(username.data(using: String.Encoding.utf8)!, withName: "username")
multipartFormData.append(token.data(using: String.Encoding.utf8)!, withName: "token")
},
to: Configuration.rootURL.appendingPathComponent("/v1/login/register")
func register(token: String, username: String, displayName: String, callback: @escaping (Result<(User, Int), Error>) -> Void) {
AF.request(
Configuration.rootURL.appendingPathComponent("/v1/login/register"),
method: .post,
parameters: ["display_name": displayName, "username": username, "token": token],
encoding: URLEncoding.default
)
.validate()
.response { result in
Expand All @@ -129,6 +121,28 @@ class APIClient: Client {
}
}

func edit(image: UIImage, callback: @escaping (Result<Void, Error>) -> Void) {
AF.upload(
multipartFormData: { multipartFormData in
guard let imgData = image.jpegData(compressionQuality: 0.5) else {
return callback(.failure(.preprocessing))
}

multipartFormData.append(imgData, withName: "profile", fileName: "profile", mimeType: "image/jpg")
},
to: Configuration.rootURL.appendingPathComponent("/v1/users/upload"),
headers: ["Authorization": token!]
)
.validate()
.response { result in
if let error = self.validate(result) {
return callback(.failure(error))
}

callback(.success(()))
}
}

func completeRegistration(callback: @escaping (Result<Void, Error>) -> Void) {
post(path: "/v1/login/register/completed", callback: callback)
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class NotificationManager {
delegate?.deviceTokenFailedToSet()
}

func requestAuthorization() {
func requestAuthorization(callback: ((Bool) -> Void)? = nil) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ in
callback?(granted)

guard granted else {
DispatchQueue.main.async {
self.delegate?.deviceTokenFailedToSet()
Expand Down
72 changes: 39 additions & 33 deletions Sources/Scenes/Authentication/AuthenticationInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import UIWindowTransitions
protocol AuthenticationInteractorOutput {
func present(error: AuthenticationInteractor.AuthenticationError)
func present(state: AuthenticationInteractor.AuthenticationState)
func presentLoggedInView()
}

class AuthenticationInteractor: NSObject, AuthenticationViewControllerOutput {
private let output: AuthenticationInteractorOutput
private let api: APIClient

private var token: String?
private var displayName: String!

enum AuthenticationState: Int {
case getStarted, login, pin, registration, requestNotifications, follow, success
case start, login, pin, name, username, profilePhoto, permissions, invite, completed
}

enum AuthenticationError {
case invalidEmail, invalidPin, invalidUsername, usernameTaken, missingProfileImage, general, registerWithEmailDisabled
case invalidEmail, invalidPin, invalidUsername, invalidDisplayName, usernameTaken, general, registerWithEmailDisabled
}

init(output: AuthenticationInteractorOutput, api: APIClient) {
Expand Down Expand Up @@ -64,7 +64,7 @@ class AuthenticationInteractor: NSObject, AuthenticationViewControllerOutput {
authController.performRequests()
}

func submitPin(pin: String?) {
func submit(pin: String?) {
guard let input = pin else {
return output.present(error: .invalidPin)
}
Expand All @@ -91,28 +91,38 @@ class AuthenticationInteractor: NSObject, AuthenticationViewControllerOutput {

self.store(token: self.token!, expires: expires, user: user)

NotificationManager.shared.requestAuthorization()

DispatchQueue.main.async {
self.output.presentLoggedInView()
self.output.present(state: .invite)
}
case .register:
self.output.present(state: .registration)
self.output.present(state: .name)
}
}
}
}

func register(username: String?, displayName: String?, image: UIImage?) {
guard let usernameInput = username, isValidUsername(usernameInput) else {
return output.present(error: .invalidUsername)
func submit(displayName: String?) {
guard let input = displayName else {
output.present(error: .invalidDisplayName)
return
}

guard let profileImage = image else {
return output.present(error: .missingProfileImage)
let name = input.trimmingCharacters(in: .whitespacesAndNewlines)
if input == "" {
output.present(error: .invalidDisplayName)
return
}

api.register(token: token!, username: usernameInput, displayName: displayName ?? usernameInput, image: profileImage) { result in
self.displayName = name
output.present(state: .username)
}

func register(withUsername username: String?) {
guard let usernameInput = username, isValidUsername(usernameInput) else {
return output.present(error: .invalidUsername)
}

api.register(token: token!, username: usernameInput, displayName: displayName) { result in
switch result {
case let .failure(error):
switch error {
Expand All @@ -128,15 +138,23 @@ class AuthenticationInteractor: NSObject, AuthenticationViewControllerOutput {
case let .success((user, expires)):
self.store(token: self.token!, expires: expires, user: user)
DispatchQueue.main.async {
self.output.present(state: .requestNotifications)

NotificationManager.shared.delegate = self
NotificationManager.shared.requestAuthorization()
self.output.present(state: .profilePhoto)
}
}
}
}

func submit(image: UIImage) {
api.edit(image: image, callback: { result in
switch result {
case let .failure(error):
return
case let .success:
return
}
})
}

func follow(users: [Int]) {
if users.count == 0 {
return registrationCompleted()
Expand All @@ -158,7 +176,7 @@ class AuthenticationInteractor: NSObject, AuthenticationViewControllerOutput {
}
})

output.present(state: .success)
// output.present(state: .success)
}

private func isValidUsername(_ username: String) -> Bool {
Expand Down Expand Up @@ -193,16 +211,6 @@ class AuthenticationInteractor: NSObject, AuthenticationViewControllerOutput {
}
}

extension AuthenticationInteractor: NotificationManagerDelegate {
func deviceTokenFailedToSet() {
output.present(state: .follow)
}

func deviceTokenWasSet() {
output.present(state: .follow)
}
}

extension AuthenticationInteractor: ASAuthorizationControllerDelegate {
func authorizationController(controller _: ASAuthorizationController, didCompleteWithError error: Error) {
output.present(error: .general)
Expand Down Expand Up @@ -238,17 +246,15 @@ extension AuthenticationInteractor: ASAuthorizationControllerDelegate {

NotificationManager.shared.requestAuthorization()

DispatchQueue.main.async {
self.output.presentLoggedInView()
}
self.output.present(state: .completed)
case .register:
guard let token = response.3 else {
return self.output.present(error: .general)
}

self.token = token

self.output.present(state: .registration)
self.output.present(state: .name)
}
}
})
Expand Down
22 changes: 6 additions & 16 deletions Sources/Scenes/Authentication/AuthenticationPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ class AuthenticationPresenter: AuthenticationInteractorOutput {
output.displayError(.normal, title: NSLocalizedString("incorrect_pin", comment: ""), description: nil)
case .invalidUsername:
output.displayError(.normal, title: NSLocalizedString("invalid_username", comment: ""), description: nil)
case .missingProfileImage:
output.displayError(.normal, title: NSLocalizedString("pick_profile_image", comment: ""), description: nil)
case .invalidDisplayName:
output.displayError(
.normal,
title: NSLocalizedString("Authentication.Error.InvalidName", comment: ""),
description: nil
)
case .usernameTaken:
output.displayError(.normal, title: NSLocalizedString("username_already_exists", comment: ""), description: nil)
case .registerWithEmailDisabled:
Expand All @@ -39,19 +43,5 @@ class AuthenticationPresenter: AuthenticationInteractorOutput {

func present(state: AuthenticationInteractor.AuthenticationState) {
output.transitionTo(state: state)

if state == .success {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.1) {
self.presentLoggedInView()
}
}
}

func presentLoggedInView() {
let delegate = UIApplication.shared.delegate as! AppDelegate
delegate.window!.set(
rootViewController: delegate.createLoggedIn(),
options: UIWindow.TransitionOptions(direction: .fade, style: .easeOut)
)
}
}
Loading