Browse Source

Fixed crashes

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

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

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

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

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

Loading…
Cancel
Save