Commit db14649d by Demid Merzlyakov

Refactoring: a dedicated LocalizationChangeObserver.

parent 0b88a0b4
......@@ -235,6 +235,7 @@
CE578FE725FB415F00E8B85D /* LocationsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */; };
CE5F0CBC268A031800B99572 /* OneWeatherWidgetsBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5F0CBB268A031800B99572 /* OneWeatherWidgetsBundle.swift */; };
CE6BE4942634170800626822 /* USStateCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6BE4932634170800626822 /* USStateCode.swift */; };
CE6E411426EBC0E9009829AE /* LocalizationChangeObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6E411326EBC0E9009829AE /* LocalizationChangeObserver.swift */; };
CE7298C9267A34F3002745D0 /* BlendFIPSSource.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEEF40FF265E47FF00425D8F /* BlendFIPSSource.framework */; };
CE7298CC267A34F5002745D0 /* BlendHealthSource.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD3883C12657B6A10070FD6F /* BlendHealthSource.framework */; };
CE7298CE267A34F7002745D0 /* CoreDataStorage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD3884542657BA8B0070FD6F /* CoreDataStorage.framework */; };
......@@ -537,6 +538,7 @@
CE5F0CBB268A031800B99572 /* OneWeatherWidgetsBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneWeatherWidgetsBundle.swift; sourceTree = "<group>"; };
CE6BE4932634170800626822 /* USStateCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = USStateCode.swift; sourceTree = "<group>"; };
CE6E410026EB4A92009829AE /* StoreKitTestCertificate.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = StoreKitTestCertificate.cer; sourceTree = "<group>"; };
CE6E411326EBC0E9009829AE /* LocalizationChangeObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizationChangeObserver.swift; sourceTree = "<group>"; };
CE81A421266E289E00800EFF /* NativeAdView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAdView.swift; sourceTree = "<group>"; };
CE849DB52638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OneWeatherNotificationServiceExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
CE849DB72638C33600DEFFBD /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
......@@ -1429,6 +1431,7 @@
CDA5542C25EF7C9700A2E08C /* ReusableCellProtocol.swift */,
CD37D404260DFFDD002669D6 /* CellFactory.swift */,
CD647A3626B42BA4007C27DA /* ThreadSafeDictionary.swift */,
CE6E411326EBC0E9009829AE /* LocalizationChangeObserver.swift */,
);
path = Common;
sourceTree = "<group>";
......@@ -1939,6 +1942,7 @@
CD1DDD332602305200AC62B2 /* ForecastInfoCell.swift in Sources */,
CD8579792672214700CC4CDA /* UITableView+HeaderSize.swift in Sources */,
CDEE8AD725DA882200C289DE /* ForecastPeriodButton.swift in Sources */,
CE6E411426EBC0E9009829AE /* LocalizationChangeObserver.swift in Sources */,
CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */,
CD39F2F525DE9571009FE398 /* ArrowButton.swift in Sources */,
CD37D3FE260DF726002669D6 /* SettingsCellFactory.swift in Sources */,
......
//
// LocalizationChangeObserver.swift
// 1Weather
//
// Created by Demid Merzlyakov on 10.09.2021.
//
import Foundation
public class LocalizationChangeObserver: NSObject {
private let handler: () -> ()
private var notificationCenter: NotificationCenter {
NotificationCenter.default
}
public init(handler: @escaping () -> ()) {
self.handler = handler
super.init()
notificationCenter.addObserver(self, selector: #selector(notificationHandler), name: .localizationChange, object: nil)
}
deinit {
notificationCenter.removeObserver(self)
}
@objc
private func notificationHandler() {
handler()
}
}
......@@ -11,7 +11,7 @@ import OneWeatherAnalytics
class NWSAlertViewController: UIViewController {
private let coordinator: NWSAlertCoordinator
private let viewModel: NWSAlertViewModel
private var localizationObserver: Any?
private var localizationObserver: LocalizationChangeObserver!
private let tableView = UITableView()
......@@ -35,13 +35,7 @@ class NWSAlertViewController: UIViewController {
super.viewDidAppear(animated)
analytics(log: .ANALYTICS_VIEW_ALERT_DETAILS)
}
deinit {
if let observer = localizationObserver {
NotificationCenter.default.removeObserver(observer)
}
}
private func close() {
self.navigationController?.dismiss(animated: true, completion: { [weak self] in
guard let self = self else { return }
......@@ -64,9 +58,9 @@ extension NWSAlertViewController {
action: #selector(handleCloseButton))
navigationItem.leftBarButtonItem = closeButton
localizationObserver = NotificationCenter.default.addObserver(forName: .localizationChange, object: nil, queue: .main, using: { [weak self] _ in
localizationObserver = LocalizationChangeObserver { [weak self] in
self?.prepareNavigationBar()
})
}
}
func prepareNavigationBar() {
......
......@@ -12,7 +12,7 @@ import OneWeatherAnalytics
class NotificationsViewController: UIViewController {
private let coordinator: NotificationsCoordinator
private let viewModel = NotificationsViewModel()
private var localizationObserver: Any?
private var localizationObserver: LocalizationChangeObserver!
private let log = Logger(componentName: "NotificationsViewController")
private let tableView = UITableView()
......@@ -40,13 +40,6 @@ class NotificationsViewController: UIViewController {
analytics(log: .ANALYTICS_VIEW_ALERTS)
}
deinit {
if let observer = localizationObserver {
NotificationCenter.default.removeObserver(observer)
}
}
private func close() {
self.navigationController?.dismiss(animated: true, completion: { [weak self] in
guard let self = self else { return }
......@@ -69,10 +62,10 @@ private extension NotificationsViewController {
action: #selector(handleCloseButton))
navigationItem.leftBarButtonItem = closeButton
localizationObserver = NotificationCenter.default.addObserver(forName: .localizationChange, object: nil, queue: .main, using: { [weak self] _ in
localizationObserver = LocalizationChangeObserver { [weak self] in
self?.tableView.reloadData()
self?.prepareNavigationBar()
})
}
}
func prepareNavigationBar() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment