Skip to content

Commit

Permalink
feat(grade): Set grade in body class depending on platform performance
Browse files Browse the repository at this point in the history
First draft of how devices play out:

.grade-a:
- iOS
- >= Android 4.4

.grade-b:
- Android >= 4 && < 4.4

.grade-c:
- Android < 4
  • Loading branch information
Adam Bradley committed Feb 21, 2014
1 parent 356afdf commit b69b40c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
72 changes: 72 additions & 0 deletions js/ext/angular/test/service/ionicPlatform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 15 additions & 7 deletions js/utils/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -38,6 +41,7 @@

_checkPlatforms: function(platforms) {
this.platforms = [];
this.grade = 'a';
var v = this.version().toString().replace('.', '_');

if(this.isCordova()) {
Expand All @@ -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');
}
}
},

Expand Down

0 comments on commit b69b40c

Please sign in to comment.