summaryrefslogtreecommitdiff
path: root/ios/iosremote/iosremote/slideShowPreviewTable_vc.m
blob: 1f6a147ab163967ebc037c77e3da4f265646b286 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#import "slideShowPreviewTable_vc.h"
#import "CommunicationManager.h"
#import "CommandTransmitter.h"
#import "CommandInterpreter.h"
#import "ControlVariables.h"
#import "SlideShow.h"

@interface slideShowPreviewTable_vc ()

@property (nonatomic, weak) UIButton * startButton;

@end

@implementation slideShowPreviewTable_vc

@synthesize startButton = _startButton;
@synthesize optionsTable = _optionsTable;
@synthesize optionsArray = _optionsArray;
@synthesize titleObserver = _titleObserver;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return YES;
    else {
        return toInterfaceOrientation == UIInterfaceOrientationMaskPortrait;
    }
}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void) viewDidDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self.slideShowStartObserver];
    self.slideShowStartObserver = nil;
    [super viewDidDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.optionsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"optionCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        UISwitch *toggleSwitch = [[UISwitch alloc] init];
        cell.accessoryView = [[UIView alloc] initWithFrame:toggleSwitch.frame];
        if (indexPath.row == 0) {
            [toggleSwitch setOn:[[NSUserDefaults standardUserDefaults] boolForKey:KEY_TIMER]];
        } else {
            [toggleSwitch setOn:[[NSUserDefaults standardUserDefaults] boolForKey:KEY_POINTER]];
        }
        [cell.accessoryView addSubview:toggleSwitch];
    }
    cell.textLabel.text = [self.optionsArray objectAtIndex:indexPath.row];
    
    return cell;
}


-(IBAction)startPresentationAction:(id)sender {
    for (UITableViewCell *cell in self.tableView.visibleCells) {
        UISwitch * toggle = [[[cell accessoryView] subviews] objectAtIndex:0];

        if ([cell.textLabel.text isEqualToString:OPTION_TIMER])
            [[NSUserDefaults standardUserDefaults] setBool:[toggle isOn] forKey:KEY_TIMER];
        else if ([cell.textLabel.text isEqualToString:OPTION_POINTER])
            [[NSUserDefaults standardUserDefaults] setBool:[toggle isOn] forKey:KEY_POINTER];
    }
    [[self.comManager transmitter] startPresentation];
}

- (UIButton *)startButton{
    if (_startButton == nil) {
        _startButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_startButton setBackgroundImage:[UIImage imageNamed:@"navBarButtonNormal"] forState:UIControlStateNormal];
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
            _startButton.frame = CGRectMake(145.0, 30.0, 160.0, 40.0);
        } else {
            self.modalViewController.view.backgroundColor = [UIColor clearColor];
            _startButton.frame = CGRectMake(30.0, 50.0, 470.0, 40.0);
        }
        [_startButton setTitle:NSLocalizedString(@"Start Presentation", nil) forState:UIControlStateNormal];
        [_startButton setTitleColor:kTintColor forState:UIControlStateNormal];
        [_startButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        [_startButton addTarget:self action:@selector(startPresentationAction:) forControlEvents:UIControlEventTouchUpInside];
        
        UIImage *backgroundImage = [UIImage imageNamed:@"buttonBackground"];
        UIEdgeInsets insets = UIEdgeInsetsMake(20, 7, 20, 7);
        UIImage *stretchableBackgroundImage = [backgroundImage resizableImageWithCapInsets:insets];
        
        [_startButton setBackgroundImage:stretchableBackgroundImage forState:UIControlStateNormal];
        _startButton.tag = 1;
    }
    return _startButton;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* customView;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 100.0)];
    } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 540.0, 100.0)];
    [customView addSubview:self.startButton];
    
    customView.center = CGPointMake(tableView.center.x, customView.center.y);
    self.startButton.center = customView.center;
    return customView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 100.0;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    UISwitch * toggle = [[[cell accessoryView] subviews] objectAtIndex:0];
    [toggle setOn:![toggle isOn] animated:YES];
    [cell setSelected:NO animated:YES];
}

- (void)viewDidUnload {
    [self setOptionsTable:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self.slideShowStartObserver];
    self.slideShowStartObserver = nil;
    [super viewDidUnload];
}
@end