Browse Source

Fixed crashes

master
Anthony Restaino 9 years ago
parent
commit
b8b2bd090f
  1. 35
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  2. 5
      app/src/main/java/acr/browser/lightning/react/Observable.java

35
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -47,6 +47,11 @@ import acr.browser.lightning.database.HistoryItem; @@ -47,6 +47,11 @@ import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.async.ImageDownloadTask;
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.utils.ThemeUtils;
import acr.browser.lightning.view.LightningView;
@ -85,16 +90,16 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -85,16 +90,16 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
// Colors
private int mIconColor, mScrollIndex;
// Init asynchronously the bookmark manager
private final Runnable mInitBookmarkManager = new Runnable() {
@Override
public void run() {
final Context context = getContext();
mBookmarkAdapter = new BookmarkViewAdapter(context, mBookmarks);
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
mBookmarksListView.setAdapter(mBookmarkAdapter);
}
};
private Observable<BookmarkViewAdapter> initBookmarkManager() {
return Observable.create(new Action<BookmarkViewAdapter>() {
@Override
public void onSubscribe(@NonNull Subscriber<BookmarkViewAdapter> subscriber) {
mBookmarkAdapter = new BookmarkViewAdapter(getContext(), mBookmarks);
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
subscriber.onNext(mBookmarkAdapter);
}
});
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@ -166,8 +171,14 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -166,8 +171,14 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
setupNavigationButton(view, R.id.action_reading, R.id.icon_reading);
setupNavigationButton(view, R.id.action_toggle_desktop, R.id.icon_desktop);
// Must be called here, only here we have a reference to the ListView
BrowserApp.getTaskThread().execute(mInitBookmarkManager);
initBookmarkManager().subscribeOn(Schedulers.worker())
.observeOn(Schedulers.main())
.subscribe(new OnSubscribe<BookmarkViewAdapter>() {
@Override
public void onNext(@Nullable BookmarkViewAdapter item) {
mBookmarksListView.setAdapter(mBookmarkAdapter);
}
});
return view;
}

5
app/src/main/java/acr/browser/lightning/react/Observable.java

@ -177,12 +177,9 @@ public class Observable<T> { @@ -177,12 +177,9 @@ public class Observable<T> {
@Override
public void onError(@NonNull final Throwable throwable) {
if (!mOnCompleteExecuted && mOnSubscribe != null) {
if (mOnSubscribe != null) {
mOnCompleteExecuted = true;
mObservable.executeOnObserverThread(new OnErrorRunnable<>(mOnSubscribe, throwable));
} else {
Log.e(TAG, "onComplete already called");
throw new RuntimeException("onComplete already called");
}
}

Loading…
Cancel
Save