Trying to remove BrowserController interface
This commit is contained in:
parent
2563e81f7a
commit
030b839aa6
@ -11,6 +11,7 @@ import net.i2p.android.ui.I2PAndroidHelper;
|
|||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
|
import acr.browser.lightning.bus.BrowserEvents;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import info.guardianproject.netcipher.proxy.OrbotHelper;
|
import info.guardianproject.netcipher.proxy.OrbotHelper;
|
||||||
@ -144,13 +145,15 @@ public class ProxyUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProxyReady(Activity activity) {
|
public boolean isProxyReady() {
|
||||||
if (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
|
if (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
|
||||||
if (!mI2PHelper.isI2PAndroidRunning()) {
|
if (!mI2PHelper.isI2PAndroidRunning()) {
|
||||||
Utils.showSnackbar(activity, R.string.i2p_not_running);
|
BrowserApp.getAppComponent().getBus()
|
||||||
|
.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_not_running));
|
||||||
return false;
|
return false;
|
||||||
} else if (!mI2PHelper.areTunnelsActive()) {
|
} else if (!mI2PHelper.areTunnelsActive()) {
|
||||||
Utils.showSnackbar(activity, R.string.i2p_tunnels_not_ready);
|
BrowserApp.getAppComponent().getBus()
|
||||||
|
.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_tunnels_not_ready));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +204,7 @@ public class ProxyUtils {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Constants.PROXY_I2P:
|
case Constants.PROXY_I2P:
|
||||||
I2PAndroidHelper ih = new I2PAndroidHelper(activity.getApplicationContext());
|
I2PAndroidHelper ih = new I2PAndroidHelper(BrowserApp.getAppContext());
|
||||||
if (!ih.isI2PAndroidInstalled()) {
|
if (!ih.isI2PAndroidInstalled()) {
|
||||||
choice = Constants.NO_PROXY;
|
choice = Constants.NO_PROXY;
|
||||||
ih.promptToInstall(activity);
|
ih.promptToInstall(activity);
|
||||||
|
@ -38,6 +38,7 @@ import android.provider.MediaStore;
|
|||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.view.GravityCompat;
|
import android.support.v4.view.GravityCompat;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
@ -1012,7 +1013,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (show) {
|
if (show) {
|
||||||
showTab(tabsManager.size() - 1);
|
showTab(tabsManager.size() - 1);
|
||||||
}
|
}
|
||||||
updateTabs();
|
// TODO Check is this is callable directly from LightningView
|
||||||
|
eventBus.post(new BrowserEvents.TabsChanged());
|
||||||
|
|
||||||
// TODO Restore this
|
// TODO Restore this
|
||||||
// new Handler().postDelayed(new Runnable() {
|
// new Handler().postDelayed(new Runnable() {
|
||||||
@ -1048,14 +1050,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (current > position) {
|
if (current > position) {
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
showTab(current - 1);
|
showTab(current - 1);
|
||||||
updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged());
|
||||||
tabToDelete.onDestroy();
|
tabToDelete.onDestroy();
|
||||||
} else if (tabsManager.size() > position + 1) {
|
} else if (tabsManager.size() > position + 1) {
|
||||||
if (current == position) {
|
if (current == position) {
|
||||||
showTab(position + 1);
|
showTab(position + 1);
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
showTab(position);
|
showTab(position);
|
||||||
updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged());
|
||||||
} else {
|
} else {
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
}
|
}
|
||||||
@ -1066,7 +1068,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
showTab(position - 1);
|
showTab(position - 1);
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
showTab(position - 1);
|
showTab(position - 1);
|
||||||
updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged());
|
||||||
} else {
|
} else {
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
}
|
}
|
||||||
@ -1424,11 +1426,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
getUrl.setAdapter(mSearchAdapter);
|
getUrl.setAdapter(mSearchAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean proxyIsNotReady() {
|
|
||||||
return !mProxyUtils.isProxyReady(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function that opens the HTML history page in the browser
|
* function that opens the HTML history page in the browser
|
||||||
*/
|
*/
|
||||||
@ -1471,11 +1468,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateTabs() {
|
|
||||||
eventBus.post(new BrowserEvents.TabsChanged());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* opens a file chooser
|
* opens a file chooser
|
||||||
* param ValueCallback is the message from the WebView indicating a file chooser
|
* param ValueCallback is the message from the WebView indicating a file chooser
|
||||||
@ -2326,9 +2318,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
String url = mPreferences.getSavedUrl();
|
String url = mPreferences.getSavedUrl();
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
BrowserActivity.this.newTab(url, true);
|
BrowserActivity.this.newTab(url, true);
|
||||||
|
|
||||||
Utils.showSnackbar(mActivity, R.string.deleted_tab);
|
Utils.showSnackbar(mActivity, R.string.deleted_tab);
|
||||||
}
|
}
|
||||||
mPreferences.setSavedUrl(null);
|
mPreferences.setSavedUrl(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void displayInSnackbar(final BrowserEvents.ShowSnackBarMessage event) {
|
||||||
|
if (event.message != null) {
|
||||||
|
Utils.showSnackbar(BrowserActivity.this, event.message);
|
||||||
|
} else {
|
||||||
|
Utils.showSnackbar(mActivity, event.stringRes); }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public class TabsManager {
|
|||||||
final String url, final boolean darkTheme,
|
final String url, final boolean darkTheme,
|
||||||
final boolean isIncognito,
|
final boolean isIncognito,
|
||||||
final BrowserController controller) {
|
final BrowserController controller) {
|
||||||
final LightningView tab = new LightningView(activity, url, darkTheme, isIncognito, controller);
|
final LightningView tab = new LightningView(activity, url, darkTheme, isIncognito);
|
||||||
mWebViewList.add(tab);
|
mWebViewList.add(tab);
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package acr.browser.lightning.app;
|
package acr.browser.lightning.app;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.squareup.otto.Bus;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import acr.browser.lightning.activity.BrowserActivity;
|
import acr.browser.lightning.activity.BrowserActivity;
|
||||||
@ -39,4 +43,8 @@ public interface AppComponent {
|
|||||||
void inject(LightningPreferenceFragment fragment);
|
void inject(LightningPreferenceFragment fragment);
|
||||||
|
|
||||||
BookmarkPage getBookmarkPage();
|
BookmarkPage getBookmarkPage();
|
||||||
|
|
||||||
|
Bus getBus();
|
||||||
|
|
||||||
|
Context getApplicationContext();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package acr.browser.lightning.bus;
|
package acr.browser.lightning.bus;
|
||||||
|
|
||||||
|
import android.support.annotation.IdRes;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
|
import acr.browser.lightning.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stefano Pacifici on 26/08/15.
|
* Created by Stefano Pacifici on 26/08/15.
|
||||||
*/
|
*/
|
||||||
@ -46,4 +51,23 @@ public final class BrowserEvents {
|
|||||||
*/
|
*/
|
||||||
public static class TabsChanged {
|
public static class TabsChanged {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify the Browser to display a SnackBar in the main activity
|
||||||
|
*/
|
||||||
|
public static class ShowSnackBarMessage {
|
||||||
|
public final String message;
|
||||||
|
@StringRes
|
||||||
|
public final int stringRes;
|
||||||
|
|
||||||
|
public ShowSnackBarMessage(final String message) {
|
||||||
|
this.message = message;
|
||||||
|
this.stringRes = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShowSnackBarMessage(@StringRes final int stringRes) {
|
||||||
|
this.message = null;
|
||||||
|
this.stringRes = stringRes;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@ public interface BrowserController {
|
|||||||
|
|
||||||
void openFileChooser(ValueCallback<Uri> uploadMsg);
|
void openFileChooser(ValueCallback<Uri> uploadMsg);
|
||||||
|
|
||||||
void updateTabs();
|
|
||||||
|
|
||||||
void onLongPress();
|
void onLongPress();
|
||||||
|
|
||||||
void onShowCustomView(View view, CustomViewCallback callback);
|
void onShowCustomView(View view, CustomViewCallback callback);
|
||||||
@ -52,8 +50,6 @@ public interface BrowserController {
|
|||||||
|
|
||||||
void closeEmptyTab();
|
void closeEmptyTab();
|
||||||
|
|
||||||
boolean proxyIsNotReady();
|
|
||||||
|
|
||||||
// void updateBookmarkIndicator(String url);
|
// void updateBookmarkIndicator(String url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ import android.webkit.WebViewClient;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import com.squareup.otto.Bus;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -60,6 +62,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
|
import acr.browser.lightning.bus.BrowserEvents;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.constant.StartPage;
|
import acr.browser.lightning.constant.StartPage;
|
||||||
import acr.browser.lightning.controller.BrowserController;
|
import acr.browser.lightning.controller.BrowserController;
|
||||||
@ -68,6 +71,7 @@ import acr.browser.lightning.preference.PreferenceManager;
|
|||||||
import acr.browser.lightning.utils.AdBlock;
|
import acr.browser.lightning.utils.AdBlock;
|
||||||
import acr.browser.lightning.utils.IntentUtils;
|
import acr.browser.lightning.utils.IntentUtils;
|
||||||
import acr.browser.lightning.utils.PermissionsManager;
|
import acr.browser.lightning.utils.PermissionsManager;
|
||||||
|
import acr.browser.lightning.utils.ProxyUtils;
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
|
||||||
@ -103,8 +107,11 @@ public class LightningView {
|
|||||||
private final PermissionsManager mPermissionsManager;
|
private final PermissionsManager mPermissionsManager;
|
||||||
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
|
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
|
||||||
|
|
||||||
|
private final Bus eventBus;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito) {
|
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito) {
|
||||||
|
eventBus = BrowserApp.getAppComponent().getBus();
|
||||||
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
|
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mWebView = new WebView(activity);
|
mWebView = new WebView(activity);
|
||||||
@ -419,7 +426,7 @@ public class LightningView {
|
|||||||
|
|
||||||
public void setForegroundTab(boolean isForeground) {
|
public void setForegroundTab(boolean isForeground) {
|
||||||
isForegroundTab = isForeground;
|
isForegroundTab = isForeground;
|
||||||
mBrowserController.updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isForegroundTab() {
|
public boolean isForegroundTab() {
|
||||||
@ -522,7 +529,7 @@ public class LightningView {
|
|||||||
|
|
||||||
public synchronized void reload() {
|
public synchronized void reload() {
|
||||||
// Check if configured proxy is available
|
// Check if configured proxy is available
|
||||||
if (mBrowserController.proxyIsNotReady()) {
|
if (!ProxyUtils.getInstance().isProxyReady()) {
|
||||||
// User has been notified
|
// User has been notified
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -625,8 +632,7 @@ public class LightningView {
|
|||||||
|
|
||||||
public synchronized void loadUrl(String url) {
|
public synchronized void loadUrl(String url) {
|
||||||
// Check if configured proxy is available
|
// Check if configured proxy is available
|
||||||
if (mBrowserController.proxyIsNotReady()) {
|
if (!ProxyUtils.getInstance().isProxyReady()) {
|
||||||
// User has been notified
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -697,7 +703,7 @@ public class LightningView {
|
|||||||
if (API >= android.os.Build.VERSION_CODES.KITKAT && mInvertPage) {
|
if (API >= android.os.Build.VERSION_CODES.KITKAT && mInvertPage) {
|
||||||
view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null);
|
view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null);
|
||||||
}
|
}
|
||||||
mBrowserController.updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -707,7 +713,7 @@ public class LightningView {
|
|||||||
mBrowserController.showActionBar();
|
mBrowserController.showActionBar();
|
||||||
}
|
}
|
||||||
mTitle.setFavicon(mWebpageBitmap);
|
mTitle.setFavicon(mWebpageBitmap);
|
||||||
mBrowserController.updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -839,7 +845,7 @@ public class LightningView {
|
|||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
// Check if configured proxy is available
|
// Check if configured proxy is available
|
||||||
if (mBrowserController.proxyIsNotReady()) {
|
if (!ProxyUtils.getInstance().isProxyReady()) {
|
||||||
// User has been notified
|
// User has been notified
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -897,7 +903,7 @@ public class LightningView {
|
|||||||
if (icon == null)
|
if (icon == null)
|
||||||
return;
|
return;
|
||||||
mTitle.setFavicon(icon);
|
mTitle.setFavicon(icon);
|
||||||
mBrowserController.updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged()); ;
|
||||||
cacheFavicon(icon);
|
cacheFavicon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -908,7 +914,7 @@ public class LightningView {
|
|||||||
} else {
|
} else {
|
||||||
mTitle.setTitle(mActivity.getString(R.string.untitled));
|
mTitle.setTitle(mActivity.getString(R.string.untitled));
|
||||||
}
|
}
|
||||||
mBrowserController.updateTabs();
|
eventBus.post(new BrowserEvents.TabsChanged()); ;
|
||||||
if (view != null)
|
if (view != null)
|
||||||
mBrowserController.updateHistory(title, view.getUrl());
|
mBrowserController.updateHistory(title, view.getUrl());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user