|
|
|
@ -36,12 +36,21 @@ class JournalDetailViewModel: ViewModel, ViewModelType {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let itemSelected = PublishSubject<AudioTrack>()
|
|
|
|
|
let items = BehaviorRelay<[JournalSection]>.init(value: [])
|
|
|
|
|
// let items = BehaviorRelay<[JournalSection]>.init(value: [])
|
|
|
|
|
|
|
|
|
|
let isExpand = BehaviorRelay<Bool>.init(value: false)
|
|
|
|
|
|
|
|
|
|
let journalNo: String
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init(journalNo: String, provider: IndieMusicAPI) {
|
|
|
|
|
self.journalNo = journalNo
|
|
|
|
|
|
|
|
|
|
super.init(provider: provider)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func transform(input: Input) -> Output {
|
|
|
|
|
let elements = BehaviorRelay<[JournalSection]>(value: [])
|
|
|
|
|
|
|
|
|
|
input.viewWillAppear.subscribe { (_) in
|
|
|
|
|
|
|
|
|
@ -56,17 +65,17 @@ class JournalDetailViewModel: ViewModel, ViewModelType {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let journalDetail = JournalDetail.init(audio: "", cover: "", title: "", artist: "", number: "", tags: [], date: 0, content: "", isExpand: false)
|
|
|
|
|
let item = AudioTrack.init(artists: [], availableMarkets: [""], discNumber: 0, durationMs: 0, explicit: false, externalUrls: ["": ""], id: "", name: "123", previewUrl: "")
|
|
|
|
|
|
|
|
|
|
let journalSection = JournalSection.init(items: [item, item, item, item], journalDetail: journalDetail)
|
|
|
|
|
|
|
|
|
|
items.accept([journalSection])
|
|
|
|
|
//
|
|
|
|
|
// let journalDetail = JournalDetail.init(audio: "", cover: "", title: "", artist: "", number: "", tags: [], date: 0, content: "", isExpand: false)
|
|
|
|
|
// let item = AudioTrack.init(artists: [], availableMarkets: [""], discNumber: 0, durationMs: 0, explicit: false, externalUrls: ["": ""], id: "", name: "123", previewUrl: "")
|
|
|
|
|
//
|
|
|
|
|
// let journalSection = JournalSection.init(items: [item, item, item, item], journalDetail: journalDetail)
|
|
|
|
|
//
|
|
|
|
|
// items.accept([journalSection])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input.selection.drive { indexPath in
|
|
|
|
|
guard let sectionItem = self.items.value.first?.items[indexPath.row] else { return }
|
|
|
|
|
guard let sectionItem = elements.value.first?.items[indexPath.row] else { return }
|
|
|
|
|
self.itemSelected.onNext(sectionItem)
|
|
|
|
|
}.disposed(by: rx.disposeBag)
|
|
|
|
|
|
|
|
|
@ -79,7 +88,25 @@ class JournalDetailViewModel: ViewModel, ViewModelType {
|
|
|
|
|
|
|
|
|
|
let isLick = BehaviorRelay<Bool>.init(value: false)
|
|
|
|
|
|
|
|
|
|
return Output.init(items: items,
|
|
|
|
|
|
|
|
|
|
self.requestMusic(journalNo: journalNo).subscribe { audioTrackArray in
|
|
|
|
|
|
|
|
|
|
let journalDetail = JournalDetail.init(audio: "", cover: "", title: "", artist: "", number: "", tags: [], date: 0, content: "", isExpand: false)
|
|
|
|
|
|
|
|
|
|
let journalSection = JournalSection.init(items: audioTrackArray, journalDetail: journalDetail)
|
|
|
|
|
elements.accept([journalSection])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} onError: { error in
|
|
|
|
|
|
|
|
|
|
}.disposed(by: rx.disposeBag)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Output.init(items: elements,
|
|
|
|
|
selection: input.selection,
|
|
|
|
|
itemSelected: itemSelected,
|
|
|
|
|
journalDetail: journal,
|
|
|
|
@ -90,4 +117,13 @@ class JournalDetailViewModel: ViewModel, ViewModelType {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func requestMusic(journalNo: String) -> Observable<[AudioTrack]> {
|
|
|
|
|
|
|
|
|
|
return self.provider.journalMusic(journalNo: journalNo)
|
|
|
|
|
.trackActivity(loading)
|
|
|
|
|
.trackError(error)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|