From b7c7c656d9ff76273326506f5653f30ae5435495 Mon Sep 17 00:00:00 2001 From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> Date: Sat, 25 Nov 2023 21:50:01 -0500 Subject: [PATCH] donation: add notifications settings Change-Id: I8e8c3e5a0fd7f3811ae97b9a3a9cd0b3ed1072b8 --- Ring/Ring/Constants/Generated/Strings.swift | 4 +- .../GeneralSettingsViewController.swift | 25 ++++++++++ .../GeneralSettingsViewModel.swift | 50 ++++++++++++++----- .../Resources/en.lproj/Localizable.strings | 4 +- 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/Ring/Ring/Constants/Generated/Strings.swift b/Ring/Ring/Constants/Generated/Strings.swift index 81ce9c99e..2c8cb1a53 100644 --- a/Ring/Ring/Constants/Generated/Strings.swift +++ b/Ring/Ring/Constants/Generated/Strings.swift @@ -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 diff --git a/Ring/Ring/GeneralSettings/GeneralSettingsViewController.swift b/Ring/Ring/GeneralSettings/GeneralSettingsViewController.swift index bfb704f33..875dbb643 100644 --- a/Ring/Ring/GeneralSettings/GeneralSettingsViewController.swift +++ b/Ring/Ring/GeneralSettings/GeneralSettingsViewController.swift @@ -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 diff --git a/Ring/Ring/GeneralSettings/GeneralSettingsViewModel.swift b/Ring/Ring/GeneralSettings/GeneralSettingsViewModel.swift index d9fe1a746..305d3c3dc 100644 --- a/Ring/Ring/GeneralSettings/GeneralSettingsViewModel.swift +++ b/Ring/Ring/GeneralSettings/GeneralSettingsViewModel.swift @@ -42,6 +42,7 @@ enum GeneralSettingsSection: SectionModelType { case locationSharingDuration case sectionHeader(title: String) case log + case donationCampaign } var items: [SectionRow] { @@ -67,20 +68,30 @@ class GeneralSettingsViewModel: ViewModel, Stateable { }() lazy var generalSettings: Observable<[GeneralSettingsSection]> = { + var items: [GeneralSettingsSection.SectionRow] = [ + .sectionHeader(title: L10n.GeneralSettings.videoSettings), + .hardwareAcceleration, + .sectionHeader(title: L10n.GeneralSettings.fileTransfer), + .automaticallyAcceptIncomingFiles, + .acceptTransferLimit, + .sectionHeader(title: L10n.GeneralSettings.locationSharing), + .limitLocationSharingDuration, + .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: - [ - .sectionHeader(title: L10n.GeneralSettings.videoSettings), - .hardwareAcceleration, - .sectionHeader(title: L10n.GeneralSettings.fileTransfer), - .automaticallyAcceptIncomingFiles, - .acceptTransferLimit, - .sectionHeader(title: L10n.GeneralSettings.locationSharing), - .limitLocationSharingDuration, - .locationSharingDuration, - .sectionHeader(title: L10n.LogView.title), - .log - ])]) + .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 diff --git a/Ring/Ring/Resources/en.lproj/Localizable.strings b/Ring/Ring/Resources/en.lproj/Localizable.strings index bdad4910a..6e3feb83f 100644 --- a/Ring/Ring/Resources/en.lproj/Localizable.strings +++ b/Ring/Ring/Resources/en.lproj/Localizable.strings @@ -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 -- GitLab