From 69be3e1e87bdc3e2706e1ded6b6f21fbe67b6cd2 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 13 Dec 2020 18:01:51 -0500 Subject: [PATCH] Complete migration off of Kotlin synthetics --- app/build.gradle | 6 +----- .../ui/base/controller/BaseController.kt | 6 ------ .../tachiyomi/ui/library/LibraryAdapter.kt | 8 ++++--- .../ui/library/LibraryCategoryView.kt | 21 +++++++++---------- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9db5e99eb2..522412997c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,8 +5,8 @@ import java.text.SimpleDateFormat apply plugin: 'com.android.application' apply plugin: 'com.mikepenz.aboutlibraries.plugin' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-parcelize' apply plugin: 'kotlinx-serialization' apply plugin: 'com.github.zellius.shortcut-helper' @@ -123,10 +123,6 @@ android { } } -androidExtensions { - experimental = true -} - dependencies { // Source models and interfaces from Tachiyomi 1.x diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index 8d4fea2151..1f094cb9de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -12,7 +12,6 @@ import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.RestoreViewOnCreateController import kotlinx.android.extensions.LayoutContainer -import kotlinx.android.synthetic.clearFindViewByIdCache import timber.log.Timber abstract class BaseController(bundle: Bundle? = null) : @@ -54,11 +53,6 @@ abstract class BaseController(bundle: Bundle? = null) : return inflateView(inflater, container) } - override fun onDestroyView(view: View) { - super.onDestroyView(view) - clearFindViewByIdCache() - } - abstract fun inflateView(inflater: LayoutInflater, container: ViewGroup): View open fun onViewCreated(view: View) {} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt index 27bb231829..152a3649c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryAdapter.kt @@ -1,9 +1,10 @@ package eu.kanade.tachiyomi.ui.library +import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category +import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.widget.RecyclerViewPagerAdapter @@ -34,8 +35,9 @@ class LibraryAdapter(private val controller: LibraryController) : RecyclerViewPa * @return a new view. */ override fun createView(container: ViewGroup): View { - val view = container.inflate(R.layout.library_category) as LibraryCategoryView - view.onCreate(controller) + val binding = LibraryCategoryBinding.inflate(LayoutInflater.from(container.context), container, false) + val view: LibraryCategoryView = binding.root + view.onCreate(controller, binding) return view } 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 5043df10de..2ed7373209 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 @@ -14,12 +14,11 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.databinding.LibraryCategoryBinding import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.widget.AutofitRecyclerView -import kotlinx.android.synthetic.main.library_category.view.fast_scroller -import kotlinx.android.synthetic.main.library_category.view.swipe_refresh import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -70,15 +69,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att private var lastClickPosition = -1 - fun onCreate(controller: LibraryController) { + fun onCreate(controller: LibraryController, binding: LibraryCategoryBinding) { this.controller = controller recycler = if (preferences.libraryDisplayMode().get() == DisplayMode.LIST) { - (swipe_refresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply { + (binding.swipeRefresh.inflate(R.layout.library_list_recycler) as RecyclerView).apply { layoutManager = LinearLayoutManager(context) } } else { - (swipe_refresh.inflate(R.layout.library_grid_recycler) as AutofitRecyclerView).apply { + (binding.swipeRefresh.inflate(R.layout.library_grid_recycler) as AutofitRecyclerView).apply { spanCount = controller.mangaPerRow } } @@ -87,28 +86,28 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att recycler.setHasFixedSize(true) recycler.adapter = adapter - swipe_refresh.addView(recycler) - adapter.fastScroller = fast_scroller + binding.swipeRefresh.addView(recycler) + adapter.fastScroller = binding.fastScroller recycler.scrollStateChanges() .onEach { // Disable swipe refresh when view is not at the top val firstPos = (recycler.layoutManager as LinearLayoutManager) .findFirstCompletelyVisibleItemPosition() - swipe_refresh.isEnabled = firstPos <= 0 + binding.swipeRefresh.isEnabled = firstPos <= 0 } .launchIn(scope) // Double the distance required to trigger sync - swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt()) - swipe_refresh.refreshes() + binding.swipeRefresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt()) + binding.swipeRefresh.refreshes() .onEach { if (LibraryUpdateService.start(context, category)) { context.toast(R.string.updating_category) } // It can be a very long operation, so we disable swipe refresh and show a toast. - swipe_refresh.isRefreshing = false + binding.swipeRefresh.isRefreshing = false } .launchIn(scope) }