VLCAboutViewController.m 4.89 KB
Newer Older
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*****************************************************************************
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 2015 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

#import "VLCAboutViewController.h"

@interface VLCAboutViewController ()
{
Tobias's avatar
Tobias committed
16 17
    CADisplayLink *displayLink;
    NSTimer *startAnimationTimer;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31
}
@end

@implementation VLCAboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSBundle *mainBundle = [NSBundle mainBundle];
    self.versionLabel.text = [[NSString stringWithFormat:NSLocalizedString(@"VERSION_FORMAT", nil), [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]] stringByAppendingFormat:@" (%@)", [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]];
    self.basedOnLabel.text = [[NSString stringWithFormat:NSLocalizedString(@"BASED_ON_FORMAT", nil),[[VLCLibrary sharedLibrary] version]] stringByReplacingOccurrencesOfString:@"<br />" withString:@" "];
    self.titleLabel.text = self.title;
    self.titleLabel.textColor = [UIColor colorWithWhite:0.5 alpha:1.];

Tobias's avatar
Tobias committed
32 33
    UITextView *textView = self.blablaTextView;
    textView.attributedText = [[NSAttributedString alloc] initWithData:[[NSString stringWithContentsOfFile:[[NSBundle mainBundle]
34 35 36 37 38 39 40
                                                                                                                       pathForResource:@"About Contents" ofType:@"html"]
                                                                                                             encoding:NSUTF8StringEncoding
                                                                                                                error:nil]
                                                                                   dataUsingEncoding:NSUTF8StringEncoding]
                                                                          options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                                                                                    NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
                                                               documentAttributes:nil error:nil];
Tobias's avatar
Tobias committed
41 42 43 44 45 46 47 48 49
    textView.scrollEnabled = YES;
    textView.panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ];
    [textView.panGestureRecognizer addTarget:self action:@selector(scrollViewPan:)];
    textView.userInteractionEnabled = YES;
    textView.showsVerticalScrollIndicator = YES;

    UITapGestureRecognizer *tapUpArrowRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollToTop)];
    tapUpArrowRecognizer.allowedPressTypes = @[@(UIPressTypeUpArrow)];
    [textView addGestureRecognizer:tapUpArrowRecognizer];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
50 51
}

Tobias's avatar
Tobias committed
52
- (void)viewDidAppear:(BOOL)animated
Felix Paul Kühne's avatar
Felix Paul Kühne committed
53
{
Tobias's avatar
Tobias committed
54 55 56 57 58 59 60
    [super viewDidAppear:animated];
    [self startAnimationTimer];
}
- (void) viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self stopAnimation];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
61 62
}

Tobias's avatar
Tobias committed
63
- (UIView *)preferredFocusedView
Felix Paul Kühne's avatar
Felix Paul Kühne committed
64
{
Tobias's avatar
Tobias committed
65 66 67 68 69 70 71 72 73
    return self.blablaTextView;
}

- (void)scrollToTop
{
    [self stopAnimation];
    [self.blablaTextView setContentOffset:CGPointZero animated:YES];
    [self startAnimationTimer];
}
Felix Paul Kühne's avatar
Felix Paul Kühne committed
74

Tobias's avatar
Tobias committed
75 76 77 78 79 80 81 82 83 84 85
- (void)scrollViewPan:(UIPanGestureRecognizer *)recognizer
{
    switch(recognizer.state) {
        case UIGestureRecognizerStateCancelled:
        case UIGestureRecognizerStateFailed:
        case UIGestureRecognizerStateEnded:
            [self startAnimationTimer];
            break;
        default:
            [self stopAnimation];
            break;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
86 87 88
    }
}

Tobias's avatar
Tobias committed
89
- (void)startAnimationTimer
Felix Paul Kühne's avatar
Felix Paul Kühne committed
90
{
Tobias's avatar
Tobias committed
91
    [startAnimationTimer invalidate];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
92
    startAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(startAnimation) userInfo:nil repeats:NO];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
93 94
}

Tobias's avatar
Tobias committed
95 96 97 98 99 100 101 102
- (void)stopAnimation
{
    [startAnimationTimer invalidate];
    startAnimationTimer = nil;
    [displayLink invalidate];
    displayLink = nil;
}
- (void)startAnimation
Felix Paul Kühne's avatar
Felix Paul Kühne committed
103
{
Tobias's avatar
Tobias committed
104 105 106 107
    [displayLink invalidate];
    displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTriggered:)];
    [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
Felix Paul Kühne's avatar
Felix Paul Kühne committed
108

Tobias's avatar
Tobias committed
109 110 111 112 113 114
- (void)displayLinkTriggered:(CADisplayLink*)link
{
    UIScrollView *scrollView = self.blablaTextView;
    CGFloat viewHeight = CGRectGetHeight(scrollView.frame);
    CGFloat maxOffsetY = scrollView.contentSize.height - viewHeight;

115
    CFTimeInterval secondsPerPage = 5.0;
Tobias's avatar
Tobias committed
116
    CGFloat offset = link.duration/secondsPerPage * viewHeight;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
117

Tobias's avatar
Tobias committed
118
    CGFloat newYOffset = scrollView.contentOffset.y + offset;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
119

Tobias's avatar
Tobias committed
120 121 122 123
    if (newYOffset > maxOffsetY+viewHeight) {
        scrollView.contentOffset = CGPointMake(0, -viewHeight);
    } else {
        scrollView.contentOffset = CGPointMake(0, newYOffset);
Felix Paul Kühne's avatar
Felix Paul Kühne committed
124 125 126 127
    }
}

@end