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; @@ -25,6 +25,7 @@ import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.search.SuggestionsAdapter;
import acr.browser.lightning.utils.AdBlock;
import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.view.LightningChromeClient;
import acr.browser.lightning.view.LightningView;
import acr.browser.lightning.view.LightningWebClient;
import dagger.Component;
@ -77,6 +78,8 @@ public interface AppComponent { @@ -77,6 +78,8 @@ public interface AppComponent {
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 { @@ -49,13 +49,13 @@ public class BrowserApp extends Application {
super.onCreate();
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
.detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
.detectAll()
.penaltyLog()
.build());
}
final Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
@ -95,12 +95,6 @@ public class BrowserApp extends Application { @@ -95,12 +95,6 @@ public class BrowserApp extends Application {
});
}
@NonNull
public static Application getApplication() {
Preconditions.checkNonNull(sApplication);
return sApplication;
}
@NonNull
public static BrowserApp get(@NonNull Context context) {
return (BrowserApp) context.getApplicationContext();

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

@ -17,6 +17,9 @@ import java.io.File; @@ -17,6 +17,9 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.inject.Inject;
import javax.inject.Singleton;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.utils.Utils;
@ -24,14 +27,18 @@ import acr.browser.lightning.utils.Utils; @@ -24,14 +27,18 @@ import acr.browser.lightning.utils.Utils;
* Reactive model that can fetch favicons
* from URLs and also cache them.
*/
@Singleton
public class 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();
mApplication = application;
}
@NonNull
@ -63,9 +70,7 @@ public class FaviconModel { @@ -63,9 +70,7 @@ public class FaviconModel {
return;
}
Application app = BrowserApp.getApplication();
File faviconCacheFile = createFaviconCacheFile(app, uri);
File faviconCacheFile = createFaviconCacheFile(mApplication, uri);
Bitmap favicon = null;
@ -117,13 +122,11 @@ public class FaviconModel { @@ -117,13 +122,11 @@ public class FaviconModel {
return;
}
Application app = BrowserApp.getApplication();
Log.d(TAG, "Caching icon for " + uri.getHost());
FileOutputStream fos = null;
try {
File image = createFaviconCacheFile(app, uri);
File image = createFaviconCacheFile(mApplication, uri);
fos = new FileOutputStream(image);
favicon.compress(Bitmap.CompressFormat.PNG, 100, fos);
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, @@ -88,7 +88,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
@Inject PreferenceManager mPreferenceManager;
private FaviconModel mFaviconModel;
@Inject FaviconModel mFaviconModel;
private TabsManager mTabsManager;
@ -148,8 +148,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -148,8 +148,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :
ThemeUtils.getIconLightThemeColor(context);
mFaviconModel = new FaviconModel();
}
private TabsManager getTabsManager() {
@ -269,8 +267,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -269,8 +267,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
ThemeUtils.getIconLightThemeColor(activity);
mFaviconModel = new FaviconModel();
}
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; @@ -22,13 +22,16 @@ import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction;
import javax.inject.Inject;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.dialog.BrowserDialog;
import acr.browser.lightning.favicon.FaviconModel;
import acr.browser.lightning.utils.Preconditions;
class LightningChromeClient extends WebChromeClient {
public class LightningChromeClient extends WebChromeClient {
private static final String TAG = LightningChromeClient.class.getSimpleName();
@ -37,15 +40,15 @@ class LightningChromeClient extends WebChromeClient { @@ -37,15 +40,15 @@ class LightningChromeClient extends WebChromeClient {
@NonNull private final Activity mActivity;
@NonNull private final LightningView mLightningView;
@NonNull private final UIController mUIController;
@NonNull private final FaviconModel mFaviconModel;
@Inject FaviconModel mFaviconModel;
LightningChromeClient(@NonNull Activity activity, @NonNull LightningView lightningView) {
Preconditions.checkNonNull(activity);
Preconditions.checkNonNull(lightningView);
BrowserApp.getAppComponent().inject(this);
mActivity = activity;
mUIController = (UIController) activity;
mLightningView = lightningView;
mFaviconModel = new FaviconModel();
}
@Override

Loading…
Cancel
Save