Commit c3a3b436 authored by Pierre SAGASPE's avatar Pierre SAGASPE Committed by Felix Paul Kühne
Browse files

Plex:add swipe gesture direction right to mark watched or un-watched a media


Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent e266e4ad
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -145,6 +145,9 @@
[cell setIconURL:[NSURL URLWithString:thumbPath]];
if ([[[ObjList objectAtIndex:indexPath.row] objectForKey:@"container"] isEqualToString:@"item"]) {
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGestureAction:)];
[swipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
[cell addGestureRecognizer:swipeRight];
NSInteger size = [[[ObjList objectAtIndex:indexPath.row] objectForKey:@"size"] integerValue];
NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
NSString *durationInSeconds = [[ObjList objectAtIndex:indexPath.row] objectForKey:@"duration"];
......@@ -242,6 +245,40 @@
return FileSubtitlePath;
}
- (void)swipeRightGestureAction:(UIGestureRecognizer *)recognizer
{
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]];
UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[[self tableView] cellForRowAtIndexPath:swipedIndexPath];
NSMutableArray *ObjList = [[NSMutableArray alloc] init];
[ObjList removeAllObjects];
[ObjList addObject:_mutableObjectList[[self.tableView indexPathForCell:swipedCell].row]];
NSString *ratingKey = [[ObjList objectAtIndex:0] objectForKey:@"ratingKey"];
NSString *tag = [[ObjList objectAtIndex:0] objectForKey:@"state"];
NSString *cellStatusLbl = nil;
NSInteger status = [_PlexParser MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag];
if (status == 200) {
if ([tag isEqualToString:@"watched"]) {
tag = @"unwatched";
cellStatusLbl = NSLocalizedString(@"PLEX_UNWATCHED", @"");
} else if ([tag isEqualToString:@"unwatched"]) {
tag = @"watched";
cellStatusLbl = NSLocalizedString(@"PLEX_WATCHED", @"");
}
} else
cellStatusLbl = NSLocalizedString(@"PLEX_ERROR_MARK", @"");
[cell.statusLabel showStatusMessage:cellStatusLbl];
[[_mutableObjectList objectAtIndex:[self.tableView indexPathForCell:swipedCell].row] setObject:tag forKey:@"state"];
}
#pragma mark - VLCLocalNetworkListCell delegation
- (void)triggerDownloadForCell:(VLCLocalNetworkListCell *)cell
......
......@@ -13,5 +13,6 @@
@interface VLCPlexParser : NSObject
- (NSMutableArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)navPath;
- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state;
@end
......@@ -65,6 +65,12 @@
[_dicoInfo setObject:@"item" forKey:@"container"];
[_dicoInfo setObject:[attributeDict objectForKey:@"key"] forKey:@"key"];
[_dicoInfo setObject:[attributeDict objectForKey:@"title"] forKey:@"title"];
[_dicoInfo setObject:[attributeDict objectForKey:@"ratingKey"] forKey:@"ratingKey"];
if([attributeDict objectForKey:@"viewCount"])
[_dicoInfo setObject:@"watched" forKey:@"state"];
else
[_dicoInfo setObject:@"unwatched" forKey:@"state"];
} else if([elementName isEqualToString:@"Part"]) {
[_dicoInfo setObject:[NSString stringWithFormat:@"%@%@",_PlexMediaServerUrl, [attributeDict objectForKey:@"key"]] forKey:@"keyMedia"];
if([attributeDict objectForKey:@"file"])
......@@ -94,6 +100,28 @@
}
}
- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state
{
NSString *url = nil;
if ([state isEqualToString:@"watched"])
url = [NSString stringWithFormat:@"http://%@%@/:/unscrobble?identifier=com.plexapp.plugins.library&key=%@", adress, port, ratingKey];
else
url = [NSString stringWithFormat:@"http://%@%@/:/scrobble?identifier=com.plexapp.plugins.library&key=%@", adress, port, ratingKey];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:20];
NSURLResponse *response = nil;
NSError *error = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSInteger httpStatus = [(NSHTTPURLResponse *)response statusCode];
if (httpStatus != 200)
APLog(@"Mark Watched Unwatched Media Error status: %ld at URL : %@", (long)httpStatus, url);
return httpStatus;
}
- (NSString *)timeFormatted:(int)mSeconds
{
mSeconds = (int)(mSeconds / 1000);
......
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