Commit ae706745 authored by Carola's avatar Carola

refactored the wificell and architecture around it

parent c99ba58d
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8164.2" systemVersion="15A226f" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8135.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="WiFiMenuCell" rowHeight="46" id="3" customClass="VLCWiFiUploadTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="260" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="3" id="qYq-WE-nye">
<rect key="frame" x="0.0" y="0.0" width="260" height="49.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="HTTP Upload" textAlignment="justified" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="28">
<rect key="frame" x="50" y="5" width="97.5" height="19.5"/>
<animations/>
<color key="backgroundColor" white="0.17000000000000001" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.76862745099999996" green="0.80000000000000004" blue="0.85490196080000003" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Inactive Server" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="YES" id="30">
<rect key="frame" x="50" y="24" width="97.5" height="24"/>
<animations/>
<color key="backgroundColor" white="0.17000000000000001" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.76862745099999996" green="0.80000000000000004" blue="0.85490196080000003" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="center" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="34">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="50" id="9hp-CX-VG6"/>
<constraint firstAttribute="height" constant="50" id="FWj-TR-Jvt"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" image="WifiUp.png">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
</button>
</subviews>
<animations/>
<constraints>
<constraint firstAttribute="bottomMargin" secondItem="30" secondAttribute="bottom" constant="-3.5" id="2Fr-vF-HgI"/>
<constraint firstItem="34" firstAttribute="top" secondItem="qYq-WE-nye" secondAttribute="topMargin" constant="-8" id="3uj-4T-hgH"/>
<constraint firstItem="28" firstAttribute="leading" secondItem="34" secondAttribute="trailing" id="Tbz-RD-inH"/>
<constraint firstItem="30" firstAttribute="leading" secondItem="34" secondAttribute="trailing" id="mxE-0S-cjg"/>
<constraint firstItem="34" firstAttribute="leading" secondItem="qYq-WE-nye" secondAttribute="leadingMargin" constant="-8" id="u4g-A3-Smq"/>
<constraint firstItem="28" firstAttribute="top" secondItem="qYq-WE-nye" secondAttribute="topMargin" constant="-3" id="xgV-vT-ruF"/>
</constraints>
</tableViewCellContentView>
<animations/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<outlet property="serverOnButton" destination="34" id="36"/>
<outlet property="titleLabel" destination="28" id="32"/>
<outlet property="uploadAddressLabel" destination="30" id="33"/>
</connections>
</tableViewCell>
</objects>
<resources>
<image name="WifiUp.png" width="16" height="29"/>
</resources>
</document>
...@@ -14,16 +14,13 @@ ...@@ -14,16 +14,13 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class HTTPServer;
@interface VLCHTTPUploaderController : NSObject @interface VLCHTTPUploaderController : NSObject
+ (instancetype)sharedInstance; + (instancetype)sharedInstance;
@property (nonatomic, readonly) HTTPServer *httpServer;
- (BOOL)changeHTTPServerState:(BOOL)state; - (BOOL)changeHTTPServerState:(BOOL)state;
- (NSString *)currentIPAddress; - (NSString *)httpStatus;
- (BOOL)isServerRunning;
- (NSString *)hostname; - (NSString *)hostname;
- (void)moveFileFrom:(NSString *)filepath; - (void)moveFileFrom:(NSString *)filepath;
......
...@@ -18,13 +18,21 @@ ...@@ -18,13 +18,21 @@
#import "VLCActivityManager.h" #import "VLCActivityManager.h"
#import "VLCMediaFileDiscoverer.h" #import "VLCMediaFileDiscoverer.h"
#import "HTTPServer.h" #import "HTTPServer.h"
#import "Reachability.h"
#import <ifaddrs.h> #import <ifaddrs.h>
#import <arpa/inet.h> #import <arpa/inet.h>
@interface VLCHTTPUploaderController()
@property(nonatomic, strong) HTTPServer *httpServer;
@end
@implementation VLCHTTPUploaderController @implementation VLCHTTPUploaderController
{ {
UIBackgroundTaskIdentifier _backgroundTaskIdentifier; UIBackgroundTaskIdentifier _backgroundTaskIdentifier;
Reachability *_reachability;
} }
+ (instancetype)sharedInstance + (instancetype)sharedInstance
...@@ -47,11 +55,21 @@ ...@@ -47,11 +55,21 @@
name:UIApplicationDidBecomeActiveNotification object:nil]; name:UIApplicationDidBecomeActiveNotification object:nil];
[center addObserver:self selector:@selector(applicationDidEnterBackground:) [center addObserver:self selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification object:nil]; name:UIApplicationDidEnterBackgroundNotification object:nil];
[center addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
BOOL isHTTPServerOn = [[NSUserDefaults standardUserDefaults] boolForKey:kVLCSettingSaveHTTPUploadServerStatus];
[self changeHTTPServerState:isHTTPServerOn];
} }
return self; return self;
} }
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)applicationDidBecomeActive: (NSNotification *)notification - (void)applicationDidBecomeActive: (NSNotification *)notification
{ {
if (!self.httpServer.isRunning) if (!self.httpServer.isRunning)
...@@ -81,6 +99,31 @@ ...@@ -81,6 +99,31 @@
} }
} }
- (NSString *)httpStatus
{
if (self.httpServer.isRunning) {
if (self.httpServer.listeningPort != 80) {
return [NSString stringWithFormat:@"http://%@:%i\nhttp://%@:%i", [self currentIPAddress], self.httpServer.listeningPort, [self hostname], self.httpServer.listeningPort];
} else {
return [NSString stringWithFormat:@"http://%@\nhttp://%@", [self currentIPAddress], [self hostname]];
}
} else {
return NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
}
}
- (BOOL)isServerRunning
{
return self.httpServer.isRunning;
}
- (void)netReachabilityChanged
{
if (_reachability.currentReachabilityStatus != ReachableViaWiFi) {
[[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:NO];
}
}
- (BOOL)changeHTTPServerState:(BOOL)state - (BOOL)changeHTTPServerState:(BOOL)state
{ {
if (!state) { if (!state) {
......
...@@ -17,12 +17,9 @@ ...@@ -17,12 +17,9 @@
#import "VLCMenuTableViewController.h" #import "VLCMenuTableViewController.h"
#import "VLCSidebarViewCell.h" #import "VLCSidebarViewCell.h"
#import "Reachability.h"
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import "VLCWiFiUploadTableViewCell.h" #import "VLCWiFiUploadTableViewCell.h"
#import "VLCHTTPUploaderController.h"
#import "VLCAppDelegate.h" #import "VLCAppDelegate.h"
#import "HTTPServer.h"
#import "IASKAppSettingsViewController.h" #import "IASKAppSettingsViewController.h"
#import "VLCServerListViewController.h" #import "VLCServerListViewController.h"
#import "VLCOpenNetworkStreamViewController.h" #import "VLCOpenNetworkStreamViewController.h"
...@@ -34,6 +31,10 @@ ...@@ -34,6 +31,10 @@
#import "VLCNavigationController.h" #import "VLCNavigationController.h"
#import "GHRevealViewController.h" #import "GHRevealViewController.h"
#define ROW_HEIGHT 50
static NSString *CellIdentifier = @"VLCMenuCell";
static NSString *WiFiCellIdentifier = @"VLCMenuWiFiCell";
@interface VLCMenuTableViewController () <UITableViewDataSource, UITableViewDelegate> @interface VLCMenuTableViewController () <UITableViewDataSource, UITableViewDelegate>
{ {
NSArray *_sectionHeaderTexts; NSArray *_sectionHeaderTexts;
...@@ -41,10 +42,7 @@ ...@@ -41,10 +42,7 @@
NSArray *_menuItemsSectionTwo; NSArray *_menuItemsSectionTwo;
NSArray *_menuItemsSectionThree; NSArray *_menuItemsSectionThree;
NSMutableSet *_hiddenSettingKeys; NSMutableSet *_hiddenSettingKeys;
UILabel *_uploadLocationLabel;
UIButton *_uploadButton;
Reachability *_reachability;
} }
@end @end
...@@ -53,7 +51,6 @@ ...@@ -53,7 +51,6 @@
- (void)dealloc - (void)dealloc
{ {
[_reachability stopNotifier];
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
} }
...@@ -77,8 +74,9 @@ ...@@ -77,8 +74,9 @@
_tableView.backgroundColor = [UIColor colorWithRed:(43.0f/255.0f) green:(43.0f/255.0f) blue:(43.0f/255.0f) alpha:1.0f]; _tableView.backgroundColor = [UIColor colorWithRed:(43.0f/255.0f) green:(43.0f/255.0f) blue:(43.0f/255.0f) alpha:1.0f];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_tableView.rowHeight = [VLCWiFiUploadTableViewCell heightOfCell]; _tableView.rowHeight = ROW_HEIGHT;
_tableView.scrollsToTop = NO; _tableView.scrollsToTop = NO;
[_tableView registerClass:[VLCWiFiUploadTableViewCell class] forCellReuseIdentifier:WiFiCellIdentifier];
self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds))]; self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds))];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight; self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
...@@ -96,32 +94,12 @@ ...@@ -96,32 +94,12 @@
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop]; [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
_reachability = [Reachability reachabilityForLocalWiFi];
[_reachability startNotifier];
[self netReachabilityChanged:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
BOOL isHTTPServerOn = [[NSUserDefaults standardUserDefaults] boolForKey:kVLCSettingSaveHTTPUploadServerStatus];
[[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:isHTTPServerOn];
[self updateHTTPServerAddress];
} }
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
self.view.frame = CGRectMake(0.0f, 0.0f,kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds)); self.view.frame = CGRectMake(0.0f, 0.0f,kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds));
[self netReachabilityChanged:nil];
}
- (void)netReachabilityChanged:(NSNotification *)notification
{
if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
_uploadButton.enabled = YES;
[self updateHTTPServerAddress];
} else
[self disableButtonHTTPServer];
} }
- (BOOL)shouldAutorotate - (BOOL)shouldAutorotate
...@@ -156,8 +134,6 @@ ...@@ -156,8 +134,6 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
static NSString *CellIdentifier = @"VLCMenuCell";
static NSString *WiFiCellIdentifier = @"VLCMenuWiFiCell";
NSString *rawTitle; NSString *rawTitle;
NSUInteger section = indexPath.section; NSUInteger section = indexPath.section;
...@@ -169,11 +145,8 @@ ...@@ -169,11 +145,8 @@
rawTitle = _menuItemsSectionThree[indexPath.row]; rawTitle = _menuItemsSectionThree[indexPath.row];
UITableViewCell *cell; UITableViewCell *cell;
if ([rawTitle isEqualToString:@"WEBINTF_TITLE"]) { if ([rawTitle isEqualToString:@"WEBINTF_TITLE"]) {
cell = (VLCWiFiUploadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:WiFiCellIdentifier]; cell = (VLCWiFiUploadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:WiFiCellIdentifier];
if (cell == nil)
cell = [VLCWiFiUploadTableViewCell cellWithReuseIdentifier:WiFiCellIdentifier];
} else { } else {
cell = (VLCSidebarViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell = (VLCSidebarViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) if (cell == nil)
...@@ -194,12 +167,7 @@ ...@@ -194,12 +167,7 @@
cell.imageView.image = [UIImage imageNamed:@"OpenNetStream"]; cell.imageView.image = [UIImage imageNamed:@"OpenNetStream"];
else if ([rawTitle isEqualToString:@"DOWNLOAD_FROM_HTTP"]) else if ([rawTitle isEqualToString:@"DOWNLOAD_FROM_HTTP"])
cell.imageView.image = [UIImage imageNamed:@"Downloads"]; cell.imageView.image = [UIImage imageNamed:@"Downloads"];
else if ([rawTitle isEqualToString:@"WEBINTF_TITLE"]) { else if ([rawTitle isEqualToString:@"CLOUD_SERVICES"])
_uploadLocationLabel = [(VLCWiFiUploadTableViewCell*)cell uploadAddressLabel];
_uploadButton = [(VLCWiFiUploadTableViewCell*)cell serverOnButton];
[_uploadButton addTarget:self action:@selector(toggleHTTPServer:) forControlEvents:UIControlEventTouchUpInside];
[self updateHTTPServerAddress];
} else if ([rawTitle isEqualToString:@"CLOUD_SERVICES"])
cell.imageView.image = [UIImage imageNamed:@"iCloudIcon"]; cell.imageView.image = [UIImage imageNamed:@"iCloudIcon"];
} else if (section == 2) { } else if (section == 2) {
if ([rawTitle isEqualToString:@"Settings"]) if ([rawTitle isEqualToString:@"Settings"])
...@@ -252,50 +220,6 @@ ...@@ -252,50 +220,6 @@
#pragma mark - menu implementation #pragma mark - menu implementation
- (void)updateHTTPServerAddress
{
if (_reachability.currentReachabilityStatus == !ReachableViaWiFi)
[self disableButtonHTTPServer];
else {
VLCHTTPUploaderController *uploadController = [VLCHTTPUploaderController sharedInstance];
HTTPServer *server = uploadController.httpServer;
_uploadButton.enabled = YES;
if (server.isRunning) {
_uploadLocationLabel.numberOfLines = 0;
if (server.listeningPort != 80)
_uploadLocationLabel.text = [NSString stringWithFormat:@"http://%@:%i\nhttp://%@:%i", [uploadController currentIPAddress], server.listeningPort, [uploadController hostname], server.listeningPort];
else
_uploadLocationLabel.text = [NSString stringWithFormat:@"http://%@\nhttp://%@", [uploadController currentIPAddress], [uploadController hostname]];
[_uploadButton setImage:[UIImage imageNamed:@"WifiUpOn"] forState:UIControlStateNormal];
} else {
_uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
[_uploadButton setImage:[UIImage imageNamed:@"WifiUp"] forState:UIControlStateNormal];
}
}
}
- (IBAction)toggleHTTPServer:(UIButton *)sender
{
if (_uploadButton.enabled) {
VLCHTTPUploaderController *uploadController = [VLCHTTPUploaderController sharedInstance];
BOOL futureHTTPServerState = !uploadController.httpServer.isRunning;
[[NSUserDefaults standardUserDefaults] setBool:futureHTTPServerState forKey:kVLCSettingSaveHTTPUploadServerStatus];
[uploadController changeHTTPServerState:futureHTTPServerState];
[self updateHTTPServerAddress];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
- (void)disableButtonHTTPServer
{
[_uploadButton setImage:[UIImage imageNamed:@"WifiUp"] forState:UIControlStateNormal];
_uploadButton.enabled = NO;
[_uploadButton setImage:[UIImage imageNamed:@"WiFiUp"] forState:UIControlStateDisabled];
_uploadLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_NO_CONNECTIVITY", nil);
[[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:NO];
}
- (void)_revealItem:(NSUInteger)itemIndex inSection:(NSUInteger)sectionNumber - (void)_revealItem:(NSUInteger)itemIndex inSection:(NSUInteger)sectionNumber
{ {
UIViewController *viewController; UIViewController *viewController;
...@@ -308,7 +232,7 @@ ...@@ -308,7 +232,7 @@
} else if (itemIndex == 2) } else if (itemIndex == 2)
viewController = [VLCDownloadViewController sharedInstance]; viewController = [VLCDownloadViewController sharedInstance];
else if (itemIndex == 3) else if (itemIndex == 3)
[self toggleHTTPServer:nil]; [((VLCWiFiUploadTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:itemIndex inSection:sectionNumber]]) toggleHTTPServer];
else if (itemIndex == 4) else if (itemIndex == 4)
viewController = [[VLCCloudServicesTableViewController alloc] initWithNibName:@"VLCCloudServicesTableViewController" bundle:nil]; viewController = [[VLCCloudServicesTableViewController alloc] initWithNibName:@"VLCCloudServicesTableViewController" bundle:nil];
} else if (sectionNumber == 2) { } else if (sectionNumber == 2) {
......
...@@ -14,11 +14,6 @@ ...@@ -14,11 +14,6 @@
@interface VLCWiFiUploadTableViewCell : UITableViewCell @interface VLCWiFiUploadTableViewCell : UITableViewCell
@property (nonatomic, strong) IBOutlet UILabel *titleLabel; - (void)toggleHTTPServer;
@property (nonatomic, strong) IBOutlet UILabel *uploadAddressLabel;
@property (nonatomic, strong) IBOutlet UIButton *serverOnButton;
+ (VLCWiFiUploadTableViewCell *)cellWithReuseIdentifier:(NSString *)ident;
+ (CGFloat)heightOfCell;
@end @end
...@@ -11,47 +11,121 @@ ...@@ -11,47 +11,121 @@
*****************************************************************************/ *****************************************************************************/
#import "VLCWiFiUploadTableViewCell.h" #import "VLCWiFiUploadTableViewCell.h"
#import "Reachability.h"
#import "VLCHTTPUploaderController.h"
@interface VLCWiFiUploadTableViewCell()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *uploadAddressLabel;
@property (nonatomic, strong) UIButton *serverOnButton;
@property (nonatomic, strong) Reachability *reachability;
@end
@implementation VLCWiFiUploadTableViewCell @implementation VLCWiFiUploadTableViewCell
+ (VLCWiFiUploadTableViewCell *)cellWithReuseIdentifier:(NSString *)ident - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{ {
NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCWiFiUploadTableViewCell" owner:nil options:nil]; self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
NSAssert([nibContentArray count] == 1, @"meh"); if (self) {
NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCWiFiUploadTableViewCell class]], @"meh meh"); [self setupCell];
VLCWiFiUploadTableViewCell *cell = (VLCWiFiUploadTableViewCell *)[nibContentArray lastObject]; [self setupConstraints];
[self updateHTTPServerAddress];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
}
return self;
}
return cell; - (void)dealloc
{
[self.reachability stopNotifier];
[[NSNotificationCenter defaultCenter] removeObserver:self];
} }
- (void)awakeFromNib - (void)setupCell
{ {
self.reachability = [Reachability reachabilityForLocalWiFi];
[self.reachability startNotifier];
self.titleLabel = [UILabel new];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:self.titleLabel];
self.titleLabel.text = NSLocalizedString(@"WEBINTF_TITLE", nil); self.titleLabel.text = NSLocalizedString(@"WEBINTF_TITLE", nil);
self.titleLabel.shadowOffset = CGSizeMake(0.0f, 1.0f); self.titleLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
self.titleLabel.shadowColor = [UIColor VLCDarkTextShadowColor]; self.titleLabel.shadowColor = [UIColor VLCDarkTextShadowColor];
self.titleLabel.textColor = [UIColor whiteColor]; self.titleLabel.textColor = [UIColor whiteColor];
self.titleLabel.font = [UIFont systemFontOfSize:16.0];
self.titleLabel.superview.backgroundColor = [UIColor colorWithRed:(43.0f/255.0f) green:(43.0f/255.0f) blue:(43.0f/255.0f) alpha:1.0f];
[self.titleLabel sizeToFit];
self.clipsToBounds = YES; self.clipsToBounds = YES;
self.backgroundColor = [UIColor clearColor]; self.backgroundColor = [UIColor clearColor];
self.titleLabel.superview.backgroundColor = [UIColor colorWithRed:(43.0f/255.0f) green:(43.0f/255.0f) blue:(43.0f/255.0f) alpha:1.0f]; self.selectionStyle = UITableViewCellSelectionStyleNone;
self.uploadAddressLabel = [UILabel new];
self.uploadAddressLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.uploadAddressLabel.numberOfLines = 0;
[self.contentView addSubview:self.uploadAddressLabel];
self.uploadAddressLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil); self.uploadAddressLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
self.uploadAddressLabel.shadowOffset = CGSizeMake(0.0f, 1.0f); self.uploadAddressLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
self.uploadAddressLabel.shadowColor = [UIColor VLCDarkTextShadowColor]; self.uploadAddressLabel.shadowColor = [UIColor VLCDarkTextShadowColor];
self.uploadAddressLabel.textColor = [UIColor whiteColor]; self.uploadAddressLabel.textColor = [UIColor whiteColor];
self.uploadAddressLabel.font = [UIFont systemFontOfSize:12.0];
[self.uploadAddressLabel sizeToFit];
self.serverOnButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.serverOnButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.serverOnButton addTarget:self action:@selector(toggleHTTPServer) forControlEvents:UIControlEventTouchUpInside];
[self.serverOnButton setImage:[UIImage imageNamed:@"WiFiUp"] forState:UIControlStateDisabled];
[self.contentView addSubview:self.serverOnButton];
UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)]; UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
topLine.backgroundColor = [UIColor colorWithRed:(16.0f/255.0f) green:(16.0f/255.0f) blue:(16.0f/255.0f) alpha:1.0f]; topLine.backgroundColor = [UIColor colorWithRed:(16.0f/255.0f) green:(16.0f/255.0f) blue:(16.0f/255.0f) alpha:1.0f];
[self.titleLabel.superview addSubview:topLine]; [self.contentView addSubview:topLine];
UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 50.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)]; UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 50.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
bottomLine.backgroundColor = [UIColor colorWithRed:(23.0f/255.0f) green:(23.0f/255.0f) blue:(23.0f/255.0f) alpha:1.0f]; bottomLine.backgroundColor = [UIColor colorWithRed:(23.0f/255.0f) green:(23.0f/255.0f) blue:(23.0f/255.0f) alpha:1.0f];
[self.titleLabel.superview addSubview:bottomLine]; [self.contentView addSubview:bottomLine];
}
- (void)setupConstraints
{
NSDictionary *dict = NSDictionaryOfVariableBindings(_titleLabel, _uploadAddressLabel, _serverOnButton);
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_serverOnButton(50)][_titleLabel]" options:0 metrics:0 views:dict]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_serverOnButton(50)][_uploadAddressLabel]" options:0 metrics:0 views:dict]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_serverOnButton(50)]|" options:0 metrics:0 views:dict]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_uploadAddressLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_titleLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]];
}
- (void)netReachabilityChanged