Skip to content

Commit

Permalink
Move Rate Us, Tell Friends and Contact Us to MainSettings module
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Oct 6, 2023
1 parent 81662f0 commit 2fcb1d7
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 274 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import UIKit

struct AboutModule {

static func viewController() -> UIViewController {
let service = AboutService(
termsManager: App.shared.termsManager,
systemInfoManager: App.shared.systemInfoManager,
rateAppManager: App.shared.rateAppManager
termsManager: App.shared.termsManager,
systemInfoManager: App.shared.systemInfoManager
)
let releaseNotesService = ReleaseNotesService(appVersionManager: App.shared.appVersionManager)

let viewModel = AboutViewModel(service: service, releaseNotesService: releaseNotesService)

return AboutViewController(viewModel: viewModel, urlManager: UrlManager(inApp: true))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ import RxSwift
class AboutService {
private let termsManager: TermsManager
private let systemInfoManager: SystemInfoManager
private let rateAppManager: RateAppManager

init(termsManager: TermsManager, systemInfoManager: SystemInfoManager, rateAppManager: RateAppManager) {
init(termsManager: TermsManager, systemInfoManager: SystemInfoManager) {
self.termsManager = termsManager
self.systemInfoManager = systemInfoManager
self.rateAppManager = rateAppManager
}

}

extension AboutService {

var termsAccepted: Bool {
termsManager.termsAccepted
}
Expand All @@ -26,9 +22,4 @@ extension AboutService {
var appVersion: String {
systemInfoManager.appVersion.description
}

func rateApp() {
rateAppManager.forceShow()
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ComponentKit
import MessageUI
import RxCocoa
import RxSwift
import SafariServices
Expand Down Expand Up @@ -71,48 +70,6 @@ class AboutViewController: ThemeViewController {
tableView.deselectCell(withCoordinator: transitionCoordinator, animated: animated)
}

private func openTellFriends() {
let text = "settings_tell_friends.text".localized + "\n" + AppConfig.appWebPageLink
let activityViewController = UIActivityViewController(activityItems: [text], applicationActivities: [])
present(activityViewController, animated: true, completion: nil)
}

private func handleEmailContact() {
let email = AppConfig.reportEmail

if MFMailComposeViewController.canSendMail() {
let controller = MFMailComposeViewController()
controller.setToRecipients([email])
controller.mailComposeDelegate = self

present(controller, animated: true)
} else {
CopyHelper.copyAndNotify(value: email)
}
}

private func handleTelegramContact() {
navigationController?.pushViewController(PersonalSupportModule.viewController(), animated: true)
}

private func handleContact() {
let viewController = BottomSheetModule.viewController(
image: .local(image: UIImage(named: "at_24")?.withTintColor(.themeJacob)),
title: "settings.contact.title".localized,
items: [],
buttons: [
.init(style: .yellow, title: "settings.contact.via_email".localized, actionType: .afterClose) { [weak self] in
self?.handleEmailContact()
},
.init(style: .gray, title: "settings.contact.via_telegram".localized, actionType: .afterClose) { [weak self] in
self?.handleTelegramContact()
},
]
)

present(viewController, animated: true)
}

private func openTwitter() {
let account = AppConfig.appTwitterAccount

Expand Down Expand Up @@ -256,52 +213,6 @@ extension AboutViewController: SectionsDataSource {
),
]
),
Section(
id: "share",
footerState: .margin(height: .margin32),
rows: [
row(
id: "rate-us",
image: "rate_24",
title: "settings.about_app.rate_us".localized,
isFirst: true,
action: { [weak self] in
self?.viewModel.onTapRateApp()
}
),
row(
id: "tell-friends",
image: "share_1_24",
title: "settings.about_app.tell_friends".localized,
isLast: true,
action: { [weak self] in
self?.openTellFriends()
}
),
]
),
Section(
id: "contact",
footerState: .margin(height: .margin32),
rows: [
row(
id: "email",
image: "mail_24",
title: "settings.about_app.contact".localized,
isFirst: true,
isLast: true,
action: { [weak self] in
self?.handleContact()
}
),
]
),
]
}
}

extension AboutViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith _: MFMailComposeResult, error _: Error?) {
controller.dismiss(animated: true)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import RxSwift
import RxRelay
import RxCocoa
import RxRelay
import RxSwift

class AboutViewModel {
private let service: AboutService
Expand All @@ -18,17 +18,15 @@ class AboutViewModel {
termsAlertRelay = BehaviorRelay(value: !service.termsAccepted)

service.termsAcceptedObservable
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated))
.subscribe(onNext: { [weak self] accepted in
self?.termsAlertRelay.accept(!accepted)
})
.disposed(by: disposeBag)
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated))
.subscribe(onNext: { [weak self] accepted in
self?.termsAlertRelay.accept(!accepted)
})
.disposed(by: disposeBag)
}

}

extension AboutViewModel {

var openLinkSignal: Signal<String> {
openLinkRelay.asSignal()
}
Expand All @@ -52,9 +50,4 @@ extension AboutViewModel {
func onTapWebPageLink() {
openLinkRelay.accept(AppConfig.appWebPageLink)
}

func onTapRateApp() {
service.rateApp()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ struct MainSettingsModule {
systemInfoManager: App.shared.systemInfoManager,
currencyKit: App.shared.currencyKit,
walletConnectSessionManager: App.shared.walletConnectSessionManager,
subscriptionManager: App.shared.subscriptionManager
subscriptionManager: App.shared.subscriptionManager,
rateAppManager: App.shared.rateAppManager
)

let viewModel = MainSettingsViewModel(service: service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class MainSettingsService {
private let currencyKit: CurrencyKit.Kit
private let walletConnectSessionManager: WalletConnectSessionManager
private let subscriptionManager: SubscriptionManager
private let rateAppManager: RateAppManager

private let iCloudAvailableErrorRelay = BehaviorRelay<Bool>(value: false)
private let noWalletRequiredActionsRelay = BehaviorRelay<Bool>(value: false)

init(backupManager: BackupManager, cloudAccountBackupManager: CloudBackupManager, accountRestoreWarningManager: AccountRestoreWarningManager, accountManager: AccountManager, contactBookManager: ContactBookManager, passcodeManager: PasscodeManager, termsManager: TermsManager,
systemInfoManager: SystemInfoManager, currencyKit: CurrencyKit.Kit, walletConnectSessionManager: WalletConnectSessionManager, subscriptionManager: SubscriptionManager)
systemInfoManager: SystemInfoManager, currencyKit: CurrencyKit.Kit, walletConnectSessionManager: WalletConnectSessionManager, subscriptionManager: SubscriptionManager, rateAppManager: RateAppManager)
{
self.cloudAccountBackupManager = cloudAccountBackupManager
self.backupManager = backupManager
Expand All @@ -38,6 +39,7 @@ class MainSettingsService {
self.currencyKit = currencyKit
self.walletConnectSessionManager = walletConnectSessionManager
self.subscriptionManager = subscriptionManager
self.rateAppManager = rateAppManager

subscribe(disposeBag, contactBookManager.iCloudErrorObservable) { [weak self] error in
if error != nil, self?.contactBookManager.remoteSync ?? false {
Expand Down Expand Up @@ -149,6 +151,10 @@ extension MainSettingsService {
var analyticsLink: String {
AppConfig.analyticsLink
}

func rateApp() {
rateAppManager.forceShow()
}
}

extension MainSettingsService {
Expand Down
Loading

0 comments on commit 2fcb1d7

Please sign in to comment.