mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 04:49:17 +01:00
Replace more Kotlin synthetics
This commit is contained in:
parent
749c2071af
commit
019a0f31c7
@ -491,13 +491,13 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
* @param manga the manga to find.
|
||||
* @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
|
||||
|
||||
adapter.allBoundViewHolders.forEach { holder ->
|
||||
val item = adapter.getItem(holder.bindingAdapterPosition) as? SourceItem
|
||||
if (item != null && item.manga.id!! == manga.id!!) {
|
||||
return holder as SourceHolder
|
||||
return holder as SourceHolder<*>
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,9 @@ import eu.kanade.tachiyomi.widget.StateImageViewTarget
|
||||
* @constructor creates a new catalogue holder.
|
||||
*/
|
||||
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
|
||||
|
@ -18,9 +18,9 @@ import eu.kanade.tachiyomi.widget.StateImageViewTarget
|
||||
* @constructor creates a new catalogue holder.
|
||||
*/
|
||||
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
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.source.browse
|
||||
|
||||
import android.view.View
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
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 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) {
|
||||
|
||||
abstract val binding: VB
|
||||
|
||||
/**
|
||||
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
|
||||
* holder with the given manga.
|
||||
|
@ -13,12 +13,12 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
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 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>) :
|
||||
AbstractFlexibleItem<SourceHolder>() {
|
||||
AbstractFlexibleItem<SourceHolder<*>>() {
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return when (displayMode.get()) {
|
||||
@ -31,17 +31,18 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
|
||||
override fun createViewHolder(
|
||||
view: View,
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
): SourceHolder {
|
||||
): SourceHolder<*> {
|
||||
return when (displayMode.get()) {
|
||||
DisplayMode.COMPACT_GRID -> {
|
||||
val binding = SourceCompactGridItemBinding.bind(view)
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
card.layoutParams = FrameLayout.LayoutParams(
|
||||
binding.card.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight
|
||||
)
|
||||
gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
binding.gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight / 2,
|
||||
Gravity.BOTTOM
|
||||
@ -50,10 +51,11 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
|
||||
SourceGridHolder(view, adapter)
|
||||
}
|
||||
DisplayMode.COMFORTABLE_GRID -> {
|
||||
val binding = SourceComfortableGridItemBinding.bind(view)
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
card.layoutParams = ConstraintLayout.LayoutParams(
|
||||
binding.card.layoutParams = ConstraintLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight
|
||||
)
|
||||
@ -68,7 +70,7 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
|
||||
|
||||
override fun bindViewHolder(
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
||||
holder: SourceHolder,
|
||||
holder: SourceHolder<*>,
|
||||
position: Int,
|
||||
payloads: List<Any?>?
|
||||
) {
|
||||
|
@ -22,9 +22,9 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
* @constructor creates a new catalogue holder.
|
||||
*/
|
||||
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 unfavoriteColor = view.context.getResourceColor(R.attr.colorOnSurface)
|
||||
|
@ -183,7 +183,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
val position = adapter.indexOf(manga)
|
||||
if (position != -1 && !adapter.isSelected(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)
|
||||
if (position != -1) {
|
||||
adapter.toggleSelection(position)
|
||||
(recycler.findViewHolderForItemId(manga.id!!) as? LibraryHolder)?.toggleActivation()
|
||||
(recycler.findViewHolderForItemId(manga.id!!) as? LibraryHolder<*>)?.toggleActivation()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,9 @@ import eu.kanade.tachiyomi.util.isLocal
|
||||
class LibraryComfortableGridHolder(
|
||||
private val view: View,
|
||||
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
|
||||
|
@ -21,9 +21,9 @@ import eu.kanade.tachiyomi.util.isLocal
|
||||
open class LibraryCompactGridHolder(
|
||||
private val view: View,
|
||||
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
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import android.view.View
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
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.
|
||||
*/
|
||||
|
||||
abstract class LibraryHolder(
|
||||
abstract class LibraryHolder<VB : ViewBinding>(
|
||||
view: View,
|
||||
adapter: FlexibleAdapter<*>
|
||||
) : FlexibleViewHolder(view, adapter) {
|
||||
|
||||
abstract val binding: VB
|
||||
|
||||
/**
|
||||
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
|
||||
* holder with the given manga.
|
||||
|
@ -14,15 +14,15 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||
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.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.api.get
|
||||
|
||||
class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Preference<DisplayMode>) :
|
||||
AbstractFlexibleItem<LibraryHolder>(), IFilterable<String> {
|
||||
AbstractFlexibleItem<LibraryHolder<*>>(), IFilterable<String> {
|
||||
|
||||
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()) {
|
||||
DisplayMode.COMPACT_GRID -> {
|
||||
val binding = SourceCompactGridItemBinding.bind(view)
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight)
|
||||
gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
binding.card.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, coverHeight)
|
||||
binding.gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight / 2,
|
||||
Gravity.BOTTOM
|
||||
@ -53,10 +54,11 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
|
||||
LibraryCompactGridHolder(view, adapter)
|
||||
}
|
||||
DisplayMode.COMFORTABLE_GRID -> {
|
||||
val binding = SourceComfortableGridItemBinding.bind(view)
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
card.layoutParams = ConstraintLayout.LayoutParams(
|
||||
binding.card.layoutParams = ConstraintLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight
|
||||
)
|
||||
@ -71,7 +73,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe
|
||||
|
||||
override fun bindViewHolder(
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
||||
holder: LibraryHolder,
|
||||
holder: LibraryHolder<*>,
|
||||
position: Int,
|
||||
payloads: List<Any?>?
|
||||
) {
|
||||
|
@ -22,13 +22,12 @@ import eu.kanade.tachiyomi.util.isLocal
|
||||
* @param listener a listener to react to single tap and long tap events.
|
||||
* @constructor creates a new library holder.
|
||||
*/
|
||||
|
||||
class LibraryListHolder(
|
||||
private val view: View,
|
||||
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
|
||||
|
@ -9,16 +9,8 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
import eu.kanade.tachiyomi.databinding.TrackSearchItemBinding
|
||||
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) :
|
||||
ArrayAdapter<TrackSearch>(context, R.layout.track_search_item, mutableListOf<TrackSearch>()) {
|
||||
@ -49,37 +41,39 @@ class TrackSearchAdapter(context: Context) :
|
||||
|
||||
class TrackSearchHolder(private val view: View) {
|
||||
|
||||
private val binding = TrackSearchItemBinding.bind(view)
|
||||
|
||||
fun onSetValues(track: TrackSearch) {
|
||||
view.track_search_title.text = track.title
|
||||
view.track_search_summary.text = track.summary
|
||||
GlideApp.with(view.context).clear(view.track_search_cover)
|
||||
binding.trackSearchTitle.text = track.title
|
||||
binding.trackSearchSummary.text = track.summary
|
||||
GlideApp.with(view.context).clear(binding.trackSearchCover)
|
||||
if (!track.cover_url.isEmpty()) {
|
||||
GlideApp.with(view.context)
|
||||
.load(track.cover_url)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.centerCrop()
|
||||
.into(view.track_search_cover)
|
||||
.into(binding.trackSearchCover)
|
||||
}
|
||||
|
||||
if (track.publishing_status.isBlank()) {
|
||||
view.track_search_status.isVisible = false
|
||||
view.track_search_status_result.isVisible = false
|
||||
binding.trackSearchStatus.isVisible = false
|
||||
binding.trackSearchStatusResult.isVisible = false
|
||||
} else {
|
||||
view.track_search_status_result.text = track.publishing_status.capitalize()
|
||||
binding.trackSearchStatusResult.text = track.publishing_status.capitalize()
|
||||
}
|
||||
|
||||
if (track.publishing_type.isBlank()) {
|
||||
view.track_search_type.isVisible = false
|
||||
view.track_search_type_result.isVisible = false
|
||||
binding.trackSearchType.isVisible = false
|
||||
binding.trackSearchTypeResult.isVisible = false
|
||||
} else {
|
||||
view.track_search_type_result.text = track.publishing_type.capitalize()
|
||||
binding.trackSearchTypeResult.text = track.publishing_type.capitalize()
|
||||
}
|
||||
|
||||
if (track.start_date.isBlank()) {
|
||||
view.track_search_start.isVisible = false
|
||||
view.track_search_start_result.isVisible = false
|
||||
binding.trackSearchStart.isVisible = false
|
||||
binding.trackSearchStartResult.isVisible = false
|
||||
} else {
|
||||
view.track_search_start_result.text = track.start_date
|
||||
binding.trackSearchStartResult.text = track.start_date
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga.track
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.core.os.bundleOf
|
||||
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.TrackService
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
import eu.kanade.tachiyomi.databinding.TrackSearchDialogBinding
|
||||
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.filter
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@ -29,7 +28,7 @@ import java.util.concurrent.TimeUnit
|
||||
|
||||
class TrackSearchDialog : DialogController {
|
||||
|
||||
private var dialogView: View? = null
|
||||
private var binding: TrackSearchDialogBinding? = null
|
||||
|
||||
private var adapter: TrackSearchAdapter? = null
|
||||
|
||||
@ -53,13 +52,13 @@ class TrackSearchDialog : DialogController {
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||
binding = TrackSearchDialogBinding.inflate(LayoutInflater.from(activity!!))
|
||||
val dialog = MaterialDialog(activity!!)
|
||||
.customView(R.layout.track_search_dialog)
|
||||
.customView(view = binding!!.root)
|
||||
.positiveButton(android.R.string.ok) { onPositiveButtonClick() }
|
||||
.negativeButton(android.R.string.cancel)
|
||||
.neutralButton(R.string.action_remove) { onRemoveButtonClick() }
|
||||
|
||||
dialogView = dialog.view
|
||||
onViewCreated(dialog.view, savedViewState)
|
||||
|
||||
return dialog
|
||||
@ -69,12 +68,12 @@ class TrackSearchDialog : DialogController {
|
||||
// Create adapter
|
||||
val adapter = TrackSearchAdapter(view.context)
|
||||
this.adapter = adapter
|
||||
view.track_search_list.adapter = adapter
|
||||
binding!!.trackSearchList.adapter = adapter
|
||||
|
||||
// Set listeners
|
||||
selectedItem = null
|
||||
|
||||
view.track_search_list.itemClicks()
|
||||
binding!!.trackSearchList.itemClicks()
|
||||
.onEach { position ->
|
||||
selectedItem = adapter.getItem(position)
|
||||
}
|
||||
@ -83,20 +82,20 @@ class TrackSearchDialog : DialogController {
|
||||
// Do an initial search based on the manga's title
|
||||
if (savedState == null) {
|
||||
val title = trackController.presenter.manga.title
|
||||
view.track_search.append(title)
|
||||
binding!!.trackSearch.append(title)
|
||||
search(title)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
super.onDestroyView(view)
|
||||
dialogView = null
|
||||
binding = null
|
||||
adapter = null
|
||||
}
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
super.onAttach(view)
|
||||
dialogView!!.track_search.textChanges()
|
||||
binding!!.trackSearch.textChanges()
|
||||
.debounce(TimeUnit.SECONDS.toMillis(1))
|
||||
.filter { it.isNotBlank() }
|
||||
.onEach { search(it.toString()) }
|
||||
@ -104,24 +103,24 @@ class TrackSearchDialog : DialogController {
|
||||
}
|
||||
|
||||
private fun search(query: String) {
|
||||
val view = dialogView ?: return
|
||||
view.progress.isVisible = true
|
||||
view.track_search_list.isInvisible = true
|
||||
val binding = binding ?: return
|
||||
binding.progress.isVisible = true
|
||||
binding.trackSearchList.isInvisible = true
|
||||
trackController.presenter.search(query, service)
|
||||
}
|
||||
|
||||
fun onSearchResults(results: List<TrackSearch>) {
|
||||
selectedItem = null
|
||||
val view = dialogView ?: return
|
||||
view.progress.isInvisible = true
|
||||
view.track_search_list.isVisible = true
|
||||
val binding = binding ?: return
|
||||
binding.progress.isInvisible = true
|
||||
binding.trackSearchList.isVisible = true
|
||||
adapter?.setItems(results)
|
||||
}
|
||||
|
||||
fun onSearchResultsError() {
|
||||
val view = dialogView ?: return
|
||||
view.progress.isVisible = true
|
||||
view.track_search_list.isInvisible = true
|
||||
val binding = binding ?: return
|
||||
binding.progress.isVisible = true
|
||||
binding.trackSearchList.isInvisible = true
|
||||
adapter?.setItems(emptyList())
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,6 @@ import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
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.schedulers.Schedulers
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@ -31,22 +28,21 @@ class TrackLoginDialog(
|
||||
constructor(service: TrackService, @StringRes usernameLabelRes: Int?) :
|
||||
this(R.string.login_title, service.name, usernameLabelRes, bundleOf("key" to service.id))
|
||||
|
||||
override fun setCredentialsOnView(view: View) = with(view) {
|
||||
username.setText(service.getUsername())
|
||||
password.setText(service.getPassword())
|
||||
override fun setCredentialsOnView(view: View) {
|
||||
binding?.username?.setText(service.getUsername())
|
||||
binding?.password?.setText(service.getPassword())
|
||||
}
|
||||
|
||||
override fun checkLogin() {
|
||||
requestSubscription?.unsubscribe()
|
||||
|
||||
v?.apply {
|
||||
if (username.text.isNullOrEmpty() || password.text.isNullOrEmpty()) {
|
||||
if (binding!!.username.text.isNullOrEmpty() || binding!!.password.text.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
login.progress = 1
|
||||
val user = username.text.toString()
|
||||
val pass = password.text.toString()
|
||||
binding!!.login.progress = 1
|
||||
val user = binding!!.username.text.toString()
|
||||
val pass = binding!!.password.text.toString()
|
||||
|
||||
requestSubscription = service.login(user, pass)
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -54,16 +50,15 @@ class TrackLoginDialog(
|
||||
.subscribe(
|
||||
{
|
||||
dialog?.dismiss()
|
||||
context.toast(R.string.login_success)
|
||||
view?.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
|
||||
binding!!.login.setText(R.string.unknown_error)
|
||||
error.message?.let { view?.context?.toast(it) }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDialogClosed() {
|
||||
super.onDialogClosed()
|
||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.annotation.StringRes
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
@ -9,11 +10,9 @@ import com.afollestad.materialdialogs.customview.customView
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.ControllerChangeType
|
||||
import com.dd.processbutton.iml.ActionProcessButton
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding
|
||||
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 uy.kohesive.injekt.injectLazy
|
||||
|
||||
@ -24,7 +23,7 @@ abstract class LoginDialogPreference(
|
||||
bundle: Bundle? = null
|
||||
) : DialogController(bundle) {
|
||||
|
||||
var v: View? = null
|
||||
var binding: PrefAccountLoginBinding? = null
|
||||
private set
|
||||
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
@ -32,8 +31,9 @@ abstract class LoginDialogPreference(
|
||||
var requestSubscription: Subscription? = null
|
||||
|
||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||
binding = PrefAccountLoginBinding.inflate(LayoutInflater.from(activity!!))
|
||||
var dialog = MaterialDialog(activity!!)
|
||||
.customView(R.layout.pref_account_login)
|
||||
.customView(view = binding!!.root)
|
||||
.negativeButton(android.R.string.cancel)
|
||||
|
||||
if (titleRes != null) {
|
||||
@ -46,16 +46,14 @@ abstract class LoginDialogPreference(
|
||||
}
|
||||
|
||||
fun onViewCreated(view: View) {
|
||||
v = view.apply {
|
||||
if (usernameLabelRes != null) {
|
||||
username_label.hint = context.getString(usernameLabelRes)
|
||||
binding!!.usernameLabel.hint = view.context.getString(usernameLabelRes)
|
||||
}
|
||||
|
||||
login.setMode(ActionProcessButton.Mode.ENDLESS)
|
||||
login.setOnClickListener { checkLogin() }
|
||||
binding!!.login.setMode(ActionProcessButton.Mode.ENDLESS)
|
||||
binding!!.login.setOnClickListener { checkLogin() }
|
||||
|
||||
setCredentialsOnView(this)
|
||||
}
|
||||
setCredentialsOnView(view)
|
||||
}
|
||||
|
||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
@ -67,6 +65,7 @@ abstract class LoginDialogPreference(
|
||||
|
||||
open fun onDialogClosed() {
|
||||
requestSubscription?.unsubscribe()
|
||||
binding = null
|
||||
}
|
||||
|
||||
protected abstract fun checkLogin()
|
||||
|
Loading…
Reference in New Issue
Block a user