2022-01-27 14:23:39 +01:00
|
|
|
//
|
|
|
|
// NotificationView+ViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2022-1-21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2022-02-11 12:27:14 +01:00
|
|
|
import Combine
|
2022-01-27 14:23:39 +01:00
|
|
|
import CoreDataStack
|
2023-11-22 12:32:04 +01:00
|
|
|
import MastodonSDK
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
extension NotificationTableViewCell {
|
|
|
|
final class ViewModel {
|
|
|
|
let value: Value
|
|
|
|
|
|
|
|
init(value: Value) {
|
|
|
|
self.value = value
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Value {
|
2023-11-22 12:32:04 +01:00
|
|
|
case feed(MastodonFeed)
|
2022-01-27 14:23:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationTableViewCell {
|
|
|
|
|
|
|
|
func configure(
|
|
|
|
tableView: UITableView,
|
|
|
|
viewModel: ViewModel,
|
|
|
|
delegate: NotificationTableViewCellDelegate?
|
|
|
|
) {
|
|
|
|
if notificationView.frame == .zero {
|
|
|
|
// set status view width
|
2022-02-10 08:03:57 +01:00
|
|
|
notificationView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin
|
2023-09-21 12:52:05 +02:00
|
|
|
|
2022-02-10 08:03:57 +01:00
|
|
|
notificationView.statusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin
|
2022-02-18 11:25:26 +01:00
|
|
|
notificationView.quoteStatusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin // the as same width as statusView
|
2022-01-27 14:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch viewModel.value {
|
|
|
|
case .feed(let feed):
|
|
|
|
notificationView.configure(feed: feed)
|
|
|
|
}
|
2022-02-11 12:27:14 +01:00
|
|
|
|
|
|
|
self.delegate = delegate
|
|
|
|
|
|
|
|
Publishers.CombineLatest(
|
|
|
|
notificationView.statusView.viewModel.$isContentReveal.removeDuplicates(),
|
|
|
|
notificationView.quoteStatusView.viewModel.$isContentReveal.removeDuplicates()
|
|
|
|
)
|
|
|
|
.dropFirst()
|
|
|
|
.receive(on: DispatchQueue.main)
|
2023-09-21 14:11:44 +02:00
|
|
|
.sink { [weak tableView] _, _ in
|
2022-02-11 12:27:14 +01:00
|
|
|
guard let tableView = tableView else { return }
|
|
|
|
|
|
|
|
UIView.performWithoutAnimation {
|
|
|
|
tableView.beginUpdates()
|
|
|
|
tableView.endUpdates()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
2022-01-27 14:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|