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
This commit is contained in:
Adam Bradley
2014-02-20 20:41:48 -06:00
parent 356afdf04f
commit b69b40c826
2 changed files with 87 additions and 7 deletions

View File

@@ -108,6 +108,78 @@ describe('Ionic Platform Service', function() {
expect(ionic.Platform.platforms[3]).toEqual('android4_2');
});
it('sets grade a from iOS7', function() {
window.cordova = {};
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.1.1');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('a');
});
it('sets grade a from iOS6', function() {
window.cordova = {};
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('6.1.1');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('a');
});
it('sets grade a from Android 4.4', function() {
window.cordova = {};
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.4.1');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('a');
});
it('sets grade b from Android 4.3', function() {
window.cordova = {};
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.3.1');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('b');
});
it('sets grade b from Android 4.0', function() {
window.cordova = {};
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.0.0');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('b');
});
it('sets grade c from Android 3.0', function() {
window.cordova = {};
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('3.0.0');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('c');
});
it('sets grade c from Android 2.3.4', function() {
window.cordova = {};
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('2.3.4');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('c');
});
it('sets grade a from unknown android version', function() {
window.cordova = {};
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('0');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('a');
});
it('sets grade a from unknown platform', function() {
window.cordova = {};
ionic.Platform.setPlatform('whatever');
ionic.Platform.setVersion('20.3.4');
ionic.Platform._checkPlatforms()
expect(ionic.Platform.grade).toEqual('a');
});
it('is android', function() {
ionic.Platform.setPlatform('AnDrOiD');
expect(ionic.Platform.is('android')).toEqual(true);

View File

@@ -5,6 +5,7 @@
isReady: false,
isFullScreen: false,
platforms: null,
grade: null,
ready: function(cb) {
// run through tasks to complete now that the device is ready
@@ -18,16 +19,18 @@
},
detect: function() {
var i, bodyClass = document.body.className;
ionic.Platform._checkPlatforms();
if(this.platforms.length) {
// only change the body class if we got platform info
var i, bodyClass = document.body.className;
for(i = 0; i < this.platforms.length; i++) {
bodyClass += ' platform-' + this.platforms[i];
}
document.body.className = bodyClass;
// only change the body class if we got platform info
for(i = 0; i < this.platforms.length; i++) {
bodyClass += ' platform-' + this.platforms[i];
}
bodyClass += ' grade-' + this.grade;
document.body.className = bodyClass.trim();
},
device: function() {
@@ -38,6 +41,7 @@
_checkPlatforms: function(platforms) {
this.platforms = [];
this.grade = 'a';
var v = this.version().toString().replace('.', '_');
if(this.isCordova()) {
@@ -55,6 +59,10 @@
this.platforms.push('android');
this.platforms.push('android' + v.split('_')[0]);
this.platforms.push('android' + v);
if(platformVersion > 0 && platformVersion < 4.4) {
this.grade = (platformVersion < 4 ? 'c' : 'b');
}
}
},