2022-01-27 14:23:39 +01:00
//
// S t a t u s T a b l e V i e w C e l l + V i e w M o d e l . s w i f t
// M a s t o d o n
//
// C r e a t e d b y M a i n a s u K o n 2 0 2 2 - 1 - 1 2 .
//
import UIKit
import CoreDataStack
extension StatusTableViewCell {
final class ViewModel {
let value : Value
init ( value : Value ) {
self . value = value
}
enum Value {
case feed ( Feed )
case status ( Status )
}
}
}
extension StatusTableViewCell {
func configure (
tableView : UITableView ,
viewModel : ViewModel ,
delegate : StatusTableViewCellDelegate ?
) {
if statusView . frame = = . zero {
// s e t s t a t u s v i e w w i d t h
statusView . frame . size . width = tableView . frame . width
logger . log ( level : . debug , " \( ( #file as NSString ) . lastPathComponent , privacy : . public ) [ \( #line , privacy : . public ) ], \( #function , privacy : . public ) : did layout for new cell " )
}
2022-01-29 10:02:30 +01:00
2022-01-27 14:23:39 +01:00
switch viewModel . value {
case . feed ( let feed ) :
statusView . configure ( feed : feed )
feed . publisher ( for : \ . hasMore )
. sink { [ weak self ] hasMore in
guard let self = self else { return }
self . separatorLine . isHidden = hasMore
}
. store ( in : & disposeBag )
case . status ( let status ) :
statusView . configure ( status : status )
}
2022-01-29 10:02:30 +01:00
self . delegate = delegate
statusView . viewModel . $ isContentReveal
. removeDuplicates ( )
. dropFirst ( )
. receive ( on : DispatchQueue . main )
. sink { [ weak tableView , weak self ] isContentReveal in
guard let tableView = tableView else { return }
guard let self = self else { return }
tableView . beginUpdates ( )
tableView . endUpdates ( )
}
. store ( in : & disposeBag )
2022-01-27 14:23:39 +01:00
}
}