[AltStore] Basic Account tab

This commit is contained in:
Riley Testut
2019-06-06 14:46:23 -07:00
parent b98ab3e852
commit c4542373c5
12 changed files with 465 additions and 41 deletions

View File

@@ -77,21 +77,29 @@ class AuthenticationOperation: RSTOperation
// Account
let account = Account(altAccount, context: context)
account.isActiveAccount = true
let otherAccountsFetchRequest = Account.fetchRequest() as NSFetchRequest<Account>
otherAccountsFetchRequest.predicate = NSPredicate(format: "%K != %@", #keyPath(Account.identifier), account.identifier)
let otherAccounts = try context.fetch(otherAccountsFetchRequest)
otherAccounts.forEach(context.delete(_:))
for account in otherAccounts
{
account.isActiveAccount = false
}
// Team
let team = Team(altTeam, account: account, context: context)
team.isActiveTeam = true
let otherTeamsFetchRequest = Team.fetchRequest() as NSFetchRequest<Team>
otherTeamsFetchRequest.predicate = NSPredicate(format: "%K != %@", #keyPath(Team.identifier), team.identifier)
let otherTeams = try context.fetch(otherTeamsFetchRequest)
otherTeams.forEach(context.delete(_:))
for team in otherTeams
{
team.isActiveTeam = false
}
// Save
try context.save()
@@ -264,27 +272,12 @@ private extension AuthenticationOperation
case .success(let teams):
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
do
if let activeTeam = DatabaseManager.shared.activeTeam(in: context), let altTeam = teams.first(where: { $0.identifier == activeTeam.identifier })
{
let fetchRequest = Team.fetchRequest() as NSFetchRequest<Team>
fetchRequest.fetchLimit = 1
fetchRequest.returnsObjectsAsFaults = false
let fetchedTeams = try context.fetch(fetchRequest)
if let fetchedTeam = fetchedTeams.first, let altTeam = teams.first(where: { $0.identifier == fetchedTeam.identifier })
{
completionHandler(.success(altTeam))
}
else
{
selectTeam(from: teams)
}
completionHandler(.success(altTeam))
}
catch
else
{
print("Error fetching Teams.", error)
selectTeam(from: teams)
}
}

View File

@@ -57,16 +57,7 @@ private extension SelectTeamViewController
dataSource.proxy = self
dataSource.cellConfigurationHandler = { [weak self] (cell, team, indexPath) in
cell.textLabel?.text = team.name
switch team.type
{
case .unknown: cell.detailTextLabel?.text = NSLocalizedString("Unknown", comment: "")
case .free: cell.detailTextLabel?.text = NSLocalizedString("Free Developer Account", comment: "")
case .individual: cell.detailTextLabel?.text = NSLocalizedString("Individual", comment: "")
case .organization: cell.detailTextLabel?.text = NSLocalizedString("Organization", comment: "")
@unknown default: cell.detailTextLabel?.text = nil
}
cell.detailTextLabel?.text = team.type.localizedDescription
cell.accessoryType = (self?.selectedTeam == team) ? .checkmark : .none
}