Use interface instead of event bus, moving some stuff out of activity and into presenter
This commit is contained in:
parent
76b297781f
commit
f71ebd2643
@ -61,7 +61,6 @@ import android.view.ViewTreeObserver;
|
|||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
|
||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
@ -95,12 +94,12 @@ 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.browser.BookmarksView;
|
||||||
import acr.browser.lightning.browser.BrowserPresenter;
|
import acr.browser.lightning.browser.BrowserPresenter;
|
||||||
import acr.browser.lightning.browser.BrowserView;
|
import acr.browser.lightning.browser.BrowserView;
|
||||||
import acr.browser.lightning.browser.TabsView;
|
import acr.browser.lightning.browser.TabsView;
|
||||||
import acr.browser.lightning.bus.BookmarkEvents;
|
import acr.browser.lightning.bus.BookmarkEvents;
|
||||||
import acr.browser.lightning.bus.BrowserEvents;
|
import acr.browser.lightning.bus.BrowserEvents;
|
||||||
import acr.browser.lightning.bus.NavigationEvents;
|
|
||||||
import acr.browser.lightning.bus.TabEvents;
|
import acr.browser.lightning.bus.TabEvents;
|
||||||
import acr.browser.lightning.constant.BookmarkPage;
|
import acr.browser.lightning.constant.BookmarkPage;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
@ -208,6 +207,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
private BrowserPresenter mPresenter;
|
private BrowserPresenter mPresenter;
|
||||||
private TabsView mTabsView;
|
private TabsView mTabsView;
|
||||||
|
private BookmarksView mBookmarksView;
|
||||||
|
|
||||||
// Proxy
|
// Proxy
|
||||||
@Inject ProxyUtils mProxyUtils;
|
@Inject ProxyUtils mProxyUtils;
|
||||||
@ -301,6 +301,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
tabsFragment.setArguments(tabsFragmentArguments);
|
tabsFragment.setArguments(tabsFragmentArguments);
|
||||||
|
|
||||||
final BookmarksFragment bookmarksFragment = new BookmarksFragment();
|
final BookmarksFragment bookmarksFragment = new BookmarksFragment();
|
||||||
|
mBookmarksView = bookmarksFragment;
|
||||||
final Bundle bookmarksFragmentArguments = new Bundle();
|
final Bundle bookmarksFragmentArguments = new Bundle();
|
||||||
bookmarksFragmentArguments.putBoolean(BookmarksFragment.INCOGNITO_MODE, isIncognito());
|
bookmarksFragmentArguments.putBoolean(BookmarksFragment.INCOGNITO_MODE, isIncognito());
|
||||||
bookmarksFragment.setArguments(bookmarksFragmentArguments);
|
bookmarksFragment.setArguments(bookmarksFragmentArguments);
|
||||||
@ -338,7 +339,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
updateTabNumber(0);
|
updateTabNumber(0);
|
||||||
} else {
|
} else {
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mSwapBookmarksAndTabs ? mDrawerRight : mDrawerLeft);
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, getTabDrawer());
|
||||||
mArrowImage.setImageResource(R.drawable.ic_action_home);
|
mArrowImage.setImageResource(R.drawable.ic_action_home);
|
||||||
mArrowImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
mArrowImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
@ -719,8 +720,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
// Handle action buttons
|
// Handle action buttons
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
if (mDrawerLayout.isDrawerOpen(mDrawerRight)) {
|
if (mDrawerLayout.isDrawerOpen(getBookmarkDrawer())) {
|
||||||
mDrawerLayout.closeDrawer(mDrawerRight);
|
mDrawerLayout.closeDrawer(getBookmarkDrawer());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_back:
|
case R.id.action_back:
|
||||||
@ -858,17 +859,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(String text) {
|
public void onClick(String text) {
|
||||||
if (!TextUtils.isEmpty(text)) {
|
if (!TextUtils.isEmpty(text)) {
|
||||||
showSearchInterfaceBar(text);
|
mPresenter.findInPage(text);
|
||||||
|
showFindInPageControls(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSearchInterfaceBar(String text) {
|
private void showFindInPageControls(@NonNull String text) {
|
||||||
final LightningView currentView = mTabsManager.getCurrentTab();
|
|
||||||
if (currentView != null) {
|
|
||||||
currentView.find(text);
|
|
||||||
}
|
|
||||||
mSearchBar.setVisibility(View.VISIBLE);
|
mSearchBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
TextView tw = (TextView) findViewById(R.id.search_query);
|
TextView tw = (TextView) findViewById(R.id.search_query);
|
||||||
@ -898,7 +896,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
new BrowserDialog.Item(R.string.close_tab) {
|
new BrowserDialog.Item(R.string.close_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
deleteTab(position);
|
mPresenter.deleteTab(position);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.close_other_tabs) {
|
new BrowserDialog.Item(R.string.close_other_tabs) {
|
||||||
@ -1060,21 +1058,16 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeEmptyTab() {
|
public void closeEmptyTab() {
|
||||||
final WebView currentWebView = mTabsManager.getCurrentWebView();
|
// Currently do nothing
|
||||||
if (currentWebView != null && currentWebView.copyBackForwardList().getSize() == 0) {
|
// Possibly closing the current tab might close the browser
|
||||||
closeCurrentTab();
|
// and mess stuff up
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeCurrentTab() {
|
|
||||||
// don't delete the tab because the browser will close and mess stuff up
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(TAG, "Low Memory, Free Memory");
|
Log.d(TAG, "Low Memory, Free Memory");
|
||||||
mTabsManager.freeMemory();
|
mPresenter.onAppLowMemory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,11 +1081,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mPresenter.newTab(null, true);
|
mPresenter.newTab(null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO move this to presenter
|
|
||||||
private synchronized void deleteTab(int position) {
|
|
||||||
mPresenter.deleteTab(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
void performExitCleanUp() {
|
void performExitCleanUp() {
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
if (mPreferences.getClearCacheExit() && currentTab != null && !isIncognito()) {
|
if (mPreferences.getClearCacheExit() && currentTab != null && !isIncognito()) {
|
||||||
@ -1178,7 +1166,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (mDrawerLayout.isDrawerOpen(getTabDrawer())) {
|
if (mDrawerLayout.isDrawerOpen(getTabDrawer())) {
|
||||||
mDrawerLayout.closeDrawer(getTabDrawer());
|
mDrawerLayout.closeDrawer(getTabDrawer());
|
||||||
} else if (mDrawerLayout.isDrawerOpen(getBookmarkDrawer())) {
|
} else if (mDrawerLayout.isDrawerOpen(getBookmarkDrawer())) {
|
||||||
mEventBus.post(new BrowserEvents.UserPressedBack());
|
mBookmarksView.navigateBack();
|
||||||
} else {
|
} else {
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
Log.d(TAG, "onBackPressed");
|
Log.d(TAG, "onBackPressed");
|
||||||
@ -1194,7 +1182,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (mCustomView != null || mCustomViewCallback != null) {
|
if (mCustomView != null || mCustomViewCallback != null) {
|
||||||
onHideCustomView();
|
onHideCustomView();
|
||||||
} else {
|
} else {
|
||||||
deleteTab(mTabsManager.positionOf(currentTab));
|
mPresenter.deleteTab(mTabsManager.positionOf(currentTab));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1491,10 +1479,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
searchTheWeb(url);
|
searchTheWeb(url);
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
mPresenter.onAutoCompleteItemPressed();
|
||||||
if (currentTab != null) {
|
|
||||||
currentTab.requestFocus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -1763,6 +1748,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeBookmarksDrawer() {
|
||||||
|
mDrawerLayout.closeDrawer(getBookmarkDrawer());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHideCustomView() {
|
public void onHideCustomView() {
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
@ -1837,6 +1827,37 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackButtonPressed() {
|
||||||
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
|
if (currentTab != null) {
|
||||||
|
if (currentTab.canGoBack()) {
|
||||||
|
currentTab.goBack();
|
||||||
|
} else {
|
||||||
|
mPresenter.deleteTab(mTabsManager.positionOf(currentTab));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onForwardButtonPressed() {
|
||||||
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
|
if (currentTab != null) {
|
||||||
|
if (currentTab.canGoForward()) {
|
||||||
|
currentTab.goForward();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHomeButtonPressed() {
|
||||||
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
|
if (currentTab != null) {
|
||||||
|
currentTab.loadHomepage();
|
||||||
|
closeDrawers(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets whether or not the activity will display
|
* This method sets whether or not the activity will display
|
||||||
* in full-screen mode (i.e. the ActionBar will be hidden) and
|
* in full-screen mode (i.e. the ActionBar will be hidden) and
|
||||||
@ -1908,7 +1929,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCloseWindow(LightningView view) {
|
public void onCloseWindow(LightningView view) {
|
||||||
deleteTab(mTabsManager.positionOf(view));
|
mPresenter.deleteTab(mTabsManager.positionOf(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1957,10 +1978,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
height = mToolbarLayout.getMeasuredHeight();
|
height = mToolbarLayout.getMeasuredHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
|
||||||
if (currentTab == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
final int totalHeight = height;
|
final int totalHeight = height;
|
||||||
if (mToolbarLayout.getTranslationY() < -(height - 0.01f)) {
|
if (mToolbarLayout.getTranslationY() < -(height - 0.01f)) {
|
||||||
Animation show = new Animation() {
|
Animation show = new Animation() {
|
||||||
@ -2135,7 +2152,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mDrawerHandler.postDelayed(new Runnable() {
|
mDrawerHandler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mDrawerLayout.closeDrawer(mDrawerRight);
|
closeDrawers(null);
|
||||||
}
|
}
|
||||||
}, 150);
|
}, 150);
|
||||||
}
|
}
|
||||||
@ -2227,19 +2244,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link acr.browser.lightning.fragment.BookmarksFragment} send this message on reply
|
|
||||||
* to {@link acr.browser.lightning.bus.BrowserEvents.UserPressedBack} message if the
|
|
||||||
* fragement is showing the boomarks root folder.
|
|
||||||
*
|
|
||||||
* @param event an event notifying the browser that the bookmark drawer
|
|
||||||
* should be closed.
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void closeBookmarks(final BookmarkEvents.CloseBookmarks event) {
|
|
||||||
mDrawerLayout.closeDrawer(mDrawerRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user wants to close a tab
|
* The user wants to close a tab
|
||||||
*
|
*
|
||||||
@ -2247,7 +2251,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void closeTab(final TabEvents.CloseTab event) {
|
public void closeTab(final TabEvents.CloseTab event) {
|
||||||
deleteTab(event.position);
|
mPresenter.deleteTab(event.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2260,67 +2264,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
BrowserActivity.this.showTab(event.position);
|
BrowserActivity.this.showTab(event.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The user long pressed on a tab, ask him if he want to close the tab
|
|
||||||
*
|
|
||||||
* @param event contains the tab position in the tabs adapter
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void showCloseDialog(final TabEvents.ShowCloseDialog event) {
|
|
||||||
BrowserActivity.this.showCloseDialog(event.position);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user wants to create a new tab
|
|
||||||
*
|
|
||||||
* @param event a marker
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void newTab(final TabEvents.NewTab event) {
|
|
||||||
BrowserActivity.this.newTab(null, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user wants to go back on current tab
|
|
||||||
*
|
|
||||||
* @param event a marker
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void goBack(final NavigationEvents.GoBack event) {
|
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
|
||||||
if (currentTab != null) {
|
|
||||||
if (currentTab.canGoBack()) {
|
|
||||||
currentTab.goBack();
|
|
||||||
} else {
|
|
||||||
deleteTab(mTabsManager.positionOf(currentTab));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user wants to go forward on current tab
|
|
||||||
*
|
|
||||||
* @param event a marker
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void goForward(final NavigationEvents.GoForward event) {
|
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
|
||||||
if (currentTab != null) {
|
|
||||||
if (currentTab.canGoForward()) {
|
|
||||||
currentTab.goForward();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void goHome(final NavigationEvents.GoHome event) {
|
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
|
||||||
if (currentTab != null) {
|
|
||||||
currentTab.loadHomepage();
|
|
||||||
closeDrawers(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user long pressed the new tab button
|
* The user long pressed the new tab button
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package acr.browser.lightning.browser;
|
||||||
|
|
||||||
|
public interface BookmarksView {
|
||||||
|
|
||||||
|
void navigateBack();
|
||||||
|
|
||||||
|
}
|
@ -341,4 +341,22 @@ public class BrowserPresenter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onAutoCompleteItemPressed() {
|
||||||
|
final LightningView currentTab = mTabsModel.getCurrentTab();
|
||||||
|
if (currentTab != null) {
|
||||||
|
currentTab.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void findInPage(@NonNull String query) {
|
||||||
|
final LightningView currentView = mTabsModel.getCurrentTab();
|
||||||
|
if (currentView != null) {
|
||||||
|
currentView.find(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAppLowMemory() {
|
||||||
|
mTabsModel.freeMemory();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,6 @@ public final class BookmarkEvents {
|
|||||||
public static class ToggleBookmarkForCurrentPage {
|
public static class ToggleBookmarkForCurrentPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sended by the {@link acr.browser.lightning.fragment.BookmarksFragment} when it wants to close
|
|
||||||
* itself (generally in reply to a {@link acr.browser.lightning.bus.BrowserEvents.UserPressedBack}
|
|
||||||
* event.
|
|
||||||
*/
|
|
||||||
public static class CloseBookmarks {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sended when a bookmark is edited
|
* Sended when a bookmark is edited
|
||||||
*/
|
*/
|
||||||
|
@ -34,12 +34,6 @@ public final class BrowserEvents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify the BookmarksFragment and TabsFragment that the user pressed the back button
|
|
||||||
*/
|
|
||||||
public static class UserPressedBack {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package acr.browser.lightning.bus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collections of navigation events, like go back or go forward
|
|
||||||
*
|
|
||||||
* @author Stefano Pacifici
|
|
||||||
* @date 2015/09/15
|
|
||||||
*/
|
|
||||||
public class NavigationEvents {
|
|
||||||
private NavigationEvents() {
|
|
||||||
// No instances please
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired by {@link acr.browser.lightning.fragment.TabsFragment} when the user presses back
|
|
||||||
* button.
|
|
||||||
*/
|
|
||||||
public static class GoBack {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired by {@link acr.browser.lightning.fragment.TabsFragment} when the user presses forward
|
|
||||||
* button.
|
|
||||||
*/
|
|
||||||
public static class GoForward {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired by {@link acr.browser.lightning.fragment.TabsFragment} when the user presses the home
|
|
||||||
* button.
|
|
||||||
*/
|
|
||||||
public static class GoHome {
|
|
||||||
}
|
|
||||||
}
|
|
@ -37,25 +37,6 @@ public final class TabEvents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sended by {@link acr.browser.lightning.fragment.TabsFragment} when the user long press on the
|
|
||||||
* tab itself.
|
|
||||||
*/
|
|
||||||
public static class ShowCloseDialog {
|
|
||||||
public final int position;
|
|
||||||
|
|
||||||
public ShowCloseDialog(int position) {
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sended by {@link acr.browser.lightning.fragment.TabsFragment} when the user want to create a
|
|
||||||
* new tab.
|
|
||||||
*/
|
|
||||||
public static class NewTab {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sended by {@link acr.browser.lightning.fragment.TabsFragment} when the user long presses on
|
* Sended by {@link acr.browser.lightning.fragment.TabsFragment} when the user long presses on
|
||||||
* new tab button.
|
* new tab button.
|
||||||
|
@ -56,6 +56,8 @@ public interface UIController {
|
|||||||
|
|
||||||
void newTabClicked();
|
void newTabClicked();
|
||||||
|
|
||||||
|
void closeBookmarksDrawer();
|
||||||
|
|
||||||
void setForwardButtonEnabled(boolean enabled);
|
void setForwardButtonEnabled(boolean enabled);
|
||||||
|
|
||||||
void setBackButtonEnabled(boolean enabled);
|
void setBackButtonEnabled(boolean enabled);
|
||||||
@ -64,4 +66,10 @@ public interface UIController {
|
|||||||
|
|
||||||
TabsManager getTabModel();
|
TabsManager getTabModel();
|
||||||
|
|
||||||
|
void onBackButtonPressed();
|
||||||
|
|
||||||
|
void onForwardButtonPressed();
|
||||||
|
|
||||||
|
void onHomeButtonPressed();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,11 @@ import android.widget.ImageView;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.anthonycr.bonsai.Action;
|
||||||
|
import com.anthonycr.bonsai.Observable;
|
||||||
|
import com.anthonycr.bonsai.OnSubscribe;
|
||||||
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
|
import com.anthonycr.bonsai.Subscriber;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
@ -40,6 +45,8 @@ import acr.browser.lightning.activity.ReadingActivity;
|
|||||||
import acr.browser.lightning.activity.TabsManager;
|
import acr.browser.lightning.activity.TabsManager;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.async.AsyncExecutor;
|
import acr.browser.lightning.async.AsyncExecutor;
|
||||||
|
import acr.browser.lightning.async.ImageDownloadTask;
|
||||||
|
import acr.browser.lightning.browser.BookmarksView;
|
||||||
import acr.browser.lightning.bus.BookmarkEvents;
|
import acr.browser.lightning.bus.BookmarkEvents;
|
||||||
import acr.browser.lightning.bus.BrowserEvents;
|
import acr.browser.lightning.bus.BrowserEvents;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
@ -48,18 +55,10 @@ import acr.browser.lightning.database.BookmarkManager;
|
|||||||
import acr.browser.lightning.database.HistoryItem;
|
import acr.browser.lightning.database.HistoryItem;
|
||||||
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.async.ImageDownloadTask;
|
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Action;
|
|
||||||
import com.anthonycr.bonsai.Observable;
|
|
||||||
import com.anthonycr.bonsai.OnSubscribe;
|
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
|
||||||
import com.anthonycr.bonsai.Subscriber;
|
|
||||||
|
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
|
|
||||||
public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener {
|
public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, BookmarksView {
|
||||||
|
|
||||||
private final static String TAG = BookmarksFragment.class.getSimpleName();
|
private final static String TAG = BookmarksFragment.class.getSimpleName();
|
||||||
|
|
||||||
@ -78,6 +77,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
private TabsManager mTabsManager;
|
private TabsManager mTabsManager;
|
||||||
|
|
||||||
|
private UIController mUiController;
|
||||||
|
|
||||||
// Adapter
|
// Adapter
|
||||||
private BookmarkViewAdapter mBookmarkAdapter;
|
private BookmarkViewAdapter mBookmarkAdapter;
|
||||||
|
|
||||||
@ -117,7 +118,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
BrowserApp.getAppComponent().inject(this);
|
BrowserApp.getAppComponent().inject(this);
|
||||||
final Bundle arguments = getArguments();
|
final Bundle arguments = getArguments();
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
mTabsManager = ((UIController) context).getTabModel();
|
mUiController = (UIController) context;
|
||||||
|
mTabsManager = mUiController.getTabModel();
|
||||||
mIsIncognito = arguments.getBoolean(INCOGNITO_MODE, false);
|
mIsIncognito = arguments.getBoolean(INCOGNITO_MODE, false);
|
||||||
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || mIsIncognito;
|
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || mIsIncognito;
|
||||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
|
||||||
@ -247,16 +249,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void userPressedBack(final BrowserEvents.UserPressedBack event) {
|
|
||||||
if (mBookmarkManager.isRootFolder()) {
|
|
||||||
mEventBus.post(new BookmarkEvents.CloseBookmarks());
|
|
||||||
} else {
|
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
|
||||||
mBookmarksListView.setSelection(mScrollIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void bookmarkDeleted(@NonNull final BookmarkEvents.Deleted event) {
|
public void bookmarkDeleted(@NonNull final BookmarkEvents.Deleted event) {
|
||||||
mBookmarks.remove(event.item);
|
mBookmarks.remove(event.item);
|
||||||
@ -365,6 +357,16 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void navigateBack() {
|
||||||
|
if (mBookmarkManager.isRootFolder()) {
|
||||||
|
mUiController.closeBookmarksDrawer();
|
||||||
|
} else {
|
||||||
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
||||||
|
mBookmarksListView.setSelection(mScrollIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class BookmarkViewAdapter extends ArrayAdapter<HistoryItem> {
|
private class BookmarkViewAdapter extends ArrayAdapter<HistoryItem> {
|
||||||
|
|
||||||
final Context context;
|
final Context context;
|
||||||
|
@ -39,7 +39,6 @@ import acr.browser.lightning.R;
|
|||||||
import acr.browser.lightning.activity.TabsManager;
|
import acr.browser.lightning.activity.TabsManager;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.browser.TabsView;
|
import acr.browser.lightning.browser.TabsView;
|
||||||
import acr.browser.lightning.bus.NavigationEvents;
|
|
||||||
import acr.browser.lightning.bus.TabEvents;
|
import acr.browser.lightning.bus.TabEvents;
|
||||||
import acr.browser.lightning.controller.UIController;
|
import acr.browser.lightning.controller.UIController;
|
||||||
import acr.browser.lightning.fragment.anim.HorizontalItemAnimator;
|
import acr.browser.lightning.fragment.anim.HorizontalItemAnimator;
|
||||||
@ -215,16 +214,16 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
mUiController.showCloseDialog(mTabsManager.indexOfCurrentTab());
|
mUiController.showCloseDialog(mTabsManager.indexOfCurrentTab());
|
||||||
break;
|
break;
|
||||||
case R.id.new_tab_button:
|
case R.id.new_tab_button:
|
||||||
mBus.post(new TabEvents.NewTab());
|
mUiController.newTabClicked();
|
||||||
break;
|
break;
|
||||||
case R.id.action_back:
|
case R.id.action_back:
|
||||||
mBus.post(new NavigationEvents.GoBack());
|
mUiController.onBackButtonPressed();
|
||||||
break;
|
break;
|
||||||
case R.id.action_forward:
|
case R.id.action_forward:
|
||||||
mBus.post(new NavigationEvents.GoForward());
|
mUiController.onForwardButtonPressed();
|
||||||
break;
|
break;
|
||||||
case R.id.action_home:
|
case R.id.action_home:
|
||||||
mBus.post(new NavigationEvents.GoHome());
|
mUiController.onHomeButtonPressed();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -416,8 +415,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
// Show close dialog
|
mUiController.showCloseDialog(getAdapterPosition());
|
||||||
mBus.post(new TabEvents.ShowCloseDialog(getAdapterPosition()));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user