Initial work on SmartSearch

This commit is contained in:
NerdNumber9
2019-07-29 02:12:30 -04:00
parent b5263a6968
commit 8934d251d9
12 changed files with 361 additions and 15 deletions

View File

@@ -1,6 +1,8 @@
package eu.kanade.tachiyomi.ui.catalogue
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.os.Bundle
import android.os.Parcelable
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.SearchView
import android.view.*
@@ -23,6 +25,8 @@ import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController
import eu.kanade.tachiyomi.ui.catalogue.latest.LatestUpdatesController
import eu.kanade.tachiyomi.ui.setting.SettingsSourcesController
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
import exh.ui.smartsearch.SmartSearchController
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.catalogue_main_controller.*
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@@ -34,7 +38,7 @@ import uy.kohesive.injekt.api.get
* [CatalogueAdapter.OnBrowseClickListener] call function data on browse item click.
* [CatalogueAdapter.OnLatestClickListener] call function data on latest item click
*/
class CatalogueController : NucleusController<CataloguePresenter>(),
class CatalogueController(bundle: Bundle? = null) : NucleusController<CataloguePresenter>(bundle),
SourceLoginDialog.Listener,
FlexibleAdapter.OnItemClickListener,
CatalogueAdapter.OnBrowseClickListener,
@@ -50,12 +54,18 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
*/
private var adapter: CatalogueAdapter? = null
private val smartSearchConfig: SmartSearchConfig? = args.getParcelable(SMART_SEARCH_CONFIG)
// EXH -->
private val mode = if(smartSearchConfig == null) Mode.CATALOGUE else Mode.SMART_SEARCH
// EXH <--
/**
* Called when controller is initialized.
*/
init {
// Enable the option menu
setHasOptionsMenu(true)
setHasOptionsMenu(mode == Mode.CATALOGUE)
}
/**
@@ -64,7 +74,10 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
* @return title.
*/
override fun getTitle(): String? {
return applicationContext?.getString(R.string.label_catalogues)
return when(mode) {
Mode.CATALOGUE -> applicationContext?.getString(R.string.label_catalogues)
Mode.SMART_SEARCH -> "Find in another source"
}
}
/**
@@ -73,7 +86,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
* @return instance of [CataloguePresenter]
*/
override fun createPresenter(): CataloguePresenter {
return CataloguePresenter()
return CataloguePresenter(controllerMode = mode)
}
/**
@@ -140,8 +153,16 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
dialog.targetController = this
dialog.showDialog(router)
} else {
// Open the catalogue view.
openCatalogue(source, BrowseCatalogueController(source))
when(mode) {
Mode.CATALOGUE -> {
// Open the catalogue view.
openCatalogue(source, BrowseCatalogueController(source))
}
Mode.SMART_SEARCH -> router.pushController(SmartSearchController(Bundle().apply {
putLong(SmartSearchController.ARG_SOURCE_ID, source.id)
putParcelable(SmartSearchController.ARG_SMART_SEARCH_CONFIG, smartSearchConfig)
}).withFadeTransaction())
}
}
return false
}
@@ -233,4 +254,18 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
}
class SettingsSourcesFadeChangeHandler : FadeChangeHandler()
// EXH -->
@Parcelize
data class SmartSearchConfig(val title: String) : Parcelable
// EXH <--
enum class Mode {
CATALOGUE,
SMART_SEARCH
}
companion object {
const val SMART_SEARCH_CONFIG = "SMART_SEARCH_CONFIG"
}
}

View File

@@ -24,7 +24,8 @@ import java.util.concurrent.TimeUnit
*/
class CataloguePresenter(
val sourceManager: SourceManager = Injekt.get(),
private val preferences: PreferencesHelper = Injekt.get()
private val preferences: PreferencesHelper = Injekt.get(),
private val controllerMode: CatalogueController.Mode
) : BasePresenter<CatalogueController>() {
/**
@@ -62,7 +63,7 @@ class CataloguePresenter(
val byLang = sources.groupByTo(map, { it.lang })
val sourceItems = byLang.flatMap {
val langItem = LangItem(it.key)
it.value.map { source -> SourceItem(source, langItem) }
it.value.map { source -> SourceItem(source, langItem, controllerMode == CatalogueController.Mode.CATALOGUE) }
}
sourceSubscription = Observable.just(sourceItems)
@@ -77,7 +78,7 @@ class CataloguePresenter(
sharedObs.take(1),
sharedObs.skip(1).delay(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread()))
.distinctUntilChanged()
.map { (sourceManager.get(it) as? CatalogueSource)?.let { SourceItem(it) } }
.map { (sourceManager.get(it) as? CatalogueSource)?.let { SourceItem(it, showButtons = controllerMode == CatalogueController.Mode.CATALOGUE) } }
.subscribeLatestCache(CatalogueController::setLastUsedSource)
}

View File

@@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.util.visible
import io.github.mthli.slice.Slice
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.*
class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
class SourceHolder(view: View, override val adapter: CatalogueAdapter, val showButtons: Boolean) :
BaseFlexibleViewHolder(view, adapter),
SlicedHolder {
@@ -30,6 +30,11 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
source_latest.setOnClickListener {
adapter.latestClickListener.onLatestClick(adapterPosition)
}
if(!showButtons) {
source_browse.gone()
source_latest.gone()
}
}
fun bind(item: SourceItem) {
@@ -50,7 +55,7 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
source_latest.gone()
} else {
source_browse.setText(R.string.browse)
if (source.supportsLatest) {
if (source.supportsLatest && showButtons) {
source_latest.visible()
} else {
source_latest.gone()

View File

@@ -14,7 +14,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource
* @param source Instance of [CatalogueSource] containing source information.
* @param header The header for this item.
*/
data class SourceItem(val source: CatalogueSource, val header: LangItem? = null) :
data class SourceItem(val source: CatalogueSource, val header: LangItem? = null, val showButtons: Boolean) :
AbstractSectionableItem<SourceHolder, LangItem>(header) {
/**
@@ -28,7 +28,7 @@ data class SourceItem(val source: CatalogueSource, val header: LangItem? = null)
* Creates a new view holder for this item.
*/
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): SourceHolder {
return SourceHolder(view, adapter as CatalogueAdapter)
return SourceHolder(view, adapter as CatalogueAdapter, showButtons)
}
/**

View File

@@ -38,6 +38,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.catalogue.CatalogueController
import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
import eu.kanade.tachiyomi.ui.main.MainActivity
@@ -160,6 +161,9 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
// EXH -->
R.id.action_smart_search -> openSmartSearch()
// EXH <--
R.id.action_open_in_browser -> openInBrowser()
R.id.action_open_in_web_view -> openInWebView()
R.id.action_share -> shareManga()
@@ -169,6 +173,17 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
return true
}
// EXH -->
private fun openSmartSearch() {
val smartSearchConfig = CatalogueController.SmartSearchConfig(presenter.manga.title)
parentController?.router?.pushController(CatalogueController(Bundle().apply {
putParcelable(CatalogueController.SMART_SEARCH_CONFIG, smartSearchConfig)
}).withFadeTransaction())
}
// EXH <--
/**
* Check if manga is initialized.
* If true update view with manga information,