From bdc836f1e70bbd52c82bdde47510e25dc31efb76 Mon Sep 17 00:00:00 2001 From: Tuan Date: Tue, 21 Mar 2017 11:46:56 -0700 Subject: [PATCH 01/13] Added low battery warning --- app/containers/Application.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 0b0298d0..36cf6f9c 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -74,6 +74,10 @@ class Application extends Component { user: PropTypes.shape({ _id: PropTypes.string, }), + device: PropTypes.shape({ + device: PropTypes.object, + batteryLevel: PropTypes.bool, + }), }; constructor() { @@ -82,6 +86,7 @@ class Application extends Component { this.state = { initializing: true, initialRoute: null, + lowBatteryWarning: true, }; this.navigator = null; // Components should use this custom navigator object @@ -310,6 +315,20 @@ class Application extends Component { }); } + // Alerts user when the deivce batter level is below 15%. This will only notify + // user once when the application open. + componentWillReceiveProps() { + const batteryLevel = this.props.device.device.batteryLevel; + if (this.state.lowBatteryWarning && batteryLevel < 15) { + this.setState({ lowBatteryWarning: false }); + Alert.alert( + 'Low Battery', + `${batteryLevel} of battery remaining`, + { text: 'Dismiss' } + ); + } + } + componentWillUnmount() { if (this.bluetoothListener) { this.bluetoothListener.remove(); @@ -328,7 +347,6 @@ class Application extends Component { } AppState.removeEventListener('change', this.handleAppStateChange); } - /** * Defines the initial scene to mount and ends the initialization process * @param {Object} route=routes.welcome Route object, defaults to the welcome route @@ -499,8 +517,8 @@ class Application extends Component { } const mapStateToProps = (state) => { - const { app, user: { user } } = state; - return { app, user }; + const { app, user: { user }, device } = state; + return { app, user, device }; }; export default connect(mapStateToProps)(Application); From 047a88fe57c5b764d7dcd2a8369da662538f6a83 Mon Sep 17 00:00:00 2001 From: Tuan Date: Tue, 21 Mar 2017 12:20:12 -0700 Subject: [PATCH 02/13] Modified alert message --- app/containers/Application.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 36cf6f9c..e30e1491 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -315,17 +315,19 @@ class Application extends Component { }); } - // Alerts user when the deivce batter level is below 15%. This will only notify - // user once when the application open. + // Alerts user when the deivce battery is below 15%. This will only notify + // user once when the application opens. componentWillReceiveProps() { - const batteryLevel = this.props.device.device.batteryLevel; - if (this.state.lowBatteryWarning && batteryLevel < 15) { - this.setState({ lowBatteryWarning: false }); - Alert.alert( - 'Low Battery', - `${batteryLevel} of battery remaining`, - { text: 'Dismiss' } - ); + if (this.state.lowBatteryWarning) { + const batteryLevel = this.props.device.device.batteryLevel; + if (batteryLevel < 15) { + this.setState({ lowBatteryWarning: false }); + Alert.alert( + 'Backbone Low Battery', + `${batteryLevel}% of battery remaining`, + [{text: 'Dismiss'}] + ); + } } } From c7beea053442a99f74021166e2c2f1911b7bae65 Mon Sep 17 00:00:00 2001 From: Tuan Date: Tue, 21 Mar 2017 12:20:57 -0700 Subject: [PATCH 03/13] Modified alert message --- app/containers/Application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index e30e1491..7a46ed5c 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -325,7 +325,7 @@ class Application extends Component { Alert.alert( 'Backbone Low Battery', `${batteryLevel}% of battery remaining`, - [{text: 'Dismiss'}] + [{ text: 'Dismiss' }] ); } } From fcc6bcdb10ff694ba2d729f0221e2912a3ac7c16 Mon Sep 17 00:00:00 2001 From: tuan-gobackbone Date: Tue, 21 Mar 2017 12:29:14 -0700 Subject: [PATCH 04/13] Update Application.js --- app/containers/Application.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/containers/Application.js b/app/containers/Application.js index 7a46ed5c..8b4797ff 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -349,6 +349,7 @@ class Application extends Component { } AppState.removeEventListener('change', this.handleAppStateChange); } + /** * Defines the initial scene to mount and ends the initialization process * @param {Object} route=routes.welcome Route object, defaults to the welcome route From 1a183a96717ef0a3ea69b4a4b8886ffcf3f6bc34 Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Tue, 21 Mar 2017 12:43:02 -0700 Subject: [PATCH 05/13] Update to include 15% --- app/containers/Application.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 7a46ed5c..4b0448f1 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -315,12 +315,12 @@ class Application extends Component { }); } - // Alerts user when the deivce battery is below 15%. This will only notify + // Alerts user when the deivce battery is 15% or less. This will only notify // user once when the application opens. componentWillReceiveProps() { if (this.state.lowBatteryWarning) { const batteryLevel = this.props.device.device.batteryLevel; - if (batteryLevel < 15) { + if (batteryLevel <= 15) { this.setState({ lowBatteryWarning: false }); Alert.alert( 'Backbone Low Battery', @@ -349,6 +349,7 @@ class Application extends Component { } AppState.removeEventListener('change', this.handleAppStateChange); } + /** * Defines the initial scene to mount and ends the initialization process * @param {Object} route=routes.welcome Route object, defaults to the welcome route From c72416a28bfc8fdb999cf6cb219cfff84cd3fbb8 Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Tue, 21 Mar 2017 15:31:16 -0700 Subject: [PATCH 06/13] Updated state, PropType, alert message --- app/containers/Application.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 4b0448f1..28d9b905 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -75,8 +75,9 @@ class Application extends Component { _id: PropTypes.string, }), device: PropTypes.shape({ - device: PropTypes.object, - batteryLevel: PropTypes.bool, + device: PropTypes.shape({ + batteryLevel: PropTypes.number, + }) }), }; @@ -86,7 +87,7 @@ class Application extends Component { this.state = { initializing: true, initialRoute: null, - lowBatteryWarning: true, + hasDisplayedLowBatteryWarning: false, }; this.navigator = null; // Components should use this custom navigator object @@ -315,17 +316,15 @@ class Application extends Component { }); } - // Alerts user when the deivce battery is 15% or less. This will only notify - // user once when the application opens. - componentWillReceiveProps() { - if (this.state.lowBatteryWarning) { - const batteryLevel = this.props.device.device.batteryLevel; + // Alerts the user anytime the Backbone device's battery drops to 15% or lower. + componentWillReceiveProps(nextProps) { + if (!this.state.hasDisplayedLowBatteryWarning) { + const batteryLevel = nextProps.device.device.batteryLevel; if (batteryLevel <= 15) { - this.setState({ lowBatteryWarning: false }); + this.setState({ hasDisplayedLowBatteryWarning: true }); Alert.alert( 'Backbone Low Battery', - `${batteryLevel}% of battery remaining`, - [{ text: 'Dismiss' }] + `${batteryLevel}% of battery remaining` ); } } From 8a5d5a5dd4df0953ec20ea9e1eb8bb866bbf0ef7 Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Tue, 21 Mar 2017 15:33:18 -0700 Subject: [PATCH 07/13] Added comma --- app/containers/Application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 28d9b905..9c8c6a49 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -77,7 +77,7 @@ class Application extends Component { device: PropTypes.shape({ device: PropTypes.shape({ batteryLevel: PropTypes.number, - }) + }), }), }; From 626c88cde55d7a5e6c46f009bac7061fe07b8521 Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Tue, 21 Mar 2017 15:49:35 -0700 Subject: [PATCH 08/13] update device mapToStateProps --- app/containers/Application.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 9c8c6a49..c43e7aa2 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -319,7 +319,7 @@ class Application extends Component { // Alerts the user anytime the Backbone device's battery drops to 15% or lower. componentWillReceiveProps(nextProps) { if (!this.state.hasDisplayedLowBatteryWarning) { - const batteryLevel = nextProps.device.device.batteryLevel; + const batteryLevel = nextProps.device.batteryLevel; if (batteryLevel <= 15) { this.setState({ hasDisplayedLowBatteryWarning: true }); Alert.alert( @@ -519,7 +519,7 @@ class Application extends Component { } const mapStateToProps = (state) => { - const { app, user: { user }, device } = state; + const { app, user: { user }, device: { device } } = state; return { app, user, device }; }; From b5dc99f4b1157f562ccc21766f8a0721643a2791 Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Tue, 21 Mar 2017 16:17:29 -0700 Subject: [PATCH 09/13] updated low power comment --- app/containers/Application.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/containers/Application.js b/app/containers/Application.js index c43e7aa2..a896dba6 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -317,6 +317,7 @@ class Application extends Component { } // Alerts the user anytime the Backbone device's battery drops to 15% or lower. + // Alert will only trigger once during the lifetime of the app. componentWillReceiveProps(nextProps) { if (!this.state.hasDisplayedLowBatteryWarning) { const batteryLevel = nextProps.device.batteryLevel; From 004a1ea13e26ee2cb4375b6b5c0c715cda2d976c Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Tue, 21 Mar 2017 21:52:16 -0700 Subject: [PATCH 10/13] Removed device PropType and added minimum battery level --- app/containers/Application.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index a896dba6..d8b6dc23 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -75,9 +75,7 @@ class Application extends Component { _id: PropTypes.string, }), device: PropTypes.shape({ - device: PropTypes.shape({ - batteryLevel: PropTypes.number, - }), + batteryLevel: PropTypes.number, }), }; @@ -316,12 +314,12 @@ class Application extends Component { }); } - // Alerts the user anytime the Backbone device's battery drops to 15% or lower. + // Alerts the user when the Backbone's battery drops to 15% or lower. // Alert will only trigger once during the lifetime of the app. componentWillReceiveProps(nextProps) { if (!this.state.hasDisplayedLowBatteryWarning) { const batteryLevel = nextProps.device.batteryLevel; - if (batteryLevel <= 15) { + if (batteryLevel <= 90 && batteryLevel > 0) { this.setState({ hasDisplayedLowBatteryWarning: true }); Alert.alert( 'Backbone Low Battery', From 893a044f7ad63d9db4a67bec098aa37e20e62ce4 Mon Sep 17 00:00:00 2001 From: tuan-gobackbone Date: Wed, 22 Mar 2017 09:03:25 -0700 Subject: [PATCH 11/13] Update Application.js --- app/containers/Application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index d8b6dc23..062dea75 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -319,7 +319,7 @@ class Application extends Component { componentWillReceiveProps(nextProps) { if (!this.state.hasDisplayedLowBatteryWarning) { const batteryLevel = nextProps.device.batteryLevel; - if (batteryLevel <= 90 && batteryLevel > 0) { + if (batteryLevel <= 15 && batteryLevel > 0) { this.setState({ hasDisplayedLowBatteryWarning: true }); Alert.alert( 'Backbone Low Battery', From f245bb58af694ded7d1806f0eb36cb7712050da5 Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Wed, 22 Mar 2017 09:47:22 -0700 Subject: [PATCH 12/13] deconstructor for batteryLevel --- app/containers/Application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 9a9c3f43..f69320d2 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -312,7 +312,7 @@ class Application extends Component { // Alert will only trigger once during the lifetime of the app. componentWillReceiveProps(nextProps) { if (!this.state.hasDisplayedLowBatteryWarning) { - const batteryLevel = nextProps.device.batteryLevel; + const { batteryLevel } = nextProps.device; if (batteryLevel <= 15 && batteryLevel > 0) { this.setState({ hasDisplayedLowBatteryWarning: true }); Alert.alert( From ea6db0b1e25abf273298ca5b872de6ad71de5780 Mon Sep 17 00:00:00 2001 From: Tuan Ho Date: Thu, 23 Mar 2017 12:11:17 -0700 Subject: [PATCH 13/13] Updated alert message --- app/containers/Application.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index f69320d2..72a4a70c 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -316,8 +316,8 @@ class Application extends Component { if (batteryLevel <= 15 && batteryLevel > 0) { this.setState({ hasDisplayedLowBatteryWarning: true }); Alert.alert( - 'Backbone Low Battery', - `${batteryLevel}% of battery remaining` + 'Your Backbone battery is low', + `Your Backbone battery is at ${batteryLevel}%. Charge your Backbone as soon as possible.` ); } }