Browse Source

AppUpdate, MultiMediaManager - apply SwiftLint

pull/1/head
InKwon James Kim 5 years ago
parent
commit
7eb883ffc7
  1. 2
      GME Remit/Modules/AppUpdate/User Interface/Presenter/AppUpdatePresenter.swift
  2. 16
      GME Remit/Modules/AppUpdate/User Interface/View/AppUpdateViewController.swift
  3. 22
      GME Remit/Modules/GmeContacts/User Interface/View/GmeContactsViewController.swift
  4. 98
      GME Remit/Utilities/MultiMediaManager.swift

2
GME Remit/Modules/AppUpdate/User Interface/Presenter/AppUpdatePresenter.swift

@ -19,7 +19,7 @@ class AppUpdatePresenter {
// MARK: Converting entities
}
// MARK: AppUpdate module interface
// MARK: AppUpdate module interface
extension AppUpdatePresenter: AppUpdateModuleInterface {

16
GME Remit/Modules/AppUpdate/User Interface/View/AppUpdateViewController.swift

@ -71,21 +71,9 @@ class AppUpdateViewController: UIViewController {
func update() {
let urlStr = "itms-apps://itunes.apple.com/gh/app/gme-remit/id1439161261?mt=8"
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: urlStr)!, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
} else {
UIApplication.shared.openURL(URL(string: urlStr)!)
}
UIApplication.tryURL(url: urlStr)
}
}
// MARK: AppUpdateViewInterface
extension AppUpdateViewController: AppUpdateViewInterface {
}
// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] {
return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)})
}
extension AppUpdateViewController: AppUpdateViewInterface {}

22
GME Remit/Modules/GmeContacts/User Interface/View/GmeContactsViewController.swift

@ -77,15 +77,7 @@ class GmeContactsViewController: UIViewController {
private func call(number: String) {
let number = number.removeWhitespacesInBetween()
if let url = URL(string: "tel://\(number)") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(
url,
options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]),
completionHandler: nil
)
}
}
UIApplication.tryURL(url: "tel://\(number)")
}
override func setupTabItem() {
@ -133,18 +125,6 @@ extension GmeContactsViewController {
presenter.view = self
wireframe.view = self
}
// Helper function inserted by Swift 4.2 migrator.
private func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(
_ input: [String: Any]
) -> [UIApplication.OpenExternalURLOptionsKey: Any] {
return Dictionary(
uniqueKeysWithValues: input.map { key, value in
(UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)
}
)
}
}
extension GmeContactsViewController: UITableViewDelegate {

98
GME Remit/Utilities/MultiMediaManager.swift

@ -5,7 +5,6 @@
// Created by shishir sapkota
//
import UIKit
import Foundation
import AVFoundation
@ -40,14 +39,24 @@ class MultiMediaManager: NSObject {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad) {
presentationStyle = .alert
}
//
let alertController = UIAlertController(title: nil, message: "Gme would like to access your camera", preferredStyle: presentationStyle)
let cameraAction = UIAlertAction(title: "camera_text".localized(), style: UIAlertAction.Style.default) { (action) in
let alertController = UIAlertController(
title: nil,
message: "Gme would like to access your camera",
preferredStyle: presentationStyle
)
let cameraAction = UIAlertAction(
title: "camera_text".localized(),
style: UIAlertAction.Style.default
) { (_) in
self.openCamera(mode: .photo)
}
let galleryAction = UIAlertAction(title: "gallery_text".localized(), style: UIAlertAction.Style.default) { (action) in
let galleryAction = UIAlertAction(
title: "gallery_text".localized(),
style: UIAlertAction.Style.default
) { (_) in
self.showPhotoGallery(mode: mode)
}
let cancelAction = UIAlertAction(title: "cancel_text".localized(), style: .cancel, handler: nil)
@ -57,7 +66,11 @@ class MultiMediaManager: NSObject {
self.presentViewController(viewController: alertController, animated: true, completion: nil)
}
private func presentViewController(viewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
private func presentViewController(
viewController: UIViewController,
animated: Bool,
completion: (() -> Void)?
) {
OperationQueue.main.addOperation {
self.presenter?.presenting().present(viewController, animated: animated, completion: completion)
}
@ -76,14 +89,9 @@ class MultiMediaManager: NSObject {
PermissionHelper.isAllowedToRecordVideo { (isAllowed) in
if isAllowed {
openPicker()
}else {
self.presenter?.presenting().alert(message: "camera_access_denied_text", okAction: {
let url = URL(string: UIApplication.openSettingsURLString)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
} else {
// Fallback on earlier versions
}
self.presenter?.presenting().alert(message: "camera_access_denied_text", okAction: {
UIApplication.tryURL(url: UIApplication.openSettingsURLString)
})
}
}
@ -97,21 +105,18 @@ class MultiMediaManager: NSObject {
let mediaTypes = mode == .video ? ["public.image", "public.movie"] : ["public.image"]
self.imagePicker.mediaTypes = mediaTypes
self.presentViewController(viewController: self.imagePicker, animated: true, completion: nil)
}else {
self.presenter?.presenting().alert(message: "galery_access_denied_text".localized(), okAction: {
let url = URL(string: UIApplication.openSettingsURLString)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
} else {
// Fallback on earlier versions
self.presenter?.presenting().alert(
message: "galery_access_denied_text".localized(),
okAction: {
UIApplication.tryURL(url: UIApplication.openSettingsURLString)
}
})
)
}
}
}
func resizeImage(image: UIImage, to targetSize: CGSize) -> UIImage? {
// This is the rect that we've calculated out and this is what is actually used below
let rect = CGRect(origin: CGPoint.zero, size: targetSize)
@ -125,34 +130,37 @@ class MultiMediaManager: NSObject {
}
extension MultiMediaManager: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
// Local variable inserted by Swift 4.2 migrator.
let info = convertFromUIImagePickerControllerInfoKeyDictionary(info)
func imagePickerController(
_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]
) {
let info = Dictionary(uniqueKeysWithValues: info.map {key, value in (key.rawValue, value)})
var completion: (()->())?
var completion: (() -> Void)?
if let mediaType = info["UIImagePickerControllerMediaType"] as? String {
if mediaType == "public.image" {
if let picture = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] as? UIImage {
if let picture = info[
UIImagePickerController.InfoKey.originalImage.rawValue
] as? UIImage {
if let cropsize = self.delegate?.cropSize?() {
if picture.size.width < cropsize.width || picture.size.height < cropsize.height {
self.delegate?.didFinishPickingWithError(error: "Image size must be greater than \(cropsize.width) X \(cropsize.height)")
}else {
let message = "Image size must be greater than \(cropsize.width) X \(cropsize.height)"
self.delegate?.didFinishPickingWithError(error: message)
} else {
guard let resizedImage = self.resizeImage(image: picture, to: cropsize) else { return }
completion = {
self.delegate?.didFinishPickingWithImage?(image: resizedImage)
}
// self.cropImage(image: picture)
}
}else {
} else {
completion = {
self.delegate?.didFinishPickingWithImage?(image: picture)
}
}
}
}else if mediaType == "public.movie" {
_ = info["UIImagePickerControllerMediaURL"] as! URL
} else if mediaType == "public.movie" {
// _ = info["UIImagePickerControllerMediaURL"] as! URL
return
}
}
@ -167,35 +175,19 @@ extension MultiMediaManager: UINavigationControllerDelegate {
}
struct PermissionHelper {
static func isAllowedToRecordVideo(completion: @escaping (Bool) -> ()) {
static func isAllowedToRecordVideo(completion: @escaping (Bool) -> Void) {
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
completion(status != .denied && status != .restricted)
}
static func isAllowedToRecordSound(completion: @escaping (Bool) -> ()) {
static func isAllowedToRecordSound(completion: @escaping (Bool) -> Void) {
AVAudioSession.sharedInstance().requestRecordPermission(completion)
}
static func isAllowedToShowGallary(completion: @escaping (Bool) -> ()) {
static func isAllowedToShowGallary(completion: @escaping (Bool) -> Void) {
PHPhotoLibrary.requestAuthorization { (status) in
completion(status == .authorized)
}
}
}
// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromUIImagePickerControllerInfoKeyDictionary(_ input: [UIImagePickerController.InfoKey: Any]) -> [String: Any] {
return Dictionary(uniqueKeysWithValues: input.map {key, value in (key.rawValue, value)})
}
// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] {
return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)})
}
// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromUIImagePickerControllerInfoKey(_ input: UIImagePickerController.InfoKey) -> String {
return input.rawValue
}
Loading…
Cancel
Save