Variable renaming, moving fields around, more injection, move ProxyUtils out of flavor specific code
This commit is contained in:
parent
cb52aa0065
commit
ac107d6704
@ -1,210 +0,0 @@
|
|||||||
package acr.browser.lightning.utils;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import net.i2p.android.ui.I2PAndroidHelper;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
|
||||||
import acr.browser.lightning.bus.BrowserEvents;
|
|
||||||
import acr.browser.lightning.constant.Constants;
|
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
|
||||||
import info.guardianproject.netcipher.proxy.OrbotHelper;
|
|
||||||
import info.guardianproject.netcipher.web.WebkitProxy;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public class ProxyUtils {
|
|
||||||
// Helper
|
|
||||||
private static boolean mI2PHelperBound;
|
|
||||||
private static boolean mI2PProxyInitialized;
|
|
||||||
|
|
||||||
@Inject PreferenceManager mPreferences;
|
|
||||||
@Inject I2PAndroidHelper mI2PHelper;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public ProxyUtils() {
|
|
||||||
BrowserApp.getAppComponent().inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If Orbot/Tor or I2P is installed, prompt the user if they want to enable
|
|
||||||
* proxying for this session
|
|
||||||
*/
|
|
||||||
public void checkForProxy(final Activity activity) {
|
|
||||||
boolean useProxy = mPreferences.getUseProxy();
|
|
||||||
|
|
||||||
final boolean orbotInstalled = OrbotHelper.isOrbotInstalled(activity);
|
|
||||||
boolean orbotChecked = mPreferences.getCheckedForTor();
|
|
||||||
boolean orbot = orbotInstalled && !orbotChecked;
|
|
||||||
|
|
||||||
boolean i2pInstalled = mI2PHelper.isI2PAndroidInstalled();
|
|
||||||
boolean i2pChecked = mPreferences.getCheckedForI2P();
|
|
||||||
boolean i2p = i2pInstalled && !i2pChecked;
|
|
||||||
|
|
||||||
// TODO Is the idea to show this per-session, or only once?
|
|
||||||
if (!useProxy && (orbot || i2p)) {
|
|
||||||
if (orbot) mPreferences.setCheckedForTor(true);
|
|
||||||
if (i2p) mPreferences.setCheckedForI2P(true);
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
||||||
|
|
||||||
if (orbotInstalled && i2pInstalled) {
|
|
||||||
String[] proxyChoices = activity.getResources().getStringArray(R.array.proxy_choices_array);
|
|
||||||
builder.setTitle(activity.getResources().getString(R.string.http_proxy))
|
|
||||||
.setSingleChoiceItems(proxyChoices, mPreferences.getProxyChoice(),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
mPreferences.setProxyChoice(which);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNeutralButton(activity.getResources().getString(R.string.action_ok),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
if (mPreferences.getUseProxy())
|
|
||||||
initializeProxy(activity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
switch (which) {
|
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
|
||||||
mPreferences.setProxyChoice(orbotInstalled ?
|
|
||||||
Constants.PROXY_ORBOT : Constants.PROXY_I2P);
|
|
||||||
initializeProxy(activity);
|
|
||||||
break;
|
|
||||||
case DialogInterface.BUTTON_NEGATIVE:
|
|
||||||
mPreferences.setProxyChoice(Constants.NO_PROXY);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
builder.setMessage(orbotInstalled ? R.string.use_tor_prompt : R.string.use_i2p_prompt)
|
|
||||||
.setPositiveButton(R.string.yes, dialogClickListener)
|
|
||||||
.setNegativeButton(R.string.no, dialogClickListener);
|
|
||||||
}
|
|
||||||
builder.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialize WebKit Proxying
|
|
||||||
*/
|
|
||||||
private void initializeProxy(Activity activity) {
|
|
||||||
String host;
|
|
||||||
int port;
|
|
||||||
|
|
||||||
switch (mPreferences.getProxyChoice()) {
|
|
||||||
case Constants.NO_PROXY:
|
|
||||||
// We shouldn't be here
|
|
||||||
return;
|
|
||||||
|
|
||||||
case Constants.PROXY_ORBOT:
|
|
||||||
if (!OrbotHelper.isOrbotRunning(activity))
|
|
||||||
OrbotHelper.requestStartTor(activity);
|
|
||||||
host = "localhost";
|
|
||||||
port = 8118;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Constants.PROXY_I2P:
|
|
||||||
mI2PProxyInitialized = true;
|
|
||||||
if (mI2PHelperBound && !mI2PHelper.isI2PAndroidRunning()) {
|
|
||||||
mI2PHelper.requestI2PAndroidStart(activity);
|
|
||||||
}
|
|
||||||
host = "localhost";
|
|
||||||
port = 4444;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
host = mPreferences.getProxyHost();
|
|
||||||
port = mPreferences.getProxyPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
WebkitProxy.setProxy(BrowserApp.class.getName(), activity.getApplicationContext(), null, host, port);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.d(Constants.TAG, "error enabling web proxying", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isProxyReady() {
|
|
||||||
if (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
|
|
||||||
if (!mI2PHelper.isI2PAndroidRunning()) {
|
|
||||||
BrowserApp.getBus()
|
|
||||||
.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_not_running));
|
|
||||||
return false;
|
|
||||||
} else if (!mI2PHelper.areTunnelsActive()) {
|
|
||||||
BrowserApp.getBus()
|
|
||||||
.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_tunnels_not_ready));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateProxySettings(Activity activity) {
|
|
||||||
if (mPreferences.getUseProxy()) {
|
|
||||||
initializeProxy(activity);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
WebkitProxy.resetProxy(BrowserApp.class.getName(), activity.getApplicationContext());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
mI2PProxyInitialized = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStop() {
|
|
||||||
mI2PHelper.unbind();
|
|
||||||
mI2PHelperBound = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStart(final Activity activity) {
|
|
||||||
if (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
|
|
||||||
// Try to bind to I2P Android
|
|
||||||
mI2PHelper.bind(new I2PAndroidHelper.Callback() {
|
|
||||||
@Override
|
|
||||||
public void onI2PAndroidBound() {
|
|
||||||
mI2PHelperBound = true;
|
|
||||||
if (mI2PProxyInitialized && !mI2PHelper.isI2PAndroidRunning())
|
|
||||||
mI2PHelper.requestI2PAndroidStart(activity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int setProxyChoice(int choice, Activity activity) {
|
|
||||||
switch (choice) {
|
|
||||||
case Constants.PROXY_ORBOT:
|
|
||||||
if (!OrbotHelper.isOrbotInstalled(activity)) {
|
|
||||||
choice = Constants.NO_PROXY;
|
|
||||||
Utils.showSnackbar(activity, R.string.install_orbot);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Constants.PROXY_I2P:
|
|
||||||
I2PAndroidHelper ih = new I2PAndroidHelper(BrowserApp.getContext());
|
|
||||||
if (!ih.isI2PAndroidInstalled()) {
|
|
||||||
choice = Constants.NO_PROXY;
|
|
||||||
ih.promptToInstall(activity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Constants.PROXY_MANUAL:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return choice;
|
|
||||||
}
|
|
||||||
}
|
|
@ -183,7 +183,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
// Event bus
|
// Event bus
|
||||||
@Inject Bus mEventBus;
|
@Inject Bus mEventBus;
|
||||||
|
|
||||||
@Inject LightningDialogBuilder bookmarksDialogBuilder;
|
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
||||||
|
|
||||||
@Inject TabsManager mTabsManager;
|
@Inject TabsManager mTabsManager;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import acr.browser.lightning.R;
|
|||||||
|
|
||||||
public class SettingsActivity extends ThemableSettingsActivity {
|
public class SettingsActivity extends ThemableSettingsActivity {
|
||||||
|
|
||||||
private static final List<String> fragments = new ArrayList<>();
|
private static final List<String> mFragments = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -44,19 +44,19 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onBuildHeaders(List<Header> target) {
|
public void onBuildHeaders(List<Header> target) {
|
||||||
loadHeadersFromResource(R.xml.preferences_headers, target);
|
loadHeadersFromResource(R.xml.preferences_headers, target);
|
||||||
fragments.clear();
|
mFragments.clear();
|
||||||
for (Header header : target) {
|
for (Header header : target) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
// Workaround for bug in the AppCompat support library
|
// Workaround for bug in the AppCompat support library
|
||||||
header.iconRes = R.drawable.empty;
|
header.iconRes = R.drawable.empty;
|
||||||
}
|
}
|
||||||
fragments.add(header.fragment);
|
mFragments.add(header.fragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isValidFragment(String fragmentName) {
|
protected boolean isValidFragment(String fragmentName) {
|
||||||
return fragments.contains(fragmentName);
|
return mFragments.contains(fragmentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,11 +34,8 @@ public class TabsManager {
|
|||||||
private final List<LightningView> mWebViewList = new ArrayList<>();
|
private final List<LightningView> mWebViewList = new ArrayList<>();
|
||||||
private LightningView mCurrentTab;
|
private LightningView mCurrentTab;
|
||||||
|
|
||||||
@Inject
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
PreferenceManager mPreferenceManager;
|
@Inject Bus mEventBus;
|
||||||
|
|
||||||
@Inject
|
|
||||||
Bus mEventBus;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TabsManager() {}
|
public TabsManager() {}
|
||||||
|
@ -14,34 +14,28 @@ import dagger.Provides;
|
|||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class AppModule {
|
public class AppModule {
|
||||||
private final BrowserApp app;
|
private final BrowserApp mApp;
|
||||||
private final Bus bus;
|
private final Bus mBus;
|
||||||
|
|
||||||
public AppModule(BrowserApp app) {
|
public AppModule(BrowserApp app) {
|
||||||
this.app = app;
|
this.mApp = app;
|
||||||
this.bus = new Bus();
|
this.mBus = new Bus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
public Context provideContext() {
|
public Context provideContext() {
|
||||||
return app.getApplicationContext();
|
return mApp.getApplicationContext();
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
public BookmarkManager provideBookmarkManager() {
|
|
||||||
return new BookmarkManager(app.getApplicationContext());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
public Bus provideBus() {
|
public Bus provideBus() {
|
||||||
return bus;
|
return mBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public I2PAndroidHelper provideI2PAndroidHelper() {
|
public I2PAndroidHelper provideI2PAndroidHelper() {
|
||||||
return new I2PAndroidHelper(app.getApplicationContext());
|
return new I2PAndroidHelper(mApp.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,22 +11,18 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
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 {
|
public class BrowserApp extends Application {
|
||||||
|
|
||||||
private static AppComponent appComponent;
|
private static AppComponent mAppComponent;
|
||||||
private static final Executor mIOThread = Executors.newSingleThreadExecutor();
|
private static final Executor mIOThread = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
@Inject Bus bus;
|
@Inject Bus mBus;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
|
mAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
|
||||||
appComponent.inject(this);
|
mAppComponent.inject(this);
|
||||||
LeakCanary.install(this);
|
LeakCanary.install(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +31,7 @@ public class BrowserApp extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static AppComponent getAppComponent() {
|
public static AppComponent getAppComponent() {
|
||||||
return appComponent;
|
return mAppComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Executor getIOThread() {
|
public static Executor getIOThread() {
|
||||||
@ -43,7 +39,7 @@ public class BrowserApp extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Bus getBus(Context context) {
|
public static Bus getBus(Context context) {
|
||||||
return get(context).bus;
|
return get(context).mBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
|
|||||||
|
|
||||||
private static final String TAG = ImageDownloadTask.class.getSimpleName();
|
private static final String TAG = ImageDownloadTask.class.getSimpleName();
|
||||||
private final File mCacheDir;
|
private final File mCacheDir;
|
||||||
private final WeakReference<ImageView> bmImage;
|
private final WeakReference<ImageView> mFaviconImage;
|
||||||
private final HistoryItem mWeb;
|
private final HistoryItem mWeb;
|
||||||
private final String mUrl;
|
private final String mUrl;
|
||||||
private final Bitmap mDefaultBitmap;
|
private final Bitmap mDefaultBitmap;
|
||||||
@ -37,7 +37,7 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
|
|||||||
// Set a tag on the ImageView so we know if the view
|
// Set a tag on the ImageView so we know if the view
|
||||||
// has gone out of scope and should not be used
|
// has gone out of scope and should not be used
|
||||||
bmImage.setTag(web.getUrl().hashCode());
|
bmImage.setTag(web.getUrl().hashCode());
|
||||||
this.bmImage = new WeakReference<>(bmImage);
|
this.mFaviconImage = new WeakReference<>(bmImage);
|
||||||
this.mWeb = web;
|
this.mWeb = web;
|
||||||
this.mUrl = web.getUrl();
|
this.mUrl = web.getUrl();
|
||||||
this.mDefaultBitmap = defaultBitmap;
|
this.mDefaultBitmap = defaultBitmap;
|
||||||
@ -135,7 +135,7 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
|
|||||||
super.onPostExecute(bitmap);
|
super.onPostExecute(bitmap);
|
||||||
AsyncExecutor.getInstance().notifyThreadFinish();
|
AsyncExecutor.getInstance().notifyThreadFinish();
|
||||||
final Bitmap fav = Utils.padFavicon(bitmap);
|
final Bitmap fav = Utils.padFavicon(bitmap);
|
||||||
ImageView view = bmImage.get();
|
ImageView view = mFaviconImage.get();
|
||||||
if (view != null && view.getTag().equals(mWeb.getUrl().hashCode())) {
|
if (view != null && view.getTag().equals(mWeb.getUrl().hashCode())) {
|
||||||
view.setImageBitmap(fav);
|
view.setImageBitmap(fav);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
@ -52,12 +53,12 @@ public class BookmarkManager {
|
|||||||
private final String DEFAULT_BOOKMARK_TITLE;
|
private final String DEFAULT_BOOKMARK_TITLE;
|
||||||
|
|
||||||
private Map<String, HistoryItem> mBookmarksMap;
|
private Map<String, HistoryItem> mBookmarksMap;
|
||||||
// private final List<HistoryItem> mBookmarkList = new ArrayList<>();
|
|
||||||
private String mCurrentFolder = "";
|
private String mCurrentFolder = "";
|
||||||
private final ExecutorService mExecutor;
|
private final ExecutorService mExecutor;
|
||||||
private boolean mReady = false;
|
private boolean mReady = false;
|
||||||
private final File mFilesDir;
|
private final File mFilesDir;
|
||||||
|
|
||||||
|
@Inject
|
||||||
public BookmarkManager(Context context) {
|
public BookmarkManager(Context context) {
|
||||||
mExecutor = Executors.newSingleThreadExecutor();
|
mExecutor = Executors.newSingleThreadExecutor();
|
||||||
mFilesDir = context.getFilesDir();
|
mFilesDir = context.getFilesDir();
|
||||||
|
@ -40,11 +40,8 @@ import acr.browser.lightning.utils.Utils;
|
|||||||
public class LightningDialogBuilder {
|
public class LightningDialogBuilder {
|
||||||
|
|
||||||
@Inject BookmarkManager mBookmarkManager;
|
@Inject BookmarkManager mBookmarkManager;
|
||||||
|
|
||||||
@Inject PreferenceManager mPreferenceManager;
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
|
|
||||||
@Inject HistoryDatabase mHistoryDatabase;
|
@Inject HistoryDatabase mHistoryDatabase;
|
||||||
|
|
||||||
@Inject Bus mEventBus;
|
@Inject Bus mEventBus;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -73,14 +73,9 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
private LightningViewAdapter mTabsAdapter;
|
private LightningViewAdapter mTabsAdapter;
|
||||||
private UIController mUiController;
|
private UIController mUiController;
|
||||||
|
|
||||||
@Inject
|
@Inject TabsManager tabsManager;
|
||||||
TabsManager tabsManager;
|
@Inject Bus mBus;
|
||||||
|
@Inject PreferenceManager mPreferences;
|
||||||
@Inject
|
|
||||||
Bus mBus;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
PreferenceManager mPreferences;
|
|
||||||
|
|
||||||
public TabsFragment() {
|
public TabsFragment() {
|
||||||
BrowserApp.getAppComponent().inject(this);
|
BrowserApp.getAppComponent().inject(this);
|
||||||
|
@ -9,8 +9,7 @@ import android.net.NetworkInfo;
|
|||||||
public class NetworkReceiver extends BroadcastReceiver {
|
public class NetworkReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {}
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isConnected(Context context) {
|
public static boolean isConnected(Context context) {
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
@ -14,11 +14,13 @@ import java.util.Locale;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
public class AdBlock {
|
public class AdBlock {
|
||||||
|
|
||||||
private static final String TAG = "AdBlock";
|
private static final String TAG = "AdBlock";
|
||||||
@ -34,18 +36,11 @@ public class AdBlock {
|
|||||||
private final Set<String> mBlockedDomainsList = new HashSet<>();
|
private final Set<String> mBlockedDomainsList = new HashSet<>();
|
||||||
private boolean mBlockAds;
|
private boolean mBlockAds;
|
||||||
private static final Locale mLocale = Locale.getDefault();
|
private static final Locale mLocale = Locale.getDefault();
|
||||||
private static AdBlock mInstance;
|
|
||||||
|
|
||||||
@Inject PreferenceManager mPreferenceManager;
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
|
|
||||||
public static AdBlock getInstance(Context context) {
|
@Inject
|
||||||
if (mInstance == null) {
|
public AdBlock(Context context) {
|
||||||
mInstance = new AdBlock(context);
|
|
||||||
}
|
|
||||||
return mInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AdBlock(Context context) {
|
|
||||||
BrowserApp.getAppComponent().inject(this);
|
BrowserApp.getAppComponent().inject(this);
|
||||||
if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) {
|
if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) {
|
||||||
loadHostsFile(context);
|
loadHostsFile(context);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package acr.browser.lightning.view;
|
package acr.browser.lightning.view;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -16,12 +17,12 @@ import acr.browser.lightning.utils.Utils;
|
|||||||
class IconCacheTask implements Runnable {
|
class IconCacheTask implements Runnable {
|
||||||
private final Uri uri;
|
private final Uri uri;
|
||||||
private final Bitmap icon;
|
private final Bitmap icon;
|
||||||
private final Context context;
|
private final Application app;
|
||||||
|
|
||||||
public IconCacheTask(final Uri uri, final Bitmap icon, final Context context) {
|
public IconCacheTask(final Uri uri, final Bitmap icon, final Application app) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.context = BrowserApp.get(context);
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,7 +31,7 @@ class IconCacheTask implements Runnable {
|
|||||||
Log.d(Constants.TAG, "Caching icon for " + uri.getHost());
|
Log.d(Constants.TAG, "Caching icon for " + uri.getHost());
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
try {
|
try {
|
||||||
File image = new File(context.getCacheDir(), hash + ".png");
|
File image = new File(app.getCacheDir(), hash + ".png");
|
||||||
fos = new FileOutputStream(image);
|
fos = new FileOutputStream(image);
|
||||||
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||||||
fos.flush();
|
fos.flush();
|
||||||
|
@ -80,7 +80,7 @@ class LightningChromeClient extends WebChromeClient {
|
|||||||
if (uri.getHost() == null) {
|
if (uri.getHost() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BrowserApp.getIOThread().execute(new IconCacheTask(uri, icon, context));
|
BrowserApp.getIOThread().execute(new IconCacheTask(uri, icon, BrowserApp.get(context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,10 +18,8 @@ class LightningViewTitle {
|
|||||||
|
|
||||||
private static Bitmap DEFAULT_ICON = null;
|
private static Bitmap DEFAULT_ICON = null;
|
||||||
|
|
||||||
@NonNull
|
@NonNull private Bitmap mFavicon;
|
||||||
private Bitmap mFavicon;
|
@NonNull private String mTitle;
|
||||||
@NonNull
|
|
||||||
private String mTitle;
|
|
||||||
|
|
||||||
public LightningViewTitle(@NonNull Context context, boolean darkTheme) {
|
public LightningViewTitle(@NonNull Context context, boolean darkTheme) {
|
||||||
if (DEFAULT_ICON == null) {
|
if (DEFAULT_ICON == null) {
|
||||||
|
@ -50,18 +50,17 @@ public class LightningWebClient extends WebViewClient {
|
|||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
private final LightningView mLightningView;
|
private final LightningView mLightningView;
|
||||||
private final UIController mUIController;
|
private final UIController mUIController;
|
||||||
private final AdBlock mAdBlock;
|
|
||||||
private final Bus mEventBus;
|
private final Bus mEventBus;
|
||||||
private final IntentUtils mIntentUtils;
|
private final IntentUtils mIntentUtils;
|
||||||
|
|
||||||
@Inject ProxyUtils mProxyUtils;
|
@Inject ProxyUtils mProxyUtils;
|
||||||
|
@Inject AdBlock mAdBlock;
|
||||||
|
|
||||||
LightningWebClient(Activity activity, LightningView lightningView) {
|
LightningWebClient(Activity activity, LightningView lightningView) {
|
||||||
BrowserApp.getAppComponent().inject(this);
|
BrowserApp.getAppComponent().inject(this);
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mUIController = (UIController) activity;
|
mUIController = (UIController) activity;
|
||||||
mLightningView = lightningView;
|
mLightningView = lightningView;
|
||||||
mAdBlock = AdBlock.getInstance(activity);
|
|
||||||
mAdBlock.updatePreference();
|
mAdBlock.updatePreference();
|
||||||
mEventBus = BrowserApp.getBus(activity);
|
mEventBus = BrowserApp.getBus(activity);
|
||||||
mIntentUtils = new IntentUtils(activity);
|
mIntentUtils = new IntentUtils(activity);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user