Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Rework playlist progressbar #1226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
43 changes: 27 additions & 16 deletions XBMC Remote/NowPlaying.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ @implementation NowPlaying

#define HMS_TO_STRING(h, m, s) [NSString stringWithFormat:@"%@%02i:%02i", (totalSeconds < 3600) ? @"" : [NSString stringWithFormat:@"%02i:", h], m, s];

#define MAX_CELLBAR_WIDTH 45
#define PARTYBUTTON_PADDING_LEFT 0
#define PROGRESSBAR_PADDING_LEFT 20
#define PROGRESSBAR_PADDING_BOTTOM 80
Expand Down Expand Up @@ -83,6 +82,7 @@ @implementation NowPlaying
#define XIB_PLAYLIST_CELL_ACTUALTIME 6
#define XIB_PLAYLIST_CELL_PROGRESSBAR 7
#define XIB_PLAYLIST_CELL_ACTIVTYINDICATOR 8
#define XIB_PLAYLIST_CELL_PROGRESSBAR_MASK 9

- (void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
Expand Down Expand Up @@ -246,18 +246,6 @@ - (UIImage*)loadImageFromName:(NSString*)imageName {
return image;
}

- (void)resizeCellBar:(CGFloat)width image:(UIImageView*)cellBarImage {
NSTimeInterval time = (width == 0) ? 0.1 : 1.0;
width = MIN(width, MAX_CELLBAR_WIDTH);
[UIView animateWithDuration:time
animations:^{
CGRect frame;
frame = cellBarImage.frame;
frame.size.width = width;
cellBarImage.frame = frame;
}];
}

- (IBAction)togglePartyMode:(id)sender {
if (AppDelegate.instance.serverVersion == 11) {
storedItemID = SELECTED_NONE;
Expand Down Expand Up @@ -1255,6 +1243,18 @@ - (void)createPlaylistAnimated:(BOOL)animTable {
}];
}

- (void)initPlaylistProgressbar:(UITableViewCell*)cell {
UIImageView *playlistProgressbarMask = (UIImageView*)[cell viewWithTag:XIB_PLAYLIST_CELL_PROGRESSBAR_MASK];
playlistProgressbarMask.layer.cornerRadius = 2;
playlistProgressbarMask.clipsToBounds = YES;

UIImageView *playlistProgressbar = (UIImageView*)[cell viewWithTag:XIB_PLAYLIST_CELL_PROGRESSBAR];
playlistProgressbar.backgroundColor = KODI_BLUE_COLOR;
CGRect frame = playlistProgressbar.frame;
frame.size.width = 0;
playlistProgressbar.frame = frame;
}

- (void)updatePlaylistProgressbar:(float)percentage actual:(NSString*)actualTime {
NSIndexPath *selection = [playlistTableView indexPathForSelectedRow];
if (!selection) {
Expand All @@ -1263,9 +1263,18 @@ - (void)updatePlaylistProgressbar:(float)percentage actual:(NSString*)actualTime
UITableViewCell *cell = [playlistTableView cellForRowAtIndexPath:selection];
UILabel *playlistActualTime = (UILabel*)[cell viewWithTag:XIB_PLAYLIST_CELL_ACTUALTIME];
playlistActualTime.text = actualTime;
UIImageView *playlistActualBar = (UIImageView*)[cell viewWithTag:XIB_PLAYLIST_CELL_PROGRESSBAR];
CGFloat newx = MAX(MAX_CELLBAR_WIDTH * percentage / 100.0, 1.0);
[self resizeCellBar:newx image:playlistActualBar];

UIImageView *playlistProgressbarMask = (UIImageView*)[cell viewWithTag:XIB_PLAYLIST_CELL_PROGRESSBAR_MASK];
UIImageView *playlistProgressbar = (UIImageView*)[cell viewWithTag:XIB_PLAYLIST_CELL_PROGRESSBAR];
CGFloat newWidth = CGRectGetWidth(playlistProgressbarMask.frame) * percentage / 100.0;
NSTimeInterval barAnimationTime = (CGRectGetWidth(playlistProgressbar.frame) == 0 && newWidth > 0) ? 0.5 : 0.0;
[UIView animateWithDuration:barAnimationTime
animations:^{
CGRect frame = playlistProgressbar.frame;
frame.size.width = newWidth;
playlistProgressbar.frame = frame;
}];

[self setPlaylistCellProgressBar:cell hidden:NO];
}

Expand Down Expand Up @@ -2133,6 +2142,8 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
placeholderImage:defaultThumb
options:SDWebImageScaleToNativeSize];
[Utilities applyRoundedEdgesView:thumb];

[self initPlaylistProgressbar:cell];
BOOL active = indexPath.row == lastSelected;
[self setPlaylistCellProgressBar:cell hidden:!active];

Expand Down
49 changes: 25 additions & 24 deletions XBMC Remote/playlistCellView.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -46,33 +47,33 @@
<size key="shadowOffset" width="0.0" height="0.0"/>
</label>
<view hidden="YES" tag="5" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="14" userLabel="currentTime View">
<rect key="frame" x="0.0" y="28" width="53" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<rect key="frame" x="0.0" y="29" width="53" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" alpha="0.60000002384185791" contentMode="scaleToFill" fixedFrame="YES" image="timeBackground" highlightedImage="timeBackground" translatesAutoresizingMaskIntoConstraints="NO" id="13">
<rect key="frame" x="0.0" y="0.0" width="53" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<label clipsSubviews="YES" userInteractionEnabled="NO" alpha="0.89999997615814209" tag="6" contentMode="center" fixedFrame="YES" text="00:00" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="1" translatesAutoresizingMaskIntoConstraints="NO" id="11">
<label clipsSubviews="YES" userInteractionEnabled="NO" tag="6" contentMode="center" fixedFrame="YES" text="00:00" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="1" translatesAutoresizingMaskIntoConstraints="NO" id="11">
<rect key="frame" x="0.0" y="0.0" width="53" height="15"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="shadowColor" red="0.0" green="0.0" blue="0.0" alpha="0.84999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="highlightedColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="shadowColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<size key="shadowOffset" width="1" height="1"/>
</label>
<imageView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" fixedFrame="YES" image="pgbar_inact_fake" translatesAutoresizingMaskIntoConstraints="NO" id="15">
<rect key="frame" x="1" y="8" width="50" height="17"/>
<autoresizingMask key="autoresizingMask"/>
</imageView>
<imageView clipsSubviews="YES" multipleTouchEnabled="YES" tag="7" contentMode="left" fixedFrame="YES" image="pgbar_act" translatesAutoresizingMaskIntoConstraints="NO" id="16">
<rect key="frame" x="4" y="8" width="0.0" height="17"/>
<autoresizingMask key="autoresizingMask" heightSizable="YES"/>
</imageView>
<view clipsSubviews="YES" tag="9" contentMode="scaleToFill" id="Xkx-rr-Plj" userLabel="progressbar_mask">
<rect key="frame" x="4" y="15" width="45" height="6"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<subviews>
<view tag="7" contentMode="scaleToFill" id="K1z-gq-qCO" userLabel="progressbar">
<rect key="frame" x="0.0" y="0.0" width="11" height="6"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</subviews>
<color key="backgroundColor" white="0.13342321165191739" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" white="0.37913670722713866" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<activityIndicatorView hidden="YES" tag="8" contentMode="scaleToFill" fixedFrame="YES" hidesWhenStopped="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="17">
<rect key="frame" x="10" y="7" width="37" height="37"/>
Expand All @@ -87,11 +88,11 @@
</tableViewCell>
</objects>
<resources>
<image name="pgbar_act" width="44" height="17"/>
<image name="pgbar_inact_fake" width="50" height="17"/>
<image name="timeBackground" width="53" height="17"/>
<systemColor name="darkTextColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>