diff --git a/Ring/Ring/Constants/Generated/Strings.swift b/Ring/Ring/Constants/Generated/Strings.swift index 81ce9c99e33622321b0a833ab9a7c4be4d3d4b04..2c8cb1a536cdffbbcae9c6afd04abf82c63bdc67 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 bfb704f33cef886f26f711a4c258a614003883a4..875dbb643bba52990e9a280005fb33f0df7a5d5e 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 d9fe1a746b60306637b8335b84d58ffdfec3e865..305d3c3dcb37d9259c85db1b16b8b38349b49a40 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 bdad4910aaecf4fedf5dd8afbf97a62020541b5a..6e3feb83f8a7e8ecc0210594f2f38143d9809c6a 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