Commit ca5914ae authored by norhalimah's avatar norhalimah

.......

parent eff51a52
...@@ -4,6 +4,7 @@ import android.app.Application; ...@@ -4,6 +4,7 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import com.facebook.react.PackageList; import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication; import com.facebook.react.ReactApplication;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
import com.zmxv.RNSound.RNSoundPackage; import com.zmxv.RNSound.RNSoundPackage;
import com.zmxv.RNSound.RNSoundPackage; import com.zmxv.RNSound.RNSoundPackage;
import com.github.yamill.orientation.OrientationPackage; import com.github.yamill.orientation.OrientationPackage;
......
rootProject.name = 'PianoApp' rootProject.name = 'PianoApp'
include ':@react-native-async-storage_async-storage'
project(':@react-native-async-storage_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-async-storage/async-storage/android')
include ':react-native-sound' include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android') project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-sound' include ':react-native-sound'
......
...@@ -16,6 +16,8 @@ target 'PianoApp' do ...@@ -16,6 +16,8 @@ target 'PianoApp' do
pod 'RNSound', :path => '../node_modules/react-native-sound' pod 'RNSound', :path => '../node_modules/react-native-sound'
pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-async-storage/async-storage'
target 'PianoAppTests' do target 'PianoAppTests' do
inherit! :complete inherit! :complete
# Pods for testing # Pods for testing
......
...@@ -11,15 +11,9 @@ import { ...@@ -11,15 +11,9 @@ import {
ScrollView, ScrollView,
// Alert, // Alert,
} from 'react-native'; } from 'react-native';
//import {Icon} from 'react-native-elements'; import AsyncStorage from '@react-native-async-storage/async-storage';
//import AsyncStorage from '@react-native-async-storage/async-storage';
import Orientation from 'react-native-orientation'; import Orientation from 'react-native-orientation';
//import AsyncStorage from '@react-native-async-storage/async-storage';
import * as RNFS from 'react-native-fs';
var path = RNFS.DocumentDirectoryPath + '/test.txt';
//var array = [];
class LogBook extends React.PureComponent { class LogBook extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -29,17 +23,19 @@ class LogBook extends React.PureComponent { ...@@ -29,17 +23,19 @@ class LogBook extends React.PureComponent {
}; };
} }
displayData = async () => { displayData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_key');
if (value !== null) {
// We have data!!
// console.log(JSON.parse(value));
this.setState({ logbook: JSON.parse(value) });
console.log(this.state.logbook.length);
RNFS.readFile(path, 'ascii') }
.then((res) => { } catch (error) {
this.setState({ // Error retrieving data
logbook: res.split('\n'), }
}); console.log(this.state.logbook);
console.log(this.state.logbook);
})
.catch((err) => {
console.log(err.message, err.code);
});
}; };
componentDidMount() { componentDidMount() {
...@@ -47,6 +43,7 @@ class LogBook extends React.PureComponent { ...@@ -47,6 +43,7 @@ class LogBook extends React.PureComponent {
this.displayData(); this.displayData();
} }
render() { render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
...@@ -61,19 +58,30 @@ class LogBook extends React.PureComponent { ...@@ -61,19 +58,30 @@ class LogBook extends React.PureComponent {
style={{ style={{
marginTop: 50, marginTop: 50,
}}> }}>
{this.state.logbook.map((item, id) => (
<View <View
key={id}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
padding: 15, padding: 10,
backgroundColor: 'white', backgroundColor: 'white',
borderBottomWidth:1, borderBottomWidth:1,
}}> }}>
<Text style={{fontSize:17}}>{item.split(',').join('\n')}</Text> <View style={{alignItems: 'center', paddingLeft:15, paddingRight:15}}>
<View style={{marginRight:5, marginBottom:5}}>
<Text style={{color:'black', fontSize: 40}}>{(this.state.logbook.date !== undefined) ? this.state.logbook.date.split(' ')[0].trim() : ''}</Text>
<Text style={{color:'black', fontSize: 15}}>{(this.state.logbook.date !== undefined) ? this.state.logbook.date.split(' ')[1].trim() : ''}</Text>
</View>
<View style={{marginRight:5}}>
<Text style={{color:'black', fontSize: 15}}>{this.state.logbook.day}</Text>
</View>
</View>
<View style={{borderWidth:1, borderColor : 'blue'}}/>
<View style={{flexDirection: 'column',marginLeft:5,marginTop:5}}>
<Text style={{color:'green', fontSize: 15}}>Correct : {this.state.logbook.correct}</Text>
<Text style={{color:'red', fontSize: 15}}>Wrong : {this.state.logbook.wrong}</Text>
<Text style={{color:'black', fontSize: 15}}>Timer : {this.state.logbook.timer}</Text>
<Text style={{color:'black', fontSize: 15}}>Time : {this.state.logbook.time}</Text>
</View>
</View> </View>
)).reverse()}
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
</ImageBackground> </ImageBackground>
......
...@@ -638,6 +638,7 @@ class Quiz extends React.Component { ...@@ -638,6 +638,7 @@ class Quiz extends React.Component {
this.setState({ this.setState({
logbook: res.split(','), logbook: res.split(','),
}); });
console.log(this.state.logbook);
RNFS.readFile(path1, 'ascii') RNFS.readFile(path1, 'ascii')
.then((ccc) => { .then((ccc) => {
console.log('has notes has counter'); console.log('has notes has counter');
......
/* eslint-disable prettier/prettier */ /* eslint-disable prettier/prettier */
/*This is an Example of Calling Other Class Function in React Native*/ /*This is an Example of Calling Other Class Function in React Native*/
import { Component } from 'react'; import { Component } from 'react';
import {Alert} from 'react-native';
import moment from 'moment'; import moment from 'moment';
import * as RNFS from 'react-native-fs'; import AsyncStorage from '@react-native-async-storage/async-storage';
const date = moment().utcOffset('+08:00').format('D MMM YYYY'); const date = moment().utcOffset('+08:00').format('D MMM');
const time = moment().utcOffset('+08:00').format('h:mm a'); const time = moment().utcOffset('+08:00').format('h:mm a');
const record = RNFS.DocumentDirectoryPath + '/test.txt'; const day = moment().utcOffset('+08:00').format('ddd');
var records = [];
class OtherClass extends Component { class OtherClass extends Component {
functionWithoutArg = () => {
//function to be called from default class (without args)
Alert.alert('Function Called Without Argument ');
};
functionWithArg = (Value) => {
//function to called from default class (with args)
Alert.alert(Value);
};
saveRecord = async (correct, wrong, stime) => { saveRecord = async (correct, wrong, stime) => {
let obj = { let obj = {
correct: correct, correct: correct,
...@@ -27,63 +16,41 @@ class OtherClass extends Component { ...@@ -27,63 +16,41 @@ class OtherClass extends Component {
timer: stime, timer: stime,
date: date, date: date,
time: time, time: time,
day : day,
}; };
if (await RNFS.exists(record)) {
console.log('BLAH EXISTS'); try {
// write the file const value = await AsyncStorage.getItem('@storage_key');
RNFS.appendFile( if (value !== null) {
record, // We have data!!
'Correct : ' + console.log(JSON.parse(value));
JSON.stringify(obj.correct) + records.push(JSON.parse(value));
',' + records.push(JSON.parse(obj));
'Wrong : ' + //console.log(records);
JSON.stringify(obj.wrong) + AsyncStorage.setItem('@storage_key', JSON.stringify(records), (err)=> {
',' + if (err){
'Timer : ' + console.log('an error');
stime + throw err;
',' + }
'Date : ' + // console.log('success');
date + }).catch((err)=> {
',' + console.log('error is: ' + err);
'Time : ' +
time +
'\n',
'utf8',
)
.then((success) => {
console.log(JSON.stringify(obj));
})
.catch((err) => {
console.log(err.message);
}); });
} else { }
console.log('BLAH DOES NOT EXIST'); else {
RNFS.writeFile( AsyncStorage.setItem('@storage_key', JSON.stringify(obj), (err)=> {
record, if (err){
'Correct : ' + console.log('an error');
JSON.stringify(obj.correct) + throw err;
',' + }
'Wrong : ' + // console.log('success');
JSON.stringify(obj.wrong) + }).catch((err)=> {
',' + console.log('error is: ' + err);
'Timer : ' +
stime +
',' +
'Date : ' +
date +
',' +
'Time : ' +
time +
'\n',
'utf8',
)
.then((success) => {
console.log(JSON.stringify(obj));
})
.catch((err) => {
console.log(err.message);
}); });
} }
} catch (error) {
// Error retrieving data
}
}; };
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import React from 'react'; import React from 'react';
import { import {
SafeAreaView, SafeAreaView,
ImageBackground, //ImageBackground,
Text, Text,
View, View,
TouchableOpacity, TouchableOpacity,
...@@ -63,6 +63,7 @@ export default class Settings extends React.Component { ...@@ -63,6 +63,7 @@ export default class Settings extends React.Component {
super(props); super(props);
this.state = { this.state = {
value: 0, value: 0,
listN : [],
}; };
} }
toggleKeyword = (keyword) => { toggleKeyword = (keyword) => {
...@@ -74,16 +75,16 @@ export default class Settings extends React.Component { ...@@ -74,16 +75,16 @@ export default class Settings extends React.Component {
} else { } else {
list.push(keyword); list.push(keyword);
} }
this.setState({notes: list}); this.setState({listN: list});
this.saveData(notes); this.saveData(this.state.listN);
this.displayData(); this.displayData();
// console.log(notes); // console.log(notes);
}; };
saveData = async () => { saveData = async () => {
RNFS.writeFile(path,JSON.stringify(notes),'utf8',) RNFS.writeFile(path,JSON.stringify(this.state.listN),'utf8',)
.then((success) => { .then((success) => {
console.log(JSON.stringify(notes)); console.log(JSON.stringify(this.state.listN));
}) })
.catch((err) => { .catch((err) => {
console.log(err.message); console.log(err.message);
...@@ -231,7 +232,7 @@ const styles = StyleSheet.create({ ...@@ -231,7 +232,7 @@ const styles = StyleSheet.create({
borderWidth: 1, borderWidth: 1,
borderColor: 'black', borderColor: 'black',
borderRadius: 10, borderRadius: 10,
backgroundColor: 'rgba(0,0,0,0)', backgroundColor: 'rgba(52, 52, 52, 0.0)',
//opacity: 0.5, //opacity: 0.5,
padding: 10, padding: 10,
marginRight: config.deviceWidth * 0.03, marginRight: config.deviceWidth * 0.03,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment