From 000e1b63c798859d96fc0164f32c7449a972f0e4 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Fri, 21 Dec 2018 17:14:27 +0100 Subject: [PATCH 1/4] Add license page --- components/app-wrapper.js | 39 +++++++++++++++------- components/button.js | 18 ++++++++++ components/home.js | 26 ++++----------- components/license.js | 22 ++++++++++++ i18n/en/labels.js | 2 ++ local-storage/index.js => local-storage.js | 11 +++++- styles/index.js | 16 ++++++++- 7 files changed, 101 insertions(+), 33 deletions(-) create mode 100644 components/button.js create mode 100644 components/license.js rename local-storage/index.js => local-storage.js (89%) diff --git a/components/app-wrapper.js b/components/app-wrapper.js index cd50bb7..90a904e 100644 --- a/components/app-wrapper.js +++ b/components/app-wrapper.js @@ -3,26 +3,41 @@ import { View } from 'react-native' import nodejs from 'nodejs-mobile-react-native' import App from './app' import PasswordPrompt from './password-prompt' +import License from './license' +import { getLicenseFlag } from '../local-storage' export default class AppWrapper extends Component { constructor() { super() - this.state = {} + this.state = { + showLicense: true + } nodejs.start('main.js') + this.checkLicenseAgreement() } + + async checkLicenseAgreement() { + const agreed = await getLicenseFlag() + console.log(agreed) + if (agreed) this.setState({showLicense: false}) + } + render() { return ( - - {this.state.showApp ? - - : - { - this.setState({showApp: true}) - }} - /> - } - + this.state.showLicense ? + + : + + {this.state.showApp ? + + : + { + this.setState({showApp: true}) + }} + /> + } + ) } } \ No newline at end of file diff --git a/components/button.js b/components/button.js new file mode 100644 index 0000000..696c918 --- /dev/null +++ b/components/button.js @@ -0,0 +1,18 @@ +import React from 'react' +import { View } from 'react-native' +import AppText from './app-text' +import styles from '../styles' + +export default function Button({ backgroundColor, style, children }) { + return ( + + + {children} + + + ) +} \ No newline at end of file diff --git a/components/home.js b/components/home.js index e57633d..ffba42f 100644 --- a/components/home.js +++ b/components/home.js @@ -10,19 +10,7 @@ import { getFertilityStatusForDay } from '../lib/sympto-adapter' import styles from '../styles' import AppText, { AppTextLight } from './app-text' import DripHomeIcon from '../assets/drip-home-icons' - -const HomeButton = ({ backgroundColor, children }) => { - return ( - - - {children} - - - ) -} +import Button from './button' export default class Home extends Component { constructor(props) { @@ -78,9 +66,9 @@ export default class Home extends Component { {cycleDayMoreText} } - + @@ -103,9 +91,9 @@ export default class Home extends Component { } - + @@ -136,9 +124,9 @@ export default class Home extends Component { } - + diff --git a/components/license.js b/components/license.js new file mode 100644 index 0000000..4e5027d --- /dev/null +++ b/components/license.js @@ -0,0 +1,22 @@ +import React from 'react' +import { ScrollView, View } from 'react-native' +import AppText from './app-text' +import { licenseText, shared } from '../i18n/en/labels' +import styles,{secondaryColor} from '../styles' +import Button from './button' + +export default function License() { + return ( + + {licenseText} + + + + + + ) +} \ No newline at end of file diff --git a/i18n/en/labels.js b/i18n/en/labels.js index 1917917..b3842ed 100644 --- a/i18n/en/labels.js +++ b/i18n/en/labels.js @@ -117,3 +117,5 @@ export const fertilityStatus = { ) } } + +export const licenseText = 'This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall copyright holders be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.' \ No newline at end of file diff --git a/local-storage/index.js b/local-storage.js similarity index 89% rename from local-storage/index.js rename to local-storage.js index 89b37d9..4cc9c75 100644 --- a/local-storage/index.js +++ b/local-storage.js @@ -1,6 +1,6 @@ import { AsyncStorage } from 'react-native' import Observable from 'obv' -import config from '../config' +import config from './config' export const scaleObservable = Observable() setObvWithInitValue('tempScale', scaleObservable, { @@ -60,6 +60,15 @@ export async function saveEncryptionFlag(bool) { hasEncryptionObservable.set(bool) } + +export async function getLicenseFlag() { + return AsyncStorage.getItem('agreedToLicense') +} + +export async function saveLicenseFlag() { + await AsyncStorage.setItem('agreedToLicense', JSON.stringify(true)) +} + async function setObvWithInitValue(key, obv, defaultValue) { const result = await AsyncStorage.getItem(key) let value diff --git a/styles/index.js b/styles/index.js index 1c6cf62..18f07d8 100644 --- a/styles/index.js +++ b/styles/index.js @@ -89,11 +89,13 @@ export default StyleSheet.create({ marginHorizontal: 50, marginTop: 20, }, - homeButton: { + button: { paddingVertical: 10, paddingHorizontal: 20, borderRadius: 5, alignItems: 'center', + }, + homeButton: { width: 200, }, homeButtonText: { @@ -391,6 +393,18 @@ export default StyleSheet.create({ passwordPromptForgotPasswordText: { marginTop: 20, color: 'grey' + }, + licensePage: { + paddingVertical: 20, + paddingHorizontal: 20 + }, + licenseButtons: { + flexDirection: 'row', + justifyContent: 'flex-end' + }, + licenseButton: { + marginLeft: 30, + width: 100 } }) From 2c1b856234c4bda6db57592588f6c65ff7f367d9 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Sun, 23 Dec 2018 16:46:10 +0100 Subject: [PATCH 2/4] Add press handlers to buttons --- components/app-wrapper.js | 3 +-- components/button.js | 20 +++++++++++--------- components/home.js | 12 +++++++++--- components/license.js | 20 ++++++++++++++++---- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/components/app-wrapper.js b/components/app-wrapper.js index 90a904e..0ac1748 100644 --- a/components/app-wrapper.js +++ b/components/app-wrapper.js @@ -18,14 +18,13 @@ export default class AppWrapper extends Component { async checkLicenseAgreement() { const agreed = await getLicenseFlag() - console.log(agreed) if (agreed) this.setState({showLicense: false}) } render() { return ( this.state.showLicense ? - + this.setState({showLicense: false})}/> : {this.state.showApp ? diff --git a/components/button.js b/components/button.js index 696c918..70d778e 100644 --- a/components/button.js +++ b/components/button.js @@ -1,18 +1,20 @@ import React from 'react' -import { View } from 'react-native' +import { TouchableOpacity } from 'react-native' import AppText from './app-text' import styles from '../styles' -export default function Button({ backgroundColor, style, children }) { +export default function Button(props) { return ( - + - {children} + {props.children} - + ) } \ No newline at end of file diff --git a/components/home.js b/components/home.js index ffba42f..37e04c2 100644 --- a/components/home.js +++ b/components/home.js @@ -66,7 +66,9 @@ export default class Home extends Component { {cycleDayMoreText} } - @@ -91,7 +93,9 @@ export default class Home extends Component { } - @@ -124,7 +128,9 @@ export default class Home extends Component { } - diff --git a/components/license.js b/components/license.js index 4e5027d..0da53e1 100644 --- a/components/license.js +++ b/components/license.js @@ -1,19 +1,31 @@ import React from 'react' -import { ScrollView, View } from 'react-native' +import { ScrollView, View, BackHandler } from 'react-native' import AppText from './app-text' import { licenseText, shared } from '../i18n/en/labels' import styles,{secondaryColor} from '../styles' import Button from './button' +import { saveLicenseFlag } from '../local-storage'; -export default function License() { +export default function License({setLicense}) { return ( {licenseText} - - From 480e4533bec756e85fc60398bb36092f865d073e Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Wed, 2 Jan 2019 14:47:43 +0100 Subject: [PATCH 3/4] Fix license screen flicker --- components/app-wrapper.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/components/app-wrapper.js b/components/app-wrapper.js index 0ac1748..4e8665b 100644 --- a/components/app-wrapper.js +++ b/components/app-wrapper.js @@ -10,7 +10,7 @@ export default class AppWrapper extends Component { constructor() { super() this.state = { - showLicense: true + retrievingLicenseSetting: true } nodejs.start('main.js') this.checkLicenseAgreement() @@ -18,25 +18,27 @@ export default class AppWrapper extends Component { async checkLicenseAgreement() { const agreed = await getLicenseFlag() - if (agreed) this.setState({showLicense: false}) + this.setState({retrievingLicenseSetting: false}) + if (!agreed) this.setState({showLicense: true}) } render() { - return ( - this.state.showLicense ? - this.setState({showLicense: false})}/> - : - - {this.state.showApp ? - - : - { - this.setState({showApp: true}) - }} - /> - } - - ) + const whiteScreen = + const licenseScreen = { + this.setState({showLicense: false}) + }}/> + const passwordPrompt = { + this.setState({showApp: true}) + }}/> + + if (this.state.retrievingLicenseSetting) { + return whiteScreen + } else if (this.state.showLicense) { + return licenseScreen + } else if (!this.state.showApp) { + return passwordPrompt + } else { + return + } } } \ No newline at end of file From b80c197b9c09be2cc014c0af9f71b724e6357de4 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Tue, 8 Jan 2019 09:41:56 +0100 Subject: [PATCH 4/4] Use GNU license on license screen --- components/license.js | 13 ++++++++++--- i18n/en/labels.js | 4 +--- i18n/en/settings.js | 5 +---- styles/index.js | 5 +++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/components/license.js b/components/license.js index 0da53e1..8fdfc9e 100644 --- a/components/license.js +++ b/components/license.js @@ -1,15 +1,22 @@ import React from 'react' import { ScrollView, View, BackHandler } from 'react-native' +import Hyperlink from 'react-native-hyperlink' import AppText from './app-text' -import { licenseText, shared } from '../i18n/en/labels' +import { shared } from '../i18n/en/labels' +import settingsLabels from '../i18n/en/settings' import styles,{secondaryColor} from '../styles' import Button from './button' -import { saveLicenseFlag } from '../local-storage'; +import { saveLicenseFlag } from '../local-storage' +import replace from './helpers/replace-url-with-text' +const labels = settingsLabels.license export default function License({setLicense}) { return ( - {licenseText} + + {labels.title} + {labels.text} +