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 @@ @@ -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 { @@ -42,12 +38,6 @@ public interface AppComponent {
void inject(LightningPreferenceFragment fragment);
PreferenceManager getPreferenceManager();
BookmarkPage getBookmarkPage();
Bus getBus();
HistoryDatabase getHistoryDatabase();
void inject(BrowserApp app);
}

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

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

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

@ -1,6 +1,7 @@ @@ -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; @@ -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 { @@ -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;
}
}

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

@ -134,7 +134,7 @@ public class DownloadHandler { @@ -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…
Cancel
Save