VLCMultiSelectionMenuView.m 8.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
//
//  VLCMultiSelectionMenuView.m
//  VLC for iOS
//
//  Created by Felix Paul Kühne on 09/03/15.
//  Copyright (c) 2015 VideoLAN. All rights reserved.
//

#import "VLCMultiSelectionMenuView.h"

11
#define buttonWidth 35.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#define buttonHeight 35.
#define spacer 8.

@interface VLCMultiSelectionMenuView ()
{
    BOOL _showsEQ;
}

@end

@implementation VLCMultiSelectionMenuView

- (instancetype)init
{
    self = [super initWithFrame:CGRectMake(0., 0., buttonWidth, buttonHeight)];

    if (self) {
        _equalizerButton = [UIButton buttonWithType:UIButtonTypeCustom];
30
        [_equalizerButton setImage:[UIImage imageNamed:@"equalizerIcon"] forState:UIControlStateNormal];
31 32 33 34 35 36 37
        _equalizerButton.titleLabel.textColor = [UIColor whiteColor];
        _equalizerButton.frame = CGRectMake(spacer, spacer, buttonWidth, buttonHeight);
        [_equalizerButton addTarget:self action:@selector(equalizerAction:) forControlEvents:UIControlEventTouchUpInside];
        _equalizerButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        [self addSubview:_equalizerButton];

        _chapterSelectorButton = [UIButton buttonWithType:UIButtonTypeCustom];
38
        [_chapterSelectorButton setImage:[UIImage imageNamed:@"chaptersIcon"] forState:UIControlStateNormal];
39 40 41 42 43 44 45
        _chapterSelectorButton.titleLabel.textColor = [UIColor whiteColor];
        _chapterSelectorButton.frame = CGRectMake(spacer, spacer + buttonHeight + spacer, buttonWidth, buttonHeight);
        [_chapterSelectorButton addTarget:self action:@selector(chapterSelectorAction:) forControlEvents:UIControlEventTouchUpInside];
        _chapterSelectorButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        [self addSubview:_chapterSelectorButton];

        _repeatButton = [UIButton buttonWithType:UIButtonTypeCustom];
46
        [_repeatButton setImage:[UIImage imageNamed:@"no-repeat"] forState:UIControlStateNormal];
47 48 49 50 51 52
        _repeatButton.frame = CGRectMake(spacer, spacer + buttonHeight + spacer + buttonHeight + spacer, buttonWidth, buttonHeight);
        [_repeatButton addTarget:self action:@selector(repeatAction:) forControlEvents:UIControlEventTouchUpInside];
        _repeatButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        [self addSubview:_repeatButton];

        _lockButton = [UIButton buttonWithType:UIButtonTypeCustom];
53
        [_lockButton setImage:[UIImage imageNamed:@"lock"] forState:UIControlStateNormal];
54
        _lockButton.frame = CGRectMake(spacer, 4. * spacer + buttonHeight * 3., buttonWidth, buttonHeight);
55 56
        [_lockButton addTarget:self action:@selector(lockAction:) forControlEvents:UIControlEventTouchUpInside];
        _lockButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
57 58
        _lockButton.clipsToBounds = YES;
        _lockButton.layer.cornerRadius = buttonWidth / 2;
59
        [self addSubview:_lockButton];
Soomin Lee's avatar
Soomin Lee committed
60 61 62 63 64 65

        _shuffleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_shuffleButton setImage:[UIImage imageNamed:@"shuffle"] forState:UIControlStateNormal];
        _shuffleButton.frame = CGRectMake(spacer, spacer * 3 + buttonHeight * 3, buttonWidth, buttonHeight);
        [_shuffleButton addTarget:self action:@selector(shuffleAction:) forControlEvents:UIControlEventTouchUpInside];
        _shuffleButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
66 67
        _shuffleButton.clipsToBounds = YES;
        _shuffleButton.layer.cornerRadius = buttonWidth / 2;
Soomin Lee's avatar
Soomin Lee committed
68
        [self addSubview:_shuffleButton];
69 70 71 72 73 74 75 76 77 78 79 80 81 82
    }
    return self;
}

- (CGSize)proposedDisplaySize
{
    _equalizerButton.hidden = !_showsEqualizer;
    _chapterSelectorButton.hidden = !_mediaHasChapters;

    CGFloat height;
    CGRect workFrame;

    if (_showsEqualizer) {
        if (_mediaHasChapters) {
83
            height = 6. * spacer + 5. * buttonHeight;
84 85 86 87 88 89 90 91 92 93 94
            workFrame = _equalizerButton.frame;
            workFrame.origin.y = spacer;
            _equalizerButton.frame = workFrame;
            _equalizerButton.hidden = NO;
            workFrame = _chapterSelectorButton.frame;
            workFrame.origin.y = spacer * 2. + buttonHeight;
            _chapterSelectorButton.frame = workFrame;
            _chapterSelectorButton.hidden = NO;
            workFrame = _repeatButton.frame;
            workFrame.origin.y = spacer * 3. + buttonHeight * 2.;
            _repeatButton.frame = workFrame;
95
            workFrame = _lockButton.frame;
96
            workFrame.origin.y = spacer * 4. + buttonHeight * 3.;
97
            _lockButton.frame = workFrame;
Soomin Lee's avatar
Soomin Lee committed
98 99 100
            workFrame = _shuffleButton.frame;
            workFrame.origin.y = spacer * 5. + buttonHeight * 4.;
            _shuffleButton.frame = workFrame;
101
        } else {
Soomin Lee's avatar
Soomin Lee committed
102
            height = 5. * spacer + 4. * buttonHeight;
103 104 105 106 107 108 109 110
            workFrame = _equalizerButton.frame;
            workFrame.origin.y = spacer;
            _equalizerButton.frame = workFrame;
            _equalizerButton.hidden = NO;
            _chapterSelectorButton.hidden = YES;
            workFrame = _repeatButton.frame;
            workFrame.origin.y = spacer * 2. + buttonHeight;
            _repeatButton.frame = workFrame;
111
            workFrame = _lockButton.frame;
112
            workFrame.origin.y = spacer * 3. + buttonHeight * 2.;
113
            _lockButton.frame = workFrame;
Soomin Lee's avatar
Soomin Lee committed
114 115 116
            workFrame = _shuffleButton.frame;
            workFrame.origin.y = spacer * 4. + buttonHeight * 3;
            _shuffleButton.frame = workFrame;
117 118 119
        }
    } else {
        if (_mediaHasChapters) {
Soomin Lee's avatar
Soomin Lee committed
120
            height = 5. * spacer + 4. * buttonHeight;
121 122 123 124 125 126 127 128 129
            _equalizerButton.hidden = YES;
            workFrame = _chapterSelectorButton.frame;
            workFrame.origin.y = spacer;
            _chapterSelectorButton.frame = workFrame;
            _chapterSelectorButton.hidden = NO;
            workFrame = _repeatButton.frame;
            workFrame.origin.y = spacer * 2. + buttonHeight;
            _repeatButton.frame = workFrame;
            workFrame = _lockButton.frame;
130
            workFrame.origin.y = spacer * 3. + buttonHeight * 2.;
131
            _lockButton.frame = workFrame;
Soomin Lee's avatar
Soomin Lee committed
132 133 134
            workFrame = _shuffleButton.frame;
            workFrame.origin.y = spacer * 4. + buttonHeight * 3;
            _shuffleButton.frame = workFrame;
135
        } else {
Soomin Lee's avatar
Soomin Lee committed
136
            height = 4. * spacer + 3. * buttonHeight;
137 138 139 140 141
            _equalizerButton.hidden = YES;
            _chapterSelectorButton.hidden = YES;
            workFrame = _repeatButton.frame;
            workFrame.origin.y = spacer;
            _repeatButton.frame = workFrame;
142
            workFrame = _lockButton.frame;
143
            workFrame.origin.y = spacer * 2. + buttonHeight;
144
            _lockButton.frame = workFrame;
Soomin Lee's avatar
Soomin Lee committed
145 146 147
            workFrame = _shuffleButton.frame;
            workFrame.origin.y = spacer * 3. + buttonHeight * 2;
            _shuffleButton.frame = workFrame;
148 149 150 151 152 153
        }
    }

    return CGSizeMake(spacer + buttonWidth + spacer, height);
}

Tobias's avatar
Tobias committed
154
- (void)setRepeatMode:(VLCRepeatMode)repeatMode
155
{
Tobias's avatar
Tobias committed
156 157 158 159 160 161
    _repeatMode = repeatMode;
    switch (repeatMode) {
        case VLCRepeatCurrentItem:
            [_repeatButton setImage:[UIImage imageNamed:@"repeatOne"] forState:UIControlStateNormal];
            break;
        case VLCRepeatAllItems:
162
            [_repeatButton setImage:[UIImage imageNamed:@"repeat"] forState:UIControlStateNormal];
Tobias's avatar
Tobias committed
163 164 165
            break;
        case VLCDoNotRepeat:
        default:
166
            [_repeatButton setImage:[UIImage imageNamed:@"no-repeat"] forState:UIControlStateNormal];
Tobias's avatar
Tobias committed
167 168
            break;
    }
169 170
}

171 172 173 174 175 176 177 178
- (void)setDisplayLock:(BOOL)displayLock
{
    if (displayLock)
        [_lockButton setBackgroundColor:[UIColor VLCOrangeTintColor]];
    else
        [_lockButton setBackgroundColor:[UIColor clearColor]];
}

Soomin Lee's avatar
Soomin Lee committed
179 180 181 182 183 184 185 186
- (void)setShuffleMode:(BOOL)shuffleMode
{
    if (shuffleMode)
        [_shuffleButton setBackgroundColor:[UIColor VLCOrangeTintColor]];
    else
        [_shuffleButton setBackgroundColor:[UIColor clearColor]];
}

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
- (void)equalizerAction:(id)sender
{
    [self.delegate toggleEqualizer];
    [self.delegate hideMenu];
}

- (void)chapterSelectorAction:(id)sender
{
    [self.delegate toggleChapterAndTitleSelector];
    [self.delegate hideMenu];
}

- (void)repeatAction:(id)sender
{
    [self.delegate toggleRepeatMode];
}

- (void)lockAction:(id)sender
{
    [self.delegate toggleUILock];
}

Soomin Lee's avatar
Soomin Lee committed
209 210 211 212 213
- (void)shuffleAction:(id)sender
{
    [self.delegate toggleShuffleMode];
}

214
@end