mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Various fixes
This commit is contained in:
parent
83ef360953
commit
5749548ac8
@ -669,12 +669,14 @@ open class ListView: ASDisplayNode, ASScrollViewDelegate, ASGestureRecognizerDel
|
||||
|
||||
private func updateReordering(offset: CGFloat) {
|
||||
if let reorderNode = self.reorderNode {
|
||||
let updatedLocation = reorderNode.initialLocation.y + offset
|
||||
if updatedLocation < self.insets.top {
|
||||
} else {
|
||||
reorderNode.updateOffset(offset: offset)
|
||||
self.checkItemReordering()
|
||||
if !self.autoScrollWhenReordering, case let .known(contentOffset) = self.visibleContentOffset() {
|
||||
let updatedLocation = reorderNode.initialLocation.y + offset
|
||||
if updatedLocation < self.insets.top - contentOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
reorderNode.updateOffset(offset: offset)
|
||||
self.checkItemReordering()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1525,10 +1527,14 @@ open class ListView: ASDisplayNode, ASScrollViewDelegate, ASGestureRecognizerDel
|
||||
topItemFound = true
|
||||
}
|
||||
|
||||
if !topItemFound, self.stackFromBottom && !self.autoScrollWhenReordering, let itemNode = self.itemNodes.first, itemNode.apparentFrame.minY > 0.0 {
|
||||
topItemFound = true
|
||||
}
|
||||
|
||||
var topOffset: CGFloat
|
||||
|
||||
if topItemFound {
|
||||
let realTopItemEdge = itemNodes.first!.apparentFrame.origin.y
|
||||
let realTopItemEdge = self.itemNodes.first!.apparentFrame.origin.y
|
||||
let realTopItemEdgeOffset = max(0.0, realTopItemEdge)
|
||||
|
||||
topOffset = realTopItemEdgeOffset
|
||||
|
@ -818,7 +818,7 @@ struct ListViewState {
|
||||
}
|
||||
operations.append(.Remove(index: index, offsetDirection: offsetDirection))
|
||||
|
||||
if let referenceNode = referenceNode , animated {
|
||||
if let referenceNode = referenceNode, animated {
|
||||
self.nodes.insert(.Placeholder(frame: nodeFrame), at: index)
|
||||
operations.append(.InsertDisappearingPlaceholder(index: index, referenceNode: referenceNode, offsetDirection: offsetDirection.inverted()))
|
||||
} else {
|
||||
|
@ -127,13 +127,39 @@ func _internal_addSavedMusic(account: Account, file: FileMediaReference, afterFi
|
||||
return account.postbox.transaction { transaction in
|
||||
if let cachedSavedMusic = transaction.retrieveItemCacheEntry(id: entryId(peerId: account.peerId))?.get(CachedProfileSavedMusic.self) {
|
||||
var updatedFiles = cachedSavedMusic.files
|
||||
updatedFiles.removeAll(where: { $0.fileId == file.media.fileId })
|
||||
if let afterFile, let index = updatedFiles.firstIndex(where: { $0.fileId == afterFile.media.fileId }) {
|
||||
updatedFiles.insert(file.media, at: index + 1)
|
||||
var updatedCount = cachedSavedMusic.count
|
||||
|
||||
if let fromIndex = updatedFiles.firstIndex(where: { $0.fileId == file.media.fileId }) {
|
||||
let anchorIdxOpt: Int? = afterFile.flatMap { af in
|
||||
updatedFiles.firstIndex(where: { $0.fileId == af.media.fileId })
|
||||
}
|
||||
updatedFiles.remove(at: fromIndex)
|
||||
let insertIndex: Int
|
||||
if let anchorIndex = anchorIdxOpt {
|
||||
if anchorIndex == fromIndex {
|
||||
insertIndex = min(fromIndex + 1, updatedFiles.count)
|
||||
} else {
|
||||
let adjustedAnchor = anchorIndex > fromIndex ? (anchorIndex - 1) : anchorIndex
|
||||
insertIndex = updatedFiles.index(after: adjustedAnchor)
|
||||
}
|
||||
} else if afterFile != nil {
|
||||
insertIndex = 0
|
||||
} else {
|
||||
insertIndex = 0
|
||||
}
|
||||
|
||||
updatedFiles.insert(file.media, at: insertIndex)
|
||||
} else {
|
||||
updatedFiles.insert(file.media, at: 0)
|
||||
if let afterFile, let anchor = updatedFiles.firstIndex(where: { $0.fileId == afterFile.media.fileId }) {
|
||||
updatedFiles.insert(file.media, at: updatedFiles.index(after: anchor))
|
||||
} else if afterFile != nil {
|
||||
updatedFiles.append(file.media)
|
||||
} else {
|
||||
updatedFiles.insert(file.media, at: 0)
|
||||
}
|
||||
updatedCount = updatedCount + 1
|
||||
}
|
||||
let updatedCount = max(0, cachedSavedMusic.count + 1)
|
||||
|
||||
if let entry = CodableEntry(CachedProfileSavedMusic(files: updatedFiles, count: updatedCount)) {
|
||||
transaction.putItemCacheEntry(id: entryId(peerId: account.peerId), entry: entry)
|
||||
}
|
||||
@ -371,15 +397,44 @@ public final class ProfileSavedMusicContext {
|
||||
}
|
||||
|
||||
public func addMusic(file: FileMediaReference, afterFile: FileMediaReference? = nil, apply: Bool = true) -> Signal<Never, AddSavedMusicError> {
|
||||
self.files.removeAll(where: { $0.fileId == file.media.fileId })
|
||||
if let afterFile, let index = self.files.firstIndex(where: { $0.fileId == afterFile.media.fileId }) {
|
||||
self.files.insert(file.media, at: index + 1)
|
||||
var updatedFiles = self.files
|
||||
|
||||
let fromIdx = updatedFiles.firstIndex { $0.fileId == file.media.fileId }
|
||||
let anchorIdxOpt = afterFile.flatMap { af in
|
||||
updatedFiles.firstIndex { $0.fileId == af.media.fileId }
|
||||
}
|
||||
|
||||
if let fromIdx = fromIdx {
|
||||
updatedFiles.remove(at: fromIdx)
|
||||
|
||||
let insertIdx: Int
|
||||
if let anchorIdx = anchorIdxOpt {
|
||||
if anchorIdx == fromIdx {
|
||||
insertIdx = min(fromIdx + 1, updatedFiles.count)
|
||||
} else {
|
||||
let adjustedAnchor = anchorIdx > fromIdx ? (anchorIdx - 1) : anchorIdx
|
||||
insertIdx = updatedFiles.index(after: adjustedAnchor)
|
||||
}
|
||||
} else if afterFile != nil {
|
||||
insertIdx = updatedFiles.count
|
||||
} else {
|
||||
insertIdx = 0
|
||||
}
|
||||
updatedFiles.insert(file.media, at: insertIdx)
|
||||
} else {
|
||||
self.files.insert(file.media, at: 0)
|
||||
}
|
||||
if let count = self.count {
|
||||
self.count = count + 1
|
||||
if let anchorIdx = anchorIdxOpt {
|
||||
updatedFiles.insert(file.media, at: updatedFiles.index(after: anchorIdx))
|
||||
} else if afterFile != nil {
|
||||
updatedFiles.append(file.media)
|
||||
} else {
|
||||
updatedFiles.insert(file.media, at: 0)
|
||||
}
|
||||
if let count = self.count {
|
||||
self.count = count + 1
|
||||
}
|
||||
}
|
||||
self.files = updatedFiles
|
||||
|
||||
self.pushState()
|
||||
|
||||
if apply {
|
||||
|
@ -268,6 +268,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
|
||||
|
||||
self.historyNode.preloadPages = true
|
||||
self.historyNode.stackFromBottom = true
|
||||
self.historyNode.areContentAnimationsEnabled = true
|
||||
self.historyNode.updateFloatingHeaderOffset = { [weak self] offset, transition in
|
||||
if let strongSelf = self {
|
||||
strongSelf.updateFloatingHeaderOffset(offset: offset, transition: transition)
|
||||
@ -461,40 +462,43 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
|
||||
guard let self, let peer = peer.flatMap({ PeerReference($0._asPeer()) }) else {
|
||||
return
|
||||
}
|
||||
|
||||
self.historyNode.reorderItem = { fromIndex, toIndex, transactionOpaqueState -> Signal<Bool, NoError> in
|
||||
guard let filteredEntries = (transactionOpaqueState as? ChatHistoryTransactionOpaqueState)?.historyView.filteredEntries else {
|
||||
guard let filteredEntries = (transactionOpaqueState as? ChatHistoryTransactionOpaqueState)?.historyView.filteredEntries, !filteredEntries.isEmpty else {
|
||||
return .single(false)
|
||||
}
|
||||
let fromEntry = filteredEntries[filteredEntries.count - 1 - fromIndex]
|
||||
let toEntry: ChatHistoryEntry?
|
||||
if toIndex == 0 {
|
||||
toEntry = nil
|
||||
|
||||
func mapIndex(_ uiIndex: Int) -> Int {
|
||||
return filteredEntries.count - 1 - uiIndex
|
||||
}
|
||||
|
||||
let mappedFromIndex = mapIndex(fromIndex)
|
||||
guard filteredEntries.indices.contains(mappedFromIndex), case let .MessageEntry(fromMessage, _, _, _, _, _) = filteredEntries[mappedFromIndex], let fromFile = fromMessage.media.first(where: { $0 is TelegramMediaFile }) as? TelegramMediaFile else {
|
||||
return .single(false)
|
||||
}
|
||||
|
||||
var afterFile: TelegramMediaFile?
|
||||
if toIndex > 0 {
|
||||
let afterMappedIndex = mapIndex(toIndex - 1)
|
||||
if filteredEntries.indices.contains(afterMappedIndex), case let .MessageEntry(afterMessage, _, _, _, _, _) = filteredEntries[afterMappedIndex], let file = afterMessage.media.first(where: { $0 is TelegramMediaFile }) as? TelegramMediaFile {
|
||||
afterFile = file
|
||||
}
|
||||
} else {
|
||||
toEntry = filteredEntries[filteredEntries.count - 1 - toIndex]
|
||||
}
|
||||
guard case let .MessageEntry(fromMessage, _, _, _, _, _) = fromEntry else {
|
||||
return .single(false)
|
||||
}
|
||||
|
||||
guard let fromFile = fromMessage.media.first(where: { $0 is TelegramMediaFile }) as? TelegramMediaFile else {
|
||||
return .single(false)
|
||||
afterFile = nil
|
||||
}
|
||||
|
||||
var toFile: TelegramMediaFile?
|
||||
if let toEntry, case let .MessageEntry(toMessage, _, _, _, _, _) = toEntry, let file = toMessage.media.first(where: { $0 is TelegramMediaFile }) as? TelegramMediaFile {
|
||||
toFile = file
|
||||
}
|
||||
if fromFile.id == toFile?.id {
|
||||
return .single(false)
|
||||
}
|
||||
|
||||
let _ = savedMusicContext.addMusic(file: .savedMusic(peer: peer, media: fromFile), afterFile: toFile.flatMap { .savedMusic(peer: peer, media: $0) }).start()
|
||||
|
||||
let _ = savedMusicContext.addMusic(
|
||||
file: .savedMusic(peer: peer, media: fromFile),
|
||||
afterFile: afterFile.flatMap { .savedMusic(peer: peer, media: $0) }
|
||||
).start()
|
||||
|
||||
return .single(true)
|
||||
}
|
||||
})
|
||||
self.historyNode.useMainQueueTransactions = true
|
||||
self.historyNode.autoScrollWhenReordering = false
|
||||
}
|
||||
|
||||
|
||||
func updatePresentationData(_ presentationData: PresentationData) {
|
||||
self.presentationData = presentationData
|
||||
@ -849,6 +853,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
|
||||
historyNode.clipsToBounds = true
|
||||
historyNode.preloadPages = true
|
||||
historyNode.stackFromBottom = true
|
||||
historyNode.areContentAnimationsEnabled = true
|
||||
historyNode.updateFloatingHeaderOffset = { [weak self] offset, _ in
|
||||
self?.replacementHistoryNodeFloatingOffset = offset
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user