Replace more Kotlin synthetics

This commit is contained in:
arkon 2020-11-28 15:54:53 -05:00
parent 749c2071af
commit 019a0f31c7
16 changed files with 116 additions and 120 deletions

View File

@ -491,13 +491,13 @@ open class BrowseSourceController(bundle: Bundle) :
* @param manga the manga to find. * @param manga the manga to find.
* @return the holder of the manga or null if it's not bound. * @return the holder of the manga or null if it's not bound.
*/ */
private fun getHolder(manga: Manga): SourceHolder? { private fun getHolder(manga: Manga): SourceHolder<*>? {
val adapter = adapter ?: return null val adapter = adapter ?: return null
adapter.allBoundViewHolders.forEach { holder -> adapter.allBoundViewHolders.forEach { holder ->
val item = adapter.getItem(holder.bindingAdapterPosition) as? SourceItem val item = adapter.getItem(holder.bindingAdapterPosition) as? SourceItem
if (item != null && item.manga.id!! == manga.id!!) { if (item != null && item.manga.id!! == manga.id!!) {
return holder as SourceHolder return holder as SourceHolder<*>
} }
} }

View File

@ -18,9 +18,9 @@ import eu.kanade.tachiyomi.widget.StateImageViewTarget
* @constructor creates a new catalogue holder. * @constructor creates a new catalogue holder.
*/ */
class SourceComfortableGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) : class SourceComfortableGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
SourceGridHolder(view, adapter) { SourceHolder<SourceComfortableGridItemBinding>(view, adapter) {
private val binding = SourceComfortableGridItemBinding.bind(view) override val binding = SourceComfortableGridItemBinding.bind(view)
/** /**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this

View File

@ -18,9 +18,9 @@ import eu.kanade.tachiyomi.widget.StateImageViewTarget
* @constructor creates a new catalogue holder. * @constructor creates a new catalogue holder.
*/ */
open class SourceGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) : open class SourceGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
SourceHolder(view, adapter) { SourceHolder<SourceComfortableGridItemBinding>(view, adapter) {
private val binding = SourceComfortableGridItemBinding.bind(view) override val binding = SourceComfortableGridItemBinding.bind(view)
/** /**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.browse.source.browse package eu.kanade.tachiyomi.ui.browse.source.browse
import android.view.View import android.view.View
import androidx.viewbinding.ViewBinding
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.viewholders.FlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
@ -11,9 +12,11 @@ import eu.kanade.tachiyomi.data.database.models.Manga
* @param view the inflated view for this holder. * @param view the inflated view for this holder.
* @param adapter the adapter handling this holder. * @param adapter the adapter handling this holder.
*/ */
abstract class SourceHolder(view: View, adapter: FlexibleAdapter<*>) : abstract class SourceHolder<VB : ViewBinding>(view: View, adapter: FlexibleAdapter<*>) :
FlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
abstract val binding: VB
/** /**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga. * holder with the given manga.

View File

@ -13,12 +13,12 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
import eu.kanade.tachiyomi.databinding.SourceCompactGridItemBinding
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.source_compact_grid_item.view.card
import kotlinx.android.synthetic.main.source_compact_grid_item.view.gradient
class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMode>) : class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMode>) :
AbstractFlexibleItem<SourceHolder>() { AbstractFlexibleItem<SourceHolder<*>>() {
override fun getLayoutRes(): Int { override fun getLayoutRes(): Int {
return when (displayMode.get()) { return when (displayMode.get()) {
@ -31,17 +31,18 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
override fun createViewHolder( override fun createViewHolder(
view: View, view: View,
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>> adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
): SourceHolder { ): SourceHolder<*> {
return when (displayMode.get()) { return when (displayMode.get()) {
DisplayMode.COMPACT_GRID -> { DisplayMode.COMPACT_GRID -> {
val binding = SourceCompactGridItemBinding.bind(view)
val parent = adapter.recyclerView as AutofitRecyclerView val parent = adapter.recyclerView as AutofitRecyclerView
val coverHeight = parent.itemWidth / 3 * 4 val coverHeight = parent.itemWidth / 3 * 4
view.apply { view.apply {
card.layoutParams = FrameLayout.LayoutParams( binding.card.layoutParams = FrameLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT,
coverHeight coverHeight
) )
gradient.layoutParams = FrameLayout.LayoutParams( binding.gradient.layoutParams = FrameLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT,
coverHeight / 2, coverHeight / 2,
Gravity.BOTTOM Gravity.BOTTOM
@ -50,10 +51,11 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
SourceGridHolder(view, adapter) SourceGridHolder(view, adapter)
} }
DisplayMode.COMFORTABLE_GRID -> { DisplayMode.COMFORTABLE_GRID -> {
val binding = SourceComfortableGridItemBinding.bind(view)
val parent = adapter.recyclerView as AutofitRecyclerView val parent = adapter.recyclerView as AutofitRecyclerView
val coverHeight = parent.itemWidth / 3 * 4 val coverHeight = parent.itemWidth / 3 * 4
view.apply { view.apply {
card.layoutParams = ConstraintLayout.LayoutParams( binding.card.layoutParams = ConstraintLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT,
coverHeight coverHeight
) )
@ -68,7 +70,7 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
override fun bindViewHolder( override fun bindViewHolder(
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
holder: SourceHolder, holder: SourceHolder<*>,
position: Int, position: Int,
payloads: List<Any?>? payloads: List<Any?>?
) { ) {

View File

@ -22,9 +22,9 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
* @constructor creates a new catalogue holder. * @constructor creates a new catalogue holder.
*/ */
class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) : class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
SourceHolder(view, adapter) { SourceHolder<SourceListItemBinding>(view, adapter) {
private val binding = SourceListItemBinding.bind(view) override val binding = SourceListItemBinding.bind(view)
private val favoriteColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f) private val favoriteColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f)
private val unfavoriteColor = view.context.getResourceColor(R.attr.colorOnSurface) private val unfavoriteColor = view.context.getResourceColor(R.attr.colorOnSurface)

View File

@ -183,7 +183,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
val position = adapter.indexOf(manga) val position = adapter.indexOf(manga)
if (position != -1 && !adapter.isSelected(position)) { if (position != -1 && !adapter.isSelected(position)) {
adapter.toggleSelection(position) adapter.toggleSelection(position)
(recycler.findViewHolderForItemId(manga.id!!) as? LibraryHolder)?.toggleActivation() (recycler.findViewHolderForItemId(manga.id!!) as? LibraryHolder<*>)?.toggleActivation()
} }
} }
} }
@ -227,7 +227,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
val position = adapter.indexOf(manga) val position = adapter.indexOf(manga)
if (position != -1) { if (position != -1) {
adapter.toggleSelection(position) adapter.toggleSelection(position)
(recycler.findViewHolderForItemId(manga.id!!) as? LibraryHolder)?.toggleActivation() (recycler.findViewHolderForItemId(manga.id!!) as? LibraryHolder<*>)?.toggleActivation()
} }
} }

View File

@ -23,9 +23,9 @@ import eu.kanade.tachiyomi.util.isLocal
class LibraryComfortableGridHolder( class LibraryComfortableGridHolder(
private val view: View, private val view: View,
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>> adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
) : LibraryCompactGridHolder(view, adapter) { ) : LibraryHolder<SourceComfortableGridItemBinding>(view, adapter) {
private val binding = SourceComfortableGridItemBinding.bind(view) override val binding = SourceComfortableGridItemBinding.bind(view)
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this

View File

@ -21,9 +21,9 @@ import eu.kanade.tachiyomi.util.isLocal
open class LibraryCompactGridHolder( open class LibraryCompactGridHolder(
private val view: View, private val view: View,
private val adapter: FlexibleAdapter<*> private val adapter: FlexibleAdapter<*>
) : LibraryHolder(view, adapter) { ) : LibraryHolder<SourceCompactGridItemBinding>(view, adapter) {
private val binding = SourceCompactGridItemBinding.bind(view) override val binding = SourceCompactGridItemBinding.bind(view)
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.view.View import android.view.View
import androidx.viewbinding.ViewBinding
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.viewholders.FlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
@ -11,11 +12,13 @@ import eu.davidea.viewholders.FlexibleViewHolder
* @param listener a listener to react to the single tap and long tap events. * @param listener a listener to react to the single tap and long tap events.
*/ */
abstract class LibraryHolder( abstract class LibraryHolder<VB : ViewBinding>(
view: View, view: View,
adapter: FlexibleAdapter<*> adapter: FlexibleAdapter<*>
) : FlexibleViewHolder(view, adapter) { ) : FlexibleViewHolder(view, adapter) {
abstract val binding: VB
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga. * holder with the given manga.

View File

@ -14,15 +14,15 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
import eu.kanade.tachiyomi.databinding.SourceCompactGridItemBinding
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.source_compact_grid_item.view.card
import kotlinx.android.synthetic.main.source_compact_grid_item.view.gradient
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Preference<DisplayMode>) : class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Preference<DisplayMode>) :
AbstractFlexibleItem<LibraryHolder>(), IFilterable<String> { AbstractFlexibleItem<LibraryHolder<*>>(), IFilterable<String> {
private val sourceManager: SourceManager = Injekt.get() private val sourceManager: SourceManager = Injekt.get()
@ -37,14 +37,15 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
} }
} }
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): LibraryHolder { override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): LibraryHolder<*> {
return when (libraryDisplayMode.get()) { return when (libraryDisplayMode.get()) {
DisplayMode.COMPACT_GRID -> { DisplayMode.COMPACT_GRID -> {
val binding = SourceCompactGridItemBinding.bind(view)
val parent = adapter.recyclerView as AutofitRecyclerView val parent = adapter.recyclerView as AutofitRecyclerView
val coverHeight = parent.itemWidth / 3 * 4 val coverHeight = parent.itemWidth / 3 * 4
view.apply { view.apply {
card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight) binding.card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight)
gradient.layoutParams = FrameLayout.LayoutParams( binding.gradient.layoutParams = FrameLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT,
coverHeight / 2, coverHeight / 2,
Gravity.BOTTOM Gravity.BOTTOM
@ -53,10 +54,11 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
LibraryCompactGridHolder(view, adapter) LibraryCompactGridHolder(view, adapter)
} }
DisplayMode.COMFORTABLE_GRID -> { DisplayMode.COMFORTABLE_GRID -> {
val binding = SourceComfortableGridItemBinding.bind(view)
val parent = adapter.recyclerView as AutofitRecyclerView val parent = adapter.recyclerView as AutofitRecyclerView
val coverHeight = parent.itemWidth / 3 * 4 val coverHeight = parent.itemWidth / 3 * 4
view.apply { view.apply {
card.layoutParams = ConstraintLayout.LayoutParams( binding.card.layoutParams = ConstraintLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT,
coverHeight coverHeight
) )
@ -71,7 +73,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
override fun bindViewHolder( override fun bindViewHolder(
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
holder: LibraryHolder, holder: LibraryHolder<*>,
position: Int, position: Int,
payloads: List<Any?>? payloads: List<Any?>?
) { ) {

View File

@ -22,13 +22,12 @@ import eu.kanade.tachiyomi.util.isLocal
* @param listener a listener to react to single tap and long tap events. * @param listener a listener to react to single tap and long tap events.
* @constructor creates a new library holder. * @constructor creates a new library holder.
*/ */
class LibraryListHolder( class LibraryListHolder(
private val view: View, private val view: View,
private val adapter: FlexibleAdapter<*> private val adapter: FlexibleAdapter<*>
) : LibraryHolder(view, adapter) { ) : LibraryHolder<SourceListItemBinding>(view, adapter) {
private val binding = SourceListItemBinding.bind(view) override val binding = SourceListItemBinding.bind(view)
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this

View File

@ -9,16 +9,8 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.databinding.TrackSearchItemBinding
import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.util.view.inflate
import kotlinx.android.synthetic.main.track_search_item.view.track_search_cover
import kotlinx.android.synthetic.main.track_search_item.view.track_search_start
import kotlinx.android.synthetic.main.track_search_item.view.track_search_start_result
import kotlinx.android.synthetic.main.track_search_item.view.track_search_status
import kotlinx.android.synthetic.main.track_search_item.view.track_search_status_result
import kotlinx.android.synthetic.main.track_search_item.view.track_search_summary
import kotlinx.android.synthetic.main.track_search_item.view.track_search_title
import kotlinx.android.synthetic.main.track_search_item.view.track_search_type
import kotlinx.android.synthetic.main.track_search_item.view.track_search_type_result
class TrackSearchAdapter(context: Context) : class TrackSearchAdapter(context: Context) :
ArrayAdapter<TrackSearch>(context, R.layout.track_search_item, mutableListOf<TrackSearch>()) { ArrayAdapter<TrackSearch>(context, R.layout.track_search_item, mutableListOf<TrackSearch>()) {
@ -49,37 +41,39 @@ class TrackSearchAdapter(context: Context) :
class TrackSearchHolder(private val view: View) { class TrackSearchHolder(private val view: View) {
private val binding = TrackSearchItemBinding.bind(view)
fun onSetValues(track: TrackSearch) { fun onSetValues(track: TrackSearch) {
view.track_search_title.text = track.title binding.trackSearchTitle.text = track.title
view.track_search_summary.text = track.summary binding.trackSearchSummary.text = track.summary
GlideApp.with(view.context).clear(view.track_search_cover) GlideApp.with(view.context).clear(binding.trackSearchCover)
if (!track.cover_url.isEmpty()) { if (!track.cover_url.isEmpty()) {
GlideApp.with(view.context) GlideApp.with(view.context)
.load(track.cover_url) .load(track.cover_url)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .centerCrop()
.into(view.track_search_cover) .into(binding.trackSearchCover)
} }
if (track.publishing_status.isBlank()) { if (track.publishing_status.isBlank()) {
view.track_search_status.isVisible = false binding.trackSearchStatus.isVisible = false
view.track_search_status_result.isVisible = false binding.trackSearchStatusResult.isVisible = false
} else { } else {
view.track_search_status_result.text = track.publishing_status.capitalize() binding.trackSearchStatusResult.text = track.publishing_status.capitalize()
} }
if (track.publishing_type.isBlank()) { if (track.publishing_type.isBlank()) {
view.track_search_type.isVisible = false binding.trackSearchType.isVisible = false
view.track_search_type_result.isVisible = false binding.trackSearchTypeResult.isVisible = false
} else { } else {
view.track_search_type_result.text = track.publishing_type.capitalize() binding.trackSearchTypeResult.text = track.publishing_type.capitalize()
} }
if (track.start_date.isBlank()) { if (track.start_date.isBlank()) {
view.track_search_start.isVisible = false binding.trackSearchStart.isVisible = false
view.track_search_start_result.isVisible = false binding.trackSearchStartResult.isVisible = false
} else { } else {
view.track_search_start_result.text = track.start_date binding.trackSearchStartResult.text = track.start_date
} }
} }
} }

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga.track
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View import android.view.View
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
@ -13,10 +14,8 @@ import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.databinding.TrackSearchDialogBinding
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import kotlinx.android.synthetic.main.track_search_dialog.view.progress
import kotlinx.android.synthetic.main.track_search_dialog.view.track_search
import kotlinx.android.synthetic.main.track_search_dialog.view.track_search_list
import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
@ -29,7 +28,7 @@ import java.util.concurrent.TimeUnit
class TrackSearchDialog : DialogController { class TrackSearchDialog : DialogController {
private var dialogView: View? = null private var binding: TrackSearchDialogBinding? = null
private var adapter: TrackSearchAdapter? = null private var adapter: TrackSearchAdapter? = null
@ -53,13 +52,13 @@ class TrackSearchDialog : DialogController {
} }
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
binding = TrackSearchDialogBinding.inflate(LayoutInflater.from(activity!!))
val dialog = MaterialDialog(activity!!) val dialog = MaterialDialog(activity!!)
.customView(R.layout.track_search_dialog) .customView(view = binding!!.root)
.positiveButton(android.R.string.ok) { onPositiveButtonClick() } .positiveButton(android.R.string.ok) { onPositiveButtonClick() }
.negativeButton(android.R.string.cancel) .negativeButton(android.R.string.cancel)
.neutralButton(R.string.action_remove) { onRemoveButtonClick() } .neutralButton(R.string.action_remove) { onRemoveButtonClick() }
dialogView = dialog.view
onViewCreated(dialog.view, savedViewState) onViewCreated(dialog.view, savedViewState)
return dialog return dialog
@ -69,12 +68,12 @@ class TrackSearchDialog : DialogController {
// Create adapter // Create adapter
val adapter = TrackSearchAdapter(view.context) val adapter = TrackSearchAdapter(view.context)
this.adapter = adapter this.adapter = adapter
view.track_search_list.adapter = adapter binding!!.trackSearchList.adapter = adapter
// Set listeners // Set listeners
selectedItem = null selectedItem = null
view.track_search_list.itemClicks() binding!!.trackSearchList.itemClicks()
.onEach { position -> .onEach { position ->
selectedItem = adapter.getItem(position) selectedItem = adapter.getItem(position)
} }
@ -83,20 +82,20 @@ class TrackSearchDialog : DialogController {
// Do an initial search based on the manga's title // Do an initial search based on the manga's title
if (savedState == null) { if (savedState == null) {
val title = trackController.presenter.manga.title val title = trackController.presenter.manga.title
view.track_search.append(title) binding!!.trackSearch.append(title)
search(title) search(title)
} }
} }
override fun onDestroyView(view: View) { override fun onDestroyView(view: View) {
super.onDestroyView(view) super.onDestroyView(view)
dialogView = null binding = null
adapter = null adapter = null
} }
override fun onAttach(view: View) { override fun onAttach(view: View) {
super.onAttach(view) super.onAttach(view)
dialogView!!.track_search.textChanges() binding!!.trackSearch.textChanges()
.debounce(TimeUnit.SECONDS.toMillis(1)) .debounce(TimeUnit.SECONDS.toMillis(1))
.filter { it.isNotBlank() } .filter { it.isNotBlank() }
.onEach { search(it.toString()) } .onEach { search(it.toString()) }
@ -104,24 +103,24 @@ class TrackSearchDialog : DialogController {
} }
private fun search(query: String) { private fun search(query: String) {
val view = dialogView ?: return val binding = binding ?: return
view.progress.isVisible = true binding.progress.isVisible = true
view.track_search_list.isInvisible = true binding.trackSearchList.isInvisible = true
trackController.presenter.search(query, service) trackController.presenter.search(query, service)
} }
fun onSearchResults(results: List<TrackSearch>) { fun onSearchResults(results: List<TrackSearch>) {
selectedItem = null selectedItem = null
val view = dialogView ?: return val binding = binding ?: return
view.progress.isInvisible = true binding.progress.isInvisible = true
view.track_search_list.isVisible = true binding.trackSearchList.isVisible = true
adapter?.setItems(results) adapter?.setItems(results)
} }
fun onSearchResultsError() { fun onSearchResultsError() {
val view = dialogView ?: return val binding = binding ?: return
view.progress.isVisible = true binding.progress.isVisible = true
view.track_search_list.isInvisible = true binding.trackSearchList.isInvisible = true
adapter?.setItems(emptyList()) adapter?.setItems(emptyList())
} }

View File

@ -9,9 +9,6 @@ import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.widget.preference.LoginDialogPreference import eu.kanade.tachiyomi.widget.preference.LoginDialogPreference
import kotlinx.android.synthetic.main.pref_account_login.view.login
import kotlinx.android.synthetic.main.pref_account_login.view.password
import kotlinx.android.synthetic.main.pref_account_login.view.username
import rx.android.schedulers.AndroidSchedulers import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
@ -31,38 +28,36 @@ class TrackLoginDialog(
constructor(service: TrackService, @StringRes usernameLabelRes: Int?) : constructor(service: TrackService, @StringRes usernameLabelRes: Int?) :
this(R.string.login_title, service.name, usernameLabelRes, bundleOf("key" to service.id)) this(R.string.login_title, service.name, usernameLabelRes, bundleOf("key" to service.id))
override fun setCredentialsOnView(view: View) = with(view) { override fun setCredentialsOnView(view: View) {
username.setText(service.getUsername()) binding?.username?.setText(service.getUsername())
password.setText(service.getPassword()) binding?.password?.setText(service.getPassword())
} }
override fun checkLogin() { override fun checkLogin() {
requestSubscription?.unsubscribe() requestSubscription?.unsubscribe()
v?.apply { if (binding!!.username.text.isNullOrEmpty() || binding!!.password.text.isNullOrEmpty()) {
if (username.text.isNullOrEmpty() || password.text.isNullOrEmpty()) { return
return
}
login.progress = 1
val user = username.text.toString()
val pass = password.text.toString()
requestSubscription = service.login(user, pass)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
dialog?.dismiss()
context.toast(R.string.login_success)
},
{ error ->
login.progress = -1
login.setText(R.string.unknown_error)
error.message?.let { context.toast(it) }
}
)
} }
binding!!.login.progress = 1
val user = binding!!.username.text.toString()
val pass = binding!!.password.text.toString()
requestSubscription = service.login(user, pass)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
dialog?.dismiss()
view?.context?.toast(R.string.login_success)
},
{ error ->
binding!!.login.progress = -1
binding!!.login.setText(R.string.unknown_error)
error.message?.let { view?.context?.toast(it) }
}
)
} }
override fun onDialogClosed() { override fun onDialogClosed() {

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.widget.preference
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View import android.view.View
import androidx.annotation.StringRes import androidx.annotation.StringRes
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
@ -9,11 +10,9 @@ import com.afollestad.materialdialogs.customview.customView
import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
import com.dd.processbutton.iml.ActionProcessButton import com.dd.processbutton.iml.ActionProcessButton
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import kotlinx.android.synthetic.main.pref_account_login.view.login
import kotlinx.android.synthetic.main.pref_account_login.view.username_label
import rx.Subscription import rx.Subscription
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -24,7 +23,7 @@ abstract class LoginDialogPreference(
bundle: Bundle? = null bundle: Bundle? = null
) : DialogController(bundle) { ) : DialogController(bundle) {
var v: View? = null var binding: PrefAccountLoginBinding? = null
private set private set
val preferences: PreferencesHelper by injectLazy() val preferences: PreferencesHelper by injectLazy()
@ -32,8 +31,9 @@ abstract class LoginDialogPreference(
var requestSubscription: Subscription? = null var requestSubscription: Subscription? = null
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
binding = PrefAccountLoginBinding.inflate(LayoutInflater.from(activity!!))
var dialog = MaterialDialog(activity!!) var dialog = MaterialDialog(activity!!)
.customView(R.layout.pref_account_login) .customView(view = binding!!.root)
.negativeButton(android.R.string.cancel) .negativeButton(android.R.string.cancel)
if (titleRes != null) { if (titleRes != null) {
@ -46,16 +46,14 @@ abstract class LoginDialogPreference(
} }
fun onViewCreated(view: View) { fun onViewCreated(view: View) {
v = view.apply { if (usernameLabelRes != null) {
if (usernameLabelRes != null) { binding!!.usernameLabel.hint = view.context.getString(usernameLabelRes)
username_label.hint = context.getString(usernameLabelRes)
}
login.setMode(ActionProcessButton.Mode.ENDLESS)
login.setOnClickListener { checkLogin() }
setCredentialsOnView(this)
} }
binding!!.login.setMode(ActionProcessButton.Mode.ENDLESS)
binding!!.login.setOnClickListener { checkLogin() }
setCredentialsOnView(view)
} }
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
@ -67,6 +65,7 @@ abstract class LoginDialogPreference(
open fun onDialogClosed() { open fun onDialogClosed() {
requestSubscription?.unsubscribe() requestSubscription?.unsubscribe()
binding = null
} }
protected abstract fun checkLogin() protected abstract fun checkLogin()