forked from antoniocasero/ACPDownload
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathViewController.m
More file actions
118 lines (95 loc) · 4.12 KB
/
ViewController.m
File metadata and controls
118 lines (95 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// ViewController.m
// ACPDownload
//
// Created by Antonio Casero Palmero on 10/01/15.
// Copyright (c) 2015 Antonio Casero Palmero. All rights reserved.
//
#import "ViewController.h"
#import "ACPDownloadView.h"
#import "ACPIndeterminateGoogleLayer.h"
#import "ExampleCell.h"
#import "ACPStaticImagesAlternative.h"
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
{
NSTimer *_timer;
}
@property (weak, nonatomic) IBOutlet ACPDownloadView *downloadView;
@property (nonatomic, assign) float progress;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// If you want to change the animation in the indeterminate state
ACPIndeterminateGoogleLayer * layer = [ACPIndeterminateGoogleLayer new];
[layer updateColor:[UIColor blueColor]];
[self.downloadView setIndeterminateLayer:layer];
// You can define a behaviour if the view is tapped. (Optional)
[self.downloadView setActionForTap:^(ACPDownloadView *downloadView, ACPDownloadStatus status){
switch (status) {
case ACPDownloadStatusNone:
[downloadView setIndicatorStatus:ACPDownloadStatusIndeterminate];
break;
case ACPDownloadStatusRunning:
[downloadView setIndicatorStatus:ACPDownloadStatusCompleted];
break;
case ACPDownloadStatusIndeterminate:
[downloadView setIndicatorStatus:ACPDownloadStatusRunning];
break;
case ACPDownloadStatusCompleted:
[downloadView setIndicatorStatus:ACPDownloadStatusNone];
break;
default:
break;
}
}];
// This timer has been written just for testing purposes. It's running and changing the value of the progress variable constantly.
_timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(increment:) userInfo:nil repeats:YES];
}
- (void)increment:(NSTimer *)timer {
self.progress = (self.progress <= 0.8f ? self.progress + 0.2f : 0.0f);
NSLog(@"Progress %f", self.progress);
[self.downloadView setProgress:self.progress animated:YES];
}
#pragma mark - Tableview configuration.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 25;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellIdentifier = @"Cell";
ExampleCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
cell.exampleLabel.text = [NSString stringWithFormat:@"Package %zd", indexPath.row];
// If you want to change the images presented
ACPStaticImagesAlternative * myOwnImages = [ACPStaticImagesAlternative new];
[myOwnImages updateColor:cell.tintColor];
[cell.exampleIndicator setImages:myOwnImages];
//Status by default.
[cell.exampleIndicator setIndicatorStatus:ACPDownloadStatusNone];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ExampleCell * cellSelected = (ExampleCell*)[tableView cellForRowAtIndexPath:indexPath];
switch (cellSelected.exampleIndicator.currentStatus
) {
case ACPDownloadStatusNone:
[cellSelected.exampleIndicator setIndicatorStatus:ACPDownloadStatusIndeterminate];
break;
case ACPDownloadStatusRunning:
[cellSelected.exampleIndicator setIndicatorStatus:ACPDownloadStatusCompleted];
break;
case ACPDownloadStatusIndeterminate:
[cellSelected.exampleIndicator setIndicatorStatus:ACPDownloadStatusRunning];
[cellSelected.exampleIndicator setProgress:self.progress animated:YES];
break;
case ACPDownloadStatusCompleted:
[cellSelected.exampleIndicator setIndicatorStatus:ACPDownloadStatusNone];
break;
default:
break;
}
}
@end