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 { @@ -56,8 +56,6 @@ public interface AppComponent {
void inject(ThemableSettingsActivity activity);
void inject(AdBlock adBlock);
void inject(LightningDownloadListener listener);
void inject(PrivacySettingsFragment fragment);

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

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

Loading…
Cancel
Save