Browse Source

fixed bug with event bus, moved adapter

master
Anthony Restaino 9 years ago
parent
commit
99c09a9d63
  1. 59
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 2
      app/src/main/java/acr/browser/lightning/adapter/SearchAdapter.java
  3. 2
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  4. 4
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java
  5. 9
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

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

@ -112,7 +112,7 @@ import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.fragment.BookmarksFragment; import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter; import acr.browser.lightning.adapter.SearchAdapter;
import acr.browser.lightning.react.Observable; import acr.browser.lightning.react.Observable;
import acr.browser.lightning.react.Schedulers; import acr.browser.lightning.react.Schedulers;
import acr.browser.lightning.receiver.NetworkReceiver; import acr.browser.lightning.receiver.NetworkReceiver;
@ -421,7 +421,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
void panicClean() { void panicClean() {
Log.d(Constants.TAG, "Closing browser"); Log.d(TAG, "Closing browser");
mTabsManager.newTab(this, "", false); mTabsManager.newTab(this, "", false);
mTabsManager.switchToTab(0); mTabsManager.switchToTab(0);
mTabsManager.clearSavedState(); mTabsManager.clearSavedState();
@ -885,19 +885,19 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override @Override
public void notifyTabViewRemoved(int position) { public void notifyTabViewRemoved(int position) {
Log.d(Constants.TAG, "Notify Tab Removed: " + position); Log.d(TAG, "Notify Tab Removed: " + position);
mTabsView.tabRemoved(position); mTabsView.tabRemoved(position);
} }
@Override @Override
public void notifyTabViewAdded() { public void notifyTabViewAdded() {
Log.d(Constants.TAG, "Notify Tab Added"); Log.d(TAG, "Notify Tab Added");
mTabsView.tabAdded(); mTabsView.tabAdded();
} }
@Override @Override
public void notifyTabViewChanged(int position) { public void notifyTabViewChanged(int position) {
Log.d(Constants.TAG, "Notify Tab Changed: " + position); Log.d(TAG, "Notify Tab Changed: " + position);
mTabsView.tabChanged(position); mTabsView.tabChanged(position);
} }
@ -909,6 +909,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override @Override
public void removeTabView() { public void removeTabView() {
Log.d(TAG, "Remove the tab view");
// Set the background color so the color mode color doesn't show through // Set the background color so the color mode color doesn't show through
mBrowserFrame.setBackgroundColor(mBackgroundColor); mBrowserFrame.setBackgroundColor(mBackgroundColor);
@ -936,6 +938,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
return; return;
} }
Log.d(TAG, "Setting the tab view");
// Set the background color so the color mode color doesn't show through // Set the background color so the color mode color doesn't show through
mBrowserFrame.setBackgroundColor(mBackgroundColor); mBrowserFrame.setBackgroundColor(mBackgroundColor);
@ -1028,7 +1032,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override @Override
public void onTrimMemory(int level) { public void onTrimMemory(int level) {
if (level > TRIM_MEMORY_MODERATE && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { if (level > TRIM_MEMORY_MODERATE && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Log.d(Constants.TAG, "Low Memory, Free Memory"); Log.d(TAG, "Low Memory, Free Memory");
mTabsManager.freeMemory(); mTabsManager.freeMemory();
} }
} }
@ -1052,19 +1056,19 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final LightningView currentTab = mTabsManager.getCurrentTab(); final LightningView currentTab = mTabsManager.getCurrentTab();
if (mPreferences.getClearCacheExit() && currentTab != null && !isIncognito()) { if (mPreferences.getClearCacheExit() && currentTab != null && !isIncognito()) {
WebUtils.clearCache(currentTab.getWebView()); WebUtils.clearCache(currentTab.getWebView());
Log.d(Constants.TAG, "Cache Cleared"); Log.d(TAG, "Cache Cleared");
} }
if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) { if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
WebUtils.clearHistory(this, mHistoryDatabase); WebUtils.clearHistory(this, mHistoryDatabase);
Log.d(Constants.TAG, "History Cleared"); Log.d(TAG, "History Cleared");
} }
if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) { if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
WebUtils.clearCookies(this); WebUtils.clearCookies(this);
Log.d(Constants.TAG, "Cookies Cleared"); Log.d(TAG, "Cookies Cleared");
} }
if (mPreferences.getClearWebStorageExitEnabled() && !isIncognito()) { if (mPreferences.getClearWebStorageExitEnabled() && !isIncognito()) {
WebUtils.clearWebStorage(); WebUtils.clearWebStorage();
Log.d(Constants.TAG, "WebStorage Cleared"); Log.d(TAG, "WebStorage Cleared");
} else if (isIncognito()) { } else if (isIncognito()) {
WebUtils.clearWebStorage(); // We want to make sure incognito mode is secure WebUtils.clearWebStorage(); // We want to make sure incognito mode is secure
} }
@ -1138,7 +1142,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mEventBus.post(new BrowserEvents.UserPressedBack()); mEventBus.post(new BrowserEvents.UserPressedBack());
} else { } else {
if (currentTab != null) { if (currentTab != null) {
Log.d(Constants.TAG, "onBackPressed"); Log.d(TAG, "onBackPressed");
if (mSearch.hasFocus()) { if (mSearch.hasFocus()) {
currentTab.requestFocus(); currentTab.requestFocus();
} else if (currentTab.canGoBack()) { } else if (currentTab.canGoBack()) {
@ -1155,7 +1159,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
} }
} else { } else {
Log.e(Constants.TAG, "This shouldn't happen ever"); Log.e(TAG, "This shouldn't happen ever");
super.onBackPressed(); super.onBackPressed();
} }
} }
@ -1165,7 +1169,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
final LightningView currentTab = mTabsManager.getCurrentTab(); final LightningView currentTab = mTabsManager.getCurrentTab();
Log.d(Constants.TAG, "onPause"); Log.d(TAG, "onPause");
if (currentTab != null) { if (currentTab != null) {
currentTab.pauseTimers(); currentTab.pauseTimers();
currentTab.onPause(); currentTab.onPause();
@ -1196,7 +1200,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override @Override
protected void onDestroy() { protected void onDestroy() {
Log.d(Constants.TAG, "onDestroy"); Log.d(TAG, "onDestroy");
mPresenter.shutdown(); mPresenter.shutdown();
@ -1204,6 +1208,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mHistoryDatabase.close(); mHistoryDatabase.close();
mHistoryDatabase = null; mHistoryDatabase = null;
} }
super.onDestroy(); super.onDestroy();
} }
@ -1223,7 +1228,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
final LightningView currentTab = mTabsManager.getCurrentTab(); final LightningView currentTab = mTabsManager.getCurrentTab();
Log.d(Constants.TAG, "onResume"); Log.d(TAG, "onResume");
if (mSearchAdapter != null) { if (mSearchAdapter != null) {
mSearchAdapter.refreshPreferences(); mSearchAdapter.refreshPreferences();
mSearchAdapter.refreshBookmarks(); mSearchAdapter.refreshBookmarks();
@ -1397,11 +1402,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
try { try {
mHistoryDatabase.visitHistoryItem(url, title); mHistoryDatabase.visitHistoryItem(url, title);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.e(Constants.TAG, "IllegalStateException in updateHistory", e); Log.e(TAG, "IllegalStateException in updateHistory", e);
} catch (NullPointerException e) { } catch (NullPointerException e) {
Log.e(Constants.TAG, "NullPointerException in updateHistory", e); Log.e(TAG, "NullPointerException in updateHistory", e);
} catch (SQLiteException e) { } catch (SQLiteException e) {
Log.e(Constants.TAG, "SQLiteException in updateHistory", e); Log.e(TAG, "SQLiteException in updateHistory", e);
} }
} }
}); });
@ -1620,7 +1625,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) { } catch (IOException ex) {
// Error occurred while creating the File // Error occurred while creating the File
Log.e(Constants.TAG, "Unable to create Image File", ex); Log.e(TAG, "Unable to create Image File", ex);
} }
// Continue only if the File was successfully created // Continue only if the File was successfully created
@ -1665,7 +1670,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
try { try {
callback.onCustomViewHidden(); callback.onCustomViewHidden();
} catch (Exception e) { } catch (Exception e) {
Log.e(Constants.TAG, "Error hiding custom view", e); Log.e(TAG, "Error hiding custom view", e);
} }
} }
return; return;
@ -1673,7 +1678,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
try { try {
view.setKeepScreenOn(true); view.setKeepScreenOn(true);
} catch (SecurityException e) { } catch (SecurityException e) {
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on"); Log.e(TAG, "WebView is not allowed to keep the screen on");
} }
mOriginalOrientation = getRequestedOrientation(); mOriginalOrientation = getRequestedOrientation();
mCustomViewCallback = callback; mCustomViewCallback = callback;
@ -1712,18 +1717,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
try { try {
mCustomViewCallback.onCustomViewHidden(); mCustomViewCallback.onCustomViewHidden();
} catch (Exception e) { } catch (Exception e) {
Log.e(Constants.TAG, "Error hiding custom view", e); Log.e(TAG, "Error hiding custom view", e);
} }
mCustomViewCallback = null; mCustomViewCallback = null;
} }
return; return;
} }
Log.d(Constants.TAG, "onHideCustomView"); Log.d(TAG, "onHideCustomView");
currentTab.setVisibility(View.VISIBLE); currentTab.setVisibility(View.VISIBLE);
try { try {
mCustomView.setKeepScreenOn(false); mCustomView.setKeepScreenOn(false);
} catch (SecurityException e) { } catch (SecurityException e) {
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on"); Log.e(TAG, "WebView is not allowed to keep the screen on");
} }
setFullscreen(mPreferences.getHideStatusBarEnabled(), false); setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
if (mFullscreenContainer != null) { if (mFullscreenContainer != null) {
@ -1737,7 +1742,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mFullscreenContainer = null; mFullscreenContainer = null;
mCustomView = null; mCustomView = null;
if (mVideoView != null) { if (mVideoView != null) {
Log.d(Constants.TAG, "VideoView is being stopped"); Log.d(TAG, "VideoView is being stopped");
mVideoView.stopPlayback(); mVideoView.stopPlayback();
mVideoView.setOnErrorListener(null); mVideoView.setOnErrorListener(null);
mVideoView.setOnCompletionListener(null); mVideoView.setOnCompletionListener(null);
@ -1747,7 +1752,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
try { try {
mCustomViewCallback.onCustomViewHidden(); mCustomViewCallback.onCustomViewHidden();
} catch (Exception e) { } catch (Exception e) {
Log.e(Constants.TAG, "Error hiding custom view", e); Log.e(TAG, "Error hiding custom view", e);
} }
} }
mCustomViewCallback = null; mCustomViewCallback = null;
@ -2118,7 +2123,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent); super.onReceive(context, intent);
boolean isConnected = isConnected(context); boolean isConnected = isConnected(context);
Log.d(Constants.TAG, "Network Connected: " + String.valueOf(isConnected)); Log.d(TAG, "Network Connected: " + String.valueOf(isConnected));
mTabsManager.notifyConnectionStatus(isConnected); mTabsManager.notifyConnectionStatus(isConnected);
} }
}; };

2
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java → app/src/main/java/acr/browser/lightning/adapter/SearchAdapter.java

@ -1,4 +1,4 @@
package acr.browser.lightning.object; package acr.browser.lightning.adapter;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;

2
app/src/main/java/acr/browser/lightning/app/AppComponent.java

@ -16,7 +16,7 @@ import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.LightningPreferenceFragment; import acr.browser.lightning.fragment.LightningPreferenceFragment;
import acr.browser.lightning.fragment.PrivacySettingsFragment; import acr.browser.lightning.fragment.PrivacySettingsFragment;
import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter; import acr.browser.lightning.adapter.SearchAdapter;
import acr.browser.lightning.utils.AdBlock; import acr.browser.lightning.utils.AdBlock;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;

4
app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

@ -146,8 +146,10 @@ public class BrowserPresenter {
tabChanged(mTabsModel.indexOfCurrentTab()); tabChanged(mTabsModel.indexOfCurrentTab());
} }
} }
final LightningView afterTab = mTabsModel.getCurrentTab(); final LightningView afterTab = mTabsModel.getCurrentTab();
mView.notifyTabViewRemoved(position); mView.notifyTabViewRemoved(position);
if (afterTab == null) { if (afterTab == null) {
mView.closeBrowser(); mView.closeBrowser();
return; return;
@ -167,7 +169,7 @@ public class BrowserPresenter {
mView.updateTabNumber(mTabsModel.size()); mView.updateTabNumber(mTabsModel.size());
Log.d(Constants.TAG, "deleted tab"); Log.d(TAG, "deleted tab");
} }
public void onNewIntent(final Intent intent) { public void onNewIntent(final Intent intent) {

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

@ -219,6 +219,7 @@ public class DownloadHandler {
request.addRequestHeader(COOKIE_REQUEST_HEADER, cookies); request.addRequestHeader(COOKIE_REQUEST_HEADER, cookies);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
if (mimetype == null) { if (mimetype == null) {
Log.d(TAG, "Mimetype is null");
if (TextUtils.isEmpty(addressString)) { if (TextUtils.isEmpty(addressString)) {
return; return;
} }
@ -226,24 +227,20 @@ public class DownloadHandler {
// are not sure of the mimetype in this case, so do a head request // are not sure of the mimetype in this case, so do a head request
new FetchUrlMimeType(context, request, addressString, cookies, userAgent).start(); new FetchUrlMimeType(context, request, addressString, cookies, userAgent).start();
} else { } else {
Log.d(TAG, "Valid mimetype, attempting to download");
final DownloadManager manager = (DownloadManager) context final DownloadManager manager = (DownloadManager) context
.getSystemService(Context.DOWNLOAD_SERVICE); .getSystemService(Context.DOWNLOAD_SERVICE);
BrowserApp.getTaskThread().execute(new Runnable() {
@Override
public void run() {
try { try {
manager.enqueue(request); manager.enqueue(request);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Probably got a bad URL or something // Probably got a bad URL or something
e.printStackTrace(); Log.e(TAG, "Unable to enqueue request", e);
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download)); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
} catch (SecurityException e) { } catch (SecurityException e) {
// TODO write a download utility that downloads files rather than rely on the system // TODO write a download utility that downloads files rather than rely on the system
// because the system can only handle Environment.getExternal... as a path // because the system can only handle Environment.getExternal... as a path
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download)); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
} }
}
});
eventBus.post(new BrowserEvents.ShowSnackBarMessage( eventBus.post(new BrowserEvents.ShowSnackBarMessage(
context.getString(R.string.download_pending) + ' ' + filename)); context.getString(R.string.download_pending) + ' ' + filename));
} }

Loading…
Cancel
Save