Properly use AppComponent to only inject classes into dagger, inject static dependencies into BrowserApp class
This commit is contained in:
parent
a60ae614d9
commit
a24eb45ae4
@ -1,20 +1,16 @@
|
||||
package acr.browser.lightning.app;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import acr.browser.lightning.activity.BrowserActivity;
|
||||
import acr.browser.lightning.activity.ThemableBrowserActivity;
|
||||
import acr.browser.lightning.constant.BookmarkPage;
|
||||
import acr.browser.lightning.database.HistoryDatabase;
|
||||
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||
import acr.browser.lightning.fragment.BookmarkSettingsFragment;
|
||||
import acr.browser.lightning.fragment.BookmarksFragment;
|
||||
import acr.browser.lightning.fragment.LightningPreferenceFragment;
|
||||
import acr.browser.lightning.fragment.TabsFragment;
|
||||
import acr.browser.lightning.object.SearchAdapter;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
import acr.browser.lightning.view.LightningView;
|
||||
import dagger.Component;
|
||||
|
||||
@ -42,12 +38,6 @@ public interface AppComponent {
|
||||
|
||||
void inject(LightningPreferenceFragment fragment);
|
||||
|
||||
PreferenceManager getPreferenceManager();
|
||||
|
||||
BookmarkPage getBookmarkPage();
|
||||
|
||||
Bus getBus();
|
||||
|
||||
HistoryDatabase getHistoryDatabase();
|
||||
void inject(BrowserApp app);
|
||||
|
||||
}
|
||||
|
@ -35,4 +35,5 @@ public class AppModule {
|
||||
public Bus provideBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package acr.browser.lightning.app;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
import com.squareup.otto.Bus;
|
||||
@ -8,38 +9,41 @@ import com.squareup.otto.Bus;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import acr.browser.lightning.constant.BookmarkPage;
|
||||
import acr.browser.lightning.database.HistoryDatabase;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
|
||||
public class BrowserApp extends Application {
|
||||
|
||||
private static BrowserApp sInstance;
|
||||
private static AppComponent appComponent;
|
||||
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
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
sInstance = this;
|
||||
appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
|
||||
appComponent.inject(this);
|
||||
LeakCanary.install(this);
|
||||
buildDepencyGraph();
|
||||
}
|
||||
|
||||
public static BrowserApp getContext() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static AppComponent getAppComponent() {
|
||||
return appComponent;
|
||||
}
|
||||
|
||||
private void buildDepencyGraph() {
|
||||
appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
|
||||
public static Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public static HistoryDatabase getHistoryDatabase() {
|
||||
return appComponent.getHistoryDatabase();
|
||||
return historyDatabase;
|
||||
}
|
||||
|
||||
public static Executor getIOThread() {
|
||||
@ -47,15 +51,15 @@ public class BrowserApp extends Application {
|
||||
}
|
||||
|
||||
public static PreferenceManager getPreferenceManager() {
|
||||
return appComponent.getPreferenceManager();
|
||||
return preferenceManager;
|
||||
}
|
||||
|
||||
public static Bus getBus() {
|
||||
return appComponent.getBus();
|
||||
return bus;
|
||||
}
|
||||
|
||||
public static BookmarkPage getBookmarkPage() {
|
||||
return appComponent.getBookmarkPage();
|
||||
return bookmarkPage;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class DownloadHandler {
|
||||
/* package */
|
||||
private static void onDownloadStartNoStream(final Context context, String url, String userAgent,
|
||||
String contentDisposition, String mimetype) {
|
||||
final Bus eventBus = BrowserApp.getAppComponent().getBus();
|
||||
final Bus eventBus = BrowserApp.getBus();
|
||||
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
|
||||
|
||||
// Check to see if we have an SDCard
|
||||
|
Loading…
Reference in New Issue
Block a user