mirror of
https://github.com/gsantner/dandelion
synced 2024-11-24 05:12:09 +01:00
Fixed most points mentioned in comments
This commit is contained in:
parent
b75e8e4174
commit
8bbd7b996e
5 changed files with 63 additions and 56 deletions
|
@ -180,14 +180,14 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
//Orbot integration
|
||||
OrbotStatusReceiver.setMainActivity(this);
|
||||
OrbotHelper.requestStartTor(this.getApplicationContext());
|
||||
OrbotHelper.requestStartTor(getApplicationContext());
|
||||
if(appSettings.isProxyOrbot()) {
|
||||
if(!OrbotHelper.isOrbotInstalled(this)) {
|
||||
if(!OrbotHelper.isOrbotInstalled(getApplicationContext())) {
|
||||
appSettings.setProxyOrbot(false);
|
||||
promptInstallOrbot();
|
||||
} else {
|
||||
//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);
|
||||
}
|
||||
|
||||
private void afterOnCreate(Bundle savedInstanceState) {
|
||||
OrbotHelper.requestStartTor(this.getApplicationContext());
|
||||
OrbotHelper.requestStartTor(getApplicationContext());
|
||||
if (savedInstanceState == null) {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (Helpers.isOnline(this)) {
|
||||
webView.loadData("", "text/html", null);
|
||||
webView.loadUrl("https://" + podDomain);
|
||||
} else {
|
||||
|
@ -986,11 +982,12 @@ public class MainActivity extends AppCompatActivity
|
|||
boolean before = appSettings.isProxyOrbot();
|
||||
appSettings.setProxyOrbot(!before);
|
||||
if(before) {
|
||||
OrbotStatusReceiver.resetProxy(MainActivity.this.getApplicationContext());
|
||||
OrbotStatusReceiver.resetProxy(getApplicationContext());
|
||||
} else {
|
||||
OrbotHelper.requestStartTor(MainActivity.this);
|
||||
OrbotHelper.requestStartTor(getApplicationContext());
|
||||
webView.reload();
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1089,47 +1086,27 @@ public class MainActivity extends AppCompatActivity
|
|||
* page on f-droid.org.
|
||||
*/
|
||||
void promptInstallOrbot() {
|
||||
String message = this.getString(R.string.you_must_have_orbot) + " ";
|
||||
|
||||
final Intent intent = OrbotHelper.getOrbotInstallIntent(MainActivity.this);
|
||||
if (intent.getPackage() == null) {
|
||||
message += MainActivity.this.getString(R.string.download_orbot_from_fdroid);
|
||||
} else {
|
||||
message += MainActivity.this.getString(R.string.get_orbot_from_fdroid);
|
||||
}
|
||||
|
||||
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() {
|
||||
String message = this.getString(R.string.you_must_have_orbot) + " "
|
||||
+ (intent.getPackage() == null ? getString(R.string.download_orbot_from_fdroid)
|
||||
: 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() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
MainActivity.this.startActivity(intent);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.no, null);
|
||||
builder.show();
|
||||
}).setNegativeButton(android.R.string.no, null).show();
|
||||
}
|
||||
|
||||
public void requestOrbotStart(boolean backgroundStartsDisabled) {
|
||||
AlertDialog.Builder startDialog = new AlertDialog.Builder(this);
|
||||
startDialog.setTitle(R.string.start_orbot_);
|
||||
if(backgroundStartsDisabled)
|
||||
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_);
|
||||
|
||||
AlertDialog.Builder startDialog = new AlertDialog.Builder(this).setTitle(R.string.start_orbot_)
|
||||
.setMessage((backgroundStartsDisabled ? R.string.orbot_starts_disabled_message
|
||||
: 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() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
startActivityForResult(OrbotHelper.getShowOrbotStartIntent(), 1);
|
||||
}
|
||||
});
|
||||
startDialog.setNegativeButton(android.R.string.no, null);
|
||||
startDialog.show();
|
||||
}
|
||||
|
||||
public boolean useOrbot() {
|
||||
return appSettings.isProxyOrbot();
|
||||
}).setNegativeButton(android.R.string.no, null).show();
|
||||
}
|
||||
}
|
|
@ -73,17 +73,25 @@ public class GetPodsService extends Service {
|
|||
StringBuilder builder = new StringBuilder();
|
||||
//HttpClient client = new DefaultHttpClient();
|
||||
List<String> list = null;
|
||||
HttpsURLConnection connection;
|
||||
InputStream inStream;
|
||||
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();
|
||||
if (statusCode == 200) {
|
||||
InputStream content = connection.getInputStream();
|
||||
inStream = connection.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(content));
|
||||
new InputStreamReader(inStream));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
|
||||
try {
|
||||
inStream.close();
|
||||
} catch (IOException e) {}
|
||||
|
||||
connection.disconnect();
|
||||
} else {
|
||||
Log.e(TAG, "Failed to download list of pods");
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import info.guardianproject.netcipher.NetCipher;
|
||||
|
||||
/**
|
||||
|
@ -37,10 +39,12 @@ public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
|
|||
String url = urls[0];
|
||||
Bitmap bitmap = null;
|
||||
FileOutputStream out = null;
|
||||
InputStream inStream;
|
||||
HttpsURLConnection connection;
|
||||
try {
|
||||
//InputStream in = new java.net.URL(url).openStream();
|
||||
InputStream in = NetCipher.getHttpsURLConnection(url).getInputStream();
|
||||
bitmap = BitmapFactory.decodeStream(in);
|
||||
connection = NetCipher.getHttpsURLConnection(url);
|
||||
inStream = connection.getInputStream();
|
||||
bitmap = BitmapFactory.decodeStream(inStream);
|
||||
|
||||
// Save to file if not null
|
||||
if (savePath != null) {
|
||||
|
@ -48,6 +52,12 @@ public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
|
|||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||
}
|
||||
|
||||
try {
|
||||
inStream.close();
|
||||
} catch (IOException e) {}
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(App.TAG, e.getMessage());
|
||||
} finally {
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.github.dfa.diaspora_android.data.PodUserProfile;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
|
@ -40,18 +41,21 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
|
|||
String cookies = cookieManager.getCookie("https://" + app.getSettings().getPodDomain());
|
||||
Log.d(App.TAG, cookies);
|
||||
|
||||
HttpsURLConnection connection;
|
||||
InputStream inStream;
|
||||
try {
|
||||
URL url = new URL("https://" + app.getSettings().getPodDomain() + "/stream");
|
||||
HttpsURLConnection conn = NetCipher.getHttpsURLConnection(url);
|
||||
conn.setReadTimeout(10000);
|
||||
conn.setConnectTimeout(15000);
|
||||
conn.setRequestMethod("GET");
|
||||
connection = NetCipher.getHttpsURLConnection(url);
|
||||
connection.setReadTimeout(10000);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setRequestMethod("GET");
|
||||
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;
|
||||
final String TARGET_TAG = "window.gon={};gon.user=";
|
||||
while ((line = br.readLine()) != null && !line.startsWith("<body")) {
|
||||
|
@ -60,6 +64,14 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
br.close();
|
||||
inStream.close();
|
||||
} catch (IOException e){}
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -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_PORT = "org.torproject.android.intent.extra.HTTP_PROXY_PORT";
|
||||
public static final String defaultHost = "127.0.0.1";
|
||||
public static final int defaultPort = 8118;
|
||||
public static final String DEFAULT_HOST = "127.0.0.1";
|
||||
public static final int DEFAULT_PORT = 8118;
|
||||
|
||||
private static String host = "";
|
||||
private static int port = 0;
|
||||
|
@ -88,7 +88,7 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
|
|||
//Got no values from intent
|
||||
if((nHost == null || nPort == -1)) {
|
||||
if(host.equals("") || port == 0) {
|
||||
setProxy(context, defaultHost, defaultPort);
|
||||
setProxy(context, DEFAULT_HOST, DEFAULT_PORT);
|
||||
}
|
||||
} else {
|
||||
setProxy(context, nHost, nPort);
|
||||
|
|
Loading…
Reference in a new issue