Browse Source

Make ProxyUtils a proper dagger singleton, inject more member variables where possible

master
Anthony Restaino 9 years ago
parent
commit
6084c9b478
  1. 24
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  2. 24
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  3. 3
      app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java
  4. 3
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  5. 8
      app/src/main/java/acr/browser/lightning/app/AppModule.java
  6. 17
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  7. 7
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

24
app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java

@ -8,6 +8,9 @@ import android.util.Log; @@ -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; @@ -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);
}
/*

24
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -178,26 +178,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -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 @@ -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 @@ -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);

3
app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java

@ -13,8 +13,7 @@ import acr.browser.lightning.preference.PreferenceManager; @@ -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;

3
app/src/main/java/acr/browser/lightning/app/AppComponent.java

@ -11,6 +11,7 @@ import acr.browser.lightning.fragment.BookmarksFragment; @@ -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 { @@ -40,4 +41,6 @@ public interface AppComponent {
void inject(BrowserApp app);
void inject(ProxyUtils proxyUtils);
}

8
app/src/main/java/acr/browser/lightning/app/AppModule.java

@ -4,6 +4,8 @@ import android.content.Context; @@ -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 { @@ -36,4 +38,10 @@ public class AppModule {
return bus;
}
@Provides
@Singleton
public I2PAndroidHelper provideI2PAndroidHelper() {
return new I2PAndroidHelper(app.getApplicationContext());
}
}

17
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -94,14 +94,10 @@ public class LightningView { @@ -94,14 +94,10 @@ public class LightningView {
private final WebViewHandler mWebViewHandler = new WebViewHandler(this);
private final Map<String, String> 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 { @@ -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 { @@ -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 { @@ -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;
}

7
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -32,6 +32,8 @@ import java.util.ArrayList; @@ -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 { @@ -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 { @@ -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;
}

Loading…
Cancel
Save