From 61bb99c3be40cc0dc2b5f445ba867353674114d3 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 26 Apr 2017 22:03:49 -0400 Subject: [PATCH] Injecting application where possible --- .../main/java/acr/browser/lightning/app/BrowserApp.java | 7 ------- .../acr/browser/lightning/download/DownloadHandler.java | 6 +----- .../acr/browser/lightning/search/SuggestionsAdapter.java | 7 ++++--- .../acr/browser/lightning/search/SuggestionsManager.java | 6 ++---- .../java/acr/browser/lightning/view/LightningView.java | 3 ++- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java b/app/src/main/java/acr/browser/lightning/app/BrowserApp.java index 8866e5f..c09f688 100644 --- a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java +++ b/app/src/main/java/acr/browser/lightning/app/BrowserApp.java @@ -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 { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); - sApplication = this; } @Override @@ -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. * diff --git a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java index ede6725..1f55e17 100644 --- a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java +++ b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java @@ -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 { .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 { 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 diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java index f465d45..d49af22 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java @@ -66,6 +66,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @Inject BookmarkManager mBookmarkManager; @Inject PreferenceManager mPreferenceManager; + @Inject Application mApplication; private final List mAllBookmarks = new ArrayList<>(5); @@ -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 { @NonNull private Single> 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(); } diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java index f453a6a..0ee0aa0 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java @@ -23,8 +23,7 @@ class SuggestionsManager { @NonNull static Single> createGoogleQueryObservable(@NonNull final String query, - @NonNull final Context context) { - final Application application = BrowserApp.get(context); + @NonNull final Application application) { return Single.create(new SingleAction>() { @Override public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { @@ -39,8 +38,7 @@ class SuggestionsManager { @NonNull static Single> createDuckQueryObservable(@NonNull final String query, - @NonNull final Context context) { - final Application application = BrowserApp.get(context); + @NonNull final Application application) { return Single.create(new SingleAction>() { @Override public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 5937393..3508f79 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -464,11 +464,12 @@ public class LightningView { } + @NonNull private Single getPathObservable(final String subFolder) { return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - File file = BrowserApp.get(mActivity).getDir(subFolder, 0); + File file = mActivity.getDir(subFolder, 0); subscriber.onItem(file); subscriber.onComplete(); }