diff --git a/app/src/LightningLite/java/acr/browser/lightning/utils/ProxyUtils.java b/app/src/LightningLite/java/acr/browser/lightning/utils/ProxyUtils.java index ed8211b..c81d61c 100644 --- a/app/src/LightningLite/java/acr/browser/lightning/utils/ProxyUtils.java +++ b/app/src/LightningLite/java/acr/browser/lightning/utils/ProxyUtils.java @@ -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()); } diff --git a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java index f450692..84236f0 100644 --- a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java +++ b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java @@ -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 { 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 { 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); diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index efcc473..01e9f8e 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -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 */ 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() { diff --git a/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java b/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java index d2733f5..1b0c41b 100644 --- a/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java @@ -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) { diff --git a/app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java b/app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java index 50abecb..75f0300 100644 --- a/app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java @@ -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 @Override protected void onResume() { super.onResume(); - if (BrowserApp.getAppComponent().getPreferenceManager().getUseTheme() != mTheme) { + if (BrowserApp.getPreferenceManager().getUseTheme() != mTheme) { restart(); } } diff --git a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java b/app/src/main/java/acr/browser/lightning/app/BrowserApp.java index 61be9df..5286d95 100644 --- a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java +++ b/app/src/main/java/acr/browser/lightning/app/BrowserApp.java @@ -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 { 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(); + } + } diff --git a/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java b/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java index e4da77e..cfe61d0 100644 --- a/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java +++ b/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java @@ -23,7 +23,7 @@ import acr.browser.lightning.utils.Utils; public class ImageDownloadTask extends AsyncTask { 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 bmImage; private final HistoryItem mWeb; private final String mUrl; diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index f1f2203..e3bbda2 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -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 { "\n" + "\n" + "" + - BrowserApp.getAppContext().getString(R.string.action_bookmarks) + + BrowserApp.getContext().getString(R.string.action_bookmarks) + "\n" + "\n" + "
"; private static final String PART1 = "
historyList = getWebHistory(context); + List historyList = getWebHistory(); Iterator it = historyList.iterator(); HistoryItem helper; while (it.hasNext()) { @@ -65,8 +65,8 @@ public class HistoryPage { return Constants.FILE + historyWebPage; } - private static List getWebHistory(Context context) { - HistoryDatabase databaseHandler = BrowserApp.getAppComponent().getHistoryDatabase(); + private static List getWebHistory() { + HistoryDatabase databaseHandler = BrowserApp.getHistoryDatabase(); return databaseHandler.getLastHundredItems(); } } diff --git a/app/src/main/java/acr/browser/lightning/constant/StartPage.java b/app/src/main/java/acr/browser/lightning/constant/StartPage.java index b13d426..51bef32 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/StartPage.java @@ -24,7 +24,7 @@ public class StartPage { + "" + "" + "" - + BrowserApp.getAppContext().getString(R.string.home) + + BrowserApp.getContext().getString(R.string.home) + "" + "" + "