Removing event buss
This commit is contained in:
parent
923e71d51f
commit
0fcf7451cb
@ -75,9 +75,6 @@ dependencies {
|
||||
// html parsing for reading mode
|
||||
compile 'org.jsoup:jsoup:1.10.2'
|
||||
|
||||
// event bus
|
||||
compile 'com.squareup:otto:1.3.8'
|
||||
|
||||
// dependency injection
|
||||
def daggerVersion = '2.10'
|
||||
compile "com.google.dagger:dagger:$daggerVersion"
|
||||
|
@ -84,8 +84,6 @@ import com.anthonycr.bonsai.Schedulers;
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
import com.anthonycr.grant.PermissionsManager;
|
||||
import com.anthonycr.progress.AnimatedProgressBar;
|
||||
import com.squareup.otto.Bus;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import java.io.File;
|
||||
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.BrowserView;
|
||||
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.Constants;
|
||||
import acr.browser.lightning.constant.HistoryPage;
|
||||
@ -189,9 +185,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
// The singleton BookmarkManager
|
||||
@Inject BookmarkManager mBookmarkManager;
|
||||
|
||||
// Event bus
|
||||
@Inject Bus mEventBus;
|
||||
|
||||
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
||||
|
||||
private TabsManager mTabsManager;
|
||||
@ -1119,6 +1112,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
}, 150);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleHistoryChange() {
|
||||
openHistory();
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the WebView contained in the LightningView Also handles the
|
||||
* removal of previous views
|
||||
@ -1288,8 +1286,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
if (isIncognito() && isFinishing()) {
|
||||
overridePendingTransition(R.anim.fade_in_scale, R.anim.slide_down_out);
|
||||
}
|
||||
|
||||
mEventBus.unregister(mBusEventListener);
|
||||
}
|
||||
|
||||
void saveOpenTabs() {
|
||||
@ -1348,8 +1344,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
filter.addAction(NETWORK_BROADCAST_ACTION);
|
||||
getApplication().registerReceiver(mNetworkReceiver, filter);
|
||||
|
||||
mEventBus.register(mBusEventListener);
|
||||
|
||||
if (mFullScreen) {
|
||||
overlayToolbarOnWebView();
|
||||
} 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.
|
||||
*
|
||||
@ -2220,66 +2251,4 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
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.CompletableAction;
|
||||
import com.anthonycr.bonsai.CompletableSubscriber;
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
import com.anthonycr.bonsai.Stream;
|
||||
import com.anthonycr.bonsai.StreamAction;
|
||||
import com.anthonycr.bonsai.StreamOnSubscribe;
|
||||
import com.anthonycr.bonsai.StreamSubscriber;
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -38,9 +38,6 @@ import acr.browser.lightning.constant.StartPage;
|
||||
import acr.browser.lightning.database.BookmarkManager;
|
||||
import acr.browser.lightning.dialog.BrowserDialog;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
|
||||
import acr.browser.lightning.utils.FileUtils;
|
||||
import acr.browser.lightning.utils.Preconditions;
|
||||
import acr.browser.lightning.utils.UrlUtils;
|
||||
@ -67,7 +64,6 @@ public class TabsManager {
|
||||
|
||||
@Inject PreferenceManager mPreferenceManager;
|
||||
@Inject BookmarkManager mBookmarkManager;
|
||||
@Inject Bus mEventBus;
|
||||
@Inject Application mApp;
|
||||
|
||||
public TabsManager() {
|
||||
|
@ -4,8 +4,6 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import net.i2p.android.ui.I2PAndroidHelper;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@ -16,11 +14,9 @@ import dagger.Provides;
|
||||
@Module
|
||||
public class AppModule {
|
||||
private final BrowserApp mApp;
|
||||
@NonNull private final Bus mBus;
|
||||
|
||||
public AppModule(BrowserApp app) {
|
||||
this.mApp = app;
|
||||
this.mBus = new Bus();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@ -33,12 +29,6 @@ public class AppModule {
|
||||
return mApp.getApplicationContext();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Provides
|
||||
public Bus provideBus() {
|
||||
return mBus;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Provides
|
||||
@Singleton
|
||||
|
@ -13,7 +13,6 @@ import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
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 mTaskThread = Executors.newCachedThreadPool();
|
||||
|
||||
@Inject Bus mBus;
|
||||
@Inject PreferenceManager mPreferenceManager;
|
||||
|
||||
@Override
|
||||
|
@ -2,10 +2,14 @@ package acr.browser.lightning.browser;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import acr.browser.lightning.database.HistoryItem;
|
||||
|
||||
public interface BookmarksView {
|
||||
|
||||
void navigateBack();
|
||||
|
||||
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.Schedulers;
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -34,7 +33,6 @@ public class BrowserPresenter {
|
||||
|
||||
@NonNull private final TabsManager mTabsModel;
|
||||
@Inject PreferenceManager mPreferences;
|
||||
@Inject Bus mEventBus;
|
||||
|
||||
@NonNull private final BrowserView mView;
|
||||
@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.database.HistoryItem;
|
||||
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||
import acr.browser.lightning.view.LightningView;
|
||||
|
||||
public interface UIController {
|
||||
@ -83,4 +84,12 @@ public interface UIController {
|
||||
|
||||
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.Schedulers;
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -23,10 +22,9 @@ import javax.inject.Inject;
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.activity.MainActivity;
|
||||
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.Constants;
|
||||
import acr.browser.lightning.controller.UIController;
|
||||
import acr.browser.lightning.database.BookmarkManager;
|
||||
import acr.browser.lightning.database.HistoryItem;
|
||||
import acr.browser.lightning.database.HistoryModel;
|
||||
@ -40,9 +38,14 @@ import acr.browser.lightning.utils.Utils;
|
||||
*/
|
||||
public class LightningDialogBuilder {
|
||||
|
||||
public enum NewTab {
|
||||
FOREGROUND,
|
||||
BACKGROUND,
|
||||
INCOGNITO
|
||||
}
|
||||
|
||||
@Inject BookmarkManager mBookmarkManager;
|
||||
@Inject PreferenceManager mPreferenceManager;
|
||||
@Inject Bus mEventBus;
|
||||
|
||||
@Inject
|
||||
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
|
||||
* if the link is relative to a bookmark or is just a folder.
|
||||
*
|
||||
* @param context used to show the dialog
|
||||
* @param url the long pressed url
|
||||
* @param activity used to show the dialog
|
||||
* @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;
|
||||
if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) {
|
||||
// TODO hacky, make a better bookmark mechanism in the future
|
||||
@ -73,56 +78,60 @@ public class LightningDialogBuilder {
|
||||
}
|
||||
if (item != null) {
|
||||
if (item.isFolder()) {
|
||||
showBookmarkFolderLongPressedDialog(context, item);
|
||||
showBookmarkFolderLongPressedDialog(activity, uiController, item);
|
||||
} 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,
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(item.getUrl(), BrowserEvents.OpenUrlInNewTab.Location.NEW_TAB));
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
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
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(item.getUrl(), BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
||||
}
|
||||
},
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_edit_bookmark) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
showEditBookmarkDialog(activity, uiController, 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);
|
||||
editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
|
||||
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);
|
||||
getUrl.setText(item.getUrl());
|
||||
final AutoCompleteTextView getFolder =
|
||||
(AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder);
|
||||
(AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder);
|
||||
getFolder.setHint(R.string.folder);
|
||||
getFolder.setText(item.getFolder());
|
||||
final List<String> folders = mBookmarkManager.getFolderTitles();
|
||||
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.setAdapter(suggestionsAdapter);
|
||||
editBookmarkDialog.setView(dialogLayout);
|
||||
editBookmarkDialog.setPositiveButton(activity.getString(R.string.action_ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
HistoryItem editedItem = new HistoryItem();
|
||||
editedItem.setTitle(getTitle.getText().toString());
|
||||
editedItem.setUrl(getUrl.getText().toString());
|
||||
editedItem.setUrl(getUrl.getText().toString());
|
||||
editedItem.setFolder(getFolder.getText().toString());
|
||||
mBookmarkManager.editBookmark(item, editedItem);
|
||||
mEventBus.post(new BookmarkEvents.BookmarkChanged());
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
HistoryItem editedItem = new HistoryItem();
|
||||
editedItem.setTitle(getTitle.getText().toString());
|
||||
editedItem.setUrl(getUrl.getText().toString());
|
||||
editedItem.setUrl(getUrl.getText().toString());
|
||||
editedItem.setFolder(getFolder.getText().toString());
|
||||
mBookmarkManager.editBookmark(item, editedItem);
|
||||
uiController.handleBookmarksChange();
|
||||
}
|
||||
});
|
||||
Dialog dialog = editBookmarkDialog.show();
|
||||
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,
|
||||
new BrowserDialog.Item(R.string.dialog_rename_folder) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
showRenameFolderDialog(activity, item);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_remove_folder) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mBookmarkManager.deleteFolder(item.getTitle());
|
||||
mEventBus.post(new BookmarkEvents.Deleted(item));
|
||||
}
|
||||
});
|
||||
new BrowserDialog.Item(R.string.dialog_rename_folder) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
showRenameFolderDialog(activity, uiController, item);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_remove_folder) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mBookmarkManager.deleteFolder(item.getTitle());
|
||||
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,
|
||||
R.string.hint_title, item.getTitle(),
|
||||
R.string.action_ok, new BrowserDialog.EditorListener() {
|
||||
@Override
|
||||
public void onClick(@NonNull String text) {
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
final String oldTitle = item.getTitle();
|
||||
final HistoryItem editedItem = new HistoryItem();
|
||||
editedItem.setTitle(text);
|
||||
editedItem.setUrl(Constants.FOLDER + text);
|
||||
editedItem.setFolder(item.getFolder());
|
||||
editedItem.setIsFolder(true);
|
||||
mBookmarkManager.renameFolder(oldTitle, text);
|
||||
mEventBus.post(new BookmarkEvents.BookmarkChanged());
|
||||
}
|
||||
R.string.hint_title, item.getTitle(),
|
||||
R.string.action_ok, new BrowserDialog.EditorListener() {
|
||||
@Override
|
||||
public void onClick(@NonNull String text) {
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
final String oldTitle = item.getTitle();
|
||||
final HistoryItem editedItem = new HistoryItem();
|
||||
editedItem.setTitle(text);
|
||||
editedItem.setUrl(Constants.FOLDER + text);
|
||||
editedItem.setFolder(item.getFolder());
|
||||
editedItem.setIsFolder(true);
|
||||
mBookmarkManager.renameFolder(oldTitle, text);
|
||||
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,
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
BrowserApp.copyToClipboard(activity, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_remove_from_history) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
HistoryModel.deleteHistoryItem(url)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new CompletableOnSubscribe() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mEventBus.post(new BrowserEvents.OpenHistoryInCurrentTab());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.FOREGROUND, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.BACKGROUND, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
BrowserApp.copyToClipboard(activity, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_remove_from_history) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
HistoryModel.deleteHistoryItem(url)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new CompletableOnSubscribe() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
uiController.handleHistoryChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 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) {
|
||||
BrowserDialog.show(activity, url.replace(Constants.HTTP, ""),
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
BrowserApp.copyToClipboard(activity, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_download_image) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
Utils.downloadFile(activity, mPreferenceManager, url, userAgent, "attachment");
|
||||
}
|
||||
});
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.FOREGROUND, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.BACKGROUND, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
BrowserApp.copyToClipboard(activity, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_download_image) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
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,
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.BACKGROUND));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url, BrowserEvents.OpenUrlInNewTab.Location.INCOGNITO));
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
BrowserApp.copyToClipboard(activity, url);
|
||||
}
|
||||
});
|
||||
new BrowserDialog.Item(R.string.dialog_open_new_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.FOREGROUND, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_background_tab) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.BACKGROUND, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_open_incognito_tab, activity instanceof MainActivity) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||
}
|
||||
},
|
||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
BrowserApp.copyToClipboard(activity, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,8 +33,6 @@ import com.anthonycr.bonsai.SingleAction;
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
import com.anthonycr.bonsai.SingleSubscriber;
|
||||
import com.anthonycr.bonsai.Subscription;
|
||||
import com.squareup.otto.Bus;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
@ -47,7 +45,6 @@ import acr.browser.lightning.activity.ReadingActivity;
|
||||
import acr.browser.lightning.activity.TabsManager;
|
||||
import acr.browser.lightning.app.BrowserApp;
|
||||
import acr.browser.lightning.browser.BookmarksView;
|
||||
import acr.browser.lightning.bus.BookmarkEvents;
|
||||
import acr.browser.lightning.constant.Constants;
|
||||
import acr.browser.lightning.controller.UIController;
|
||||
import acr.browser.lightning.database.BookmarkManager;
|
||||
@ -80,9 +77,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
// Managers
|
||||
@Inject BookmarkManager mBookmarkManager;
|
||||
|
||||
// Event bus
|
||||
@Inject Bus mEventBus;
|
||||
|
||||
// Dialog builder
|
||||
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
||||
|
||||
@ -248,13 +242,11 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mEventBus.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
mEventBus.unregister(this);
|
||||
}
|
||||
|
||||
public void reinitializePreferences() {
|
||||
@ -279,10 +271,10 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void bookmarkDeleted(@NonNull final BookmarkEvents.Deleted event) {
|
||||
mBookmarks.remove(event.item);
|
||||
if (event.item.isFolder()) {
|
||||
@Override
|
||||
public void handleBookmarkDeleted(@NonNull HistoryItem item) {
|
||||
mBookmarks.remove(item);
|
||||
if (item.isFolder()) {
|
||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||
} else {
|
||||
mBookmarkAdapter.notifyDataSetChanged();
|
||||
@ -349,9 +341,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
|
||||
private void handleLongPress(@NonNull final HistoryItem item) {
|
||||
if (item.isFolder()) {
|
||||
mBookmarksDialogBuilder.showBookmarkFolderLongPressedDialog(getActivity(), item);
|
||||
mBookmarksDialogBuilder.showBookmarkFolderLongPressedDialog(getActivity(), mUiController, item);
|
||||
} 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.TextView;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import acr.browser.lightning.R;
|
||||
@ -93,7 +91,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
||||
private Unbinder mUnbinder;
|
||||
|
||||
private TabsManager mTabsManager;
|
||||
@Inject Bus mBus;
|
||||
@Inject PreferenceManager mPreferences;
|
||||
|
||||
public TabsFragment() {
|
||||
@ -192,12 +189,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
||||
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mBus.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void 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
|
||||
public void tabsInitialized() {
|
||||
if (mTabsAdapter != null) {
|
||||
|
@ -7,8 +7,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import net.i2p.android.ui.I2PAndroidHelper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -33,7 +31,6 @@ public class ProxyUtils {
|
||||
|
||||
@Inject PreferenceManager mPreferences;
|
||||
@Inject I2PAndroidHelper mI2PHelper;
|
||||
@Inject Bus mBus;
|
||||
|
||||
@Inject
|
||||
public ProxyUtils() {
|
||||
|
@ -36,7 +36,6 @@ import com.anthonycr.bonsai.Single;
|
||||
import com.anthonycr.bonsai.SingleAction;
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
import com.anthonycr.bonsai.SingleSubscriber;
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
@ -108,7 +107,6 @@ public class LightningView {
|
||||
@NonNull private final WebViewHandler mWebViewHandler = new WebViewHandler(this);
|
||||
@NonNull private final Map<String, String> mRequestHeaders = new ArrayMap<>();
|
||||
|
||||
@Inject Bus mEventBus;
|
||||
@Inject PreferenceManager mPreferences;
|
||||
@Inject LightningDialogBuilder mBookmarksDialogBuilder;
|
||||
@Inject ProxyUtils mProxyUtils;
|
||||
@ -974,36 +972,36 @@ public class LightningView {
|
||||
if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) {
|
||||
if (currentUrl.endsWith(HistoryPage.FILENAME)) {
|
||||
if (url != null) {
|
||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, url);
|
||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity,mUIController, url);
|
||||
} else if (result != null && result.getExtra() != null) {
|
||||
final String newUrl = result.getExtra();
|
||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, newUrl);
|
||||
mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl);
|
||||
}
|
||||
} else if (currentUrl.endsWith(BookmarkPage.FILENAME)) {
|
||||
if (url != null) {
|
||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, url);
|
||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url);
|
||||
} else if (result != null && result.getExtra() != null) {
|
||||
final String newUrl = result.getExtra();
|
||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, newUrl);
|
||||
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (url != null) {
|
||||
if (result != null) {
|
||||
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 {
|
||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url);
|
||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url);
|
||||
}
|
||||
} else {
|
||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url);
|
||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url);
|
||||
}
|
||||
} else if (result != null && result.getExtra() != null) {
|
||||
final String newUrl = result.getExtra();
|
||||
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 {
|
||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, newUrl);
|
||||
mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, newUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user