Browse Source

More injection

master
anthony restaino 8 years ago
parent
commit
0cc8777e31
  1. 5
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  2. 18
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  3. 19
      app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java
  4. 6
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  5. 9
      app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java

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

@ -25,6 +25,7 @@ import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.search.SuggestionsAdapter; import acr.browser.lightning.search.SuggestionsAdapter;
import acr.browser.lightning.utils.AdBlock; import acr.browser.lightning.utils.AdBlock;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.view.LightningChromeClient;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;
import acr.browser.lightning.view.LightningWebClient; import acr.browser.lightning.view.LightningWebClient;
import dagger.Component; import dagger.Component;
@ -77,6 +78,8 @@ public interface AppComponent {
void inject(SuggestionsAdapter suggestionsAdapter); void inject(SuggestionsAdapter suggestionsAdapter);
@NonNull HistoryDatabase historyDatabase(); void inject(LightningChromeClient chromeClient);
HistoryDatabase historyDatabase();
} }

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

@ -49,13 +49,13 @@ public class BrowserApp extends Application {
super.onCreate(); super.onCreate();
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll() .detectAll()
.penaltyLog() .penaltyLog()
.build()); .build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll() .detectAll()
.penaltyLog() .penaltyLog()
.build()); .build());
} }
final Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); final Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
@ -95,12 +95,6 @@ public class BrowserApp extends Application {
}); });
} }
@NonNull
public static Application getApplication() {
Preconditions.checkNonNull(sApplication);
return sApplication;
}
@NonNull @NonNull
public static BrowserApp get(@NonNull Context context) { public static BrowserApp get(@NonNull Context context) {
return (BrowserApp) context.getApplicationContext(); return (BrowserApp) context.getApplicationContext();

19
app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java

@ -17,6 +17,9 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import javax.inject.Inject;
import javax.inject.Singleton;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
@ -24,14 +27,18 @@ import acr.browser.lightning.utils.Utils;
* Reactive model that can fetch favicons * Reactive model that can fetch favicons
* from URLs and also cache them. * from URLs and also cache them.
*/ */
@Singleton
public class FaviconModel { public class FaviconModel {
private static final String TAG = "FaviconModel"; private static final String TAG = "FaviconModel";
private final ImageFetcher mImageFetcher; @NonNull private final ImageFetcher mImageFetcher;
@NonNull private final Application mApplication;
public FaviconModel() { @Inject
public FaviconModel(@NonNull Application application) {
mImageFetcher = new ImageFetcher(); mImageFetcher = new ImageFetcher();
mApplication = application;
} }
@NonNull @NonNull
@ -63,9 +70,7 @@ public class FaviconModel {
return; return;
} }
Application app = BrowserApp.getApplication(); File faviconCacheFile = createFaviconCacheFile(mApplication, uri);
File faviconCacheFile = createFaviconCacheFile(app, uri);
Bitmap favicon = null; Bitmap favicon = null;
@ -117,13 +122,11 @@ public class FaviconModel {
return; return;
} }
Application app = BrowserApp.getApplication();
Log.d(TAG, "Caching icon for " + uri.getHost()); Log.d(TAG, "Caching icon for " + uri.getHost());
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
File image = createFaviconCacheFile(app, uri); File image = createFaviconCacheFile(mApplication, uri);
fos = new FileOutputStream(image); fos = new FileOutputStream(image);
favicon.compress(Bitmap.CompressFormat.PNG, 100, fos); favicon.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush(); fos.flush();

6
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -88,7 +88,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
private FaviconModel mFaviconModel; @Inject FaviconModel mFaviconModel;
private TabsManager mTabsManager; private TabsManager mTabsManager;
@ -148,8 +148,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme); mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) : mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :
ThemeUtils.getIconLightThemeColor(context); ThemeUtils.getIconLightThemeColor(context);
mFaviconModel = new FaviconModel();
} }
private TabsManager getTabsManager() { private TabsManager getTabsManager() {
@ -269,8 +267,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme); mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) : mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
ThemeUtils.getIconLightThemeColor(activity); ThemeUtils.getIconLightThemeColor(activity);
mFaviconModel = new FaviconModel();
} }
private void updateBookmarkIndicator(final String url) { private void updateBookmarkIndicator(final String url) {

9
app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java

@ -22,13 +22,16 @@ import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.grant.PermissionsManager; import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction; import com.anthonycr.grant.PermissionsResultAction;
import javax.inject.Inject;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.controller.UIController; import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.dialog.BrowserDialog;
import acr.browser.lightning.favicon.FaviconModel; import acr.browser.lightning.favicon.FaviconModel;
import acr.browser.lightning.utils.Preconditions; import acr.browser.lightning.utils.Preconditions;
class LightningChromeClient extends WebChromeClient { public class LightningChromeClient extends WebChromeClient {
private static final String TAG = LightningChromeClient.class.getSimpleName(); private static final String TAG = LightningChromeClient.class.getSimpleName();
@ -37,15 +40,15 @@ class LightningChromeClient extends WebChromeClient {
@NonNull private final Activity mActivity; @NonNull private final Activity mActivity;
@NonNull private final LightningView mLightningView; @NonNull private final LightningView mLightningView;
@NonNull private final UIController mUIController; @NonNull private final UIController mUIController;
@NonNull private final FaviconModel mFaviconModel; @Inject FaviconModel mFaviconModel;
LightningChromeClient(@NonNull Activity activity, @NonNull LightningView lightningView) { LightningChromeClient(@NonNull Activity activity, @NonNull LightningView lightningView) {
Preconditions.checkNonNull(activity); Preconditions.checkNonNull(activity);
Preconditions.checkNonNull(lightningView); Preconditions.checkNonNull(lightningView);
BrowserApp.getAppComponent().inject(this);
mActivity = activity; mActivity = activity;
mUIController = (UIController) activity; mUIController = (UIController) activity;
mLightningView = lightningView; mLightningView = lightningView;
mFaviconModel = new FaviconModel();
} }
@Override @Override

Loading…
Cancel
Save