Skip to content
Snippets Groups Projects
Commit b7c7c656 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

donation: add notifications settings

Change-Id: I8e8c3e5a0fd7f3811ae97b9a3a9cd0b3ed1072b8
parent bd9435a7
Branches
No related tags found
No related merge requests found
......@@ -433,9 +433,9 @@ internal enum L10n {
/// Automatically accept incoming files
internal static let automaticAcceptIncomingFiles = L10n.tr("Localizable", "generalSettings.automaticAcceptIncomingFiles", fallback: "Automatically accept incoming files")
/// Donation campaign
internal static let donationCanpaign = L10n.tr("Localizable", "generalSettings.donationCanpaign", fallback: "Donation campaign")
internal static let donationCampaign = L10n.tr("Localizable", "generalSettings.donationCampaign", fallback: "Donation campaign")
/// Enable donation campaign
internal static let enableDonationCanpaign = L10n.tr("Localizable", "generalSettings.enableDonationCanpaign", fallback: "Enable donation campaign")
internal static let enableDonationCampaign = L10n.tr("Localizable", "generalSettings.enableDonationCampaign", fallback: "Enable donation campaign")
/// File transfer
internal static let fileTransfer = L10n.tr("Localizable", "generalSettings.fileTransfer", fallback: "File transfer")
/// Limit the duration of location sharing
......
......@@ -107,6 +107,8 @@ class GeneralSettingsViewController: UIViewController, StoryboardBased, ViewMode
return self.makeLimitLocationSharingCell()
case .locationSharingDuration:
return self.makeLocationSharingDurationCell()
case .donationCampaign:
return self.makeDoantionCell()
case .log:
let cell = DisposableCell()
cell.textLabel?.text = L10n.LogView.description
......@@ -133,6 +135,29 @@ class GeneralSettingsViewController: UIViewController, StoryboardBased, ViewMode
.disposed(by: disposeBag)
}
func makeDoantionCell() -> DisposableCell {
let cell = DisposableCell()
cell.textLabel?.text = L10n.GeneralSettings.enableDonationCampaign
cell.textLabel?.font = self.defaultFont
let switchView = UISwitch()
cell.selectionStyle = .none
cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
cell.accessoryView = switchView
self.viewModel.enableDonationCampaign
.asObservable()
.observe(on: MainScheduler.instance)
.startWith(viewModel.enableDonationCampaign.value)
.bind(to: switchView.rx.value)
.disposed(by: cell.disposeBag)
switchView.rx.value
.observe(on: MainScheduler.instance)
.subscribe(onNext: { [weak self] (enabled) in
self?.viewModel.togleEnableDonationCampaign(enable: enabled)
})
.disposed(by: cell.disposeBag)
return cell
}
func makeAutoDownloadFilesCell() -> DisposableCell {
let cell = DisposableCell()
cell.textLabel?.text = L10n.GeneralSettings.automaticAcceptIncomingFiles
......
......@@ -42,6 +42,7 @@ enum GeneralSettingsSection: SectionModelType {
case locationSharingDuration
case sectionHeader(title: String)
case log
case donationCampaign
}
var items: [SectionRow] {
......@@ -67,9 +68,7 @@ class GeneralSettingsViewModel: ViewModel, Stateable {
}()
lazy var generalSettings: Observable<[GeneralSettingsSection]> = {
return Observable
.just([GeneralSettingsSection.generalSettings(items:
[
var items: [GeneralSettingsSection.SectionRow] = [
.sectionHeader(title: L10n.GeneralSettings.videoSettings),
.hardwareAcceleration,
.sectionHeader(title: L10n.GeneralSettings.fileTransfer),
......@@ -77,10 +76,22 @@ class GeneralSettingsViewModel: ViewModel, Stateable {
.acceptTransferLimit,
.sectionHeader(title: L10n.GeneralSettings.locationSharing),
.limitLocationSharingDuration,
.locationSharingDuration,
.locationSharingDuration
]
if !PreferenceManager.isReachEndOfDonationCampaign() {
items.append(contentsOf: [
.sectionHeader(title: L10n.GeneralSettings.donationCampaign),
.donationCampaign
])
}
items.append(contentsOf: [
.sectionHeader(title: L10n.LogView.title),
.log
])])
])
return Observable
.just([GeneralSettingsSection.generalSettings(items: items)])
}()
var hardwareAccelerationEnabled: BehaviorRelay<Bool>
......@@ -88,6 +99,7 @@ class GeneralSettingsViewModel: ViewModel, Stateable {
var acceptTransferLimit: BehaviorRelay<String>
var limitLocationSharingDuration: BehaviorRelay<Bool>
var locationSharingDuration: BehaviorRelay<Int>
var enableDonationCampaign: BehaviorRelay<Bool>
var locationSharingDurationText: String {
return convertMinutesToText(minutes: locationSharingDuration.value)
}
......@@ -115,6 +127,7 @@ class GeneralSettingsViewModel: ViewModel, Stateable {
let locationSharingDurationValue = UserDefaults.standard.integer(forKey: locationSharingDurationKey)
locationSharingDuration = BehaviorRelay<Int>(value: locationSharingDurationValue)
enableDonationCampaign = BehaviorRelay<Bool>(value: PreferenceManager.isCampaignEnabled())
}
func togleHardwareAcceleration(enable: Bool) {
......@@ -156,6 +169,17 @@ class GeneralSettingsViewModel: ViewModel, Stateable {
self.stateSubject.onNext(SettingsState.openLog)
}
func togleEnableDonationCampaign(enable: Bool) {
if enableDonationCampaign.value == enable {
return
}
PreferenceManager.setCampaignEnabled(enable)
if enable {
PreferenceManager.setStartDonationDate(DefaultValues.donationStartDate)
}
enableDonationCampaign.accept(enable)
}
func changeTransferLimit(value: String) {
if acceptTransferLimit.value == value {
return
......
......@@ -379,8 +379,8 @@
"generalSettings.acceptTransferLimitDescription" = "(in MB, 0 = unlimited)";
"generalSettings.limitLocationSharingDuration" = "Limit the duration of location sharing";
"generalSettings.locationSharingDuration" = "Position share duration";
"generalSettings.donationCanpaign" = "Donation campaign";
"generalSettings.enableDonationCanpaign" = "Enable donation campaign";
"generalSettings.donationCampaign" = "Donation campaign";
"generalSettings.enableDonationCampaign" = "Enable donation campaign";
//Log View
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment