From 6704b31ab2d661095962a2528d409707885c05b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 14 Dec 2016 11:44:55 -0300 Subject: [PATCH] adding infinite scroll again --- src/js/controllers/preferencesAltCurrency.js | 33 +++++++++++++------- www/views/preferencesAltCurrency.html | 5 +++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/preferencesAltCurrency.js b/src/js/controllers/preferencesAltCurrency.js index 9fba5d220..20e1e16dd 100644 --- a/src/js/controllers/preferencesAltCurrency.js +++ b/src/js/controllers/preferencesAltCurrency.js @@ -3,6 +3,9 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyController', function($scope, $log, $timeout, $ionicHistory, configService, rateService, lodash, profileService, walletService, storageService) { + var next = 10; + var completeAlternativeList; + function init() { var unusedCurrencyList = [{ isoCode: 'LTL' @@ -11,22 +14,38 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl }]; rateService.whenAvailable(function() { + $scope.listComplete = false; + var idx = lodash.indexBy(unusedCurrencyList, 'isoCode'); var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode'); - $scope.completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { + completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) { return idx[c.isoCode] || idx2[c.isoCode]; }); - $scope.altCurrencyList = $scope.completeAlternativeList; + + completeAlternativeList = completeAlternativeList.sort(function(a, b) { + return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1; + }); + + $scope.altCurrencyList = completeAlternativeList.slice(0, 10); $timeout(function() { $scope.$apply(); }); }); } + $scope.loadMore = function() { + $timeout(function() { + $scope.altCurrencyList = completeAlternativeList.slice(0, next); + next += 10; + $scope.listComplete = $scope.altCurrencyList.length >= completeAlternativeList.length; + $scope.$broadcast('scroll.infiniteScrollComplete'); + }, 100); + }; + $scope.findCurrency = function(search) { if (!search) init(); - $scope.altCurrencyList = lodash.filter($scope.completeAlternativeList, function(item) { + $scope.altCurrencyList = lodash.filter(completeAlternativeList, function(item) { var val = item.name; return lodash.includes(val.toLowerCase(), search.toLowerCase()); }); @@ -68,14 +87,6 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl $scope.currentCurrency = config.wallet.settings.alternativeIsoCode; storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) { $scope.lastUsedAltCurrencyList = lastUsedAltCurrency ? JSON.parse(lastUsedAltCurrency) : []; - $timeout(function() { - $scope.$apply(); - }); - }); - }); - - $scope.$on("$ionicView.enter", function(event, data) { - $timeout(function() { init(); }); }); diff --git a/www/views/preferencesAltCurrency.html b/www/views/preferencesAltCurrency.html index 1a59c60f3..dc9be4286 100644 --- a/www/views/preferencesAltCurrency.html +++ b/www/views/preferencesAltCurrency.html @@ -24,5 +24,10 @@ ng-click="save(altCurrency)">{{altCurrency.name}} + +