Files
SideStore/SideStoreApp/Sources/SideStoreAppKit/Settings/RefreshAttemptsViewController.swift

67 lines
2.4 KiB
Swift
Raw Normal View History

//
// RefreshAttemptsViewController.swift
// AltStore
//
// Created by Riley Testut on 7/31/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import UIKit
2023-03-01 00:48:36 -05:00
import SideStoreCore
2023-03-01 14:36:52 -05:00
import RoxasUIKit
@objc(RefreshAttemptTableViewCell)
2023-03-01 00:48:36 -05:00
private final class RefreshAttemptTableViewCell: UITableViewCell {
@IBOutlet var successLabel: UILabel!
@IBOutlet var dateLabel: UILabel!
@IBOutlet var errorDescriptionLabel: UILabel!
}
2023-03-01 00:48:36 -05:00
final class RefreshAttemptsViewController: UITableViewController {
private lazy var dataSource = self.makeDataSource()
2023-03-01 00:48:36 -05:00
private lazy var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .short
dateFormatter.timeStyle = .short
return dateFormatter
}()
2023-03-01 00:48:36 -05:00
override func viewDidLoad() {
super.viewDidLoad()
2023-03-01 00:48:36 -05:00
tableView.dataSource = dataSource
}
}
2023-03-01 00:48:36 -05:00
private extension RefreshAttemptsViewController {
func makeDataSource() -> RSTFetchedResultsTableViewDataSource<RefreshAttempt> {
let fetchRequest = RefreshAttempt.fetchRequest() as NSFetchRequest<RefreshAttempt>
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \RefreshAttempt.date, ascending: false)]
fetchRequest.returnsObjectsAsFaults = false
2023-03-01 00:48:36 -05:00
let dataSource = RSTFetchedResultsTableViewDataSource(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext)
2023-03-01 00:48:36 -05:00
dataSource.cellConfigurationHandler = { [weak self] cell, attempt, _ in
let cell = cell as! RefreshAttemptTableViewCell
cell.dateLabel.text = self?.dateFormatter.string(from: attempt.date)
cell.errorDescriptionLabel.text = attempt.errorDescription
2023-03-01 00:48:36 -05:00
if attempt.isSuccess {
cell.successLabel.text = NSLocalizedString("Success", comment: "")
cell.successLabel.textColor = .refreshGreen
2023-03-01 00:48:36 -05:00
} else {
cell.successLabel.text = NSLocalizedString("Failure", comment: "")
cell.successLabel.textColor = .refreshRed
}
}
2023-03-01 00:48:36 -05:00
let placeholderView = RSTPlaceholderView()
placeholderView.textLabel.text = NSLocalizedString("No Refresh Attempts", comment: "")
placeholderView.detailTextLabel.text = NSLocalizedString("The more you use SideStore, the more often iOS will allow it to refresh apps in the background.", comment: "")
dataSource.placeholderView = placeholderView
2023-03-01 00:48:36 -05:00
return dataSource
}
}