mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-28 21:55:27 +00:00
ios: Some cover view improvements:
Don't allocate new views when reusing a cell. If a file item doesn't have an attached image, its filename will be printed in the cell instead. Images maintain aspect ratio when scaled.
This commit is contained in:
parent
cae85b7401
commit
1212116dfb
@ -39,8 +39,10 @@
|
||||
|
||||
self.navigationItem.rightBarButtonItem = [RetroArch_iOS get].settings_button;
|
||||
[self setTitle: [_path lastPathComponent]];
|
||||
|
||||
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"filecell"];
|
||||
|
||||
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"dircell"];
|
||||
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"textcell"];
|
||||
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"imagecell"];
|
||||
|
||||
return self;
|
||||
}
|
||||
@ -55,7 +57,6 @@
|
||||
return [_list count];
|
||||
}
|
||||
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
RADirectoryItem* path = [_list objectAtIndex: indexPath.row];
|
||||
@ -69,17 +70,42 @@
|
||||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
RADirectoryItem* path = [_list objectAtIndex: indexPath.row];
|
||||
UICollectionViewCell* cell = nil;
|
||||
|
||||
UICollectionViewCell* cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"filecell" forIndexPath:indexPath];
|
||||
if (path.isDirectory)
|
||||
cell.backgroundView = [[UIImageView alloc] initWithImage:[RetroArch_iOS get].folder_icon];
|
||||
{
|
||||
cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"dircell" forIndexPath:indexPath];
|
||||
|
||||
if (!cell.backgroundView)
|
||||
{
|
||||
cell.backgroundView = [[UIImageView alloc] initWithImage:[RetroArch_iOS get].folder_icon];
|
||||
((UIImageView*)cell.backgroundView).contentMode = UIViewContentModeScaleAspectFit;
|
||||
}
|
||||
}
|
||||
else if (path.coverPath)
|
||||
{
|
||||
cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"imagecell" forIndexPath:indexPath];
|
||||
|
||||
if (!cell.backgroundView)
|
||||
{
|
||||
cell.backgroundView = [UIImageView new];
|
||||
((UIImageView*)cell.backgroundView).contentMode = UIViewContentModeScaleAspectFit;
|
||||
}
|
||||
|
||||
((UIImageView*)cell.backgroundView).image = [UIImage imageWithContentsOfFile:path.coverPath];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString* img = [NSString stringWithFormat:@"%@/.coverart/%@.png", _path, [[path.path lastPathComponent] stringByDeletingPathExtension]];
|
||||
if (ra_ios_is_file(img))
|
||||
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:img]];
|
||||
else
|
||||
cell.backgroundView = [[UIImageView alloc] initWithImage:_templateImage];
|
||||
cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"textcell" forIndexPath:indexPath];
|
||||
|
||||
if (!cell.backgroundView)
|
||||
{
|
||||
cell.backgroundView = [UILabel new];
|
||||
((UILabel*)cell.backgroundView).numberOfLines = 0;
|
||||
((UILabel*)cell.backgroundView).textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
|
||||
((UILabel*)cell.backgroundView).text = [path.path lastPathComponent];
|
||||
}
|
||||
|
||||
return cell;
|
||||
|
@ -20,6 +20,7 @@ extern NSString* ra_ios_get_browser_root();
|
||||
|
||||
@interface RADirectoryItem : NSObject
|
||||
@property (strong) NSString* path;
|
||||
@property (strong) NSString* coverPath;
|
||||
@property bool isDirectory;
|
||||
@end
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
#import "browser.h"
|
||||
|
||||
@implementation RADirectoryItem
|
||||
+ (RADirectoryItem*)directoryItemFromPath:(const char*)thePath
|
||||
+ (RADirectoryItem*)directoryItemFromPath:(const char*)thePath checkForCovers:(BOOL)checkCovers
|
||||
{
|
||||
RADirectoryItem* result = [RADirectoryItem new];
|
||||
result.path = [NSString stringWithUTF8String:thePath];
|
||||
@ -26,6 +26,14 @@
|
||||
struct stat statbuf;
|
||||
if (stat(thePath, &statbuf) == 0)
|
||||
result.isDirectory = S_ISDIR(statbuf.st_mode);
|
||||
|
||||
if (checkCovers && !result.isDirectory)
|
||||
{
|
||||
result.coverPath = [NSString stringWithFormat:@"%@/.coverart/%@.png", [result.path stringByDeletingLastPathComponent], [[result.path lastPathComponent] stringByDeletingPathExtension]];
|
||||
|
||||
if (!ra_ios_is_file(result.coverPath))
|
||||
result.coverPath = nil;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -65,7 +73,7 @@ NSArray* ra_ios_list_directory(NSString* path, NSRegularExpression* regex)
|
||||
cpath[cpath_end] = 0;
|
||||
strcat(cpath, item->d_name);
|
||||
|
||||
[result addObject:[RADirectoryItem directoryItemFromPath:cpath]];
|
||||
[result addObject:[RADirectoryItem directoryItemFromPath:cpath checkForCovers:YES]];
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
Loading…
Reference in New Issue
Block a user