2019-07-31 13:35:12 -07:00
//
// R e f r e s h A t t e m p t s V i e w C o n t r o l l e r . s w i f t
// A l t S t o r e
//
// C r e a t e d b y R i l e y T e s t u t o n 7 / 3 1 / 1 9 .
// C o p y r i g h t © 2 0 1 9 R i l e y T e s t u t . A l l r i g h t s r e s e r v e d .
//
import UIKit
2023-03-01 00:48:36 -05:00
import SideStoreCore
2023-03-01 14:36:52 -05:00
import RoxasUIKit
2019-07-31 13:35:12 -07:00
@objc ( RefreshAttemptTableViewCell )
2023-03-01 00:48:36 -05:00
private final class RefreshAttemptTableViewCell : UITableViewCell {
2019-07-31 13:35:12 -07:00
@IBOutlet var successLabel : UILabel !
@IBOutlet var dateLabel : UILabel !
@IBOutlet var errorDescriptionLabel : UILabel !
}
2023-03-01 00:48:36 -05:00
final class RefreshAttemptsViewController : UITableViewController {
2019-07-31 13:35:12 -07:00
private lazy var dataSource = self . makeDataSource ( )
2023-03-01 00:48:36 -05:00
2019-07-31 13:35:12 -07: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 ( ) {
2019-07-31 13:35:12 -07:00
super . viewDidLoad ( )
2023-03-01 00:48:36 -05:00
tableView . dataSource = dataSource
2019-07-31 13:35:12 -07:00
}
}
2023-03-01 00:48:36 -05:00
private extension RefreshAttemptsViewController {
func makeDataSource ( ) -> RSTFetchedResultsTableViewDataSource < RefreshAttempt > {
2019-07-31 13:35:12 -07:00
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
2019-07-31 13:35:12 -07: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
2019-07-31 13:35:12 -07:00
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 {
2019-07-31 13:35:12 -07:00
cell . successLabel . text = NSLocalizedString ( " Success " , comment : " " )
2019-09-08 14:21:40 -07:00
cell . successLabel . textColor = . refreshGreen
2023-03-01 00:48:36 -05:00
} else {
2019-07-31 13:35:12 -07:00
cell . successLabel . text = NSLocalizedString ( " Failure " , comment : " " )
cell . successLabel . textColor = . refreshRed
}
}
2023-03-01 00:48:36 -05:00
2019-07-31 13:35:12 -07:00
let placeholderView = RSTPlaceholderView ( )
placeholderView . textLabel . text = NSLocalizedString ( " No Refresh Attempts " , comment : " " )
2022-11-05 23:50:07 -07:00
placeholderView . detailTextLabel . text = NSLocalizedString ( " The more you use SideStore, the more often iOS will allow it to refresh apps in the background. " , comment : " " )
2019-07-31 13:35:12 -07:00
dataSource . placeholderView = placeholderView
2023-03-01 00:48:36 -05:00
2019-07-31 13:35:12 -07:00
return dataSource
}
}