summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPliable Pixels <pliablepixels@gmail.com>2018-09-24 16:48:40 -0400
committerPliable Pixels <pliablepixels@gmail.com>2018-09-24 16:48:40 -0400
commite520aecb5b1e3c3da74383f0c91e2e2f81d003f0 (patch)
tree7bb087822c1fe0e93ddf0b1c01c5fef593f2575e
parent60ec86f19b1e6003851df5ed33dc60cdf1d23a3a (diff)
#710 allow native video downloads
-rw-r--r--www/js/EventModalCtrl.js221
-rw-r--r--www/templates/events-modal.html4
2 files changed, 148 insertions, 77 deletions
diff --git a/www/js/EventModalCtrl.js b/www/js/EventModalCtrl.js
index eb78573a..217025d4 100644
--- a/www/js/EventModalCtrl.js
+++ b/www/js/EventModalCtrl.js
@@ -509,7 +509,7 @@ angular.module('zmApp.controllers').controller('EventModalCtrl', ['$scope', '$ro
$ionicLoading.show({
template: $translate.instant('kDone'),
noBackdrop: true,
- duration: 1000
+ duration: 2000
});
NVRDataModel.debug("ModalCtrl:Photo saved successfuly");
}
@@ -518,7 +518,7 @@ angular.module('zmApp.controllers').controller('EventModalCtrl', ['$scope', '$ro
$ionicLoading.show({
template: $translate.instant('kErrorSave'),
noBackdrop: true,
- duration: 2000
+ duration: 3000
});
//NVRDataModel.log("Error saving image: " + e.message);
//console.log("***ERROR");
@@ -562,8 +562,20 @@ angular.module('zmApp.controllers').controller('EventModalCtrl', ['$scope', '$ro
function processSaveEventImageToPhone(onlyAlarms) {
+
+ if ($scope.isSnapShot()) {
+
+
+ $scope.selectEventUrl = $scope.constructStream();
+ NVRDataModel.debug ("just saving current snapshot:"+$scope.selectEventUrl);
+ saveNow();
+ return;
+
+ }
+
if ($scope.loginData.useNphZmsForEvents) {
NVRDataModel.log("Use ZMS stream to save to phone");
+
saveEventImageToPhoneZms(onlyAlarms);
} else {
@@ -874,34 +886,70 @@ angular.module('zmApp.controllers').controller('EventModalCtrl', ['$scope', '$ro
]
});
- function saveNow() {
- $ionicLoading.show({
- template: $translate.instant('kSavingSnapshot') + "...",
- noBackdrop: true,
- duration: zm.httpTimeout
- });
+
+ }
- var url = $scope.selectEventUrl;
- NVRDataModel.log(">>saveNow: File path to grab is " + url);
+ function saveNow() {
- if ($rootScope.platformOS != 'desktop') {
-
- var album = 'zmNinja';
- NVRDataModel.debug ("Trying to save image to album: "+album);
- cordova.plugins.photoLibrary.requestAuthorization(
- function () {
- //url = "https://picsum.photos/200/300/?random";
-
- var fileTransfer = new FileTransfer();
- var urle = encodeURI(url);
- var fname = "zmninja.jpg";
-
- fileTransfer.download(urle, cordova.file.dataDirectory + fname,
- function(entry){
- NVRDataModel.debug("local download complete: " + entry.toURL());
- NVRDataModel.debug("Now trying to move it to album");
- cordova.plugins.photoLibrary.saveImage(entry.toURL(), album,
+ var fname = "zmninja.jpg";
+ var fn = "cordova.plugins.photoLibrary.saveImage";
+
+ $ionicLoading.show({
+ template: $translate.instant('kPleaseWait') + "...",
+ noBackdrop: true,
+ //duration: zm.httpTimeout
+ });
+
+ if ($scope.defaultVideo !== undefined && $scope.defaultVideo != '') {
+ $scope.selectEventUrl = $scope.video_url;
+ fname = "zmNinja.mp4";
+ fn = "cordova.plugins.photoLibrary.saveVideo";
+
+ NVRDataModel.debug ("-->Going to try and download "+$scope.selectEventUrl);
+ }
+
+
+ var url = $scope.selectEventUrl;
+
+
+ NVRDataModel.log(">>saveNow: File path to grab is " + url);
+
+ if ($rootScope.platformOS != 'desktop') {
+
+ var album = 'zmNinja';
+ NVRDataModel.debug ("Trying to save image to album: "+album);
+ cordova.plugins.photoLibrary.requestAuthorization(
+ function () {
+ //url = "https://picsum.photos/200/300/?random";
+
+ var fileTransfer = new FileTransfer();
+ var urle = encodeURI(url);
+
+
+ fileTransfer.onprogress = function (progressEvent) {
+ if (progressEvent.lengthComputable) {
+
+ $timeout (function() {
+ var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
+ $ionicLoading.show({
+ template: $translate.instant('kPleaseWait') + "... ("+perc+"%)",
+ noBackdrop: true,
+ //duration: zm.httpTimeout
+ });
+ });
+
+
+ }
+ };
+
+ fileTransfer.download(urle, cordova.file.dataDirectory + fname,
+ function(entry){
+ NVRDataModel.debug("local download complete: " + entry.toURL());
+ NVRDataModel.debug("Now trying to move it to album");
+
+ if (fname == "zmNinja.mp4") {
+ cordova.plugins.photoLibrary.saveVideo(entry.toURL(), album,
function (cameraRollAssetId) {
SaveSuccess();
$cordovaFile.removeFile(cordova.file.dataDirectory, fname)
@@ -920,62 +968,85 @@ angular.module('zmApp.controllers').controller('EventModalCtrl', ['$scope', '$ro
SaveError();
});
-
- },
- function(err) { console.log ("error downloading:"+JSON.stringify(err));}, false, {});
-
-
-
-
- // User gave us permission to his library, retry reading it!
- },
- function (err) {
- // User denied the access
- NVRDataModel.debug ("Permission not granted");
- SaveError();
- }, // if options not provided, defaults to {read: true}.
-
- {
- read: true,
- write: true
- }
- );
+ }
+ else {
- }
- else {
- var img = new Image();
- img.onload = function () {
- // console.log("********* ONLOAD");
- canvas = document.createElement('canvas');
- canvas.width = img.width;
- canvas.height = img.height;
- context = canvas.getContext('2d');
- context.drawImage(img, 0, 0);
-
- imageDataUrl = canvas.toDataURL('image/jpeg', 1.0);
- imageData = imageDataUrl.replace(/data:image\/jpeg;base64,/, '');
+ cordova.plugins.photoLibrary.saveImage(entry.toURL(), album,
+ function (cameraRollAssetId) {
+ SaveSuccess();
+ $cordovaFile.removeFile(cordova.file.dataDirectory, fname)
+ .then (
+ function () {
+ NVRDataModel.debug ("file removed from data directory");
+ },
+ function (e) {
+ NVRDataModel.debug ("could not delete temp file: "+JSON.stringify(e));
+ }
+ );
+
- var fname = $scope.relativePath + $scope.slides[$scope.slideIndex].img + ".png";
- fname = fname.replace(/\//, "-");
- fname = fname.replace(/\.jpg/, '');
+ }, function (err) {
+ NVRDataModel.debug ("Saving error:" + JSON.stringify(err));
+ SaveError();
+
+ });
+
+ }
+
+
+ },
+ function(err) { console.log ("error downloading:"+JSON.stringify(err));}, false, {});
- canvas.toBlob(function (blob) {
- saveAs(blob, fname);
- SaveSuccess();
- });
- };
- try {
- img.src = url;
- console.log ("DESKTOP SAVING IMAGE SOURCE");
- } catch (e) {
- SaveError(e.message);
+
+
+ // User gave us permission to his library, retry reading it!
+ },
+ function (err) {
+ // User denied the access
+ NVRDataModel.debug ("Permission not granted");
+ SaveError();
+ }, // if options not provided, defaults to {read: true}.
+
+ {
+ read: true,
+ write: true
}
- }
+ );
+ }
+ else {
+ var img = new Image();
+ img.onload = function () {
+ // console.log("********* ONLOAD");
+ canvas = document.createElement('canvas');
+ canvas.width = img.width;
+ canvas.height = img.height;
+ context = canvas.getContext('2d');
+ context.drawImage(img, 0, 0);
+
+ imageDataUrl = canvas.toDataURL('image/jpeg', 1.0);
+ imageData = imageDataUrl.replace(/data:image\/jpeg;base64,/, '');
+
+ var fname = $scope.relativePath + $scope.slides[$scope.slideIndex].img + ".png";
+ fname = fname.replace(/\//, "-");
+ fname = fname.replace(/\.jpg/, '');
+
+ canvas.toBlob(function (blob) {
+ saveAs(blob, fname);
+ SaveSuccess();
+ });
+ };
+
+ try {
+ img.src = url;
+ console.log ("DESKTOP SAVING IMAGE SOURCE");
+ } catch (e) {
+ SaveError(e.message);
}
+ }
- }
+ }
$scope.reloadView = function () {
NVRDataModel.log("Reloading view for modal view, recomputing rand");
diff --git a/www/templates/events-modal.html b/www/templates/events-modal.html
index 598bde23..6342ab98 100644
--- a/www/templates/events-modal.html
+++ b/www/templates/events-modal.html
@@ -155,9 +155,9 @@
<a href="" ng-click="toggleGapless()">
<i class="ion-ios-loop-strong"></i>-{{loginData.gapless? ('kOn' | translate): ('kOff' | translate)}}</a>
</li>
- <li ng-if="defaultVideo=='' && isToggleListMenu && (!isSnapShot() || liveFeedMid) ">
+ <li ng-if="isToggleListMenu ">
<a href="" ng-click="saveEventImageToPhoneWithPerms(false)">
- <i class="ion-ios-camera"></i>
+ <i class="ion-android-download"></i>
</a>
</li>
<li ng-if="defaultVideo=='' && isToggleListMenu">