Browse Source

Fixed bug where opening a URL in the browser wouldn't work, refactored the ui controller, fixed bad database practices.

master
Anthony Restaino 9 years ago
parent
commit
9f755aeed7
  1. 27
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 4
      app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java
  3. 4
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java
  4. 44
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  5. 8
      app/src/main/java/acr/browser/lightning/controller/UIController.java
  6. 49
      app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java
  7. 6
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java
  8. 34
      app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java
  9. 19
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  10. 15
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

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

@ -97,7 +97,7 @@ import acr.browser.lightning.bus.TabEvents; @@ -97,7 +97,7 @@ import acr.browser.lightning.bus.TabEvents;
import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.HistoryPage;
import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.database.HistoryDatabase;
import acr.browser.lightning.dialog.LightningDialogBuilder;
@ -116,7 +116,7 @@ import acr.browser.lightning.view.LightningView; @@ -116,7 +116,7 @@ import acr.browser.lightning.view.LightningView;
import butterknife.Bind;
import butterknife.ButterKnife;
public abstract class BrowserActivity extends ThemableBrowserActivity implements BrowserController, OnClickListener, OnLongClickListener {
public abstract class BrowserActivity extends ThemableBrowserActivity implements UIController, OnClickListener, OnLongClickListener {
// Static Layout
@Bind(R.id.drawer_layout)
@ -213,11 +213,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -213,11 +213,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
protected abstract boolean isIncognito();
// abstract void initializeTabs();
abstract void closeActivity();
public abstract void updateHistory(final String title, final String url);
public abstract void updateHistory(@Nullable final String title, @NonNull final String url);
abstract void updateCookiePreference();
@ -348,7 +346,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -348,7 +346,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
}
tabsManager.restoreTabs(this, mDarkTheme, isIncognito());
tabsManager.restoreTabsAndHandleIntent(this, getIntent(), isIncognito());
// At this point we always have at least a tab in the tab manager
showTab(0);
@ -955,7 +953,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -955,7 +953,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
return false;
}
mIsNewIntent = false;
LightningView startingTab = tabsManager.newTab(this, url, mDarkTheme, isIncognito());
LightningView startingTab = tabsManager.newTab(this, url, isIncognito());
if (mIdGenerator == 0) {
startingTab.resumeTimers();
}
@ -1257,6 +1255,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1257,6 +1255,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
});
}
@Override
public boolean getUseDarkTheme() {
return mDarkTheme;
}
@ColorInt
@Override
public int getUiColor() {
@ -1264,11 +1267,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1264,11 +1267,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
@Override
public void updateUrl(String url, boolean shortUrl) {
final LightningView currentTab = tabsManager.getCurrentTab();
public void updateUrl(@Nullable String url, boolean shortUrl) {
if (url == null || mSearch == null || mSearch.hasFocus()) {
return;
}
final LightningView currentTab = tabsManager.getCurrentTab();
mEventBus.post(new BrowserEvents.CurrentPageUrl(url));
if (shortUrl && !url.startsWith(Constants.FILE)) {
switch (mPreferences.getUrlBoxContentChoice()) {
@ -1302,7 +1305,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1302,7 +1305,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mProgressBar.setProgress(n);
}
void addItemToHistory(final String title, final String url) {
void addItemToHistory(@Nullable final String title, @NonNull final String url) {
Runnable update = new Runnable() {
@Override
public void run() {
@ -1317,7 +1320,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1317,7 +1320,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
}
};
if (url != null && !url.startsWith(Constants.FILE)) {
if (!url.startsWith(Constants.FILE)) {
new Thread(update).start();
}
}
@ -1893,7 +1896,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1893,7 +1896,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
super.onReceive(context, intent);
boolean isConnected = isConnected(context);
Log.d(Constants.TAG, "Network Connected: " + String.valueOf(isConnected));
tabsManager.notifyConnectioneStatus(isConnected);
tabsManager.notifyConnectionStatus(isConnected);
}
};

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

@ -2,6 +2,8 @@ package acr.browser.lightning.activity; @@ -2,6 +2,8 @@ package acr.browser.lightning.activity;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Menu;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
@ -44,7 +46,7 @@ public class IncognitoActivity extends BrowserActivity { @@ -44,7 +46,7 @@ public class IncognitoActivity extends BrowserActivity {
}
@Override
public void updateHistory(String title, String url) {
public void updateHistory(@Nullable String title, @NonNull String url) {
// addItemToHistory(title, url);
}

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

@ -2,6 +2,8 @@ package acr.browser.lightning.activity; @@ -2,6 +2,8 @@ package acr.browser.lightning.activity;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Menu;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
@ -45,7 +47,7 @@ public class MainActivity extends BrowserActivity { @@ -45,7 +47,7 @@ public class MainActivity extends BrowserActivity {
}
@Override
public void updateHistory(String title, String url) {
public void updateHistory(@Nullable String title, @NonNull String url) {
addItemToHistory(title, url);
}

44
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -1,7 +1,10 @@ @@ -1,7 +1,10 @@
package acr.browser.lightning.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.util.Log;
import android.webkit.WebView;
import java.util.ArrayList;
@ -21,6 +24,7 @@ import acr.browser.lightning.view.LightningView; @@ -21,6 +24,7 @@ import acr.browser.lightning.view.LightningView;
@Singleton
public class TabsManager {
private static final String TAG = TabsManager.class.getSimpleName();
private final List<LightningView> mWebViewList = new ArrayList<>();
private LightningView mCurrentTab;
@ -28,24 +32,30 @@ public class TabsManager { @@ -28,24 +32,30 @@ public class TabsManager {
PreferenceManager mPreferenceManager;
@Inject
public TabsManager() {
}
public TabsManager() {}
public void restoreTabs(BrowserActivity activity, boolean darkTheme, boolean incognito) {
public void restoreTabsAndHandleIntent(Activity activity, Intent intent, boolean incognito) {
String url = null;
if (intent != null) {
url = intent.getDataString();
}
mWebViewList.clear();
mCurrentTab = null;
if (url != null) {
newTab(activity, url, incognito);
}
if (!incognito && mPreferenceManager.getRestoreLostTabsEnabled()) {
final String mem = mPreferenceManager.getMemoryUrl();
mPreferenceManager.setMemoryUrl("");
String[] array = Utils.getArray(mem);
for (String urlString : array) {
if (!urlString.isEmpty()) {
newTab(activity, urlString, darkTheme, incognito);
newTab(activity, urlString, incognito);
}
}
}
if (mWebViewList.size() == 0) {
newTab(activity, null, darkTheme, incognito);
newTab(activity, null, incognito);
}
// mCurrentTab = mWebViewList.get(0);
}
@ -68,7 +78,7 @@ public class TabsManager { @@ -68,7 +78,7 @@ public class TabsManager {
* @return the corespondent {@link LightningView}, or null if the index is invalid
*/
@Nullable
public LightningView getTabAtPosition(final int position) {
public synchronized LightningView getTabAtPosition(final int position) {
if (position < 0 || position >= mWebViewList.size()) {
return null;
}
@ -79,7 +89,7 @@ public class TabsManager { @@ -79,7 +89,7 @@ public class TabsManager {
/**
* Try to low memory pressure
*/
public void freeMemory() {
public synchronized void freeMemory() {
for (LightningView tab : mWebViewList) {
tab.freeMemory();
}
@ -111,7 +121,7 @@ public class TabsManager { @@ -111,7 +121,7 @@ public class TabsManager {
*
* @param isConnected
*/
public synchronized void notifyConnectioneStatus(final boolean isConnected) {
public synchronized void notifyConnectionStatus(final boolean isConnected) {
for (LightningView tab : mWebViewList) {
final WebView webView = tab.getWebView();
if (webView != null) {
@ -123,7 +133,7 @@ public class TabsManager { @@ -123,7 +133,7 @@ public class TabsManager {
/**
* @return The number of currently opened tabs
*/
public int size() {
public synchronized int size() {
return mWebViewList.size();
}
@ -132,14 +142,13 @@ public class TabsManager { @@ -132,14 +142,13 @@ public class TabsManager {
*
* @param activity
* @param url
* @param darkTheme
* @param isIncognito
* @return
*/
public synchronized LightningView newTab(final BrowserActivity activity,
final String url, final boolean darkTheme,
public synchronized LightningView newTab(final Activity activity,
final String url,
final boolean isIncognito) {
final LightningView tab = new LightningView(activity, url, darkTheme, isIncognito);
final LightningView tab = new LightningView(activity, url, isIncognito);
mWebViewList.add(tab);
return tab;
}
@ -166,7 +175,7 @@ public class TabsManager { @@ -166,7 +175,7 @@ public class TabsManager {
* @param tab the tab to look for
* @return the position of the tab or -1 if the tab is not in the list
*/
public int positionOf(final LightningView tab) {
public synchronized int positionOf(final LightningView tab) {
return mWebViewList.indexOf(tab);
}
@ -190,7 +199,7 @@ public class TabsManager { @@ -190,7 +199,7 @@ public class TabsManager {
* @return a {@link WebView} or null
*/
@Nullable
public WebView getCurrentWebView() {
public synchronized WebView getCurrentWebView() {
return mCurrentTab != null ? mCurrentTab.getWebView() : null;
}
@ -200,7 +209,7 @@ public class TabsManager { @@ -200,7 +209,7 @@ public class TabsManager {
* @return
*/
@Nullable
public LightningView getCurrentTab() {
public synchronized LightningView getCurrentTab() {
return mCurrentTab;
}
@ -212,8 +221,9 @@ public class TabsManager { @@ -212,8 +221,9 @@ public class TabsManager {
* @return the selected tab or null if position is out of tabs range
*/
@Nullable
public LightningView switchToTab(final int position) {
public synchronized LightningView switchToTab(final int position) {
if (position < 0 || position >= mWebViewList.size()) {
Log.e(TAG, "Returning a null LightningView requested for position: " + position);
return null;
} else {
final LightningView tab = mWebViewList.get(position);

8
app/src/main/java/acr/browser/lightning/controller/BrowserController.java → app/src/main/java/acr/browser/lightning/controller/UIController.java

@ -16,18 +16,20 @@ import android.webkit.WebChromeClient.CustomViewCallback; @@ -16,18 +16,20 @@ import android.webkit.WebChromeClient.CustomViewCallback;
import acr.browser.lightning.view.LightningView;
public interface BrowserController {
public interface UIController {
void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable Drawable drawable);
@ColorInt
int getUiColor();
void updateUrl(String title, boolean shortUrl);
boolean getUseDarkTheme();
void updateUrl(@Nullable String title, boolean shortUrl);
void updateProgress(int n);
void updateHistory(String title, String url);
void updateHistory(@Nullable String title, @NonNull String url);
void openFileChooser(ValueCallback<Uri> uploadMsg);

49
app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java

@ -8,6 +8,8 @@ import android.content.Context; @@ -8,6 +8,8 @@ import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@ -38,10 +40,6 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -38,10 +40,6 @@ public class HistoryDatabase extends SQLiteOpenHelper {
private SQLiteDatabase mDatabase;
private static HistoryDatabase mInstance;
private boolean mLock;
@Inject
public HistoryDatabase(Context context) {
super(context.getApplicationContext(), DATABASE_NAME, null, DATABASE_VERSION);
@ -66,24 +64,22 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -66,24 +64,22 @@ public class HistoryDatabase extends SQLiteOpenHelper {
onCreate(db);
}
public void deleteHistory() {
public synchronized void deleteHistory() {
mDatabase.delete(TABLE_HISTORY, null, null);
mDatabase.close();
mDatabase = this.getWritableDatabase();
}
private boolean isClosed() {
private synchronized boolean isClosed() {
return mDatabase == null || !mDatabase.isOpen();
}
@Override
public synchronized void close() {
if (!mLock) {
if (mDatabase != null) {
mDatabase.close();
mDatabase = null;
}
}
super.close();
}
@ -94,42 +90,35 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -94,42 +90,35 @@ public class HistoryDatabase extends SQLiteOpenHelper {
}
public synchronized void deleteHistoryItem(String url) {
mLock = true;
openIfNecessary();
mDatabase.delete(TABLE_HISTORY, KEY_URL + " = ?", new String[]{url});
mLock = false;
}
public synchronized void visitHistoryItem(String url, String title) {
mLock = true;
public synchronized void visitHistoryItem(@NonNull String url, @Nullable String title) {
openIfNecessary();
ContentValues values = new ContentValues();
values.put(KEY_TITLE, title);
values.put(KEY_TITLE, title == null ? "" : title);
values.put(KEY_TIME_VISITED, System.currentTimeMillis());
Cursor q = mDatabase.query(false, TABLE_HISTORY, new String[]{KEY_URL},
KEY_URL + " = ?", new String[]{url}, null, null, null, "1");
if (q.getCount() > 0) {
mDatabase.update(TABLE_HISTORY, values, KEY_URL + " = ?", new String[]{url});
} else {
addHistoryItem(new HistoryItem(url, title));
addHistoryItem(new HistoryItem(url, title == null ? "" : title));
}
q.close();
mLock = false;
}
private synchronized void addHistoryItem(HistoryItem item) {
mLock = true;
private synchronized void addHistoryItem(@NonNull HistoryItem item) {
openIfNecessary();
ContentValues values = new ContentValues();
values.put(KEY_URL, item.getUrl());
values.put(KEY_TITLE, item.getTitle());
values.put(KEY_TIME_VISITED, System.currentTimeMillis());
mDatabase.insert(TABLE_HISTORY, null, values);
mLock = false;
}
String getHistoryItem(String url) {
mLock = true;
synchronized String getHistoryItem(String url) {
openIfNecessary();
Cursor cursor = mDatabase.query(TABLE_HISTORY, new String[]{KEY_ID, KEY_URL, KEY_TITLE},
KEY_URL + " = ?", new String[]{url}, null, null, null, null);
@ -140,14 +129,15 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -140,14 +129,15 @@ public class HistoryDatabase extends SQLiteOpenHelper {
cursor.close();
}
mLock = false;
return m;
}
public List<HistoryItem> findItemsContaining(String search) {
mLock = true;
public synchronized List<HistoryItem> findItemsContaining(@Nullable String search) {
openIfNecessary();
List<HistoryItem> itemList = new ArrayList<>(5);
if (search == null) {
return itemList;
}
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " WHERE " + KEY_TITLE + " LIKE '%"
+ search + "%' OR " + KEY_URL + " LIKE '%" + search + "%' " + "ORDER BY "
+ KEY_TIME_VISITED + " DESC LIMIT 5";
@ -165,12 +155,10 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -165,12 +155,10 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} while (cursor.moveToNext() && n < 5);
}
cursor.close();
mLock = false;
return itemList;
}
public List<HistoryItem> getLastHundredItems() {
mLock = true;
public synchronized List<HistoryItem> getLastHundredItems() {
openIfNecessary();
List<HistoryItem> itemList = new ArrayList<>(100);
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
@ -189,12 +177,10 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -189,12 +177,10 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} while (cursor.moveToNext() && counter < 100);
}
cursor.close();
mLock = false;
return itemList;
}
public List<HistoryItem> getAllHistoryItems() {
mLock = true;
public synchronized List<HistoryItem> getAllHistoryItems() {
openIfNecessary();
List<HistoryItem> itemList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
@ -212,18 +198,15 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -212,18 +198,15 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} while (cursor.moveToNext());
}
cursor.close();
mLock = false;
return itemList;
}
public int getHistoryItemsCount() {
mLock = true;
public synchronized int getHistoryItemsCount() {
openIfNecessary();
String countQuery = "SELECT * FROM " + TABLE_HISTORY;
Cursor cursor = mDatabase.rawQuery(countQuery, null);
int n = cursor.getCount();
cursor.close();
mLock = false;
return n;
}
}

6
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -40,7 +40,7 @@ import acr.browser.lightning.app.BrowserApp; @@ -40,7 +40,7 @@ import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.bus.NavigationEvents;
import acr.browser.lightning.bus.TabEvents;
import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.Utils;
@ -71,7 +71,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -71,7 +71,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
private RecyclerView mRecyclerView;
private LightningViewAdapter mTabsAdapter;
private BrowserController mUiController;
private UIController mUiController;
@Inject
TabsManager tabsManager;
@ -91,7 +91,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -91,7 +91,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
super.onCreate(savedInstanceState);
final Bundle arguments = getArguments();
final Context context = getContext();
mUiController = (BrowserController) getActivity();
mUiController = (UIController) getActivity();
mIsIncognito = arguments.getBoolean(IS_INCOGNITO, false);
mShowInNavigationDrawer = arguments.getBoolean(VERTICAL_MODE, true);
mDarkTheme = mPreferences.getUseTheme() != 0 || mIsIncognito;

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package acr.browser.lightning.view;
import android.Manifest;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
@ -23,10 +24,10 @@ import java.io.FileOutputStream; @@ -23,10 +24,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import acr.browser.lightning.R;
import acr.browser.lightning.activity.BrowserActivity;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.utils.PermissionsManager;
import acr.browser.lightning.utils.Utils;
@ -38,12 +39,14 @@ class LightningChromeClient extends WebChromeClient { @@ -38,12 +39,14 @@ class LightningChromeClient extends WebChromeClient {
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
private final BrowserActivity mActivity;
private final Activity mActivity;
private final LightningView mLightningView;
private final UIController mUIController;
private final Bus eventBus;
LightningChromeClient(BrowserActivity activity, LightningView lightningView) {
LightningChromeClient(Activity activity, LightningView lightningView) {
mActivity = activity;
mUIController = (UIController) activity;
mLightningView = lightningView;
eventBus = BrowserApp.getAppComponent().getBus();
}
@ -51,7 +54,7 @@ class LightningChromeClient extends WebChromeClient { @@ -51,7 +54,7 @@ class LightningChromeClient extends WebChromeClient {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (mLightningView.isShown()) {
mActivity.updateProgress(newProgress);
mUIController.updateProgress(newProgress);
}
}
@ -103,7 +106,7 @@ class LightningChromeClient extends WebChromeClient { @@ -103,7 +106,7 @@ class LightningChromeClient extends WebChromeClient {
}
eventBus.post(new BrowserEvents.TabsChanged());
if (view != null) {
mActivity.updateHistory(title, view.getUrl());
mUIController.updateHistory(title, view.getUrl());
}
}
@ -152,30 +155,33 @@ class LightningChromeClient extends WebChromeClient { @@ -152,30 +155,33 @@ class LightningChromeClient extends WebChromeClient {
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture,
Message resultMsg) {
mActivity.onCreateWindow(resultMsg);
mUIController.onCreateWindow(resultMsg);
return true;
}
@Override
public void onCloseWindow(WebView window) {
mActivity.onCloseWindow(mLightningView);
mUIController.onCloseWindow(mLightningView);
}
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mActivity.openFileChooser(uploadMsg);
mUIController.openFileChooser(uploadMsg);
}
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mActivity.openFileChooser(uploadMsg);
mUIController.openFileChooser(uploadMsg);
}
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mActivity.openFileChooser(uploadMsg);
mUIController.openFileChooser(uploadMsg);
}
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
WebChromeClient.FileChooserParams fileChooserParams) {
mActivity.showFileChooser(filePathCallback);
mUIController.showFileChooser(filePathCallback);
return true;
}
@ -206,7 +212,7 @@ class LightningChromeClient extends WebChromeClient { @@ -206,7 +212,7 @@ class LightningChromeClient extends WebChromeClient {
@Override
public void onHideCustomView() {
mActivity.onHideCustomView();
mUIController.onHideCustomView();
super.onHideCustomView();
}
@ -224,7 +230,7 @@ class LightningChromeClient extends WebChromeClient { @@ -224,7 +230,7 @@ class LightningChromeClient extends WebChromeClient {
// video.setVisibility(View.GONE);
// }
// } else {
mActivity.onShowCustomView(view, callback);
mUIController.onShowCustomView(view, callback);
// }
@ -247,7 +253,7 @@ class LightningChromeClient extends WebChromeClient { @@ -247,7 +253,7 @@ class LightningChromeClient extends WebChromeClient {
// video.setVisibility(View.GONE);
// }
// } else {
mActivity.onShowCustomView(view, callback);
mUIController.onShowCustomView(view, callback);
// }

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

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
package acr.browser.lightning.view;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
@ -40,12 +41,12 @@ import java.lang.ref.WeakReference; @@ -40,12 +41,12 @@ import java.lang.ref.WeakReference;
import javax.inject.Inject;
import acr.browser.lightning.R;
import acr.browser.lightning.activity.BrowserActivity;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.HistoryPage;
import acr.browser.lightning.constant.StartPage;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.download.LightningDownloadListener;
import acr.browser.lightning.preference.PreferenceManager;
@ -58,8 +59,9 @@ public class LightningView { @@ -58,8 +59,9 @@ public class LightningView {
final LightningViewTitle mTitle;
private WebView mWebView;
final boolean mIsIncognitoTab;
private final UIController mUIController;
private final GestureDetector mGestureDetector;
private final BrowserActivity mActivity;
private final Activity mActivity;
private static String mHomepage;
private static String mDefaultUserAgent;
private final Paint mPaint = new Paint();
@ -87,12 +89,13 @@ public class LightningView { @@ -87,12 +89,13 @@ public class LightningView {
LightningDialogBuilder mBookmarksDialogBuilder;
@SuppressLint("NewApi")
public LightningView(BrowserActivity activity, String url, boolean darkTheme, boolean isIncognito) {
public LightningView(Activity activity, String url, boolean isIncognito) {
BrowserApp.getAppComponent().inject(this);
mActivity = activity;
mUIController = (UIController) activity;
mWebView = new WebView(activity);
mIsIncognitoTab = isIncognito;
mTitle = new LightningViewTitle(activity, darkTheme);
mTitle = new LightningViewTitle(activity, mUIController.getUseDarkTheme());
mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();
@ -710,9 +713,9 @@ public class LightningView { @@ -710,9 +713,9 @@ public class LightningView {
} else if (mAction == MotionEvent.ACTION_UP) {
final float distance = (mY - mLocation);
if (distance > SCROLL_UP_THRESHOLD && view.getScrollY() < SCROLL_UP_THRESHOLD) {
mActivity.showActionBar();
mUIController.showActionBar();
} else if (distance < -SCROLL_UP_THRESHOLD) {
mActivity.hideActionBar();
mUIController.hideActionBar();
}
mLocation = 0;
}
@ -727,9 +730,9 @@ public class LightningView { @@ -727,9 +730,9 @@ public class LightningView {
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
int power = (int) (velocityY * 100 / mMaxFling);
if (power < -10) {
mActivity.hideActionBar();
mUIController.hideActionBar();
} else if (power > 15) {
mActivity.showActionBar();
mUIController.showActionBar();
}
return super.onFling(e1, e2, velocityX, velocityY);
}

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package acr.browser.lightning.view;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
@ -31,10 +32,10 @@ import java.util.ArrayList; @@ -31,10 +32,10 @@ import java.util.ArrayList;
import java.util.List;
import acr.browser.lightning.R;
import acr.browser.lightning.activity.BrowserActivity;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.utils.AdBlock;
import acr.browser.lightning.utils.IntentUtils;
import acr.browser.lightning.utils.ProxyUtils;
@ -46,14 +47,16 @@ import acr.browser.lightning.utils.Utils; @@ -46,14 +47,16 @@ import acr.browser.lightning.utils.Utils;
*/
class LightningWebClient extends WebViewClient {
private final BrowserActivity mActivity;
private final Activity mActivity;
private final LightningView mLightningView;
private final UIController mUIController;
private final AdBlock mAdBlock;
private final Bus mEventBus;
private final IntentUtils mIntentUtils;
LightningWebClient(BrowserActivity activity, LightningView lightningView) {
LightningWebClient(Activity activity, LightningView lightningView) {
mActivity = activity;
mUIController = (UIController) activity;
mLightningView = lightningView;
mAdBlock = AdBlock.getInstance(activity);
mAdBlock.updatePreference();
@ -86,7 +89,7 @@ class LightningWebClient extends WebViewClient { @@ -86,7 +89,7 @@ class LightningWebClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
if (view.isShown()) {
mActivity.updateUrl(url, true);
mUIController.updateUrl(url, true);
view.postInvalidate();
}
if (view.getTitle() == null || view.getTitle().isEmpty()) {
@ -105,8 +108,8 @@ class LightningWebClient extends WebViewClient { @@ -105,8 +108,8 @@ class LightningWebClient extends WebViewClient {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
mLightningView.mTitle.setFavicon(null);
if (mLightningView.isShown()) {
mActivity.updateUrl(url, false);
mActivity.showActionBar();
mUIController.updateUrl(url, false);
mUIController.showActionBar();
}
mEventBus.post(new BrowserEvents.TabsChanged());
}

Loading…
Cancel
Save