IOS-1252 merge in default IOS-1226
authorDirk Zimmermann <dirk@pep-project.org>
Thu, 16 Aug 2018 13:24:41 +0200
branchIOS-1226
changeset 585011fdaba12c1d
parent 5848 e06bea5baf07
parent 5849 3cee57dd8029
child 5851 03765f4b2d23
IOS-1252 merge in default
pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift
pEpForiOS/UI/EmailDisplayList/EmailListViewModel+MessageFolderDelegate.swift
pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift
     1.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Thu Aug 16 11:54:53 2018 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Thu Aug 16 13:24:41 2018 +0200
     1.3 @@ -422,6 +422,13 @@
     1.4          self.navigationItem.rightBarButtonItem = editRightButton
     1.5      }
     1.6  
     1.7 +    private func moveSelectionIfNeeded(fromIndexPath: IndexPath, toIndexPath: IndexPath) {
     1.8 +        if lastSelectedIndexPath == fromIndexPath {
     1.9 +            lastSelectedIndexPath = toIndexPath
    1.10 +            resetSelection()
    1.11 +        }
    1.12 +    }
    1.13 +
    1.14      private func resetSelectionIfNeeded(for indexPath: IndexPath) {
    1.15          if lastSelectedIndexPath == indexPath {
    1.16              resetSelection()
    1.17 @@ -824,6 +831,16 @@
    1.18          // ignore
    1.19      }
    1.20  
    1.21 +    func emailListViewModel(viewModel: EmailListViewModel, didMoveData atIndexPath: IndexPath, toIndexPath: IndexPath) {
    1.22 +        lastSelectedIndexPath = tableView.indexPathForSelectedRow
    1.23 +
    1.24 +        tableView.beginUpdates()
    1.25 +        tableView.moveRow(at: atIndexPath, to: toIndexPath)
    1.26 +        tableView.endUpdates()
    1.27 +
    1.28 +        moveSelectionIfNeeded(fromIndexPath: atIndexPath, toIndexPath: toIndexPath)
    1.29 +    }
    1.30 +
    1.31      func updateView() {
    1.32          loadingBlocked = false
    1.33          tableView.dataSource = self
     2.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewModel+MessageFolderDelegate.swift	Thu Aug 16 11:54:53 2018 +0200
     2.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewModel+MessageFolderDelegate.swift	Thu Aug 16 13:24:41 2018 +0200
     2.3 @@ -82,14 +82,20 @@
     2.4                  } else {
     2.5                      if let index = referencedIndices.first {
     2.6                          // The thread count might need to be updated
     2.7 -                        if let messageModel = theSelf.messages.object(at: index),
     2.8 -                            let messageCount = messageModel.internalMessageCount  {
     2.9 -                            messageModel.internalMessageCount = messageCount + 1
    2.10 +
    2.11 +                        theSelf.messages.removeObject(at: index)
    2.12 +                        let newIndex = theSelf.messages.insert(object: previewMessage)
    2.13 +
    2.14 +                        if newIndex != index {
    2.15 +                            theSelf.emailListViewModelDelegate?.emailListViewModel(
    2.16 +                                viewModel: theSelf,
    2.17 +                                didMoveData: IndexPath(row: index, section: 0),
    2.18 +                                toIndexPath: IndexPath(row: newIndex, section: 0))
    2.19                          }
    2.20  
    2.21                          theSelf.emailListViewModelDelegate?.emailListViewModel(
    2.22                              viewModel: theSelf,
    2.23 -                            didUpdateDataAt: [IndexPath(row: index, section: 0)])
    2.24 +                            didUpdateDataAt: [IndexPath(row: newIndex, section: 0)])
    2.25  
    2.26                          if let index = theSelf.currentlyDisplayedIndex(of: referencedIndices) {
    2.27                              if theSelf.isShowingSingleMessage() {
     3.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Thu Aug 16 11:54:53 2018 +0200
     3.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Thu Aug 16 13:24:41 2018 +0200
     3.3 @@ -14,6 +14,7 @@
     3.4      func emailListViewModel(viewModel: EmailListViewModel, didInsertDataAt indexPaths: [IndexPath])
     3.5      func emailListViewModel(viewModel: EmailListViewModel, didUpdateDataAt indexPaths: [IndexPath])
     3.6      func emailListViewModel(viewModel: EmailListViewModel, didRemoveDataAt indexPaths: [IndexPath])
     3.7 +    func emailListViewModel(viewModel: EmailListViewModel, didMoveData atIndexPath: IndexPath, toIndexPath: IndexPath)
     3.8      func emailListViewModel(viewModel: EmailListViewModel,
     3.9                              didUpdateUndisplayedMessage message: Message)
    3.10