show plugin name instead of file name

This commit is contained in:
Philipp Schaefer
2013-04-22 20:35:01 +02:00
parent 99a18444bf
commit 0f04acbc36
3 changed files with 28 additions and 15 deletions

View File

@ -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<String> asset_list = new ArrayList<String>(Arrays.asList(asset_array));
ArrayList<String> asset_list = new ArrayList<String>();
ArrayList<String> asset_values = new ArrayList<String>();
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]);
}
}