Updating bonsai
This commit is contained in:
parent
5bdc9294db
commit
77a2f61df3
2
Bonsai
2
Bonsai
@ -1 +1 @@
|
||||
Subproject commit 68eb7eb377803f7971baedb28144aa3b1c420cd0
|
||||
Subproject commit d47c9626c2583b09a1102a980186f9ca51bc4e29
|
@ -80,6 +80,7 @@ import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import com.anthonycr.bonsai.Completable;
|
||||
import com.anthonycr.bonsai.Observable;
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
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);
|
||||
|
||||
abstract Observable<Void> updateCookiePreference();
|
||||
abstract Completable updateCookiePreference();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -8,19 +8,20 @@ import android.view.Menu;
|
||||
import android.webkit.CookieManager;
|
||||
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 com.anthonycr.bonsai.Action;
|
||||
import com.anthonycr.bonsai.Observable;
|
||||
import com.anthonycr.bonsai.Subscriber;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class IncognitoActivity extends BrowserActivity {
|
||||
|
||||
@Override
|
||||
public Observable<Void> updateCookiePreference() {
|
||||
return Observable.create(new Action<Void>() {
|
||||
public Completable updateCookiePreference() {
|
||||
return Completable.create(new CompletableAction() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<Void> subscriber) {
|
||||
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
CookieSyncManager.createInstance(IncognitoActivity.this);
|
||||
|
@ -8,19 +8,20 @@ import android.view.Menu;
|
||||
import android.webkit.CookieManager;
|
||||
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 com.anthonycr.bonsai.Action;
|
||||
import com.anthonycr.bonsai.Observable;
|
||||
import com.anthonycr.bonsai.Subscriber;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MainActivity extends BrowserActivity {
|
||||
|
||||
@Override
|
||||
public Observable<Void> updateCookiePreference() {
|
||||
return Observable.create(new Action<Void>() {
|
||||
public Completable updateCookiePreference() {
|
||||
return Completable.create(new CompletableAction() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<Void> subscriber) {
|
||||
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
CookieSyncManager.createInstance(MainActivity.this);
|
||||
|
@ -30,11 +30,11 @@ import acr.browser.lightning.app.BrowserApp;
|
||||
import acr.browser.lightning.constant.Constants;
|
||||
import acr.browser.lightning.dialog.BrowserDialog;
|
||||
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.Single;
|
||||
import com.anthonycr.bonsai.SingleAction;
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
import com.anthonycr.bonsai.SingleSubscriber;
|
||||
import com.anthonycr.bonsai.Subscription;
|
||||
import acr.browser.lightning.reading.HtmlFetcher;
|
||||
import acr.browser.lightning.reading.JResult;
|
||||
@ -152,7 +152,7 @@ public class ReadingActivity extends AppCompatActivity {
|
||||
getSupportActionBar().setTitle(Utils.getDomainName(mUrl));
|
||||
mPageLoaderSubscription = loadPage(mUrl).subscribeOn(Schedulers.worker())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<ReaderInfo>() {
|
||||
.subscribe(new SingleOnSubscribe<ReaderInfo>() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
mProgressDialog = new ProgressDialog(ReadingActivity.this);
|
||||
@ -165,7 +165,7 @@ public class ReadingActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@Nullable ReaderInfo item) {
|
||||
public void onItem(@Nullable ReaderInfo item) {
|
||||
if (item == null || item.getTitle().isEmpty() || item.getBody().isEmpty()) {
|
||||
setText(getString(R.string.untitled), getString(R.string.loading_failed));
|
||||
} else {
|
||||
@ -193,14 +193,14 @@ public class ReadingActivity extends AppCompatActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Observable<ReaderInfo> loadPage(@NonNull final String url) {
|
||||
return Observable.create(new Action<ReaderInfo>() {
|
||||
private static Single<ReaderInfo> loadPage(@NonNull final String url) {
|
||||
return Single.create(new SingleAction<ReaderInfo>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<ReaderInfo> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<ReaderInfo> subscriber) {
|
||||
HtmlFetcher fetcher = new HtmlFetcher();
|
||||
try {
|
||||
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) {
|
||||
subscriber.onError(new Throwable("Encountered exception"));
|
||||
Log.e(TAG, "Error parsing page", e);
|
||||
|
@ -14,6 +14,14 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
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 java.util.ArrayList;
|
||||
@ -32,11 +40,7 @@ import acr.browser.lightning.database.HistoryDatabase;
|
||||
import acr.browser.lightning.dialog.BrowserDialog;
|
||||
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.Subscriber;
|
||||
|
||||
import acr.browser.lightning.utils.FileUtils;
|
||||
import acr.browser.lightning.utils.UrlUtils;
|
||||
@ -108,13 +112,12 @@ public class TabsManager {
|
||||
* @param intent the intent that started the browser activity.
|
||||
* @param incognito whether or not we are in incognito mode.
|
||||
*/
|
||||
public synchronized Observable<Void> initializeTabs(@NonNull final Activity activity,
|
||||
@Nullable final Intent intent,
|
||||
final boolean incognito) {
|
||||
return Observable.create(new Action<Void>() {
|
||||
public synchronized Completable initializeTabs(@NonNull final Activity activity,
|
||||
@Nullable final Intent intent,
|
||||
final boolean incognito) {
|
||||
return Completable.create(new CompletableAction() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull final Subscriber<Void> subscriber) {
|
||||
|
||||
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
|
||||
// Make sure we start with a clean tab list
|
||||
shutdown();
|
||||
|
||||
@ -150,12 +153,12 @@ public class TabsManager {
|
||||
}
|
||||
|
||||
private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity,
|
||||
@NonNull final Subscriber subscriber) {
|
||||
@NonNull final CompletableSubscriber subscriber) {
|
||||
|
||||
restoreState().subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<Bundle>() {
|
||||
.observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<Bundle>() {
|
||||
@Override
|
||||
public void onNext(Bundle item) {
|
||||
public void onItem(@Nullable Bundle item) {
|
||||
LightningView tab = newTab(activity, "", false);
|
||||
String url = item.getString(URL_KEY);
|
||||
if (url != null && tab.getWebView() != null) {
|
||||
@ -477,16 +480,16 @@ public class TabsManager {
|
||||
* and will delete the saved instance file when
|
||||
* restoration is complete.
|
||||
*/
|
||||
private Observable<Bundle> restoreState() {
|
||||
return Observable.create(new Action<Bundle>() {
|
||||
private Single<Bundle> restoreState() {
|
||||
return Single.create(new SingleAction<Bundle>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<Bundle> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<Bundle> subscriber) {
|
||||
Bundle savedState = FileUtils.readBundleFromStorage(mApp, BUNDLE_STORAGE);
|
||||
if (savedState != null) {
|
||||
Log.d(Constants.TAG, "Restoring previous WebView state now");
|
||||
for (String key : savedState.keySet()) {
|
||||
if (key.startsWith(BUNDLE_KEY)) {
|
||||
subscriber.onNext(savedState.getBundle(key));
|
||||
subscriber.onItem(savedState.getBundle(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
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.preference.PreferenceManager;
|
||||
|
||||
import com.anthonycr.bonsai.OnSubscribe;
|
||||
|
||||
import acr.browser.lightning.utils.UrlUtils;
|
||||
import acr.browser.lightning.view.LightningView;
|
||||
|
||||
@ -64,16 +63,16 @@ public class BrowserPresenter {
|
||||
*/
|
||||
public void setupTabs(@Nullable Intent intent) {
|
||||
mTabsModel.initializeTabs((Activity) mView, intent, mIsIncognito)
|
||||
.subscribeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<Void>() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
// At this point we always have at least a tab in the tab manager
|
||||
mView.notifyTabViewInitialized();
|
||||
mView.updateTabNumber(mTabsModel.size());
|
||||
tabChanged(mTabsModel.last());
|
||||
}
|
||||
});
|
||||
.subscribeOn(Schedulers.main())
|
||||
.subscribe(new CompletableOnSubscribe() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
// At this point we always have at least a tab in the tab manager
|
||||
mView.notifyTabViewInitialized();
|
||||
mView.updateTabNumber(mTabsModel.size());
|
||||
tabChanged(mTabsModel.last());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,12 +8,13 @@ import android.support.annotation.Nullable;
|
||||
import android.support.annotation.WorkerThread;
|
||||
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.List;
|
||||
|
||||
import com.anthonycr.bonsai.Action;
|
||||
import com.anthonycr.bonsai.Observable;
|
||||
import com.anthonycr.bonsai.Subscriber;
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
|
||||
public class BookmarkLocalSync {
|
||||
@ -89,10 +90,10 @@ public class BookmarkLocalSync {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Observable<List<Source>> getSupportedBrowsers() {
|
||||
return Observable.create(new Action<List<Source>>() {
|
||||
public Single<List<Source>> getSupportedBrowsers() {
|
||||
return Single.create(new SingleAction<List<Source>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<List<Source>> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<List<Source>> subscriber) {
|
||||
List<Source> sources = new ArrayList<>(1);
|
||||
if (isBrowserSupported(STOCK_BOOKMARKS_CONTENT)) {
|
||||
sources.add(Source.STOCK);
|
||||
@ -106,7 +107,7 @@ public class BookmarkLocalSync {
|
||||
if (isBrowserSupported(CHROME_DEV_BOOKMARKS_CONTENT)) {
|
||||
sources.add(Source.CHROME_DEV);
|
||||
}
|
||||
subscriber.onNext(sources);
|
||||
subscriber.onItem(sources);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
|
@ -21,6 +21,7 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
import com.anthonycr.grant.PermissionsManager;
|
||||
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.BookmarkManager;
|
||||
import acr.browser.lightning.database.HistoryItem;
|
||||
import com.anthonycr.bonsai.OnSubscribe;
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
|
||||
import acr.browser.lightning.dialog.BrowserDialog;
|
||||
@ -213,14 +213,14 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
|
||||
return true;
|
||||
case SETTINGS_IMPORT_BROWSER:
|
||||
getSync().getSupportedBrowsers().subscribeOn(Schedulers.worker())
|
||||
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<List<Source>>() {
|
||||
.observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<List<Source>>() {
|
||||
@Override
|
||||
public void onNext(@Nullable List<Source> items) {
|
||||
public void onItem(@Nullable List<Source> item) {
|
||||
Activity activity = getActivity();
|
||||
if (items == null || activity == null) {
|
||||
if (item == null || activity == null) {
|
||||
return;
|
||||
}
|
||||
List<String> titles = buildTitleList(activity, items);
|
||||
List<String> titles = buildTitleList(activity, item);
|
||||
showChooserDialog(activity, titles);
|
||||
}
|
||||
});
|
||||
|
@ -27,11 +27,11 @@ import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.anthonycr.bonsai.Action;
|
||||
import com.anthonycr.bonsai.Observable;
|
||||
import com.anthonycr.bonsai.OnSubscribe;
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
import com.anthonycr.bonsai.Subscriber;
|
||||
import com.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.Subscribe;
|
||||
|
||||
@ -96,15 +96,15 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
|
||||
private boolean mIsIncognito;
|
||||
|
||||
private Observable<BookmarkViewAdapter> initBookmarkManager() {
|
||||
return Observable.create(new Action<BookmarkViewAdapter>() {
|
||||
private Single<BookmarkViewAdapter> initBookmarkManager() {
|
||||
return Single.create(new SingleAction<BookmarkViewAdapter>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<BookmarkViewAdapter> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<BookmarkViewAdapter> subscriber) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
mBookmarkAdapter = new BookmarkViewAdapter(context, mBookmarks);
|
||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||
subscriber.onNext(mBookmarkAdapter);
|
||||
subscriber.onItem(mBookmarkAdapter);
|
||||
}
|
||||
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);
|
||||
|
||||
initBookmarkManager().subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<BookmarkViewAdapter>() {
|
||||
@Override
|
||||
public void onNext(@Nullable BookmarkViewAdapter item) {
|
||||
mBookmarksListView.setAdapter(mBookmarkAdapter);
|
||||
}
|
||||
});
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<BookmarkViewAdapter>() {
|
||||
@Override
|
||||
public void onItem(@Nullable BookmarkViewAdapter item) {
|
||||
mBookmarksListView.setAdapter(mBookmarkAdapter);
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,15 @@ import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.anthonycr.bonsai.Action;
|
||||
import com.anthonycr.bonsai.Observable;
|
||||
import com.anthonycr.bonsai.OnSubscribe;
|
||||
import com.anthonycr.bonsai.Completable;
|
||||
import com.anthonycr.bonsai.CompletableAction;
|
||||
import com.anthonycr.bonsai.CompletableSubscriber;
|
||||
import com.anthonycr.bonsai.Scheduler;
|
||||
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.FilenameFilter;
|
||||
@ -98,16 +101,15 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
|
||||
}
|
||||
|
||||
public void refreshBookmarks() {
|
||||
Observable.create(new Action<Void>() {
|
||||
Completable.create(new CompletableAction() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<Void> subscriber) {
|
||||
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
|
||||
mAllBookmarks.clear();
|
||||
mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true));
|
||||
|
||||
subscriber.onComplete();
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.subscribe();
|
||||
}).subscribeOn(Schedulers.io()).subscribe();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -200,25 +202,25 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
|
||||
}
|
||||
|
||||
private void clearSuggestions() {
|
||||
Observable.create(new Action<Void>() {
|
||||
Completable.create(new CompletableAction() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<Void> subscriber) {
|
||||
public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
|
||||
mBookmarks.clear();
|
||||
mHistory.clear();
|
||||
mSuggestions.clear();
|
||||
subscriber.onComplete();
|
||||
}
|
||||
}).subscribeOn(FILTER_SCHEDULER)
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe();
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
private void combineResults(final @Nullable List<HistoryItem> bookmarkList,
|
||||
final @Nullable List<HistoryItem> historyList,
|
||||
final @Nullable List<HistoryItem> suggestionList) {
|
||||
Observable.create(new Action<List<HistoryItem>>() {
|
||||
Single.create(new SingleAction<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
|
||||
List<HistoryItem> list = new ArrayList<>(5);
|
||||
if (bookmarkList != null) {
|
||||
mBookmarks.clear();
|
||||
@ -251,25 +253,24 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
|
||||
}
|
||||
|
||||
Collections.sort(list, mFilterComparator);
|
||||
subscriber.onNext(list);
|
||||
subscriber.onItem(list);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
}).subscribeOn(FILTER_SCHEDULER)
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onNext(@Nullable List<HistoryItem> item) {
|
||||
publishResults(item);
|
||||
}
|
||||
});
|
||||
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onItem(@Nullable List<HistoryItem> item) {
|
||||
publishResults(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Observable<List<HistoryItem>> getBookmarksForQuery(@NonNull final String query) {
|
||||
return Observable.create(new Action<List<HistoryItem>>() {
|
||||
private Single<List<HistoryItem>> getBookmarksForQuery(@NonNull final String query) {
|
||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
|
||||
List<HistoryItem> bookmarks = new ArrayList<>(5);
|
||||
int counter = 0;
|
||||
for (int n = 0; n < mAllBookmarks.size(); n++) {
|
||||
@ -285,36 +286,30 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
subscriber.onNext(bookmarks);
|
||||
subscriber.onItem(bookmarks);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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) {
|
||||
return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.GOOGLE);
|
||||
} else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) {
|
||||
return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.DUCK);
|
||||
} else {
|
||||
return Observable.create(new Action<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) {
|
||||
//TODO add an Observable.empty() method to generate an empty Observable
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
return Single.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Observable<List<HistoryItem>> getHistoryForQuery(@NonNull final String query) {
|
||||
return Observable.create(new Action<List<HistoryItem>>() {
|
||||
private Single<List<HistoryItem>> getHistoryForQuery(@NonNull final String query) {
|
||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
|
||||
List<HistoryItem> historyList = mDatabaseHandler.findItemsContaining(query);
|
||||
subscriber.onNext(historyList);
|
||||
subscriber.onItem(historyList);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
@ -345,9 +340,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
|
||||
mSuggestionsAdapter.getSuggestionsForQuery(query)
|
||||
.subscribeOn(Schedulers.worker())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<List<HistoryItem>>() {
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onNext(@Nullable List<HistoryItem> item) {
|
||||
public void onItem(@Nullable List<HistoryItem> item) {
|
||||
mSuggestionsAdapter.combineResults(null, null, item);
|
||||
}
|
||||
});
|
||||
@ -356,9 +351,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
|
||||
mSuggestionsAdapter.getBookmarksForQuery(query)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<List<HistoryItem>>() {
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onNext(@Nullable List<HistoryItem> item) {
|
||||
public void onItem(@Nullable List<HistoryItem> item) {
|
||||
mSuggestionsAdapter.combineResults(item, null, null);
|
||||
}
|
||||
});
|
||||
@ -366,9 +361,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
|
||||
mSuggestionsAdapter.getHistoryForQuery(query)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<List<HistoryItem>>() {
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onNext(@Nullable List<HistoryItem> item) {
|
||||
public void onItem(@Nullable List<HistoryItem> item) {
|
||||
mSuggestionsAdapter.combineResults(null, item, null);
|
||||
}
|
||||
});
|
||||
|
@ -4,9 +4,9 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.anthonycr.bonsai.Action;
|
||||
import com.anthonycr.bonsai.Observable;
|
||||
import com.anthonycr.bonsai.Subscriber;
|
||||
import com.anthonycr.bonsai.Single;
|
||||
import com.anthonycr.bonsai.SingleAction;
|
||||
import com.anthonycr.bonsai.SingleSubscriber;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -26,18 +26,18 @@ class SuggestionsManager {
|
||||
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);
|
||||
return Observable.create(new Action<List<HistoryItem>>() {
|
||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull final Subscriber<List<HistoryItem>> subscriber) {
|
||||
public void onSubscribe(@NonNull final SingleSubscriber<List<HistoryItem>> subscriber) {
|
||||
sIsTaskExecuting = true;
|
||||
switch (source) {
|
||||
case GOOGLE:
|
||||
new GoogleSuggestionsTask(query, application, new SuggestionsResult() {
|
||||
@Override
|
||||
public void resultReceived(@NonNull List<HistoryItem> searchResults) {
|
||||
subscriber.onNext(searchResults);
|
||||
subscriber.onItem(searchResults);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
}).run();
|
||||
@ -46,7 +46,7 @@ class SuggestionsManager {
|
||||
new DuckSuggestionsTask(query, application, new SuggestionsResult() {
|
||||
@Override
|
||||
public void resultReceived(@NonNull List<HistoryItem> searchResults) {
|
||||
subscriber.onNext(searchResults);
|
||||
subscriber.onItem(searchResults);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
}).run();
|
||||
|
@ -32,6 +32,10 @@ import android.webkit.WebSettings.LayoutAlgorithm;
|
||||
import android.webkit.WebSettings.PluginState;
|
||||
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 java.io.File;
|
||||
@ -51,11 +55,7 @@ import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||
import acr.browser.lightning.download.LightningDownloadListener;
|
||||
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.Subscriber;
|
||||
import com.anthonycr.bonsai.OnSubscribe;
|
||||
|
||||
import acr.browser.lightning.utils.ProxyUtils;
|
||||
import acr.browser.lightning.utils.UrlUtils;
|
||||
@ -405,59 +405,51 @@ public class LightningView {
|
||||
settings.setAllowUniversalAccessFromFileURLs(false);
|
||||
}
|
||||
|
||||
getPathObservable("appcache")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<File>() {
|
||||
@Override
|
||||
public void onNext(File item) {
|
||||
settings.setAppCachePath(item.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {}
|
||||
});
|
||||
getPathObservable("appcache").subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<File>() {
|
||||
@Override
|
||||
public void onItem(@Nullable File item) {
|
||||
settings.setAppCachePath(item.getPath());
|
||||
}
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||
getPathObservable("geolocation")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<File>() {
|
||||
@Override
|
||||
public void onNext(File item) {
|
||||
//noinspection deprecation
|
||||
settings.setGeolocationDatabasePath(item.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {}
|
||||
});
|
||||
getPathObservable("geolocation").subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<File>() {
|
||||
@Override
|
||||
public void onItem(@Nullable File item) {
|
||||
//noinspection deprecation
|
||||
settings.setGeolocationDatabasePath(item.getPath());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getPathObservable("databases")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new OnSubscribe<File>() {
|
||||
@Override
|
||||
public void onNext(File item) {
|
||||
if (API < Build.VERSION_CODES.KITKAT) {
|
||||
//noinspection deprecation
|
||||
settings.setDatabasePath(item.getPath());
|
||||
getPathObservable("databases").subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<File>() {
|
||||
@Override
|
||||
public void onItem(@Nullable File item) {
|
||||
if (API < Build.VERSION_CODES.KITKAT) {
|
||||
//noinspection deprecation
|
||||
settings.setDatabasePath(item.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {}
|
||||
});
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private Observable<File> getPathObservable(final String subFolder) {
|
||||
return Observable.create(new Action<File>() {
|
||||
private Single<File> getPathObservable(final String subFolder) {
|
||||
return Single.create(new SingleAction<File>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<File> subscriber) {
|
||||
public void onSubscribe(@NonNull SingleSubscriber<File> subscriber) {
|
||||
File file = BrowserApp.get(mActivity).getDir(subFolder, 0);
|
||||
subscriber.onNext(file);
|
||||
subscriber.onItem(file);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
|
10
build.gradle
10
build.gradle
@ -15,3 +15,13 @@ allprojects {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
ext {
|
||||
// Necessary for Bonsai submodule
|
||||
versionCode = 1
|
||||
versionName = '1.0'
|
||||
|
||||
minSdkVersion = 14
|
||||
targetSdkVersion = 25
|
||||
buildToolsVersion = '25.0.2'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user