From d74181dad0ac3a5bf944df9496b008b637a67464 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Mon, 14 Sep 2015 11:27:29 +0800 Subject: [PATCH] select alert set username --- .../EditProfileViewController.swift | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Yep/ViewControllers/EditProfile/EditProfileViewController.swift b/Yep/ViewControllers/EditProfile/EditProfileViewController.swift index b4027f60..e710d6cf 100644 --- a/Yep/ViewControllers/EditProfile/EditProfileViewController.swift +++ b/Yep/ViewControllers/EditProfile/EditProfileViewController.swift @@ -338,6 +338,43 @@ extension EditProfileViewController: UITableViewDataSource, UITableViewDelegate switch indexPath.row { + case InfoRow.Username.rawValue: + + if let + myUserID = YepUserDefaults.userID.value, + me = userWithUserID(myUserID, inRealm: Realm()) { + + let username = me.username + + if username.isEmpty { + + YepAlert.textInput(title: NSLocalizedString("Set Username", comment: ""), message: NSLocalizedString("Please note that you can only set username once.", comment: ""), placeholder: NSLocalizedString("use letters, numbers, and underscore", comment: ""), oldText: nil, confirmTitle: NSLocalizedString("Set", comment: ""), cancelTitle: NSLocalizedString("Cancel", comment: ""), inViewController: self, withConfirmAction: { text in + + let newUsername = text + + updateMyselfWithInfo(["username": newUsername], failureHandler: { [weak self] reason, errorMessage in + defaultFailureHandler(reason, errorMessage) + + YepAlert.alertSorry(message: errorMessage ?? NSLocalizedString("Set username failed!", comment: ""), inViewController: self) + + }, completion: { success in + dispatch_async(dispatch_get_main_queue()) { + let realm = Realm() + if let + myUserID = YepUserDefaults.userID.value, + me = userWithUserID(myUserID, inRealm: realm) { + realm.write { + me.username = newUsername + } + } + } + }) + + }, cancelAction: { + }) + } + } + case InfoRow.Nickname.rawValue: performSegueWithIdentifier("showEditNicknameAndBadge", sender: nil)