Commit 7a070806 authored by Adam Viaud's avatar Adam Viaud Committed by Felix Paul Kühne

Renaming item in the Network Stream panel, rev2

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 8f3e9f5d
......@@ -67,6 +67,7 @@
#define kVLCShowRemainingTime @"show-remaining-time"
#define kVLCRecentURLs @"recent-urls"
#define kVLCRecentURLTitles @"recent-url-titles"
#define kVLCPrivateWebStreaming @"private-streaming"
#define kVLChttpScanSubtitle @"http-scan-subtitle"
......
......@@ -8,7 +8,7 @@
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
* Gleb Pinigin <gpinigin # gmail.com>
* Pierre Sagaspe <pierre.sagaspe # me.com>
*
* Adam Viaud <mcnight # mcnight.fr>
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
......@@ -16,11 +16,13 @@
#import "VLCPlaybackController.h"
#import "VLCLibraryViewController.h"
#import "VLCMenuTableViewController.h"
#import "VLCStreamingHistoryCell.h"
#import "UIDevice+VLC.h"
@interface VLCOpenNetworkStreamViewController () <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>
@interface VLCOpenNetworkStreamViewController () <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UIAlertViewDelegate, VLCStreamingHistoryCellMenuItemProtocol>
{
NSMutableArray *_recentURLs;
NSMutableDictionary *_recentURLTitles;
}
@end
......@@ -30,7 +32,7 @@
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = @{kVLCRecentURLs : @[], kVLCPrivateWebStreaming : @(NO)};
NSDictionary *appDefaults = @{kVLCRecentURLs : @[], kVLCRecentURLTitles : @{}, kVLCPrivateWebStreaming : @(NO)};
[defaults registerDefaults:appDefaults];
}
......@@ -44,6 +46,7 @@
{
/* TODO: don't blindly trust that the Cloud knows best */
_recentURLs = [NSMutableArray arrayWithArray:[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:kVLCRecentURLs]];
_recentURLTitles = [NSMutableDictionary dictionaryWithDictionary:[[NSUbiquitousKeyValueStore defaultStore] dictionaryForKey:kVLCRecentURLTitles]];
[self.historyTableView reloadData];
}
......@@ -68,6 +71,7 @@
/* fetch data from cloud */
_recentURLs = [NSMutableArray arrayWithArray:[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:kVLCRecentURLs]];
_recentURLTitles = [NSMutableDictionary dictionaryWithDictionary:[[NSUbiquitousKeyValueStore defaultStore] dictionaryForKey:kVLCRecentURLTitles]];
/* merge data from local storage (aka legacy VLC versions) */
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
......@@ -111,6 +115,14 @@
// This will be called every time this VC is opened by the side menu controller
[self updatePasteboardTextInURLField];
// Registering a custom menu item for renaming streams
NSString *renameTitle = NSLocalizedString(@"BUTTON_RENAME", nil);
SEL renameStreamSelector = @selector(renameStream:);
UIMenuItem *renameItem = [[UIMenuItem alloc] initWithTitle:renameTitle action:renameStreamSelector];
UIMenuController *sharedMenuController = [UIMenuController sharedMenuController];
[sharedMenuController setMenuItems:@[renameItem]];
[sharedMenuController update];
}
- (void)updatePasteboardTextInURLField
......@@ -185,6 +197,69 @@
}
}
- (void)renameStreamFromCell:(UITableViewCell *)cell {
NSIndexPath *cellIndexPath = [self.historyTableView indexPathForCell:cell];
NSString *renameString = NSLocalizedString(@"BUTTON_RENAME", nil);
NSString *cancelString = NSLocalizedString(@"BUTTON_CANCEL", nil);
if ([UIAlertController class])
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:renameString
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelString
style:UIAlertActionStyleCancel
handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *streamTitle = alertController.textFields.firstObject.text;
[self renameStreamWithTitle:streamTitle atIndex:cellIndexPath.row];
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.text = cell.textLabel.text;
[[NSNotificationCenter defaultCenter] addObserverForName:UITextFieldTextDidChangeNotification
object:textField
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull note) {
okAction.enabled = (textField.text.length != 0);
}];
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
alertView.title = renameString;
alertView.tag = cellIndexPath.row; // Dirty...
[alertView addButtonWithTitle:cancelString];
[alertView addButtonWithTitle:@"OK"];
[alertView show];
}
}
- (void)renameStreamWithTitle:(NSString *)title atIndex:(NSInteger)index {
[_recentURLTitles setObject:title forKey:[@(index) stringValue]];
[[NSUbiquitousKeyValueStore defaultStore] setDictionary:_recentURLTitles forKey:kVLCRecentURLTitles];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self.historyTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
}
#pragma mark - alert view delegate (iOS 7)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *streamTitle = [alertView textFieldAtIndex:0].text;
[self renameStreamWithTitle:streamTitle atIndex:alertView.tag]; // Dirty...
}
#pragma mark - table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
......@@ -200,18 +275,18 @@
{
static NSString *CellIdentifier = @"StreamingHistoryCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
VLCStreamingHistoryCell *cell = (VLCStreamingHistoryCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.highlightedTextColor = [UIColor blackColor];
cell.detailTextLabel.textColor = [UIColor VLCLightTextColor];
cell.detailTextLabel.highlightedTextColor = [UIColor blackColor];
cell = [[VLCStreamingHistoryCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.delegate = self;
[cell customizeAppearance];
}
NSString *content = [_recentURLs[indexPath.row] stringByRemovingPercentEncoding];
cell.textLabel.text = [content lastPathComponent];
NSString *possibleTitle = _recentURLTitles[[@(indexPath.row) stringValue]];
cell.detailTextLabel.text = content;
cell.textLabel.text = (possibleTitle != nil) ? possibleTitle : [content lastPathComponent];
return cell;
}
......@@ -232,7 +307,9 @@
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_recentURLs removeObjectAtIndex:indexPath.row];
[_recentURLTitles removeObjectForKey:@(indexPath.row)];
[[NSUbiquitousKeyValueStore defaultStore] setArray:_recentURLs forKey:kVLCRecentURLs];
[[NSUbiquitousKeyValueStore defaultStore] setDictionary:_recentURLTitles forKey:kVLCRecentURLTitles];
[tableView reloadData];
}
}
......
/*****************************************************************************
* VLCStreamingHistoryCell.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2016 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Adam Viaud <mcnight # mcnight.fr>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <UIKit/UIKit.h>
@protocol VLCStreamingHistoryCellMenuItemProtocol
- (void)renameStreamFromCell:(UITableViewCell *)cell;
@end
@interface VLCStreamingHistoryCell : UITableViewCell
@property (weak, nonatomic) id<VLCStreamingHistoryCellMenuItemProtocol> delegate;
- (void)customizeAppearance;
@end
/*****************************************************************************
* VLCStreamingHistoryCell.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2016 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Adam Viaud <mcnight # mcnight.fr>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCStreamingHistoryCell.h"
@implementation VLCStreamingHistoryCell
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
return (action == @selector(copy:) || action == @selector(renameStream:)) || [super canPerformAction:action withSender:sender];
}
- (void)customizeAppearance {
UIColor *blackColor = [UIColor blackColor];
self.textLabel.textColor = [UIColor whiteColor];
self.textLabel.highlightedTextColor = blackColor;
self.detailTextLabel.textColor = [UIColor VLCLightTextColor];
self.detailTextLabel.highlightedTextColor = blackColor;
}
- (void)renameStream:(id)sender {
[self.delegate renameStreamFromCell:self];
}
@end
......@@ -454,6 +454,8 @@
CC1BBC56170493C100A20CBF /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC1BBC55170493C100A20CBF /* QuartzCore.framework */; };
CC1BBC58170493E100A20CBF /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC1BBC57170493E100A20CBF /* CoreData.framework */; };
CCE2A22E17A5859E00D9EAAD /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCE2A22D17A5859E00D9EAAD /* CoreText.framework */; };
D6E034ED1CC284FC0037F516 /* VLCStreamingHistoryCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D6E034EC1CC284FC0037F516 /* VLCStreamingHistoryCell.m */; };
D6E034F71CC287760037F516 /* VLCStreamingHistoryCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D6E034EC1CC284FC0037F516 /* VLCStreamingHistoryCell.m */; };
D9C52A9E9D4D5AFA7EF1B45A /* libPods-vlc-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DAF8927B0BE9C328466C0EA7 /* libPods-vlc-ios.a */; };
DD13A37B1BEE2FAA00A35554 /* VLCMaskView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD13A37A1BEE2FAA00A35554 /* VLCMaskView.m */; };
DD1A45FD1B676BAC00086F57 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = DDE1BCE41B676B8800A4B9CE /* Localizable.strings */; };
......@@ -1189,6 +1191,8 @@
CC87148317A56C85003C7383 /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; lineEnding = 0; name = ca; path = ca.lproj/Localizable.strings; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.simpleColoring; };
CCAF837E17DE46D800E3578F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
CCE2A22D17A5859E00D9EAAD /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; };
D6E034EB1CC284FC0037F516 /* VLCStreamingHistoryCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCStreamingHistoryCell.h; path = Sources/VLCStreamingHistoryCell.h; sourceTree = SOURCE_ROOT; };
D6E034EC1CC284FC0037F516 /* VLCStreamingHistoryCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCStreamingHistoryCell.m; path = Sources/VLCStreamingHistoryCell.m; sourceTree = SOURCE_ROOT; };
DAF8927B0BE9C328466C0EA7 /* libPods-vlc-ios.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-vlc-ios.a"; sourceTree = BUILT_PRODUCTS_DIR; };
DD13A3791BEE2FAA00A35554 /* VLCMaskView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCMaskView.h; path = "UI Elements/VLCMaskView.h"; sourceTree = "<group>"; };
DD13A37A1BEE2FAA00A35554 /* VLCMaskView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCMaskView.m; path = "UI Elements/VLCMaskView.m"; sourceTree = "<group>"; };
......@@ -2320,6 +2324,8 @@
children = (
7D30F3C5183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.h */,
7D30F3C6183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.m */,
D6E034EB1CC284FC0037F516 /* VLCStreamingHistoryCell.h */,
D6E034EC1CC284FC0037F516 /* VLCStreamingHistoryCell.m */,
7D30F3C8183AB27A00FFC021 /* VLCDownloadViewController.h */,
7D30F3C9183AB27A00FFC021 /* VLCDownloadViewController.m */,
);
......@@ -3455,6 +3461,7 @@
4171D35818A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.m in Sources */,
DD3EFF391BDEBCE500B68579 /* VLCLocalNetworkServiceVLCMedia.m in Sources */,
DD3EFF5D1BDEBCE500B68579 /* VLCLocalServerDiscoveryController.m in Sources */,
D6E034ED1CC284FC0037F516 /* VLCStreamingHistoryCell.m in Sources */,
7DC19B0C1868D21800810BF7 /* VLCFirstStepsSixthPageViewController.m in Sources */,
DD3EFEED1BDEBA3800B68579 /* VLCNetworkServerBrowserViewController.m in Sources */,
DD3EABFC1BE14C4B003668DA /* UIViewController+VLCAlert.m in Sources */,
......@@ -3577,6 +3584,7 @@
7DC54FB51C046615007B4E42 /* LXReorderableCollectionViewFlowLayout.m in Sources */,
7DC54FB61C046615007B4E42 /* VLCLocalNetworkServiceVLCMedia.m in Sources */,
7DC54FB71C046615007B4E42 /* VLCLocalServerDiscoveryController.m in Sources */,
D6E034F71CC287760037F516 /* VLCStreamingHistoryCell.m in Sources */,
7DC54FB81C046615007B4E42 /* VLCFirstStepsSixthPageViewController.m in Sources */,
7DC54FB91C046615007B4E42 /* VLCNetworkServerBrowserViewController.m in Sources */,
7DC54FBA1C046615007B4E42 /* UIViewController+VLCAlert.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment