mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 00:39:14 +01:00
Fix #373 and a few crashes
This commit is contained in:
parent
a7192e866f
commit
3a1699f0b3
@ -15,11 +15,17 @@ import uy.kohesive.injekt.api.get
|
|||||||
|
|
||||||
interface ActivityMixin {
|
interface ActivityMixin {
|
||||||
|
|
||||||
|
var resumed: Boolean
|
||||||
|
|
||||||
fun setupToolbar(toolbar: Toolbar, backNavigation: Boolean = true) {
|
fun setupToolbar(toolbar: Toolbar, backNavigation: Boolean = true) {
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
getSupportActionBar()?.setDisplayHomeAsUpEnabled(true)
|
getSupportActionBar()?.setDisplayHomeAsUpEnabled(true)
|
||||||
if (backNavigation) {
|
if (backNavigation) {
|
||||||
toolbar.setNavigationOnClickListener { onBackPressed() }
|
toolbar.setNavigationOnClickListener {
|
||||||
|
if (resumed) {
|
||||||
|
onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,15 +5,14 @@ import eu.kanade.tachiyomi.util.LocaleHelper
|
|||||||
|
|
||||||
abstract class BaseActivity : AppCompatActivity(), ActivityMixin {
|
abstract class BaseActivity : AppCompatActivity(), ActivityMixin {
|
||||||
|
|
||||||
|
override var resumed = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
LocaleHelper.updateConfiguration(this)
|
LocaleHelper.updateConfiguration(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getActivity() = this
|
override fun getActivity() = this
|
||||||
|
|
||||||
var resumed = false
|
|
||||||
private set
|
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
resumed = true
|
resumed = true
|
||||||
|
@ -8,6 +8,8 @@ import nucleus.view.NucleusAppCompatActivity
|
|||||||
|
|
||||||
abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>(), ActivityMixin {
|
abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>(), ActivityMixin {
|
||||||
|
|
||||||
|
override var resumed = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
LocaleHelper.updateConfiguration(this)
|
LocaleHelper.updateConfiguration(this)
|
||||||
}
|
}
|
||||||
@ -25,9 +27,6 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
|
|||||||
|
|
||||||
override fun getActivity() = this
|
override fun getActivity() = this
|
||||||
|
|
||||||
var resumed = false
|
|
||||||
private set
|
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
resumed = true
|
resumed = true
|
||||||
|
@ -293,9 +293,12 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
|||||||
*
|
*
|
||||||
* @param mangas the list of manga.
|
* @param mangas the list of manga.
|
||||||
*/
|
*/
|
||||||
fun getCommonCategories(mangas: List<Manga>): Collection<Category> = mangas.toSet()
|
fun getCommonCategories(mangas: List<Manga>): Collection<Category> {
|
||||||
|
if (mangas.isEmpty()) return emptyList()
|
||||||
|
return mangas.toSet()
|
||||||
.map { db.getCategoriesForManga(it).executeAsBlocking() }
|
.map { db.getCategoriesForManga(it).executeAsBlocking() }
|
||||||
.reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) }
|
.reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the selected manga from the library.
|
* Remove the selected manga from the library.
|
||||||
|
@ -118,7 +118,7 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
|
|||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
// Initialize menu items.
|
// 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 menuFilterUnread = menu.findItem(R.id.action_filter_unread)
|
||||||
val menuFilterDownloaded = menu.findItem(R.id.action_filter_downloaded)
|
val menuFilterDownloaded = menu.findItem(R.id.action_filter_downloaded)
|
||||||
val menuFilterBookmarked = menu.findItem(R.id.action_filter_bookmarked)
|
val menuFilterBookmarked = menu.findItem(R.id.action_filter_bookmarked)
|
||||||
|
@ -141,6 +141,11 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
*/
|
*/
|
||||||
private var adjacentChaptersSubscription: Subscription? = null
|
private var adjacentChaptersSubscription: Subscription? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the active chapter has been loaded.
|
||||||
|
*/
|
||||||
|
private var chapterLoaded = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Id of the restartable that loads the active chapter.
|
* Id of the restartable that loads the active chapter.
|
||||||
@ -211,6 +216,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
return loader.loadChapter(chapter)
|
return loader.loadChapter(chapter)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnNext { chapterLoaded = true }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -298,6 +304,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
nextChapter = null
|
nextChapter = null
|
||||||
prevChapter = null
|
prevChapter = null
|
||||||
|
|
||||||
|
chapterLoaded = false
|
||||||
start(LOAD_ACTIVE_CHAPTER)
|
start(LOAD_ACTIVE_CHAPTER)
|
||||||
getAdjacentChapters(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.
|
* @return true if the next chapter is being loaded, false if there is no next chapter.
|
||||||
*/
|
*/
|
||||||
fun loadNextChapter(): Boolean {
|
fun loadNextChapter(): Boolean {
|
||||||
|
// Avoid skipping chapters.
|
||||||
|
if (!chapterLoaded) return true
|
||||||
|
|
||||||
nextChapter?.let {
|
nextChapter?.let {
|
||||||
onChapterLeft()
|
onChapterLeft()
|
||||||
loadChapter(it, 0)
|
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.
|
* @return true if the previous chapter is being loaded, false if there is no previous chapter.
|
||||||
*/
|
*/
|
||||||
fun loadPreviousChapter(): Boolean {
|
fun loadPreviousChapter(): Boolean {
|
||||||
|
// Avoid skipping chapters.
|
||||||
|
if (!chapterLoaded) return true
|
||||||
|
|
||||||
prevChapter?.let {
|
prevChapter?.let {
|
||||||
onChapterLeft()
|
onChapterLeft()
|
||||||
loadChapter(it, if (it.read) -1 else 0)
|
loadChapter(it, if (it.read) -1 else 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user