diff --git a/client/www/index.html b/client/www/index.html index d1dc658cd..52ecc2eec 100644 --- a/client/www/index.html +++ b/client/www/index.html @@ -99,6 +99,10 @@

{{'LOC_TODAYWEATHER'|translate}}

{{'LOC_REFRESH_INTERVAL'|translate}} {{getRefreshIntervalValueStr(settingsInfo.refreshInterval)|translate}} +
{{'LOC_REMOVE_ADS'|translate}} diff --git a/client/www/js/controller.setting.radio.js b/client/www/js/controller.setting.radio.js index 36d6160c2..34917bac4 100644 --- a/client/www/js/controller.setting.radio.js +++ b/client/www/js/controller.setting.radio.js @@ -3,7 +3,7 @@ */ angular.module('controller.setting.radio', []) - .factory("radioList", function RadioList($rootScope, Units, TwStorage, Util) { + .factory("radioList", function RadioList($rootScope, Units, TwStorage, Util, WeatherInfo) { var radioList = {}; radioList.type = ""; radioList.title = ""; @@ -36,6 +36,7 @@ angular.module('controller.setting.radio', []) $rootScope.$broadcast('changeAirUnitEvent'); } } + return true; } else if (this.type === 'startupPage' || this.type === 'refreshInterval') { var settingsInfo = TwStorage.get("settingsInfo"); @@ -52,10 +53,20 @@ angular.module('controller.setting.radio', []) if (this.type === 'refreshInterval') { $rootScope.$broadcast('reloadEvent', 'setRefreshInterval'); } + return false; + } + else if (this.type === 'currentPosition') { + WeatherInfo.disableCity(!value); + if (value === true) { + WeatherInfo.setCityIndex(0); + return true; + } + return false; } else { Util.ga.trackEvent('action', 'error', 'unknown type='+this.type); } + return false; }; radioList.getValue = function () { @@ -84,8 +95,10 @@ angular.module('controller.setting.radio', []) $scope.list = radioList.list; $scope.data = {value: radioList.getValue()}; $scope.valueChanged = function(item) { - radioList.setValue(item.value); - _resetUpdateTimeCities(); + var needToResetUpdateTime = radioList.setValue(item.value); + if (needToResetUpdateTime) { + _resetUpdateTimeCities(); + } }; }); diff --git a/client/www/js/controller.settingctrl.js b/client/www/js/controller.settingctrl.js index 16f360280..347d78901 100644 --- a/client/www/js/controller.settingctrl.js +++ b/client/www/js/controller.settingctrl.js @@ -1,16 +1,12 @@ angular.module('controller.settingctrl', []) .controller('SettingCtrl', function($scope, $rootScope, Util, Purchase, $ionicHistory, $translate, - $ionicSideMenuDelegate, $ionicPopup, $location, TwStorage, radioList) { + $ionicSideMenuDelegate, $ionicPopup, $location, TwStorage, radioList, WeatherInfo) { var menuContent = null; var strOkay = "OK"; var strCancel = "Cancel"; - $translate(['LOC_OK', 'LOC_CANCEL']).then(function (translations) { - strOkay = translations.LOC_OK; - strCancel = translations.LOC_CANCEL; - }, function (translationIds) { - console.log("Fail to translate : "+JSON.stringify(translationIds)); - }); + var strCurrent = "Current"; + var strLocation = "Location"; function init() { if (ionic.Platform.isIOS()) { @@ -28,6 +24,18 @@ angular.module('controller.settingctrl', []) console.info(settingsInfo); $rootScope.settingsInfo = settingsInfo; + + if ( + Util.language.indexOf("ko") != -1 || + Util.language.indexOf("ja") != -1 || + Util.language.indexOf("zh-CN") != -1 || + Util.language.indexOf("zh-TU") != -1) { + + $scope.strCurrentPosition = strCurrent+strLocation; + } + else { + $scope.strCurrentPosition = strCurrent+" "+strLocation; + } } $scope.clickMenu = function (menu) { @@ -155,10 +163,21 @@ angular.module('controller.settingctrl', []) return {label: $scope.getRefreshIntervalValueStr(value), value: value}; }); } + else if (name === 'currentPosition') { + title = $scope.strCurrentPosition; + list = [{label:'On', value:true}, {label:'Off', value:false}].map(function (obj) { + return {label:obj.label, value: obj.value} + }); + } console.info(JSON.stringify({name: name, title: title, value: $rootScope.settingsInfo[name], list: list})); radioList.type = name; radioList.title = title; - radioList.setValue($rootScope.settingsInfo[name]); + if (name === 'currentPosition') { + radioList.setValue(!WeatherInfo.getCityOfIndex(0).disable); + } + else { + radioList.setValue($rootScope.settingsInfo[name]); + } radioList.importData(list); $location.path('/setting-radio'); }; @@ -197,5 +216,34 @@ angular.module('controller.settingctrl', []) return 'N/A' }; - init(); + $scope.getCurrentPositionStatus = function () { + var city = WeatherInfo.getCityOfIndex(0); + if (!city) { + return "Off"; + } + return city.disable?"Off":"On"; + }; + + $scope.canDisableCurrentPosition = function () { + return WeatherInfo.getCityCount() > 1; + }; + + $scope.getCurrentPositionStr = function () { + return strCurrentLocation; + }; + + $translate(['LOC_OK', 'LOC_CANCEL', 'LOC_CURRENT', 'LOC_LOCATION']) + .then( + function (translations) { + strOkay = translations.LOC_OK; + strCancel = translations.LOC_CANCEL; + strCurrent = translations.LOC_CURRENT; + strLocation = translations.LOC_LOCATION; + }, + function (translationIds) { + console.log("Fail to translate : "+JSON.stringify(translationIds)); + }) + .finally(function () { + init(); + }); }); diff --git a/client/www/js/controller.tabctrl.js b/client/www/js/controller.tabctrl.js index c9820b2ed..1bc4e0e65 100644 --- a/client/www/js/controller.tabctrl.js +++ b/client/www/js/controller.tabctrl.js @@ -352,24 +352,15 @@ angular.module('controller.tabctrl', []) Util.ga.trackEvent("translate", "error", "showRetryConfirm"); }).finally(function () { var buttons = []; - if (type == 'search') { - buttons.push({ - text: strClose, - onTap: function () { - return 'close'; - } - }); - } + buttons.push({ + text: strClose, + onTap: function () { + return 'close'; + } + }); //fail to get weather data if (type == 'weather') { - buttons.push({ - text: strClose, - onTap: function () { - return 'close'; - } - }); - buttons.push({ text: strOkay, type: 'button-positive', @@ -380,8 +371,7 @@ angular.module('controller.tabctrl', []) Util.ga.trackEvent('window', 'show', 'getWeatherPopup'); } - else if (ionic.Platform.isAndroid() && - gLocationAuthorizationStatus == cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS) { + else if (gLocationAuthorizationStatus == cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS) { template += '
'; template += strOpensTheAppInfoPage; @@ -413,6 +403,14 @@ angular.module('controller.tabctrl', []) }); } + buttons.push({ + text: strSetting, + type: 'button-positive', + onTap: function () { + return 'settings'; + } + }); + buttons.push({ text: strOkay, type: 'button-positive', @@ -463,15 +461,6 @@ angular.module('controller.tabctrl', []) } else { //fail to get address information - if (type == 'forecast') { - buttons.push({ - text: strClose, - onTap: function () { - return 'close'; - } - }); - } - buttons.push({ text: strOkay, type: 'button-positive', @@ -862,18 +851,22 @@ angular.module('controller.tabctrl', []) } showLoadingIndicator(); - updateWeatherData(weatherInfo).then(function () { - $scope.$broadcast('applyEvent', 'updateWeatherData'); - //data cache된 경우에라도, Loading했다는 느낌을 주기 위해서 최소 지연 시간 설정 - if (!weatherInfo.currentPosition) { - hideLoadingIndicator(); - } - }, function (msg) { - if (!weatherInfo.currentPosition) { - hideLoadingIndicator(); - } - $scope.showRetryConfirm(strError, msg, 'weather'); - }); + updateWeatherData(weatherInfo).then( + function () { + $scope.$broadcast('applyEvent', 'updateWeatherData'); + //data cache된 경우에라도, Loading했다는 느낌을 주기 위해서 최소 지연 시간 설정 + if (!weatherInfo.currentPosition) { + hideLoadingIndicator(); + } + }, + function (msg) { + if (!weatherInfo.currentPosition) { + hideLoadingIndicator(); + } + if (msg) { + $scope.showRetryConfirm(strError, msg, 'weather'); + } + }); if (weatherInfo.currentPosition === true) { /** @@ -1034,6 +1027,9 @@ angular.module('controller.tabctrl', []) }); } else if (isLocationAuthorized === false) { + if (window.cordova && window.cordova.plugins && window.cordova.plugins.diagnostic) { + $scope.setLocationAuthorizationStatus(cordova.plugins.diagnostic.permissionStatus.DENIED); + } msg = $translate.instant("LOC_ACCESS_TO_LOCATION_SERVICES_HAS_BEEN_DENIED"); deferred.reject(msg); } @@ -1074,11 +1070,10 @@ angular.module('controller.tabctrl', []) } } else if (isLocationEnabled === false) { - if (cityInfo.address === null && cityInfo.location === null) { // 현재 위치 정보가 없는 경우 에러 팝업 표시 + if (isLocationAuthorized === true) { if (window.cordova && cordova.plugins.locationAccuracy) { cordova.plugins.locationAccuracy.request( function (success) { - console.log(success); Util.ga.trackEvent("position", "status", "successUserAgreed"); //메세지 없이 통과시키고, reload by locationOn. deferred.reject(null); @@ -1096,8 +1091,64 @@ angular.module('controller.tabctrl', []) deferred.reject(msg); } } - else { // 위치 서비스가 꺼져있으면 저장된 위치로 날씨 업데이트 - deferred.resolve(); + else if (isLocationAuthorized === false) { + if (window.cordova && window.cordova.plugins && window.cordova.plugins.diagnostic) { + $scope.setLocationAuthorizationStatus(cordova.plugins.diagnostic.permissionStatus.DENIED); + } + msg = $translate.instant("LOC_ACCESS_TO_LOCATION_SERVICES_HAS_BEEN_DENIED"); + deferred.reject(msg); + } + else if (isLocationAuthorized === undefined) { + if (window.cordova && window.cordova.plugins && window.cordova.plugins.diagnostic) { + // ios : 앱을 사용하는 동안 '오늘날씨'에서 사용자의 위치에 접근하도록 허용하겠습니까? + // android : 오늘날씨의 다음 작업을 허용하시겠습니까? 이 기기의 위치에 액세스하기 + + cordova.plugins.diagnostic.getLocationAuthorizationStatus(function (status) { + switch (status) { + case cordova.plugins.diagnostic.permissionStatus.DENIED: + console.log("Permission denied"); + $scope.setLocationAuthorizationStatus(status); + msg = $translate.instant("LOC_ACCESS_TO_LOCATION_SERVICES_HAS_BEEN_DENIED"); + deferred.reject(msg); + break; + case cordova.plugins.diagnostic.permissionStatus.GRANTED: + console.error("Permission granted always"); + break; + case cordova.plugins.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE: + console.error("Permission granted only when in use"); + break; + case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED: + console.log("Permission not requested"); + cordova.plugins.diagnostic.requestLocationAuthorization(function (status) { + if (ionic.Platform.isAndroid()) { + $scope.setLocationAuthorizationStatus(status); + if (status === cordova.plugins.diagnostic.permissionStatus.DENIED) { + msg = $translate.instant("LOC_ACCESS_TO_LOCATION_SERVICES_HAS_BEEN_DENIED"); + deferred.reject(msg); + } + else { + console.log('status=' + status + ' by request location authorization and reload by resume'); + deferred.reject(null); + } + } + else { + //메세지 없이 통과시키고, reload by locationOn. + deferred.reject(null); + } + }, function (error) { + Util.ga.trackEvent('position', 'error', 'request location authorization'); + Util.ga.trackException(error, false); + deferred.reject(null); + }, cordova.plugins.diagnostic.locationAuthorizationMode.WHEN_IN_USE); + break; + } + }, function (error) { + console.error("The following error occurred: " + error); + }); + } + else { + deferred.reject(null); + } } } } @@ -1108,7 +1159,15 @@ angular.module('controller.tabctrl', []) var logLabel = geoInfo.address || geoInfo.name; if (!logLabel) { - logLabel = JSON.stringify(geoInfo.location); + if (geoInfo.location) { + logLabel = JSON.stringify(geoInfo.location); + } + else { + Util.ga.trackEvent('weather', 'warn', 'rejectByNoGeoInfo'); + console.log('It will be the first update for current position'); + deferred.reject(); + return deferred.promise; + } } WeatherUtil.getWeatherByGeoInfo(geoInfo).then(function (weatherData) {