Fix #373 and a few crashes

This commit is contained in:
len 2016-12-31 16:19:32 +01:00
parent a7192e866f
commit 3a1699f0b3
6 changed files with 31 additions and 11 deletions

View file

@ -15,11 +15,17 @@ import uy.kohesive.injekt.api.get
interface ActivityMixin {
var resumed: Boolean
fun setupToolbar(toolbar: Toolbar, backNavigation: Boolean = true) {
setSupportActionBar(toolbar)
getSupportActionBar()?.setDisplayHomeAsUpEnabled(true)
if (backNavigation) {
toolbar.setNavigationOnClickListener { onBackPressed() }
toolbar.setNavigationOnClickListener {
if (resumed) {
onBackPressed()
}
}
}
}

View file

@ -5,15 +5,14 @@ import eu.kanade.tachiyomi.util.LocaleHelper
abstract class BaseActivity : AppCompatActivity(), ActivityMixin {
override var resumed = false
init {
LocaleHelper.updateConfiguration(this)
}
override fun getActivity() = this
var resumed = false
private set
override fun onResume() {
super.onResume()
resumed = true

View file

@ -8,6 +8,8 @@ import nucleus.view.NucleusAppCompatActivity
abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>(), ActivityMixin {
override var resumed = false
init {
LocaleHelper.updateConfiguration(this)
}
@ -25,9 +27,6 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
override fun getActivity() = this
var resumed = false
private set
override fun onResume() {
super.onResume()
resumed = true

View file

@ -293,9 +293,12 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
*
* @param mangas the list of manga.
*/
fun getCommonCategories(mangas: List<Manga>): Collection<Category> = mangas.toSet()
.map { db.getCategoriesForManga(it).executeAsBlocking() }
.reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) }
fun getCommonCategories(mangas: List<Manga>): Collection<Category> {
if (mangas.isEmpty()) return emptyList()
return mangas.toSet()
.map { db.getCategoriesForManga(it).executeAsBlocking() }
.reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) }
}
/**
* Remove the selected manga from the library.

View file

@ -118,7 +118,7 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
override fun onPrepareOptionsMenu(menu: Menu) {
// Initialize menu items.
val menuFilterRead = menu.findItem(R.id.action_filter_read)
val menuFilterRead = menu.findItem(R.id.action_filter_read) ?: return
val menuFilterUnread = menu.findItem(R.id.action_filter_unread)
val menuFilterDownloaded = menu.findItem(R.id.action_filter_downloaded)
val menuFilterBookmarked = menu.findItem(R.id.action_filter_bookmarked)

View file

@ -141,6 +141,11 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
*/
private var adjacentChaptersSubscription: Subscription? = null
/**
* Whether the active chapter has been loaded.
*/
private var chapterLoaded = false
companion object {
/**
* Id of the restartable that loads the active chapter.
@ -211,6 +216,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
return loader.loadChapter(chapter)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnNext { chapterLoaded = true }
}
/**
@ -298,6 +304,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
nextChapter = null
prevChapter = null
chapterLoaded = false
start(LOAD_ACTIVE_CHAPTER)
getAdjacentChapters(chapter)
}
@ -474,6 +481,9 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
* @return true if the next chapter is being loaded, false if there is no next chapter.
*/
fun loadNextChapter(): Boolean {
// Avoid skipping chapters.
if (!chapterLoaded) return true
nextChapter?.let {
onChapterLeft()
loadChapter(it, 0)
@ -488,6 +498,9 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
* @return true if the previous chapter is being loaded, false if there is no previous chapter.
*/
fun loadPreviousChapter(): Boolean {
// Avoid skipping chapters.
if (!chapterLoaded) return true
prevChapter?.let {
onChapterLeft()
loadChapter(it, if (it.read) -1 else 0)