1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 13:22:08 +01:00

Fixed most points mentioned in comments

This commit is contained in:
vanitasvitae 2016-06-06 14:35:07 +02:00
parent b75e8e4174
commit 8bbd7b996e
5 changed files with 63 additions and 56 deletions

View file

@ -180,14 +180,14 @@ public class MainActivity extends AppCompatActivity
//Orbot integration //Orbot integration
OrbotStatusReceiver.setMainActivity(this); OrbotStatusReceiver.setMainActivity(this);
OrbotHelper.requestStartTor(this.getApplicationContext()); OrbotHelper.requestStartTor(getApplicationContext());
if(appSettings.isProxyOrbot()) { if(appSettings.isProxyOrbot()) {
if(!OrbotHelper.isOrbotInstalled(this)) { if(!OrbotHelper.isOrbotInstalled(getApplicationContext())) {
appSettings.setProxyOrbot(false); appSettings.setProxyOrbot(false);
promptInstallOrbot(); promptInstallOrbot();
} else { } else {
//precautionary set Proxy //precautionary set Proxy
OrbotStatusReceiver.setProxy(this.getApplicationContext(), OrbotStatusReceiver.defaultHost, OrbotStatusReceiver.defaultPort); OrbotStatusReceiver.setProxy(getApplicationContext(), OrbotStatusReceiver.DEFAULT_HOST, OrbotStatusReceiver.DEFAULT_PORT);
} }
} }
@ -323,13 +323,9 @@ public class MainActivity extends AppCompatActivity
} }
}); });
afterOnCreate(savedInstanceState); OrbotHelper.requestStartTor(getApplicationContext());
}
private void afterOnCreate(Bundle savedInstanceState) {
OrbotHelper.requestStartTor(this.getApplicationContext());
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (Helpers.isOnline(MainActivity.this)) { if (Helpers.isOnline(this)) {
webView.loadData("", "text/html", null); webView.loadData("", "text/html", null);
webView.loadUrl("https://" + podDomain); webView.loadUrl("https://" + podDomain);
} else { } else {
@ -986,11 +982,12 @@ public class MainActivity extends AppCompatActivity
boolean before = appSettings.isProxyOrbot(); boolean before = appSettings.isProxyOrbot();
appSettings.setProxyOrbot(!before); appSettings.setProxyOrbot(!before);
if(before) { if(before) {
OrbotStatusReceiver.resetProxy(MainActivity.this.getApplicationContext()); OrbotStatusReceiver.resetProxy(getApplicationContext());
} else { } else {
OrbotHelper.requestStartTor(MainActivity.this); OrbotHelper.requestStartTor(getApplicationContext());
webView.reload(); webView.reload();
} }
break;
} }
} }
@ -1089,47 +1086,27 @@ public class MainActivity extends AppCompatActivity
* page on f-droid.org. * page on f-droid.org.
*/ */
void promptInstallOrbot() { void promptInstallOrbot() {
String message = this.getString(R.string.you_must_have_orbot) + " ";
final Intent intent = OrbotHelper.getOrbotInstallIntent(MainActivity.this); final Intent intent = OrbotHelper.getOrbotInstallIntent(MainActivity.this);
if (intent.getPackage() == null) { String message = this.getString(R.string.you_must_have_orbot) + " "
message += MainActivity.this.getString(R.string.download_orbot_from_fdroid); + (intent.getPackage() == null ? getString(R.string.download_orbot_from_fdroid)
} else { : getString(R.string.get_orbot_from_fdroid));
message += MainActivity.this.getString(R.string.get_orbot_from_fdroid); new AlertDialog.Builder(this).setTitle(R.string.install_orbot_).setMessage(message).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.install_orbot_);
builder.setMessage(message);
builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
MainActivity.this.startActivity(intent); MainActivity.this.startActivity(intent);
} }
}); }).setNegativeButton(android.R.string.no, null).show();
builder.setNegativeButton(android.R.string.no, null);
builder.show();
} }
public void requestOrbotStart(boolean backgroundStartsDisabled) { public void requestOrbotStart(boolean backgroundStartsDisabled) {
AlertDialog.Builder startDialog = new AlertDialog.Builder(this); AlertDialog.Builder startDialog = new AlertDialog.Builder(this).setTitle(R.string.start_orbot_)
startDialog.setTitle(R.string.start_orbot_); .setMessage((backgroundStartsDisabled ? R.string.orbot_starts_disabled_message
if(backgroundStartsDisabled) : R.string.orbot_doesn_t_appear_to_be_running_would_you_like_to_start_it_up_and_connect_to_tor_));
startDialog.setMessage(R.string.orbot_starts_disabled_message);
else
startDialog.setMessage(R.string.orbot_doesn_t_appear_to_be_running_would_you_like_to_start_it_up_and_connect_to_tor_);
startDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { startDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
startActivityForResult(OrbotHelper.getShowOrbotStartIntent(), 1); startActivityForResult(OrbotHelper.getShowOrbotStartIntent(), 1);
} }
}); }).setNegativeButton(android.R.string.no, null).show();
startDialog.setNegativeButton(android.R.string.no, null);
startDialog.show();
}
public boolean useOrbot() {
return appSettings.isProxyOrbot();
} }
} }

View file

@ -73,17 +73,25 @@ public class GetPodsService extends Service {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
//HttpClient client = new DefaultHttpClient(); //HttpClient client = new DefaultHttpClient();
List<String> list = null; List<String> list = null;
HttpsURLConnection connection;
InputStream inStream;
try { try {
HttpsURLConnection connection = NetCipher.getHttpsURLConnection("https://podupti.me/api.php?key=4r45tg&format=json"); connection = NetCipher.getHttpsURLConnection("https://podupti.me/api.php?key=4r45tg&format=json");
int statusCode = connection.getResponseCode(); int statusCode = connection.getResponseCode();
if (statusCode == 200) { if (statusCode == 200) {
InputStream content = connection.getInputStream(); inStream = connection.getInputStream();
BufferedReader reader = new BufferedReader( BufferedReader reader = new BufferedReader(
new InputStreamReader(content)); new InputStreamReader(inStream));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
builder.append(line); builder.append(line);
} }
try {
inStream.close();
} catch (IOException e) {}
connection.disconnect();
} else { } else {
Log.e(TAG, "Failed to download list of pods"); Log.e(TAG, "Failed to download list of pods");
} }

View file

@ -13,6 +13,8 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import javax.net.ssl.HttpsURLConnection;
import info.guardianproject.netcipher.NetCipher; import info.guardianproject.netcipher.NetCipher;
/** /**
@ -37,10 +39,12 @@ public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
String url = urls[0]; String url = urls[0];
Bitmap bitmap = null; Bitmap bitmap = null;
FileOutputStream out = null; FileOutputStream out = null;
InputStream inStream;
HttpsURLConnection connection;
try { try {
//InputStream in = new java.net.URL(url).openStream(); connection = NetCipher.getHttpsURLConnection(url);
InputStream in = NetCipher.getHttpsURLConnection(url).getInputStream(); inStream = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(in); bitmap = BitmapFactory.decodeStream(inStream);
// Save to file if not null // Save to file if not null
if (savePath != null) { if (savePath != null) {
@ -48,6 +52,12 @@ public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} }
try {
inStream.close();
} catch (IOException e) {}
connection.disconnect();
} catch (Exception e) { } catch (Exception e) {
Log.e(App.TAG, e.getMessage()); Log.e(App.TAG, e.getMessage());
} finally { } finally {

View file

@ -10,6 +10,7 @@ import com.github.dfa.diaspora_android.data.PodUserProfile;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
@ -40,18 +41,21 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
String cookies = cookieManager.getCookie("https://" + app.getSettings().getPodDomain()); String cookies = cookieManager.getCookie("https://" + app.getSettings().getPodDomain());
Log.d(App.TAG, cookies); Log.d(App.TAG, cookies);
HttpsURLConnection connection;
InputStream inStream;
try { try {
URL url = new URL("https://" + app.getSettings().getPodDomain() + "/stream"); URL url = new URL("https://" + app.getSettings().getPodDomain() + "/stream");
HttpsURLConnection conn = NetCipher.getHttpsURLConnection(url); connection = NetCipher.getHttpsURLConnection(url);
conn.setReadTimeout(10000); connection.setReadTimeout(10000);
conn.setConnectTimeout(15000); connection.setConnectTimeout(15000);
conn.setRequestMethod("GET"); connection.setRequestMethod("GET");
if (cookies != null) { if (cookies != null) {
conn.setRequestProperty("Cookie", cookies); connection.setRequestProperty("Cookie", cookies);
} }
conn.connect(); connection.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); inStream = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
String line; String line;
final String TARGET_TAG = "window.gon={};gon.user="; final String TARGET_TAG = "window.gon={};gon.user=";
while ((line = br.readLine()) != null && !line.startsWith("<body")) { while ((line = br.readLine()) != null && !line.startsWith("<body")) {
@ -60,6 +64,14 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
break; break;
} }
} }
try{
br.close();
inStream.close();
} catch (IOException e){}
connection.disconnect();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -42,8 +42,8 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
public static final String EXTRA_HTTP_HOST = "org.torproject.android.intent.extra.HTTP_PROXY_HOST"; public static final String EXTRA_HTTP_HOST = "org.torproject.android.intent.extra.HTTP_PROXY_HOST";
public static final String EXTRA_HTTP_PORT = "org.torproject.android.intent.extra.HTTP_PROXY_PORT"; public static final String EXTRA_HTTP_PORT = "org.torproject.android.intent.extra.HTTP_PROXY_PORT";
public static final String defaultHost = "127.0.0.1"; public static final String DEFAULT_HOST = "127.0.0.1";
public static final int defaultPort = 8118; public static final int DEFAULT_PORT = 8118;
private static String host = ""; private static String host = "";
private static int port = 0; private static int port = 0;
@ -88,7 +88,7 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
//Got no values from intent //Got no values from intent
if((nHost == null || nPort == -1)) { if((nHost == null || nPort == -1)) {
if(host.equals("") || port == 0) { if(host.equals("") || port == 0) {
setProxy(context, defaultHost, defaultPort); setProxy(context, DEFAULT_HOST, DEFAULT_PORT);
} }
} else { } else {
setProxy(context, nHost, nPort); setProxy(context, nHost, nPort);