made getScriptInfo static and use it in pluginpreferenceactivity
This commit is contained in:
parent
bb4d57acad
commit
3f901a588a
@ -21,6 +21,7 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@ -193,29 +194,12 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
void addPluginPreference(String src, String plugin_key, boolean user) {
|
void addPluginPreference(String src, String plugin_key, boolean user) {
|
||||||
|
|
||||||
// now parse plugin name, description and category
|
// parse plugin name, description and category
|
||||||
String header = src.substring(src.indexOf("==UserScript=="),
|
// we need default versions here otherwise iitcm may crash
|
||||||
src.indexOf("==/UserScript=="));
|
HashMap<String,String> info = IITC_WebViewClient.getScriptInfo(src);
|
||||||
// remove new line comments and replace with space
|
String plugin_name = info.get("name");
|
||||||
// this way we get double spaces instead of newline + double slash
|
String plugin_cat = info.get("category");
|
||||||
header = header.replace("\n//", " ");
|
String plugin_desc = info.get("description");
|
||||||
// get a list of key-value...split on multiple spaces
|
|
||||||
String[] attributes = header.split(" +");
|
|
||||||
String plugin_name = "not found";
|
|
||||||
String plugin_desc = "not found";
|
|
||||||
String plugin_cat = "Misc";
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
if (attributes[j].equals("@description")) {
|
|
||||||
plugin_desc = attributes[j + 1];
|
|
||||||
}
|
|
||||||
if (attributes[j].equals("@category")) {
|
|
||||||
plugin_cat = attributes[j + 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove IITC plugin prefix from plugin_name
|
// remove IITC plugin prefix from plugin_name
|
||||||
plugin_name = plugin_name.replace("IITC Plugin: ", "");
|
plugin_name = plugin_name.replace("IITC Plugin: ", "");
|
||||||
|
@ -56,7 +56,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
return map.get("version");
|
return map.get("version");
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, String> getScriptInfo(String js) {
|
// static method because we use it in IITC_PluginPreferenceActivity too
|
||||||
|
public static HashMap<String, String> getScriptInfo(String js) {
|
||||||
HashMap<String, String> map = new HashMap<String, String>();
|
HashMap<String, String> map = new HashMap<String, String>();
|
||||||
String header = "";
|
String header = "";
|
||||||
if (js != null) {
|
if (js != null) {
|
||||||
@ -67,7 +68,12 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
header = header.replace("\n//", " ");
|
header = header.replace("\n//", " ");
|
||||||
// get a list of key-value
|
// get a list of key-value
|
||||||
String[] attributes = header.split(" +");
|
String[] attributes = header.split(" +");
|
||||||
String iitc_version = "not found";
|
// add default values
|
||||||
|
map.put("version", "not found");
|
||||||
|
map.put("name", "unknown");
|
||||||
|
map.put("description", "");
|
||||||
|
map.put("category", "Misc");
|
||||||
|
// add parsed values
|
||||||
for (int i = 0; i < attributes.length; i++) {
|
for (int i = 0; i < attributes.length; i++) {
|
||||||
// search for attributes and use the value
|
// search for attributes and use the value
|
||||||
if (attributes[i].equals("@version")) {
|
if (attributes[i].equals("@version")) {
|
||||||
@ -79,6 +85,9 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
if (attributes[i].equals("@description")) {
|
if (attributes[i].equals("@description")) {
|
||||||
map.put("description", attributes[i + 1]);
|
map.put("description", attributes[i + 1]);
|
||||||
}
|
}
|
||||||
|
if (attributes[i].equals("@category")) {
|
||||||
|
map.put("category", attributes[i + 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user