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

donations: add settings in account

Change-Id: I15ff958e64bb298914bc2db188bd5fde0928bd49
parent b7c7c656
Branches
No related tags found
No related merge requests found
...@@ -683,6 +683,10 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas ...@@ -683,6 +683,10 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
.configureTurnCell(cellType: .turnRealm, .configureTurnCell(cellType: .turnRealm,
value: self.viewModel.turnRealm.value) value: self.viewModel.turnRealm.value)
return cell return cell
case .donationCampaign:
return self.createDonationNotificationCell()
case .donate:
return self.createDonationCell()
} }
} }
...@@ -695,6 +699,50 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas ...@@ -695,6 +699,50 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
.disposed(by: disposeBag) .disposed(by: disposeBag)
} }
func createDonationCell() -> UITableViewCell {
let cell = DisposableCell()
cell.textLabel?.text = L10n.Global.donate
cell.textLabel?.textColor = UIColor.jamiButtonDark
cell.textLabel?.textAlignment = .center
cell.textLabel?.numberOfLines = 0
cell.selectionStyle = .none
cell.sizeToFit()
let button = UIButton.init(frame: cell.frame)
let size = CGSize(width: self.settingsTable.frame.width, height: button.frame.height)
button.frame.size = size
cell.addSubview(button)
button.rx.tap
.subscribe(onNext: { [weak self] in
self?.viewModel.donate()
})
.disposed(by: cell.disposeBag)
cell.backgroundColor = .clear
cell.contentView.backgroundColor = .systemBackground
return cell
}
func createDonationNotificationCell() -> DisposableCell {
let cell = DisposableCell()
cell.textLabel?.text = L10n.GeneralSettings.enableDonationCampaign
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 configureCellWithEnableTextCopy(text: String, secondaryText: String, style: UIFont.TextStyle) -> DisposableCell { func configureCellWithEnableTextCopy(text: String, secondaryText: String, style: UIFont.TextStyle) -> DisposableCell {
let cell = DisposableCell(style: .subtitle, reuseIdentifier: self.jamiIDCell) let cell = DisposableCell(style: .subtitle, reuseIdentifier: self.jamiIDCell)
cell.selectionStyle = .none cell.selectionStyle = .none
......
...@@ -37,6 +37,7 @@ enum SettingsSection: SectionModelType { ...@@ -37,6 +37,7 @@ enum SettingsSection: SectionModelType {
case connectivitySettings(items: [SectionRow]) case connectivitySettings(items: [SectionRow])
case credentials(items: [SectionRow]) case credentials(items: [SectionRow])
case otherSettings(items: [SectionRow]) case otherSettings(items: [SectionRow])
case donations(items: [SectionRow])
case removeAccountSettings(items: [SectionRow]) case removeAccountSettings(items: [SectionRow])
enum SectionRow { enum SectionRow {
...@@ -67,11 +68,20 @@ enum SettingsSection: SectionModelType { ...@@ -67,11 +68,20 @@ enum SettingsSection: SectionModelType {
case turnPassword case turnPassword
case turnRealm case turnRealm
case upnpEnabled case upnpEnabled
case donationCampaign
case donate
} }
var items: [SectionRow] { var items: [SectionRow] {
switch self { switch self {
case .linkedDevices(let items), .removeAccountSettings(items: let items), .notificationSettings(let items), .connectivitySettings(let items), .credentials(let items), .otherSettings(items: let items), .accountSettings(items: let items): case .linkedDevices(let items),
.removeAccountSettings(items: let items),
.notificationSettings(let items),
.connectivitySettings(let items),
.credentials(let items),
.otherSettings(items: let items),
.accountSettings(items: let items),
.donations(items: let items):
return items return items
} }
} }
...@@ -90,7 +100,9 @@ enum SettingsSection: SectionModelType { ...@@ -90,7 +100,9 @@ enum SettingsSection: SectionModelType {
return L10n.AccountPage.connectivityHeader return L10n.AccountPage.connectivityHeader
case .credentials: case .credentials:
return L10n.AccountPage.credentialsHeader return L10n.AccountPage.credentialsHeader
case .accountSettings(items: let items): case .donations(items: _):
return L10n.Global.donate
case .accountSettings(items: _):
return nil return nil
} }
} }
...@@ -111,6 +123,8 @@ enum SettingsSection: SectionModelType { ...@@ -111,6 +123,8 @@ enum SettingsSection: SectionModelType {
self = .otherSettings(items: items) self = .otherSettings(items: items)
case .removeAccountSettings(items: let items): case .removeAccountSettings(items: let items):
self = .removeAccountSettings(items: items) self = .removeAccountSettings(items: items)
case .donations(items: let items):
self = .donations(items: items)
} }
} }
} }
...@@ -207,6 +221,20 @@ class MeViewModel: ViewModel, Stateable { ...@@ -207,6 +221,20 @@ class MeViewModel: ViewModel, Stateable {
.just(.notificationSettings( items: [.notifications])) .just(.notificationSettings( items: [.notifications]))
}() }()
lazy var donationsSettings: Observable<SettingsSection> = {
var items: [SettingsSection.SectionRow] = []
if !PreferenceManager.isReachEndOfDonationCampaign() {
items.append(contentsOf: [
.donationCampaign
])
}
items.append(contentsOf: [
.donate
])
return Observable
.just(.donations( items: items))
}()
lazy var connectivitySettings: Observable<SettingsSection> = { lazy var connectivitySettings: Observable<SettingsSection> = {
var server = "" var server = ""
var username = "" var username = ""
...@@ -261,11 +289,12 @@ class MeViewModel: ViewModel, Stateable { ...@@ -261,11 +289,12 @@ class MeViewModel: ViewModel, Stateable {
lazy var jamiSettings: Observable<[SettingsSection]> = { lazy var jamiSettings: Observable<[SettingsSection]> = {
Observable.combineLatest(accountCredentials, Observable.combineLatest(accountCredentials,
linkedDevices, linkedDevices,
donationsSettings,
accountJamiSettings, accountJamiSettings,
connectivitySettings, connectivitySettings,
otherJamiSettings, otherJamiSettings,
removeAccountSettings) { (credentials, devices, settings, connectivity, other, removeAccount) in removeAccountSettings) { (credentials, devices, donate, settings, connectivity, other, removeAccount) in
return [credentials, devices, settings, connectivity, other, removeAccount] return [credentials, devices, donate, settings, connectivity, other, removeAccount]
} }
}() }()
...@@ -323,8 +352,9 @@ class MeViewModel: ViewModel, Stateable { ...@@ -323,8 +352,9 @@ class MeViewModel: ViewModel, Stateable {
lazy var sipSettings: Observable<[SettingsSection]> = { lazy var sipSettings: Observable<[SettingsSection]> = {
Observable.combineLatest(sipCredentials, Observable.combineLatest(sipCredentials,
otherSipSettings) { (credentials, other) in donationsSettings,
return [credentials, other] otherSipSettings) { (credentials, donate, other) in
return [credentials, donate, other]
} }
}() }()
...@@ -354,6 +384,7 @@ class MeViewModel: ViewModel, Stateable { ...@@ -354,6 +384,7 @@ class MeViewModel: ViewModel, Stateable {
self.contactService = injectionBag.contactsService self.contactService = injectionBag.contactsService
self.presenceService = injectionBag.presenceService self.presenceService = injectionBag.presenceService
self.secureTextEntry.onNext(true) self.secureTextEntry.onNext(true)
self.enableDonationCampaign = BehaviorRelay<Bool>(value: PreferenceManager.isCampaignEnabled())
} }
func updateDataFor(account: AccountModel) { func updateDataFor(account: AccountModel) {
...@@ -554,6 +585,8 @@ class MeViewModel: ViewModel, Stateable { ...@@ -554,6 +585,8 @@ class MeViewModel: ViewModel, Stateable {
let currentAccountProxy = PublishSubject<Bool>() let currentAccountProxy = PublishSubject<Bool>()
let currentAccountState = PublishSubject<AccountState>() let currentAccountState = PublishSubject<AccountState>()
var enableDonationCampaign: BehaviorRelay<Bool>
lazy var accountState: Observable<AccountState> = { lazy var accountState: Observable<AccountState> = {
var state = AccountState.registered var state = AccountState.registered
if let account = self.accountService.currentAccount { if let account = self.accountService.currentAccount {
...@@ -807,6 +840,21 @@ class MeViewModel: ViewModel, Stateable { ...@@ -807,6 +840,21 @@ class MeViewModel: ViewModel, Stateable {
keepAliveEnabled.accept(enable) keepAliveEnabled.accept(enable)
} }
func donate() {
SharedActionsPresenter.openDonationLink()
}
func togleEnableDonationCampaign(enable: Bool) {
if enableDonationCampaign.value == enable {
return
}
PreferenceManager.setCampaignEnabled(enable)
if enable {
PreferenceManager.setStartDonationDate(DefaultValues.donationStartDate)
}
enableDonationCampaign.accept(enable)
}
// MARK: Connectivity // MARK: Connectivity
lazy var turnEnabled: BehaviorRelay<Bool> = { lazy var turnEnabled: BehaviorRelay<Bool> = {
if let account = self.accountService.currentAccount, if let account = self.accountService.currentAccount,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment