-
Notifications
You must be signed in to change notification settings - Fork 2
/
SuggestionCollectionViewCell.m
129 lines (105 loc) · 4.54 KB
/
SuggestionCollectionViewCell.m
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
119
120
121
122
123
124
125
126
127
128
129
//
// SuggestionCollectionViewCell.m
// Soundrocket
//
// Created by Sebastian Boldt on 14.06.15.
// Copyright © 2015 sebastianboldt. All rights reserved.
//
#import "SuggestionCollectionViewCell.h"
#import "Track.h"
#import "TrackRepost.h"
#import "Playlist.h"
#import "PlaylistRepost.h"
#import <FAKIonIcons.h>
#import <FAKFontAwesome.h>
#import <UIImageView+AFNetworking.h>
#import <NSDate+DateTools.h>
#import <FAKFontAwesome.h>
@implementation SuggestionCollectionViewCell
-(void)mySharedSuggestionCell {
self.usernameLabel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[self.usernameLabel addTarget:self action:@selector(userButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
FAKIonIcons *playIcon = [FAKIonIcons iosAlbumsIconWithSize:17];
self.playlistLabel.attributedText = [playIcon attributedString];
}
-(void)awakeFromNib {
[super awakeFromNib];
[self mySharedSuggestionCell];
}
-(void)userButtonPressed:(id)sender {
if([self.object respondsToSelector:@selector(user)]){
User * user = (User*)[self.object performSelector:@selector(user) withObject:nil];
[self.delegate userButtonPressedWithUser:user];
}
}
-(instancetype)init {
if (self = [super init]) {
[self mySharedSuggestionCell];
}
return self;
}
-(void)prepareForReuse {
[super prepareForReuse];
self.coverView.image = nil;
self.playlistIndicator.hidden = YES;
}
-(void)setObject:(id)object {
_object = object;
if ([object isKindOfClass:[Track class]]) {
[self setupCellWithTrack:(Track*)object];
} else if([object isKindOfClass:[TrackRepost class]]) {
[self setupCellWithTrack:[[Track alloc]initWithTrackRespost:object]];
} else if([object isKindOfClass:[Playlist class]]){
[self setupCellWithPlaylist:(Playlist*)object];
} else if([object isKindOfClass:[PlaylistRepost class]]){
[self setupCellWithPlaylist:[[Playlist alloc]initWithPlayListRepost:object]];
}
}
#pragma mark - Setup Functions
-(void)setupCellWithTrack:(Track*)track {
self.playlistIndicator.hidden = YES;
if (track.artwork_url) {
[self.coverView setImageWithURL:[NSURL URLWithString:track.artwork_url] placeholderImage:nil];
} else {
[self.coverView setImageWithURL:[NSURL URLWithString:track.user.avatar_url] placeholderImage:nil];
}
[self.usernameLabel setTitle:track.user.username forState:UIControlStateNormal];
self.trackNameLabel.text = track.title;
FAKIonIcons *playIcon = [FAKIonIcons playIconWithSize:10];
NSMutableAttributedString * playbackcount = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%ld ",(long)[track.playback_count integerValue]]];
[playbackcount appendAttributedString:[playIcon attributedString]];
self.playbackCountLabel.attributedText = playbackcount;
}
-(void)setupCellWithPlaylist:(Playlist*)playlist {
if (playlist.artwork_url) {
[self.coverView setImageWithURL:[NSURL URLWithString:playlist.artwork_url] placeholderImage:nil];
} else {
[self.coverView setImageWithURL:[NSURL URLWithString:playlist.user.avatar_url] placeholderImage:nil];
}
[self.usernameLabel setTitle:playlist.user.username forState:UIControlStateNormal];
self.trackNameLabel.text = playlist.title;
// Private not private etc
FAKFontAwesome * lockIcon = [FAKFontAwesome lockIconWithSize:10];
NSMutableAttributedString * lockString = [[NSMutableAttributedString alloc]init];
if ([playlist.sharing isEqualToString:@"private"]) {
lockString = [[lockIcon attributedString]mutableCopy];
[lockString appendAttributedString:[[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@" %ld Tracks",(long)[playlist.track_count integerValue]]]];
} else {
[lockString appendAttributedString:[[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%ld Tracks",(long)[playlist.track_count integerValue]]]];
}
self.playbackCountLabel.attributedText = lockString;
self.playlistIndicator.hidden = NO;
}
-(NSDate *)convertUTCStringToDate:(NSString *)utcDateString {
NSDateFormatter *df = [[NSDateFormatter alloc]init];
df.dateFormat = @"yyyy/MM/dd HH:mm:ss +0000";
return [df dateFromString:utcDateString];
}
/*
-(void)userButtonPressed:(id)sender {
if([self.data respondsToSelector:@selector(user)]){
User * user = (User*)[self.data performSelector:@selector(user) withObject:nil];
[self.delegate userButtonPressedWithUserID:user.id];
}
}*/
@end