Skip to content

Commit b69b40c

Browse files
author
Adam Bradley
committed
feat(grade): Set grade in body class depending on platform performance
First draft of how devices play out: .grade-a: - iOS - >= Android 4.4 .grade-b: - Android >= 4 && < 4.4 .grade-c: - Android < 4
1 parent 356afdf commit b69b40c

File tree

2 files changed

+87
-7
lines changed

2 files changed

+87
-7
lines changed

Diff for: js/ext/angular/test/service/ionicPlatform.unit.js

+72
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,78 @@ describe('Ionic Platform Service', function() {
108108
expect(ionic.Platform.platforms[3]).toEqual('android4_2');
109109
});
110110

111+
it('sets grade a from iOS7', function() {
112+
window.cordova = {};
113+
ionic.Platform.setPlatform('iOS');
114+
ionic.Platform.setVersion('7.1.1');
115+
ionic.Platform._checkPlatforms()
116+
expect(ionic.Platform.grade).toEqual('a');
117+
});
118+
119+
it('sets grade a from iOS6', function() {
120+
window.cordova = {};
121+
ionic.Platform.setPlatform('iOS');
122+
ionic.Platform.setVersion('6.1.1');
123+
ionic.Platform._checkPlatforms()
124+
expect(ionic.Platform.grade).toEqual('a');
125+
});
126+
127+
it('sets grade a from Android 4.4', function() {
128+
window.cordova = {};
129+
ionic.Platform.setPlatform('android');
130+
ionic.Platform.setVersion('4.4.1');
131+
ionic.Platform._checkPlatforms()
132+
expect(ionic.Platform.grade).toEqual('a');
133+
});
134+
135+
it('sets grade b from Android 4.3', function() {
136+
window.cordova = {};
137+
ionic.Platform.setPlatform('android');
138+
ionic.Platform.setVersion('4.3.1');
139+
ionic.Platform._checkPlatforms()
140+
expect(ionic.Platform.grade).toEqual('b');
141+
});
142+
143+
it('sets grade b from Android 4.0', function() {
144+
window.cordova = {};
145+
ionic.Platform.setPlatform('android');
146+
ionic.Platform.setVersion('4.0.0');
147+
ionic.Platform._checkPlatforms()
148+
expect(ionic.Platform.grade).toEqual('b');
149+
});
150+
151+
it('sets grade c from Android 3.0', function() {
152+
window.cordova = {};
153+
ionic.Platform.setPlatform('android');
154+
ionic.Platform.setVersion('3.0.0');
155+
ionic.Platform._checkPlatforms()
156+
expect(ionic.Platform.grade).toEqual('c');
157+
});
158+
159+
it('sets grade c from Android 2.3.4', function() {
160+
window.cordova = {};
161+
ionic.Platform.setPlatform('android');
162+
ionic.Platform.setVersion('2.3.4');
163+
ionic.Platform._checkPlatforms()
164+
expect(ionic.Platform.grade).toEqual('c');
165+
});
166+
167+
it('sets grade a from unknown android version', function() {
168+
window.cordova = {};
169+
ionic.Platform.setPlatform('android');
170+
ionic.Platform.setVersion('0');
171+
ionic.Platform._checkPlatforms()
172+
expect(ionic.Platform.grade).toEqual('a');
173+
});
174+
175+
it('sets grade a from unknown platform', function() {
176+
window.cordova = {};
177+
ionic.Platform.setPlatform('whatever');
178+
ionic.Platform.setVersion('20.3.4');
179+
ionic.Platform._checkPlatforms()
180+
expect(ionic.Platform.grade).toEqual('a');
181+
});
182+
111183
it('is android', function() {
112184
ionic.Platform.setPlatform('AnDrOiD');
113185
expect(ionic.Platform.is('android')).toEqual(true);

Diff for: js/utils/platform.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
isReady: false,
66
isFullScreen: false,
77
platforms: null,
8+
grade: null,
89

910
ready: function(cb) {
1011
// run through tasks to complete now that the device is ready
@@ -18,16 +19,18 @@
1819
},
1920

2021
detect: function() {
22+
var i, bodyClass = document.body.className;
23+
2124
ionic.Platform._checkPlatforms();
2225

23-
if(this.platforms.length) {
24-
// only change the body class if we got platform info
25-
var i, bodyClass = document.body.className;
26-
for(i = 0; i < this.platforms.length; i++) {
27-
bodyClass += ' platform-' + this.platforms[i];
28-
}
29-
document.body.className = bodyClass;
26+
// only change the body class if we got platform info
27+
for(i = 0; i < this.platforms.length; i++) {
28+
bodyClass += ' platform-' + this.platforms[i];
3029
}
30+
31+
bodyClass += ' grade-' + this.grade;
32+
33+
document.body.className = bodyClass.trim();
3134
},
3235

3336
device: function() {
@@ -38,6 +41,7 @@
3841

3942
_checkPlatforms: function(platforms) {
4043
this.platforms = [];
44+
this.grade = 'a';
4145
var v = this.version().toString().replace('.', '_');
4246

4347
if(this.isCordova()) {
@@ -55,6 +59,10 @@
5559
this.platforms.push('android');
5660
this.platforms.push('android' + v.split('_')[0]);
5761
this.platforms.push('android' + v);
62+
63+
if(platformVersion > 0 && platformVersion < 4.4) {
64+
this.grade = (platformVersion < 4 ? 'c' : 'b');
65+
}
5866
}
5967
},
6068

0 commit comments

Comments
 (0)