|
|
@ -100,6 +100,7 @@ import acr.browser.lightning.constant.HistoryPage; |
|
|
|
import acr.browser.lightning.controller.UIController; |
|
|
|
import acr.browser.lightning.controller.UIController; |
|
|
|
import acr.browser.lightning.database.BookmarkManager; |
|
|
|
import acr.browser.lightning.database.BookmarkManager; |
|
|
|
import acr.browser.lightning.database.HistoryDatabase; |
|
|
|
import acr.browser.lightning.database.HistoryDatabase; |
|
|
|
|
|
|
|
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; |
|
|
@ -667,6 +668,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean onOptionsItemSelected(MenuItem item) { |
|
|
|
public boolean onOptionsItemSelected(MenuItem item) { |
|
|
|
final LightningView currentView = mTabsManager.getCurrentTab(); |
|
|
|
final LightningView currentView = mTabsManager.getCurrentTab(); |
|
|
|
|
|
|
|
final String currentUrl = currentView != null ? currentView.getUrl() : null; |
|
|
|
// Handle action buttons
|
|
|
|
// Handle action buttons
|
|
|
|
switch (item.getItemId()) { |
|
|
|
switch (item.getItemId()) { |
|
|
|
case android.R.id.home: |
|
|
|
case android.R.id.home: |
|
|
@ -692,11 +694,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale); |
|
|
|
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_share: |
|
|
|
case R.id.action_share: |
|
|
|
if (currentView != null && !UrlUtils.isSpecialUrl(currentView.getUrl())) { |
|
|
|
if (currentUrl != null && !UrlUtils.isSpecialUrl(currentUrl)) { |
|
|
|
Intent shareIntent = new Intent(Intent.ACTION_SEND); |
|
|
|
Intent shareIntent = new Intent(Intent.ACTION_SEND); |
|
|
|
shareIntent.setType("text/plain"); |
|
|
|
shareIntent.setType("text/plain"); |
|
|
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT, currentView.getTitle()); |
|
|
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT, currentView.getTitle()); |
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, currentView.getUrl()); |
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, currentUrl); |
|
|
|
startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.dialog_title_share))); |
|
|
|
startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.dialog_title_share))); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -704,9 +706,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
openBookmarks(); |
|
|
|
openBookmarks(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_copy: |
|
|
|
case R.id.action_copy: |
|
|
|
if (currentView != null && !UrlUtils.isSpecialUrl(currentView.getUrl())) { |
|
|
|
if (currentUrl != null && !UrlUtils.isSpecialUrl(currentUrl)) { |
|
|
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); |
|
|
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); |
|
|
|
ClipData clip = ClipData.newPlainText("label", currentView.getUrl()); |
|
|
|
ClipData clip = ClipData.newPlainText("label", currentUrl); |
|
|
|
clipboard.setPrimaryClip(clip); |
|
|
|
clipboard.setPrimaryClip(clip); |
|
|
|
Utils.showSnackbar(this, R.string.message_link_copied); |
|
|
|
Utils.showSnackbar(this, R.string.message_link_copied); |
|
|
|
} |
|
|
|
} |
|
|
@ -718,18 +720,17 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
openHistory(); |
|
|
|
openHistory(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_add_bookmark: |
|
|
|
case R.id.action_add_bookmark: |
|
|
|
if (currentView != null && !UrlUtils.isSpecialUrl(currentView.getUrl())) { |
|
|
|
if (currentUrl != null && !UrlUtils.isSpecialUrl(currentUrl)) { |
|
|
|
mEventBus.post(new BrowserEvents.AddBookmark(currentView.getTitle(), |
|
|
|
addBookmark(currentView.getTitle(), currentUrl); |
|
|
|
currentView.getUrl())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_find: |
|
|
|
case R.id.action_find: |
|
|
|
findInPage(); |
|
|
|
findInPage(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_reading_mode: |
|
|
|
case R.id.action_reading_mode: |
|
|
|
if (currentView != null) { |
|
|
|
if (currentUrl != null) { |
|
|
|
Intent read = new Intent(this, ReadingActivity.class); |
|
|
|
Intent read = new Intent(this, ReadingActivity.class); |
|
|
|
read.putExtra(Constants.LOAD_READING_URL, currentView.getUrl()); |
|
|
|
read.putExtra(Constants.LOAD_READING_URL, currentUrl); |
|
|
|
startActivity(read); |
|
|
|
startActivity(read); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -738,6 +739,27 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// By using a manager, adds a bookmark and notifies third parties about that
|
|
|
|
|
|
|
|
private void addBookmark(final String title, final String url) { |
|
|
|
|
|
|
|
final HistoryItem item = !mBookmarkManager.isBookmark(url) |
|
|
|
|
|
|
|
? new HistoryItem(url, title) |
|
|
|
|
|
|
|
: null; |
|
|
|
|
|
|
|
if (item != null && mBookmarkManager.addBookmark(item)) { |
|
|
|
|
|
|
|
mSearchAdapter.refreshBookmarks(); |
|
|
|
|
|
|
|
mEventBus.post(new BrowserEvents.BookmarkAdded(title, url)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void deleteBookmark(final String title, final String url) { |
|
|
|
|
|
|
|
final HistoryItem item = mBookmarkManager.isBookmark(url) |
|
|
|
|
|
|
|
? new HistoryItem(url, title) |
|
|
|
|
|
|
|
: null; |
|
|
|
|
|
|
|
if (item != null && mBookmarkManager.deleteBookmark(item)) { |
|
|
|
|
|
|
|
mSearchAdapter.refreshBookmarks(); |
|
|
|
|
|
|
|
mEventBus.post(new BrowserEvents.CurrentPageUrl(url)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* method that shows a dialog asking what string the user wishes to search |
|
|
|
* method that shows a dialog asking what string the user wishes to search |
|
|
|
* for. It highlights the text entered. |
|
|
|
* for. It highlights the text entered. |
|
|
@ -817,8 +839,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private synchronized void showTab(final int position) { |
|
|
|
private synchronized void showTab(final int position) { |
|
|
|
final LightningView currentView = mTabsManager.getCurrentTab(); |
|
|
|
final LightningView currentView = mTabsManager.getCurrentTab(); |
|
|
|
final WebView currentWebView = currentView != null ? currentView.getWebView() : null; |
|
|
|
|
|
|
|
final LightningView newView = mTabsManager.switchToTab(position); |
|
|
|
final LightningView newView = mTabsManager.switchToTab(position); |
|
|
|
|
|
|
|
switchTabs(currentView, newView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This is commodity to breack the flow between regular tab management and the CLIQZ's search
|
|
|
|
|
|
|
|
// interface.
|
|
|
|
|
|
|
|
private void switchTabs(final LightningView currentView, final LightningView newView) { |
|
|
|
|
|
|
|
final WebView currentWebView = currentView != null ? currentView.getWebView() : null; |
|
|
|
final WebView newWebView = newView != null ? newView.getWebView() : null; |
|
|
|
final WebView newWebView = newView != null ? newView.getWebView() : null; |
|
|
|
if (newView == null || newWebView == null) { |
|
|
|
if (newView == null || newWebView == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -1001,14 +1029,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void deleteTab(int position) { |
|
|
|
private synchronized void deleteTab(int position) { |
|
|
|
final LightningView tabToDelete = mTabsManager.getTabAtPosition(position); |
|
|
|
final LightningView tabToDelete = mTabsManager.getTabAtPosition(position); |
|
|
|
final LightningView currentTab = mTabsManager.getCurrentTab(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tabToDelete == null) { |
|
|
|
if (tabToDelete == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int current = mTabsManager.positionOf(currentTab); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!UrlUtils.isSpecialUrl(tabToDelete.getUrl()) && !isIncognito()) { |
|
|
|
if (!UrlUtils.isSpecialUrl(tabToDelete.getUrl()) && !isIncognito()) { |
|
|
|
mPreferences.setSavedUrl(tabToDelete.getUrl()); |
|
|
|
mPreferences.setSavedUrl(tabToDelete.getUrl()); |
|
|
|
} |
|
|
|
} |
|
|
@ -1017,37 +1042,22 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
if (isShown) { |
|
|
|
if (isShown) { |
|
|
|
mBrowserFrame.setBackgroundColor(mBackgroundColor); |
|
|
|
mBrowserFrame.setBackgroundColor(mBackgroundColor); |
|
|
|
} |
|
|
|
} |
|
|
|
if (current > position) { |
|
|
|
final LightningView currentTab = mTabsManager.getCurrentTab(); |
|
|
|
mTabsManager.deleteTab(position); |
|
|
|
mTabsManager.deleteTab(position); |
|
|
|
mEventBus.post(new BrowserEvents.TabsChanged()); |
|
|
|
final LightningView afterTab = mTabsManager.getCurrentTab(); |
|
|
|
} else if (mTabsManager.size() > position + 1) { |
|
|
|
if (afterTab == null) { |
|
|
|
if (current == position) { |
|
|
|
// if (currentTab != null && (UrlUtils.isSpecialUrl(currentTab.getUrl())
|
|
|
|
showTab(position + 1); |
|
|
|
// || currentTab.getUrl().equals(mPreferenceManager.getHomepage()))) {
|
|
|
|
mTabsManager.deleteTab(position); |
|
|
|
// closeActivity();
|
|
|
|
mEventBus.post(new BrowserEvents.TabsChanged()); |
|
|
|
// } else {
|
|
|
|
} else { |
|
|
|
performExitCleanUp(); |
|
|
|
mTabsManager.deleteTab(position); |
|
|
|
finish(); |
|
|
|
} |
|
|
|
// }
|
|
|
|
} else if (mTabsManager.size() > 1) { |
|
|
|
} else if (afterTab != currentTab) { |
|
|
|
if (current == position) { |
|
|
|
switchTabs(currentTab, afterTab); |
|
|
|
showTab(position - 1); |
|
|
|
currentTab.pauseTimers(); |
|
|
|
mTabsManager.deleteTab(position); |
|
|
|
|
|
|
|
mEventBus.post(new BrowserEvents.TabsChanged()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
mTabsManager.deleteTab(position); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (currentTab != null && (UrlUtils.isSpecialUrl(currentTab.getUrl()) |
|
|
|
|
|
|
|
|| currentTab.getUrl().equals(mHomepage))) { |
|
|
|
|
|
|
|
closeActivity(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
mTabsManager.deleteTab(position); |
|
|
|
|
|
|
|
performExitCleanUp(); |
|
|
|
|
|
|
|
tabToDelete.pauseTimers(); |
|
|
|
|
|
|
|
mEventBus.post(new BrowserEvents.TabsChanged()); |
|
|
|
|
|
|
|
finish(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mEventBus.post(new BrowserEvents.TabsChanged()); |
|
|
|
mEventBus.post(new BrowserEvents.TabsChanged()); |
|
|
|
|
|
|
|
|
|
|
|
if (shouldClose) { |
|
|
|
if (shouldClose) { |
|
|
@ -2007,29 +2017,26 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* When receive a {@link acr.browser.lightning.bus.BookmarkEvents.WantToBookmarkCurrentPage} |
|
|
|
* When receive a {@link BookmarkEvents.ToggleBookmarkForCurrentPage} |
|
|
|
* message this receiver answer firing the |
|
|
|
* message this receiver answer firing the |
|
|
|
* {@link acr.browser.lightning.bus.BrowserEvents.AddBookmark} message |
|
|
|
* {@link BrowserEvents.BookmarkAdded} message |
|
|
|
* |
|
|
|
* |
|
|
|
* @param event an event that the user wishes to bookmark the current page |
|
|
|
* @param event an event that the user wishes to bookmark the current page |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Subscribe |
|
|
|
@Subscribe |
|
|
|
public void bookmarkCurrentPage(final BookmarkEvents.WantToBookmarkCurrentPage event) { |
|
|
|
public void bookmarkCurrentPage(final BookmarkEvents.ToggleBookmarkForCurrentPage event) { |
|
|
|
final LightningView currentTab = mTabsManager.getCurrentTab(); |
|
|
|
final LightningView currentTab = mTabsManager.getCurrentTab(); |
|
|
|
if (currentTab != null) { |
|
|
|
final String url = currentTab != null ? currentTab.getUrl() : null; |
|
|
|
mEventBus.post(new BrowserEvents.AddBookmark(currentTab.getTitle(), currentTab.getUrl())); |
|
|
|
final String title = currentTab != null ? currentTab.getTitle() : null; |
|
|
|
|
|
|
|
if (url == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
if (!mBookmarkManager.isBookmark(url)) { |
|
|
|
* This message is received when a bookmark was added by the |
|
|
|
addBookmark(title, url); |
|
|
|
* {@link acr.browser.lightning.fragment.BookmarksFragment} |
|
|
|
} else { |
|
|
|
* |
|
|
|
deleteBookmark(title, url); |
|
|
|
* @param event the event that a bookmark has been added |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
|
|
|
|
public void bookmarkAdded(final BookmarkEvents.Added event) { |
|
|
|
|
|
|
|
mSearchAdapter.refreshBookmarks(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|