diff --git a/Hydroflux/app/src/main/assets/js/modules/dashboard.js b/Hydroflux/app/src/main/assets/js/modules/dashboard.js
index 60c8467..c188467 100644
--- a/Hydroflux/app/src/main/assets/js/modules/dashboard.js
+++ b/Hydroflux/app/src/main/assets/js/modules/dashboard.js
@@ -10,13 +10,17 @@ export class Dashboard {
render() {
if (!this.container) return;
- // Data Retrieval (Keeping persistence)
// Data Retrieval (Keeping persistence)
const waterData = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
- const stepsData = 8432;
+
+ // Real Health Data (Default to 0 until synced)
+ const healthData = JSON.parse(localStorage.getItem('hydroflux_health_data') || '{"steps": 0, "sleep": 0}');
+ const stepsData = healthData.steps;
+ const sleepHoursTotal = healthData.sleep;
+ const sleepHours = Math.floor(sleepHoursTotal);
+ const sleepMins = Math.round((sleepHoursTotal - sleepHours) * 60);
+
const goalData = 10000;
- const sleepHours = 7;
- const sleepMins = 20;
const goalsData = JSON.parse(localStorage.getItem('hydroflux_goals') || JSON.stringify([
{ id: '1', text: 'Drink 3L of water', completed: true },
@@ -56,13 +60,15 @@ export class Dashboard {
-
-
-
14 Days
+
+
@@ -102,7 +108,7 @@ export class Dashboard {
- ${stepsData.toLocaleString()}
+ ${stepsData.toLocaleString()}
steps
@@ -131,7 +137,7 @@ export class Dashboard {
- ${sleepHours}h ${sleepMins}m
+ ${sleepHours}h ${sleepMins}m
Light Sleep
@@ -157,6 +163,34 @@ export class Dashboard {
this.updateDynamicElements(stepsData, goalData);
this.renderGoals(goalsData);
+
+ // Expose Native Callback
+ window.updateHealthData = (steps, sleepHoursTotal) => {
+ console.log("Received Health Data:", steps, sleepHoursTotal);
+
+ // Save to Storage
+ localStorage.setItem('hydroflux_health_data', JSON.stringify({ steps: steps, sleep: sleepHoursTotal }));
+
+ // Update UI directly
+ const stepsCount = this.container.querySelector('#stepsCount');
+ if (stepsCount) stepsCount.textContent = steps.toLocaleString();
+
+ const sh = Math.floor(sleepHoursTotal);
+ const sm = Math.round((sleepHoursTotal - sh) * 60);
+ const sleepTime = this.container.querySelector('#sleepTime');
+ if (sleepTime) sleepTime.textContent = `${sh}h ${sm}m`;
+
+ this.updateDynamicElements(steps, 10000);
+ };
+
+ // Trigger initial sync if native interface exists
+ if (window.HydroFluxNative) {
+ try {
+ window.HydroFluxNative.requestHealthPermissions();
+ } catch (e) {
+ console.error("Native sync error", e);
+ }
+ }
}
updateDynamicElements(steps, goal) {
@@ -170,7 +204,7 @@ export class Dashboard {
circle.style.strokeDashoffset = strokeDashoffset;
}
- // Sleep Chart Logic
+ // Sleep Chart Logic (Static for now, but could be dynamic)
const sleepData = [30, 35, 25, 40, 55, 45, 60, 75, 70, 80, 65, 55, 50, 45, 40];
const chartWidth = 300;
const chartHeight = 100;
@@ -308,6 +342,20 @@ export class Dashboard {
});
}
+ // Sync Health Listener
+ const syncBtn = this.container.querySelector('#syncHealthBtn');
+ if (syncBtn) {
+ syncBtn.addEventListener('click', () => {
+ if (window.HydroFluxNative) {
+ window.HydroFluxNative.requestHealthPermissions();
+ } else {
+ alert("Health Sync only available on Android App");
+ // Mock data for browser testing
+ window.updateHealthData(12500, 7.8);
+ }
+ });
+ }
+
// Notes Save
const noteArea = this.container.querySelector('#notesInput');
if (noteArea) {
diff --git a/Hydroflux/app/src/main/assets/js/modules/views/FitnessView.js b/Hydroflux/app/src/main/assets/js/modules/views/FitnessView.js
index d8987d3..3c224e4 100644
--- a/Hydroflux/app/src/main/assets/js/modules/views/FitnessView.js
+++ b/Hydroflux/app/src/main/assets/js/modules/views/FitnessView.js
@@ -7,8 +7,9 @@ export class FitnessView {
}
render() {
- // Mock Data
- const steps = 8432;
+ // Real Data
+ const healthData = JSON.parse(localStorage.getItem('hydroflux_health_data') || '{"steps": 0, "sleep": 0}');
+ const steps = healthData.steps;
const goal = 10000;
const pct = Math.min((steps / goal) * 100, 100);
const radius = 80;
diff --git a/Hydroflux/app/src/main/assets/js/modules/views/SleepView.js b/Hydroflux/app/src/main/assets/js/modules/views/SleepView.js
index e286e26..4ed729d 100644
--- a/Hydroflux/app/src/main/assets/js/modules/views/SleepView.js
+++ b/Hydroflux/app/src/main/assets/js/modules/views/SleepView.js
@@ -7,9 +7,11 @@ export class SleepView {
}
render() {
- // Mock Sleep Data
- const sleepHours = 7;
- const sleepMins = 20;
+ // Real Sleep Data
+ const healthData = JSON.parse(localStorage.getItem('hydroflux_health_data') || '{"steps": 0, "sleep": 0}');
+ const sleepHoursTotal = healthData.sleep;
+ const sleepHours = Math.floor(sleepHoursTotal);
+ const sleepMins = Math.round((sleepHoursTotal - sleepHours) * 60);
this.container.innerHTML = `
diff --git a/Hydroflux/releases/HydroFlux_v2.apk b/Hydroflux/releases/HydroFlux_v2.apk
index 8a07338..ba2cc04 100644
Binary files a/Hydroflux/releases/HydroFlux_v2.apk and b/Hydroflux/releases/HydroFlux_v2.apk differ