Browse Source

Injecting application where possible

master
anthony restaino 8 years ago
parent
commit
61bb99c3be
  1. 7
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  2. 6
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  3. 7
      app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java
  4. 6
      app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java
  5. 3
      app/src/main/java/acr/browser/lightning/view/LightningView.java

7
app/src/main/java/acr/browser/lightning/app/BrowserApp.java

@ -30,7 +30,6 @@ public class BrowserApp extends Application { @@ -30,7 +30,6 @@ public class BrowserApp extends Application {
private static final String TAG = BrowserApp.class.getSimpleName();
@Nullable private static Application sApplication;
@Nullable private static AppComponent sAppComponent;
private static final Executor mIOThread = Executors.newSingleThreadExecutor();
private static final Executor mTaskThread = Executors.newCachedThreadPool();
@ -41,7 +40,6 @@ public class BrowserApp extends Application { @@ -41,7 +40,6 @@ public class BrowserApp extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
sApplication = this;
}
@Override
@ -116,11 +114,6 @@ public class BrowserApp extends Application { @@ -116,11 +114,6 @@ public class BrowserApp extends Application {
return mTaskThread;
}
@NonNull
public static Bus getBus(@NonNull Context context) {
return get(context).mBus;
}
/**
* Determines whether this is a release build.
*

6
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -23,15 +23,12 @@ import android.webkit.CookieManager; @@ -23,15 +23,12 @@ import android.webkit.CookieManager;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import com.squareup.otto.Bus;
import java.io.File;
import java.io.IOException;
import acr.browser.lightning.BuildConfig;
import acr.browser.lightning.R;
import acr.browser.lightning.activity.MainActivity;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.dialog.BrowserDialog;
import acr.browser.lightning.preference.PreferenceManager;
@ -50,7 +47,7 @@ public class DownloadHandler { @@ -50,7 +47,7 @@ public class DownloadHandler {
.getPath();
@Nullable
public static String guessFileExtension(@NonNull String filename) {
static String guessFileExtension(@NonNull String filename) {
int lastIndex = filename.lastIndexOf('.') + 1;
if (lastIndex > 0 && filename.length() > lastIndex) {
return filename.substring(lastIndex, filename.length());
@ -157,7 +154,6 @@ public class DownloadHandler { @@ -157,7 +154,6 @@ public class DownloadHandler {
private static void onDownloadStartNoStream(@NonNull final Activity context, @NonNull PreferenceManager preferences,
String url, String userAgent,
String contentDisposition, @Nullable String mimetype) {
final Bus eventBus = BrowserApp.getBus(context);
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
// Check to see if we have an SDCard

7
app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java

@ -66,6 +66,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @@ -66,6 +66,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
@Inject BookmarkManager mBookmarkManager;
@Inject PreferenceManager mPreferenceManager;
@Inject Application mApplication;
private final List<HistoryItem> mAllBookmarks = new ArrayList<>(5);
@ -96,7 +97,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @@ -96,7 +97,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
public void clearCache() {
// We don't need these cache files anymore
Schedulers.io().execute(new ClearCacheRunnable(BrowserApp.get(mContext)));
Schedulers.io().execute(new ClearCacheRunnable(mApplication));
}
public void refreshBookmarks() {
@ -294,9 +295,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @@ -294,9 +295,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
@NonNull
private Single<List<HistoryItem>> getSuggestionsForQuery(@NonNull final String query) {
if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_GOOGLE) {
return SuggestionsManager.createGoogleQueryObservable(query, mContext);
return SuggestionsManager.createGoogleQueryObservable(query, mApplication);
} else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) {
return SuggestionsManager.createDuckQueryObservable(query, mContext);
return SuggestionsManager.createDuckQueryObservable(query, mApplication);
} else {
return Single.empty();
}

6
app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java

@ -23,8 +23,7 @@ class SuggestionsManager { @@ -23,8 +23,7 @@ class SuggestionsManager {
@NonNull
static Single<List<HistoryItem>> createGoogleQueryObservable(@NonNull final String query,
@NonNull final Context context) {
final Application application = BrowserApp.get(context);
@NonNull final Application application) {
return Single.create(new SingleAction<List<HistoryItem>>() {
@Override
public void onSubscribe(@NonNull final SingleSubscriber<List<HistoryItem>> subscriber) {
@ -39,8 +38,7 @@ class SuggestionsManager { @@ -39,8 +38,7 @@ class SuggestionsManager {
@NonNull
static Single<List<HistoryItem>> createDuckQueryObservable(@NonNull final String query,
@NonNull final Context context) {
final Application application = BrowserApp.get(context);
@NonNull final Application application) {
return Single.create(new SingleAction<List<HistoryItem>>() {
@Override
public void onSubscribe(@NonNull final SingleSubscriber<List<HistoryItem>> subscriber) {

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

@ -464,11 +464,12 @@ public class LightningView { @@ -464,11 +464,12 @@ public class LightningView {
}
@NonNull
private Single<File> getPathObservable(final String subFolder) {
return Single.create(new SingleAction<File>() {
@Override
public void onSubscribe(@NonNull SingleSubscriber<File> subscriber) {
File file = BrowserApp.get(mActivity).getDir(subFolder, 0);
File file = mActivity.getDir(subFolder, 0);
subscriber.onItem(file);
subscriber.onComplete();
}

Loading…
Cancel
Save