Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ <h1 class="title">{{'LOC_TODAYWEATHER'|translate}}</h1>
{{'LOC_REFRESH_INTERVAL'|translate}}
<span style="float: right">{{getRefreshIntervalValueStr(settingsInfo.refreshInterval)|translate}}</span>
</label>
<label class="item" ng-disabled="canDisableCurrentPosition()" ng-click="settingRadio('currentPosition')">
{{strCurrentPosition}}
<span style="float: right">{{getCurrentPositionStatus()|translate}}</span>
</label>
<a class="item item-input" ng-click="clickMenu('purchase')" ng-if="hasInAppPurchase()">
<div class="input-label">
{{'LOC_REMOVE_ADS'|translate}}
Expand Down
19 changes: 16 additions & 3 deletions client/www/js/controller.setting.radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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");
Expand All @@ -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 () {
Expand Down Expand Up @@ -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();
}
};
});

66 changes: 57 additions & 9 deletions client/www/js/controller.settingctrl.js
Original file line number Diff line number Diff line change
@@ -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()) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
};
Expand Down Expand Up @@ -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();
});
});
145 changes: 102 additions & 43 deletions client/www/js/controller.tabctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 += '<br>';
template += strOpensTheAppInfoPage;

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
/**
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}
}
Expand All @@ -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) {
Expand Down