Repository: tachiyomiorg/tachiyomi
Issue: [Bug] No dialog box to select categories when auto adding manga

### Device information
* Tachiyomi version: 0.8.5-1936
* Android version: 9

## Steps to reproduce
1. Go to any manga from catalogue
2. Download chapters
3. Select "add to library" ok when prompted at the bottom

### Expected behavior
Dialog box should appear to choose categories to add in. (when option enabled in settings)

### Actual behavior
Nothing appears and manga is added to default category. 


Changed files:
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt
app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt

diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
index 728f5bdde..976257853 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
@@ -13,7 +13,6 @@ import com.bluelinelabs.conductor.RouterTransaction
 import com.bluelinelabs.conductor.support.RouterPagerAdapter
 import com.google.android.material.tabs.TabLayout
 import com.jakewharton.rxrelay.BehaviorRelay
-import com.jakewharton.rxrelay.PublishRelay
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.data.database.DatabaseHelper
 import eu.kanade.tachiyomi.data.database.models.Manga
@@ -63,8 +62,6 @@ class MangaController : RxController<PagerControllerBinding>, TabbedController {
 
     val fromSource = args.getBoolean(FROM_SOURCE_EXTRA, false)
 
-    val mangaFavoriteRelay: PublishRelay<Boolean> = PublishRelay.create()
-
     private val trackingIconRelay: BehaviorRelay<Boolean> = BehaviorRelay.create()
 
     private var trackingIconSubscription: Subscription? = null
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt
index da7808990..57e8de66a 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt
@@ -97,7 +97,7 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
     override fun createPresenter(): MangaInfoChaptersPresenter {
         val ctrl = parentController as MangaController
         return MangaInfoChaptersPresenter(
-            ctrl.manga!!, ctrl.source!!, ctrl.mangaFavoriteRelay
+            ctrl.manga!!, ctrl.source!!
         )
     }
 
@@ -381,35 +381,39 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
             toggleFavorite()
             activity?.toast(activity?.getString(R.string.manga_removed_library))
         } else {
-            val categories = presenter.getCategories()
-            val defaultCategoryId = preferences.defaultCategory()
-            val defaultCategory = categories.find { it.id == defaultCategoryId }
-
-            when {
-                // Default category set
-                defaultCategory != null -> {
-                    toggleFavorite()
-                    presenter.moveMangaToCategory(manga, defaultCategory)
-                    activity?.toast(activity?.getString(R.string.manga_added_library))
-                }
+            addToLibrary(manga)
+        }
+    }
 
-                // Automatic 'Default' or no categories
-                defaultCategoryId == 0 || categories.isEmpty() -> {
-                    toggleFavorite()
-                    presenter.moveMangaToCategory(manga, null)
-                    activity?.toast(activity?.getString(R.string.manga_added_library))
-                }
+    private fun addToLibrary(manga: Manga) {
+        val categories = presenter.getCategories()
+        val defaultCategoryId = preferences.defaultCategory()
+        val defaultCategory = categories.find { it.id == defaultCategoryId }
+
+        when {
+            // Default category set
+            defaultCategory != null -> {
+                toggleFavorite()
+                presenter.moveMangaToCategory(manga, defaultCategory)
+                activity?.toast(activity?.getString(R.string.manga_added_library))
+            }
+
+            // Automatic 'Default' or no categories
+            defaultCategoryId == 0 || categories.isEmpty() -> {
+                toggleFavorite()
+                presenter.moveMangaToCategory(manga, null)
+                activity?.toast(activity?.getString(R.string.manga_added_library))
+            }
 
-                // Choose a category
-                else -> {
-                    val ids = presenter.getMangaCategoryIds(manga)
-                    val preselected = ids.mapNotNull { id ->
-                        categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
-                    }.toTypedArray()
+            // Choose a category
+            else -> {
+                val ids = presenter.getMangaCategoryIds(manga)
+                val preselected = ids.mapNotNull { id ->
+                    categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
+                }.toTypedArray()
 
-                    ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
-                        .showDialog(router)
-                }
+                ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
+                    .showDialog(router)
             }
         }
     }
@@ -758,11 +762,12 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
 
     private fun downloadChapters(chapters: List<ChapterItem>) {
         val view = view
+        val manga = presenter.manga
         presenter.downloadChapters(chapters)
-        if (view != null && !presenter.manga.favorite) {
+        if (view != null && !manga.favorite) {
             binding.recycler.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) {
                 setAction(R.string.action_add) {
-                    presenter.addToLibrary()
+                    addToLibrary(manga)
                 }
             }
         }
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt
index 72cfc7bc2..4644a2144 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt
@@ -30,7 +30,6 @@ import uy.kohesive.injekt.api.get
 class MangaInfoChaptersPresenter(
     val manga: Manga,
     val source: Source,
-    private val mangaFavoriteRelay: PublishRelay<Boolean>,
     val preferences: PreferencesHelper = Injekt.get(),
     private val db: DatabaseHelper = Injekt.get(),
     private val downloadManager: DownloadManager = Injekt.get(),
@@ -79,11 +78,6 @@ class MangaInfoChaptersPresenter(
         getMangaObservable()
             .subscribeLatestCache({ view, manga -> view.onNextMangaInfo(manga, source) })
 
-        // Update favorite status
-        mangaFavoriteRelay.observeOn(AndroidSchedulers.mainThread())
-            .subscribe { setFavorite(it) }
-            .apply { add(this) }
-
         // Prepare the relay.
         chaptersRelay.flatMap { applyChapterFilters(it) }
             .observeOn(AndroidSchedulers.mainThread())
@@ -161,13 +155,6 @@ class MangaInfoChaptersPresenter(
         return manga.favorite
     }
 
-    private fun setFavorite(favorite: Boolean) {
-        if (manga.favorite == favorite) {
-            return
-        }
-        toggleFavorite()
-    }
-
     /**
      * Returns true if the manga has any downloads.
      */
@@ -498,13 +485,6 @@ class MangaInfoChaptersPresenter(
         refreshChapters()
     }
 
-    /**
-     * Adds manga to library
-     */
-    fun addToLibrary() {
-        mangaFavoriteRelay.call(true)
-    }
-
     /**
      * Sets the active display mode.
      * @param mode the mode to set.