Commit cd1a85f5 authored by Hadrien De Sousa's avatar Hadrien De Sousa Committed by Kateryna Kostiuk
Browse files

Me: refactor MeViewController



This commit refactors the meViewController that now displays the user
name and the registered name if there is one

It allows the user to pick or take a picture from the device

Change-Id: I0a1bf9c1636a216668dae5de8d78948bea66ead1
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 8fe122e0
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
04399B131D1C341A00E99CD9 /* libvpx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04399AE11D1C341A00E99CD9 /* libvpx.a */; }; 04399B131D1C341A00E99CD9 /* libvpx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04399AE11D1C341A00E99CD9 /* libvpx.a */; };
04399B141D1C341A00E99CD9 /* libx264.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04399AE21D1C341A00E99CD9 /* libx264.a */; }; 04399B141D1C341A00E99CD9 /* libx264.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04399AE21D1C341A00E99CD9 /* libx264.a */; };
04399B151D1C341A00E99CD9 /* libyaml-cpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04399AE31D1C341A00E99CD9 /* libyaml-cpp.a */; }; 04399B151D1C341A00E99CD9 /* libyaml-cpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04399AE31D1C341A00E99CD9 /* libyaml-cpp.a */; };
0586C94B1F684DF600613517 /* UIImage+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0586C94A1F684DF600613517 /* UIImage+Helpers.swift */; };
1A0C4EDA1F1D4B1B00550433 /* WelcomeViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A0C4ED91F1D4B1B00550433 /* WelcomeViewController.storyboard */; }; 1A0C4EDA1F1D4B1B00550433 /* WelcomeViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A0C4ED91F1D4B1B00550433 /* WelcomeViewController.storyboard */; };
1A0C4EDC1F1D4B7E00550433 /* WelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C4EDB1F1D4B7E00550433 /* WelcomeViewController.swift */; }; 1A0C4EDC1F1D4B7E00550433 /* WelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C4EDB1F1D4B7E00550433 /* WelcomeViewController.swift */; };
1A0C4EE31F1D673600550433 /* InjectionBag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C4EE21F1D673600550433 /* InjectionBag.swift */; }; 1A0C4EE31F1D673600550433 /* InjectionBag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C4EE21F1D673600550433 /* InjectionBag.swift */; };
...@@ -136,7 +137,6 @@ ...@@ -136,7 +137,6 @@
1A2D18FD1F292DAD00B2C785 /* ConversationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1A2D18FB1F292DAD00B2C785 /* ConversationCell.xib */; }; 1A2D18FD1F292DAD00B2C785 /* ConversationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1A2D18FB1F292DAD00B2C785 /* ConversationCell.xib */; };
1A2D18FF1F29352D00B2C785 /* MeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */; }; 1A2D18FF1F29352D00B2C785 /* MeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */; };
1A2D19011F29353A00B2C785 /* MeDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D19001F29353A00B2C785 /* MeDetailViewModel.swift */; }; 1A2D19011F29353A00B2C785 /* MeDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D19001F29353A00B2C785 /* MeDetailViewModel.swift */; };
1A2D19041F2937DF00B2C785 /* AccountTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D19031F2937DF00B2C785 /* AccountTableViewCell.swift */; };
1A3CA32B1F102BB700283748 /* Chameleon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A3CA32A1F102BB700283748 /* Chameleon.framework */; }; 1A3CA32B1F102BB700283748 /* Chameleon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A3CA32A1F102BB700283748 /* Chameleon.framework */; };
1A3CA32D1F13DA7200283748 /* Chameleon+Ring.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3CA32C1F13DA7200283748 /* Chameleon+Ring.swift */; }; 1A3CA32D1F13DA7200283748 /* Chameleon+Ring.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3CA32C1F13DA7200283748 /* Chameleon+Ring.swift */; };
1A3D28A71F0EB9DB00B524EE /* Bool+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3D28A61F0EB9DB00B524EE /* Bool+String.swift */; }; 1A3D28A71F0EB9DB00B524EE /* Bool+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3D28A61F0EB9DB00B524EE /* Bool+String.swift */; };
...@@ -295,6 +295,7 @@ ...@@ -295,6 +295,7 @@
04399AE11D1C341A00E99CD9 /* libvpx.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvpx.a; path = ../fat/lib/libvpx.a; sourceTree = "<group>"; }; 04399AE11D1C341A00E99CD9 /* libvpx.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvpx.a; path = ../fat/lib/libvpx.a; sourceTree = "<group>"; };
04399AE21D1C341A00E99CD9 /* libx264.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libx264.a; path = ../fat/lib/libx264.a; sourceTree = "<group>"; }; 04399AE21D1C341A00E99CD9 /* libx264.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libx264.a; path = ../fat/lib/libx264.a; sourceTree = "<group>"; };
04399AE31D1C341A00E99CD9 /* libyaml-cpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libyaml-cpp.a"; path = "../fat/lib/libyaml-cpp.a"; sourceTree = "<group>"; }; 04399AE31D1C341A00E99CD9 /* libyaml-cpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libyaml-cpp.a"; path = "../fat/lib/libyaml-cpp.a"; sourceTree = "<group>"; };
0586C94A1F684DF600613517 /* UIImage+Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Helpers.swift"; sourceTree = "<group>"; };
1A0C4ED91F1D4B1B00550433 /* WelcomeViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = WelcomeViewController.storyboard; path = Welcome/WelcomeViewController.storyboard; sourceTree = "<group>"; }; 1A0C4ED91F1D4B1B00550433 /* WelcomeViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = WelcomeViewController.storyboard; path = Welcome/WelcomeViewController.storyboard; sourceTree = "<group>"; };
1A0C4EDB1F1D4B7E00550433 /* WelcomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WelcomeViewController.swift; path = Welcome/WelcomeViewController.swift; sourceTree = "<group>"; }; 1A0C4EDB1F1D4B7E00550433 /* WelcomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WelcomeViewController.swift; path = Welcome/WelcomeViewController.swift; sourceTree = "<group>"; };
1A0C4EE21F1D673600550433 /* InjectionBag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionBag.swift; sourceTree = "<group>"; }; 1A0C4EE21F1D673600550433 /* InjectionBag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionBag.swift; sourceTree = "<group>"; };
...@@ -348,7 +349,6 @@ ...@@ -348,7 +349,6 @@
1A2D18FB1F292DAD00B2C785 /* ConversationCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ConversationCell.xib; sourceTree = "<group>"; }; 1A2D18FB1F292DAD00B2C785 /* ConversationCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ConversationCell.xib; sourceTree = "<group>"; };
1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeViewModel.swift; sourceTree = "<group>"; }; 1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeViewModel.swift; sourceTree = "<group>"; };
1A2D19001F29353A00B2C785 /* MeDetailViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeDetailViewModel.swift; sourceTree = "<group>"; }; 1A2D19001F29353A00B2C785 /* MeDetailViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeDetailViewModel.swift; sourceTree = "<group>"; };
1A2D19031F2937DF00B2C785 /* AccountTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountTableViewCell.swift; sourceTree = "<group>"; };
1A3CA32A1F102BB700283748 /* Chameleon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Chameleon.framework; path = Carthage/Build/iOS/Chameleon.framework; sourceTree = "<group>"; }; 1A3CA32A1F102BB700283748 /* Chameleon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Chameleon.framework; path = Carthage/Build/iOS/Chameleon.framework; sourceTree = "<group>"; };
1A3CA32C1F13DA7200283748 /* Chameleon+Ring.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Chameleon+Ring.swift"; sourceTree = "<group>"; }; 1A3CA32C1F13DA7200283748 /* Chameleon+Ring.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Chameleon+Ring.swift"; sourceTree = "<group>"; };
1A3D28A61F0EB9DB00B524EE /* Bool+String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bool+String.swift"; sourceTree = "<group>"; }; 1A3D28A61F0EB9DB00B524EE /* Bool+String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bool+String.swift"; sourceTree = "<group>"; };
...@@ -610,6 +610,7 @@ ...@@ -610,6 +610,7 @@
1A2D18991F2642C000B2C785 /* NotificationCenter+Ring.swift */, 1A2D18991F2642C000B2C785 /* NotificationCenter+Ring.swift */,
1A2D189B1F264AD900B2C785 /* UIViewController+Ring.swift */, 1A2D189B1F264AD900B2C785 /* UIViewController+Ring.swift */,
1A2D18A51F27F7A400B2C785 /* UIViewController+Rx.swift */, 1A2D18A51F27F7A400B2C785 /* UIViewController+Rx.swift */,
0586C94A1F684DF600613517 /* UIImage+Helpers.swift */,
); );
path = Extensions; path = Extensions;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -914,7 +915,6 @@ ...@@ -914,7 +915,6 @@
1A2D18D91F2918F300B2C785 /* Me */ = { 1A2D18D91F2918F300B2C785 /* Me */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
1A2D19021F2937BB00B2C785 /* Cells */,
1A2D18EC1F2919D800B2C785 /* MeViewController.storyboard */, 1A2D18EC1F2919D800B2C785 /* MeViewController.storyboard */,
1A5DC02B1F3565250075E8EF /* MeViewController.swift */, 1A5DC02B1F3565250075E8EF /* MeViewController.swift */,
1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */, 1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */,
...@@ -943,14 +943,6 @@ ...@@ -943,14 +943,6 @@
path = ../SmartList/Cells; path = ../SmartList/Cells;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
1A2D19021F2937BB00B2C785 /* Cells */ = {
isa = PBXGroup;
children = (
1A2D19031F2937DF00B2C785 /* AccountTableViewCell.swift */,
);
path = Cells;
sourceTree = "<group>";
};
1A5DC0331F3567080075E8EF /* ContactRequests */ = { 1A5DC0331F3567080075E8EF /* ContactRequests */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -1248,6 +1240,7 @@ ...@@ -1248,6 +1240,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
557086521E8ADB9D001A7CE4 /* SystemAdapter.mm in Sources */, 557086521E8ADB9D001A7CE4 /* SystemAdapter.mm in Sources */,
0586C94B1F684DF600613517 /* UIImage+Helpers.swift in Sources */,
1A2D18AC1F29149D00B2C785 /* MeCoordinator.swift in Sources */, 1A2D18AC1F29149D00B2C785 /* MeCoordinator.swift in Sources */,
1A2D18C51F29180700B2C785 /* ContactModel.swift in Sources */, 1A2D18C51F29180700B2C785 /* ContactModel.swift in Sources */,
1A2D18F71F292D7200B2C785 /* MessageCellSent.swift in Sources */, 1A2D18F71F292D7200B2C785 /* MessageCellSent.swift in Sources */,
...@@ -1291,7 +1284,6 @@ ...@@ -1291,7 +1284,6 @@
1A2041821F1E906B00C08435 /* CreateProfileViewModel.swift in Sources */, 1A2041821F1E906B00C08435 /* CreateProfileViewModel.swift in Sources */,
1A0C4EE31F1D673600550433 /* InjectionBag.swift in Sources */, 1A0C4EE31F1D673600550433 /* InjectionBag.swift in Sources */,
564C44641E943E1E000F92B1 /* NameRegistrationAdapterDelegate.swift in Sources */, 564C44641E943E1E000F92B1 /* NameRegistrationAdapterDelegate.swift in Sources */,
1A2D19041F2937DF00B2C785 /* AccountTableViewCell.swift in Sources */,
1A2D18AA1F29131900B2C785 /* ConversationsCoordinator.swift in Sources */, 1A2D18AA1F29131900B2C785 /* ConversationsCoordinator.swift in Sources */,
043999F71D1C2D9D00E99CD9 /* AppDelegate.swift in Sources */, 043999F71D1C2D9D00E99CD9 /* AppDelegate.swift in Sources */,
1A2041861F1EA19600C08435 /* CreateAccountViewController.swift in Sources */, 1A2041861F1EA19600C08435 /* CreateAccountViewController.swift in Sources */,
......
//
// UIImage+Helpers.swift
// Ring
//
// Created by Hadrien De Sousa on 17-07-19.
// Copyright © 2017 Savoir-faire Linux. All rights reserved.
//
import Foundation
import UIKit
extension UIImage {
var circleMasked: UIImage? {
let newSize = self.size
let minEdge = min(newSize.height, newSize.width)
let size = CGSize(width: minEdge, height: minEdge)
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
let context = UIGraphicsGetCurrentContext()
self.draw(in: CGRect(origin: CGPoint.zero, size: size), blendMode: .copy, alpha: 1.0)
context!.setBlendMode(.copy)
context!.setFillColor(UIColor.clear.cgColor)
let rectPath = UIBezierPath(rect: CGRect(origin: CGPoint.zero, size: size))
let circlePath = UIBezierPath(ovalIn: CGRect(origin: CGPoint.zero, size: size))
rectPath.append(circlePath)
rectPath.usesEvenOddFillRule = true
rectPath.fill()
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return result
}
// convenience function in UIImage extension to resize a given image
func convert(toSize size: CGSize, scale: CGFloat) -> UIImage {
let imgRect = CGRect(origin: CGPoint(x:0.0, y:0.0), size: size)
UIGraphicsBeginImageContextWithOptions(size, false, scale)
self.draw(in: imgRect)
let copied = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return copied!
}
}
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
*
* Author: Edric Ladent-Milaret <edric.ladent-milaret@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import UIKit
import Reusable
class AccountTableViewCell: UITableViewCell, NibReusable {
// MARK: - Properties
@IBOutlet weak var activeSwitch: UISwitch!
@IBOutlet weak var accountNameLabel: UILabel!
@IBOutlet weak var accountTypeLabel: UILabel!
var account: AccountModel!
// MARK: - Actions
@IBAction func switchAccountState(_ sender: UISwitch) {
// account.isEnabled = sender.isOn
}
}
...@@ -20,16 +20,20 @@ ...@@ -20,16 +20,20 @@
import UIKit import UIKit
import Reusable import Reusable
import RxSwift
class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, StoryboardBased, ViewModelBased { class MeViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, StoryboardBased, ViewModelBased {
// MARK: - outlets // MARK: - outlets
@IBOutlet weak var accountTableView: UITableView!
@IBOutlet weak var nameLabel: UILabel! @IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var qrImageView: UIImageView! @IBOutlet weak var ringIdLabel: UILabel!
@IBOutlet weak var profileImageView: UIImageView!
@IBOutlet weak var importButton: UIButton!
@IBOutlet weak var photoButton: UIButton!
// MARK: - members // MARK: - members
var viewModel: MeViewModel! var viewModel: MeViewModel!
fileprivate let disposeBag = DisposeBag()
// MARK: - functions // MARK: - functions
override func viewDidLoad() { override func viewDidLoad() {
...@@ -37,76 +41,88 @@ class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSo ...@@ -37,76 +41,88 @@ class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSo
self.title = L10n.Global.meTabBarTitle self.title = L10n.Global.meTabBarTitle
self.navigationItem.title = L10n.Global.meTabBarTitle self.navigationItem.title = L10n.Global.meTabBarTitle
self.setupUI()
} }
// MARK: - QRCode func setupUI() {
func createQRFromString(_ str: String) {
let data = str.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) self.viewModel.userName.asObservable()
.bind(to: self.nameLabel.rx.text)
.disposed(by: disposeBag)
let filter = CIFilter(name: "CIQRCodeGenerator") self.viewModel.ringId.asObservable()
filter!.setValue(data, forKey: "inputMessage") .bind(to: self.ringIdLabel.rx.text)
.disposed(by: disposeBag)
let qrImage: CIImage = filter!.outputImage! let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
profileImageView.isUserInteractionEnabled = true
profileImageView.addGestureRecognizer(tapGestureRecognizer)
let scaleX = qrImageView.frame.size.width / qrImage.extent.size.width photoButton.rx.tap.subscribe(onNext: {
let scaleY = qrImageView.frame.size.height / qrImage.extent.size.height self.takePicture()
}).disposed(by: self.disposeBag)
photoButton.backgroundColor = UIColor(white: 1, alpha: 0)
let resultQrImage = qrImage.applying(CGAffineTransform(scaleX: scaleX, y: scaleY)) importButton.rx.tap.subscribe(onNext: {
qrImageView.image = UIImage(ciImage: resultQrImage) self.importPicture()
}).disposed(by: self.disposeBag)
importButton.backgroundColor = UIColor(white: 1, alpha: 0)
} }
// MARK: - TableView func imageTapped(tapGestureRecognizer: UITapGestureRecognizer) {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.viewModel.accountNumber + 1
} }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func takePicture() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
if indexPath.row < self.viewModel.accountNumber { let imagePicker = UIImagePickerController()
let cell = tableView.dequeueReusableCell(for: indexPath, cellType: AccountTableViewCell.self) imagePicker.delegate = self
let account = self.viewModel.account(at: indexPath.row) imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
cell.account = account imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "addAccountTableCell", for: indexPath)
return cell
} }
} }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { func importPicture() {
if indexPath.row == self.viewModel.accountNumber { let imagePicker = UIImagePickerController()
accountTableView.reloadData() imagePicker.delegate = self
} imagePicker.allowsEditing = true
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(imagePicker, animated: true, completion: nil)
} }
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { // MARK: - Delegates
if indexPath.row == self.viewModel.accountNumber { func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
return false var image: UIImage!
}
return true if let img = info[UIImagePickerControllerEditedImage] as? UIImage {
} image = img
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { } else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage {
if editingStyle == UITableViewCellEditingStyle.delete { image = img
self.viewModel.deleteAccount(at: indexPath.row)
accountTableView.reloadData()
} }
}
// MARK: - Actions profileImageView.contentMode = .scaleAspectFit
@IBAction func addAccountClicked(_ sender: AnyObject) { profileImageView.image = image.convert(toSize:CGSize(width:100.0, height:100.0), scale: UIScreen.main.scale).circleMasked
let index = IndexPath(row: self.viewModel.accountNumber, section: 0) dismiss(animated:true, completion: nil)
accountTableView.selectRow(at: index, animated: false, scrollPosition: UITableViewScrollPosition.none)
tableView(accountTableView, didSelectRowAt: index)
} }
// MARK: - QRCode
// func createQRFromString(_ str: String) {
//
// let data = str.data(using: String.Encoding.isoLatin1, allowLossyConversion: false)
//
// let filter = CIFilter(name: "CIQRCodeGenerator")
// filter!.setValue(data, forKey: "inputMessage")
//
// let qrImage: CIImage = filter!.outputImage!
//
// let scaleX = qrImageView.frame.size.width / qrImage.extent.size.width
// let scaleY = qrImageView.frame.size.height / qrImage.extent.size.height
//
// let resultQrImage = qrImage.applying(CGAffineTransform(scaleX: scaleX, y: scaleY))
// qrImageView.image = UIImage(ciImage: resultQrImage)
// }
} }
...@@ -25,26 +25,19 @@ class MeViewModel: Stateable, ViewModel { ...@@ -25,26 +25,19 @@ class MeViewModel: Stateable, ViewModel {
// MARK: - Rx Stateable // MARK: - Rx Stateable
private let stateSubject = PublishSubject<State>() private let stateSubject = PublishSubject<State>()
let accountService: AccountsService
var userName: Single<String?>
let ringId: Single<String?>
lazy var state: Observable<State> = { lazy var state: Observable<State> = {
return self.stateSubject.asObservable() return self.stateSubject.asObservable()
}() }()
var accountNumber: Int {
return self.accountService.accounts.count
}
let accountService: AccountsService
required init(with injectionBag: InjectionBag) { required init(with injectionBag: InjectionBag) {
self.accountService = injectionBag.accountService self.accountService = injectionBag.accountService
} self.userName = Single.just(self.accountService.currentAccount?.volatileDetails?.get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountRegisteredName)))
self.ringId = Single.just(self.accountService.currentAccount?.details?.get(withConfigKeyModel: ConfigKeyModel(withKey: .accountUsername)))
func account(at row: Int) -> AccountModel {
return self.accountService.accounts[row]
}
func deleteAccount(at row: Int) {
self.accountService.removeAccount(row)
} }
} }
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
<!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>NSPhotoLibraryUsageDescription</key>
<string>Used to let the user choose a profile picture</string>
<key>NSCameraUsageDescription</key>
<string>Used to take user profile picture</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment