diff --git a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java index 84236f0..3e978ed 100644 --- a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java +++ b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java @@ -8,6 +8,9 @@ import android.util.Log; import net.i2p.android.ui.I2PAndroidHelper; +import javax.inject.Inject; +import javax.inject.Singleton; + import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.bus.BrowserEvents; @@ -16,27 +19,18 @@ import acr.browser.lightning.preference.PreferenceManager; import info.guardianproject.netcipher.proxy.OrbotHelper; import info.guardianproject.netcipher.web.WebkitProxy; -/** - * 6/4/2015 Anthony Restaino - */ +@Singleton public class ProxyUtils { // Helper - private final I2PAndroidHelper mI2PHelper; private static boolean mI2PHelperBound; private static boolean mI2PProxyInitialized; - private final PreferenceManager mPreferences; - private static ProxyUtils mInstance; - private ProxyUtils(Context context) { - mPreferences = BrowserApp.getPreferenceManager(); - mI2PHelper = new I2PAndroidHelper(context.getApplicationContext()); - } + @Inject PreferenceManager mPreferences; + @Inject I2PAndroidHelper mI2PHelper; - public static ProxyUtils getInstance() { - if (mInstance == null) { - mInstance = new ProxyUtils(BrowserApp.getContext()); - } - return mInstance; + @Inject + public ProxyUtils() { + BrowserApp.getAppComponent().inject(this); } /* diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 118ed6c..a3dc7a8 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -178,26 +178,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements private String mCameraPhotoPath; // The singleton BookmarkManager - @Inject - BookmarkManager mBookmarkManager; + @Inject BookmarkManager mBookmarkManager; // Event bus - @Inject - Bus mEventBus; + @Inject Bus mEventBus; - @Inject - BookmarkPage mBookmarkPage; + @Inject BookmarkPage mBookmarkPage; - @Inject - LightningDialogBuilder bookmarksDialogBuilder; + @Inject LightningDialogBuilder bookmarksDialogBuilder; - @Inject - TabsManager mTabsManager; + @Inject TabsManager mTabsManager; - // Preference manager was moved on ThemeableBrowserActivity - - @Inject - HistoryDatabase mHistoryDatabase; + @Inject HistoryDatabase mHistoryDatabase; // Image private Bitmap mWebpageBitmap; @@ -206,7 +198,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements private DrawerArrowDrawable mArrowDrawable; // Proxy - private ProxyUtils mProxyUtils; + @Inject ProxyUtils mProxyUtils; // Constant private static final int API = android.os.Build.VERSION.SDK_INT; @@ -311,8 +303,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } arrowButton.setOnClickListener(this); - mProxyUtils = ProxyUtils.getInstance(); - // create the search EditText in the ToolBar mSearch = (AutoCompleteTextView) customView.findViewById(R.id.search); mUntitledTitle = getString(R.string.untitled); diff --git a/app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java index 13f210e..b4c1d4c 100644 --- a/app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java @@ -13,8 +13,7 @@ import acr.browser.lightning.preference.PreferenceManager; public abstract class ThemableBrowserActivity extends AppCompatActivity { - @Inject - PreferenceManager mPreferences; + @Inject PreferenceManager mPreferences; private int mTheme; private boolean mShowTabsInDrawer; diff --git a/app/src/main/java/acr/browser/lightning/app/AppComponent.java b/app/src/main/java/acr/browser/lightning/app/AppComponent.java index b0d55cf..3b30803 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppComponent.java +++ b/app/src/main/java/acr/browser/lightning/app/AppComponent.java @@ -11,6 +11,7 @@ import acr.browser.lightning.fragment.BookmarksFragment; import acr.browser.lightning.fragment.LightningPreferenceFragment; import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.object.SearchAdapter; +import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.view.LightningView; import dagger.Component; @@ -40,4 +41,6 @@ public interface AppComponent { void inject(BrowserApp app); + void inject(ProxyUtils proxyUtils); + } diff --git a/app/src/main/java/acr/browser/lightning/app/AppModule.java b/app/src/main/java/acr/browser/lightning/app/AppModule.java index e0a00bf..bed1d9a 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppModule.java +++ b/app/src/main/java/acr/browser/lightning/app/AppModule.java @@ -4,6 +4,8 @@ import android.content.Context; import com.squareup.otto.Bus; +import net.i2p.android.ui.I2PAndroidHelper; + import javax.inject.Singleton; import acr.browser.lightning.database.BookmarkManager; @@ -36,4 +38,10 @@ public class AppModule { return bus; } + @Provides + @Singleton + public I2PAndroidHelper provideI2PAndroidHelper() { + return new I2PAndroidHelper(app.getApplicationContext()); + } + } diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 4ae7d99..376592a 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -94,14 +94,10 @@ public class LightningView { private final WebViewHandler mWebViewHandler = new WebViewHandler(this); private final Map mRequestHeaders = new ArrayMap<>(); - @Inject - Bus mEventBus; - - @Inject - PreferenceManager mPreferences; - - @Inject - LightningDialogBuilder mBookmarksDialogBuilder; + @Inject Bus mEventBus; + @Inject PreferenceManager mPreferences; + @Inject LightningDialogBuilder mBookmarksDialogBuilder; + @Inject ProxyUtils mProxyUtils; @SuppressLint("NewApi") public LightningView(Activity activity, String url, boolean isIncognito) { @@ -362,7 +358,6 @@ public class LightningView { /** * Initialize the settings of the WebView that are intrinsic to Lightning and cannot * be altered by the user. Distinguish between Incognito and Regular tabs here. - * */ @SuppressLint("NewApi") private void initializeSettings() { @@ -724,7 +719,7 @@ public class LightningView { */ public synchronized void reload() { // Check if configured proxy is available - if (!ProxyUtils.getInstance().isProxyReady()) { + if (!mProxyUtils.isProxyReady()) { // User has been notified return; } @@ -976,7 +971,7 @@ public class LightningView { */ public synchronized void loadUrl(@NonNull String url) { // Check if configured proxy is available - if (!ProxyUtils.getInstance().isProxyReady()) { + if (!mProxyUtils.isProxyReady()) { return; } diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index b38b4a0..1d58262 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -32,6 +32,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import javax.inject.Inject; + import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.bus.BrowserEvents; @@ -52,6 +54,9 @@ class LightningWebClient extends WebViewClient { private final Bus mEventBus; private final IntentUtils mIntentUtils; + @Inject + ProxyUtils mProxyUtils; + LightningWebClient(Activity activity, LightningView lightningView) { mActivity = activity; mUIController = (UIController) activity; @@ -267,7 +272,7 @@ class LightningWebClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // Check if configured proxy is available - if (!ProxyUtils.getInstance().isProxyReady()) { + if (!mProxyUtils.isProxyReady()) { // User has been notified return true; }