Skip to content
This repository
tree: 4430b9c381
Fetching contributors…

Cannot retrieve contributors at this time

file 69 lines (59 sloc) 2.156 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
//
// AccountStatusView.m
// AppSales
//
// Created by Ole Zorn on 03.08.11.
// Copyright 2011 omz:software. All rights reserved.
//

#import "AccountStatusView.h"
#import "ASAccount.h"

@implementation AccountStatusView

- (id)initWithFrame:(CGRect)frame account:(ASAccount *)anAccount
{
self = [super initWithFrame:frame];
if (self) {
account = [anAccount retain];
self.backgroundColor = [UIColor clearColor];
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 5, 16, 16)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[self addSubview:activityIndicator];

statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(36, 5, frame.size.width - 2 * 36, 16)];
statusLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.font = [UIFont systemFontOfSize:14.0];
statusLabel.textColor = [UIColor colorWithRed:0.322 green:0.357 blue:0.443 alpha:1.0];
statusLabel.shadowColor = [UIColor whiteColor];
statusLabel.shadowOffset = CGSizeMake(0, 1);
statusLabel.textAlignment = UITextAlignmentCenter;
[self addSubview:statusLabel];

[self updateStatus];

[account addObserver:self forKeyPath:@"isDownloadingReports" options:NSKeyValueObservingOptionNew context:nil];
[account addObserver:self forKeyPath:@"downloadStatus" options:NSKeyValueObservingOptionNew context:nil];
}
return self;
}

- (void)updateStatus
{
if (account.isDownloadingReports) {
[activityIndicator startAnimating];
statusLabel.text = account.downloadStatus;
} else {
[activityIndicator stopAnimating];
statusLabel.text = @"";
}
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
[self updateStatus];
}

- (void)dealloc
{
[account removeObserver:self forKeyPath:@"isDownloadingReports"];
[account removeObserver:self forKeyPath:@"downloadStatus"];
[activityIndicator release];
[statusLabel release];
[account release];
[super dealloc];
}

@end
Something went wrong with that request. Please try again.