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
2020-09-03 16:39:08 -07:00
import AltStoreCore
2019-07-31 13:35:12 -07:00
import Roxas
@objc ( RefreshAttemptTableViewCell )
private class RefreshAttemptTableViewCell : UITableViewCell
{
@IBOutlet var successLabel : UILabel !
@IBOutlet var dateLabel : UILabel !
@IBOutlet var errorDescriptionLabel : UILabel !
}
class RefreshAttemptsViewController : UITableViewController
{
private lazy var dataSource = self . makeDataSource ( )
private lazy var dateFormatter : DateFormatter = {
let dateFormatter = DateFormatter ( )
dateFormatter . dateStyle = . short
dateFormatter . timeStyle = . short
return dateFormatter
} ( )
override func viewDidLoad ( )
{
super . viewDidLoad ( )
self . tableView . dataSource = self . dataSource
}
}
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
let dataSource = RSTFetchedResultsTableViewDataSource ( fetchRequest : fetchRequest , managedObjectContext : DatabaseManager . shared . viewContext )
dataSource . cellConfigurationHandler = { [ weak self ] ( cell , attempt , indexPath ) in
let cell = cell as ! RefreshAttemptTableViewCell
cell . dateLabel . text = self ? . dateFormatter . string ( from : attempt . date )
cell . errorDescriptionLabel . text = attempt . errorDescription
if attempt . isSuccess
{
cell . successLabel . text = NSLocalizedString ( " Success " , comment : " " )
2019-09-08 14:21:40 -07:00
cell . successLabel . textColor = . refreshGreen
2019-07-31 13:35:12 -07:00
}
else
{
cell . successLabel . text = NSLocalizedString ( " Failure " , comment : " " )
cell . successLabel . textColor = . refreshRed
}
}
let placeholderView = RSTPlaceholderView ( )
placeholderView . textLabel . text = NSLocalizedString ( " No Refresh Attempts " , comment : " " )
placeholderView . detailTextLabel . text = NSLocalizedString ( " The more you use AltStore, the more often iOS will allow it to refresh apps in the background. " , comment : " " )
dataSource . placeholderView = placeholderView
return dataSource
}
}