recents_category_drag_drop

the drag and drop is implemented : the cell can be move in the recents sections.
This commit is contained in:
yannick
2015-12-11 11:50:13 +01:00
parent 5e8e81d019
commit 27a72ae7db
3 changed files with 136 additions and 6 deletions
+72
View File
@@ -482,4 +482,76 @@
[super destroy];
}
#pragma mark - drag and drop managemenent
- (BOOL)isDraggableCellAt:(NSIndexPath*)path
{
return (path && ((path.section == favoritesSection) || (path.section == lowPrioritySection) || (path.section == conversationSection)));
}
- (BOOL)canCellMoveFrom:(NSIndexPath*)oldPath to:(NSIndexPath*)newPath
{
BOOL res = [self isDraggableCellAt:oldPath] && [self isDraggableCellAt:newPath];
// the both index pathes are movable
if (res)
{
// cannot move conversation rooms in the same section
res &= !((oldPath.section == conversationSection) && (newPath.section == conversationSection));
// other cases ?
}
return res;
}
- (NSString*)roomTagAt:(NSIndexPath*)path
{
if (path.section == favoritesSection)
{
return kMXRoomTagFavourite;
}
else if (path.section == lowPrioritySection)
{
return kMXRoomTagLowPriority;
}
return nil;
}
- (void)moveCellFrom:(NSIndexPath*)oldPath to:(NSIndexPath*)newPath
{
if ([self canCellMoveFrom:oldPath to:newPath] && ![newPath isEqual:oldPath])
{
NSString* oldRoomTag = [self roomTagAt:oldPath];
NSString* dstRoomTag = [self roomTagAt:newPath];
MXRoom* room = [self getRoomAtIndexPath:oldPath];
NSString* tagOrder = [room.mxSession tagOrderToBeAtIndex:newPath.row withTag:dstRoomTag];
NSLog(@"[MXKRecentsDataSource] Update the room %@ tag from %@ to %@ with tag order %@", room.state.roomId, oldRoomTag, dstRoomTag, tagOrder);
[room replaceTag:oldRoomTag
byTag:dstRoomTag
withOrder:tagOrder
success: ^{
// Refresh table display
if (self.delegate)
{
[self.delegate dataSource:self didCellChange:nil];
}
} failure:^(NSError *error) {
NSLog(@"[MXKRecentsDataSource] Failed to update the tag %@ of room (%@) failed: %@", dstRoomTag, room.state.roomId, error);
// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
}];
}
}
@end