Skip to content

Commit

Permalink
Merge pull request #1174 from shankari/fix_json_dump_download
Browse files Browse the repository at this point in the history
🐛 Re-enable "Download JSON dump"
  • Loading branch information
shankari committed Sep 7, 2024
2 parents 2c647d8 + 3b6ecd5 commit 18047b0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
2 changes: 1 addition & 1 deletion package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"cordova-plugin-app-version": "0.1.14",
"cordova-plugin-customurlscheme": "5.0.2",
"cordova-plugin-device": "2.1.0",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.9",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.9.0",
"cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2",
"cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.7",
"cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.3",
Expand Down
3 changes: 3 additions & 0 deletions setup/activate_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ then
echo "ANDROID_HOME and ANDROID_SDK_ROOT not set, android SDK not found"
fi

echo "Activating sdkman, and by default, gradle"
source ~/.sdkman/bin/sdkman-init.sh

echo "Ensuring that we use the most recent version of the command line tools"
export PATH=$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/emulator:$PATH

Expand Down
1 change: 1 addition & 0 deletions setup/export_shared_dep_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export NODE_VERSION=20.9.0
# Looks like brew supports only major and minor, not patch version
export RUBY_VERSION=3.0
export COCOAPODS_VERSION=1.15.2
export GRADLE_VERSION=8.10
export OSX_EXP_VERSION=12

export NVM_DIR="$HOME/.nvm"
Expand Down
15 changes: 15 additions & 0 deletions setup/setup_android_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ else
echo "ANDROID_HOME = $ANDROID_HOME; ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT"
fi

echo "Setting up sdkman"
curl -s "https://get.sdkman.io" | bash
source ~/.sdkman/bin/sdkman-init.sh

CURR_GRADLE_VER=`sdk current gradle | cut -d " " -f 4 | xargs`

echo "CURR_GRADLE_VER = '$CURR_GRADLE_VER', expected $GRADLE_VERSION"

if [[ $CURR_GRADLE_VER == $GRADLE_VERSION ]]; then
echo "Already have gradle version $GRADLE_VERSION"
else
echo "Setting up gradle using SDKMan"
sdk install gradle $GRADLE_VERSION
fi

source setup/setup_shared_native.sh
79 changes: 35 additions & 44 deletions www/js/services/controlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,38 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT
function localShareData() {
return new Promise<void>((resolve, reject) => {
window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (fs) => {
fs.filesystem.root.getFile(fileName, null, (fileEntry) => {
logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`);
fileEntry.file(
(file) => {
const reader = new FileReader();

reader.onloadend = () => {
const readResult = this.result as string;
logDebug(`Successfull file read with ${readResult.length} characters`);
const dataArray = JSON.parse(readResult);
logDebug(`Successfully read resultList of size ${dataArray.length}`);
let attachFile = fileEntry.nativeURL;
const shareObj = {
files: [attachFile],
message: i18next.t(
'shareFile-service.send-data.body-data-consists-of-list-of-entries',
),
subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', {
start: startTimeString,
end: endTimeString,
}),
};
window['plugins'].socialsharing.shareWithOptions(
shareObj,
(result) => {
logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false
logDebug(`Shared to app: ${result.app}`);
resolve();
},
(msg) => {
logDebug(`Sharing failed with message ${msg}`);
},
);
};
reader.readAsText(file);
},
(error) => {
displayError(error, 'Error while downloading JSON dump');
reject(error);
},
);
});
fs.filesystem.root.getFile(
fileName,
null,
(fileEntry) => {
logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`);
const shareObj = {
files: [fileEntry.nativeURL],
message: i18next.t(
'shareFile-service.send-data.body-data-consists-of-list-of-entries',
),
subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', {
start: startTimeString,
end: endTimeString,
}),
};
window['plugins'].socialsharing.shareWithOptions(
shareObj,
(result) => {
logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false
logDebug(`Shared to app: ${result.app}`);
resolve();
},
(error) => {
displayError(error, `Sharing failed with message`);
},
);
},
(error) => {
displayError(error, 'Error while downloading JSON dump');
reject(error);
},
);
});
});
}
Expand Down Expand Up @@ -117,15 +107,16 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT
* getMyData fetches timeline data for a given day, and then gives the user a prompt to share the data
* @param timeStamp initial timestamp of the timeline to be fetched.
*/
export function getMyData(timeStamp: Date) {
export async function getMyData(timeStamp: Date) {
// We are only retrieving data for a single day to avoid
// running out of memory on the phone
const endTime = DateTime.fromJSDate(timeStamp);
const startTime = endTime.startOf('day');
const startTimeString = startTime.toFormat("yyyy'-'MM'-'dd");
const endTimeString = endTime.toFormat("yyyy'-'MM'-'dd");

const dumpFile = startTimeString + '.' + endTimeString + '.timeline';
// let's rename this to .txt so that we can email it on iPhones
const dumpFile = startTimeString + '.' + endTimeString + '.timeline.txt';
alert(`Going to retrieve data to ${dumpFile}`);

const getDataMethods = getMyDataHelpers(dumpFile, startTimeString, endTimeString);
Expand Down

0 comments on commit 18047b0

Please sign in to comment.