Skip to content

Commit

Permalink
Check the version of the installed platform and return the correct pa…
Browse files Browse the repository at this point in the history
…th of the resources.

Bugfix issue apla#135
  • Loading branch information
vash15 committed Mar 19, 2018
1 parent 2f4924e commit f2da164
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
52 changes: 45 additions & 7 deletions bin/lib/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,27 @@ module.exports = function (context) {
cordova_lib = cordova.cordova_lib,
ConfigParser = cordova_lib.configparser,
cordova_util = req('cordova-lib/src/cordova/util'),
ofs = req("fs"),
fs = require("./filesystem")(Q, req('fs'), path),
platforms = {};

// fs, path, ET, cordova_util, ConfigParser

// Check the currente platform version and map the path of resources
function getResPath(){
return cordova_util
.getInstalledPlatformsWithVersions(context.opts.projectRoot)
.then(function(platformMap){
if ( typeof platformMap == 'object' && platformMap.android ){
var majorVersion = parseInt( platformMap.android[0] );
if ( majorVersion != NaN && majorVersion >= 7 ){
return path.join('platforms','android','app','src','main','res');
}
}
return path.join('platforms','android','res');
});
}

function mapConfig(config) {
var element = {
attrs: {},
Expand Down Expand Up @@ -153,15 +169,24 @@ module.exports = function (context) {
preferencesDocument = settingsDocuments.preferencesDocument,
preferencesStringDocument = settingsDocuments.preferencesStringDocument;


var pathXml = null;
var pathValues = null;
return fs.exists('platforms/android')
// Check version Platfom installed
.then(function () {
return getResPath();
})
// Write preferences xml file
.then(function () { return fs.mkdir('platforms/android/res/xml'); })
.then(function () { return fs.writeFile('platforms/android/res/xml/apppreferences.xml', preferencesDocument.write()); })
.then(function (pathRes) {
pathXml = path.join(pathRes, 'xml');
pathValues = path.join(pathRes, 'values');
return fs.mkdir(pathXml);
})
.then(function () { return fs.writeFile( path.join(pathXml,'apppreferences.xml'), preferencesDocument.write()); })

// Write localization resource file
.then(function () { return fs.mkdir('platforms/android/res/values'); })
.then(function (prefs) { return fs.writeFile('platforms/android/res/values/apppreferences.xml', preferencesStringDocument.write()); })
.then(function () { return fs.mkdir(pathValues); })
.then(function (prefs) { return fs.writeFile( path.join(pathValues,'apppreferences.xml'), preferencesStringDocument.write()); })

.then(function () { console.log('android preferences file was successfully generated'); })
.catch(function (err) {
Expand Down Expand Up @@ -214,12 +239,25 @@ module.exports = function (context) {
var androidPackagePath = "me.apla.cordova".replace (/\./g, '/');
var activityFileName = path.join ('platforms/android/src', androidPackagePath, 'AppPreferencesActivity.java');

var pathXml = null;
var pathValues = null;
return fs.exists('platforms/android')
// Check version Platfom installed
.then(function () {
return getResPath();
})

// Remove preferences xml file
.then(function () { return fs.unlink('platforms/android/res/xml/apppreferences.xml'); })
.then(function (pathRes) {
pathXml = path.join(pathRes, 'xml');
pathValues = path.join(pathRes, 'values');
return fs.unlink( path.join(pathXml,'apppreferences.xml') );
})

// Remove localization resource file
.then(function (prefs) { return fs.unlink('platforms/android/res/values/apppreferences.xml'); })
.then(function (prefs) {
return fs.unlink( path.join(pathValues,'values','apppreferences.xml') );
})

// Remove preferences from native android project
.then(function (data) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-app-preferences",
"version": "0.99.3",
"version": "0.99.4",
"description": "Application preferences plugin and preference pane generator",
"cordova": {
"id": "cordova-plugin-app-preferences",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-app-preferences"
version="0.99.3">
version="0.99.4">

<name>AppPreferences</name>
<description>Application preferences plugin and preference pane generator</description>
Expand Down

0 comments on commit f2da164

Please sign in to comment.