Renamed OnSubscribe/Subscriber, moved anonymous class to static class, added --stacktrace to gradle build to capture build crash
This commit is contained in:
parent
77465c83dd
commit
941f54d615
@ -18,4 +18,4 @@ before_install:
|
||||
install:
|
||||
- ./gradlew
|
||||
script:
|
||||
- ./gradlew assembleRelease
|
||||
- ./gradlew assembleRelease --stacktrace
|
||||
|
@ -110,8 +110,8 @@ import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||
import acr.browser.lightning.fragment.BookmarksFragment;
|
||||
import acr.browser.lightning.fragment.TabsFragment;
|
||||
import acr.browser.lightning.object.SearchAdapter;
|
||||
import acr.browser.lightning.react.OnSubscribe;
|
||||
import acr.browser.lightning.react.Schedulers;
|
||||
import acr.browser.lightning.react.Subscriber;
|
||||
import acr.browser.lightning.receiver.NetworkReceiver;
|
||||
|
||||
import com.anthonycr.grant.PermissionsManager;
|
||||
@ -360,7 +360,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
}
|
||||
|
||||
mTabsManager.initializeTabs(this, getIntent(), isIncognito())
|
||||
.subscribe(new Subscriber<Void>() {
|
||||
.subscribe(new OnSubscribe<Void>() {
|
||||
@Override
|
||||
public void onNext(Void item) {}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import android.webkit.CookieSyncManager;
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.react.Action;
|
||||
import acr.browser.lightning.react.Observable;
|
||||
import acr.browser.lightning.react.OnSubscribe;
|
||||
import acr.browser.lightning.react.Subscriber;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class IncognitoActivity extends BrowserActivity {
|
||||
@ -20,13 +20,13 @@ public class IncognitoActivity extends BrowserActivity {
|
||||
public Observable<Void> updateCookiePreference() {
|
||||
return Observable.create(new Action<Void>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull OnSubscribe<Void> onSubscribe) {
|
||||
public void onSubscribe(@NonNull Subscriber<Void> subscriber) {
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
CookieSyncManager.createInstance(IncognitoActivity.this);
|
||||
}
|
||||
cookieManager.setAcceptCookie(mPreferences.getIncognitoCookiesEnabled());
|
||||
onSubscribe.onComplete();
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import android.webkit.CookieSyncManager;
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.react.Action;
|
||||
import acr.browser.lightning.react.Observable;
|
||||
import acr.browser.lightning.react.OnSubscribe;
|
||||
import acr.browser.lightning.react.Subscriber;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MainActivity extends BrowserActivity {
|
||||
@ -20,13 +20,13 @@ public class MainActivity extends BrowserActivity {
|
||||
public Observable<Void> updateCookiePreference() {
|
||||
return Observable.create(new Action<Void>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull OnSubscribe<Void> onSubscribe) {
|
||||
public void onSubscribe(@NonNull Subscriber<Void> subscriber) {
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
CookieSyncManager.createInstance(MainActivity.this);
|
||||
}
|
||||
cookieManager.setAcceptCookie(mPreferences.getCookiesEnabled());
|
||||
onSubscribe.onComplete();
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package acr.browser.lightning.activity;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -23,8 +21,6 @@ import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import acr.browser.lightning.R;
|
||||
@ -34,8 +30,8 @@ import acr.browser.lightning.preference.PreferenceManager;
|
||||
import acr.browser.lightning.react.Action;
|
||||
import acr.browser.lightning.react.Observable;
|
||||
import acr.browser.lightning.react.OnSubscribe;
|
||||
import acr.browser.lightning.react.Schedulers;
|
||||
import acr.browser.lightning.react.Subscriber;
|
||||
import acr.browser.lightning.react.Schedulers;
|
||||
import acr.browser.lightning.react.Subscription;
|
||||
import acr.browser.lightning.reading.HtmlFetcher;
|
||||
import acr.browser.lightning.reading.JResult;
|
||||
@ -151,7 +147,7 @@ public class ReadingActivity extends AppCompatActivity {
|
||||
getSupportActionBar().setTitle(Utils.getDomainName(mUrl));
|
||||
mPageLoaderSubscription = loadPage(mUrl).subscribeOn(Schedulers.worker())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new Subscriber<ReaderInfo>() {
|
||||
.subscribe(new OnSubscribe<ReaderInfo>() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
mProgressDialog = new ProgressDialog(ReadingActivity.this);
|
||||
@ -194,20 +190,20 @@ public class ReadingActivity extends AppCompatActivity {
|
||||
private static Observable<ReaderInfo> loadPage(@NonNull final String url) {
|
||||
return Observable.create(new Action<ReaderInfo>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull OnSubscribe<ReaderInfo> onSubscribe) {
|
||||
public void onSubscribe(@NonNull Subscriber<ReaderInfo> subscriber) {
|
||||
HtmlFetcher fetcher = new HtmlFetcher();
|
||||
try {
|
||||
JResult result = fetcher.fetchAndExtract(url, 2500, true);
|
||||
onSubscribe.onNext(new ReaderInfo(result.getTitle(), result.getText()));
|
||||
subscriber.onNext(new ReaderInfo(result.getTitle(), result.getText()));
|
||||
} catch (Exception e) {
|
||||
onSubscribe.onError(new Throwable("Encountered exception"));
|
||||
subscriber.onError(new Throwable("Encountered exception"));
|
||||
e.printStackTrace();
|
||||
} catch (OutOfMemoryError e) {
|
||||
System.gc();
|
||||
onSubscribe.onError(new Throwable("Out of memory"));
|
||||
subscriber.onError(new Throwable("Out of memory"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
onSubscribe.onComplete();
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ import acr.browser.lightning.constant.Constants;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
import acr.browser.lightning.react.Action;
|
||||
import acr.browser.lightning.react.OnSubscribe;
|
||||
import acr.browser.lightning.react.Schedulers;
|
||||
import acr.browser.lightning.react.Subscriber;
|
||||
import acr.browser.lightning.react.Schedulers;
|
||||
import acr.browser.lightning.utils.FileUtils;
|
||||
import acr.browser.lightning.react.Observable;
|
||||
import acr.browser.lightning.view.LightningView;
|
||||
@ -66,14 +66,14 @@ public class TabsManager {
|
||||
final boolean incognito) {
|
||||
return Observable.create(new Action<Void>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull final OnSubscribe<Void> onSubscribe) {
|
||||
public void onSubscribe(@NonNull final Subscriber<Void> subscriber) {
|
||||
|
||||
|
||||
// If incognito, only create one tab, do not handle intent
|
||||
// in order to protect user privacy
|
||||
if (incognito && mTabList.isEmpty()) {
|
||||
newTab(activity, null, true);
|
||||
onSubscribe.onComplete();
|
||||
subscriber.onComplete();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public class TabsManager {
|
||||
mTabList.clear();
|
||||
mCurrentTab = null;
|
||||
if (mPreferenceManager.getRestoreLostTabsEnabled()) {
|
||||
restoreLostTabs(url, activity, onSubscribe);
|
||||
restoreLostTabs(url, activity, subscriber);
|
||||
}
|
||||
|
||||
}
|
||||
@ -94,9 +94,9 @@ public class TabsManager {
|
||||
}
|
||||
|
||||
private void restoreLostTabs(final String url, final Activity activity,
|
||||
final OnSubscribe onSubscribe) {
|
||||
final Subscriber subscriber) {
|
||||
restoreState().subscribeOn(Schedulers.worker())
|
||||
.observeOn(Schedulers.main()).subscribe(new Subscriber<Bundle>() {
|
||||
.observeOn(Schedulers.main()).subscribe(new OnSubscribe<Bundle>() {
|
||||
@Override
|
||||
public void onNext(Bundle item) {
|
||||
LightningView tab = newTab(activity, "", false);
|
||||
@ -127,7 +127,7 @@ public class TabsManager {
|
||||
if (mTabList.size() == 0) {
|
||||
newTab(activity, null, false);
|
||||
}
|
||||
onSubscribe.onComplete();
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -331,17 +331,17 @@ public class TabsManager {
|
||||
private Observable<Bundle> restoreState() {
|
||||
return Observable.create(new Action<Bundle>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull OnSubscribe<Bundle> onSubscribe) {
|
||||
public void onSubscribe(@NonNull Subscriber<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)) {
|
||||
onSubscribe.onNext(savedState.getBundle(key));
|
||||
subscriber.onNext(savedState.getBundle(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
onSubscribe.onComplete();
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ import android.support.annotation.NonNull;
|
||||
|
||||
public interface Action<T> {
|
||||
/**
|
||||
* Should be overridden to send the onSubscribe
|
||||
* events such as {@link OnSubscribe#onNext(Object)}
|
||||
* or {@link OnSubscribe#onComplete()}.
|
||||
* Should be overridden to send the subscriber
|
||||
* events such as {@link Subscriber#onNext(Object)}
|
||||
* or {@link Subscriber#onComplete()}.
|
||||
*
|
||||
* @param onSubscribe the onSubscribe that is sent in
|
||||
* @param subscriber the subscriber that is sent in
|
||||
* when the user of the Observable
|
||||
* subscribes.
|
||||
*/
|
||||
void onSubscribe(@NonNull OnSubscribe<T> onSubscribe);
|
||||
void onSubscribe(@NonNull Subscriber<T> subscriber);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class Observable<T> {
|
||||
* must not be null.
|
||||
*
|
||||
* @param action the Action to perform
|
||||
* @param <T> the type that will be emitted to the subscriber
|
||||
* @param <T> the type that will be emitted to the onSubscribe
|
||||
* @return a valid non-null Observable.
|
||||
*/
|
||||
@NonNull
|
||||
@ -49,7 +49,7 @@ public class Observable<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the Observable what Executor that the subscriber
|
||||
* Tells the Observable what Executor that the onSubscribe
|
||||
* work should run on.
|
||||
*
|
||||
* @param subscribeExecutor the Executor to run the work on.
|
||||
@ -61,7 +61,7 @@ public class Observable<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the Observable what Executor the subscriber should observe
|
||||
* Tells the Observable what Executor the onSubscribe should observe
|
||||
* the work on.
|
||||
*
|
||||
* @param observerExecutor the Executor to run to callback on.
|
||||
@ -80,7 +80,7 @@ public class Observable<T> {
|
||||
executeOnSubscriberThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAction.onSubscribe(new OnSubscribe<T>(null) {
|
||||
mAction.onSubscribe(new Subscriber<T>() {
|
||||
@Override
|
||||
public void unsubscribe() {}
|
||||
|
||||
@ -88,7 +88,7 @@ public class Observable<T> {
|
||||
public void onComplete() {}
|
||||
|
||||
@Override
|
||||
public void start() {}
|
||||
public void onStart() {}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable throwable) {}
|
||||
@ -102,73 +102,27 @@ public class Observable<T> {
|
||||
|
||||
/**
|
||||
* Immediately subscribes to the Observable and starts
|
||||
* sending events from the Observable to the {@link Subscriber}.
|
||||
* sending events from the Observable to the {@link OnSubscribe}.
|
||||
*
|
||||
* @param subscriber the class that wishes to receive onNext and
|
||||
* onComplete callbacks from the Observable.
|
||||
* @param onSubscribe the class that wishes to receive onNext and
|
||||
* onComplete callbacks from the Observable.
|
||||
*/
|
||||
public Subscription subscribe(@NonNull Subscriber<T> subscriber) {
|
||||
public Subscription subscribe(@NonNull OnSubscribe<T> onSubscribe) {
|
||||
|
||||
Preconditions.checkNonNull(subscriber);
|
||||
Preconditions.checkNonNull(onSubscribe);
|
||||
|
||||
final OnSubscribe<T> onSubscribe = new OnSubscribe<T>(subscriber) {
|
||||
final Subscriber<T> subscriber = new SubscriberImpl<>(onSubscribe, this);
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
setSubscriber(null);
|
||||
}
|
||||
subscriber.onStart();
|
||||
|
||||
private boolean mOnCompleteExecuted = false;
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Subscriber<T> subscription = getSubscriber();
|
||||
if (!mOnCompleteExecuted && subscription != null) {
|
||||
mOnCompleteExecuted = true;
|
||||
executeOnObserverThread(new OnCompleteRunnable<>(subscription));
|
||||
} else {
|
||||
Log.e(TAG, "onComplete called more than once");
|
||||
throw new RuntimeException("onComplete called more than once");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
Subscriber<T> subscription = getSubscriber();
|
||||
executeOnObserverThread(new OnStartRunnable<>(subscription));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull final Throwable throwable) {
|
||||
Subscriber<T> subscription = getSubscriber();
|
||||
if (!mOnCompleteExecuted && subscription != null) {
|
||||
mOnCompleteExecuted = true;
|
||||
executeOnObserverThread(new OnErrorRunnable<>(subscription, throwable));
|
||||
} else {
|
||||
Log.e(TAG, "onComplete already called");
|
||||
throw new RuntimeException("onComplete already called");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(final T item) {
|
||||
Subscriber<T> subscription = getSubscriber();
|
||||
if (!mOnCompleteExecuted && subscription != null) {
|
||||
executeOnObserverThread(new OnNextRunnable<>(subscription, item));
|
||||
} else {
|
||||
Log.e(TAG, "onComplete has been already called, onNext should not be called");
|
||||
throw new RuntimeException("onNext should not be called after onComplete has been called");
|
||||
}
|
||||
}
|
||||
};
|
||||
executeOnSubscriberThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mAction.onSubscribe(onSubscribe);
|
||||
mAction.onSubscribe(subscriber);
|
||||
}
|
||||
});
|
||||
return onSubscribe;
|
||||
|
||||
return subscriber;
|
||||
}
|
||||
|
||||
private void executeOnObserverThread(@NonNull Runnable runnable) {
|
||||
@ -187,55 +141,111 @@ public class Observable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private static class OnCompleteRunnable<T> implements Runnable {
|
||||
private final Subscriber<T> subscriber;
|
||||
private static class SubscriberImpl<T> implements Subscriber<T> {
|
||||
|
||||
public OnCompleteRunnable(Subscriber<T> subscriber) {this.subscriber = subscriber;}
|
||||
@Nullable private OnSubscribe<T> mOnSubscribe;
|
||||
@NonNull private Observable<T> mObservable;
|
||||
private boolean mOnCompleteExecuted = false;
|
||||
|
||||
public SubscriberImpl(@NonNull OnSubscribe<T> onSubscribe, @NonNull Observable<T> observable) {
|
||||
mOnSubscribe = onSubscribe;
|
||||
mObservable = observable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
mOnSubscribe = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
if (!mOnCompleteExecuted && mOnSubscribe != null) {
|
||||
mOnCompleteExecuted = true;
|
||||
mObservable.executeOnObserverThread(new OnCompleteRunnable<>(mOnSubscribe));
|
||||
} else {
|
||||
Log.e(TAG, "onComplete called more than once");
|
||||
throw new RuntimeException("onComplete called more than once");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mOnSubscribe != null) {
|
||||
mObservable.executeOnObserverThread(new OnStartRunnable<>(mOnSubscribe));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull final Throwable throwable) {
|
||||
if (!mOnCompleteExecuted && mOnSubscribe != null) {
|
||||
mOnCompleteExecuted = true;
|
||||
mObservable.executeOnObserverThread(new OnErrorRunnable<>(mOnSubscribe, throwable));
|
||||
} else {
|
||||
Log.e(TAG, "onComplete already called");
|
||||
throw new RuntimeException("onComplete already called");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(final T item) {
|
||||
if (!mOnCompleteExecuted && mOnSubscribe != null) {
|
||||
mObservable.executeOnObserverThread(new OnNextRunnable<>(mOnSubscribe, item));
|
||||
} else {
|
||||
Log.e(TAG, "onComplete has been already called, onNext should not be called");
|
||||
throw new RuntimeException("onNext should not be called after onComplete has been called");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class OnCompleteRunnable<T> implements Runnable {
|
||||
private final OnSubscribe<T> onSubscribe;
|
||||
|
||||
public OnCompleteRunnable(OnSubscribe<T> onSubscribe) {this.onSubscribe = onSubscribe;}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
subscriber.onComplete();
|
||||
onSubscribe.onComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private static class OnNextRunnable<T> implements Runnable {
|
||||
private final Subscriber<T> subscriber;
|
||||
private final OnSubscribe<T> onSubscribe;
|
||||
private final T item;
|
||||
|
||||
public OnNextRunnable(Subscriber<T> subscriber, T item) {
|
||||
this.subscriber = subscriber;
|
||||
public OnNextRunnable(OnSubscribe<T> onSubscribe, T item) {
|
||||
this.onSubscribe = onSubscribe;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
subscriber.onNext(item);
|
||||
onSubscribe.onNext(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static class OnErrorRunnable<T> implements Runnable {
|
||||
private final Subscriber<T> subscriber;
|
||||
private final OnSubscribe<T> onSubscribe;
|
||||
private final Throwable throwable;
|
||||
|
||||
public OnErrorRunnable(Subscriber<T> subscriber, Throwable throwable) {
|
||||
this.subscriber = subscriber;
|
||||
public OnErrorRunnable(OnSubscribe<T> onSubscribe, Throwable throwable) {
|
||||
this.onSubscribe = onSubscribe;
|
||||
this.throwable = throwable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
subscriber.onError(throwable);
|
||||
onSubscribe.onError(throwable);
|
||||
}
|
||||
}
|
||||
|
||||
private static class OnStartRunnable<T> implements Runnable {
|
||||
private final Subscriber<T> subscriber;
|
||||
private final OnSubscribe<T> onSubscribe;
|
||||
|
||||
public OnStartRunnable(Subscriber<T> subscriber) {this.subscriber = subscriber;}
|
||||
public OnStartRunnable(OnSubscribe<T> onSubscribe) {this.onSubscribe = onSubscribe;}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
subscriber.onStart();
|
||||
onSubscribe.onStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,25 +3,7 @@ package acr.browser.lightning.react;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public abstract class OnSubscribe<T> implements Subscription {
|
||||
|
||||
@Nullable private Subscriber<T> mSubscriber;
|
||||
|
||||
public OnSubscribe(@Nullable Subscriber<T> subscriber) {
|
||||
mSubscriber = subscriber;
|
||||
start();
|
||||
}
|
||||
|
||||
public abstract void start();
|
||||
|
||||
@Nullable
|
||||
public Subscriber<T> getSubscriber() {
|
||||
return mSubscriber;
|
||||
}
|
||||
|
||||
public void setSubscriber(@Nullable Subscriber<T> subscriber) {
|
||||
mSubscriber = subscriber;
|
||||
}
|
||||
public abstract class OnSubscribe<T> {
|
||||
|
||||
/**
|
||||
* Called when the observable
|
||||
@ -35,7 +17,13 @@ public abstract class OnSubscribe<T> implements Subscription {
|
||||
* @param throwable an optional throwable that could
|
||||
* be sent.
|
||||
*/
|
||||
public abstract void onError(@NonNull Throwable throwable);
|
||||
public void onError(@NonNull Throwable throwable) {}
|
||||
|
||||
/**
|
||||
* Called before the observer begins
|
||||
* to process and emit items or complete.
|
||||
*/
|
||||
public void onStart() {}
|
||||
|
||||
/**
|
||||
* Called when the Observer emits an
|
||||
@ -46,14 +34,14 @@ public abstract class OnSubscribe<T> implements Subscription {
|
||||
* @param item the item that has been emitted,
|
||||
* can be null.
|
||||
*/
|
||||
public abstract void onNext(@Nullable T item);
|
||||
public void onNext(@Nullable T item) {}
|
||||
|
||||
/**
|
||||
* This method is called when the observer is
|
||||
* finished sending the subscriber events. It
|
||||
* is guaranteed that no other methods will be
|
||||
* called on the Subscriber after this method
|
||||
* called on the OnSubscribe after this method
|
||||
* has been called.
|
||||
*/
|
||||
public abstract void onComplete();
|
||||
public void onComplete() {}
|
||||
}
|
||||
|
@ -3,7 +3,17 @@ package acr.browser.lightning.react;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public abstract class Subscriber<T> {
|
||||
public interface Subscriber<T> extends Subscription {
|
||||
|
||||
/**
|
||||
* Called immediately upon subscribing
|
||||
* and before the Observable begins
|
||||
* emitting items. This should not be
|
||||
* called by the creator of the Observable
|
||||
* and is rather called internally by the
|
||||
* Observable class itself.
|
||||
*/
|
||||
void onStart();
|
||||
|
||||
/**
|
||||
* Called when the observable
|
||||
@ -17,13 +27,7 @@ public abstract class Subscriber<T> {
|
||||
* @param throwable an optional throwable that could
|
||||
* be sent.
|
||||
*/
|
||||
public void onError(@NonNull Throwable throwable) {}
|
||||
|
||||
/**
|
||||
* Called before the observer begins
|
||||
* to process and emit items or complete.
|
||||
*/
|
||||
public void onStart() {}
|
||||
void onError(@NonNull Throwable throwable);
|
||||
|
||||
/**
|
||||
* Called when the Observer emits an
|
||||
@ -34,14 +38,14 @@ public abstract class Subscriber<T> {
|
||||
* @param item the item that has been emitted,
|
||||
* can be null.
|
||||
*/
|
||||
public void onNext(@Nullable T item) {}
|
||||
void onNext(@Nullable T item);
|
||||
|
||||
/**
|
||||
* This method is called when the observer is
|
||||
* finished sending the subscriber events. It
|
||||
* is guaranteed that no other methods will be
|
||||
* called on the Subscriber after this method
|
||||
* called on the OnSubscribe after this method
|
||||
* has been called.
|
||||
*/
|
||||
public void onComplete() {}
|
||||
void onComplete();
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ import acr.browser.lightning.preference.PreferenceManager;
|
||||
import acr.browser.lightning.react.Action;
|
||||
import acr.browser.lightning.react.Observable;
|
||||
import acr.browser.lightning.react.Schedulers;
|
||||
import acr.browser.lightning.react.OnSubscribe;
|
||||
import acr.browser.lightning.react.Subscriber;
|
||||
import acr.browser.lightning.react.OnSubscribe;
|
||||
import acr.browser.lightning.utils.ProxyUtils;
|
||||
import acr.browser.lightning.utils.ThemeUtils;
|
||||
import acr.browser.lightning.utils.UrlUtils;
|
||||
@ -375,7 +375,7 @@ public class LightningView {
|
||||
|
||||
getPathObservable("appcache")
|
||||
.subscribeOn(Schedulers.worker())
|
||||
.subscribe(new Subscriber<File>() {
|
||||
.subscribe(new OnSubscribe<File>() {
|
||||
@Override
|
||||
public void onNext(File item) {
|
||||
settings.setAppCachePath(item.getPath());
|
||||
@ -387,7 +387,7 @@ public class LightningView {
|
||||
|
||||
getPathObservable("geolocation")
|
||||
.subscribeOn(Schedulers.worker())
|
||||
.subscribe(new Subscriber<File>() {
|
||||
.subscribe(new OnSubscribe<File>() {
|
||||
@Override
|
||||
public void onNext(File item) {
|
||||
settings.setGeolocationDatabasePath(item.getPath());
|
||||
@ -399,7 +399,7 @@ public class LightningView {
|
||||
|
||||
getPathObservable("databases")
|
||||
.subscribeOn(Schedulers.worker())
|
||||
.subscribe(new Subscriber<File>() {
|
||||
.subscribe(new OnSubscribe<File>() {
|
||||
@Override
|
||||
public void onNext(File item) {
|
||||
if (API < Build.VERSION_CODES.KITKAT) {
|
||||
@ -417,10 +417,10 @@ public class LightningView {
|
||||
private Observable<File> getPathObservable(final String subFolder) {
|
||||
return Observable.create(new Action<File>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull OnSubscribe<File> onSubscribe) {
|
||||
public void onSubscribe(@NonNull Subscriber<File> subscriber) {
|
||||
File file = BrowserApp.get(mActivity).getDir(subFolder, 0);
|
||||
onSubscribe.onNext(file);
|
||||
onSubscribe.onComplete();
|
||||
subscriber.onNext(file);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user