diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ContextMenuWebView.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ContextMenuWebView.java index b7841ab7..0c2cab98 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ContextMenuWebView.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ContextMenuWebView.java @@ -20,6 +20,7 @@ import android.widget.Toast; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.activity.MainActivity; +import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.util.OrbotStatusReceiver; import java.io.File; @@ -156,14 +157,27 @@ public class ContextMenuWebView extends NestedWebView { @Override public void reload() { - OrbotHelper.requestStartTor(context.getApplicationContext()); + AppSettings settings = new AppSettings(context); + if(settings.isProxyOrbot()) { + if(OrbotStatusReceiver.isInCorrectState(settings.isLoadImages())) { + super.reload(); + } else { + OrbotHelper.requestStartTor(context.getApplicationContext()); + } + } super.reload(); } @Override public void loadUrl(String url) { - if(!OrbotStatusReceiver.isProxySet()) - OrbotHelper.requestStartTor(context.getApplicationContext()); + AppSettings settings = new AppSettings(context); + if(settings.isProxyOrbot()) { + if(OrbotStatusReceiver.isInCorrectState(settings.isLoadImages())) { + super.loadUrl(url); + } else { + OrbotHelper.requestStartTor(context.getApplicationContext()); + } + } super.loadUrl(url); } } \ No newline at end of file diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/OrbotStatusReceiver.java b/app/src/main/java/com/github/dfa/diaspora_android/util/OrbotStatusReceiver.java index 0be9c451..5c97df2f 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/OrbotStatusReceiver.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/OrbotStatusReceiver.java @@ -147,4 +147,16 @@ public class OrbotStatusReceiver extends BroadcastReceiver { return proxySet; } + /** + * Return true if actual state represents desired state + * @param orbotProxyActive desired state; true if app should proxy through tor, false if no proxy used + * @return boolean + */ + public static boolean isInCorrectState(boolean orbotProxyActive) { + if(orbotProxyActive) { + return host != null && !host.equals("") && port > 0 && proxySet; + } else { + return (host.equals("") || host == null) && port < 1 && !proxySet; + } + } }