diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index fca3704da0..cc7dfb7839 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -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<*> } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceComfortableGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceComfortableGridHolder.kt index a4a9def833..7b2236e32d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceComfortableGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceComfortableGridHolder.kt @@ -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(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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceGridHolder.kt index 212b23f24c..d4ed34155f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceGridHolder.kt @@ -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(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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceHolder.kt index 07d46ad094..78d8492958 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceHolder.kt @@ -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(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. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt index 8fefce9e04..a1382cd92b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceItem.kt @@ -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) : - AbstractFlexibleItem() { + AbstractFlexibleItem>() { override fun getLayoutRes(): Int { return when (displayMode.get()) { @@ -31,17 +31,18 @@ class SourceItem(val manga: Manga, private val displayMode: Preference> - ): 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 { + 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>, - holder: SourceHolder, + holder: SourceHolder<*>, position: Int, payloads: List? ) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceListHolder.kt index 16e4e5b4f3..9b9af026bd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceListHolder.kt @@ -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(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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index f2d3a94d44..bc20680bcc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -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() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt index de861d42a1..96aa02150d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt @@ -23,9 +23,9 @@ import eu.kanade.tachiyomi.util.isLocal class LibraryComfortableGridHolder( private val view: View, adapter: FlexibleAdapter> -) : LibraryCompactGridHolder(view, adapter) { +) : LibraryHolder(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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt index 39718a9c15..851223a184 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt @@ -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(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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt index c3b4621710..d6e054d233 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt @@ -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( 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. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 8c4176f96b..21d8f481b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -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) : - AbstractFlexibleItem(), IFilterable { + AbstractFlexibleItem>(), IFilterable { 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>): LibraryHolder { + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): 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>, - holder: LibraryHolder, + holder: LibraryHolder<*>, position: Int, payloads: List? ) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 5d1f1155d9..d7071f32b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -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(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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt index ec4e3f8fbe..dd8769ab03 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt @@ -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(context, R.layout.track_search_item, mutableListOf()) { @@ -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 } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt index 0c3b768645..bcbcf3c7de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt @@ -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) { 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()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt index 8d4ac2fbcf..dee34aa06e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt @@ -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,38 +28,36 @@ 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()) { - 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) } - } - ) + if (binding!!.username.text.isNullOrEmpty() || binding!!.password.text.isNullOrEmpty()) { + return } + + 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() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt index 3065b1a306..322bc8691b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt @@ -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) - } - - login.setMode(ActionProcessButton.Mode.ENDLESS) - login.setOnClickListener { checkLogin() } - - setCredentialsOnView(this) + if (usernameLabelRes != null) { + binding!!.usernameLabel.hint = view.context.getString(usernameLabelRes) } + + binding!!.login.setMode(ActionProcessButton.Mode.ENDLESS) + binding!!.login.setOnClickListener { checkLogin() } + + 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()