add footer button

pull/941/head
ryanzhao 2 years ago
parent c758ef4d27
commit 6c4adc08e1

@ -44,6 +44,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
private let threadVariant: SessionThread.Variant private let threadVariant: SessionThread.Variant
private let config: DisappearingMessagesConfiguration private let config: DisappearingMessagesConfiguration
private var currentSelection: CurrentValueSubject<DisappearingMessagesConfiguration, Error> private var currentSelection: CurrentValueSubject<DisappearingMessagesConfiguration, Error>
private var shouldShowConfirmButton: CurrentValueSubject<Bool, Never>
// MARK: - Initialization // MARK: - Initialization
@ -58,6 +59,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
self.threadVariant = threadVariant self.threadVariant = threadVariant
self.config = config self.config = config
self.currentSelection = CurrentValueSubject(self.config) self.currentSelection = CurrentValueSubject(self.config)
self.shouldShowConfirmButton = CurrentValueSubject(false)
} }
// MARK: - Content // MARK: - Content
@ -68,6 +70,21 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
private var _settingsData: [SectionModel] = [] private var _settingsData: [SectionModel] = []
public override var settingsData: [SectionModel] { _settingsData } public override var settingsData: [SectionModel] { _settingsData }
override var footerButtonInfo: AnyPublisher<SessionButton.Info?, Never> {
self.shouldShowConfirmButton
.removeDuplicates()
.map { [weak self] shouldShowConfirmButton in
guard shouldShowConfirmButton else { return nil }
return SessionButton.Info(
style: .bordered,
title: "DISAPPERING_MESSAGES_SAVE_TITLE".localized(),
isEnabled: true,
onTap: { self?.saveChanges() }
)
}
.eraseToAnyPublisher()
}
public override var observableSettingsData: ObservableData { _observableSettingsData } public override var observableSettingsData: ObservableData { _observableSettingsData }
/// This is all the data the screen needs to populate itself, please see the following link for tips to help optimise /// This is all the data the screen needs to populate itself, please see the following link for tips to help optimise
@ -101,6 +118,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
durationSeconds: 0, durationSeconds: 0,
type: nil type: nil
) )
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
), ),
@ -118,6 +136,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
durationSeconds: (24 * 60 * 60), durationSeconds: (24 * 60 * 60),
type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterRead type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterRead
) )
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
), ),
@ -135,6 +154,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
durationSeconds: (24 * 60 * 60), durationSeconds: (24 * 60 * 60),
type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterSend type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterSend
) )
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
) )
@ -160,6 +180,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
.with( .with(
durationSeconds: duration durationSeconds: duration
) )
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
) )
@ -184,6 +205,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
durationSeconds: 0, durationSeconds: 0,
type: nil type: nil
) )
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
) )
@ -206,6 +228,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
durationSeconds: duration, durationSeconds: duration,
type: .disappearAfterSend type: .disappearAfterSend
) )
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
) )

Loading…
Cancel
Save