From 46287f88a1a819f809a3acfdbfa274e6d4f5d5b3 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 29 Mar 2021 23:29:53 -0400 Subject: [PATCH] Binding Sub Recent Controller Actually not as bad, but still might remove one day --- .../RecentChaptersController.kt | 30 +++++++++---------- .../recently_read/RecentlyReadController.kt | 15 +++++----- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index c05eeb4f22..62352c85c5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -27,8 +27,6 @@ import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.withFadeTransaction -import kotlinx.android.synthetic.main.recent_chapters_controller.* -import kotlinx.android.synthetic.main.recent_chapters_controller.empty_view import timber.log.Timber /** @@ -71,29 +69,29 @@ class RecentChaptersController(bundle: Bundle? = null) : view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS) // Init RecyclerView and adapter val layoutManager = LinearLayoutManager(view.context) - recycler.layoutManager = layoutManager - recycler.addItemDecoration(DividerItemDecoration(view.context, DividerItemDecoration.VERTICAL)) - recycler.setHasFixedSize(true) + binding.recycler.layoutManager = layoutManager + binding.recycler.addItemDecoration(DividerItemDecoration(view.context, DividerItemDecoration.VERTICAL)) + binding.recycler.setHasFixedSize(true) adapter = RecentChaptersAdapter(this@RecentChaptersController) - recycler.adapter = adapter + binding.recycler.adapter = adapter adapter?.isSwipeEnabled = true adapter?.itemTouchHelperCallback?.setSwipeFlags( ItemTouchHelper.LEFT ) if (presenter.chapters.isNotEmpty()) adapter?.updateDataSet(presenter.chapters.toList()) - swipe_refresh.setStyle() - swipe_refresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt()) - swipe_refresh.setOnRefreshListener { + binding.swipeRefresh.setStyle() + binding.swipeRefresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt()) + binding.swipeRefresh.setOnRefreshListener { if (!LibraryUpdateService.isRunning()) { LibraryUpdateService.start(view.context) snack = view.snack(R.string.updating_library) } // It can be a very long operation, so we disable swipe refresh and show a snackbar. - swipe_refresh.isRefreshing = false + binding.swipeRefresh.isRefreshing = false } - scrollViewWith(recycler, swipeRefreshLayout = swipe_refresh, padBottom = true) + scrollViewWith(binding.recycler, swipeRefreshLayout = binding.swipeRefresh, padBottom = true) presenter.onCreate() } @@ -152,15 +150,15 @@ class RecentChaptersController(bundle: Bundle? = null) : fun updateChapterDownload(download: Download) { if (view == null) return val id = download.chapter.id ?: return - val holder = recycler.findViewHolderForItemId(id) as? RecentChapterHolder ?: return + val holder = binding.recycler.findViewHolderForItemId(id) as? RecentChapterHolder ?: return holder.notifyStatus(download.status, download.progress) } override fun onUpdateEmptyView(size: Int) { if (size > 0) { - empty_view?.hide() + binding.emptyView.hide() } else { - empty_view?.show(R.drawable.ic_update_24dp, R.string.no_recent_chapters) + binding.emptyView.show(R.drawable.ic_update_24dp, R.string.no_recent_chapters) } } @@ -168,7 +166,7 @@ class RecentChaptersController(bundle: Bundle? = null) : override fun shouldMoveItem(fromPosition: Int, toPosition: Int) = true override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { - swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_SWIPE + binding.swipeRefresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_SWIPE } /** @@ -184,7 +182,7 @@ class RecentChaptersController(bundle: Bundle? = null) : * @param download [Download] object containing download progress. */ private fun getHolder(download: Download): RecentChapterHolder? { - return recycler?.findViewHolderForItemId(download.chapter.id!!) as? RecentChapterHolder + return binding.recycler.findViewHolderForItemId(download.chapter.id!!) as? RecentChapterHolder } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index 93362fdcce..7a7c53bf84 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -25,7 +25,6 @@ import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.withFadeTransaction -import kotlinx.android.synthetic.main.recently_read_controller.* /** * Fragment that shows recently read manga. @@ -77,12 +76,12 @@ class RecentlyReadController(bundle: Bundle? = null) : // view.applyWindowInsetsForController() // Initialize adapter adapter = RecentlyReadAdapter(this) - recycler.adapter = adapter - recycler.layoutManager = LinearLayoutManager(view.context) - recycler.setHasFixedSize(true) - recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) + binding.recycler.adapter = adapter + binding.recycler.layoutManager = LinearLayoutManager(view.context) + binding.recycler.setHasFixedSize(true) + binding.recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) resetProgressItem() - scrollViewWith(recycler, padBottom = true) + scrollViewWith(binding.recycler, padBottom = true) if (recentItems != null) { adapter?.updateDataSet(recentItems!!.toList()) @@ -129,9 +128,9 @@ class RecentlyReadController(bundle: Bundle? = null) : override fun onUpdateEmptyView(size: Int) { if (size > 0) { - empty_view?.hide() + binding.emptyView.hide() } else { - empty_view.show( + binding.emptyView.show( R.drawable.ic_history_24dp, R.string .no_recently_read_manga