Browse Source

fix recap

feature/sdk_upgrade
Dslak 4 weeks ago
parent
commit
0b0c193dd9
  1. 6
      vds-app/App/components/Variables.js
  2. 2
      vds-app/App/index.js
  3. 2
      vds-app/App/screens/Exam.js
  4. 136
      vds-app/App/screens/Recap.js
  5. 200
      vds-app/App/screens/RecapExam.js
  6. 319
      vds-app/App/screens/Results.js
  7. 2
      vds-app/App/screens/ResultsTrueFalse.js
  8. 3
      vds-app/App/screens/TrueFalse.js
  9. 4
      vds-app/android/app/build.gradle
  10. 4
      vds-app/app.json
  11. 2
      vds-app/package.json

6
vds-app/App/components/Variables.js

@ -87,7 +87,7 @@ export const texts = {
changeQuestion: "Cambia domanda...",
lens: "\uD83D\uDD0D"
}
/*
export const examScheme = [
{section: "aerodynamics", questions: 8, points: 3},
{section: "firstAid", questions: 1, points: 2},
@ -99,14 +99,14 @@ export const examScheme = [
{section: "physiopathology", questions: 1, points: 2},
{section: "pilotingTechniques", questions: 5, points: 4}
]
/*
*/
export const examScheme = [
{section: "aerodynamics", questions: 1, points: 3},
{section: "firstAid", questions: 1, points: 2},
{section: "flightSafety", questions: 1, points: 4},
{section: "instruments", questions: 1, points: 2}
]
*/
export const resultsScheme = [
{points: "da 86 a 100 punti", result: "idoneo"},

2
vds-app/App/index.js

@ -11,6 +11,7 @@ import Exam from "./screens/Exam";
import Results from "./screens/Results";
import ResultsTrueFalse from "./screens/ResultsTrueFalse";
import Recap from "./screens/Recap";
import RecapExam from "./screens/RecapExam";
import RecapTrueFalse from "./screens/RecapTrueFalse";
import Info from "./screens/Info";
import Setup from "./screens/Setup";
@ -28,6 +29,7 @@ export default function App() {
<Stack.Screen name="Splash" component={Splash} />
<Stack.Screen name="RecapTrueFalse" component={RecapTrueFalse} />
<Stack.Screen name="Recap" component={Recap} />
<Stack.Screen name="RecapExam" component={RecapExam} />
<Stack.Screen name="Results" component={Results} />
<Stack.Screen name="ResultsTrueFalse" component={ResultsTrueFalse} />
<Stack.Screen name="Info" component={Info} />

2
vds-app/App/screens/Exam.js

@ -172,7 +172,7 @@ class Exam extends React.Component {
render() {
const { availableIds, activeQuestionId, results, correctCount, wrongCount, totalCount, clickedId } = this.state;
const questions = this.props.route.params?.questions || [];
const questions = this.props.route?.params?.questions || [];
const question = questions.find(q => q.id === activeQuestionId) || questions[0];
return (

136
vds-app/App/screens/Recap.js

@ -134,65 +134,101 @@ const Recap = () => {
return true;
}, [navigation, storeWrongAnswers]);
// Attach hardware back handler
const showResults = useCallback(() => {
navigation.navigate("Results", {
wrongAnswers: wrongAnswers
})
return true;
}, [navigation, storeWrongAnswers]);
useFocusEffect(
useCallback(() => {
this.backHandler = BackHandler.addEventListener( 'hardwareBackPress', this.handleBackButton)
return () => this.backHandler?.remove();
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
handleBackButton
);
return () => backHandler.remove();
}, [handleBackButton])
);
const questions = route.params?.wrongAnswers || [];
return (
<View style={styles.container}>
<View style={styles.headerContainer}>
<Image source={header} style={styles.header} resizeMode="contain" />
</View>
const currentResults = route.params
const wrongAnswers = currentResults.wrongAnswers || null
const percentage = currentResults.total ? (100/currentResults.total) * currentResults.correct : 0
let resultStyle = ''//currentResults.points >= 80 ? currentResults.points >= 85 ? styles.correct : styles.unsafe : styles.wrong
let boxStyle = currentResults.points >= 80 ? currentResults.points >= 85 ? styles.boxCorrect : styles.boxUnsafe : styles.boxWrong
<Text style={styles.textBig}>aaa{texts.recapTitle}</Text>
<ScrollView>
<SafeAreaView style={styles.safearea}>
{questions.map((question) => (
<View style={styles.box} key={question.id}>
<Text style={styles.textCode}>{question.id}</Text>
<Text style={styles.text}>{question.question}</Text>
<ButtonContainer>
{question.answers.map((answer) => (
<Button
key={answer.id}
text={answer.text}
colorize={{
id: answer.id,
clicked: question.clicked,
answered: true,
isCorrect: answer.correct,
}}
/>
))}
</ButtonContainer>
</View>
))}
<View style={{ marginTop: 20 }}>
<Button
color={colors.white_alpha2}
hasShadow
hasBg
text={texts.restart}
onPress={handleBackButton}
/>
</View>
</SafeAreaView>
<View style={styles.bannerContainer}>
<Banner />
if(!currentResults.isExam) {
resultStyle = ''//percentage >= 80 ? percentage >= 85 ? styles.correct : styles.unsafe : styles.wrong
boxStyle = percentage >= 80 ? percentage >= 85 ? styles.boxCorrect : styles.boxUnsafe : styles.boxWrong
}
return (
<View style={styles.container} >
<View style={styles.headerContainer} >
<Image source={header} style={styles.header} resizeMode="contain" />
</View>
</ScrollView>
</View>
);
<ScrollView>
<SafeAreaView style={styles.safearea}>
<View style={[styles.box, boxStyle]}>
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.corrects}: ${currentResults.correct}`}</Text>
</Text>
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.wrongs}: ${currentResults.wrong}`}</Text>
</Text>
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.percentage}: ${Math.round(percentage)}%`}</Text>
</Text>
{
currentResults.points ? (
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.points}: ${currentResults.points}/${currentResults.totalPoints}`}</Text>
</Text>
) : null
}
{currentResults.isExam ?
<Text style={[styles.textSmall, resultStyle]}>
{currentResults.points >= 80 ? currentResults.points >= 85 ? texts.exam_passed : texts.exam_needs_oral : texts.exam_not_passed}
</Text> : <Text/>
}
</View>
{wrongAnswers.length ?
<View style={styles.button}>
<Button
color={colors.red_light}
text={texts.recap}
hasBg={true}
onPress={showResults}/>
<Button
isBig={false}
hasBg={true}
color={colors.white_alpha}
text={texts.restart}
onPress={handleBackButton}
/>
</View> :
<View style={styles.button}>
<Button
isBig={false}
hasBg={true}
color={colors.white_alpha}
text={texts.restart}
onPress={handleBackButton}
/>
</View>
}
</SafeAreaView>
</ScrollView>
</View>
)
};
export default Recap;

200
vds-app/App/screens/RecapExam.js

@ -0,0 +1,200 @@
import React from "react"
import { View, ScrollView, StyleSheet, StatusBar, Text, Dimensions, Image, ImageBackground, BackHandler } from "react-native"
import SafeAreaView from 'react-native-safe-area-view'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { Button, ButtonContainer } from "../components/Button"
import { Banner } from "../components/Banner"
import { colors, texts, examScheme, credentials } from "../components/Variables"
import aerodynamicsQuestions from "../data/aerodynamics"
import firstAidQuestions from "../data/firstAid"
import flightSafetyQuestions from "../data/flightSafety"
import instrumentsQuestions from "../data/instruments"
import legislationQuestions from "../data/legislation"
import materialsQuestions from "../data/materials"
import meteorologyQuestions from "../data/meteorology"
import physiopathologyQuestions from "../data/physiopathology"
import pilotingTechniquesQuestions from "../data/pilotingTechniques"
const screen = Dimensions.get("window")
const header = require("../assets/header.png")
const bgImage = require("../assets/bg.jpg")
const allQuestions = {
aerodynamics: aerodynamicsQuestions,
firstAid: firstAidQuestions,
flightSafety: flightSafetyQuestions,
instruments: instrumentsQuestions,
legislation: legislationQuestions,
materials: materialsQuestions,
meteorology: meteorologyQuestions,
physiopathology: physiopathologyQuestions,
pilotingTechniques: pilotingTechniquesQuestions
}
const styles = StyleSheet.create({
container: {
backgroundColor: colors.blue,
flex: 1
},
safearea: {
flex: 1,
marginTop: 0,
justifyContent: "space-between",
paddingHorizontal: 20,
paddingBottom: 40
},
headerContainer: {
marginTop: -40,
alignItems: "center",
justifyContent: "center",
width: "100%",
height: screen.width/1.5
},
header: {
width: "100%"
},
box: {
marginTop: 30,
borderColor: colors.black_alpha,
borderWidth: 1,
padding: 15,
borderRadius: 5,
backgroundColor: colors.white_alpha
},
text: {
color: colors.white,
fontSize: 20,
textAlign: "center",
fontWeight: "600",
paddingTop: 0
},
textCode: {
color: colors.white,
fontSize: 12,
textAlign: "center",
fontWeight: "500",
paddingTop: 10,
paddingBottom: 0
},
textBig: {
color: colors.white,
fontSize: 22,
textAlign: "center",
fontWeight: "400",
paddingBottom: 15,
textTransform: "uppercase",
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 10
},
bg: {
width: "100%",
height: "100%"
},
bannerContainer: {
flex: 1,
alignItems: "center",
justifyContent: "center"
}
})
class RecapTrueFalse extends React.Component {
componentDidMount() {
this.backHandler = BackHandler.addEventListener( 'hardwareBackPress', this.handleBackButton)
AsyncStorage.getItem('storeWrongAnswers').then((value) => {
//console.log(value)
})
}
componentWillUnmount() {
this.backHandler?.remove()
}
handleBackButton = () => {
let tmpQuestions = []
let fullQuestions = []
examScheme.forEach( (elem) => {
let currentSection = allQuestions[elem.section]
for(let i=0; i<currentSection.length; i++) {
fullQuestions.push(currentSection[i])
}
})
for(let i=0; i<10; i++) {
const currentIndex = Math.floor(Math.random() * fullQuestions.length)
tmpQuestions.push(fullQuestions[currentIndex])
fullQuestions = fullQuestions.filter( (item, index) => index != currentIndex)
}
this.props.navigation.navigate("Splash", {
trueFalseQuestions: tmpQuestions
})
return true
}
render() {
const questions = this.props.route?.params?.wrongAnswers || []
return (
<View style={styles.container} >
<View style={styles.headerContainer} >
<Image source={header} style={styles.header} resizeMode="contain" />
</View>
<Text style={styles.textBig}>{texts.recapTitle}</Text>
<ScrollView>
<SafeAreaView style={styles.safearea}>
{questions.map( (question, index) => (
<View style={styles.box} key={question.id}>
<Text style={styles.textCode}>{question.id}</Text>
<Text style={styles.text}>{question.question}</Text>
<ButtonContainer>
{question.answers.map( (answer, index) => {
if(question.clicked == answer.id) {
return (
<Button
noBorder={true}
key={answer.id}
text={answer.text}
colorize={{id: answer.id, clicked: question.clicked, answered: true, isCorrect: answer.correct}}
/>
)}
}
)}
</ButtonContainer>
</View>
))}
<View style={styles.button}>
<Button
color={colors.white_alpha2}
hasShadow={true}
hasBg={true}
text={texts.restart}
onPress={() => {this.handleBackButton()}
}
/>
</View>
</SafeAreaView>
<View style={styles.bannerContainer}>
<Banner />
</View>
</ScrollView>
</View>
)
}
}
export default RecapTrueFalse

319
vds-app/App/screens/Results.js

@ -1,4 +1,4 @@
import React, { useCallback } from "react";
import React from "react";
import {
View,
ScrollView,
@ -6,9 +6,12 @@ import {
Text,
Image,
BackHandler,
} from "react-native";
Dimensions,
} from "react-native"; // 👈 Add Dimensions here
import { SafeAreaView } from "react-native-safe-area-context";
import { useNavigation, useRoute, useFocusEffect } from "@react-navigation/native";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { Button, ButtonContainer } from "../components/Button";
import { Banner } from "../components/Banner";
@ -37,148 +40,240 @@ const allQuestions = {
};
const header = require("../assets/header.png");
// Get screen dimensions
const screen = Dimensions.get("window");
const maxTime = 0
const styles = StyleSheet.create({
container: { backgroundColor: colors.blue, flex: 1 },
container: {
backgroundColor: colors.dark_blue,
flex: 1
},
safearea: {
flex: 1,
marginTop: 0,
justifyContent: "space-between",
paddingHorizontal: 20,
paddingBottom: 40,
paddingBottom: 40
},
headerContainer: {
marginTop: -40,
alignItems: "center",
justifyContent: "center",
width: "100%",
height: 200,
height: screen.width/1.5
},
header: {
width: "100%"
},
header: { width: "100%" },
box: {
marginTop: 30,
borderColor: colors.black_alpha,
borderWidth: 1,
padding: 15,
borderRadius: 5,
marginTop: 20,
marginBottom: 20,
marginHorizontal: 20,
width: screen.width-80,
borderRadius: 10,
borderBottomEndRadius: 80,
borderTopStartRadius: 100,
backgroundColor: colors.white_alpha,
borderColor: colors.white,
borderWidth: 2,
paddingVertical: 30
},
boxCorrect: {
backgroundColor: colors.green_light,
},
boxWrong: {
backgroundColor: colors.red,
},
boxUnsafe: {
backgroundColor: colors.orange,
},
button: {
width: screen.width-80,
marginHorizontal: 20
},
text: {
color: colors.white,
fontSize: 20,
fontSize: 22,
textAlign: "center",
fontWeight: "600",
fontWeight: "400",
lineHeight: 40,
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 10
},
textCode: {
textSmall: {
color: colors.white,
fontSize: 12,
marginTop: 20,
fontSize: 26,
textAlign: "center",
fontWeight: "500",
paddingTop: 10,
lineHeight: 30,
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 10
},
textBig: {
color: colors.white,
fontSize: 22,
textAlign: "center",
fontWeight: "400",
paddingBottom: 15,
textTransform: "uppercase",
textShadowColor: "rgba(0,0,0,0.75)",
textShadowOffset: { width: -1, height: 1 },
textShadowRadius: 10,
textLabel: {
paddingHorizontal: 20,
paddingVertical: 20
},
bannerContainer: { flex: 1, alignItems: "center", justifyContent: "center" },
});
correct: {
color: colors.green
},
wrong: {
color: colors.red
},
unsafe: {
color: colors.yellow
}
})
class Results extends React.Component {
const Results = () => {
const navigation = useNavigation();
const route = useRoute();
state = {
bannerExpanded: true,
timer: maxTime,
storeWrongAnswers: []
}
const handleBackButton = useCallback(() => {
const tmpQuestions = [];
let fullQuestions = [];
componentDidMount() {
this.backHandler = BackHandler.addEventListener(
"hardwareBackPress",
this.handleBackButton
);
examScheme.forEach((elem) => {
fullQuestions.push(...allQuestions[elem.section]);
AsyncStorage.getItem("storeWrongAnswers").then((value) => {
const currentResults = this.props.route.params.results;
const wrongAnswers = currentResults.wrongAnswers || [];
const stored = JSON.parse(value) || [];
const result = currentResults.isWrong
? wrongAnswers
: Object.assign([], wrongAnswers, stored);
AsyncStorage.setItem("storeWrongAnswers", JSON.stringify(result));
this.setState({ storeWrongAnswers: result });
});
}
componentWillUnmount() {
if (this.backHandler) { this.backHandler.remove(); }
}
for (let i = 0; i < 10; i++) {
const index = Math.floor(Math.random() * fullQuestions.length);
tmpQuestions.push(fullQuestions[index]);
fullQuestions.splice(index, 1);
handleBackButton = () => {
let tmpQuestions = []
AsyncStorage.getItem('setupData').then((value) => {
let setupData = JSON.parse(value)
examScheme.forEach( (elem) => {
let currentSection = setupData.excludeDelta ? allQuestions[elem.section].filter(item => !item.delta) : allQuestions[elem.section]
for(let i=0; i<elem.questions; i++) {
const currentIndex = Math.floor(Math.random() * currentSection.length)
tmpQuestions.push(currentSection[currentIndex])
currentSection = currentSection.filter( (item, index) => index != currentIndex)
}
})
this.props.navigation.navigate("Splash", {
examQuestions: tmpQuestions,
storeWrongAnswers: this.state.storeWrongAnswers
})
return true
})
}
render() {
const currentResults = this.props.route?.params?.results || [];
const wrongAnswers = currentResults.wrongAnswers || null
const percentage = currentResults.total ? (100/currentResults.total) * currentResults.correct : 0
let resultStyle = ''//currentResults.points >= 80 ? currentResults.points >= 85 ? styles.correct : styles.unsafe : styles.wrong
let boxStyle = currentResults.points >= 80 ? currentResults.points >= 85 ? styles.boxCorrect : styles.boxUnsafe : styles.boxWrong
if(!currentResults.isExam) {
resultStyle = ''//percentage >= 80 ? percentage >= 85 ? styles.correct : styles.unsafe : styles.wrong
boxStyle = percentage >= 80 ? percentage >= 85 ? styles.boxCorrect : styles.boxUnsafe : styles.boxWrong
}
navigation.navigate("Splash", { trueFalseQuestions: tmpQuestions });
return true;
}, [navigation]);
// Attach hardware back button handler
useFocusEffect(
useCallback(() => {
// this.backHandler = BackHandler.addEventListener( 'hardwareBackPress', this.handleBackButton)
// return () => this.backHandler?.remove()
const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
handleBackButton
);
return () => backHandler.remove();
}, [handleBackButton])
);
const questions = route.params.results?.wrongAnswers || [];
return (
<View style={styles.container}>
<View style={styles.headerContainer}>
<Image source={header} style={styles.header} resizeMode="contain" />
</View>
<Text style={styles.textBig}>{texts.recapTitle}</Text>
<ScrollView>
<SafeAreaView style={styles.safearea}>
{questions.map((q) => (
<View style={styles.box} key={q.id}>
<Text style={styles.textCode}>{q.id}</Text>
<Text style={styles.text}>{q.question}</Text>
<ButtonContainer>
{q.answers.map(
(ans) =>
q.clicked === ans.id && (
<Button
key={ans.id}
text={ans.text}
noBorder
colorize={{
id: ans.id,
clicked: q.clicked,
answered: true,
isCorrect: ans.correct,
}}
/>
)
)}
</ButtonContainer>
</View>
))}
<View style={{ marginTop: 20 }}>
<Button
color={colors.white_alpha2}
hasBg
hasShadow
text={texts.restart}
onPress={handleBackButton}
/>
</View>
</SafeAreaView>
<View style={styles.bannerContainer}>
<Banner />
return (
<View style={styles.container} >
<View style={styles.headerContainer} >
<Image source={header} style={styles.header} resizeMode="contain" />
</View>
</ScrollView>
</View>
);
};
<ScrollView>
<SafeAreaView style={styles.safearea}>
<View style={[styles.box, boxStyle]}>
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.corrects}: ${currentResults.correct}`}</Text>
</Text>
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.wrongs}: ${currentResults.wrong}`}</Text>
</Text>
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.percentage}: ${Math.round(percentage)}%`}</Text>
</Text>
{
currentResults.points ? (
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.points}: ${currentResults.points}/${currentResults.totalPoints}`}</Text>
</Text>
) : null
}
{currentResults.isExam ?
<Text style={[styles.textSmall, resultStyle]}>
{currentResults.points >= 80 ? currentResults.points >= 85 ? texts.exam_passed : texts.exam_needs_oral : texts.exam_not_passed}
</Text> : <Text/>
}
</View>
{wrongAnswers.length ?
<View style={styles.button}>
<Button
color={colors.red_light}
text={texts.recap}
hasBg={true}
onPress={ ()=> {
this.props.navigation.navigate("RecapExam", {
wrongAnswers: wrongAnswers
})
}}/>
<Button
isBig={false}
hasBg={true}
color={colors.white_alpha}
text={texts.restart}
onPress={() => {this.handleBackButton()}
}
/>
</View> :
<View style={styles.button}>
<Button
isBig={false}
hasBg={true}
color={colors.white_alpha}
text={texts.restart}
onPress={() => {this.handleBackButton()}
}
/>
</View>
}
</SafeAreaView>
</ScrollView>
</View>
)
}
}
export default Results;
export default Results

2
vds-app/App/screens/ResultsTrueFalse.js

@ -71,7 +71,7 @@ class Results extends React.Component {
render() {
const questions = this.props.route.params.results?.wrongAnswers || [];
const questions = this.props.route?.params?.results?.wrongAnswers || [];
return (
<View style={styles.container}>

3
vds-app/App/screens/TrueFalse.js

@ -107,8 +107,7 @@ class Quiz extends React.Component {
componentDidMount() {
this.backHandler = BackHandler.addEventListener( 'hardwareBackPress', this.handleBackButton)
const questions = this.props.route.params?.questions || [];
const questions = this.props.route?.params?.questions || [];
this.setState({
availableIds: questions.map(q => q.id),
activeQuestionId: questions.length ? questions[Math.floor(Math.random() * questions.length)].id : null

4
vds-app/android/app/build.gradle

@ -92,8 +92,8 @@ android {
applicationId 'com.dslak.vdsquiz'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 33
versionName "3.8.5"
versionCode 34
versionName "3.8.6"
buildConfigField "String", "REACT_NATIVE_RELEASE_LEVEL", "\"${findProperty('reactNativeReleaseLevel') ?: 'stable'}\""
}

4
vds-app/app.json

@ -7,7 +7,7 @@
"android",
"web"
],
"version": "3.8.5",
"version": "3.8.6",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
@ -25,7 +25,7 @@
"android": {
"icon": "./assets/icon.png",
"permissions": [],
"versionCode": 33
"versionCode": 34
},
"ios": {
"icon": "./assets/iconIOS.png",

2
vds-app/package.json

@ -1,6 +1,6 @@
{
"name": "vds-quiz",
"version": "3.8.5",
"version": "3.8.6",
"license": "MIT",
"main": "node_modules/expo/AppEntry.js",
"scripts": {

Loading…
Cancel
Save