Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat:- Account Section Implementation. #561

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
3 changes: 1 addition & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ SPEC CHECKSUMS:
SwiftValidators: 660ce9ef3f0358c25c3a6154f7edc02c7d4a0578
Toast-Swift: 594b5c5e5129f15438e410207e43287f027b3c00

PODFILE CHECKSUM: 9b8f14b1a46ec3d802c3eb0dbd813391f49a6f98

PODFILE CHECKSUM: 22d5c21b254f853d49d5c16ae2738eaaa4338e5f

COCOAPODS: 1.5.3
17 changes: 17 additions & 0 deletions Susi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
71DF0561EA8079C5C53174C1 /* Pods_Susi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C564B012515FE5529232089A /* Pods_Susi.framework */; };
80183F6F21D170BB00859F72 /* AboutVCMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80183F6E21D170BB00859F72 /* AboutVCMethods.swift */; };
807A754421D143A1008D4032 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807A754321D143A1008D4032 /* AboutViewController.swift */; };
80E8C2CE229D2F400086F420 /* AccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80E8C2CD229D2F400086F420 /* AccountViewController.swift */; };
80E8C2D0229D2F6D0086F420 /* AccountVCMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80E8C2CF229D2F6D0086F420 /* AccountVCMethods.swift */; };
94889CA61F7CCD370028B8C3 /* GeneralViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94889CA51F7CCD370028B8C3 /* GeneralViewController.swift */; };
94889CAE1F7CEAA80028B8C3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 94889CB01F7CEAA80028B8C3 /* Localizable.strings */; };
A0DEC06E21E0F40300659A5B /* SelectLanguageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0DEC06D21E0F40300659A5B /* SelectLanguageViewController.swift */; };
Expand Down Expand Up @@ -244,6 +246,8 @@
6DFC75B81EE077E9002F92BA /* ForgotPasswordViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForgotPasswordViewController.swift; sourceTree = "<group>"; };
80183F6E21D170BB00859F72 /* AboutVCMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutVCMethods.swift; sourceTree = "<group>"; };
807A754321D143A1008D4032 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
80E8C2CD229D2F400086F420 /* AccountViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountViewController.swift; sourceTree = "<group>"; };
80E8C2CF229D2F6D0086F420 /* AccountVCMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountVCMethods.swift; sourceTree = "<group>"; };
94889CA51F7CCD370028B8C3 /* GeneralViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralViewController.swift; sourceTree = "<group>"; };
94889CAF1F7CEAA80028B8C3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
94889CB11F7CEAAA0028B8C3 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -563,6 +567,7 @@
6D4D9B501E768F2E0067459C /* Controllers */ = {
isa = PBXGroup;
children = (
80E8C2CC229D2F110086F420 /* AccountViewController */,
A0DEC06C21E0F40300659A5B /* SelectLanguageController */,
807A754521D1639B008D4032 /* AboutViewController */,
406482FE20FCF2EF0014EB47 /* PlayerViewController */,
Expand Down Expand Up @@ -685,6 +690,15 @@
path = AboutViewController;
sourceTree = "<group>";
};
80E8C2CC229D2F110086F420 /* AccountViewController */ = {
isa = PBXGroup;
children = (
80E8C2CD229D2F400086F420 /* AccountViewController.swift */,
80E8C2CF229D2F6D0086F420 /* AccountVCMethods.swift */,
);
path = AccountViewController;
sourceTree = "<group>";
};
94889CAB1F7CEA620028B8C3 /* Localization */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -809,6 +823,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
ru,
Expand Down Expand Up @@ -1005,12 +1020,14 @@
40623B7F20D243910013FE60 /* Ratings.swift in Sources */,
6D395D1D1F58966900BCC3C5 /* SkillDetailExampleCell.swift in Sources */,
3BC1D8D5203B177E003E62F9 /* noConnectionViewController.swift in Sources */,
80E8C2D0229D2F6D0086F420 /* AccountVCMethods.swift in Sources */,
6D395D1F1F589CC000BCC3C5 /* SkillDetailVCMethods.swift in Sources */,
94889CA61F7CCD370028B8C3 /* GeneralViewController.swift in Sources */,
6DEE71121F2C9DC900A512CF /* AppNavigationController.swift in Sources */,
80183F6F21D170BB00859F72 /* AboutVCMethods.swift in Sources */,
40801EE320F33B4C0071860E /* VideoPlayerView.swift in Sources */,
6DE0025B1F3FF93A0065DB85 /* AnchorCell.swift in Sources */,
80E8C2CE229D2F400086F420 /* AccountViewController.swift in Sources */,
6D24B0961EE409DB0097418A /* SignUpVCMethods.swift in Sources */,
40DE743920E49F3A003C0116 /* AllFeedbackViewController.swift in Sources */,
407EFAC020C34C0000675A0B /* LanguagePickerController.swift in Sources */,
Expand Down
116 changes: 116 additions & 0 deletions Susi/Controllers/AccountViewController/AccountVCMethods.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// AccountVCMethods.swift
// Susi
//
// Created by Syed on 28/05/19.
// Copyright © 2019 FOSSAsia. All rights reserved.
//

import Foundation

extension AccountViewController: UITextFieldDelegate {

@objc func dismissView() {
self.dismiss(animated: true, completion: nil)
}

func setupTitle() {
navigationItem.titleLabel.text = ControllerConstants.SettingParams.title
navigationItem.titleLabel.textAlignment = .left
navigationItem.titleLabel.textColor = .white
navigationItem.leftViews = [backButton]
navigationItem.rightViews = [settingsButton]
deleteAccountButton.tintColor = .red
}

func setUpUserDetails() {
if let user = delegate?.currentUser {
let imageURL = URL(string: SettingsViewController.getAvatarPath(user.accessToken) )
userAvatarImageView.kf.setImage(with: imageURL)
if UserDefaults.standard.object(forKey: ControllerConstants.SettingParams.userName) == nil {
userEmailLabel.text = user.emailID
} else {
userEmailLabel.text = UserDefaults.standard.object(forKey: ControllerConstants.SettingParams.userName) as? String
}
roundedCorner()
}
}

func roundedCorner() {
userAvatarImageView.layer.cornerRadius = 38.0
userAvatarImageView.layer.borderWidth = 1.0
userAvatarImageView.layer.borderColor = UIColor.iOSGray().cgColor
userAvatarImageView.layer.masksToBounds = true
userAvatarImageView.clipsToBounds = true
}

// Setting Action

@objc func settingButtonClicked() {
if let user = delegate?.currentUser {
let param = [
ControllerConstants.SettingParams.userName: userNameTextField.text as AnyObject,
ControllerConstants.SettingParams.phoneNumber: phoneNumberTextField.text as AnyObject,
ControllerConstants.SettingParams.prefLanguage: prefLanguageTextField.text as AnyObject,
ControllerConstants.SettingParams.count: 3 as AnyObject,
ControllerConstants.SettingParams.accessToken: user.accessToken as AnyObject
]
Client.sharedInstance.changeUserSettings(param) { (_, message) in
DispatchQueue.main.async {
UserDefaults.standard.set(self.userNameTextField.text, forKey: ControllerConstants.SettingParams.userName)
self.view.makeToast(message)
}
}
}
}

// Key Return on Hit

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
switch textField {
case userNameTextField:
_ = phoneNumberTextField.becomeFirstResponder()
case phoneNumberTextField:
dismissKeyboard() default:
textField.resignFirstResponder()
}
return true
}

// Dismiss Keyboard

@objc func dismissKeyboard() {
view.endEditing(true)
}

// Add Delegates

func addDelegates() {
userNameTextField.delegate = self
phoneNumberTextField.delegate = self
picker.dataSource = self
picker.delegate = self
prefLanguageTextField.inputView = picker
}

// Handle Delete Account Request.

func handleDeleteAccountRequest() {
deleteAccountButton.addTarget(self, action: #selector(deleteAccount), for: .touchUpInside)
}

@objc func deleteAccount() {

}

// Handle Upload Avatar

func handleAvatarUpload() {
uploadAvatarButton.addTarget(self, action: #selector(uploadAvatar), for: .touchUpInside)
}

@objc func uploadAvatar() {

}

}
72 changes: 72 additions & 0 deletions Susi/Controllers/AccountViewController/AccountViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// AccountViewController.swift
// Susi
//
// Created by Syed on 28/05/19.
// Copyright © 2019 FOSSAsia. All rights reserved.
//

import UIKit
import Material

class AccountViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {


let delegate = UIApplication.shared.delegate as? AppDelegate

lazy var backButton: IconButton = {
let ib = IconButton()
ib.image = Icon.cm.arrowBack
ib.tintColor = .white
ib.addTarget(self, action: #selector(dismissView), for: .touchUpInside)
return ib
}()

lazy var settingsButton: IconButton = {
let ib = IconButton()
ib.image = Icon.check
ib.tintColor = .white
ib.layer.cornerRadius = 18.0
ib.addTarget(self, action: #selector(settingButtonClicked), for: .touchUpInside)
return ib
}()

var picker = UIPickerView()

var preferredLanguage = ["Armenian (am-AM)","Chinese (zh-CH)","Deutsch (de-DE)"," Greek (gr-GR)","Hindi (hi-IN) ","Punjabi (pb-IN)","Nepali (np-NP)","Russian (ru-RU)","Spanish (es-SP)","French (fr-FR)","apanese (jp-JP) ","Dutch (nl-NL)","US Eng (en-US)"]

@IBOutlet weak var uploadAvatarButton: UIButton!
@IBOutlet weak var deleteAccountButton: UIButton!
@IBOutlet weak var prefLanguageTextField: TextField!
@IBOutlet weak var phoneNumberTextField: TextField!
@IBOutlet weak var userNameTextField: TextField!
@IBOutlet weak var userEmailLabel: UILabel!
@IBOutlet weak var userAvatarImageView: UIImageView!

override func viewDidLoad() {
super.viewDidLoad()
setupTitle()
setUpUserDetails()
addDelegates()
}

//UIPickerView Deledate Functions

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return preferredLanguage.count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return preferredLanguage[row]
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
prefLanguageTextField.text = preferredLanguage[row]
self.view.endEditing(false)
}

}
9 changes: 9 additions & 0 deletions Susi/Controllers/SettingsController/SettingsVCMethods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ extension SettingsViewController {
let nvc = AppNavigationController(rootViewController: vc)
present(nvc, animated: true, completion: nil)
}

// Present Account View Controller

func presentAccountController() {
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = mainStoryboard.instantiateViewController(withIdentifier: "AccountViewController")
let nvc = AppNavigationController(rootViewController: vc)
present(nvc, animated: true, completion: nil)
}

func presentDeviceActivity() {
if let delegate = UIApplication.shared.delegate as? AppDelegate, delegate.currentUser != nil {
Expand Down
10 changes: 7 additions & 3 deletions Susi/Controllers/SettingsController/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class SettingsViewController: UITableViewController {
if user == nil {
presentLoginScreen()
} else {
// Will Connect to the Account Section.
presentAccountController()
}
} else if row == 1 {
presentResetPasswordController()
Expand Down Expand Up @@ -176,10 +176,14 @@ class SettingsViewController: UITableViewController {
if indexPath.section == 6 && indexPath.row == 0 {
let imageURL = URL(string: SettingsViewController.getAvatarPath((user?.accessToken)!) )
userImage.kf.setImage(with: imageURL)
userEmailTitle.text = user?.emailID
if UserDefaults.standard.object(forKey: ControllerConstants.SettingParams.userName) == nil {
userEmailTitle.text = user?.emailID
} else {
userEmailTitle.text = UserDefaults.standard.object(forKey: ControllerConstants.SettingParams.userName) as? String
}
roundedCorner()
//Since account VC not available so, cell should be inactive
cell.isUserInteractionEnabled = false
cell.isUserInteractionEnabled = true
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions Susi/Helpers/ControllerConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ class ControllerConstants {
static let unBookmarkSuccessMessage = "Bookmark Removed Successfully"
}

struct SettingParams {
static let userName = "userName"
static let phoneNumber = "phoneNo"
static let prefLanguage = "prefLanguage"
static let timeZone = "timeZone"
static let accessToken = "access_token"
static let count = "count"
static let title = "Account Settings"
}

}


Loading