Skip to content
Open
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 @@ -22,6 +22,10 @@
"Today's Tasks" = "Today's Tasks";
"My Villagers" = "My Villagers";
"Collection Progress" = "Collection Progress";
"Now Playing" = "Now Playing";
"No song playing" = "No song playing";
"Tap to start playing K.K. songs" = "Tap to start playing K.K. songs";
"Loading songs..." = "Loading songs...";
"Residents who can visit randomly on weekdays" = "Residents who can visit randomly on weekdays";
"Residents who visit regularly" = "Residents who visit regularly";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"Today's Tasks" = "오늘의 할일";
"My Villagers" = "마을 주민";
"Collection Progress" = "수집 현황";
"Now Playing" = "지금 재생 중";
"No song playing" = "재생 중인 곡 없음";
"Tap to start playing K.K. songs" = "K.K. 슬라이더 음악을 재생하려면 탭하세요";
"Loading songs..." = "노래 불러오는 중...";
"Residents who can visit randomly on weekdays" = "평일에 랜덤하게 방문할 수 있는 주민";
"Residents who visit regularly" = "고정으로 방문하는 주민";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ final class DashboardCoordinator: Coordinator {
villagersVM: VillagersSectionReactor(coordinator: self),
progressVM: CollectionProgressSectionReactor(coordinator: self),
fixeVisitdNPCListVM: NpcsSectionReactor(state: .init(), mode: .fixedVisit, coordinator: self),
randomVisitNPCListVM: NpcsSectionReactor(state: .init(), mode: .randomVisit, coordinator: self)
randomVisitNPCListVM: NpcsSectionReactor(state: .init(), mode: .randomVisit, coordinator: self),
musicPlayerVM: MusicPlayerSectionReactor()
)
rootViewController.addChild(viewController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ final class DashboardViewController: UIViewController {
villagersVM: VillagersSectionReactor,
progressVM: CollectionProgressSectionReactor,
fixeVisitdNPCListVM: NpcsSectionReactor,
randomVisitNPCListVM: NpcsSectionReactor
randomVisitNPCListVM: NpcsSectionReactor,
musicPlayerVM: MusicPlayerSectionReactor
) {
let userInfoSection = SectionView(
title: "My Island".localized,
Expand All @@ -85,6 +86,11 @@ final class DashboardViewController: UIViewController {
iconName: "chart.pie.fill",
contentView: CollectionProgressView(viewModel: progressVM)
)
let musicPlayerSection = SectionView(
title: "Now Playing".localized,
iconName: "music.note",
contentView: MusicPlayerSectionView(musicPlayerVM)
)
let randomVisitResidentsSectionView = SectionView(
title: "Residents who can visit randomly on weekdays".localized,
iconName: "bubbles.and.sparkles.fill",
Expand All @@ -96,10 +102,11 @@ final class DashboardViewController: UIViewController {
contentView: NpcsView(fixeVisitdNPCListVM)
)
sectionsScrollView.addSection(userInfoSection,
tasksSection,
villagersSection,
progressSection,
randomVisitResidentsSectionView,
tasksSection,
villagersSection,
progressSection,
musicPlayerSection,
randomVisitResidentsSectionView,
fixedVisitResidentsSectionView)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// MusicPlayerSectionReactor.swift
// Animal-Crossing-Wiki
//
// Created by Claude on 2025/01/01.
//

import Foundation
import ReactorKit

final class MusicPlayerSectionReactor: Reactor {

enum Action {
case playPauseTapped
case previousTapped
case nextTapped
}

enum Mutation {
case setCurrentSong(Item?)
case setIsPlaying(Bool)
case setProgress(Float)
case setSongsAvailable(Bool)
}

struct State {
var currentSong: Item?
var isPlaying: Bool = false
var progress: Float = 0
var isSongsAvailable: Bool = false
}

let initialState: State = State()
private let musicPlayerManager: MusicPlayerManager

init(musicPlayerManager: MusicPlayerManager = .shared) {
self.musicPlayerManager = musicPlayerManager
}

func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let currentSongMutation = musicPlayerManager.currentMusic
.map { Mutation.setCurrentSong($0) }

let isPlayingMutation = musicPlayerManager.isNowPlaying
.map { Mutation.setIsPlaying($0 ?? false) }

let progressMutation = musicPlayerManager.songProgress
.map { Mutation.setProgress($0) }

let songsAvailableMutation = musicPlayerManager.songList
.map { Mutation.setSongsAvailable(!$0.isEmpty) }

return Observable.merge(
mutation,
currentSongMutation,
isPlayingMutation,
progressMutation,
songsAvailableMutation
)
}

func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .playPauseTapped:
musicPlayerManager.togglePlaying()
return .empty()

case .previousTapped:
musicPlayerManager.prev()
return .empty()

case .nextTapped:
musicPlayerManager.next()
return .empty()
}
}

func reduce(state: State, mutation: Mutation) -> State {
var newState = state
switch mutation {
case .setCurrentSong(let song):
newState.currentSong = song
case .setIsPlaying(let isPlaying):
newState.isPlaying = isPlaying
case .setProgress(let progress):
newState.progress = progress
case .setSongsAvailable(let isAvailable):
newState.isSongsAvailable = isAvailable
}
return newState
}
}
Loading