Skip to content

Commit

Permalink
ux
Browse files Browse the repository at this point in the history
  • Loading branch information
xqsadness committed Sep 18, 2023
1 parent ae735aa commit 78d6af9
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 77 deletions.
Binary file not shown.
55 changes: 35 additions & 20 deletions DefaultProject/View/Color/ColorSubmitNextButtonsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ struct ColorSubmitNextButtonsView: View {

var body: some View {
HStack(spacing: 10){
Button{
isSubmit = true

Button{
if selectedAnswer.lowercased().cw_localized == answerCorrect.lowercased().cw_localized{
loadAudio(nameSound: "correct")
isCorrect = true
countCorrect += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7, execute: {
if selectedTab < CONSTANT.SHARED.DATA_COLOR.count - 1{
submitCorrect()
}else{
isSubmit = true
completeAllQuestion()
}
})
}else{
isSubmit = true
loadAudio(nameSound: "wrong")
isCorrect = false
countWrong += 1
Expand All @@ -53,24 +60,9 @@ struct ColorSubmitNextButtonsView: View {
Button{
synthesizer.stopSpeaking(at: .immediate)
if selectedTab < CONSTANT.SHARED.DATA_COLOR.count - 1 {
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
submitCorrect()
}else{

withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
completeAllQuestion()
}

// if selectedTab >= QUIZDEFAULT.SHARED.listQuestionsHistory.count - 1{
Expand All @@ -91,6 +83,29 @@ struct ColorSubmitNextButtonsView: View {
.padding()
}

func submitCorrect(){
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
}

func completeAllQuestion(){
// processed upon completion of All Questions
withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
}

func loadAudio(nameSound: String) {
if let audioURL = Bundle.main.url(forResource: nameSound, withExtension: "mp3") {
audioPlayer = try? AVAudioPlayer(contentsOf: audioURL)
Expand Down
56 changes: 36 additions & 20 deletions DefaultProject/View/History/HistorySubmitNextButtonsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ struct HistorySubmitNextButtonsView: View {
HStack(spacing: 10){
Button{
offset = -10
isSubmit = true

synthesizer.stopSpeaking(at: .immediate)
if selectedAnswer == answerCorrect{
loadAudio(nameSound: "correct")
isCorrect = true
countCorrect += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7, execute: {
if selectedTab < CONSTANT.SHARED.DATA_HISTORY.count - 1{
submitCorrect()
}else{
isSubmit = true
completeAllQuestion()
}
})
}else{
isSubmit = true
loadAudio(nameSound: "wrong")
isCorrect = false
countWrong += 1
Expand All @@ -54,29 +63,12 @@ struct HistorySubmitNextButtonsView: View {
Button{
synthesizer.stopSpeaking(at: .immediate)
if selectedTab < CONSTANT.SHARED.DATA_HISTORY.count - 1 {
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
submitCorrect()
}else{

withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
completeAllQuestion()
}

// if selectedTab >= QUIZDEFAULT.SHARED.listQuestionsHistory.count - 1{
Point.updatePointHistory(newPointHistory: countCorrect)
// }
}label: {
Text(selectedTab < CONSTANT.SHARED.DATA_HISTORY.count - 1 ? "Next".cw_localized : "Done".cw_localized)
.foregroundColor(.text)
Expand All @@ -92,6 +84,30 @@ struct HistorySubmitNextButtonsView: View {
.padding()
}

func submitCorrect(){
// processed after answering 1 question correctly
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
}

func completeAllQuestion(){
// processed upon completion of All Questions
withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
}

func loadAudio(nameSound: String) {
if let audioURL = Bundle.main.url(forResource: nameSound, withExtension: "mp3") {
audioPlayer = try? AVAudioPlayer(contentsOf: audioURL)
Expand Down
54 changes: 35 additions & 19 deletions DefaultProject/View/Listen/ListeningSubmitNextButtonsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ struct ListeningSubmitNextButtonsView: View {
var body: some View {
HStack(spacing: 10){
Button{
isSubmit = true

if selectedAnswer.lowercased().cw_localized == answerCorrect.lowercased().cw_localized{
loadAudio(nameSound: "correct")
isCorrect = true
countCorrect += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7, execute: {
if selectedTab < CONSTANT.SHARED.DATA_LISTEN.count - 1{
submitCorrect()
}else{
isSubmit = true
completeAllQuestion()
}
})
}else{
isSubmit = true
loadAudio(nameSound: "wrong")
isCorrect = false
countWrong += 1
Expand All @@ -53,24 +60,9 @@ struct ListeningSubmitNextButtonsView: View {
Button{
synthesizer.stopSpeaking(at: .immediate)
if selectedTab < CONSTANT.SHARED.DATA_LISTEN.count - 1 {
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
submitCorrect()
}else{

withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
completeAllQuestion()
}

Point.updatePointListen(point: countCorrect)
Expand All @@ -89,6 +81,30 @@ struct ListeningSubmitNextButtonsView: View {
.padding()
}

func submitCorrect(){
// processed after answering 1 question correctly
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
}

func completeAllQuestion(){
// processed upon completion of All Questions
withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
}

func loadAudio(nameSound: String) {
if let audioURL = Bundle.main.url(forResource: nameSound, withExtension: "mp3") {
audioPlayer = try? AVAudioPlayer(contentsOf: audioURL)
Expand Down
54 changes: 36 additions & 18 deletions DefaultProject/View/Math/MathSubmitNextButtonsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ struct MathSubmitNextButtonsView: View {
HStack(spacing: 10){
Button{
offset = -10
isSubmit = true

if selectedAnswer.lowercased().cw_localized == answerCorrect.lowercased().cw_localized{
loadAudio(nameSound: "correct")
isCorrect = true
countCorrect += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7, execute: {
if selectedTab < CONSTANT.SHARED.DATA_MATH.count - 1{
submitCorrect()
}else{
isSubmit = true
completeAllQuestion()
}
})
}else{
isSubmit = true
loadAudio(nameSound: "wrong")
isCorrect = false
countWrong += 1
Expand All @@ -54,24 +62,10 @@ struct MathSubmitNextButtonsView: View {
Button{
synthesizer.stopSpeaking(at: .immediate)
if selectedTab < CONSTANT.SHARED.DATA_MATH.count - 1 {
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
submitCorrect()
}else{

withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
// Check if all questions have been answered
completeAllQuestion()
}

Point.updatePointMath(point: countCorrect)
Expand All @@ -90,6 +84,30 @@ struct MathSubmitNextButtonsView: View {
.padding()
}

func submitCorrect(){
// processed after answering 1 question correctly
progress += 1
selectedAnswer = ""
isSubmit = false
isCorrect = false
withAnimation {
selectedTab += 1
}
}

func completeAllQuestion(){
// processed upon completion of All Questions
withAnimation {
isShowPopup = true
}
audioPlayer?.pause()
if countCorrect == 0{
loadAudio(nameSound: "wrong")
}else{
loadAudio(nameSound: "congralutions")
}
}

func loadAudio(nameSound: String) {
if let audioURL = Bundle.main.url(forResource: nameSound, withExtension: "mp3") {
audioPlayer = try? AVAudioPlayer(contentsOf: audioURL)
Expand Down

0 comments on commit 78d6af9

Please sign in to comment.