From bf9ad6fc06b6d904d6d08fd005a6e12a55f8414d Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Tue, 5 Jul 2016 10:25:10 +0200
Subject: [PATCH] - disable effects on old device (=without 'a' grade) - clean
 code on motion effects

---
 www/js/app.js                              | 46 +++++++----
 www/js/controllers/currency-controllers.js | 20 +++--
 www/js/controllers/wallet-controllers.js   |  9 +-
 www/js/controllers/wot-controllers.js      | 12 +--
 www/js/services/utils-services.js          | 95 ++++++++++++++--------
 www/templates/wot/view_identity.html       |  2 +-
 6 files changed, 111 insertions(+), 73 deletions(-)

diff --git a/www/js/app.js b/www/js/app.js
index f15edef4..4a59bf35 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -18,23 +18,26 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate',
   })
 
   .filter('formatDecimal', function() {
-      return function(input) {
-        if (input === undefined) return '0';
-        //if (input === Infinity || input === -Infinity) {
-        //  return '∞';
-        //}
-        if (Math.abs(input) < 0.0001) return '~ 0';
-        return numeral(input-0.00005).format('0,0.0000').replace(',', ' ');
-      };
-    })
+    return function(input) {
+      if (input === undefined) return '0';
+      //if (input === Infinity || input === -Infinity) {
+      //  return '∞';
+      //}
+      if (Math.abs(input) < 0.0001) return '~ 0';
+      return numeral(input-0.00005).format('0,0.0000').replace(',', ' ');
+    };
+  })
 
   .filter('formatNumeral', function() {
-      return function(input, pattern) {
-        if (input === undefined) return '0';
-        if (Math.abs(input) < 0.0001) return '~ 0';
-        return numeral(input).format(pattern).replace(',', ' ');
-      };
-    })
+    return function(input, pattern) {
+      if (input === undefined) return '0';
+      //if (isNaN(input)) {
+      //    return 'NaN';
+      //}
+      if (Math.abs(input) < 0.0001) return '~ 0';
+      return numeral(input).format(pattern).replace(',', ' ');
+    };
+  })
 
   .filter('formatDate', function() {
     return function(input) {
@@ -140,7 +143,8 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate',
   .config(function($ionicNativeTransitionsProvider){
     'ngInject';
     // Use native transition
-    var enableNativeTransitions = ionic.Platform.isAndroid() || ionic.Platform.isIOS();
+    var enableNativeTransitions = (ionic.Platform.isAndroid() || ionic.Platform.isIOS()) &&
+      ionic.Platform.grade.toLowerCase()=='a';
     $ionicNativeTransitionsProvider.enable(enableNativeTransitions);
   })
   // endRemoveIf(no-device)
@@ -230,7 +234,8 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate',
     };
   })
 
-.run(function($rootScope, amMoment, $translate, Device) {
+.run(function($rootScope, amMoment, $translate, Device, UIUtils, $ionicConfig
+) {
   'ngInject';
 
   // We use 'Device.ready()' instead of '$ionicPlatform.ready()', because it could be call many times
@@ -255,6 +260,13 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate',
       // org.apache.cordova.statusbar required
       StatusBar.styleDefault();
     }
+
+    // Ionic Platform Grade is not A, disabling views transitions
+    if (ionic.Platform.grade.toLowerCase()!='a') {
+      console.log('Disable visual effects because plateform grade is not [a] but [' + ionic.Platform.grade + ']');
+      $ionicConfig.views.transition('none');
+      UIUtils.disableEffects();
+    }
   });
 
   $rootScope.onLanguageChange = function() {
diff --git a/www/js/controllers/currency-controllers.js b/www/js/controllers/currency-controllers.js
index 84496d69..f0a9aafe 100644
--- a/www/js/controllers/currency-controllers.js
+++ b/www/js/controllers/currency-controllers.js
@@ -95,13 +95,7 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
 
   PeersController.call(this, $scope, $rootScope, BMA, UIUtils, $q, $interval, $timeout);
 
-  $scope.search = {
-    text: '',
-    results: {},
-    options: {
-        listInset: true
-      }
-  };
+  $scope.search = {};
   $scope.formData = {
     useRelative: Wallet.data.settings.useRelative
   };
@@ -109,6 +103,18 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
   $scope.node = null;
   $scope.loading = true;
 
+  $scope.currency = '';
+  $scope.M = 0;
+  $scope.MoverN = 0;
+  $scope.UD = 0;
+  $scope.cactual = 0;
+  $scope.c = 0;
+  $scope.dt = 0;
+  $scope.sigQty = 0;
+  $scope.time  = 0;
+  $scope.difficulty  = 0;
+  $scope.Nprev = 0;
+
   $scope.$on('$ionicView.enter', function(e, $state) {
     $scope.closeNode();
 
diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js
index fd003ee9..3b5756a3 100644
--- a/www/js/controllers/wallet-controllers.js
+++ b/www/js/controllers/wallet-controllers.js
@@ -90,9 +90,7 @@ function WalletController($scope, $rootScope, $state, $q, $ionicPopup, $ionicAct
     $scope.refreshConvertedBalance();
     // Set Motion
     $timeout(function() {
-      UIUtils.motion.fadeSlideInRight({
-        startVelocity: 3000
-      });
+      UIUtils.motion.fadeSlideInRight();
       // Set Ink
       UIUtils.ink({selector: '.item'});
     }, 10);
@@ -121,7 +119,6 @@ function WalletController($scope, $rootScope, $state, $q, $ionicPopup, $ionicAct
       // Set Motion
       $timeout(function() {
         UIUtils.motion.fadeSlideInRight({
-          startVelocity: 3000,
           selector: '.item-pending'
         });
         // Set Ink
@@ -353,9 +350,7 @@ function WalletTxErrorController($scope, $rootScope, $ionicPopup, $timeout, UIUt
     $scope.walletData = wallet;
     // Set Motion
     $timeout(function() {
-      UIUtils.motion.fadeSlideInRight({
-        startVelocity: 3000
-      });
+      UIUtils.motion.fadeSlideInRight();
       // Set Ink
       UIUtils.ink({selector: '.item'});
     }, 10);
diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js
index 47157e65..411c57f8 100644
--- a/www/js/controllers/wot-controllers.js
+++ b/www/js/controllers/wot-controllers.js
@@ -161,11 +161,8 @@ function WotIdentityViewController($scope, $state, BMA, Wallet, UIUtils, $q, $ti
       $scope.loaded = true;
 
       $timeout(function() {
-          UIUtils.motion.fadeSlideInRight({
-            selector: '.animate-fade-slide-in .item',
-            startVelocity: 3000
-          });
-      }, 100);
+          UIUtils.motion.fadeSlideInRight();
+      }, 10);
       UIUtils.ink();
     };
     BMA.wot.lookup({ search: pub })
@@ -285,10 +282,7 @@ function WotCertificationsViewController($scope, $state, BMA, Wallet, UIUtils, $
       $scope.loaded = true;
       // Set Motion
       $timeout(function() {
-        UIUtils.motion.fadeSlideInRight({
-            selector: '.animate-fade-slide-in-right .item',
-            startVelocity: 3000
-        });
+        UIUtils.motion.fadeSlideInRight();
       }, 10);
       if ($scope.canCertify) {
         $scope.showFab('fab-certify');
diff --git a/www/js/services/utils-services.js b/www/js/services/utils-services.js
index 6390c5d6..5e882458 100644
--- a/www/js/services/utils-services.js
+++ b/www/js/services/utils-services.js
@@ -167,51 +167,81 @@ angular.module('cesium.utils.services', ['ngResource'])
   }
 
   function resizeImageFromFile(file) {
-      return $q(function(resolve, reject) {
+    return $q(function(resolve, reject) {
 
-        var reader = new FileReader();
+      var reader = new FileReader();
 
-        reader.onload = function(event){
-          var img = document.createElement("img");
+      reader.onload = function(event){
+        var img = document.createElement("img");
 
-          img.onload = function(event) {
-            var width = event.target.width;
-            var height = event.target.height;
+        img.onload = function(event) {
+          var width = event.target.width;
+          var height = event.target.height;
 
-            if (width > height) {
-              if (width > CONST.MAX_WIDTH) {
-                height *= CONST.MAX_WIDTH / width;
-                width = CONST.MAX_WIDTH;
-              }
-            } else {
-              if (height > CONST.MAX_HEIGHT) {
-                width *= CONST.MAX_HEIGHT / height;
-                height = CONST.MAX_HEIGHT;
-              }
+          if (width > height) {
+            if (width > CONST.MAX_WIDTH) {
+              height *= CONST.MAX_WIDTH / width;
+              width = CONST.MAX_WIDTH;
             }
-            var canvas = document.createElement("canvas");
-            canvas.width = width;
-            canvas.height = height;
-            var ctx = canvas.getContext("2d");
-            ctx.drawImage(event.target, 0, 0,  canvas.width, canvas.height);
-
-            var dataurl = canvas.toDataURL();
+          } else {
+            if (height > CONST.MAX_HEIGHT) {
+              width *= CONST.MAX_HEIGHT / height;
+              height = CONST.MAX_HEIGHT;
+            }
+          }
+          var canvas = document.createElement("canvas");
+          canvas.width = width;
+          canvas.height = height;
+          var ctx = canvas.getContext("2d");
+          ctx.drawImage(event.target, 0, 0,  canvas.width, canvas.height);
 
-            resolve(dataurl);
-          };
+          var dataurl = canvas.toDataURL();
 
-          img.src = event.target.result;
+          resolve(dataurl);
         };
 
-        if (file) {
-          reader.readAsDataURL(file);
+        img.src = event.target.result;
+      };
+
+      if (file) {
+        reader.readAsDataURL(file);
+      }
+      else {
+        //reject("Not a file");
+      }
+    });
+  }
+
+  function disableEffects() {
+    this.ink = function(){};
+
+    function disableMotion(baseSelector) {
+      return function(options) {
+        if (!options || !options.selector) {
+          options = {
+              selector: (baseSelector + ' .item')
+            };
         }
-        else {
-          //reject("Not a file");
+        var parentsInDom = document.querySelectorAll(baseSelector);
+        for (var i = 0; i < parentsInDom.length; i++) {
+            var parent = parentsInDom[i];
+            parent.className = parent.className.replace(/\banimate-[a-z- ]+\b/,'');
         }
-      });
+
+        var itemsInDom = document.querySelectorAll(options.selector);
+        for (var j = 0; j < itemsInDom.length; j++) {
+            var child = itemsInDom[j];
+            child.style.webkitTransitionDelay = "0s";
+            child.style.transitionDelay = "0s";
+            child.className += ' in done';
+        }
+      };
     }
 
+    this.motion.fadeSlideIn= disableMotion('.animate-fade-slide-in');
+    this.motion.fadeSlideInRight = disableMotion('.animate-fade-slide-in-right');
+  }
+
   return {
     alert: {
       error: alertError,
@@ -228,6 +258,7 @@ angular.module('cesium.utils.services', ['ngResource'])
     onError: onError,
     ink: ionicMaterialInk.displayEffect,
     motion: ionicMaterialMotion,
+    disableEffects: disableEffects,
     selection: {
       select: selectElementText,
       get: getSelectionText
diff --git a/www/templates/wot/view_identity.html b/www/templates/wot/view_identity.html
index 87b1911e..ecb57b42 100644
--- a/www/templates/wot/view_identity.html
+++ b/www/templates/wot/view_identity.html
@@ -30,7 +30,7 @@
       <div class="col col-20 hidden-xs hidden-sm">&nbsp;
       </div>
 
-      <div class="col list animate-fade-slide-in">
+      <div class="col list animate-fade-slide-in-right">
 
         <!-- Certifications count -->
         <a class="item item-icon-left item-text-wrap item-icon-right ink" ng-if="hasSelf"
-- 
GitLab