Skip to content

Commit

Permalink
Fix iPad crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Jul 13, 2024
1 parent 03fdce3 commit e08c048
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Submodules/MVVMFoundation
48 changes: 48 additions & 0 deletions iTorrent/Core/Assets/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,54 @@
}
}
},
"details.files.mediaPlayerPreview" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Media player"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Медиаплеер"
}
}
}
},
"details.files.previewMode" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Preview mode"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Режим превью"
}
}
}
},
"details.files.quickLookPreview" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Quick Look preview"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Quick Look превью"
}
}
}
},
"details.info" : {
"localizations" : {
"en" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private extension PatreonPreferencesViewController {
}, for: .touchUpInside)

linkPatreonButton.addAction(.init { [unowned self] _ in
viewModel.linkPatreon()
viewModel.linkPatreon(from: linkPatreonButton)
}, for: .touchUpInside)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import MvvmFoundation
import Combine
import UIKit

extension PatreonPreferencesViewModel {
enum PatreonAccountState: Equatable {
Expand Down Expand Up @@ -71,7 +72,7 @@ extension PatreonPreferencesViewModel {
preferencesStorage.$patreonAccount.map { $0?.fullVersion ?? false }.eraseToAnyPublisher()
}

func linkPatreon() {
func linkPatreon(from view: UIView) {
if accountState.value == .none {
guard let context = navigationService?()
else { return }
Expand All @@ -91,7 +92,7 @@ extension PatreonPreferencesViewModel {
try? patreonService.signOut()
accountState.value = .none
}
])
], sourceView: view)
}
}
}
17 changes: 11 additions & 6 deletions iTorrent/Screens/TorrentFiles/TorrentFilesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private extension TorrentFilesViewController {
let cell = collectionView.dequeue(for: indexPath) as TorrentFilesFileListCell<TorrentFilesFileItemViewModel>
let vm = parent.viewModel.fileModel(for: node.index)
vm.previewAction = { [unowned self] in
parent.openPreview(start: node.index)
parent.openPreview(from: indexPath, start: node.index)
}
cell.setup(with: vm)
return cell
Expand Down Expand Up @@ -144,8 +144,9 @@ private extension TorrentFilesViewController {
}
}

func openPreview(start fileIndex: Int) {
guard let startIndex = viewModel.filesForPreview.firstIndex(where: { $0.index == fileIndex })
func openPreview(from indexPath: IndexPath, start fileIndex: Int) {
guard let startIndex = viewModel.filesForPreview.firstIndex(where: { $0.index == fileIndex }),
let cell = collectionView.cellForItem(at: indexPath)
else { return }

let path = viewModel.filesForPreview[startIndex].path
Expand All @@ -158,14 +159,18 @@ private extension TorrentFilesViewController {
return
}

let alert = UIAlertController(title: "Preview mode", message: nil, preferredStyle: .actionSheet)
alert.addAction(.init(title: "Quick Look preview", style: .default) { [self] _ in
let alert = UIAlertController(title: %"details.files.previewMode", message: nil, preferredStyle: .actionSheet)
alert.addAction(.init(title: %"details.files.quickLookPreview", style: .default) { [self] _ in
previewAction(start: startIndex)
})
alert.addAction(.init(title: "Media player", style: .default) { [self] _ in
alert.addAction(.init(title: %"details.files.mediaPlayerPreview", style: .default) { [self] _ in
playerAction(start: startIndex)
})
alert.addAction(.init(title: %"common.cancel", style: .cancel))

alert.popoverPresentationController?.sourceView = cell
alert.popoverPresentationController?.sourceRect = cell.bounds

present(alert, animated: true)
}
}
Expand Down

0 comments on commit e08c048

Please sign in to comment.