added 'add external plugin' button to IITC plugins preference. ensures that the scripts are always copied to the correct folder.
This commit is contained in:
parent
5e723ca328
commit
2054b5f790
BIN
mobile/res/drawable-hdpi/ic_action_new.png
Normal file
BIN
mobile/res/drawable-hdpi/ic_action_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 262 B |
BIN
mobile/res/drawable-mdpi/ic_action_new.png
Normal file
BIN
mobile/res/drawable-mdpi/ic_action_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 185 B |
BIN
mobile/res/drawable-xhdpi/ic_action_new.png
Normal file
BIN
mobile/res/drawable-xhdpi/ic_action_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 250 B |
BIN
mobile/res/drawable-xxhdpi/ic_action_new.png
Normal file
BIN
mobile/res/drawable-xxhdpi/ic_action_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 288 B |
12
mobile/res/menu/plugins.xml
Normal file
12
mobile/res/menu/plugins.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_plugins_add"
|
||||
android:icon="@drawable/ic_action_new"
|
||||
android:orderInCategory="10"
|
||||
android:showAsAction="ifRoom|collapseActionView"
|
||||
android:title="@string/menu_plugins_add"/>
|
||||
|
||||
</menu>
|
@ -86,9 +86,8 @@
|
||||
<string name="notice_extplugins">
|
||||
<![CDATA[Hint:<br><br>
|
||||
IITC Mobile is able to load external plugins too!<br><br>
|
||||
• create <b>%1$s</b><br>
|
||||
• move *.user.js files there<br>
|
||||
• plugins should be listed above the official plugins]]>
|
||||
Add them by clicking the (+) icon at the top right.
|
||||
The plugin files have to end with \'.user.js\' and are copied to <b>%1$s</b><br>]]>
|
||||
</string>
|
||||
<string name="notice_sharing">
|
||||
<![CDATA[With <em>Share portal</em> you can:<br>
|
||||
@ -162,6 +161,7 @@
|
||||
<string name="menu_clear_cookies">Clear Cookies</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="menu_debug">Debug</string>
|
||||
<string name="menu_plugins_add">Add external plugins</string>
|
||||
<string name="choose_account_to_login">Choose account to login</string>
|
||||
<string name="login_failed">Login failed.</string>
|
||||
<string name="search_hint">Search Locations</string>
|
||||
|
@ -1,26 +1,32 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cradle.iitc_mobile.fragments.PluginsFragment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -29,6 +35,8 @@ import java.util.TreeMap;
|
||||
|
||||
public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
private final static int COPY_PLUGIN_REQUEST = 1;
|
||||
|
||||
private List<Header> mHeaders;
|
||||
// we use a tree map to have a map with alphabetical order
|
||||
// don't initialize the asset plugin map, because it tells us if the settings are started the first time
|
||||
@ -103,17 +111,75 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.plugins, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home: // exit settings when home button (iitc icon) is pressed
|
||||
onBackPressed();
|
||||
return true;
|
||||
case R.id.menu_plugins_add:
|
||||
// create the chooser Intent
|
||||
final Intent target = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
// iitcm only parses *.user.js scripts
|
||||
target.setType("file/*");
|
||||
target.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
||||
try {
|
||||
startActivityForResult(Intent.createChooser(target, "Choose file"), COPY_PLUGIN_REQUEST);
|
||||
} catch (final ActivityNotFoundException e) {
|
||||
Toast.makeText(this, "No activity to select a file found." +
|
||||
"Please install a file browser of your choice!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch(requestCode) {
|
||||
case COPY_PLUGIN_REQUEST:
|
||||
if (data != null && data.getData() != null) {
|
||||
String filePath = data.getData().getPath();
|
||||
copyPlugin(filePath);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void copyPlugin(String pluginPath) {
|
||||
try {
|
||||
File inFile = new File(pluginPath);
|
||||
// create IITCm external plugins directory if it doesn't already exist
|
||||
File pluginsDirectory = getUserPluginsDirectory();
|
||||
pluginsDirectory.mkdirs();
|
||||
|
||||
// create in and out streams and copy plugin
|
||||
File outFile = new File(pluginsDirectory.getPath() + "/" + inFile.getName());
|
||||
InputStream is = new FileInputStream(inFile);
|
||||
OutputStream os = new FileOutputStream(outFile);
|
||||
IITC_FileManager.copyStream(is, os, true);
|
||||
|
||||
// invalidate headers to build a fresh preference screen with the new plugin listed
|
||||
invalidateHeaders();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(final String s) {
|
||||
return true;
|
||||
@ -140,10 +206,15 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
return asset_array;
|
||||
}
|
||||
|
||||
private File[] getUserPlugins() {
|
||||
private File getUserPluginsDirectory() {
|
||||
final String iitc_path = Environment.getExternalStorageDirectory().getPath()
|
||||
+ "/IITC_Mobile/";
|
||||
final File directory = new File(iitc_path + "plugins/");
|
||||
return directory;
|
||||
}
|
||||
|
||||
private File[] getUserPlugins() {
|
||||
final File directory = getUserPluginsDirectory();
|
||||
File[] files = directory.listFiles();
|
||||
if (files == null) {
|
||||
files = new File[0];
|
||||
@ -164,6 +235,8 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
if ((userPlugins.length + officialPlugins.length) != (numPlugins + mDeletedPlugins)) {
|
||||
Log.d("new or less plugins found since last start, rebuild preferences");
|
||||
sAssetPlugins.clear();
|
||||
sUserPlugins.clear();
|
||||
mDeletedPlugins = 0;
|
||||
setUpPluginPreferenceScreen();
|
||||
}
|
||||
}
|
||||
|
@ -158,19 +158,17 @@ From here you can remove/disable individual plugins or IITC itself.
|
||||
END
|
||||
),
|
||||
|
||||
'mobile-plugins' => Array ( "IITC Mobile: Is it possible to add other plugins to IITC Mobile?",
|
||||
'mobile-plugins' => Array ( "IITC Mobile: Is it possible to add external plugins to IITC Mobile?",
|
||||
<<<'END'
|
||||
Yes it is!
|
||||
<ul>
|
||||
<li>Create a folder named "IITC_Mobile" in your home directory.</li>
|
||||
<li>Inside this folder, create a new folder named "plugins".</li>
|
||||
<li>Copy all your additional plugins to this folder.</li>
|
||||
<li>You should see your plugins listed above the official plugins.</li>
|
||||
<li>Navigate to the IITC Plugins preference screen and click the (+) icon at the top right. You can select the script using a file explorer of your choice.</li>
|
||||
<li>IITCm creates a new folder in your home directory, named "IITC_Mobile". Inside this folder you'll find a "plugins" folder where all external plugins are copied to.</li>
|
||||
</ul>
|
||||
Note:
|
||||
<ul>
|
||||
<li>The filename has to end with *.user.js.</li>
|
||||
<li>If you don't know where to find your home directory: Enable dev-mode in the settings and follow the hint.</li>
|
||||
<li>You need a file explorer app installed to add external plugins</li>
|
||||
</ul>
|
||||
END
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user