Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
VLC-iOS
Commits
0f9f63e9
Commit
0f9f63e9
authored
Mar 08, 2014
by
Felix Paul Kühne
Browse files
generalize thumbnail clustering code to also use it with TV shows
parent
f3dd4f66
Changes
4
Hide whitespace changes
Inline
Side-by-side
Sources/VLCPlaylistCollectionViewCell.m
View file @
0f9f63e9
...
...
@@ -166,8 +166,7 @@
[
self
_configureForShow
:
mediaObject
];
if
([
keyPath
isEqualToString
:
@"computedThumbnail"
]
||
!
keyPath
||
(
!
self
.
thumbnailView
.
image
&&
[
keyPath
isEqualToString
:
@"editing"
]))
{
MLFile
*
anyFileFromAnyEpisode
=
[
mediaObject
.
episodes
.
anyObject
files
].
anyObject
;
self
.
thumbnailView
.
image
=
[
VLCThumbnailsCache
thumbnailForMediaFile
:
anyFileFromAnyEpisode
];
self
.
thumbnailView
.
image
=
[
VLCThumbnailsCache
thumbnailForShow
:
mediaObject
];
}
}
else
if
([
self
.
mediaObject
isKindOfClass
:[
MLShowEpisode
class
]])
{
MLShowEpisode
*
mediaObject
=
(
MLShowEpisode
*
)
self
.
mediaObject
;
...
...
Sources/VLCPlaylistTableViewCell.m
View file @
0f9f63e9
...
...
@@ -125,8 +125,7 @@
[
self
_configureForShow
:
mediaObject
];
if
([
keyPath
isEqualToString
:
@"computedThumbnail"
]
||
!
keyPath
||
(
!
self
.
thumbnailView
.
image
&&
[
keyPath
isEqualToString
:
@"editing"
]))
{
MLFile
*
anyFileFromAnyEpisode
=
[
mediaObject
.
episodes
.
anyObject
files
].
anyObject
;
self
.
thumbnailView
.
image
=
[
VLCThumbnailsCache
thumbnailForMediaFile
:
anyFileFromAnyEpisode
];
self
.
thumbnailView
.
image
=
[
VLCThumbnailsCache
thumbnailForShow
:
mediaObject
];
}
}
else
if
([
self
.
mediaObject
isKindOfClass
:[
MLShowEpisode
class
]])
{
MLShowEpisode
*
mediaObject
=
(
MLShowEpisode
*
)
self
.
mediaObject
;
...
...
Sources/VLCThumbnailsCache.h
View file @
0f9f63e9
...
...
@@ -19,6 +19,7 @@
+
(
UIImage
*
)
thumbnailForMediaItemWithTitle
:(
NSString
*
)
title
Artist
:(
NSString
*
)
artist
andAlbumName
:(
NSString
*
)
albumname
;
+
(
UIImage
*
)
thumbnailForShow
:(
MLShow
*
)
mediaShow
;
+
(
UIImage
*
)
thumbnailForLabel
:(
MLLabel
*
)
mediaLabel
;
@end
Sources/VLCThumbnailsCache.m
View file @
0f9f63e9
...
...
@@ -102,6 +102,28 @@ static NSCache *_thumbnailCache;
return
displayedImage
;
}
+
(
UIImage
*
)
thumbnailForShow
:
(
MLShow
*
)
mediaShow
{
NSManagedObjectID
*
objID
=
mediaShow
.
objectID
;
UIImage
*
displayedImage
=
[
_thumbnailCache
objectForKey
:
objID
];
if
(
displayedImage
)
return
displayedImage
;
NSUInteger
count
=
[
mediaShow
.
episodes
count
];
NSUInteger
fileNumber
=
count
>
3
?
3
:
count
;
NSArray
*
episodes
=
[
mediaShow
.
episodes
allObjects
];
NSMutableArray
*
files
=
[[
NSMutableArray
alloc
]
init
];
for
(
NSUInteger
x
=
0
;
x
<
count
;
x
++
)
[
files
addObject
:[
episodes
[
x
]
files
].
anyObject
];
displayedImage
=
[
self
clusterThumbFromFiles
:
files
andNumber
:
fileNumber
];
if
(
displayedImage
)
[
_thumbnailCache
setObject
:
displayedImage
forKey
:
objID
];
return
displayedImage
;
}
+
(
UIImage
*
)
thumbnailForLabel
:
(
MLLabel
*
)
mediaLabel
{
NSManagedObjectID
*
objID
=
mediaLabel
.
objectID
;
...
...
@@ -110,9 +132,19 @@ static NSCache *_thumbnailCache;
if
(
displayedImage
)
return
displayedImage
;
NSUInteger
fileNumber
=
[
mediaLabel
.
files
count
]
>
3
?
3
:
[
mediaLabel
.
files
count
];
NSUInteger
count
=
[
mediaLabel
.
files
count
];
NSUInteger
fileNumber
=
count
>
3
?
3
:
count
;
NSArray
*
files
=
[
mediaLabel
.
files
allObjects
];
displayedImage
=
[
self
clusterThumbFromFiles
:
files
andNumber
:
fileNumber
];
if
(
displayedImage
)
[
_thumbnailCache
setObject
:
displayedImage
forKey
:
objID
];
return
displayedImage
;
}
+
(
UIImage
*
)
clusterThumbFromFiles
:
(
NSArray
*
)
files
andNumber
:
(
NSUInteger
)
fileNumber
{
UIImage
*
clusterThumb
;
CGSize
imageSize
;
if
(
UI_USER_INTERFACE_IDIOM
()
==
UIUserInterfaceIdiomPad
)
{
if
([
UIScreen
mainScreen
].
scale
==
2
.
0
)
...
...
@@ -133,7 +165,7 @@ static NSCache *_thumbnailCache;
UIGraphicsBeginImageContext
(
imageSize
);
for
(
NSUInteger
i
=
0
;
i
<
fileNumber
;
i
++
)
{
MLFile
*
file
=
[
files
objectAtIndex
:
i
];
displayedImage
=
[
VLCThumbnailsCache
thumbnailForMediaFile
:
file
];
clusterThumb
=
[
VLCThumbnailsCache
thumbnailForMediaFile
:
file
];
CGContextRef
context
=
UIGraphicsGetCurrentContext
();
CGFloat
imagePartWidth
=
(
imageSize
.
width
/
fileNumber
);
//the rect in which the image should be drawn
...
...
@@ -144,16 +176,14 @@ static NSCache *_thumbnailCache;
CGFloat
centerOffset
=
(
imagePartWidth
*
i
+
imagePartWidth
/
2
)
-
imageSize
.
width
/
2
;
//shift the rect to draw the middle of the image in the clippingrect
CGRect
drawingRect
=
CGRectMake
(
centerOffset
,
0
,
imageSize
.
width
,
imageSize
.
height
);
[
displayedImage
drawInRect
:
drawingRect
];
[
clusterThumb
drawInRect
:
drawingRect
];
//get rid of the old clippingRect
CGContextRestoreGState
(
context
);
}
displayedImage
=
UIGraphicsGetImageFromCurrentImageContext
();
clusterThumb
=
UIGraphicsGetImageFromCurrentImageContext
();
UIGraphicsEndImageContext
();
[
_thumbnailCache
setObject
:
displayedImage
forKey
:
objID
];
return
displayedImage
;
return
clusterThumb
;
}
@end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment