From 055eb6ced651c7e65571afdf33f4b15299abafc9 Mon Sep 17 00:00:00 2001 From: Eko Mirhard Date: Sat, 8 Apr 2017 12:59:09 +0700 Subject: [PATCH 1/6] Prevent the app to navigate away from alert scene on active sessions --- app/components/posture/PostureMonitor.js | 5 ++++- app/containers/Application.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/components/posture/PostureMonitor.js b/app/components/posture/PostureMonitor.js index 47812bfe..c2a4ebca 100755 --- a/app/components/posture/PostureMonitor.js +++ b/app/components/posture/PostureMonitor.js @@ -176,7 +176,10 @@ class PostureMonitor extends Component { this.sessionStateListener = SessionControlServiceEvents.addListener('SessionState', event => { if (event.hasActiveSession) { // There is currently an active session running on the device, resume session - this.resumeSession(); + // only if we are not on the Alert scene + if (this.props.currentRoute.name !== routes.alerts.name) { + this.resumeSession(); + } } else { // There is no active session running on the device, invoke statsHandler to show summary this.statsHandler(event); diff --git a/app/containers/Application.js b/app/containers/Application.js index a474ea60..11d6c2b5 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -187,8 +187,11 @@ class Application extends Component { // There is an active session, check if we're on the PostureMonitor scene if (this.navigator) { const routeStack = this.navigator.getCurrentRoutes(); + // Making sure that we are not on the Alert scene inside the Monitor const currentRoute = routeStack[routeStack.length - 1]; - if (currentRoute.name !== routes.postureMonitor.name) { + const parentRoute = routeStack[routeStack.length - (routeStack.length > 1 ? 2 : 1)]; + if (currentRoute.name !== routes.postureMonitor.name + && parentRoute.name !== routes.postureMonitor.name) { // Not currently on the PostureMonitor scene // Navigate to PostureMonitor to resume session using previous session parameters SensitiveInfo.getItem(storageKeys.SESSION_STATE) From b1ff76065a81bcefe14602aea69dac503cbd2e5f Mon Sep 17 00:00:00 2001 From: Eko Mirhard Date: Sat, 8 Apr 2017 16:17:05 +0700 Subject: [PATCH 2/6] Refactor for better flexibility --- app/components/posture/PostureMonitor.js | 2 +- app/containers/Application.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/components/posture/PostureMonitor.js b/app/components/posture/PostureMonitor.js index c2a4ebca..00a05d5b 100755 --- a/app/components/posture/PostureMonitor.js +++ b/app/components/posture/PostureMonitor.js @@ -177,7 +177,7 @@ class PostureMonitor extends Component { if (event.hasActiveSession) { // There is currently an active session running on the device, resume session // only if we are not on the Alert scene - if (this.props.currentRoute.name !== routes.alerts.name) { + if (this.props.currentRoute.name === routes.postureMonitor.name) { this.resumeSession(); } } else { diff --git a/app/containers/Application.js b/app/containers/Application.js index 11d6c2b5..24387ef4 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -187,11 +187,18 @@ class Application extends Component { // There is an active session, check if we're on the PostureMonitor scene if (this.navigator) { const routeStack = this.navigator.getCurrentRoutes(); - // Making sure that we are not on the Alert scene inside the Monitor - const currentRoute = routeStack[routeStack.length - 1]; - const parentRoute = routeStack[routeStack.length - (routeStack.length > 1 ? 2 : 1)]; - if (currentRoute.name !== routes.postureMonitor.name - && parentRoute.name !== routes.postureMonitor.name) { + // Stay on the current scene if postureMonitor is still in the stack + let shouldGoToPostureMonitor = true; + for (let i = 0; i < routeStack.length; i++) { + // Route to the last route before DeviceScan / DeviceConnect + // If it matches device or postureDashboard in that order + if (routeStack[i].name === routes.postureMonitor.name) { + shouldGoToPostureMonitor = false; + break; + } + } + + if (shouldGoToPostureMonitor) { // Not currently on the PostureMonitor scene // Navigate to PostureMonitor to resume session using previous session parameters SensitiveInfo.getItem(storageKeys.SESSION_STATE) From e1013e351e766c2efc65edbc1081cd2b5aa04c1d Mon Sep 17 00:00:00 2001 From: Eko Mirhard Date: Sat, 8 Apr 2017 16:25:05 +0700 Subject: [PATCH 3/6] Replace comments --- app/containers/Application.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/containers/Application.js b/app/containers/Application.js index 24387ef4..05085f6d 100644 --- a/app/containers/Application.js +++ b/app/containers/Application.js @@ -187,11 +187,10 @@ class Application extends Component { // There is an active session, check if we're on the PostureMonitor scene if (this.navigator) { const routeStack = this.navigator.getCurrentRoutes(); - // Stay on the current scene if postureMonitor is still in the stack + // Stay on the current scene if postureMonitor is still in the stack. + // Only navigate to it when the user's currently not accessing the monitor let shouldGoToPostureMonitor = true; for (let i = 0; i < routeStack.length; i++) { - // Route to the last route before DeviceScan / DeviceConnect - // If it matches device or postureDashboard in that order if (routeStack[i].name === routes.postureMonitor.name) { shouldGoToPostureMonitor = false; break; From 5d046153f5f0bc1debdc7731719dcd0dbdfb144d Mon Sep 17 00:00:00 2001 From: Eko Mirhard Date: Sun, 9 Apr 2017 11:56:42 +0700 Subject: [PATCH 4/6] Manually bind some session methods --- app/components/posture/PostureMonitor.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/components/posture/PostureMonitor.js b/app/components/posture/PostureMonitor.js index 00a05d5b..efa37599 100755 --- a/app/components/posture/PostureMonitor.js +++ b/app/components/posture/PostureMonitor.js @@ -148,6 +148,11 @@ class PostureMonitor extends Component { // Debounce update of user posture threshold setting to limit the number of API requests this.updateUserPostureThreshold = debounce(this.updateUserPostureThreshold, 1000); this.backAndroidListener = null; + + // Manually bind these methods to ensure valid instance state + // especially after interacting with foreground session controls + this.pauseSession = this.pauseSession.bind(this); + this.resumeSession = this.resumeSession.bind(this); } componentWillMount() { @@ -582,7 +587,6 @@ class PostureMonitor extends Component { }); } - @autobind pauseSession() { if (!this.state.hasPendingSessionOperation) { this.setState({ hasPendingSessionOperation: true }); @@ -619,7 +623,6 @@ class PostureMonitor extends Component { } } - @autobind resumeSession() { if (!this.state.hasPendingSessionOperation) { this.setState({ hasPendingSessionOperation: true }); From 276bb007396474dd65c439c805fd5c23b3949cde Mon Sep 17 00:00:00 2001 From: Eko Mirhard Date: Thu, 13 Apr 2017 01:11:49 +0700 Subject: [PATCH 5/6] Resume only when needed --- app/components/posture/PostureMonitor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/components/posture/PostureMonitor.js b/app/components/posture/PostureMonitor.js index ea29613d..3e66e05a 100755 --- a/app/components/posture/PostureMonitor.js +++ b/app/components/posture/PostureMonitor.js @@ -183,8 +183,9 @@ class PostureMonitor extends Component { this.sessionStateListener = SessionControlServiceEvents.addListener('SessionState', event => { if (event.hasActiveSession) { // There is currently an active session running on the device, resume session - // only if we are not on the Alert scene - if (this.props.currentRoute.name === routes.postureMonitor.name) { + // only if we are not on the Alert scene and the session's paused + if (this.props.currentRoute.name === routes.postureMonitor.name + && this.state.sessionState !== sessionStates.RUNNING) { this.resumeSession(); } } else { From af6abd53f003413c7e096c9df53858576b7e49bc Mon Sep 17 00:00:00 2001 From: Eko Mirhard Date: Thu, 13 Apr 2017 09:05:15 +0700 Subject: [PATCH 6/6] Remove manual binding --- app/components/posture/PostureMonitor.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/components/posture/PostureMonitor.js b/app/components/posture/PostureMonitor.js index 3e66e05a..9c477593 100755 --- a/app/components/posture/PostureMonitor.js +++ b/app/components/posture/PostureMonitor.js @@ -150,11 +150,6 @@ class PostureMonitor extends Component { // Debounce update of user posture threshold setting to limit the number of API requests this.updateUserPostureThreshold = debounce(this.updateUserPostureThreshold, 1000); this.backAndroidListener = null; - - // Manually bind these methods to ensure valid instance state - // especially after interacting with foreground session controls - this.pauseSession = this.pauseSession.bind(this); - this.resumeSession = this.resumeSession.bind(this); } componentWillMount() { @@ -183,9 +178,9 @@ class PostureMonitor extends Component { this.sessionStateListener = SessionControlServiceEvents.addListener('SessionState', event => { if (event.hasActiveSession) { // There is currently an active session running on the device, resume session - // only if we are not on the Alert scene and the session's paused + // only if we are not on the Alert scene if (this.props.currentRoute.name === routes.postureMonitor.name - && this.state.sessionState !== sessionStates.RUNNING) { + && this.state.sessionState === sessionStates.RUNNING) { this.resumeSession(); } } else { @@ -604,6 +599,7 @@ class PostureMonitor extends Component { }); } + @autobind pauseSession() { if (!this.state.hasPendingSessionOperation) { this.setState({ hasPendingSessionOperation: true }); @@ -640,6 +636,7 @@ class PostureMonitor extends Component { } } + @autobind resumeSession() { if (!this.state.hasPendingSessionOperation) { this.setState({ hasPendingSessionOperation: true });