Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
#206 홈화면 알림버튼관련 비즈니스 로직 및 화면이동 코드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
dlrjswns committed Sep 25, 2024
1 parent 233ebfc commit da290b9
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 5 deletions.
12 changes: 12 additions & 0 deletions ShowPot/ShowPot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
70DC8F6D2CA1B351006DDAF7 /* AlarmCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F6C2CA1B351006DDAF7 /* AlarmCollectionViewCell.swift */; };
70DC8F712CA27E37006DDAF7 /* MyAlarmListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F702CA27E37006DDAF7 /* MyAlarmListUseCase.swift */; };
70DC8F732CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F722CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift */; };
70DC8F762CA4A599006DDAF7 /* FetchNotificationUpdatesUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F752CA4A599006DDAF7 /* FetchNotificationUpdatesUseCase.swift */; };
70F3C0DB2C663A8900786738 /* MyShowAlarmViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F3C0DA2C663A8900786738 /* MyShowAlarmViewController.swift */; };
70F3C0DD2C663A9C00786738 /* MyShowAlarmViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F3C0DC2C663A9C00786738 /* MyShowAlarmViewModel.swift */; };
70F3C0DF2C663AA900786738 /* MyShowAlarmCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F3C0DE2C663AA900786738 /* MyShowAlarmCoordinator.swift */; };
Expand Down Expand Up @@ -436,6 +437,7 @@
70DC8F6C2CA1B351006DDAF7 /* AlarmCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmCollectionViewCell.swift; sourceTree = "<group>"; };
70DC8F702CA27E37006DDAF7 /* MyAlarmListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyAlarmListUseCase.swift; sourceTree = "<group>"; };
70DC8F722CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultMyAlarmListUseCase.swift; sourceTree = "<group>"; };
70DC8F752CA4A599006DDAF7 /* FetchNotificationUpdatesUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchNotificationUpdatesUseCase.swift; sourceTree = "<group>"; };
70F3C0DA2C663A8900786738 /* MyShowAlarmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyShowAlarmViewController.swift; sourceTree = "<group>"; };
70F3C0DC2C663A9C00786738 /* MyShowAlarmViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyShowAlarmViewModel.swift; sourceTree = "<group>"; };
70F3C0DE2C663AA900786738 /* MyShowAlarmCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyShowAlarmCoordinator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -889,6 +891,7 @@
70A95B812C7E29E80007836E /* Featured */ = {
isa = PBXGroup;
children = (
70DC8F742CA4A58E006DDAF7 /* Protocol */,
70A95B842C7E29FD0007836E /* DefaultFeaturedUseCase.swift */,
);
path = Featured;
Expand Down Expand Up @@ -1033,6 +1036,14 @@
path = MyAlarmList;
sourceTree = "<group>";
};
70DC8F742CA4A58E006DDAF7 /* Protocol */ = {
isa = PBXGroup;
children = (
70DC8F752CA4A599006DDAF7 /* FetchNotificationUpdatesUseCase.swift */,
);
path = Protocol;
sourceTree = "<group>";
};
70F3C0D92C663A7700786738 /* MyShowAlarm */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1973,6 +1984,7 @@
7DD2CB872C2ED63E0052ECCD /* MyPageCoordinator.swift in Sources */,
7DEDA5492C70DFD000B07818 /* UIImageView+Extension.swift in Sources */,
7D6005052C7F595500B670A3 /* UserAccessRequest.swift in Sources */,
70DC8F762CA4A599006DDAF7 /* FetchNotificationUpdatesUseCase.swift in Sources */,
7DD2CB812C2ED4430052ECCD /* FeaturedViewHolder.swift in Sources */,
700485112C7A382C00B9A964 /* TicketingAlarmBottomSheetViewController.swift in Sources */,
7D93096C2C569DFB000889DE /* SPSnackBar.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import Foundation
import RxSwift
import RxCocoa

final class DefaultFeaturedUseCase: SubscribeArtistUseCase, AllPerformanceUseCase {
final class DefaultFeaturedUseCase: SubscribeArtistUseCase, AllPerformanceUseCase, FetchNotificationUpdatesUseCase {

private let disposeBag = DisposeBag()
private let apiService: APIClient

var artistList = BehaviorRelay<[FeaturedSubscribeArtistCellModel]>(value: [])
var performanceList = BehaviorRelay<[FeaturedPerformanceWithTicketOnSaleSoonCellModel]>(value: [])
var subscribeArtistResult = PublishSubject<Bool>()
var hasNewNotifications = BehaviorRelay<Bool>(value: false)

init(apiService: APIClient = APIClient()) {
self.apiService = apiService
Expand Down Expand Up @@ -68,4 +69,8 @@ final class DefaultFeaturedUseCase: SubscribeArtistUseCase, AllPerformanceUseCas
}
.disposed(by: disposeBag)
}

func fetchNotificationUpdates() {
hasNewNotifications.accept([true, false].shuffled()[0])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// FetchNotificationUpdatesUseCase.swift
// ShowPot
//
// Created by 이건준 on 9/26/24.
//

import RxCocoa

protocol FetchNotificationUpdatesUseCase {
var hasNewNotifications: BehaviorRelay<Bool> { get }
func fetchNotificationUpdates()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ final class FeaturedCoordinator: NavigationCoordinator {

}

// TODO: 각 화면 개발 이후, 실제 로직 추가 필요
extension FeaturedCoordinator {

func goToFeaturedSearchScreen() {
Expand Down Expand Up @@ -57,4 +56,10 @@ extension FeaturedCoordinator {
coordinator.start()
self.childCoordinators.append(coordinator)
}

func goToMyAlarmListViewController() {
let coordinator = MyAlarmListCoordinator(navigationController: self.navigationController)
coordinator.start()
self.childCoordinators.append(coordinator)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ final class FeaturedViewController: ViewController {

override func bind() {
let input = FeaturedViewModel.Input(
viewWillAppear: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in Void() },
requestFeaturedSectionModel: .just(()),
didTapSearchField: viewHolder.searchFieldTopView.rx.tapGesture().when(.recognized),
didTappedSubscribeGenreButton: didTappedSubscribeGenreButtonSubject,
didTappedSubscribeArtistButton: didTappedSubscribeArtistButtonSubject,
didTappedFeaturedCell: viewHolder.featuredCollectionView.rx.itemSelected.asObservable(),
didTappedWatchTheFullPerformanceButton: didTappedWatchTheFullPerformanceButtonSubject.asObservable()
didTappedWatchTheFullPerformanceButton: didTappedWatchTheFullPerformanceButtonSubject.asObservable(),
didTappedRightBarButton: viewHolder.alarmRightBarButton.rx.tap.asObservable()
)
let output = viewModel.transform(input: input)
output.updateFeaturedLayout
Expand All @@ -73,6 +75,12 @@ final class FeaturedViewController: ViewController {
owner.showLoginBottomSheet()
}
.disposed(by: disposeBag)

output.hasNewNotifications
.subscribe(with: self) { owner, hasNewNotifications in
owner.viewHolder.alarmRightBarButton.setImage(hasNewNotifications ? .icAlarmLargeOn : .icAlarmLarge, for: .normal)
}
.disposed(by: disposeBag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class FeaturedViewModel: ViewModelType {
var coordinator: FeaturedCoordinator
private let disposeBag = DisposeBag()

private let usecase: SubscribeArtistUseCase & AllPerformanceUseCase
private let usecase: SubscribeArtistUseCase & AllPerformanceUseCase & FetchNotificationUpdatesUseCase

private let subscribeGenreModelRelay = BehaviorRelay<[GenreType]>(value: [])
private let recommendedPerformanceModelRelay = BehaviorRelay<[FeaturedRecommendedPerformanceCellModel]>(value: [])
Expand All @@ -36,23 +36,26 @@ final class FeaturedViewModel: ViewModelType {
featuredSectionModelRelay.value
}

init(coordinator: FeaturedCoordinator, usecase: SubscribeArtistUseCase & AllPerformanceUseCase) {
init(coordinator: FeaturedCoordinator, usecase: SubscribeArtistUseCase & AllPerformanceUseCase & FetchNotificationUpdatesUseCase) {
self.coordinator = coordinator
self.usecase = usecase
}

struct Input {
let viewWillAppear: Observable<Void>
let requestFeaturedSectionModel: Observable<Void>
let didTapSearchField: Observable<UITapGestureRecognizer>
let didTappedSubscribeGenreButton: PublishSubject<Void>
let didTappedSubscribeArtistButton: PublishSubject<Void>
let didTappedFeaturedCell: Observable<IndexPath>
let didTappedWatchTheFullPerformanceButton: Observable<Void>
let didTappedRightBarButton: Observable<Void>
}

struct Output {
let updateFeaturedLayout: Signal<Void>
let showLoginBottomSheet: PublishSubject<Void>
let hasNewNotifications = PublishRelay<Bool>()
}

func transform(input: Input) -> Output {
Expand Down Expand Up @@ -82,6 +85,12 @@ final class FeaturedViewModel: ViewModelType {
}
.disposed(by: disposeBag)

input.didTappedRightBarButton
.subscribe(with: self) { owner, _ in
owner.coordinator.goToMyAlarmListViewController()
}
.disposed(by: disposeBag)

Observable.combineLatest(
subscribeGenreModelRelay,
usecase.artistList,
Expand All @@ -97,6 +106,12 @@ final class FeaturedViewModel: ViewModelType {
owner.updateFeaturedLayoutSubject.onNext(())
}
.disposed(by: disposeBag)

input.viewWillAppear
.subscribe(with: self) { owner, _ in
owner.usecase.fetchNotificationUpdates()
}
.disposed(by: disposeBag)
}

private func createOutput(from input: Input) -> Output {
Expand Down Expand Up @@ -152,6 +167,10 @@ final class FeaturedViewModel: ViewModelType {
}
.disposed(by: disposeBag)

usecase.hasNewNotifications
.bind(to: output.hasNewNotifications)
.disposed(by: disposeBag)

return output
}
}
Expand Down

0 comments on commit da290b9

Please sign in to comment.