Browse Source

Properly use AppComponent to only inject classes into dagger, inject static dependencies into BrowserApp class

master
Anthony Restaino 9 years ago
parent
commit
a24eb45ae4
  1. 12
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  2. 1
      app/src/main/java/acr/browser/lightning/app/AppModule.java
  3. 30
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  4. 2
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

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

@ -1,20 +1,16 @@
package acr.browser.lightning.app; package acr.browser.lightning.app;
import com.squareup.otto.Bus;
import javax.inject.Singleton; import javax.inject.Singleton;
import acr.browser.lightning.activity.BrowserActivity; import acr.browser.lightning.activity.BrowserActivity;
import acr.browser.lightning.activity.ThemableBrowserActivity; import acr.browser.lightning.activity.ThemableBrowserActivity;
import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.database.HistoryDatabase;
import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.fragment.BookmarkSettingsFragment; import acr.browser.lightning.fragment.BookmarkSettingsFragment;
import acr.browser.lightning.fragment.BookmarksFragment; 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.preference.PreferenceManager;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;
import dagger.Component; import dagger.Component;
@ -42,12 +38,6 @@ public interface AppComponent {
void inject(LightningPreferenceFragment fragment); void inject(LightningPreferenceFragment fragment);
PreferenceManager getPreferenceManager(); void inject(BrowserApp app);
BookmarkPage getBookmarkPage();
Bus getBus();
HistoryDatabase getHistoryDatabase();
} }

1
app/src/main/java/acr/browser/lightning/app/AppModule.java

@ -35,4 +35,5 @@ public class AppModule {
public Bus provideBus() { public Bus provideBus() {
return bus; return bus;
} }
} }

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

@ -1,6 +1,7 @@
package acr.browser.lightning.app; package acr.browser.lightning.app;
import android.app.Application; import android.app.Application;
import android.content.Context;
import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.LeakCanary;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
@ -8,38 +9,41 @@ import com.squareup.otto.Bus;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import javax.inject.Inject;
import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.database.HistoryDatabase; import acr.browser.lightning.database.HistoryDatabase;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
public class BrowserApp extends Application { public class BrowserApp extends Application {
private static BrowserApp sInstance;
private static AppComponent appComponent; private static AppComponent appComponent;
private static final Executor mIOThread = Executors.newSingleThreadExecutor(); private static final Executor mIOThread = Executors.newSingleThreadExecutor();
@Inject static Context context;
@Inject static BookmarkPage bookmarkPage;
@Inject static HistoryDatabase historyDatabase;
@Inject static Bus bus;
@Inject static PreferenceManager preferenceManager;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
sInstance = this; appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
appComponent.inject(this);
LeakCanary.install(this); LeakCanary.install(this);
buildDepencyGraph();
}
public static BrowserApp getContext() {
return sInstance;
} }
public static AppComponent getAppComponent() { public static AppComponent getAppComponent() {
return appComponent; return appComponent;
} }
private void buildDepencyGraph() { public static Context getContext() {
appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); return context;
} }
public static HistoryDatabase getHistoryDatabase() { public static HistoryDatabase getHistoryDatabase() {
return appComponent.getHistoryDatabase(); return historyDatabase;
} }
public static Executor getIOThread() { public static Executor getIOThread() {
@ -47,15 +51,15 @@ public class BrowserApp extends Application {
} }
public static PreferenceManager getPreferenceManager() { public static PreferenceManager getPreferenceManager() {
return appComponent.getPreferenceManager(); return preferenceManager;
} }
public static Bus getBus() { public static Bus getBus() {
return appComponent.getBus(); return bus;
} }
public static BookmarkPage getBookmarkPage() { public static BookmarkPage getBookmarkPage() {
return appComponent.getBookmarkPage(); return bookmarkPage;
} }
} }

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

@ -134,7 +134,7 @@ public class DownloadHandler {
/* package */ /* package */
private static void onDownloadStartNoStream(final Context context, String url, String userAgent, private static void onDownloadStartNoStream(final Context context, String url, String userAgent,
String contentDisposition, String mimetype) { String contentDisposition, String mimetype) {
final Bus eventBus = BrowserApp.getAppComponent().getBus(); final Bus eventBus = BrowserApp.getBus();
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
// Check to see if we have an SDCard // Check to see if we have an SDCard

Loading…
Cancel
Save