Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] WhiteboardList 당겨서 새로고침 구현 및 다크모드 대응 #116

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public protocol NearbyNetworkInterface {
/// 주변 기기 검색을 중지합니다.
func stopSearching()

/// 주변 기기 검색을 중지 후 다시 시작합니다.
func restartSearching()

/// 주변에 내 기기를 정보와 함께 알립니다.
/// - Parameter data: 담을 정보
func startPublishing(with info: [String: String])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public final class WhiteboardRepository: WhiteboardRepositoryInterface {
nearbyNetwork.stopSearching()
}

public func restartSearching() {
nearbyNetwork.restartSearching()
}

private func updatePublishingInfo(myProfile: Profile) {
var newIconList: [String] = []
newIconList.append(myProfile.profileIcon.emoji)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public protocol WhiteboardRepositoryInterface {

/// 화이트보드 탐색을 중지합니다.
func stopSearching()

/// 화이트보드 탐색을 중단 후 다시 시작합니다.
func restartSearching()

/// 선택한 화이트보드와 연결을 시도합니다.
/// - Parameter whiteboard: 연결할 화이트보드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public protocol WhiteboardUseCaseInterface {

/// 화이트보드 탐색을 중지합니다.
func stopSearchingWhiteboard()

/// 화이트보드 탐색을 중단 후 다시 시작합니다.
func refreshWhiteboardList()
}
4 changes: 4 additions & 0 deletions Domain/Domain/Sources/UseCase/WhiteboardUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public final class WhiteboardUseCase: WhiteboardUseCaseInterface {
let profile = profileRepository.loadProfile()
try whiteboardRepository.joinWhiteboard(whiteboard: whiteboard, myProfile: profile)
}

public func refreshWhiteboardList() {
whiteboardRepository.restartSearching()
}
}

extension WhiteboardUseCase: WhiteboardRepositoryDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ extension NearbyNetworkService: NearbyNetworkInterface {
serviceBrowser.stopBrowsingForPeers()
}

public func restartSearching() {
serialQueue.sync {
serviceBrowser.stopBrowsingForPeers()
foundPeers.removeAll()
serviceBrowser.startBrowsingForPeers()
}
}

public func startPublishing(with info: [String: String]) {
isHost = true
serviceAdvertiser.stopAdvertisingPeer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class WhiteboardCell: UICollectionViewCell {
private let titleLabel: UILabel = {
let label = UILabel()
label.font = AirplainFont.Subtitle2
label.textColor = .airplainBlack
let originColor = UIColor(named: "AirplainBlack") ?? .black
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어라 혹시 .airplainbalck 말고 사용하신 이요눈 뭘까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 색상은 다크모드, 라이트모드 관계 없이 검정색으로 유지되어야합니다.
이유는 cell의 색상이 흰색이라 그냥 .airplainBlack 상태에서 다크모드 전환 시 글자가 안보이는 이슈가 있었습니다!

let resolvedColor = originColor.resolvedColor(with: UITraitCollection(userInterfaceStyle: .light))
label.textColor = resolvedColor
return label
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class WhiteboardListViewController: UIViewController {
}()

private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
private let refreshControl = UIRefreshControl()
private var dataSource: UICollectionViewDiffableDataSource<Int, Whiteboard>?
private let viewModel: WhiteboardListViewModel
private var cancellables = Set<AnyCancellable>()
Expand Down Expand Up @@ -171,8 +172,14 @@ public final class WhiteboardListViewController: UIViewController {
private func configureCollectionView() {
collectionView.delegate = self
collectionView.collectionViewLayout = createCollectionViewLayout()
collectionView.backgroundColor = .white
collectionView.backgroundColor = .systemBackground
collectionView.register(WhiteboardCell.self, forCellWithReuseIdentifier: WhiteboardCell.reuseIdentifier)

let refreshAction = UIAction { [weak self] _ in
self?.refreshWhiteboardList()
}
refreshControl.addAction(refreshAction, for: .valueChanged)
collectionView.refreshControl = refreshControl
}

private func createCollectionViewLayout() -> UICollectionViewLayout {
Expand Down Expand Up @@ -237,14 +244,8 @@ public final class WhiteboardListViewController: UIViewController {
guard let dataSource = dataSource else { return }
dataSource.apply(snapshot, animatingDifferences: true)
}
private func bind() {
viewModel.output.whiteboardPublisher
.receive(on: DispatchQueue.main)
.sink { _ in
// TODO: 화이트보드 추가
}
.store(in: &cancellables)

private func bind() {
viewModel.output.whiteboardListPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] whiteboards in
Expand All @@ -253,6 +254,13 @@ public final class WhiteboardListViewController: UIViewController {
}
.store(in: &cancellables)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘 띵똥이 죽이지 않았나요 ??? whiteboardPublisher ??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MPC 버그 이슈를 롤백하면서 같이 부활했나봐요 ㅋㅋㅋ큐ㅠㅠ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제 완

}

private func refreshWhiteboardList() {
viewModel.action(input: .refreshWhiteboardList)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
self?.refreshControl.endRefreshing()
}
Comment on lines +260 to +262
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실제로는 화이트보드 리프레쉬가 완료되지 않았는데, endRefreshing이 되는 경우도 있을 것 같습니다.
물론 저희 로직이 실제 리프레쉬랑은 약간 다른 부분이 있긴 하지만요!! 일단 킵 고잉~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

킵코잉~

}
}

// MARK: - UICollectionViewDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public final class WhiteboardListViewModel: ViewModel {
case searchWhiteboard
case joinWhiteboard(whiteboard: Whiteboard)
case stopSearchingWhiteboard
case refreshWhiteboardList
}

struct Output {
let whiteboardPublisher: AnyPublisher<Whiteboard, Never>
let whiteboardListPublisher: AnyPublisher<[Whiteboard], Never>
}

Expand All @@ -32,7 +32,6 @@ public final class WhiteboardListViewModel: ViewModel {
self.whiteboardUseCase = whiteboardUseCase
whiteboardSubject = PassthroughSubject<Whiteboard, Never>()
self.output = Output(
whiteboardPublisher: whiteboardSubject.eraseToAnyPublisher(),
whiteboardListPublisher: whiteboardUseCase.whiteboardListPublisher)
}

Expand All @@ -46,6 +45,8 @@ public final class WhiteboardListViewModel: ViewModel {
joinWhiteboard(whiteboard: whiteboard)
case .stopSearchingWhiteboard:
stopSearchingWhiteboard()
case .refreshWhiteboardList:
refreshWhiteboardList()
}
}

Expand All @@ -70,4 +71,8 @@ public final class WhiteboardListViewModel: ViewModel {
private func stopSearchingWhiteboard() {
whiteboardUseCase.stopSearchingWhiteboard()
}

private func refreshWhiteboardList() {
whiteboardUseCase.refreshWhiteboardList()
}
}