Skip to content

Commit

Permalink
refactor(example): improve the way upload was managed
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Nov 10, 2023
1 parent 321dd83 commit bc17f80
Show file tree
Hide file tree
Showing 12 changed files with 520 additions and 348 deletions.
56 changes: 51 additions & 5 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
objects = {

/* Begin PBXBuildFile section */
211834CE29CDBAB2002F2CCD /* AsyncApiUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211834CD29CDBAB2002F2CCD /* AsyncApiUtils.swift */; };
211834DB29CDEFF8002F2CCD /* Contents.json in Resources */ = {isa = PBXBuildFile; fileRef = 211834D829CDEFF8002F2CCD /* Contents.json */; };
211834E129CDF08F002F2CCD /* ClientAppError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211834DE29CDF08F002F2CCD /* ClientAppError.swift */; };
211834E229CDF08F002F2CCD /* CancellableApiTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211834DF29CDF08F002F2CCD /* CancellableApiTask.swift */; };
211834E329CDF08F002F2CCD /* TaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211834E029CDF08F002F2CCD /* TaskManager.swift */; };
211834E729CDF0A8002F2CCD /* AsyncApiUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211834E529CDF0A8002F2CCD /* AsyncApiUtils.swift */; };
211834E829CDF0A8002F2CCD /* AlertUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211834E629CDF0A8002F2CCD /* AlertUtils.swift */; };
2136DD4A274B9E74007B9FC9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2136DD49274B9E74007B9FC9 /* AppDelegate.swift */; };
2136DD4C274B9E74007B9FC9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2136DD4B274B9E74007B9FC9 /* SceneDelegate.swift */; };
2136DD4E274B9E74007B9FC9 /* VideosViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2136DD4D274B9E74007B9FC9 /* VideosViewController.swift */; };
Expand All @@ -21,6 +28,13 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
211834CD29CDBAB2002F2CCD /* AsyncApiUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AsyncApiUtils.swift; path = Utils/AsyncApiUtils.swift; sourceTree = "<group>"; };
211834D829CDEFF8002F2CCD /* Contents.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Contents.json; path = Assets.xcassets/Contents.json; sourceTree = "<group>"; };
211834DE29CDF08F002F2CCD /* ClientAppError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClientAppError.swift; sourceTree = "<group>"; };
211834DF29CDF08F002F2CCD /* CancellableApiTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CancellableApiTask.swift; sourceTree = "<group>"; };
211834E029CDF08F002F2CCD /* TaskManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskManager.swift; sourceTree = "<group>"; };
211834E529CDF0A8002F2CCD /* AsyncApiUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AsyncApiUtils.swift; sourceTree = "<group>"; };
211834E629CDF0A8002F2CCD /* AlertUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertUtils.swift; sourceTree = "<group>"; };
2136DD46274B9E74007B9FC9 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
2136DD49274B9E74007B9FC9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2136DD4B274B9E74007B9FC9 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -49,6 +63,25 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
211834DD29CDF08F002F2CCD /* Models */ = {
isa = PBXGroup;
children = (
211834DE29CDF08F002F2CCD /* ClientAppError.swift */,
211834DF29CDF08F002F2CCD /* CancellableApiTask.swift */,
211834E029CDF08F002F2CCD /* TaskManager.swift */,
);
path = Models;
sourceTree = "<group>";
};
211834E429CDF0A8002F2CCD /* Utils */ = {
isa = PBXGroup;
children = (
211834E529CDF0A8002F2CCD /* AsyncApiUtils.swift */,
211834E629CDF0A8002F2CCD /* AlertUtils.swift */,
);
path = Utils;
sourceTree = "<group>";
};
2136DD3D274B9E74007B9FC9 = {
isa = PBXGroup;
children = (
Expand All @@ -70,7 +103,10 @@
2136DD48274B9E74007B9FC9 /* Example */ = {
isa = PBXGroup;
children = (
C7BC280827A18111007406AB /* Controller */,
211834E429CDF0A8002F2CCD /* Utils */,
211834DD29CDF08F002F2CCD /* Models */,
211834D829CDEFF8002F2CCD /* Contents.json */,
C7BC280827A18111007406AB /* ViewControllers */,
C7BC280527A17FD4007406AB /* Cell */,
2136DD49274B9E74007B9FC9 /* AppDelegate.swift */,
2136DD4B274B9E74007B9FC9 /* SceneDelegate.swift */,
Expand All @@ -79,6 +115,7 @@
2136DD54274B9E77007B9FC9 /* LaunchScreen.storyboard */,
2136DD57274B9E77007B9FC9 /* Info.plist */,
C7BC280927A18CC3007406AB /* ClientManager.swift */,
211834CD29CDBAB2002F2CCD /* AsyncApiUtils.swift */,
);
path = Example;
sourceTree = "<group>";
Expand Down Expand Up @@ -107,13 +144,13 @@
path = Cell;
sourceTree = "<group>";
};
C7BC280827A18111007406AB /* Controller */ = {
C7BC280827A18111007406AB /* ViewControllers */ = {
isa = PBXGroup;
children = (
2136DD4D274B9E74007B9FC9 /* VideosViewController.swift */,
C7BC280327A17CD2007406AB /* UploaderViewController.swift */,
);
path = Controller;
path = ViewControllers;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -180,6 +217,7 @@
2136DD56274B9E77007B9FC9 /* LaunchScreen.storyboard in Resources */,
2136DD53274B9E77007B9FC9 /* Assets.xcassets in Resources */,
2136DD51274B9E74007B9FC9 /* Main.storyboard in Resources */,
211834DB29CDEFF8002F2CCD /* Contents.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -191,10 +229,16 @@
buildActionMask = 2147483647;
files = (
2136DD4E274B9E74007B9FC9 /* VideosViewController.swift in Sources */,
211834E129CDF08F002F2CCD /* ClientAppError.swift in Sources */,
211834CE29CDBAB2002F2CCD /* AsyncApiUtils.swift in Sources */,
2136DD4A274B9E74007B9FC9 /* AppDelegate.swift in Sources */,
C7BC280A27A18CC3007406AB /* ClientManager.swift in Sources */,
C7BC280427A17CD2007406AB /* UploaderViewController.swift in Sources */,
211834E729CDF0A8002F2CCD /* AsyncApiUtils.swift in Sources */,
211834E829CDF0A8002F2CCD /* AlertUtils.swift in Sources */,
2136DD4C274B9E74007B9FC9 /* SceneDelegate.swift in Sources */,
211834E229CDF08F002F2CCD /* CancellableApiTask.swift in Sources */,
211834E329CDF08F002F2CCD /* TaskManager.swift in Sources */,
C7BC280727A17FEB007406AB /* VideoTableViewCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -344,9 +388,10 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VY3VXRC7P4;
DEVELOPMENT_TEAM = GBC36KP98K;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Example/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = ApiVideoClient;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand All @@ -372,9 +417,10 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VY3VXRC7P4;
DEVELOPMENT_TEAM = GBC36KP98K;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Example/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = ApiVideoClient;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand Down
13 changes: 7 additions & 6 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="3CK-R2-GCw">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="3CK-R2-GCw">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -37,8 +38,8 @@
<color key="selectedImageTintColor" systemColor="systemOrangeColor"/>
</tabBar>
<connections>
<segue destination="Oab-1J-PC3" kind="relationship" relationship="viewControllers" id="H1D-MD-HYN"/>
<segue destination="In4-UD-ga0" kind="relationship" relationship="viewControllers" id="i1c-pb-5v8"/>
<segue destination="Oab-1J-PC3" kind="relationship" relationship="viewControllers" id="H1D-MD-HYN"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="YCT-xC-6pf" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
Expand All @@ -59,7 +60,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iu5-5Z-Td8" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1079.7101449275362" y="564.50892857142856"/>
<point key="canvasLocation" x="1038" y="603"/>
</scene>
<!--Videos-->
<scene sceneID="A2Y-hp-1rs">
Expand All @@ -68,7 +69,7 @@
<tabBarItem key="tabBarItem" title="Videos" image="play.tv" catalog="system" id="fXv-jp-edW"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" largeTitles="YES" id="d0o-RT-P8e">
<rect key="frame" x="0.0" y="44" width="414" height="96"/>
<rect key="frame" x="0.0" y="48" width="414" height="96"/>
<autoresizingMask key="autoresizingMask"/>
<textAttributes key="largeTitleTextAttributes">
<color key="textColor" systemColor="systemOrangeColor"/>
Expand All @@ -85,7 +86,7 @@
</scene>
</scenes>
<resources>
<image name="play.tv" catalog="system" width="128" height="97"/>
<image name="play.tv" catalog="system" width="128" height="95"/>
<image name="square.and.arrow.up.fill" catalog="system" width="115" height="128"/>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down
66 changes: 42 additions & 24 deletions Example/Example/Cell/VideoTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
//

import UIKit
import ApiVideoClient

class VideoTableViewCell: UITableViewCell {

static let identifier = "VideoTableViewCell"

private let title: UILabel = {
let label = UILabel()
label.numberOfLines = 1
Expand All @@ -19,66 +20,83 @@ class VideoTableViewCell: UITableViewCell {
label.numberOfLines = 1
return label
}()
private let myImageView: UIImageView = {

private let thumbnailView: UIImageView = {
let imageView = UIImageView()
return imageView
}()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(title)
contentView.addSubview(videoId)
contentView.addSubview(myImageView)
myImageView.contentMode = .scaleAspectFit
myImageView.backgroundColor = .black
contentView.addSubview(thumbnailView)
thumbnailView.contentMode = .scaleAspectFit
thumbnailView.backgroundColor = .black
contentView.clipsToBounds = true
accessoryType = .none
}
required init?(coder: NSCoder){

required init?(coder: NSCoder) {
fatalError()
}

override func layoutSubviews() {
super.layoutSubviews()
myImageView.frame = CGRect(
thumbnailView.frame = CGRect(
x: 10,
y: 5,
width: contentView.frame.size.width - 20,
height: contentView.frame.size.height * 0.7
)

title.frame = CGRect(
x: 20,
y: (myImageView.frame.height * 0.6) + 55,
y: (thumbnailView.frame.height * 0.6) + 55,
width: contentView.frame.size.width,
height: contentView.frame.size.height * 0.4
)
videoId.frame = CGRect(
x: 20,
y: (myImageView.frame.height * 0.6) + 80,
y: (thumbnailView.frame.height * 0.6) + 80,
width: contentView.frame.size.width,
height: contentView.frame.size.height * 0.4
)
videoId.textColor = .lightGray
videoId.font = videoId.font.withSize(10)
}

override func prepareForReuse() {
super.prepareForReuse()
title.text = nil
videoId.text = nil
}

public func configure(with model: VideosOption){
title.text = model.title
videoId.text = model.videoId

let myUrl = URL(string: model.thumbnail!)
let myData = try? Data(contentsOf: myUrl!)
myImageView.image = UIImage(data: myData!)


public func bind(with video: Video) {
title.text = video.title ?? "Unknown title"
videoId.text = video.videoId

if let thumbnail = video.assets?.thumbnail {
do {
guard let thumbnailUrl = URL(string: thumbnail) else {
print("Invalid thumbnail url: \(thumbnail)")
return
}
fetchThumbnails(url: thumbnailUrl)
} catch {
print("Error while loading thumbnail: \(error)")
}
}
}

private func fetchThumbnails(url: URL) {
Task {
do {
let (data, _) = try await URLSession.shared.data(from: url)
thumbnailView.image = UIImage(data: data)
} catch {
print("Error while loading thumbnail: \(error)")
}
}
}
}
19 changes: 10 additions & 9 deletions Example/Example/ClientManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import Foundation
import ApiVideoClient

class ClientManager{
public static var apiKey: String = ""
class ClientManager {
public static var apiKey: String = "YOUR_API_KEY"
public static var environment: Environment = Environment.sandbox

public static func environmentToBool()-> Bool{
var isOn = false
if(environment == Environment.production){
isOn = true

public static var isProduction: Bool {
get {
if (environment == Environment.production) {
return true
} else {
return false
}
}
return isOn
}

}
Loading

0 comments on commit bc17f80

Please sign in to comment.