Skip to content

Commit

Permalink
Update demo project
Browse files Browse the repository at this point in the history
  • Loading branch information
chasseurmic committed Sep 22, 2014
1 parent f15c95e commit 4c0fd1f
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 5 deletions.
Binary file not shown.
66 changes: 63 additions & 3 deletions Demo/BackgroundDownload/Base.lproj/Main.storyboard
@@ -1,22 +1,82 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="wAS-B0-96b">
<rect key="frame" x="16" y="299" width="568" height="2"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bbp-oA-aBc">
<rect key="frame" x="16" y="270" width="568" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="U26-WQ-IQu">
<rect key="frame" x="248" y="309" width="105" height="30"/>
<state key="normal" title="Start download">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="startDownload:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Pnl-IK-3vQ"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rP3-DB-NLN">
<rect key="frame" x="262" y="385" width="76" height="30"/>
<state key="normal" title="Delete files">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="deleteFiles:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="ydV-WH-8Me"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gjf-kd-ehl">
<rect key="frame" x="240" y="347" width="121" height="30"/>
<state key="normal" title="Cancel Download">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="cancelDownload:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="wlC-iT-lp6"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="wAS-B0-96b" firstAttribute="top" secondItem="Bbp-oA-aBc" secondAttribute="bottom" constant="8" symbolic="YES" id="2IM-4N-xXM"/>
<constraint firstItem="Bbp-oA-aBc" firstAttribute="leading" secondItem="wAS-B0-96b" secondAttribute="leading" id="30h-r5-NbL"/>
<constraint firstItem="U26-WQ-IQu" firstAttribute="centerX" secondItem="wAS-B0-96b" secondAttribute="centerX" id="3Bp-jB-iNc"/>
<constraint firstItem="wAS-B0-96b" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="4wn-K0-b4a"/>
<constraint firstItem="rP3-DB-NLN" firstAttribute="centerX" secondItem="Gjf-kd-ehl" secondAttribute="centerX" id="BHr-Uc-SyW"/>
<constraint firstItem="rP3-DB-NLN" firstAttribute="top" secondItem="Gjf-kd-ehl" secondAttribute="bottom" constant="8" symbolic="YES" id="BIQ-9J-TiR"/>
<constraint firstItem="wAS-B0-96b" firstAttribute="trailing" secondItem="kh9-bI-dsS" secondAttribute="trailingMargin" id="FE7-GG-l0A"/>
<constraint firstItem="U26-WQ-IQu" firstAttribute="centerX" secondItem="Gjf-kd-ehl" secondAttribute="centerX" id="S7l-e0-sxQ"/>
<constraint firstItem="wAS-B0-96b" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="asl-vC-pjG"/>
<constraint firstItem="Bbp-oA-aBc" firstAttribute="trailing" secondItem="wAS-B0-96b" secondAttribute="trailing" id="ci4-U4-wmg"/>
<constraint firstItem="U26-WQ-IQu" firstAttribute="top" secondItem="wAS-B0-96b" secondAttribute="bottom" constant="8" symbolic="YES" id="k5f-rp-IJp"/>
<constraint firstItem="Gjf-kd-ehl" firstAttribute="top" secondItem="U26-WQ-IQu" secondAttribute="bottom" constant="8" symbolic="YES" id="wJ3-Ok-y5S"/>
</constraints>
</view>
<connections>
<outlet property="cancelButton" destination="Gjf-kd-ehl" id="2iU-Dk-ILz"/>
<outlet property="deleteButton" destination="rP3-DB-NLN" id="x5L-J6-jSQ"/>
<outlet property="mainLabel" destination="Bbp-oA-aBc" id="wev-eH-qrL"/>
<outlet property="progressView" destination="wAS-B0-96b" id="91L-CS-oST"/>
<outlet property="startButton" destination="U26-WQ-IQu" id="DAN-vQ-jNS"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
Expand Down
63 changes: 61 additions & 2 deletions Demo/BackgroundDownload/ViewController.m
Expand Up @@ -6,24 +6,83 @@
// Copyright (c) 2014 Touchware. All rights reserved.
//

#define FILE_URL @"http://ovh.net/files/10Mio.dat"

#import "ViewController.h"
#import <TWRDownloadManager/TWRDownloadManager.h>

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *mainLabel;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UIButton *startButton;
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;
@property (assign, nonatomic) CGFloat progress;

- (IBAction)startDownload:(id)sender;
- (IBAction)cancelDownload:(id)sender;
- (IBAction)deleteFiles:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.progressView.progress = 0.0f;
self.mainLabel.text = @"TWRDownloadManager Demo";
if ([[TWRDownloadManager sharedManager] fileExistsForUrl:FILE_URL]) {
self.deleteButton.enabled = YES;
self.cancelButton.enabled = NO;
self.startButton.enabled = NO;
} else {
self.deleteButton.enabled = NO;
self.cancelButton.enabled = NO;
self.startButton.enabled = YES;
}
}

- (IBAction)startDownload:(id)sender {
// Just a demo example file...
[[TWRDownloadManager sharedManager] downloadFileForURL:@"http://ovh.net/files/10Mio.dat" progressBlock:^(CGFloat progress) {
NSLog(@"%.2f", progress);
[[TWRDownloadManager sharedManager] downloadFileForURL:FILE_URL progressBlock:^(CGFloat progress) {
// NSLog(@"%.2f", progress);
self.progress = progress;
self.progressView.progress = progress;
} remainingTime:^(NSUInteger seconds) {
NSLog(@"ETA: %lu sec.", (unsigned long)seconds);
self.mainLabel.text = [NSString stringWithFormat:@"Progress: %.0f%% - ETA: %lu sec.", self.progress, seconds];
} completionBlock:^(BOOL completed) {
NSLog(@"Download completed!");
self.deleteButton.enabled = YES;
self.cancelButton.enabled = NO;
self.startButton.enabled = NO;
} enableBackgroundMode:YES];

self.cancelButton.enabled = YES;
self.startButton.enabled = NO;
}

- (IBAction)cancelDownload:(id)sender {
[[TWRDownloadManager sharedManager] cancelAllDownloads];
[self nilProgress];
self.startButton.enabled = YES;
self.cancelButton.enabled = NO;
self.deleteButton.enabled = NO;
}

- (IBAction)deleteFiles:(id)sender {
[[TWRDownloadManager sharedManager] deleteFileForUrl:FILE_URL];
[self nilProgress];
self.deleteButton.enabled = NO;
self.startButton.enabled = YES;
self.cancelButton.enabled = NO;
}

- (void)nilProgress {
self.progressView.progress = 0.0f;
self.progress = 0.0f;
self.mainLabel.text = @"TWRDownloadManager Demo";
}

@end

0 comments on commit 4c0fd1f

Please sign in to comment.