Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit b9f7c10

Browse files
committed
feat(plugin:appRate): refractor setPreferences
Before: ``` $cordovaAppRateProvider.useLanguage(...) $cordovaAppRateProvider.displayAppName(...) ... ``` Now: ``` var prefs = {language: 'en', appName: 'some name'}; $cordovaAppRateProvider.setPreferences(prefs) ```
1 parent a638822 commit b9f7c10

File tree

7 files changed

+55
-98
lines changed

7 files changed

+55
-98
lines changed

demo/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
<feature name="StatusBar">
2121
<param name="ios-package" value="CDVStatusBar" onload="true"/>
2222
</feature>
23-
</widget>
23+
</widget>

demo/www/app/app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ angular.module('demo', [
116116

117117

118118
document.addEventListener("deviceready", function () {
119-
$cordovaAppRateProvider.displayAppName("APP NAME");
119+
var preferences = {
120+
iosURL: "some URL",
121+
appName: 'APP NAME',
122+
language: 'fr'
123+
};
124+
$cordovaAppRateProvider.setPreferences(preferences);
120125
}, false);
121126

122127
$cordovaInAppBrowserProvider.setDefaultOptions(browserOptions);

demo/www/lib/ngCordova/dist/ng-cordova.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,42 +133,26 @@ angular.module('ngCordova.plugins.appRate', [])
133133

134134
.provider("$cordovaAppRate", [function () {
135135

136-
this.setAppUrl = function (device, url) {
137-
var devices = ['ios', 'android', 'blackberry', 'windows8'];
138136

139-
if (devices.indexOf(device) !== -1) {
140-
AppRate.preferences.storeAppURL[device] = url;
137+
this.setPreferences = function (defaults) {
138+
if (!defaults || !angular.isObject(defaults)) {
139+
return;
141140
}
142-
else {
143-
alert("wrong device type");
144-
}
145-
};
146-
147-
this.useLanguage = function (language) {
148-
AppRate.preferences.useLanguage = language;
149-
};
150-
151-
this.displayAppName = function (name) {
152-
AppRate.preferences.displayAppName = name;
153-
};
154141

155-
this.promptAgainForEachNewVersion = function (boolean) {
156-
AppRate.preferences.promptAgainForEachNewVersion = boolean;
142+
AppRate.preferences.useLanguage = defaults.language || null;
143+
AppRate.preferences.displayAppName = defaults.appName || "";
144+
AppRate.preferences.promptAgainForEachNewVersion = defaults.promptAgainForEachNewVersion || true;
145+
AppRate.preferences.openStoreInApp = defaults.openStoreInApp || false;
146+
AppRate.preferences.usesUntilPrompt = defaults.usesUntilPrompt || 3;
147+
AppRate.preferences.useCustomRateDialog = defaults.useCustomRateDialog || false;
148+
AppRate.preferences.storeAppURL.ios = defaults.iosURL || null;
149+
AppRate.preferences.storeAppURL.android = defaults.androidURL || null;
150+
AppRate.preferences.storeAppURL.blackberry = defaults.blackberryURL || null;
151+
AppRate.preferences.storeAppURL.windows8 = defaults.windows8URL || null;
157152
};
158153

159-
this.usesUntilPrompt = function (number) {
160-
AppRate.preferences.usesUntilPrompt = number;
161-
};
162-
163-
this.openStoreInApp = function (boolean) {
164-
AppRate.preferences.openStoreInApp = boolean;
165-
};
166-
167-
this.useCustomRateDialog = function (boolean) {
168-
AppRate.preferences.useCustomRateDialog = boolean;
169-
};
170154

171-
this.customLocale = function (customObj) {
155+
this.setCustomLocale = function (customObj) {
172156
var strings = {
173157
title: 'Rate %@',
174158
message: 'If you enjoy using %@, would you mind taking a moment to rate it? It won’t take more than a minute. Thanks for your support!',

demo/www/lib/ngCordova/dist/ng-cordova.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ng-cordova.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,42 +133,26 @@ angular.module('ngCordova.plugins.appRate', [])
133133

134134
.provider("$cordovaAppRate", [function () {
135135

136-
this.setAppUrl = function (device, url) {
137-
var devices = ['ios', 'android', 'blackberry', 'windows8'];
138136

139-
if (devices.indexOf(device) !== -1) {
140-
AppRate.preferences.storeAppURL[device] = url;
137+
this.setPreferences = function (defaults) {
138+
if (!defaults || !angular.isObject(defaults)) {
139+
return;
141140
}
142-
else {
143-
alert("wrong device type");
144-
}
145-
};
146-
147-
this.useLanguage = function (language) {
148-
AppRate.preferences.useLanguage = language;
149-
};
150-
151-
this.displayAppName = function (name) {
152-
AppRate.preferences.displayAppName = name;
153-
};
154141

155-
this.promptAgainForEachNewVersion = function (boolean) {
156-
AppRate.preferences.promptAgainForEachNewVersion = boolean;
142+
AppRate.preferences.useLanguage = defaults.language || null;
143+
AppRate.preferences.displayAppName = defaults.appName || "";
144+
AppRate.preferences.promptAgainForEachNewVersion = defaults.promptAgainForEachNewVersion || true;
145+
AppRate.preferences.openStoreInApp = defaults.openStoreInApp || false;
146+
AppRate.preferences.usesUntilPrompt = defaults.usesUntilPrompt || 3;
147+
AppRate.preferences.useCustomRateDialog = defaults.useCustomRateDialog || false;
148+
AppRate.preferences.storeAppURL.ios = defaults.iosURL || null;
149+
AppRate.preferences.storeAppURL.android = defaults.androidURL || null;
150+
AppRate.preferences.storeAppURL.blackberry = defaults.blackberryURL || null;
151+
AppRate.preferences.storeAppURL.windows8 = defaults.windows8URL || null;
157152
};
158153

159-
this.usesUntilPrompt = function (number) {
160-
AppRate.preferences.usesUntilPrompt = number;
161-
};
162-
163-
this.openStoreInApp = function (boolean) {
164-
AppRate.preferences.openStoreInApp = boolean;
165-
};
166-
167-
this.useCustomRateDialog = function (boolean) {
168-
AppRate.preferences.useCustomRateDialog = boolean;
169-
};
170154

171-
this.customLocale = function (customObj) {
155+
this.setCustomLocale = function (customObj) {
172156
var strings = {
173157
title: 'Rate %@',
174158
message: 'If you enjoy using %@, would you mind taking a moment to rate it? It won’t take more than a minute. Thanks for your support!',

dist/ng-cordova.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/appRate.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,26 @@ angular.module('ngCordova.plugins.appRate', [])
55

66
.provider("$cordovaAppRate", [function () {
77

8-
this.setAppUrl = function (device, url) {
9-
var devices = ['ios', 'android', 'blackberry', 'windows8'];
108

11-
if (devices.indexOf(device) !== -1) {
12-
AppRate.preferences.storeAppURL[device] = url;
9+
this.setPreferences = function (defaults) {
10+
if (!defaults || !angular.isObject(defaults)) {
11+
return;
1312
}
14-
else {
15-
alert("wrong device type");
16-
}
17-
};
18-
19-
this.useLanguage = function (language) {
20-
AppRate.preferences.useLanguage = language;
21-
};
22-
23-
this.displayAppName = function (name) {
24-
AppRate.preferences.displayAppName = name;
25-
};
2613

27-
this.promptAgainForEachNewVersion = function (boolean) {
28-
AppRate.preferences.promptAgainForEachNewVersion = boolean;
14+
AppRate.preferences.useLanguage = defaults.language || null;
15+
AppRate.preferences.displayAppName = defaults.appName || "";
16+
AppRate.preferences.promptAgainForEachNewVersion = defaults.promptAgainForEachNewVersion || true;
17+
AppRate.preferences.openStoreInApp = defaults.openStoreInApp || false;
18+
AppRate.preferences.usesUntilPrompt = defaults.usesUntilPrompt || 3;
19+
AppRate.preferences.useCustomRateDialog = defaults.useCustomRateDialog || false;
20+
AppRate.preferences.storeAppURL.ios = defaults.iosURL || null;
21+
AppRate.preferences.storeAppURL.android = defaults.androidURL || null;
22+
AppRate.preferences.storeAppURL.blackberry = defaults.blackberryURL || null;
23+
AppRate.preferences.storeAppURL.windows8 = defaults.windows8URL || null;
2924
};
3025

31-
this.usesUntilPrompt = function (number) {
32-
AppRate.preferences.usesUntilPrompt = number;
33-
};
34-
35-
this.openStoreInApp = function (boolean) {
36-
AppRate.preferences.openStoreInApp = boolean;
37-
};
38-
39-
this.useCustomRateDialog = function (boolean) {
40-
AppRate.preferences.useCustomRateDialog = boolean;
41-
};
4226

43-
this.customLocale = function (customObj) {
27+
this.setCustomLocale = function (customObj) {
4428
var strings = {
4529
title: 'Rate %@',
4630
message: 'If you enjoy using %@, would you mind taking a moment to rate it? It won’t take more than a minute. Thanks for your support!',

0 commit comments

Comments
 (0)