Browse Source

Constructor injection > field injection

master
anthony restaino 8 years ago
parent
commit
ba976cd4b0
  1. 2
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  2. 18
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java

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

@ -56,8 +56,6 @@ public interface AppComponent {
void inject(ThemableSettingsActivity activity); void inject(ThemableSettingsActivity activity);
void inject(AdBlock adBlock);
void inject(LightningDownloadListener listener); void inject(LightningDownloadListener listener);
void inject(PrivacySettingsFragment fragment); void inject(PrivacySettingsFragment fragment);

18
app/src/main/java/acr/browser/lightning/utils/AdBlock.java

@ -1,5 +1,6 @@
package acr.browser.lightning.utils; package acr.browser.lightning.utils;
import android.app.Application;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -21,7 +22,6 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
@ -38,14 +38,16 @@ public class AdBlock {
private static final String TAB = "\t"; private static final String TAB = "\t";
private static final String SPACE = " "; private static final String SPACE = " ";
private static final String EMPTY = ""; private static final String EMPTY = "";
private final Set<String> mBlockedDomainsList = new HashSet<>();
private boolean mBlockAds;
@Inject PreferenceManager mPreferenceManager; @NonNull private final Set<String> mBlockedDomainsList = new HashSet<>();
@NonNull private final PreferenceManager mPreferenceManager;
@NonNull private final Application mApplication;
private boolean mBlockAds;
@Inject @Inject
public AdBlock() { AdBlock(@NonNull Application application, @NonNull PreferenceManager preferenceManager) {
BrowserApp.getAppComponent().inject(this); mApplication = application;
mPreferenceManager = preferenceManager;
if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) { if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) {
loadHostsFile().subscribeOn(Schedulers.io()).subscribe(); loadHostsFile().subscribeOn(Schedulers.io()).subscribe();
} }
@ -120,10 +122,10 @@ public class AdBlock {
return Completable.create(new CompletableAction() { return Completable.create(new CompletableAction() {
@Override @Override
public void onSubscribe(@NonNull CompletableSubscriber subscriber) { public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
AssetManager asset = BrowserApp.getApplication().getAssets(); AssetManager asset = mApplication.getAssets();
BufferedReader reader = null; BufferedReader reader = null;
//noinspection TryFinallyCanBeTryWithResources
try { try {
//noinspection IOResourceOpenedButNotSafelyClosed
reader = new BufferedReader(new InputStreamReader( reader = new BufferedReader(new InputStreamReader(
asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME))); asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME)));
StringBuilder lineBuilder = new StringBuilder(); StringBuilder lineBuilder = new StringBuilder();

Loading…
Cancel
Save