|
1 | 1 | import UIKit |
2 | 2 | import PhotoGetherDomainInterface |
3 | | -import DesignSystem |
4 | 3 |
|
5 | 4 | public final class CaptureVideosUseCaseImpl: CaptureVideosUseCase { |
6 | 5 | public func execute() -> [UIImage] { |
7 | | - guard let localImage = connectionRepository.capturedLocalVideo |
8 | | - else { return [ |
9 | | - PTGImage.temp1.image, |
10 | | - PTGImage.temp2.image, |
11 | | - PTGImage.temp3.image, |
12 | | - PTGImage.temp4.image] |
13 | | - } |
14 | | - let remoteImages = connectionRepository.clients.map { $0.captureVideo() } |
| 6 | + let localImage = connectionRepository.capturedLocalVideo ?? UIImage() |
| 7 | + |
| 8 | + let localUserImageInfo = [(connectionRepository.localUserInfo?.viewPosition, localImage)] |
| 9 | + let remoteUserImagesInfo = connectionRepository.clients |
| 10 | + .map { ($0.remoteUserInfo?.viewPosition, $0.captureVideo()) } |
15 | 11 |
|
16 | | - return [localImage] + remoteImages |
| 12 | + return sortImages(localUserImageInfo + remoteUserImagesInfo) |
17 | 13 | } |
18 | 14 |
|
19 | 15 | private let connectionRepository: ConnectionRepository |
20 | 16 |
|
21 | 17 | public init(connectionRepository: ConnectionRepository) { |
22 | 18 | self.connectionRepository = connectionRepository |
23 | 19 | } |
| 20 | + |
| 21 | + private func sortImages(_ images: [(viewPosition: UserInfo.ViewPosition?, image: UIImage)]) -> [UIImage] { |
| 22 | + let convertedArray = images.map { |
| 23 | + (position: PositionOder(rawValue: $0.viewPosition?.rawValue ?? -1), |
| 24 | + image: $0.image) |
| 25 | + } |
| 26 | + |
| 27 | + // ๋ฐฐ์ด์ 2๋ฒ ์ธ๋ฑ์ค๊ฐ ๋ง์ง๋ง ์๋ฆฌ์ด๊ธฐ ๋๋ฌธ์ nil์ผ ๊ฒฝ์ฐ 2๋ก ์ค์ ํ์ต๋๋ค |
| 28 | + let sortedByViewPosition = convertedArray.sorted { |
| 29 | + let lhs = $0.position?.sequence ?? 2 |
| 30 | + let rhs = $1.position?.sequence ?? 2 |
| 31 | + return lhs < rhs |
| 32 | + } |
| 33 | + |
| 34 | + return sortedByViewPosition.map { $0.image } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +/// case์ ์์๋ ์ฐธ๊ฐ์์ ์ฐธ๊ฐ ์์์ ๋ฐ๋ฅธ ํ๋ฉด ๋ฐฐ์น์ด๊ณ sequence๋ ์ด๋ฏธ์ง ๋ฐ์ดํฐ ์ ๋ฌํ ๋์ ๋ฐฐ์ด ์์์
๋๋ค |
| 39 | +private enum PositionOder: Int { |
| 40 | + case topLeading |
| 41 | + case bottomTrailing |
| 42 | + case topTrailing |
| 43 | + case bottomLeading |
| 44 | + |
| 45 | + var sequence: Int { |
| 46 | + switch self { |
| 47 | + case .topLeading: 0 |
| 48 | + case .topTrailing: 1 |
| 49 | + case .bottomLeading: 2 |
| 50 | + case .bottomTrailing: 3 |
| 51 | + } |
| 52 | + } |
24 | 53 | } |
0 commit comments