some code formatting, adding final modifiers
This commit is contained in:
parent
a690b2bc03
commit
9516994fa4
@ -3,7 +3,6 @@ package com.cradle.iitc_mobile;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@ -248,68 +247,61 @@ public class IITC_FileManager {
|
|||||||
|
|
||||||
public void installPlugin(final Uri uri, final boolean invalidateHeaders) {
|
public void installPlugin(final Uri uri, final boolean invalidateHeaders) {
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivity);
|
|
||||||
|
|
||||||
// set title
|
|
||||||
alertDialogBuilder.setTitle(mActivity.getString(R.string.install_dialog_top));
|
|
||||||
|
|
||||||
// set dialog message
|
|
||||||
String text = mActivity.getString(R.string.install_dialog_msg);
|
String text = mActivity.getString(R.string.install_dialog_msg);
|
||||||
text = String.format(text, uri);
|
text = String.format(text, uri);
|
||||||
alertDialogBuilder
|
|
||||||
|
// create alert dialog
|
||||||
|
new AlertDialog.Builder(mActivity)
|
||||||
|
.setTitle(mActivity.getString(R.string.install_dialog_top))
|
||||||
.setMessage(Html.fromHtml(text))
|
.setMessage(Html.fromHtml(text))
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(final DialogInterface dialog, final int which) {
|
||||||
copyPlugin(uri, invalidateHeaders);
|
copyPlugin(uri, invalidateHeaders);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(final DialogInterface dialog, final int which) {
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.create()
|
||||||
// create alert dialog
|
.show();
|
||||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
||||||
|
|
||||||
// show it
|
|
||||||
alertDialog.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyPlugin(final Uri uri, final boolean invalidateHeaders) {
|
private void copyPlugin(final Uri uri, final boolean invalidateHeaders) {
|
||||||
Thread thread = new Thread(new Runnable() {
|
final Thread thread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final String url = uri.toString();
|
final String url = uri.toString();
|
||||||
String fileName = url.substring( url.lastIndexOf('/')+1, url.length() );
|
|
||||||
// we need 2 stream since an inputStream is useless after read once
|
// we need 2 stream since an inputStream is useless after read once
|
||||||
// we read it twice because we first need the script ID for the fileName and
|
// we read it twice because we first need the script ID for the fileName and
|
||||||
// afterwards reading it again while copying
|
// afterwards reading it again while copying
|
||||||
InputStream is, isCopy;
|
InputStream is, isCopy;
|
||||||
if (uri.getScheme().contains("http")) {
|
if (uri.getScheme().contains("http")) {
|
||||||
URLConnection conn = new URL(url).openConnection();
|
final URLConnection conn = new URL(url).openConnection();
|
||||||
URLConnection connCopy = new URL(url).openConnection();
|
final URLConnection connCopy = new URL(url).openConnection();
|
||||||
is = conn.getInputStream();
|
is = conn.getInputStream();
|
||||||
isCopy = connCopy.getInputStream();
|
isCopy = connCopy.getInputStream();
|
||||||
} else {
|
} else {
|
||||||
is = mActivity.getContentResolver().openInputStream(uri);
|
is = mActivity.getContentResolver().openInputStream(uri);
|
||||||
isCopy = mActivity.getContentResolver().openInputStream(uri);
|
isCopy = mActivity.getContentResolver().openInputStream(uri);
|
||||||
}
|
}
|
||||||
fileName = getScriptInfo(isCopy).get("id") + ".user.js";
|
final String fileName = getScriptInfo(isCopy).get("id") + ".user.js";
|
||||||
|
|
||||||
// create IITCm external plugins directory if it doesn't already exist
|
// create IITCm external plugins directory if it doesn't already exist
|
||||||
final File pluginsDirectory = new File(PLUGINS_PATH);
|
final File pluginsDirectory = new File(PLUGINS_PATH);
|
||||||
pluginsDirectory.mkdirs();
|
pluginsDirectory.mkdirs();
|
||||||
|
|
||||||
// create in and out streams and copy plugin
|
// create in and out streams and copy plugin
|
||||||
File outFile = new File(pluginsDirectory + "/" + fileName);
|
final File outFile = new File(pluginsDirectory, fileName);
|
||||||
OutputStream os = new FileOutputStream(outFile);
|
final OutputStream os = new FileOutputStream(outFile);
|
||||||
IITC_FileManager.copyStream(is, os, true);
|
IITC_FileManager.copyStream(is, os, true);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
Log.w(e);
|
Log.w(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,7 +311,7 @@ public class IITC_FileManager {
|
|||||||
try {
|
try {
|
||||||
thread.join();
|
thread.join();
|
||||||
((IITC_PluginPreferenceActivity) mActivity).invalidateHeaders();
|
((IITC_PluginPreferenceActivity) mActivity).invalidateHeaders();
|
||||||
} catch (InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
Log.w(e);
|
Log.w(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user