diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java b/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java index 6a72c476..a5684005 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java @@ -2,7 +2,7 @@ package com.cradle.iitc_mobile; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Scanner; import android.app.Activity; import android.content.res.AssetManager; @@ -25,22 +25,35 @@ public class IITC_Settings extends Activity { e.printStackTrace(); } - ArrayList asset_list = new ArrayList(Arrays.asList(asset_array)); + ArrayList asset_list = new ArrayList(); ArrayList asset_values = new ArrayList(); - for (int i = 0; i < asset_list.size();) { - try { - if (asset_list.get(i).endsWith("user.js")) { - asset_values.add(am.open("plugins/" + asset_list.get(i)).toString()); - i++; + for (int i = 0; i < asset_array.length ; i++) { + if (asset_array[i].endsWith("user.js")) { + // find user plugin name for user readable entries + Scanner s = null; + String src = ""; + try { + s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A"); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } - else { - asset_list.remove(i); - asset_values.add(am.open("plugins/" + asset_list.get(i)).toString()); + if (s != null) src = s.hasNext() ? s.next() : ""; + String header = src.substring(src.indexOf("==UserScript=="), src.indexOf("==/UserScript==")); + // remove new line comments and replace with space + // this way we get double spaces instead of newline + double slash + header = header.replace("\n//", " "); + // get a list of key-value...split on multiple spaces + String[] attributes = header.split(" +"); + String plugin_name = "not found"; + for (int j = 0; j < attributes.length; j++) { + // search for name and use the value + if (attributes[j].equals("@name")) plugin_name = attributes[j+1]; } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + asset_list.add(plugin_name); + // real value + asset_values.add(asset_array[i]); } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java index 702f59db..5a68f307 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java @@ -26,7 +26,7 @@ public class IITC_SettingsFragment extends PreferenceFragment { //plugins MultiSelectListPreference pref_plugins = (MultiSelectListPreference) findPreference("pref_plugins"); pref_plugins.setEntries(getArguments().getStringArray("ASSETS")); - pref_plugins.setEntryValues(getArguments().getStringArray("ASSETS")); + pref_plugins.setEntryValues(getArguments().getStringArray("ASSETS_VAL")); // set build version ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version"); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 15873a28..caa42e89 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -46,7 +46,7 @@ public class IITC_WebViewClient extends WebViewClient { String[] attributes = header.split(" +"); String iitc_version = "not found"; for (int i = 0; i < attributes.length; i++) { - // search vor version and use the value + // search for version and use the value if (attributes[i].equals("@version")) iitc_version = attributes[i+1]; } return iitc_version;