chore: update password hint, handle error when use PhotosUI

This commit is contained in:
sunxiaojian 2021-03-02 17:24:04 +08:00
parent eb2057d14e
commit f16b4ed1cb
6 changed files with 32 additions and 19 deletions

View File

@ -108,8 +108,7 @@
}, },
"password": { "password": {
"placeholder": "password", "placeholder": "password",
"prompt": "Your password needs at least:", "hint": "Your password needs at least Eight characters"
"prompt_eight_characters": "Eight characters"
}, },
"invite": { "invite": {
"registration_user_invite_request": "Why do you want to join?" "registration_user_invite_request": "Why do you want to join?"

View File

@ -192,12 +192,10 @@ internal enum L10n {
internal static let registrationUserInviteRequest = L10n.tr("Localizable", "Scene.Register.Input.Invite.RegistrationUserInviteRequest") internal static let registrationUserInviteRequest = L10n.tr("Localizable", "Scene.Register.Input.Invite.RegistrationUserInviteRequest")
} }
internal enum Password { internal enum Password {
/// Your password needs at least Eight characters
internal static let hint = L10n.tr("Localizable", "Scene.Register.Input.Password.Hint")
/// password /// password
internal static let placeholder = L10n.tr("Localizable", "Scene.Register.Input.Password.Placeholder") 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 { internal enum Username {
/// This username is taken. /// This username is taken.

View File

@ -61,9 +61,8 @@ tap the link to confirm your account.";
"Scene.Register.Input.DisplayName.Placeholder" = "display name"; "Scene.Register.Input.DisplayName.Placeholder" = "display name";
"Scene.Register.Input.Email.Placeholder" = "email"; "Scene.Register.Input.Email.Placeholder" = "email";
"Scene.Register.Input.Invite.RegistrationUserInviteRequest" = "Why do you want to join?"; "Scene.Register.Input.Invite.RegistrationUserInviteRequest" = "Why do you want to join?";
"Scene.Register.Input.Password.Hint" = "Your password needs at least Eight characters";
"Scene.Register.Input.Password.Placeholder" = "password"; "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.DuplicatePrompt" = "This username is taken.";
"Scene.Register.Input.Username.Placeholder" = "username"; "Scene.Register.Input.Username.Placeholder" = "username";
"Scene.Register.Success" = "Success"; "Scene.Register.Success" = "Success";

View File

@ -16,12 +16,27 @@ extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerVi
picker.dismiss(animated: true, completion: {}) picker.dismiss(animated: true, completion: {})
return return
} }
itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, _ in itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in
guard let self = self, let image = image as? UIImage else { return } guard let self = self else { return }
guard let image = image as? UIImage else {
guard let error = error else { return }
let alertController = UIAlertController(for: error, title: "", preferredStyle: .alert)
let okAction = UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default, handler: nil)
alertController.addAction(okAction)
DispatchQueue.main.async {
self.coordinator.present(
scene: .alertController(alertController: alertController),
from: nil,
transition: .alertController(animated: true, completion: nil)
)
}
return
}
DispatchQueue.main.async { DispatchQueue.main.async {
let cropController = CropViewController(croppingStyle: .default, image: image) let cropController = CropViewController(croppingStyle: .default, image: image)
cropController.delegate = self cropController.delegate = self
cropController.setAspectRatioPreset(.presetSquare, animated: true) cropController.setAspectRatioPreset(.presetSquare, animated: true)
cropController.aspectRatioPickerButtonHidden = true
cropController.aspectRatioLockEnabled = true cropController.aspectRatioLockEnabled = true
picker.dismiss(animated: true, completion: { picker.dismiss(animated: true, completion: {
self.present(cropController, animated: true, completion: nil) self.present(cropController, animated: true, completion: nil)
@ -37,11 +52,6 @@ extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerVi
} }
@objc func avatarButtonPressed(_ sender: UIButton) { @objc func avatarButtonPressed(_ sender: UIButton) {
var configuration = PHPickerConfiguration()
configuration.filter = .images
let imagePicker = PHPickerViewController(configuration: configuration)
imagePicker.delegate = self
self.present(imagePicker, animated: true, completion: nil) self.present(imagePicker, animated: true, completion: nil)
} }
} }

View File

@ -10,6 +10,7 @@ import MastodonSDK
import os.log import os.log
import UIKit import UIKit
import UITextField_Shake import UITextField_Shake
import PhotosUI
final class MastodonRegisterViewController: UIViewController, NeedsDependency, OnboardingViewControllerAppearance { final class MastodonRegisterViewController: UIViewController, NeedsDependency, OnboardingViewControllerAppearance {
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
@ -19,6 +20,15 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
var viewModel: MastodonRegisterViewModel! var viewModel: MastodonRegisterViewModel!
lazy var imagePicker: PHPickerViewController = {
var configuration = PHPickerConfiguration()
configuration.filter = .images
let imagePicker = PHPickerViewController(configuration: configuration)
imagePicker.delegate = self
return imagePicker
}()
let tapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer let tapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
let scrollView: UIScrollView = { let scrollView: UIScrollView = {

View File

@ -161,11 +161,8 @@ extension MastodonRegisterViewModel {
let falseColor = UIColor.clear let falseColor = UIColor.clear
let attributeString = NSMutableAttributedString() let attributeString = NSMutableAttributedString()
let start = NSAttributedString(string: "Your password needs at least:", attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: color])
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: L10n.Scene.Register.Input.Password.hint, attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: color])
attributeString.append(eightCharactersDescription) attributeString.append(eightCharactersDescription)
return attributeString return attributeString