Updating bonsai

This commit is contained in:
anthony restaino 2017-03-18 22:20:57 -04:00
parent 5bdc9294db
commit 77a2f61df3
14 changed files with 181 additions and 178 deletions

2
Bonsai

@ -1 +1 @@
Subproject commit 68eb7eb377803f7971baedb28144aa3b1c420cd0 Subproject commit d47c9626c2583b09a1102a980186f9ca51bc4e29

View File

@ -80,6 +80,7 @@ import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener; import android.widget.TextView.OnEditorActionListener;
import android.widget.VideoView; import android.widget.VideoView;
import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.Observable; import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.grant.PermissionsManager; import com.anthonycr.grant.PermissionsManager;
@ -225,7 +226,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
public abstract void updateHistory(@Nullable final String title, @NonNull final String url); public abstract void updateHistory(@Nullable final String title, @NonNull final String url);
abstract Observable<Void> updateCookiePreference(); abstract Completable updateCookiePreference();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {

View File

@ -8,19 +8,20 @@ import android.view.Menu;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.CompletableAction;
import com.anthonycr.bonsai.CompletableSubscriber;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import com.anthonycr.bonsai.Action;
import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.Subscriber;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class IncognitoActivity extends BrowserActivity { public class IncognitoActivity extends BrowserActivity {
@Override @Override
public Observable<Void> updateCookiePreference() { public Completable updateCookiePreference() {
return Observable.create(new Action<Void>() { return Completable.create(new CompletableAction() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<Void> subscriber) { public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
CookieManager cookieManager = CookieManager.getInstance(); CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(IncognitoActivity.this); CookieSyncManager.createInstance(IncognitoActivity.this);

View File

@ -8,19 +8,20 @@ import android.view.Menu;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.CompletableAction;
import com.anthonycr.bonsai.CompletableSubscriber;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import com.anthonycr.bonsai.Action;
import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.Subscriber;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class MainActivity extends BrowserActivity { public class MainActivity extends BrowserActivity {
@Override @Override
public Observable<Void> updateCookiePreference() { public Completable updateCookiePreference() {
return Observable.create(new Action<Void>() { return Completable.create(new CompletableAction() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<Void> subscriber) { public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
CookieManager cookieManager = CookieManager.getInstance(); CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(MainActivity.this); CookieSyncManager.createInstance(MainActivity.this);

View File

@ -30,11 +30,11 @@ import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
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.Action;
import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.OnSubscribe;
import com.anthonycr.bonsai.Subscriber;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleOnSubscribe;
import com.anthonycr.bonsai.SingleSubscriber;
import com.anthonycr.bonsai.Subscription; import com.anthonycr.bonsai.Subscription;
import acr.browser.lightning.reading.HtmlFetcher; import acr.browser.lightning.reading.HtmlFetcher;
import acr.browser.lightning.reading.JResult; import acr.browser.lightning.reading.JResult;
@ -152,7 +152,7 @@ public class ReadingActivity extends AppCompatActivity {
getSupportActionBar().setTitle(Utils.getDomainName(mUrl)); getSupportActionBar().setTitle(Utils.getDomainName(mUrl));
mPageLoaderSubscription = loadPage(mUrl).subscribeOn(Schedulers.worker()) mPageLoaderSubscription = loadPage(mUrl).subscribeOn(Schedulers.worker())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new OnSubscribe<ReaderInfo>() { .subscribe(new SingleOnSubscribe<ReaderInfo>() {
@Override @Override
public void onStart() { public void onStart() {
mProgressDialog = new ProgressDialog(ReadingActivity.this); mProgressDialog = new ProgressDialog(ReadingActivity.this);
@ -165,7 +165,7 @@ public class ReadingActivity extends AppCompatActivity {
} }
@Override @Override
public void onNext(@Nullable ReaderInfo item) { public void onItem(@Nullable ReaderInfo item) {
if (item == null || item.getTitle().isEmpty() || item.getBody().isEmpty()) { if (item == null || item.getTitle().isEmpty() || item.getBody().isEmpty()) {
setText(getString(R.string.untitled), getString(R.string.loading_failed)); setText(getString(R.string.untitled), getString(R.string.loading_failed));
} else { } else {
@ -193,14 +193,14 @@ public class ReadingActivity extends AppCompatActivity {
return true; return true;
} }
private static Observable<ReaderInfo> loadPage(@NonNull final String url) { private static Single<ReaderInfo> loadPage(@NonNull final String url) {
return Observable.create(new Action<ReaderInfo>() { return Single.create(new SingleAction<ReaderInfo>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<ReaderInfo> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<ReaderInfo> subscriber) {
HtmlFetcher fetcher = new HtmlFetcher(); HtmlFetcher fetcher = new HtmlFetcher();
try { try {
JResult result = fetcher.fetchAndExtract(url, 2500, true); JResult result = fetcher.fetchAndExtract(url, 2500, true);
subscriber.onNext(new ReaderInfo(result.getTitle(), result.getText())); subscriber.onItem(new ReaderInfo(result.getTitle(), result.getText()));
} catch (Exception e) { } catch (Exception e) {
subscriber.onError(new Throwable("Encountered exception")); subscriber.onError(new Throwable("Encountered exception"));
Log.e(TAG, "Error parsing page", e); Log.e(TAG, "Error parsing page", e);

View File

@ -14,6 +14,14 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.webkit.WebView; import android.webkit.WebView;
import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.CompletableAction;
import com.anthonycr.bonsai.CompletableSubscriber;
import com.anthonycr.bonsai.ObservableSubscriber;
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 com.squareup.otto.Bus;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,11 +40,7 @@ import acr.browser.lightning.database.HistoryDatabase;
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.Action;
import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.OnSubscribe;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Subscriber;
import acr.browser.lightning.utils.FileUtils; import acr.browser.lightning.utils.FileUtils;
import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.UrlUtils;
@ -108,13 +112,12 @@ public class TabsManager {
* @param intent the intent that started the browser activity. * @param intent the intent that started the browser activity.
* @param incognito whether or not we are in incognito mode. * @param incognito whether or not we are in incognito mode.
*/ */
public synchronized Observable<Void> initializeTabs(@NonNull final Activity activity, public synchronized Completable initializeTabs(@NonNull final Activity activity,
@Nullable final Intent intent, @Nullable final Intent intent,
final boolean incognito) { final boolean incognito) {
return Observable.create(new Action<Void>() { return Completable.create(new CompletableAction() {
@Override @Override
public void onSubscribe(@NonNull final Subscriber<Void> subscriber) { public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
// Make sure we start with a clean tab list // Make sure we start with a clean tab list
shutdown(); shutdown();
@ -150,12 +153,12 @@ public class TabsManager {
} }
private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity, private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity,
@NonNull final Subscriber subscriber) { @NonNull final CompletableSubscriber subscriber) {
restoreState().subscribeOn(Schedulers.io()) restoreState().subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<Bundle>() { .observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<Bundle>() {
@Override @Override
public void onNext(Bundle item) { public void onItem(@Nullable Bundle item) {
LightningView tab = newTab(activity, "", false); LightningView tab = newTab(activity, "", false);
String url = item.getString(URL_KEY); String url = item.getString(URL_KEY);
if (url != null && tab.getWebView() != null) { if (url != null && tab.getWebView() != null) {
@ -477,16 +480,16 @@ public class TabsManager {
* and will delete the saved instance file when * and will delete the saved instance file when
* restoration is complete. * restoration is complete.
*/ */
private Observable<Bundle> restoreState() { private Single<Bundle> restoreState() {
return Observable.create(new Action<Bundle>() { return Single.create(new SingleAction<Bundle>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<Bundle> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<Bundle> subscriber) {
Bundle savedState = FileUtils.readBundleFromStorage(mApp, BUNDLE_STORAGE); Bundle savedState = FileUtils.readBundleFromStorage(mApp, BUNDLE_STORAGE);
if (savedState != null) { if (savedState != null) {
Log.d(Constants.TAG, "Restoring previous WebView state now"); Log.d(Constants.TAG, "Restoring previous WebView state now");
for (String key : savedState.keySet()) { for (String key : savedState.keySet()) {
if (key.startsWith(BUNDLE_KEY)) { if (key.startsWith(BUNDLE_KEY)) {
subscriber.onNext(savedState.getBundle(key)); subscriber.onItem(savedState.getBundle(key));
} }
} }
} }

View File

@ -7,6 +7,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import com.anthonycr.bonsai.CompletableOnSubscribe;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
@ -19,8 +20,6 @@ import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.controller.UIController; import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import com.anthonycr.bonsai.OnSubscribe;
import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.UrlUtils;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;
@ -64,16 +63,16 @@ public class BrowserPresenter {
*/ */
public void setupTabs(@Nullable Intent intent) { public void setupTabs(@Nullable Intent intent) {
mTabsModel.initializeTabs((Activity) mView, intent, mIsIncognito) mTabsModel.initializeTabs((Activity) mView, intent, mIsIncognito)
.subscribeOn(Schedulers.main()) .subscribeOn(Schedulers.main())
.subscribe(new OnSubscribe<Void>() { .subscribe(new CompletableOnSubscribe() {
@Override @Override
public void onComplete() { public void onComplete() {
// At this point we always have at least a tab in the tab manager // At this point we always have at least a tab in the tab manager
mView.notifyTabViewInitialized(); mView.notifyTabViewInitialized();
mView.updateTabNumber(mTabsModel.size()); mView.updateTabNumber(mTabsModel.size());
tabChanged(mTabsModel.last()); tabChanged(mTabsModel.last());
} }
}); });
} }
/** /**

View File

@ -8,12 +8,13 @@ import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread; import android.support.annotation.WorkerThread;
import android.util.Log; import android.util.Log;
import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleSubscriber;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.anthonycr.bonsai.Action;
import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.Subscriber;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
public class BookmarkLocalSync { public class BookmarkLocalSync {
@ -89,10 +90,10 @@ public class BookmarkLocalSync {
} }
@NonNull @NonNull
public Observable<List<Source>> getSupportedBrowsers() { public Single<List<Source>> getSupportedBrowsers() {
return Observable.create(new Action<List<Source>>() { return Single.create(new SingleAction<List<Source>>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<List<Source>> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<List<Source>> subscriber) {
List<Source> sources = new ArrayList<>(1); List<Source> sources = new ArrayList<>(1);
if (isBrowserSupported(STOCK_BOOKMARKS_CONTENT)) { if (isBrowserSupported(STOCK_BOOKMARKS_CONTENT)) {
sources.add(Source.STOCK); sources.add(Source.STOCK);
@ -106,7 +107,7 @@ public class BookmarkLocalSync {
if (isBrowserSupported(CHROME_DEV_BOOKMARKS_CONTENT)) { if (isBrowserSupported(CHROME_DEV_BOOKMARKS_CONTENT)) {
sources.add(Source.CHROME_DEV); sources.add(Source.CHROME_DEV);
} }
subscriber.onNext(sources); subscriber.onItem(sources);
subscriber.onComplete(); subscriber.onComplete();
} }
}); });

View File

@ -21,6 +21,7 @@ import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import com.anthonycr.bonsai.SingleOnSubscribe;
import com.anthonycr.grant.PermissionsManager; import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction; import com.anthonycr.grant.PermissionsResultAction;
@ -40,7 +41,6 @@ import acr.browser.lightning.database.BookmarkLocalSync;
import acr.browser.lightning.database.BookmarkLocalSync.Source; import acr.browser.lightning.database.BookmarkLocalSync.Source;
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 com.anthonycr.bonsai.OnSubscribe;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.dialog.BrowserDialog;
@ -213,14 +213,14 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
return true; return true;
case SETTINGS_IMPORT_BROWSER: case SETTINGS_IMPORT_BROWSER:
getSync().getSupportedBrowsers().subscribeOn(Schedulers.worker()) getSync().getSupportedBrowsers().subscribeOn(Schedulers.worker())
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<List<Source>>() { .observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<List<Source>>() {
@Override @Override
public void onNext(@Nullable List<Source> items) { public void onItem(@Nullable List<Source> item) {
Activity activity = getActivity(); Activity activity = getActivity();
if (items == null || activity == null) { if (item == null || activity == null) {
return; return;
} }
List<String> titles = buildTitleList(activity, items); List<String> titles = buildTitleList(activity, item);
showChooserDialog(activity, titles); showChooserDialog(activity, titles);
} }
}); });

View File

@ -27,11 +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.Schedulers;
import com.anthonycr.bonsai.Subscriber; 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 com.squareup.otto.Bus;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
@ -96,15 +96,15 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
private boolean mIsIncognito; private boolean mIsIncognito;
private Observable<BookmarkViewAdapter> initBookmarkManager() { private Single<BookmarkViewAdapter> initBookmarkManager() {
return Observable.create(new Action<BookmarkViewAdapter>() { return Single.create(new SingleAction<BookmarkViewAdapter>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<BookmarkViewAdapter> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<BookmarkViewAdapter> subscriber) {
Context context = getContext(); Context context = getContext();
if (context != null) { if (context != null) {
mBookmarkAdapter = new BookmarkViewAdapter(context, mBookmarks); mBookmarkAdapter = new BookmarkViewAdapter(context, mBookmarks);
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false); setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
subscriber.onNext(mBookmarkAdapter); subscriber.onItem(mBookmarkAdapter);
} }
subscriber.onComplete(); subscriber.onComplete();
} }
@ -191,13 +191,13 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
setupNavigationButton(view, R.id.action_toggle_desktop, R.id.icon_desktop); setupNavigationButton(view, R.id.action_toggle_desktop, R.id.icon_desktop);
initBookmarkManager().subscribeOn(Schedulers.io()) initBookmarkManager().subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new OnSubscribe<BookmarkViewAdapter>() { .subscribe(new SingleOnSubscribe<BookmarkViewAdapter>() {
@Override @Override
public void onNext(@Nullable BookmarkViewAdapter item) { public void onItem(@Nullable BookmarkViewAdapter item) {
mBookmarksListView.setAdapter(mBookmarkAdapter); mBookmarksListView.setAdapter(mBookmarkAdapter);
} }
}); });
return view; return view;
} }

View File

@ -15,12 +15,15 @@ import android.widget.Filterable;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.anthonycr.bonsai.Action; import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.Observable; import com.anthonycr.bonsai.CompletableAction;
import com.anthonycr.bonsai.OnSubscribe; import com.anthonycr.bonsai.CompletableSubscriber;
import com.anthonycr.bonsai.Scheduler; import com.anthonycr.bonsai.Scheduler;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Subscriber; import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleOnSubscribe;
import com.anthonycr.bonsai.SingleSubscriber;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
@ -98,16 +101,15 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
} }
public void refreshBookmarks() { public void refreshBookmarks() {
Observable.create(new Action<Void>() { Completable.create(new CompletableAction() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<Void> subscriber) { public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
mAllBookmarks.clear(); mAllBookmarks.clear();
mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true)); mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true));
subscriber.onComplete(); subscriber.onComplete();
} }
}).subscribeOn(Schedulers.io()) }).subscribeOn(Schedulers.io()).subscribe();
.subscribe();
} }
@Override @Override
@ -200,25 +202,25 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
} }
private void clearSuggestions() { private void clearSuggestions() {
Observable.create(new Action<Void>() { Completable.create(new CompletableAction() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<Void> subscriber) { public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
mBookmarks.clear(); mBookmarks.clear();
mHistory.clear(); mHistory.clear();
mSuggestions.clear(); mSuggestions.clear();
subscriber.onComplete(); subscriber.onComplete();
} }
}).subscribeOn(FILTER_SCHEDULER) }).subscribeOn(FILTER_SCHEDULER)
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(); .subscribe();
} }
private void combineResults(final @Nullable List<HistoryItem> bookmarkList, private void combineResults(final @Nullable List<HistoryItem> bookmarkList,
final @Nullable List<HistoryItem> historyList, final @Nullable List<HistoryItem> historyList,
final @Nullable List<HistoryItem> suggestionList) { final @Nullable List<HistoryItem> suggestionList) {
Observable.create(new Action<List<HistoryItem>>() { Single.create(new SingleAction<List<HistoryItem>>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
List<HistoryItem> list = new ArrayList<>(5); List<HistoryItem> list = new ArrayList<>(5);
if (bookmarkList != null) { if (bookmarkList != null) {
mBookmarks.clear(); mBookmarks.clear();
@ -251,25 +253,24 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
} }
Collections.sort(list, mFilterComparator); Collections.sort(list, mFilterComparator);
subscriber.onNext(list); subscriber.onItem(list);
subscriber.onComplete(); subscriber.onComplete();
} }
}).subscribeOn(FILTER_SCHEDULER) }).subscribeOn(FILTER_SCHEDULER)
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new OnSubscribe<List<HistoryItem>>() { .subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override @Override
public void onNext(@Nullable List<HistoryItem> item) { public void onItem(@Nullable List<HistoryItem> item) {
publishResults(item); publishResults(item);
} }
}); });
} }
@NonNull @NonNull
private Observable<List<HistoryItem>> getBookmarksForQuery(@NonNull final String query) { private Single<List<HistoryItem>> getBookmarksForQuery(@NonNull final String query) {
return Observable.create(new Action<List<HistoryItem>>() { return Single.create(new SingleAction<List<HistoryItem>>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
List<HistoryItem> bookmarks = new ArrayList<>(5); List<HistoryItem> bookmarks = new ArrayList<>(5);
int counter = 0; int counter = 0;
for (int n = 0; n < mAllBookmarks.size(); n++) { for (int n = 0; n < mAllBookmarks.size(); n++) {
@ -285,36 +286,30 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
counter++; counter++;
} }
} }
subscriber.onNext(bookmarks); subscriber.onItem(bookmarks);
subscriber.onComplete(); subscriber.onComplete();
} }
}); });
} }
@NonNull @NonNull
private Observable<List<HistoryItem>> getSuggestionsForQuery(@NonNull final String query) { private Single<List<HistoryItem>> getSuggestionsForQuery(@NonNull final String query) {
if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_GOOGLE) { if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_GOOGLE) {
return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.GOOGLE); return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.GOOGLE);
} else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) { } else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) {
return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.DUCK); return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.DUCK);
} else { } else {
return Observable.create(new Action<List<HistoryItem>>() { return Single.empty();
@Override
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) {
//TODO add an Observable.empty() method to generate an empty Observable
subscriber.onComplete();
}
});
} }
} }
@NonNull @NonNull
private Observable<List<HistoryItem>> getHistoryForQuery(@NonNull final String query) { private Single<List<HistoryItem>> getHistoryForQuery(@NonNull final String query) {
return Observable.create(new Action<List<HistoryItem>>() { return Single.create(new SingleAction<List<HistoryItem>>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
List<HistoryItem> historyList = mDatabaseHandler.findItemsContaining(query); List<HistoryItem> historyList = mDatabaseHandler.findItemsContaining(query);
subscriber.onNext(historyList); subscriber.onItem(historyList);
subscriber.onComplete(); subscriber.onComplete();
} }
}); });
@ -345,9 +340,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
mSuggestionsAdapter.getSuggestionsForQuery(query) mSuggestionsAdapter.getSuggestionsForQuery(query)
.subscribeOn(Schedulers.worker()) .subscribeOn(Schedulers.worker())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new OnSubscribe<List<HistoryItem>>() { .subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override @Override
public void onNext(@Nullable List<HistoryItem> item) { public void onItem(@Nullable List<HistoryItem> item) {
mSuggestionsAdapter.combineResults(null, null, item); mSuggestionsAdapter.combineResults(null, null, item);
} }
}); });
@ -356,9 +351,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
mSuggestionsAdapter.getBookmarksForQuery(query) mSuggestionsAdapter.getBookmarksForQuery(query)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new OnSubscribe<List<HistoryItem>>() { .subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override @Override
public void onNext(@Nullable List<HistoryItem> item) { public void onItem(@Nullable List<HistoryItem> item) {
mSuggestionsAdapter.combineResults(item, null, null); mSuggestionsAdapter.combineResults(item, null, null);
} }
}); });
@ -366,9 +361,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
mSuggestionsAdapter.getHistoryForQuery(query) mSuggestionsAdapter.getHistoryForQuery(query)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new OnSubscribe<List<HistoryItem>>() { .subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override @Override
public void onNext(@Nullable List<HistoryItem> item) { public void onItem(@Nullable List<HistoryItem> item) {
mSuggestionsAdapter.combineResults(null, item, null); mSuggestionsAdapter.combineResults(null, item, null);
} }
}); });

View File

@ -4,9 +4,9 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.anthonycr.bonsai.Action; import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.Observable; import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.Subscriber; import com.anthonycr.bonsai.SingleSubscriber;
import java.util.List; import java.util.List;
@ -26,18 +26,18 @@ class SuggestionsManager {
return sIsTaskExecuting; return sIsTaskExecuting;
} }
static Observable<List<HistoryItem>> getObservable(@NonNull final String query, @NonNull final Context context, @NonNull final Source source) { static Single<List<HistoryItem>> getObservable(@NonNull final String query, @NonNull final Context context, @NonNull final Source source) {
final Application application = BrowserApp.get(context); final Application application = BrowserApp.get(context);
return Observable.create(new Action<List<HistoryItem>>() { return Single.create(new SingleAction<List<HistoryItem>>() {
@Override @Override
public void onSubscribe(@NonNull final Subscriber<List<HistoryItem>> subscriber) { public void onSubscribe(@NonNull final SingleSubscriber<List<HistoryItem>> subscriber) {
sIsTaskExecuting = true; sIsTaskExecuting = true;
switch (source) { switch (source) {
case GOOGLE: case GOOGLE:
new GoogleSuggestionsTask(query, application, new SuggestionsResult() { new GoogleSuggestionsTask(query, application, new SuggestionsResult() {
@Override @Override
public void resultReceived(@NonNull List<HistoryItem> searchResults) { public void resultReceived(@NonNull List<HistoryItem> searchResults) {
subscriber.onNext(searchResults); subscriber.onItem(searchResults);
subscriber.onComplete(); subscriber.onComplete();
} }
}).run(); }).run();
@ -46,7 +46,7 @@ class SuggestionsManager {
new DuckSuggestionsTask(query, application, new SuggestionsResult() { new DuckSuggestionsTask(query, application, new SuggestionsResult() {
@Override @Override
public void resultReceived(@NonNull List<HistoryItem> searchResults) { public void resultReceived(@NonNull List<HistoryItem> searchResults) {
subscriber.onNext(searchResults); subscriber.onItem(searchResults);
subscriber.onComplete(); subscriber.onComplete();
} }
}).run(); }).run();

View File

@ -32,6 +32,10 @@ import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.PluginState; import android.webkit.WebSettings.PluginState;
import android.webkit.WebView; import android.webkit.WebView;
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 com.squareup.otto.Bus;
import java.io.File; import java.io.File;
@ -51,11 +55,7 @@ import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.download.LightningDownloadListener; import acr.browser.lightning.download.LightningDownloadListener;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import com.anthonycr.bonsai.Action;
import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Subscriber;
import com.anthonycr.bonsai.OnSubscribe;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.UrlUtils;
@ -405,59 +405,51 @@ public class LightningView {
settings.setAllowUniversalAccessFromFileURLs(false); settings.setAllowUniversalAccessFromFileURLs(false);
} }
getPathObservable("appcache") getPathObservable("appcache").subscribeOn(Schedulers.io())
.subscribeOn(Schedulers.io()) .observeOn(Schedulers.main())
.observeOn(Schedulers.main()) .subscribe(new SingleOnSubscribe<File>() {
.subscribe(new OnSubscribe<File>() { @Override
@Override public void onItem(@Nullable File item) {
public void onNext(File item) { settings.setAppCachePath(item.getPath());
settings.setAppCachePath(item.getPath()); }
} });
@Override
public void onComplete() {}
});
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
getPathObservable("geolocation") getPathObservable("geolocation").subscribeOn(Schedulers.io())
.subscribeOn(Schedulers.io()) .observeOn(Schedulers.main())
.observeOn(Schedulers.main()) .subscribe(new SingleOnSubscribe<File>() {
.subscribe(new OnSubscribe<File>() { @Override
@Override public void onItem(@Nullable File item) {
public void onNext(File item) { //noinspection deprecation
//noinspection deprecation settings.setGeolocationDatabasePath(item.getPath());
settings.setGeolocationDatabasePath(item.getPath()); }
} });
@Override
public void onComplete() {}
});
} }
getPathObservable("databases") getPathObservable("databases").subscribeOn(Schedulers.io())
.subscribeOn(Schedulers.io()) .observeOn(Schedulers.main())
.observeOn(Schedulers.main()) .subscribe(new SingleOnSubscribe<File>() {
.subscribe(new OnSubscribe<File>() { @Override
@Override public void onItem(@Nullable File item) {
public void onNext(File item) { if (API < Build.VERSION_CODES.KITKAT) {
if (API < Build.VERSION_CODES.KITKAT) { //noinspection deprecation
//noinspection deprecation settings.setDatabasePath(item.getPath());
settings.setDatabasePath(item.getPath()); }
} }
}
@Override @Override
public void onComplete() {} public void onComplete() {
}); }
});
} }
private Observable<File> getPathObservable(final String subFolder) { private Single<File> getPathObservable(final String subFolder) {
return Observable.create(new Action<File>() { return Single.create(new SingleAction<File>() {
@Override @Override
public void onSubscribe(@NonNull Subscriber<File> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<File> subscriber) {
File file = BrowserApp.get(mActivity).getDir(subFolder, 0); File file = BrowserApp.get(mActivity).getDir(subFolder, 0);
subscriber.onNext(file); subscriber.onItem(file);
subscriber.onComplete(); subscriber.onComplete();
} }
}); });

View File

@ -15,3 +15,13 @@ allprojects {
mavenCentral() mavenCentral()
} }
} }
ext {
// Necessary for Bonsai submodule
versionCode = 1
versionName = '1.0'
minSdkVersion = 14
targetSdkVersion = 25
buildToolsVersion = '25.0.2'
}