Fixing crash on restore caused by bonsai upgrade

This commit is contained in:
anthony restaino 2017-03-26 20:08:36 -04:00
parent 826ca9118e
commit 1f1d1e7f32

View File

@ -17,11 +17,14 @@ import android.webkit.WebView;
import com.anthonycr.bonsai.Completable; import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.CompletableAction; import com.anthonycr.bonsai.CompletableAction;
import com.anthonycr.bonsai.CompletableSubscriber; import com.anthonycr.bonsai.CompletableSubscriber;
import com.anthonycr.bonsai.ObservableSubscriber;
import com.anthonycr.bonsai.Single; import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.SingleAction; import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleOnSubscribe; import com.anthonycr.bonsai.SingleOnSubscribe;
import com.anthonycr.bonsai.SingleSubscriber; import com.anthonycr.bonsai.SingleSubscriber;
import com.anthonycr.bonsai.Stream;
import com.anthonycr.bonsai.StreamAction;
import com.anthonycr.bonsai.StreamOnSubscribe;
import com.anthonycr.bonsai.StreamSubscriber;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import java.util.ArrayList; import java.util.ArrayList;
@ -156,9 +159,9 @@ public class TabsManager {
@NonNull final CompletableSubscriber subscriber) { @NonNull final CompletableSubscriber subscriber) {
restoreState().subscribeOn(Schedulers.io()) restoreState().subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<Bundle>() { .observeOn(Schedulers.main()).subscribe(new StreamOnSubscribe<Bundle>() {
@Override @Override
public void onItem(@Nullable Bundle item) { public void onNext(@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) {
@ -480,16 +483,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 Single<Bundle> restoreState() { private Stream<Bundle> restoreState() {
return Single.create(new SingleAction<Bundle>() { return Stream.create(new StreamAction<Bundle>() {
@Override @Override
public void onSubscribe(@NonNull SingleSubscriber<Bundle> subscriber) { public void onSubscribe(@NonNull StreamSubscriber<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.onItem(savedState.getBundle(key)); subscriber.onNext(savedState.getBundle(key));
} }
} }
} }