Browse Source

Mirror AppComponent getters in BrowserApp so that classes are less reliant on AppComponent, refactored getAppContext to getContext

master
Anthony Restaino 9 years ago
parent
commit
057b4296d7
  1. 4
      app/src/LightningLite/java/acr/browser/lightning/utils/ProxyUtils.java
  2. 10
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  3. 4
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  4. 2
      app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java
  5. 4
      app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java
  6. 34
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  7. 2
      app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java
  8. 10
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  9. 8
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java
  10. 4
      app/src/main/java/acr/browser/lightning/constant/StartPage.java
  11. 4
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  12. 2
      app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java
  13. 3
      app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
  14. 6
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java
  15. 4
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java
  16. 2
      app/src/main/java/acr/browser/lightning/utils/WebUtils.java
  17. 2
      app/src/main/java/acr/browser/lightning/view/IconCacheTask.java
  18. 4
      app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java
  19. 2
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  20. 2
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

4
app/src/LightningLite/java/acr/browser/lightning/utils/ProxyUtils.java

@ -32,8 +32,8 @@ public class ProxyUtils { @@ -32,8 +32,8 @@ public class ProxyUtils {
private final Bus mEventBus;
private ProxyUtils(Context context) {
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mEventBus = BrowserApp.getAppComponent().getBus();
mPreferences = BrowserApp.getPreferenceManager();
mEventBus = BrowserApp.getBus();
mI2PHelper = new I2PAndroidHelper(context.getApplicationContext());
}

10
app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java

@ -28,13 +28,13 @@ public class ProxyUtils { @@ -28,13 +28,13 @@ public class ProxyUtils {
private static ProxyUtils mInstance;
private ProxyUtils(Context context) {
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mPreferences = BrowserApp.getPreferenceManager();
mI2PHelper = new I2PAndroidHelper(context.getApplicationContext());
}
public static ProxyUtils getInstance() {
if (mInstance == null) {
mInstance = new ProxyUtils(BrowserApp.getAppContext());
mInstance = new ProxyUtils(BrowserApp.getContext());
}
return mInstance;
}
@ -147,11 +147,11 @@ public class ProxyUtils { @@ -147,11 +147,11 @@ public class ProxyUtils {
public boolean isProxyReady() {
if (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
if (!mI2PHelper.isI2PAndroidRunning()) {
BrowserApp.getAppComponent().getBus()
BrowserApp.getBus()
.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_not_running));
return false;
} else if (!mI2PHelper.areTunnelsActive()) {
BrowserApp.getAppComponent().getBus()
BrowserApp.getBus()
.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_tunnels_not_ready));
return false;
}
@ -203,7 +203,7 @@ public class ProxyUtils { @@ -203,7 +203,7 @@ public class ProxyUtils {
break;
case Constants.PROXY_I2P:
I2PAndroidHelper ih = new I2PAndroidHelper(BrowserApp.getAppContext());
I2PAndroidHelper ih = new I2PAndroidHelper(BrowserApp.getContext());
if (!ih.isI2PAndroidInstalled()) {
choice = Constants.NO_PROXY;
ih.promptToInstall(activity);

4
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -1342,7 +1342,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1342,7 +1342,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
if (UrlUtils.isSpecialUrl(url)) {
return;
}
BrowserApp.getAppComponent().getHistoryDatabase().getIOThread().execute(new Runnable() {
BrowserApp.getHistoryDatabase().getIOThread().execute(new Runnable() {
@Override
public void run() {
try {
@ -1406,7 +1406,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1406,7 +1406,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
*/
private void openHistory() {
// use a thread so that history retrieval doesn't block the UI
BrowserApp.getAppComponent().getHistoryDatabase().getIOThread().execute(new Runnable() {
BrowserApp.getHistoryDatabase().getIOThread().execute(new Runnable() {
@Override
public void run() {

2
app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java

@ -53,7 +53,7 @@ public class ReadingActivity extends AppCompatActivity { @@ -53,7 +53,7 @@ public class ReadingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
overridePendingTransition(R.anim.slide_in_from_right, R.anim.fade_out_scale);
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
mPreferences = BrowserApp.getPreferenceManager();
mInvert = mPreferences.getInvertColors();
final int color;
if (mInvert) {

4
app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java

@ -13,7 +13,7 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi @@ -13,7 +13,7 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi
@Override
protected void onCreate(Bundle savedInstanceState) {
mTheme = BrowserApp.getAppComponent().getPreferenceManager().getUseTheme();
mTheme = BrowserApp.getPreferenceManager().getUseTheme();
// set the theme
if (mTheme == 0) {
@ -32,7 +32,7 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi @@ -32,7 +32,7 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi
@Override
protected void onResume() {
super.onResume();
if (BrowserApp.getAppComponent().getPreferenceManager().getUseTheme() != mTheme) {
if (BrowserApp.getPreferenceManager().getUseTheme() != mTheme) {
restart();
}
}

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

@ -4,27 +4,27 @@ import android.app.Application; @@ -4,27 +4,27 @@ import android.app.Application;
import android.content.Context;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.otto.Bus;
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 Context sContext;
private static BrowserApp sInstance;
private static AppComponent appComponent;
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
LeakCanary.install(this);
buildDepencyGraph();
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
sContext = base;
}
public static Context getAppContext() {
return sContext;
public static BrowserApp getContext() {
return sInstance;
}
public static AppComponent getAppComponent() {
@ -35,4 +35,20 @@ public class BrowserApp extends Application { @@ -35,4 +35,20 @@ public class BrowserApp extends Application {
appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
}
public static HistoryDatabase getHistoryDatabase() {
return appComponent.getHistoryDatabase();
}
public static PreferenceManager getPreferenceManager() {
return appComponent.getPreferenceManager();
}
public static Bus getBus() {
return appComponent.getBus();
}
public static BookmarkPage getBookmarkPage() {
return appComponent.getBookmarkPage();
}
}

2
app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java

@ -23,7 +23,7 @@ import acr.browser.lightning.utils.Utils; @@ -23,7 +23,7 @@ import acr.browser.lightning.utils.Utils;
public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
private static final String TAG = ImageDownloadTask.class.getSimpleName();
private static final File mCacheDir = BrowserApp.getAppContext().getCacheDir();
private static final File mCacheDir = BrowserApp.getContext().getCacheDir();
private final WeakReference<ImageView> bmImage;
private final HistoryItem mWeb;
private final String mUrl;

10
app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java

@ -3,8 +3,6 @@ @@ -3,8 +3,6 @@
*/
package acr.browser.lightning.constant;
import android.content.Context;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@ -31,7 +29,7 @@ public final class BookmarkPage { @@ -31,7 +29,7 @@ public final class BookmarkPage {
"<meta content='text/html; charset=utf-8' http-equiv=Content-Type />\n" +
"<meta name=viewport content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'>\n" +
"<title>" +
BrowserApp.getAppContext().getString(R.string.action_bookmarks) +
BrowserApp.getContext().getString(R.string.action_bookmarks) +
"</title>\n" +
"</head>\n" +
"<style>body{background:#e1e1e1;max-width:100%;min-height:100%}#content{width:100%;max-width:800px;margin:0 auto;text-align:center}.box{vertical-align:middle;text-align:center;position:relative;display:inline-block;height:45px;width:150px;margin:10px;background-color:#fff;box-shadow:0 3px 6px rgba(0,0,0,0.25);font-family:Arial;color:#444;font-size:12px;-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px}.box-content{height:25px;width:100%;vertical-align:middle;text-align:center;display:table-cell}p.ellipses{" +
@ -61,10 +59,10 @@ public final class BookmarkPage { @@ -61,10 +59,10 @@ public final class BookmarkPage {
private final File CACHE_DIR;
@Inject
public BookmarkPage(Context context) {
public BookmarkPage() {
BrowserApp.getAppComponent().inject(this);
FILES_DIR = context.getFilesDir();
CACHE_DIR = context.getCacheDir();
FILES_DIR = BrowserApp.getContext().getFilesDir();
CACHE_DIR = BrowserApp.getContext().getCacheDir();
}
public void buildBookmarkPage(final String folder) {

8
app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

@ -22,7 +22,7 @@ public class HistoryPage { @@ -22,7 +22,7 @@ public class HistoryPage {
public static final String FILENAME = "history.html";
private static final String HEADING = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"><title>"
+ BrowserApp.getAppContext().getString(R.string.action_history)
+ BrowserApp.getContext().getString(R.string.action_history)
+ "</title></head><style>body { background: #e1e1e1;}.box { vertical-align:middle;position:relative; display: block; margin: 10px;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:5px; background-color:#fff;box-shadow: 0px 2px 3px rgba( 0, 0, 0, 0.25 );font-family: Arial;color: #444;font-size: 12px;-moz-border-radius: 2px;-webkit-border-radius: 2px;border-radius: 2px;}.box a { width: 100%; height: 100%; position: absolute; left: 0; top: 0;}.black {color: black;font-size: 15px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}.font {color: gray;font-size: 10px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}</style><body><div id=\"content\">";
private static final String PART1 = "<div class=\"box\"><a href=\"";
@ -37,7 +37,7 @@ public class HistoryPage { @@ -37,7 +37,7 @@ public class HistoryPage {
public static String getHistoryPage(Context context) {
StringBuilder historyBuilder = new StringBuilder(HistoryPage.HEADING);
List<HistoryItem> historyList = getWebHistory(context);
List<HistoryItem> historyList = getWebHistory();
Iterator<HistoryItem> it = historyList.iterator();
HistoryItem helper;
while (it.hasNext()) {
@ -65,8 +65,8 @@ public class HistoryPage { @@ -65,8 +65,8 @@ public class HistoryPage {
return Constants.FILE + historyWebPage;
}
private static List<HistoryItem> getWebHistory(Context context) {
HistoryDatabase databaseHandler = BrowserApp.getAppComponent().getHistoryDatabase();
private static List<HistoryItem> getWebHistory() {
HistoryDatabase databaseHandler = BrowserApp.getHistoryDatabase();
return databaseHandler.getLastHundredItems();
}
}

4
app/src/main/java/acr/browser/lightning/constant/StartPage.java

@ -24,7 +24,7 @@ public class StartPage { @@ -24,7 +24,7 @@ public class StartPage {
+ "<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">"
+ "<title>"
+ BrowserApp.getAppContext().getString(R.string.home)
+ BrowserApp.getContext().getString(R.string.home)
+ "</title>"
+ "</head>"
+ "<style>body{background:#f2f2f2;text-align:center;margin:0px;}#search_input{height:35px; "
@ -57,7 +57,7 @@ public class StartPage { @@ -57,7 +57,7 @@ public class StartPage {
StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD);
String icon;
String searchUrl;
final PreferenceManager preferenceManager = BrowserApp.getAppComponent().getPreferenceManager();
final PreferenceManager preferenceManager = BrowserApp.getPreferenceManager();
switch (preferenceManager.getSearchChoice()) {
case 0:
// CUSTOM SEARCH

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

@ -186,7 +186,7 @@ public class DownloadHandler { @@ -186,7 +186,7 @@ public class DownloadHandler {
// or, should it be set to one of several Environment.DIRECTORY* dirs
// depending on mimetype?
String location = BrowserApp.getAppComponent().getPreferenceManager().getDownloadDirectory();
String location = BrowserApp.getPreferenceManager().getDownloadDirectory();
Uri downloadFolder;
if (location != null) {
location = addNecessarySlashes(location);
@ -194,7 +194,7 @@ public class DownloadHandler { @@ -194,7 +194,7 @@ public class DownloadHandler {
} else {
location = addNecessarySlashes(DEFAULT_DOWNLOAD_PATH);
downloadFolder = Uri.parse(location);
BrowserApp.getAppComponent().getPreferenceManager().setDownloadDirectory(location);
BrowserApp.getPreferenceManager().setDownloadDirectory(location);
}
File dir = new File(downloadFolder.getPath());

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

@ -54,7 +54,7 @@ class FetchUrlMimeType extends Thread { @@ -54,7 +54,7 @@ class FetchUrlMimeType extends Thread {
public void run() {
// User agent is likely to be null, though the AndroidHttpClient
// seems ok with that.
final Bus eventBus = BrowserApp.getAppComponent().getBus();
final Bus eventBus = BrowserApp.getBus();
String mimeType = null;
String contentDisposition = null;
HttpURLConnection connection = null;

3
app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java

@ -149,8 +149,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme @@ -149,8 +149,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
BrowserApp.getAppComponent()
.getHistoryDatabase()
BrowserApp.getHistoryDatabase()
.getIOThread()
.execute(new Runnable() {
@Override

6
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

@ -106,7 +106,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -106,7 +106,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
}
private static void deleteOldCacheFiles() {
File dir = new File(BrowserApp.getAppContext().getCacheDir().toString());
File dir = new File(BrowserApp.getContext().getCacheDir().toString());
String[] fileList = dir.list(new NameFilter());
long earliestTimeAllowed = System.currentTimeMillis() - INTERVAL_DAY;
for (String fileName : fileList) {
@ -373,11 +373,11 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -373,11 +373,11 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
* @return the cache file containing the suggestions
*/
private static File downloadSuggestionsForQuery(String query, String language) {
File cacheFile = new File(BrowserApp.getAppContext().getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
File cacheFile = new File(BrowserApp.getContext().getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
return cacheFile;
}
if (!isNetworkConnected(BrowserApp.getAppContext())) {
if (!isNetworkConnected(BrowserApp.getContext())) {
return cacheFile;
}
InputStream in = null;

4
app/src/main/java/acr/browser/lightning/utils/AdBlock.java

@ -44,11 +44,11 @@ public class AdBlock { @@ -44,11 +44,11 @@ public class AdBlock {
if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) {
loadHostsFile(context);
}
mBlockAds = BrowserApp.getAppComponent().getPreferenceManager().getAdBlockEnabled();
mBlockAds = BrowserApp.getPreferenceManager().getAdBlockEnabled();
}
public void updatePreference() {
mBlockAds = BrowserApp.getAppComponent().getPreferenceManager().getAdBlockEnabled();
mBlockAds = BrowserApp.getPreferenceManager().getAdBlockEnabled();
}
private void loadBlockedDomainsList(final Context context) {

2
app/src/main/java/acr/browser/lightning/utils/WebUtils.java

@ -34,7 +34,7 @@ public class WebUtils { @@ -34,7 +34,7 @@ public class WebUtils {
}
public static void clearHistory(@NonNull Context context) {
BrowserApp.getAppComponent().getHistoryDatabase().deleteHistory();
BrowserApp.getHistoryDatabase().deleteHistory();
WebViewDatabase m = WebViewDatabase.getInstance(context);
m.clearFormData();
m.clearHttpAuthUsernamePassword();

2
app/src/main/java/acr/browser/lightning/view/IconCacheTask.java

@ -31,7 +31,7 @@ class IconCacheTask implements Runnable{ @@ -31,7 +31,7 @@ class IconCacheTask implements Runnable{
Log.d(Constants.TAG, "Caching icon for " + uri.getHost());
FileOutputStream fos = null;
try {
File image = new File(BrowserApp.getAppContext().getCacheDir(), hash + ".png");
File image = new File(BrowserApp.getContext().getCacheDir(), hash + ".png");
fos = new FileOutputStream(image);
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();

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

@ -49,7 +49,7 @@ class LightningChromeClient extends WebChromeClient { @@ -49,7 +49,7 @@ class LightningChromeClient extends WebChromeClient {
mActivity = activity;
mUIController = (UIController) activity;
mLightningView = lightningView;
eventBus = BrowserApp.getAppComponent().getBus();
eventBus = BrowserApp.getBus();
}
@Override
@ -84,7 +84,7 @@ class LightningChromeClient extends WebChromeClient { @@ -84,7 +84,7 @@ class LightningChromeClient extends WebChromeClient {
Log.d(Constants.TAG, "Caching icon for " + uri.getHost());
FileOutputStream fos = null;
try {
File image = new File(BrowserApp.getAppContext().getCacheDir(), hash + ".png");
File image = new File(BrowserApp.getContext().getCacheDir(), hash + ".png");
fos = new FileOutputStream(image);
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();

2
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -176,7 +176,7 @@ public class LightningView { @@ -176,7 +176,7 @@ public class LightningView {
}
File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
BrowserApp.getAppComponent().getBookmarkPage().buildBookmarkPage(null);
BrowserApp.getBookmarkPage().buildBookmarkPage(null);
mWebView.loadUrl(Constants.FILE + bookmarkWebPage, mRequestHeaders);
}

2
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -58,7 +58,7 @@ class LightningWebClient extends WebViewClient { @@ -58,7 +58,7 @@ class LightningWebClient extends WebViewClient {
mLightningView = lightningView;
mAdBlock = AdBlock.getInstance(activity);
mAdBlock.updatePreference();
mEventBus = BrowserApp.getAppComponent().getBus();
mEventBus = BrowserApp.getBus();
mIntentUtils = new IntentUtils(activity);
}

Loading…
Cancel
Save