VLCPlaylistViewController.m 4.62 KB
Newer Older
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1 2 3 4 5 6 7 8 9 10
//
//  VLCMasterViewController.m
//  AspenProject
//
//  Created by Felix Paul Kühne on 27.02.13.
//  Copyright (c) 2013 VideoLAN. All rights reserved.
//

#import "VLCPlaylistViewController.h"

11
#import "VLCMovieViewController.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

@interface VLCPlaylistViewController () {
    NSMutableArray *_foundMedia;
}
@end

@implementation VLCPlaylistViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Aspen Project";
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            self.clearsSelectionOnViewWillAppear = NO;
            self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
        }
    }
    return self;
}

- (void)dealloc
{
35
    [_movieViewController release];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
36 37 38 39 40 41 42 43 44 45 46 47 48
    [_foundMedia release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAboutView:)] autorelease];
    self.navigationItem.leftBarButtonItem = addButton;

    self.navigationItem.rightBarButtonItem = self.editButtonItem;

49 50
    [self updateViewContents];
    [[MLMediaLibrary sharedMediaLibrary] libraryDidAppear];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
51 52 53 54 55 56 57 58 59 60
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table View

61
- (void)updateViewContents
Felix Paul Kühne's avatar
Felix Paul Kühne committed
62
{
63 64
    [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];

Felix Paul Kühne's avatar
Felix Paul Kühne committed
65 66 67 68
    if (_foundMedia)
        [_foundMedia release];

    _foundMedia = [[NSMutableArray arrayWithArray:[MLFile allFiles]] retain];
69 70

    [self.tableView reloadData];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _foundMedia.count;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
90
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
91 92 93 94
    }

    MLFile *object = _foundMedia[indexPath.row];
    cell.textLabel.text = object.title;
95 96
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
    cell.imageView.image = object.computedThumbnail;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [_foundMedia removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }
}

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
134
    MLFile *mediaObject = _foundMedia[indexPath.row];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
135
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
136 137 138 139 140 141 142
        if (!self.movieViewController) {
            self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController_iPhone" bundle:nil] autorelease];
        }
        self.movieViewController.mediaItem = mediaObject;
        [self.navigationController pushViewController:self.movieViewController animated:YES];
    } else
        self.movieViewController.mediaItem = mediaObject;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
143 144
}

145 146 147
#pragma mark - UI implementation
- (void)showAboutView:(id)sender
{
148
    APLog(@"asked to show the about view");
149 150
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
151
@end