feat: code review notes

This commit is contained in:
Nikita Semenov 2022-11-18 18:53:28 +03:00
parent 1c1fa1290b
commit 4778f2e70d
4 changed files with 53 additions and 20 deletions

View File

@ -41,11 +41,12 @@ final public class LoggingPresenter {
}
/// Shows the UIWindow with a button that opens a logging list view.
public func addLogsButton(to scene: UIWindowScene? = nil) {
window = .init(frame: UIScreen.main.bounds)
public func addLogsButton(to scene: UIWindowScene? = nil,
windowRect rect: CGRect = UIScreen.main.bounds) {
window = .init(frame: rect)
showWindow(withScene: scene)
window?.setDefaultRootController()
window?.set(isVisible: true)
window?.set(isRegisteredForShakingEvent: false)
}

View File

@ -51,6 +51,7 @@ open class LogsListViewController: BaseInitializeableViewController,
public typealias Snapshot = NSDiffableDataSourceSnapshot<String, OSLogEntryLog>
public let viewModel = LogsStorageViewModel()
public var logsFileExtension = "log"
// MARK: - Life cycle
@ -117,7 +118,8 @@ open class LogsListViewController: BaseInitializeableViewController,
viewModel.logsListView = self
searchView.delegate = self
tableView.register(LogEntryTableViewCell.self, forCellReuseIdentifier: "identifier")
tableView.register(LogEntryTableViewCell.self,
forCellReuseIdentifier: LogEntryTableViewCell.reuseIdentifier)
refreshControl.addTarget(self, action: #selector(reloadLogs), for: .valueChanged)
shareButton.addTarget(self, action: #selector(shareLogs), for: .touchUpInside)
}
@ -170,7 +172,7 @@ open class LogsListViewController: BaseInitializeableViewController,
}
timer?.invalidate()
timer = Timer.scheduledTimer(timeInterval: 3,
timer = Timer.scheduledTimer(timeInterval: 1,
target: self,
selector: #selector(filterLogsByText),
userInfo: nil,
@ -182,14 +184,14 @@ open class LogsListViewController: BaseInitializeableViewController,
}
open func textFieldDidEndEditing(_ textField: UITextField) {
viewModel.fileCreator = .init(fileName: textField.text ?? "", fileExtension: "log")
viewModel.fileCreator = .init(fileName: textField.text ?? "", fileExtension: logsFileExtension)
}
// MARK: - Open methods
open func createDataSource() -> DataSource {
let cellProvider: DataSource.CellProvider = { collectionView, indexPath, itemIdentifier in
let cell = collectionView.dequeueReusableCell(withIdentifier: "identifier",
let cell = collectionView.dequeueReusableCell(withIdentifier: LogEntryTableViewCell.reuseIdentifier,
for: indexPath) as? LogEntryTableViewCell
cell?.configure(with: itemIdentifier)

View File

@ -20,6 +20,7 @@
// THE SOFTWARE.
//
import TIUIKitCore
import UIKit
@available(iOS 15, *)
@ -34,6 +35,7 @@ public final class LoggingTogglingWindow: UIWindow {
override public init(frame: CGRect) {
super.init(frame: frame)
rootViewController = loggingController
windowLevel = .statusBar
backgroundColor = .clear
}
@ -70,10 +72,6 @@ public final class LoggingTogglingWindow: UIWindow {
// MARK: - Public methdos
public func setDefaultRootController() {
rootViewController = loggingController
}
public func set(isRegisteredForShakingEvent: Bool) {
loggingController.set(isRegisteredForShakingEvent: isRegisteredForShakingEvent)
}
@ -97,7 +95,7 @@ public final class LoggingTogglingWindow: UIWindow {
return
}
let topViewController = getTopViewController(from: rootViewController)
let topViewController = rootViewController.topVisibleViewController
topViewController.present(LogsListViewController(), animated: true, completion: { [weak self] in
self?.loggingController.set(isLogsPresented: false)
@ -105,12 +103,4 @@ public final class LoggingTogglingWindow: UIWindow {
loggingController.set(isLogsPresented: true)
}
private func getTopViewController(from viewController: UIViewController) -> UIViewController {
guard let presentedViewController = viewController.presentedViewController else {
return viewController
}
return getTopViewController(from: presentedViewController)
}
}

View File

@ -0,0 +1,40 @@
//
// Copyright (c) 2022 Touch Instinct
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
import UIKit
public extension UIViewController {
/// Return top visible controller even if we have inner UI(Navigation/TabBar)Controller's inside
var topVisibleViewController: UIViewController {
switch self {
case let navController as UINavigationController:
return navController.visibleViewController?.topVisibleViewController ?? navController
case let tabController as UITabBarController:
return tabController.selectedViewController?.topVisibleViewController ?? tabController
default:
return self.presentedViewController?.topVisibleViewController ?? self
}
}
}