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;
import net.i2p.android.ui.I2PAndroidHelper; import net.i2p.android.ui.I2PAndroidHelper;
import javax.inject.Inject;
import javax.inject.Singleton;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents; 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.proxy.OrbotHelper;
import info.guardianproject.netcipher.web.WebkitProxy; import info.guardianproject.netcipher.web.WebkitProxy;
/** @Singleton
* 6/4/2015 Anthony Restaino
*/
public class ProxyUtils { public class ProxyUtils {
// Helper // Helper
private final I2PAndroidHelper mI2PHelper;
private static boolean mI2PHelperBound; private static boolean mI2PHelperBound;
private static boolean mI2PProxyInitialized; private static boolean mI2PProxyInitialized;
private final PreferenceManager mPreferences;
private static ProxyUtils mInstance;
private ProxyUtils(Context context) { @Inject PreferenceManager mPreferences;
mPreferences = BrowserApp.getPreferenceManager(); @Inject I2PAndroidHelper mI2PHelper;
mI2PHelper = new I2PAndroidHelper(context.getApplicationContext());
}
public static ProxyUtils getInstance() { @Inject
if (mInstance == null) { public ProxyUtils() {
mInstance = new ProxyUtils(BrowserApp.getContext()); BrowserApp.getAppComponent().inject(this);
}
return mInstance;
} }
/* /*

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

@ -178,26 +178,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private String mCameraPhotoPath; private String mCameraPhotoPath;
// The singleton BookmarkManager // The singleton BookmarkManager
@Inject @Inject BookmarkManager mBookmarkManager;
BookmarkManager mBookmarkManager;
// Event bus // Event bus
@Inject @Inject Bus mEventBus;
Bus mEventBus;
@Inject @Inject BookmarkPage mBookmarkPage;
BookmarkPage mBookmarkPage;
@Inject @Inject LightningDialogBuilder bookmarksDialogBuilder;
LightningDialogBuilder bookmarksDialogBuilder;
@Inject @Inject TabsManager mTabsManager;
TabsManager mTabsManager;
// Preference manager was moved on ThemeableBrowserActivity @Inject HistoryDatabase mHistoryDatabase;
@Inject
HistoryDatabase mHistoryDatabase;
// Image // Image
private Bitmap mWebpageBitmap; private Bitmap mWebpageBitmap;
@ -206,7 +198,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private DrawerArrowDrawable mArrowDrawable; private DrawerArrowDrawable mArrowDrawable;
// Proxy // Proxy
private ProxyUtils mProxyUtils; @Inject ProxyUtils mProxyUtils;
// Constant // Constant
private static final int API = android.os.Build.VERSION.SDK_INT; 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); arrowButton.setOnClickListener(this);
mProxyUtils = ProxyUtils.getInstance();
// create the search EditText in the ToolBar // create the search EditText in the ToolBar
mSearch = (AutoCompleteTextView) customView.findViewById(R.id.search); mSearch = (AutoCompleteTextView) customView.findViewById(R.id.search);
mUntitledTitle = getString(R.string.untitled); 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;
public abstract class ThemableBrowserActivity extends AppCompatActivity { public abstract class ThemableBrowserActivity extends AppCompatActivity {
@Inject @Inject PreferenceManager mPreferences;
PreferenceManager mPreferences;
private int mTheme; private int mTheme;
private boolean mShowTabsInDrawer; private boolean mShowTabsInDrawer;

3
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.LightningPreferenceFragment;
import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter; import acr.browser.lightning.object.SearchAdapter;
import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;
import dagger.Component; import dagger.Component;
@ -40,4 +41,6 @@ public interface AppComponent {
void inject(BrowserApp app); 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;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import net.i2p.android.ui.I2PAndroidHelper;
import javax.inject.Singleton; import javax.inject.Singleton;
import acr.browser.lightning.database.BookmarkManager; import acr.browser.lightning.database.BookmarkManager;
@ -36,4 +38,10 @@ public class AppModule {
return bus; 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 {
private final WebViewHandler mWebViewHandler = new WebViewHandler(this); private final WebViewHandler mWebViewHandler = new WebViewHandler(this);
private final Map<String, String> mRequestHeaders = new ArrayMap<>(); private final Map<String, String> mRequestHeaders = new ArrayMap<>();
@Inject @Inject Bus mEventBus;
Bus mEventBus; @Inject PreferenceManager mPreferences;
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
@Inject @Inject ProxyUtils mProxyUtils;
PreferenceManager mPreferences;
@Inject
LightningDialogBuilder mBookmarksDialogBuilder;
@SuppressLint("NewApi") @SuppressLint("NewApi")
public LightningView(Activity activity, String url, boolean isIncognito) { 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 * 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. * be altered by the user. Distinguish between Incognito and Regular tabs here.
*
*/ */
@SuppressLint("NewApi") @SuppressLint("NewApi")
private void initializeSettings() { private void initializeSettings() {
@ -724,7 +719,7 @@ public class LightningView {
*/ */
public synchronized void reload() { public synchronized void reload() {
// Check if configured proxy is available // Check if configured proxy is available
if (!ProxyUtils.getInstance().isProxyReady()) { if (!mProxyUtils.isProxyReady()) {
// User has been notified // User has been notified
return; return;
} }
@ -976,7 +971,7 @@ public class LightningView {
*/ */
public synchronized void loadUrl(@NonNull String url) { public synchronized void loadUrl(@NonNull String url) {
// Check if configured proxy is available // Check if configured proxy is available
if (!ProxyUtils.getInstance().isProxyReady()) { if (!mProxyUtils.isProxyReady()) {
return; return;
} }

7
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.List;
import java.util.Map; import java.util.Map;
import javax.inject.Inject;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents; import acr.browser.lightning.bus.BrowserEvents;
@ -52,6 +54,9 @@ class LightningWebClient extends WebViewClient {
private final Bus mEventBus; private final Bus mEventBus;
private final IntentUtils mIntentUtils; private final IntentUtils mIntentUtils;
@Inject
ProxyUtils mProxyUtils;
LightningWebClient(Activity activity, LightningView lightningView) { LightningWebClient(Activity activity, LightningView lightningView) {
mActivity = activity; mActivity = activity;
mUIController = (UIController) activity; mUIController = (UIController) activity;
@ -267,7 +272,7 @@ class LightningWebClient extends WebViewClient {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Check if configured proxy is available // Check if configured proxy is available
if (!ProxyUtils.getInstance().isProxyReady()) { if (!mProxyUtils.isProxyReady()) {
// User has been notified // User has been notified
return true; return true;
} }

Loading…
Cancel
Save