Commit efe9aad0 authored by Tobias's avatar Tobias

Improve table controller objects comparison so rows for objects which were...

Improve table controller objects comparison so rows for objects which were updated are not removed and added, but updated.
Rows no longer slide out and in when the represented object was updated.
parent f467ca95
......@@ -57,6 +57,7 @@ static NSString *const rowType = @"mediaRow";
tableController.emptyLibraryInterfaceObjects = self.emptyLibraryGroup;
tableController.pageSize = 20;
tableController.rowType = rowType;
tableController.identifierKeyPath = @"objectID.URIRepresentation";
tableController.configureRowControllerWithObjectBlock = ^(id controller, id object) {
if ([controller respondsToSelector:@selector(configureWithMediaLibraryObject:)]) {
......
......@@ -52,6 +52,14 @@ typedef void(^VLCWatchTableControllerConfigureRowControllerWithObjectBlock)(id r
*/
@property (nonatomic, copy) NSArray *objects;
/*
* Set the identifierKeyPath to the key path of a unique identifier of the objects.
* The identifier at the keyPath is used to determine if a object was added or removed.
* Default is @"self".
*/
@property (nonatomic, copy) NSString *identifierKeyPath;
/* updates the table with the current configuration (pagesize, page, objects) */
- (void)updateTable;
......
......@@ -23,6 +23,12 @@
@implementation VLCWatchTableController
- (NSString *)identifierKey {
if (!_identifierKeyPath) {
_identifierKeyPath = @"self";
}
return _identifierKeyPath;
}
- (void)setObjects:(NSArray *)objects {
_objects = [objects copy];
......@@ -56,10 +62,10 @@
/* get new dispayed objects */
NSRange range = NSMakeRange(startIndex, endIndex-startIndex);
NSArray *newObjects = [self.objects subarrayWithRange:range];
NSSet *newSet = [[NSSet alloc] initWithArray:newObjects];
NSSet *newSet = [[NSSet alloc] initWithArray:[newObjects valueForKeyPath:self.identifierKeyPath]];
NSArray *oldObjects = self.displayedObjects;
NSSet *oldSet = [[NSSet alloc] initWithArray:oldObjects];
NSSet *oldSet = [[NSSet alloc] initWithArray:[oldObjects valueForKeyPath:self.identifierKeyPath]];
WKInterfaceTable *table = self.table;
......@@ -102,14 +108,14 @@
else {
NSMutableIndexSet *removeRowIndexes = [NSMutableIndexSet new];
[oldObjects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([removedSet containsObject:obj]) {
if ([removedSet containsObject:[obj valueForKeyPath:self.identifierKeyPath]]) {
[removeRowIndexes addIndex:idx];
}
}];
[table removeRowsAtIndexes:removeRowIndexes];
[newObjects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([addedSet containsObject:obj]) {
if ([addedSet containsObject:[obj valueForKeyPath:self.identifierKeyPath]]) {
NSString *rowType = [self _rowTypeForObject:obj];
[table insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:idx] withRowType:rowType];
}
......
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