Fix some crashes
This commit is contained in:
parent
42cd6ea007
commit
c6dc5d344d
@ -89,19 +89,19 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
|
|||||||
CatalogueSpinnerAdapter spinnerAdapter = new CatalogueSpinnerAdapter(themedContext,
|
CatalogueSpinnerAdapter spinnerAdapter = new CatalogueSpinnerAdapter(themedContext,
|
||||||
android.R.layout.simple_spinner_item, getPresenter().getEnabledSources());
|
android.R.layout.simple_spinner_item, getPresenter().getEnabledSources());
|
||||||
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
if (savedState == null) selectedIndex = spinnerAdapter.getEmptyIndex();
|
||||||
spinner.setAdapter(spinnerAdapter);
|
spinner.setAdapter(spinnerAdapter);
|
||||||
spinner.setSelection(savedState == null ? spinnerAdapter.getEmptyIndex() : selectedIndex);
|
spinner.setSelection(selectedIndex);
|
||||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
Source source = spinnerAdapter.getItem(position);
|
Source source = spinnerAdapter.getItem(position);
|
||||||
// We add an empty source with id -1 that acts as a placeholder to show a hint
|
// We add an empty source with id -1 that acts as a placeholder to show a hint
|
||||||
// that asks to select a source
|
// that asks to select a source
|
||||||
if (source.getId() != -1 && selectedIndex != position) {
|
if (source.getId() != -1 && (selectedIndex != position || adapter.isEmpty())) {
|
||||||
// Set previous selection if it's not a valid source and notify the user
|
// Set previous selection if it's not a valid source and notify the user
|
||||||
if (!getPresenter().isValidSource(source)) {
|
if (!getPresenter().isValidSource(source)) {
|
||||||
spinner.setSelection(selectedIndex != -1 ? selectedIndex :
|
spinner.setSelection(spinnerAdapter.getEmptyIndex());
|
||||||
spinnerAdapter.getEmptyIndex());
|
|
||||||
ToastUtil.showShort(getActivity(), R.string.source_requires_login);
|
ToastUtil.showShort(getActivity(), R.string.source_requires_login);
|
||||||
} else {
|
} else {
|
||||||
selectedIndex = position;
|
selectedIndex = position;
|
||||||
|
@ -50,6 +50,10 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
|||||||
protected void onCreate(Bundle savedState) {
|
protected void onCreate(Bundle savedState) {
|
||||||
super.onCreate(savedState);
|
super.onCreate(savedState);
|
||||||
|
|
||||||
|
if (savedState != null) {
|
||||||
|
onProcessRestart();
|
||||||
|
}
|
||||||
|
|
||||||
mangaDetailSubject = PublishSubject.create();
|
mangaDetailSubject = PublishSubject.create();
|
||||||
|
|
||||||
restartableReplay(GET_MANGA_LIST,
|
restartableReplay(GET_MANGA_LIST,
|
||||||
@ -80,6 +84,11 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
|||||||
(view, error) -> Timber.e(error.getMessage()));
|
(view, error) -> Timber.e(error.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onProcessRestart() {
|
||||||
|
stop(GET_MANGA_LIST);
|
||||||
|
stop(GET_MANGA_DETAIL);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
// Catalogue covers are probably not going to be needed for a long time
|
// Catalogue covers are probably not going to be needed for a long time
|
||||||
|
@ -181,7 +181,8 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
|
|
||||||
private void observeChapterDownloadProgress() {
|
private void observeChapterDownloadProgress() {
|
||||||
downloadProgressSubscription = getPresenter().getDownloadProgressObs()
|
downloadProgressSubscription = getPresenter().getDownloadProgressObs()
|
||||||
.subscribe(this::onDownloadProgressChange);
|
.subscribe(this::onDownloadProgressChange,
|
||||||
|
error -> { /* TODO getting a NPE sometimes on 'manga' from presenter */ });
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unsubscribeChapterDownloadProgress() {
|
private void unsubscribeChapterDownloadProgress() {
|
||||||
|
@ -78,9 +78,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
if (currentPage != 0)
|
if (currentPage != 0)
|
||||||
view.setSelectedPage(currentPage);
|
view.setSelectedPage(currentPage);
|
||||||
},
|
},
|
||||||
(view, error) -> {
|
(view, error) -> view.onChapterError());
|
||||||
view.onChapterError();
|
|
||||||
});
|
|
||||||
|
|
||||||
restartableReplay(GET_PAGE_IMAGES,
|
restartableReplay(GET_PAGE_IMAGES,
|
||||||
() -> getPageImagesObservable()
|
() -> getPageImagesObservable()
|
||||||
@ -104,10 +102,8 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
unregisterForEvents();
|
unregisterForEvents();
|
||||||
if (pageList != null && isChapterFinished()) {
|
|
||||||
updateMangaSyncLastChapterRead();
|
|
||||||
}
|
|
||||||
onChapterLeft();
|
onChapterLeft();
|
||||||
|
updateMangaSyncLastChapterRead();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +237,9 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateMangaSyncLastChapterRead() {
|
private void updateMangaSyncLastChapterRead() {
|
||||||
|
if (pageList == null)
|
||||||
|
return;
|
||||||
|
|
||||||
db.getMangaSync(manga).createObservable()
|
db.getMangaSync(manga).createObservable()
|
||||||
.take(1)
|
.take(1)
|
||||||
.flatMap(Observable::from)
|
.flatMap(Observable::from)
|
||||||
@ -249,15 +248,21 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
if (!service.isLogged())
|
if (!service.isLogged())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int lastChapterReadLocal = (int) Math.floor(chapter.chapter_number);
|
int lastChapterReadLocal = 0;
|
||||||
int lastChapterReadRemote = mangaSync.last_chapter_read;
|
// If the current chapter has been read, we check with this one
|
||||||
|
if (chapter.read)
|
||||||
|
lastChapterReadLocal = (int) Math.floor(chapter.chapter_number);
|
||||||
|
// If not, we check if the previous chapter has been read
|
||||||
|
else if (previousChapter != null && previousChapter.read)
|
||||||
|
lastChapterReadLocal = (int) Math.floor(previousChapter.chapter_number);
|
||||||
|
|
||||||
if (lastChapterReadLocal > lastChapterReadRemote) {
|
if (lastChapterReadLocal > mangaSync.last_chapter_read) {
|
||||||
mangaSync.last_chapter_read = lastChapterReadLocal;
|
mangaSync.last_chapter_read = lastChapterReadLocal;
|
||||||
UpdateMangaSyncService.start(getContext(), mangaSync);
|
UpdateMangaSyncService.start(getContext(), mangaSync);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.subscribe();
|
.subscribe(next -> {},
|
||||||
|
error -> Timber.e(error.getCause(), error.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentPage(int currentPage) {
|
public void setCurrentPage(int currentPage) {
|
||||||
|
Loading…
Reference in New Issue
Block a user