add recommendations button to manga info

(cherry picked from commit 0d370004e6c78597957284d67f1af80881e17a49)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt
#	app/src/main/res/layout/manga_info_controller.xml
#	app/src/main/res/values/strings.xml
This commit is contained in:
Rani Sargees 2020-05-07 17:54:23 -04:00 committed by Jobobby04
parent 38b469755f
commit b0f39a7d0a
6 changed files with 83 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.browse.source.browse
import android.content.res.Configuration
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
@ -49,6 +50,7 @@ import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import eu.kanade.tachiyomi.widget.EmptyView
import exh.EXHSavedSearch
import kotlinx.android.parcel.Parcelize
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -87,6 +89,11 @@ open class BrowseSourceController(bundle: Bundle) :
private val preferences: PreferencesHelper by injectLazy()
private val recommendsConfig: RecommendsConfig? = args.getParcelable(RECOMMENDS_CONFIG)
// AZ -->
private val mode = if (recommendsConfig == null) Mode.CATALOGUE else Mode.RECOMMENDS
// AZ <--
/**
* Adapter containing the list of manga from the catalogue.
*/
@ -122,7 +129,10 @@ open class BrowseSourceController(bundle: Bundle) :
}
override fun getTitle(): String? {
return presenter.source.name
return when (mode) {
Mode.CATALOGUE -> presenter.source.name
Mode.RECOMMENDS -> recommendsConfig!!.origTitle
}
}
override fun createPresenter(): BrowseSourcePresenter {
@ -151,7 +161,7 @@ open class BrowseSourceController(bundle: Bundle) :
}
open fun initFilterSheet() {
if (presenter.sourceFilters.isEmpty()) {
if (presenter.sourceFilters.isEmpty() || mode == Mode.RECOMMENDS) {
return
}
@ -348,6 +358,11 @@ open class BrowseSourceController(bundle: Bundle) :
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.source_browse, menu)
if (mode == Mode.RECOMMENDS) {
menu.findItem(R.id.action_set_filter).isVisible = false
menu.findItem(R.id.action_search).isVisible = false
}
// Initialize search menu
val searchItem = menu.findItem(R.id.action_search)
val searchView = searchItem.actionView as SearchView
@ -389,10 +404,10 @@ open class BrowseSourceController(bundle: Bundle) :
super.onPrepareOptionsMenu(menu)
val isHttpSource = presenter.source is HttpSource
menu.findItem(R.id.action_open_in_web_view).isVisible = isHttpSource
menu.findItem(R.id.action_open_in_web_view).isVisible = isHttpSource && mode == Mode.CATALOGUE
val isLocalSource = presenter.source is LocalSource
menu.findItem(R.id.action_local_source_help).isVisible = isLocalSource
menu.findItem(R.id.action_local_source_help).isVisible = isLocalSource && mode == Mode.CATALOGUE
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -483,7 +498,7 @@ open class BrowseSourceController(bundle: Bundle) :
if (adapter.isEmpty) {
val actions = emptyList<EmptyView.Action>().toMutableList()
if (presenter.source is LocalSource) {
if (presenter.source is LocalSource && mode == Mode.CATALOGUE) {
actions += EmptyView.Action(R.string.local_source_help_guide, View.OnClickListener { openLocalSourceHelpGuide() })
} else {
actions += EmptyView.Action(R.string.action_retry, retryAction)
@ -718,11 +733,20 @@ open class BrowseSourceController(bundle: Bundle) :
}
activity?.toast(activity?.getString(R.string.manga_added_library))
}
@Parcelize
data class RecommendsConfig(val origTitle: String, val origSource: Long) : Parcelable
protected companion object {
enum class Mode {
CATALOGUE,
RECOMMENDS
}
companion object {
const val SOURCE_ID_KEY = "sourceId"
const val SEARCH_QUERY_KEY = "searchQuery"
const val SMART_SEARCH_CONFIG_KEY = "smartSearchConfig"
const val RECOMMENDS_CONFIG = "RECOMMENDS_CONFIG"
}
}

View File

@ -220,9 +220,14 @@ class MangaInfoController(private val fromSource: Boolean = false) :
.launchIn(scope)
// EXH -->
if (smartSearchConfig == null) {
binding.recommendBtn.visible()
binding.recommendBtn.clicks()
.onEach { openRecommends() }
.launchIn(scope)
}
smartSearchConfig?.let { smartSearchConfig ->
binding.mergeBtn.visible()
binding.mergeBtn.clicks()
.onEach {
// Init presenter here to avoid threading issues
@ -269,6 +274,20 @@ class MangaInfoController(private val fromSource: Boolean = false) :
}
// EXH <--
// AZ -->
private fun openRecommends() {
val recommendsConfig = BrowseSourceController.RecommendsConfig(presenter.manga.title, presenter.manga.source)
parentController?.router?.pushController(
BrowseSourceController(
Bundle().apply {
putParcelable(BrowseSourceController.RECOMMENDS_CONFIG, recommendsConfig)
}
).withFadeTransaction()
)
}
// AZ <--
/**
* Check if manga is initialized.
* If true update view with manga information,

View File

@ -177,7 +177,12 @@ class MangaInfoPresenter(
fun moveMangaToCategory(manga: Manga, category: Category?) {
moveMangaToCategories(manga, listOfNotNull(category))
}
/*
suspend fun recommendationView(manga: Manga): Manga {
val title = manga.title
val source = manga.source
}*/
suspend fun smartSearchMerge(manga: Manga, originalMangaId: Long): Manga {
val originalManga = db.getManga(originalMangaId).await()
?: throw IllegalArgumentException("Unknown manga ID: $originalMangaId")

View File

@ -355,6 +355,20 @@
android:visibility="gone"
tools:visibility="visible"/>
<Button
android:id="@+id/recommend_btn"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/az_recommends"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/manga_info_toggle"
tools:layout_constraintTop_toBottomOf="@+id/merge_btn"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -381,10 +381,20 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/merge"
android:text="@string/eh_merge_with_another_source"
android:visibility="gone"
tools:visibility="visible"/>
<Button
android:id="@+id/recommend_btn"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/az_recommends"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -96,4 +96,7 @@
<string name="eh_force_sync_reset_message">Resetting the sync state can cause your next sync to be extremely slow.</string>
<string name="eh_show_update_statistics_dialog">Collecting statistics…</string>
<!-- AZ -->
<string name="az_recommends">See Recommendations</string>
</resources>