Removing event buss
This commit is contained in:
parent
923e71d51f
commit
0fcf7451cb
@ -75,9 +75,6 @@ dependencies {
|
|||||||
// html parsing for reading mode
|
// html parsing for reading mode
|
||||||
compile 'org.jsoup:jsoup:1.10.2'
|
compile 'org.jsoup:jsoup:1.10.2'
|
||||||
|
|
||||||
// event bus
|
|
||||||
compile 'com.squareup:otto:1.3.8'
|
|
||||||
|
|
||||||
// dependency injection
|
// dependency injection
|
||||||
def daggerVersion = '2.10'
|
def daggerVersion = '2.10'
|
||||||
compile "com.google.dagger:dagger:$daggerVersion"
|
compile "com.google.dagger:dagger:$daggerVersion"
|
||||||
|
@ -84,8 +84,6 @@ import com.anthonycr.bonsai.Schedulers;
|
|||||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||||
import com.anthonycr.grant.PermissionsManager;
|
import com.anthonycr.grant.PermissionsManager;
|
||||||
import com.anthonycr.progress.AnimatedProgressBar;
|
import com.anthonycr.progress.AnimatedProgressBar;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -98,8 +96,6 @@ 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.BrowserEvents;
|
|
||||||
import acr.browser.lightning.constant.BookmarkPage;
|
import acr.browser.lightning.constant.BookmarkPage;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.constant.HistoryPage;
|
import acr.browser.lightning.constant.HistoryPage;
|
||||||
@ -189,9 +185,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
// The singleton BookmarkManager
|
// The singleton BookmarkManager
|
||||||
@Inject BookmarkManager mBookmarkManager;
|
@Inject BookmarkManager mBookmarkManager;
|
||||||
|
|
||||||
// Event bus
|
|
||||||
@Inject Bus mEventBus;
|
|
||||||
|
|
||||||
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
||||||
|
|
||||||
private TabsManager mTabsManager;
|
private TabsManager mTabsManager;
|
||||||
@ -1119,6 +1112,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}, 150);
|
}, 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleHistoryChange() {
|
||||||
|
openHistory();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displays the WebView contained in the LightningView Also handles the
|
* displays the WebView contained in the LightningView Also handles the
|
||||||
* removal of previous views
|
* removal of previous views
|
||||||
@ -1288,8 +1286,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (isIncognito() && isFinishing()) {
|
if (isIncognito() && isFinishing()) {
|
||||||
overridePendingTransition(R.anim.fade_in_scale, R.anim.slide_down_out);
|
overridePendingTransition(R.anim.fade_in_scale, R.anim.slide_down_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
mEventBus.unregister(mBusEventListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveOpenTabs() {
|
void saveOpenTabs() {
|
||||||
@ -1348,8 +1344,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
filter.addAction(NETWORK_BROADCAST_ACTION);
|
filter.addAction(NETWORK_BROADCAST_ACTION);
|
||||||
getApplication().registerReceiver(mNetworkReceiver, filter);
|
getApplication().registerReceiver(mNetworkReceiver, filter);
|
||||||
|
|
||||||
mEventBus.register(mBusEventListener);
|
|
||||||
|
|
||||||
if (mFullScreen) {
|
if (mFullScreen) {
|
||||||
overlayToolbarOnWebView();
|
overlayToolbarOnWebView();
|
||||||
} else {
|
} else {
|
||||||
@ -2080,6 +2074,43 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleBookmarksChange() {
|
||||||
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
|
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
|
||||||
|
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
||||||
|
currentTab.loadBookmarkpage();
|
||||||
|
}
|
||||||
|
if (currentTab != null) {
|
||||||
|
mBookmarksView.handleUpdatedUrl(currentTab.getUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleBookmarkDeleted(@NonNull HistoryItem item) {
|
||||||
|
mBookmarksView.handleBookmarkDeleted(item);
|
||||||
|
handleBookmarksChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleNewTab(@NonNull LightningDialogBuilder.NewTab newTabType, @NonNull String url) {
|
||||||
|
mDrawerLayout.closeDrawers();
|
||||||
|
switch (newTabType) {
|
||||||
|
case FOREGROUND:
|
||||||
|
newTab(url, true);
|
||||||
|
break;
|
||||||
|
case BACKGROUND:
|
||||||
|
newTab(url, false);
|
||||||
|
break;
|
||||||
|
case INCOGNITO:
|
||||||
|
Intent intent = new Intent(BrowserActivity.this, IncognitoActivity.class);
|
||||||
|
intent.setData(Uri.parse(url));
|
||||||
|
startActivity(intent);
|
||||||
|
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs an action when the provided view is laid out.
|
* Performs an action when the provided view is laid out.
|
||||||
*
|
*
|
||||||
@ -2220,66 +2251,4 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Object mBusEventListener = new Object() {
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void loadHistory(final BrowserEvents.OpenHistoryInCurrentTab event) {
|
|
||||||
openHistory();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the given url in a new tab, used by the the
|
|
||||||
* {@link acr.browser.lightning.fragment.BookmarksFragment} and by the
|
|
||||||
* {@link LightningDialogBuilder}
|
|
||||||
*
|
|
||||||
* @param event Bus event indicating that the user wishes
|
|
||||||
* to open a bookmark in a new tab
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void loadUrlInNewTab(final BrowserEvents.OpenUrlInNewTab event) {
|
|
||||||
mDrawerLayout.closeDrawers();
|
|
||||||
if (event.location == BrowserEvents.OpenUrlInNewTab.Location.NEW_TAB) {
|
|
||||||
newTab(event.url, true);
|
|
||||||
} else if (event.location == BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND) {
|
|
||||||
newTab(event.url, false);
|
|
||||||
} else if (event.location == BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO) {
|
|
||||||
Intent intent = new Intent(BrowserActivity.this, IncognitoActivity.class);
|
|
||||||
intent.setData(Uri.parse(event.url));
|
|
||||||
startActivity(intent);
|
|
||||||
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is called when the user edits a bookmark.
|
|
||||||
*
|
|
||||||
* @param event the event that the bookmark has changed.
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void bookmarkChanged(final BookmarkEvents.BookmarkChanged event) {
|
|
||||||
handleBookmarksChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify the browser that a bookmark was deleted.
|
|
||||||
*
|
|
||||||
* @param event the event that the bookmark has been deleted
|
|
||||||
*/
|
|
||||||
@Subscribe
|
|
||||||
public void bookmarkDeleted(final BookmarkEvents.Deleted event) {
|
|
||||||
handleBookmarksChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleBookmarksChange() {
|
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
|
||||||
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
|
|
||||||
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
|
||||||
currentTab.loadBookmarkpage();
|
|
||||||
}
|
|
||||||
if (currentTab != null) {
|
|
||||||
mBookmarksView.handleUpdatedUrl(currentTab.getUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@ import android.webkit.WebView;
|
|||||||
import com.anthonycr.bonsai.Completable;
|
import com.anthonycr.bonsai.Completable;
|
||||||
import com.anthonycr.bonsai.CompletableAction;
|
import com.anthonycr.bonsai.CompletableAction;
|
||||||
import com.anthonycr.bonsai.CompletableSubscriber;
|
import com.anthonycr.bonsai.CompletableSubscriber;
|
||||||
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||||
import com.anthonycr.bonsai.Stream;
|
import com.anthonycr.bonsai.Stream;
|
||||||
import com.anthonycr.bonsai.StreamAction;
|
import com.anthonycr.bonsai.StreamAction;
|
||||||
import com.anthonycr.bonsai.StreamOnSubscribe;
|
import com.anthonycr.bonsai.StreamOnSubscribe;
|
||||||
import com.anthonycr.bonsai.StreamSubscriber;
|
import com.anthonycr.bonsai.StreamSubscriber;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -38,9 +38,6 @@ import acr.browser.lightning.constant.StartPage;
|
|||||||
import acr.browser.lightning.database.BookmarkManager;
|
import acr.browser.lightning.database.BookmarkManager;
|
||||||
import acr.browser.lightning.dialog.BrowserDialog;
|
import acr.browser.lightning.dialog.BrowserDialog;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
|
||||||
|
|
||||||
import acr.browser.lightning.utils.FileUtils;
|
import acr.browser.lightning.utils.FileUtils;
|
||||||
import acr.browser.lightning.utils.Preconditions;
|
import acr.browser.lightning.utils.Preconditions;
|
||||||
import acr.browser.lightning.utils.UrlUtils;
|
import acr.browser.lightning.utils.UrlUtils;
|
||||||
@ -67,7 +64,6 @@ public class TabsManager {
|
|||||||
|
|
||||||
@Inject PreferenceManager mPreferenceManager;
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
@Inject BookmarkManager mBookmarkManager;
|
@Inject BookmarkManager mBookmarkManager;
|
||||||
@Inject Bus mEventBus;
|
|
||||||
@Inject Application mApp;
|
@Inject Application mApp;
|
||||||
|
|
||||||
public TabsManager() {
|
public TabsManager() {
|
||||||
|
@ -4,8 +4,6 @@ import android.app.Application;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import net.i2p.android.ui.I2PAndroidHelper;
|
import net.i2p.android.ui.I2PAndroidHelper;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -16,11 +14,9 @@ import dagger.Provides;
|
|||||||
@Module
|
@Module
|
||||||
public class AppModule {
|
public class AppModule {
|
||||||
private final BrowserApp mApp;
|
private final BrowserApp mApp;
|
||||||
@NonNull private final Bus mBus;
|
|
||||||
|
|
||||||
public AppModule(BrowserApp app) {
|
public AppModule(BrowserApp app) {
|
||||||
this.mApp = app;
|
this.mApp = app;
|
||||||
this.mBus = new Bus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@ -33,12 +29,6 @@ public class AppModule {
|
|||||||
return mApp.getApplicationContext();
|
return mApp.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Provides
|
|
||||||
public Bus provideBus() {
|
|
||||||
return mBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -13,7 +13,6 @@ import android.util.Log;
|
|||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import com.squareup.leakcanary.LeakCanary;
|
import com.squareup.leakcanary.LeakCanary;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -34,7 +33,6 @@ public class BrowserApp extends Application {
|
|||||||
private static final Executor mIOThread = Executors.newSingleThreadExecutor();
|
private static final Executor mIOThread = Executors.newSingleThreadExecutor();
|
||||||
private static final Executor mTaskThread = Executors.newCachedThreadPool();
|
private static final Executor mTaskThread = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
@Inject Bus mBus;
|
|
||||||
@Inject PreferenceManager mPreferenceManager;
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,10 +2,14 @@ package acr.browser.lightning.browser;
|
|||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import acr.browser.lightning.database.HistoryItem;
|
||||||
|
|
||||||
public interface BookmarksView {
|
public interface BookmarksView {
|
||||||
|
|
||||||
void navigateBack();
|
void navigateBack();
|
||||||
|
|
||||||
void handleUpdatedUrl(@NonNull String url);
|
void handleUpdatedUrl(@NonNull String url);
|
||||||
|
|
||||||
|
void handleBookmarkDeleted(@NonNull HistoryItem item);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -34,7 +33,6 @@ public class BrowserPresenter {
|
|||||||
|
|
||||||
@NonNull private final TabsManager mTabsModel;
|
@NonNull private final TabsManager mTabsModel;
|
||||||
@Inject PreferenceManager mPreferences;
|
@Inject PreferenceManager mPreferences;
|
||||||
@Inject Bus mEventBus;
|
|
||||||
|
|
||||||
@NonNull private final BrowserView mView;
|
@NonNull private final BrowserView mView;
|
||||||
@Nullable private LightningView mCurrentTab;
|
@Nullable private LightningView mCurrentTab;
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package acr.browser.lightning.bus;
|
|
||||||
|
|
||||||
import acr.browser.lightning.database.HistoryItem;
|
|
||||||
|
|
||||||
public final class BookmarkEvents {
|
|
||||||
|
|
||||||
private BookmarkEvents() {
|
|
||||||
// No instances
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user ask to delete the selected bookmark
|
|
||||||
*/
|
|
||||||
public static class Deleted {
|
|
||||||
public final HistoryItem item;
|
|
||||||
|
|
||||||
public Deleted(final HistoryItem item) {
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sended when a bookmark is edited
|
|
||||||
*/
|
|
||||||
public static class BookmarkChanged {
|
|
||||||
|
|
||||||
public BookmarkChanged() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package acr.browser.lightning.bus;
|
|
||||||
|
|
||||||
public final class BrowserEvents {
|
|
||||||
|
|
||||||
private BrowserEvents() {
|
|
||||||
// No instances
|
|
||||||
}
|
|
||||||
|
|
||||||
public final static class OpenHistoryInCurrentTab {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user ask to open the given url as new tab
|
|
||||||
*/
|
|
||||||
public final static class OpenUrlInNewTab {
|
|
||||||
|
|
||||||
public enum Location {
|
|
||||||
NEW_TAB,
|
|
||||||
BACKGROUND,
|
|
||||||
INCOGNITO
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String url;
|
|
||||||
|
|
||||||
public final Location location;
|
|
||||||
|
|
||||||
public OpenUrlInNewTab(final String url) {
|
|
||||||
this.url = url;
|
|
||||||
this.location = Location.NEW_TAB;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OpenUrlInNewTab(final String url, Location location) {
|
|
||||||
this.url = url;
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,6 +16,7 @@ import android.webkit.WebChromeClient.CustomViewCallback;
|
|||||||
|
|
||||||
import acr.browser.lightning.activity.TabsManager;
|
import acr.browser.lightning.activity.TabsManager;
|
||||||
import acr.browser.lightning.database.HistoryItem;
|
import acr.browser.lightning.database.HistoryItem;
|
||||||
|
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
|
|
||||||
public interface UIController {
|
public interface UIController {
|
||||||
@ -83,4 +84,12 @@ public interface UIController {
|
|||||||
|
|
||||||
void onHomeButtonPressed();
|
void onHomeButtonPressed();
|
||||||
|
|
||||||
|
void handleBookmarksChange();
|
||||||
|
|
||||||
|
void handleBookmarkDeleted(@NonNull HistoryItem item);
|
||||||
|
|
||||||
|
void handleNewTab(@NonNull LightningDialogBuilder.NewTab newTabType, @NonNull String url);
|
||||||
|
|
||||||
|
void handleHistoryChange();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import android.widget.EditText;
|
|||||||
|
|
||||||
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,10 +22,9 @@ import javax.inject.Inject;
|
|||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.activity.MainActivity;
|
import acr.browser.lightning.activity.MainActivity;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.bus.BookmarkEvents;
|
|
||||||
import acr.browser.lightning.bus.BrowserEvents;
|
|
||||||
import acr.browser.lightning.constant.BookmarkPage;
|
import acr.browser.lightning.constant.BookmarkPage;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
|
import acr.browser.lightning.controller.UIController;
|
||||||
import acr.browser.lightning.database.BookmarkManager;
|
import acr.browser.lightning.database.BookmarkManager;
|
||||||
import acr.browser.lightning.database.HistoryItem;
|
import acr.browser.lightning.database.HistoryItem;
|
||||||
import acr.browser.lightning.database.HistoryModel;
|
import acr.browser.lightning.database.HistoryModel;
|
||||||
@ -40,9 +38,14 @@ import acr.browser.lightning.utils.Utils;
|
|||||||
*/
|
*/
|
||||||
public class LightningDialogBuilder {
|
public class LightningDialogBuilder {
|
||||||
|
|
||||||
|
public enum NewTab {
|
||||||
|
FOREGROUND,
|
||||||
|
BACKGROUND,
|
||||||
|
INCOGNITO
|
||||||
|
}
|
||||||
|
|
||||||
@Inject BookmarkManager mBookmarkManager;
|
@Inject BookmarkManager mBookmarkManager;
|
||||||
@Inject PreferenceManager mPreferenceManager;
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
@Inject Bus mEventBus;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public LightningDialogBuilder() {
|
public LightningDialogBuilder() {
|
||||||
@ -53,10 +56,12 @@ public class LightningDialogBuilder {
|
|||||||
* Show the appropriated dialog for the long pressed link. It means that we try to understand
|
* Show the appropriated dialog for the long pressed link. It means that we try to understand
|
||||||
* if the link is relative to a bookmark or is just a folder.
|
* if the link is relative to a bookmark or is just a folder.
|
||||||
*
|
*
|
||||||
* @param context used to show the dialog
|
* @param activity used to show the dialog
|
||||||
* @param url the long pressed url
|
* @param url the long pressed url
|
||||||
*/
|
*/
|
||||||
public void showLongPressedDialogForBookmarkUrl(@NonNull final Activity context, @NonNull final String url) {
|
public void showLongPressedDialogForBookmarkUrl(@NonNull final Activity activity,
|
||||||
|
@NonNull UIController uiController,
|
||||||
|
@NonNull final String url) {
|
||||||
final HistoryItem item;
|
final HistoryItem item;
|
||||||
if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) {
|
if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) {
|
||||||
// TODO hacky, make a better bookmark mechanism in the future
|
// TODO hacky, make a better bookmark mechanism in the future
|
||||||
@ -73,56 +78,60 @@ public class LightningDialogBuilder {
|
|||||||
}
|
}
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (item.isFolder()) {
|
if (item.isFolder()) {
|
||||||
showBookmarkFolderLongPressedDialog(context, item);
|
showBookmarkFolderLongPressedDialog(activity, uiController, item);
|
||||||
} else {
|
} else {
|
||||||
showLongPressedDialogForBookmarkUrl(context, item);
|
showLongPressedDialogForBookmarkUrl(activity, uiController, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLongPressedDialogForBookmarkUrl(@NonNull final Activity activity, @NonNull final HistoryItem item) {
|
public void showLongPressedDialogForBookmarkUrl(@NonNull final Activity activity,
|
||||||
|
@NonNull final UIController uiController,
|
||||||
|
@NonNull final HistoryItem item) {
|
||||||
BrowserDialog.show(activity, R.string.action_bookmarks,
|
BrowserDialog.show(activity, R.string.action_bookmarks,
|
||||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(item.getUrl(), BrowserEvents.OpenUrlInNewTab.Location.NEW_TAB));
|
uiController.handleNewTab(NewTab.FOREGROUND, item.getUrl());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
uiController.handleNewTab(NewTab.BACKGROUND, item.getUrl());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
uiController.handleNewTab(NewTab.INCOGNITO, item.getUrl());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
BrowserApp.copyToClipboard(activity, item.getUrl());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BrowserDialog.Item(R.string.dialog_remove_bookmark) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
if (mBookmarkManager.deleteBookmark(item)) {
|
||||||
|
uiController.handleBookmarkDeleted(item);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
},
|
||||||
@Override
|
new BrowserDialog.Item(R.string.dialog_edit_bookmark) {
|
||||||
public void onClick() {
|
@Override
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(item.getUrl(), BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
public void onClick() {
|
||||||
}
|
showEditBookmarkDialog(activity, uiController, item);
|
||||||
},
|
}
|
||||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
});
|
||||||
@Override
|
|
||||||
public void onClick() {
|
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(item.getUrl(), BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
|
||||||
@Override
|
|
||||||
public void onClick() {
|
|
||||||
BrowserApp.copyToClipboard(activity, item.getUrl());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new BrowserDialog.Item(R.string.dialog_remove_bookmark) {
|
|
||||||
@Override
|
|
||||||
public void onClick() {
|
|
||||||
if (mBookmarkManager.deleteBookmark(item)) {
|
|
||||||
mEventBus.post(new BookmarkEvents.Deleted(item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new BrowserDialog.Item(R.string.dialog_edit_bookmark) {
|
|
||||||
@Override
|
|
||||||
public void onClick() {
|
|
||||||
showEditBookmarkDialog(activity, item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showEditBookmarkDialog(@NonNull final Activity activity, @NonNull final HistoryItem item) {
|
private void showEditBookmarkDialog(@NonNull final Activity activity,
|
||||||
|
@NonNull final UIController uiController,
|
||||||
|
@NonNull final HistoryItem item) {
|
||||||
final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity);
|
final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity);
|
||||||
editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
|
editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
|
||||||
final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null);
|
final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null);
|
||||||
@ -131,175 +140,185 @@ public class LightningDialogBuilder {
|
|||||||
final EditText getUrl = (EditText) dialogLayout.findViewById(R.id.bookmark_url);
|
final EditText getUrl = (EditText) dialogLayout.findViewById(R.id.bookmark_url);
|
||||||
getUrl.setText(item.getUrl());
|
getUrl.setText(item.getUrl());
|
||||||
final AutoCompleteTextView getFolder =
|
final AutoCompleteTextView getFolder =
|
||||||
(AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder);
|
(AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder);
|
||||||
getFolder.setHint(R.string.folder);
|
getFolder.setHint(R.string.folder);
|
||||||
getFolder.setText(item.getFolder());
|
getFolder.setText(item.getFolder());
|
||||||
final List<String> folders = mBookmarkManager.getFolderTitles();
|
final List<String> folders = mBookmarkManager.getFolderTitles();
|
||||||
final ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(activity,
|
final ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(activity,
|
||||||
android.R.layout.simple_dropdown_item_1line, folders);
|
android.R.layout.simple_dropdown_item_1line, folders);
|
||||||
getFolder.setThreshold(1);
|
getFolder.setThreshold(1);
|
||||||
getFolder.setAdapter(suggestionsAdapter);
|
getFolder.setAdapter(suggestionsAdapter);
|
||||||
editBookmarkDialog.setView(dialogLayout);
|
editBookmarkDialog.setView(dialogLayout);
|
||||||
editBookmarkDialog.setPositiveButton(activity.getString(R.string.action_ok),
|
editBookmarkDialog.setPositiveButton(activity.getString(R.string.action_ok),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
HistoryItem editedItem = new HistoryItem();
|
HistoryItem editedItem = new HistoryItem();
|
||||||
editedItem.setTitle(getTitle.getText().toString());
|
editedItem.setTitle(getTitle.getText().toString());
|
||||||
editedItem.setUrl(getUrl.getText().toString());
|
editedItem.setUrl(getUrl.getText().toString());
|
||||||
editedItem.setUrl(getUrl.getText().toString());
|
editedItem.setUrl(getUrl.getText().toString());
|
||||||
editedItem.setFolder(getFolder.getText().toString());
|
editedItem.setFolder(getFolder.getText().toString());
|
||||||
mBookmarkManager.editBookmark(item, editedItem);
|
mBookmarkManager.editBookmark(item, editedItem);
|
||||||
mEventBus.post(new BookmarkEvents.BookmarkChanged());
|
uiController.handleBookmarksChange();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Dialog dialog = editBookmarkDialog.show();
|
Dialog dialog = editBookmarkDialog.show();
|
||||||
BrowserDialog.setDialogSize(activity, dialog);
|
BrowserDialog.setDialogSize(activity, dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showBookmarkFolderLongPressedDialog(@NonNull final Activity activity, @NonNull final HistoryItem item) {
|
public void showBookmarkFolderLongPressedDialog(@NonNull final Activity activity,
|
||||||
|
@NonNull final UIController uiController,
|
||||||
|
@NonNull final HistoryItem item) {
|
||||||
|
|
||||||
BrowserDialog.show(activity, R.string.action_folder,
|
BrowserDialog.show(activity, R.string.action_folder,
|
||||||
new BrowserDialog.Item(R.string.dialog_rename_folder) {
|
new BrowserDialog.Item(R.string.dialog_rename_folder) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
showRenameFolderDialog(activity, item);
|
showRenameFolderDialog(activity, uiController, item);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_remove_folder) {
|
new BrowserDialog.Item(R.string.dialog_remove_folder) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mBookmarkManager.deleteFolder(item.getTitle());
|
mBookmarkManager.deleteFolder(item.getTitle());
|
||||||
mEventBus.post(new BookmarkEvents.Deleted(item));
|
uiController.handleBookmarkDeleted(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showRenameFolderDialog(@NonNull final Activity activity, @NonNull final HistoryItem item) {
|
private void showRenameFolderDialog(@NonNull final Activity activity,
|
||||||
|
@NonNull final UIController uiController,
|
||||||
|
@NonNull final HistoryItem item) {
|
||||||
BrowserDialog.showEditText(activity, R.string.title_rename_folder,
|
BrowserDialog.showEditText(activity, R.string.title_rename_folder,
|
||||||
R.string.hint_title, item.getTitle(),
|
R.string.hint_title, item.getTitle(),
|
||||||
R.string.action_ok, new BrowserDialog.EditorListener() {
|
R.string.action_ok, new BrowserDialog.EditorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NonNull String text) {
|
public void onClick(@NonNull String text) {
|
||||||
if (!TextUtils.isEmpty(text)) {
|
if (!TextUtils.isEmpty(text)) {
|
||||||
final String oldTitle = item.getTitle();
|
final String oldTitle = item.getTitle();
|
||||||
final HistoryItem editedItem = new HistoryItem();
|
final HistoryItem editedItem = new HistoryItem();
|
||||||
editedItem.setTitle(text);
|
editedItem.setTitle(text);
|
||||||
editedItem.setUrl(Constants.FOLDER + text);
|
editedItem.setUrl(Constants.FOLDER + text);
|
||||||
editedItem.setFolder(item.getFolder());
|
editedItem.setFolder(item.getFolder());
|
||||||
editedItem.setIsFolder(true);
|
editedItem.setIsFolder(true);
|
||||||
mBookmarkManager.renameFolder(oldTitle, text);
|
mBookmarkManager.renameFolder(oldTitle, text);
|
||||||
mEventBus.post(new BookmarkEvents.BookmarkChanged());
|
uiController.handleBookmarksChange();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLongPressedHistoryLinkDialog(@NonNull final Activity activity, @NonNull final String url) {
|
public void showLongPressedHistoryLinkDialog(@NonNull final Activity activity,
|
||||||
|
@NonNull final UIController uiController,
|
||||||
|
@NonNull final String url) {
|
||||||
BrowserDialog.show(activity, R.string.action_history,
|
BrowserDialog.show(activity, R.string.action_history,
|
||||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url));
|
uiController.handleNewTab(NewTab.FOREGROUND, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
uiController.handleNewTab(NewTab.BACKGROUND, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO));
|
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
BrowserApp.copyToClipboard(activity, url);
|
BrowserApp.copyToClipboard(activity, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_remove_from_history) {
|
new BrowserDialog.Item(R.string.dialog_remove_from_history) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
HistoryModel.deleteHistoryItem(url)
|
HistoryModel.deleteHistoryItem(url)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(Schedulers.main())
|
.observeOn(Schedulers.main())
|
||||||
.subscribe(new CompletableOnSubscribe() {
|
.subscribe(new CompletableOnSubscribe() {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
mEventBus.post(new BrowserEvents.OpenHistoryInCurrentTab());
|
uiController.handleHistoryChange();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO There should be a way in which we do not need an activity reference to dowload a file
|
// TODO There should be a way in which we do not need an activity reference to dowload a file
|
||||||
public void showLongPressImageDialog(@NonNull final Activity activity, @NonNull final String url,
|
public void showLongPressImageDialog(@NonNull final Activity activity,
|
||||||
|
@NonNull final UIController uiController,
|
||||||
|
@NonNull final String url,
|
||||||
@NonNull final String userAgent) {
|
@NonNull final String userAgent) {
|
||||||
BrowserDialog.show(activity, url.replace(Constants.HTTP, ""),
|
BrowserDialog.show(activity, url.replace(Constants.HTTP, ""),
|
||||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url));
|
uiController.handleNewTab(NewTab.FOREGROUND, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
uiController.handleNewTab(NewTab.BACKGROUND, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO));
|
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
BrowserApp.copyToClipboard(activity, url);
|
BrowserApp.copyToClipboard(activity, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_download_image) {
|
new BrowserDialog.Item(R.string.dialog_download_image) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
Utils.downloadFile(activity, mPreferenceManager, url, userAgent, "attachment");
|
Utils.downloadFile(activity, mPreferenceManager, url, userAgent, "attachment");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLongPressLinkDialog(@NonNull final Activity activity, @NonNull final String url) {
|
public void showLongPressLinkDialog(@NonNull final Activity activity,
|
||||||
|
@NonNull final UIController uiController,
|
||||||
|
@NonNull final String url) {
|
||||||
BrowserDialog.show(activity, url,
|
BrowserDialog.show(activity, url,
|
||||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url));
|
uiController.handleNewTab(NewTab.FOREGROUND, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
uiController.handleNewTab(NewTab.BACKGROUND, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO));
|
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
BrowserApp.copyToClipboard(activity, url);
|
BrowserApp.copyToClipboard(activity, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,6 @@ import com.anthonycr.bonsai.SingleAction;
|
|||||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||||
import com.anthonycr.bonsai.SingleSubscriber;
|
import com.anthonycr.bonsai.SingleSubscriber;
|
||||||
import com.anthonycr.bonsai.Subscription;
|
import com.anthonycr.bonsai.Subscription;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -47,7 +45,6 @@ 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.browser.BookmarksView;
|
import acr.browser.lightning.browser.BookmarksView;
|
||||||
import acr.browser.lightning.bus.BookmarkEvents;
|
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.controller.UIController;
|
import acr.browser.lightning.controller.UIController;
|
||||||
import acr.browser.lightning.database.BookmarkManager;
|
import acr.browser.lightning.database.BookmarkManager;
|
||||||
@ -80,9 +77,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
// Managers
|
// Managers
|
||||||
@Inject BookmarkManager mBookmarkManager;
|
@Inject BookmarkManager mBookmarkManager;
|
||||||
|
|
||||||
// Event bus
|
|
||||||
@Inject Bus mEventBus;
|
|
||||||
|
|
||||||
// Dialog builder
|
// Dialog builder
|
||||||
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
||||||
|
|
||||||
@ -248,13 +242,11 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
mEventBus.register(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
mEventBus.unregister(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reinitializePreferences() {
|
public void reinitializePreferences() {
|
||||||
@ -279,10 +271,10 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Override
|
||||||
public void bookmarkDeleted(@NonNull final BookmarkEvents.Deleted event) {
|
public void handleBookmarkDeleted(@NonNull HistoryItem item) {
|
||||||
mBookmarks.remove(event.item);
|
mBookmarks.remove(item);
|
||||||
if (event.item.isFolder()) {
|
if (item.isFolder()) {
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||||
} else {
|
} else {
|
||||||
mBookmarkAdapter.notifyDataSetChanged();
|
mBookmarkAdapter.notifyDataSetChanged();
|
||||||
@ -349,9 +341,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
private void handleLongPress(@NonNull final HistoryItem item) {
|
private void handleLongPress(@NonNull final HistoryItem item) {
|
||||||
if (item.isFolder()) {
|
if (item.isFolder()) {
|
||||||
mBookmarksDialogBuilder.showBookmarkFolderLongPressedDialog(getActivity(), item);
|
mBookmarksDialogBuilder.showBookmarkFolderLongPressedDialog(getActivity(), mUiController, item);
|
||||||
} else {
|
} else {
|
||||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(getActivity(), item);
|
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(getActivity(), mUiController, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,6 @@ import android.widget.ImageView;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
@ -93,7 +91,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
private Unbinder mUnbinder;
|
private Unbinder mUnbinder;
|
||||||
|
|
||||||
private TabsManager mTabsManager;
|
private TabsManager mTabsManager;
|
||||||
@Inject Bus mBus;
|
|
||||||
@Inject PreferenceManager mPreferences;
|
@Inject PreferenceManager mPreferences;
|
||||||
|
|
||||||
public TabsFragment() {
|
public TabsFragment() {
|
||||||
@ -192,12 +189,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
mBus.register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@ -207,12 +198,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
mBus.unregister(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tabsInitialized() {
|
public void tabsInitialized() {
|
||||||
if (mTabsAdapter != null) {
|
if (mTabsAdapter != null) {
|
||||||
|
@ -7,8 +7,6 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import net.i2p.android.ui.I2PAndroidHelper;
|
import net.i2p.android.ui.I2PAndroidHelper;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -33,7 +31,6 @@ public class ProxyUtils {
|
|||||||
|
|
||||||
@Inject PreferenceManager mPreferences;
|
@Inject PreferenceManager mPreferences;
|
||||||
@Inject I2PAndroidHelper mI2PHelper;
|
@Inject I2PAndroidHelper mI2PHelper;
|
||||||
@Inject Bus mBus;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ProxyUtils() {
|
public ProxyUtils() {
|
||||||
|
@ -36,7 +36,6 @@ import com.anthonycr.bonsai.Single;
|
|||||||
import com.anthonycr.bonsai.SingleAction;
|
import com.anthonycr.bonsai.SingleAction;
|
||||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||||
import com.anthonycr.bonsai.SingleSubscriber;
|
import com.anthonycr.bonsai.SingleSubscriber;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
@ -108,7 +107,6 @@ public class LightningView {
|
|||||||
@NonNull private final WebViewHandler mWebViewHandler = new WebViewHandler(this);
|
@NonNull private final WebViewHandler mWebViewHandler = new WebViewHandler(this);
|
||||||
@NonNull private final Map<String, String> mRequestHeaders = new ArrayMap<>();
|
@NonNull private final Map<String, String> mRequestHeaders = new ArrayMap<>();
|
||||||
|
|
||||||
@Inject Bus mEventBus;
|
|
||||||
@Inject PreferenceManager mPreferences;
|
@Inject PreferenceManager mPreferences;
|
||||||
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
||||||
@Inject ProxyUtils mProxyUtils;
|
@Inject ProxyUtils mProxyUtils;
|
||||||
@ -974,36 +972,36 @@ public class LightningView {
|
|||||||
if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) {
|
if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) {
|
||||||
if (currentUrl.endsWith(HistoryPage.FILENAME)) {
|
if (currentUrl.endsWith(HistoryPage.FILENAME)) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, url);
|
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity,mUIController, url);
|
||||||
} else if (result != null && result.getExtra() != null) {
|
} else if (result != null && result.getExtra() != null) {
|
||||||
final String newUrl = result.getExtra();
|
final String newUrl = result.getExtra();
|
||||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, newUrl);
|
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl);
|
||||||
}
|
}
|
||||||
} else if (currentUrl.endsWith(BookmarkPage.FILENAME)) {
|
} else if (currentUrl.endsWith(BookmarkPage.FILENAME)) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, url);
|
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url);
|
||||||
} else if (result != null && result.getExtra() != null) {
|
} else if (result != null && result.getExtra() != null) {
|
||||||
final String newUrl = result.getExtra();
|
final String newUrl = result.getExtra();
|
||||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, newUrl);
|
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
|
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
|
||||||
mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, url, getUserAgent());
|
mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, mUIController, url, getUserAgent());
|
||||||
} else {
|
} else {
|
||||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url);
|
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url);
|
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url);
|
||||||
}
|
}
|
||||||
} else if (result != null && result.getExtra() != null) {
|
} else if (result != null && result.getExtra() != null) {
|
||||||
final String newUrl = result.getExtra();
|
final String newUrl = result.getExtra();
|
||||||
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
|
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
|
||||||
mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, newUrl, getUserAgent());
|
mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, mUIController, newUrl, getUserAgent());
|
||||||
} else {
|
} else {
|
||||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, newUrl);
|
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, newUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user