Skip to content

Commit

Permalink
added basic accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehasawii committed May 2, 2023
1 parent f386e3a commit ac1ec7b
Show file tree
Hide file tree
Showing 23 changed files with 229 additions and 57 deletions.
4 changes: 4 additions & 0 deletions SoundboardQuiz.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
2A0ACF2C29F1A66E001E5D03 /* PreloadedData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2A0ACF2B29F1A66E001E5D03 /* PreloadedData.plist */; };
2A2B750D29F2E38D0089DE69 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2B750C29F2E38D0089DE69 /* GameViewController.swift */; };
2A2B750F29F2F0130089DE69 /* SquareCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2B750E29F2F0130089DE69 /* SquareCollectionViewController.swift */; };
2A7AF47A2A015F8500AF3E7B /* HighScoresViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A7AF4792A015F8500AF3E7B /* HighScoresViewController.swift */; };
2A9093D129F71DD3002DBA4F /* BoxContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9093D029F71DD3002DBA4F /* BoxContainerView.swift */; };
2A9093D329F72D3D002DBA4F /* ImageCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9093D229F72D3D002DBA4F /* ImageCollectionView.swift */; };
2A9093D529F72D49002DBA4F /* SoundCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9093D429F72D49002DBA4F /* SoundCollectionView.swift */; };
Expand Down Expand Up @@ -65,6 +66,7 @@
2A0ACF2B29F1A66E001E5D03 /* PreloadedData.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = PreloadedData.plist; path = SoundboardQuiz/PreloadedData.plist; sourceTree = "<group>"; };
2A2B750C29F2E38D0089DE69 /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = GameViewController.swift; path = SoundboardQuiz/GameViewController.swift; sourceTree = "<group>"; };
2A2B750E29F2F0130089DE69 /* SquareCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SquareCollectionViewController.swift; path = SoundboardQuiz/SquareCollectionViewController.swift; sourceTree = "<group>"; };
2A7AF4792A015F8500AF3E7B /* HighScoresViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = HighScoresViewController.swift; path = SoundboardQuiz/HighScoresViewController.swift; sourceTree = "<group>"; };
2A9093D029F71DD3002DBA4F /* BoxContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BoxContainerView.swift; path = SoundboardQuiz/BoxContainerView.swift; sourceTree = "<group>"; };
2A9093D229F72D3D002DBA4F /* ImageCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ImageCollectionView.swift; path = SoundboardQuiz/ImageCollectionView.swift; sourceTree = "<group>"; };
2A9093D429F72D49002DBA4F /* SoundCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SoundCollectionView.swift; path = SoundboardQuiz/SoundCollectionView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -118,6 +120,7 @@
2A0ACF0929F1A02E001E5D03 /* LevelSelectTableViewController.swift */,
2A0ACF2529F1A0F3001E5D03 /* LaunchScreen.storyboard */,
2A0ACF2729F1A107001E5D03 /* Main.storyboard */,
2A7AF4792A015F8500AF3E7B /* HighScoresViewController.swift */,
2AC744AB29FB1CF5006E0CD7 /* GameOverViewController.swift */,
2AFCB22D29FAD2B5003BD84E /* ShuffleView.swift */,
2A9093D629F73564002DBA4F /* MainGameViewController.swift */,
Expand Down Expand Up @@ -271,6 +274,7 @@
2A9093D129F71DD3002DBA4F /* BoxContainerView.swift in Sources */,
2A9093D529F72D49002DBA4F /* SoundCollectionView.swift in Sources */,
2A9093D329F72D3D002DBA4F /* ImageCollectionView.swift in Sources */,
2A7AF47A2A015F8500AF3E7B /* HighScoresViewController.swift in Sources */,
2A0ACF1929F1A02F001E5D03 /* AppDelegate.swift in Sources */,
2A0ACF1829F1A02F001E5D03 /* LevelSelectTableViewController.swift in Sources */,
2AC1DDC129F6D292001253C3 /* SoundCollectionViewCell.swift in Sources */,
Expand Down
1 change: 0 additions & 1 deletion SoundboardQuiz/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let preloadedDataKey = "didPreloadData"
let userDefaults = UserDefaults.standard
if(userDefaults.bool(forKey: preloadedDataKey) == false || manualLoadDataFromPlist){
//TODO: Remove "true" when database has been finalized

userDefaults.set(true, forKey: preloadedDataKey)
guard let urlPath = Bundle.main.url(forResource: "PreloadedData", withExtension: "plist")
Expand Down
97 changes: 52 additions & 45 deletions SoundboardQuiz/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

61 changes: 59 additions & 2 deletions SoundboardQuiz/GameOverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
//

import UIKit
import Foundation

public struct MyTuple: Codable {
var categoryName: String
var score: Int
}

class GameOverViewController: UIViewController {

Expand All @@ -22,9 +28,60 @@ class GameOverViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.hidesBackButton = true
if let score {
if let score, let categoryName {
scoreLabel.text = "Score: \(score)"
//TODO: ADD SCORE TO HIGH SCORES LIST
let defaults = UserDefaults.standard
let fetchedData = UserDefaults.standard.data(forKey: "highScores")
// var highScoresArr: Array<MyTuple>? = defaults.array(forKey: "highScores") as? Array<MyTuple>

var highScoresArr = try? PropertyListDecoder().decode([MyTuple].self, from: fetchedData ?? Data())

if(highScoresArr == nil){
defaults.set(NSArray(), forKey: "highScores")
highScoresArr = defaults.array(forKey: "highScores") as? Array<MyTuple>
}
if let highScoresArr{
if(score > 0) {
print("High Score Array Successfully Obtained.")
if(!highScoresArr.allSatisfy({predicate in
if(predicate.score > score){
return true
}else{
return false
}
}) || highScoresArr.count <= 0){
print("The score is greater than at least one previous high score. Creating new array")
/*
let bookiesData = try! PropertyListEncoder().encode(bookies)
UserDefaults.standard.set(bookiesData, forKey: "bookies")

let fetchedData = UserDefaults.standard.data(forKey: "bookies")!
let fetchedBookies = try! PropertyListDecoder().decode([Bookie].self, from: fetchedData)
print(fetchedBookies)
*/
let newElement: MyTuple = MyTuple(categoryName: categoryName, score: score)
// newElement = try! PropertyListEncoder().encode(arrSorted)
var arrSorted = (highScoresArr) + [newElement] //[(categoryName as NSString, score as NSNumber)]

arrSorted = Array(arrSorted.sorted(by: {t1, t2 in
let int1: Int = t1.score
let int2: Int = t2.score
return int1 >= int2
})[0..<min(5, arrSorted.endIndex)])

print("New sorted array: \(arrSorted)")
let arrayEncoded = try! PropertyListEncoder().encode(arrSorted)

defaults.set(arrayEncoded, forKey: "highScores")



}
}
}else{
print("Error: cannot add to high scores")
}

}else{
print("ERROR")
}
Expand Down
70 changes: 70 additions & 0 deletions SoundboardQuiz/HighScoresViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// HighScoresViewController.swift
// SoundboardQuiz
//
// Created by Luke A Aschenbrenner on 5/2/23.
//

import UIKit

class HighScoresViewController: UIViewController {

@IBOutlet weak var score1: UILabel!
@IBOutlet weak var score2: UILabel!
@IBOutlet weak var score3: UILabel!
@IBOutlet weak var score4: UILabel!
@IBOutlet weak var score5: UILabel!
private var scoreArray: [UILabel]?
//private var tupleArray: [(String, String)] = []

override func viewDidLoad() {
scoreArray = [score1, score2, score3, score4, score5]
super.viewDidLoad()
// let defaults = UserDefaults.standard
//let highScoresArr: Array<(String, Int)>? = defaults.array(forKey: "highScores") as? Array<(String, Int)>
let fetchedData = UserDefaults.standard.data(forKey: "highScores")!
let highScoresArr = try? PropertyListDecoder().decode([MyTuple].self, from: fetchedData)
// highScoresDict?.forEach({
//
// let (gameType, score) = $0
// let scoreString = score as! Int
// tupleArray.append((gameType, scoreString))
//
// })
if let scoreArray, let highScoresArr{
var i = 0
for myTuple in highScoresArr[0..<min(5, highScoresArr.endIndex)]{
scoreArray[i].text? = "\(myTuple.score) (\(myTuple.categoryName))"
i += 1
}
if(i < scoreArray.count){
while(i < scoreArray.count){
scoreArray[i].text? = "N/A"
i += 1
}
}
}else{
var i = 1
for label in scoreArray!{
label.text = "N/A"
i += 1
}
}



// Do any additional setup after loading the view.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/

}
10 changes: 8 additions & 2 deletions SoundboardQuiz/ImageCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
class ImageCollectionViewCell: UICollectionViewCell {
public static let REUSE_IDENTIFIER = "imagePanel";

@IBOutlet private var label: UILabel!
// @IBOutlet private var label: UILabel!
@IBOutlet private var image: UIImageView!
private var secretName: String?

Expand All @@ -22,7 +22,10 @@ class ImageCollectionViewCell: UICollectionViewCell {
}
set{
secretName = newValue
label.text = secretName
// label.text = secretName
image.accessibilityLabel = secretName
image.accessibilityValue = "image"

}
}

Expand Down Expand Up @@ -58,5 +61,8 @@ class ImageCollectionViewCell: UICollectionViewCell {
secretImageFile = nil
backgroundColor = .systemRed
}
required init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
}

}
1 change: 1 addition & 0 deletions SoundboardQuiz/LevelSelectTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class LevelSelectTableViewController: UITableViewController {
// Configure the cell...
// let cell = tableView.dequeueReusableCell(withIdentifier: CategoryTableViewCell.RESUSE_IDENTIFIER, for: indexPath) as! CategoryTableViewCell
// cell.catLabel.text = "Done!"
cell.accessibilityTraits = UIAccessibilityTraits.button
return cell
}

Expand Down
10 changes: 10 additions & 0 deletions SoundboardQuiz/ShuffleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import UIKit

class ShuffleView: UIView {



required init?(coder: NSCoder) {
super.init(coder: coder)
self.accessibilityTraits = UIAccessibilityTraits.button

//TODO: Add voiceover support for shuffle button number of shuffles left and fix green sound buttons to read out the number of plays left from their accessible sub-labels
// TODO: Announce to accessibility users before the sound starts playing that there are X plays left (even if there are 0!)

}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
Expand Down
11 changes: 10 additions & 1 deletion SoundboardQuiz/SoundCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class SoundCollectionView: UICollectionView, AVAudioPlayerDelegate {
}

func playSound(for name: String, cell: SoundCollectionViewCell) {
if let mostRecentCell {
if(mostRecentCell.isPlaying){
mostRecentCell.isPlaying = false
stopSound(cell: mostRecentCell)
}
mostRecentCell.playButtonImage.image = UIImage(systemName: "play.fill")

}
mostRecentCell = cell
if(cell.cellPlaysLeft <= 0){
return
Expand All @@ -44,10 +52,10 @@ class SoundCollectionView: UICollectionView, AVAudioPlayerDelegate {
let url = URL(fileURLWithPath: path)

do {
cell.playButtonImage.image = UIImage(systemName: "stop.fill")
player = try AVAudioPlayer(contentsOf: url)
player?.delegate = self
player?.play()
cell.playButtonImage.image = UIImage(systemName: "stop.fill")

} catch let error {
print(error.localizedDescription)
Expand All @@ -61,6 +69,7 @@ extension SoundCollectionView{
successfully flag: Bool
){
mostRecentCell?.playButtonImage.image = UIImage(systemName: "play.fill")
mostRecentCell?.isPlaying = false

}
}
16 changes: 13 additions & 3 deletions SoundboardQuiz/SoundCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class SoundCollectionViewCell: UICollectionViewCell {
}
label.text = "\(secretCellPlaysLeft)"
}
// TODO: add voiceover to say exactly how many left
UIAccessibility.post(notification: .announcement, argument: "You have \(secretCellPlaysLeft) plays left for this sound box.")


}


Expand All @@ -77,9 +81,15 @@ class SoundCollectionViewCell: UICollectionViewCell {
// }()


// required init?(coder: NSCoder) {
// super.init(coder: coder)
// SoundCollectionViewCell.lastNum = ((SoundCollectionViewCell.lastNum + 1) % Int.max)
required init?(coder: NSCoder) {
super.init(coder: coder)
self.isAccessibilityElement = true
self.accessibilityTraits = .none
self.accessibilityLabel = "Sound Box"
self.accessibilityValue = "label.accessibilityActivate()"

}
// SoundCollectionViewCell.lastNum = ((SoundCollectionViewCell.lastNum + 1) % Int.max)
// }
// override func layoutSubviews() {
// super.layoutSubviews()
Expand Down
Binary file removed SoundboardQuiz/Sounds/Birds/robin.wav
Binary file not shown.
Binary file removed SoundboardQuiz/Sounds/Birds/swallow.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed SoundboardQuiz/Sounds/National Anthems/usa.wav
Binary file not shown.
Binary file removed SoundboardQuiz/Sounds/Random One/cvxccxvcxv.wav
Binary file not shown.
Binary file removed SoundboardQuiz/Sounds/Random One/werwerrwere.wav
Binary file not shown.
Binary file removed SoundboardQuiz/Sounds/Random Two/223253.wav
Binary file not shown.
Binary file not shown.
5 changes: 2 additions & 3 deletions SoundboardQuiz/SquareCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class SquareCollectionViewController: UICollectionViewController, UICollectionVi
cell.backgroundColor = UIColor(white: 0.8, alpha: 0.8)
cell.isMatched = true
(self.parent as! MainGameViewController).stopDragAndGreyOutSoundCell(name: name)
//TODO: stopAllowDragOfDragItem()
//or: stopAllowDragOfDragItem()
// greyOutDragItemAndTargetCell()

}else{
Expand All @@ -526,7 +526,6 @@ class SquareCollectionViewController: UICollectionViewController, UICollectionVi
(self.parent as! MainGameViewController).performSegue(withIdentifier: "segueGameOver", sender: self)
// }
// }
//TODO: gameOver()
}
}
}
Expand Down Expand Up @@ -620,9 +619,9 @@ class SquareCollectionViewController: UICollectionViewController, UICollectionVi
if let tappedCell = collectionView.cellForItem(at:indexPath) as? SoundCollectionViewCell, let soundFileName = tappedCell.soundFile{
print("CELL TAPPED!!!!!")
if(!tappedCell.isPlaying){
tappedCell.isPlaying = true
(collectionView as! SoundCollectionView).playSound(for: soundFileName, cell: tappedCell)
tappedCell.decrementPlayCount()
tappedCell.isPlaying = true
}else{
tappedCell.isPlaying = false
(collectionView as! SoundCollectionView).stopSound(cell: tappedCell)
Expand Down

0 comments on commit ac1ec7b

Please sign in to comment.