Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Health connect support #869

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@
<allow-navigation href="*" />
<allow-intent href="market:*" />
<platform name="android">
<preference name="android-minSdkVersion" value="21" />
<preference name="android-compileSdkVersion" value="34" />
<preference name="android-targetSdkVersion" value="34" />
<preference name="android-minSdkVersion" value="26" />
<preference name="android-compileSdkVersion" value="35" />
<preference name="android-targetSdkVersion" value="35" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="files,sdcard,cache" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />
<preference name="AndroidXEnabled" value="true" />
<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradleVersion" value="8.5" />
<preference name="AndroidGradlePluginVersion" value="8.1.1" />
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
<application android:requestLegacyExternalStorage="true" />
<application android:extractNativeLibs="true" />
<application android:largeHeap="true" />
</edit-config>
<config-file target="AndroidManifest.xml" parent="/*" mode="merge" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.health.READ_NUTRITION" />
<uses-permission android:name="android.permission.health.WRITE_NUTRITION" />
</config-file>
<icon density="ldpi" background="res/icon/android/ldpi-background.png" foreground="res/icon/android/ldpi-foreground.png" monochrome="res/icon/android/ldpi-monochrome.png" src="res/android/ldpi.png" />
<icon density="mdpi" background="res/icon/android/mdpi-background.png" foreground="res/icon/android/mdpi-foreground.png" monochrome="res/icon/android/mdpi-monochrome.png" src="res/android/mdpi.png" />
<icon density="hdpi" background="res/icon/android/hdpi-background.png" foreground="res/icon/android/hdpi-foreground.png" monochrome="res/icon/android/hdpi-monochrome.png" src="res/android/hdpi.png" />
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alvrme/alpine-android:android-33-jdk11
FROM alvrme/alpine-android:android-35-jdk17

# Set up some environment variables
ENV GRADLE_VERSION 7.6
ENV GRADLE_VERSION 8.5
ENV GRADLE_HOME /opt/gradle-$GRADLE_VERSION
ENV ANDROID_HOME /opt/sdk
ENV PATH $PATH:$GRADLE_HOME/bin
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
},
"devDependencies": {
"cordova": "^12.0.0",
"cordova-android": "^12.0.1",
"cordova-android": "^13.0.0",
"cordova-browser": "^7.0.0",
"cordova-electron": "^3.1.0",
"cordova-plugin-browsersync-gen2": "^1.1.7",
"cordova-plugin-camera": "^7.0.0",
"cordova-plugin-chooser": "^1.3.2",
"cordova-plugin-crop": "github:rastafan/cordova-plugin-crop",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "^8.0.0",
"cordova-plugin-health": "github:dariosalvi78/cordova-plugin-health",
"cordova-plugin-inappbrowser": "^5.0.0",
"cordova-plugin-ionic-keyboard": "2.2.0",
"cordova-plugin-network-information": "^3.0.0",
Expand Down Expand Up @@ -40,7 +43,8 @@
"cordova-plugin-x-socialsharing": {},
"phonegap-plugin-barcodescanner": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
}
},
"cordova-plugin-health": {}
},
"platforms": [
"android"
Expand Down
75 changes: 75 additions & 0 deletions www/activities/settings/js/health-connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright 2021 David Healey

This file is part of Waistline.

Waistline is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Waistline is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with app. If not, see <http://www.gnu.org/licenses/>.
*/

app.HealthConnect = {

el: {},

init: async function() {
this.getComponents();
this.bindUIActions();
this.toggleVisibility();
},

getComponents: function() {
this.el.disabledList = document.querySelector(".page[data-name='settings-health-connect'] #health-connect-settings-disabled");
this.el.enabledList = document.querySelector(".page[data-name='settings-health-connect'] #health-connect-settings-enabled");
},

bindUIActions: function() {
},

toggleVisibility: function() {
if (app.Settings.get("healthConnect", "enabled")) {
this.el.enabledList.style.display = "block"
this.el.disabledList.style.display = "none"
} else {
this.el.disabledList.style.display = "block"
this.el.enabledList.style.display = "none"
}
},
};

document.addEventListener("page:init", function(e) {
app.HealthConnect.init();
dbHandler.getAllItems("diary").then(response => {
const meals = ["breakfast" ,"lunch" ,"dinner" ,"snack"]
response.forEach(day => {
day.items.forEach(item => {
app.FoodsMealsRecipes.getItem(item.id, item.type, item.portion, item.quantity).then((data) => {
alert(data.dateTime, data.name, data.nutrition.calories, meals[item.category])
cordova.plugins.health.store({
startDate: data.dateTime,
endDate: new Date(data.dateTime.getTime() + 10000), // startDate and endDate must be different.
dataType: 'nutrition',
value: {
item: data.name,
meal_type: meals[item.category],
calories: data.nutrition.calories || 0,
protein: data.nutrition.protein || 0,
"fat.total": data.nutrition.calories || 0,
"carbs.total": data.nutrition.calories || 0
},
})
})
})
})
})

});
47 changes: 47 additions & 0 deletions www/activities/settings/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,29 @@ app.Settings = {
});
}

// Health Connect Settings

let enableHealthConnect = document.getElementById("enable-health-connect");
if (enableHealthConnect) {
enableHealthConnect.addEventListener("click", function(e) {
app.Settings.enableHealthConnect();
});
}

let disableHealthConnect = document.getElementById("disable-health-connect");
if (disableHealthConnect) {
disableHealthConnect.addEventListener("click", function(e) {
app.Settings.disableHealthConnect();
});
}

let openHealthConnect = document.getElementById("open-health-connect");
if (openHealthConnect) {
openHealthConnect.addEventListener("click", function(e) {
cordova.plugins.health.openHealthSettings()
});
}

// Mode
let modeSelect = document.querySelector(".page[data-name='settings-appearance'] #mode");

Expand Down Expand Up @@ -272,6 +295,27 @@ app.Settings = {
}
},

enableHealthConnect: function() {
cordova.plugins.health.requestAuthorization({
read: ['nutrition'],
write: ['nutrition'],
}, (result) => {
if (result) {
app.Settings.put("healthConnect", "enabled", true);
app.HealthConnect.toggleVisibility();
} else {
let msg = app.strings.settings["health-connect"]["permission-fail"] || "Please allow the Nutrition permissions in Health Connect";
app.Utils.toast(msg);
cordova.plugins.health.openHealthSettings()
}
},)
},

disableHealthConnect: function() {
app.Settings.put("healthConnect", "enabled", false);
app.HealthConnect.toggleVisibility();
},

changeTheme: function(appMode, colourTheme) {
let body = document.getElementsByTagName("body")[0];
body.className = colourTheme;
Expand Down Expand Up @@ -670,6 +714,9 @@ app.Settings = {
"show-nutrition-units": false,
"prompt-add-items": false
},
healthConnect: {
"enabled": false,
},
foodlist: {
labels: app.FoodsCategories.defaultLabels,
categories: app.FoodsCategories.defaultCategories,
Expand Down
48 changes: 48 additions & 0 deletions www/activities/settings/views/health-connect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
Copyright 2022 David Healey

This file is part of Waistline.

Waistline is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Waistline is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with app. If not, see <http://www.gnu.org/licenses/>.
-->

<div class="page" data-name="settings-health-connect">

<div class="navbar">
<div class="navbar-bg"></div>
<div class="navbar-inner">
<div class="left">
<a class="link back"><i class="icon icon-back"></i></a>
</div>
<div class="title" data-localize="settings.health-connect.title">Health Connect</div>
<div class="right"></div>
</div>
</div>

<div class="page-content">
<div class="list multi-line-titles">
<ul id="health-connect-settings-disabled">
<li>
<p><a href="#" class="button button-large" id="enable-health-connect" data-localize="settings.health-connect.enable">Enable Health Connect</a></p>
</li>
</ul>
<ul id="health-connect-settings-enabled">
<li>
<p><a href="#" class="button button-large" id="disable-health-connect" data-localize="settings.health-connect.disable">Disable Health Connect</a></p>
<p><a href="#" class="button button-large" id="open-health-connect" data-localize="settings.health-connect.open">Open Health Connect</a></p>
</li>
</ul>
</div>
</div>
</div>
6 changes: 6 additions & 0 deletions www/activities/settings/views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
</a>
</li>

<li>
<a href="./health-connect/" class="item-link item-content">
<div class="item-inner" data-localize="settings.health-connect.title">Health Connect</div>
</a>
</li>

<li>
<a href="./developer/" class="item-link item-content">
<div class="item-inner" data-localize="settings.developer.title">Developer</div>
Expand Down
7 changes: 7 additions & 0 deletions www/assets/locales/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@
"centimeters": "Centimeters",
"inches": "Inches"
},
"health-connect": {
"title": "Health Connect",
"enable": "Enable Health Connect",
"disable": "Disable Health Connect",
"open": "Open Health Connect",
"permission-fail": "Please allow the Nutrition permissions in Health Connect"
},
"diary": {
"title": "Diary",
"categories": "Categories",
Expand Down
1 change: 1 addition & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<script src="activities/settings/js/nutriments.js"></script>
<script src="activities/settings/js/body-stats.js"></script>
<script src="activities/settings/js/foods-categories.js"></script>
<script src="activities/settings/js/health-connect.js"></script>
<script src="activities/settings/js/text-so-speech.js"></script>
<script src="activities/setup-wizard/js/setup-wizard.js"></script>
</body>
Expand Down
7 changes: 7 additions & 0 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ const app = {
transition: "f7-parallax"
}
},
{
path: "health-connect/",
url: "activities/settings/views/health-connect.html",
options: {
transition: "f7-parallax"
}
},
{
path: "developer/",
url: "activities/settings/views/developer.html",
Expand Down
21 changes: 21 additions & 0 deletions www/privacypolicy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h1>Privacy Policy</h1>
<p>This Privacy Policy explains and gives information regarding the collection, use, and disclosure of personal data when you utilize Waistline and the choices you have associated with that data. By utilizing the software, you accept the terms and conditions of this Policy. This Policy applies to this software and the developer is not responsible for the content or privacy practices on any third-party app not operated by the developer to which this software links or that links to this software.</p>

<h2>Information Collection and Use</h2>
<p>Waistline only requires the availability of an internet connection when the barcode of a product is scanned, when searching for a product online, or when uploading a product to the Open Food Facts database. During a scan or a search, the only information sent to Open Food Facts or the USDA is the product barcode or the search terms entered.</p>
<p>For the software to function efficiently camera and storage permissions are required. These are needed to be able to scan barcodes, upload product images, and to import and export data.</p>

<h2>Types of Data Collected</h2>
<h3>Personal Data</h3>
<p>No personal data is collected while utilizing the software.</p>
<h3>Usage Data</h3>
<p>Usage data is collected only when interacting with the Open Food Facts or USDA databases.</p>

<h2>Security of Data</h2>
<p>The security of your data is important but no method of transmission over the internet or electronic storage is 100% secure, therefore the developer doesn't guarantee its absolute security.</p>

<h2>Service Providers</h2>
<p>Waistline requires third-party databases (Open Food Facts and USDA) to facilitate some of its functionality.</p>

<h2>Changes to this Privacy Policy</h2>
<p>This privacy policy may be updated from time to time as the functionalities of the software are further developed and improved and may contain disparities that will nullify this current policy</p>