Binding Sub Recent Controller

Actually not as bad, but still might remove one day
This commit is contained in:
Jays2Kings 2021-03-29 23:29:53 -04:00
parent bd136696b0
commit 46287f88a1
2 changed files with 21 additions and 24 deletions

View File

@ -27,8 +27,6 @@ import eu.kanade.tachiyomi.util.view.scrollViewWith
import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.setStyle
import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.snack
import eu.kanade.tachiyomi.util.view.withFadeTransaction 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 import timber.log.Timber
/** /**
@ -71,29 +69,29 @@ class RecentChaptersController(bundle: Bundle? = null) :
view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS) view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS)
// Init RecyclerView and adapter // Init RecyclerView and adapter
val layoutManager = LinearLayoutManager(view.context) val layoutManager = LinearLayoutManager(view.context)
recycler.layoutManager = layoutManager binding.recycler.layoutManager = layoutManager
recycler.addItemDecoration(DividerItemDecoration(view.context, DividerItemDecoration.VERTICAL)) binding.recycler.addItemDecoration(DividerItemDecoration(view.context, DividerItemDecoration.VERTICAL))
recycler.setHasFixedSize(true) binding.recycler.setHasFixedSize(true)
adapter = RecentChaptersAdapter(this@RecentChaptersController) adapter = RecentChaptersAdapter(this@RecentChaptersController)
recycler.adapter = adapter binding.recycler.adapter = adapter
adapter?.isSwipeEnabled = true adapter?.isSwipeEnabled = true
adapter?.itemTouchHelperCallback?.setSwipeFlags( adapter?.itemTouchHelperCallback?.setSwipeFlags(
ItemTouchHelper.LEFT ItemTouchHelper.LEFT
) )
if (presenter.chapters.isNotEmpty()) adapter?.updateDataSet(presenter.chapters.toList()) if (presenter.chapters.isNotEmpty()) adapter?.updateDataSet(presenter.chapters.toList())
swipe_refresh.setStyle() binding.swipeRefresh.setStyle()
swipe_refresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt()) binding.swipeRefresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt())
swipe_refresh.setOnRefreshListener { binding.swipeRefresh.setOnRefreshListener {
if (!LibraryUpdateService.isRunning()) { if (!LibraryUpdateService.isRunning()) {
LibraryUpdateService.start(view.context) LibraryUpdateService.start(view.context)
snack = view.snack(R.string.updating_library) snack = view.snack(R.string.updating_library)
} }
// It can be a very long operation, so we disable swipe refresh and show a snackbar. // 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() presenter.onCreate()
} }
@ -152,15 +150,15 @@ class RecentChaptersController(bundle: Bundle? = null) :
fun updateChapterDownload(download: Download) { fun updateChapterDownload(download: Download) {
if (view == null) return if (view == null) return
val id = download.chapter.id ?: 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) holder.notifyStatus(download.status, download.progress)
} }
override fun onUpdateEmptyView(size: Int) { override fun onUpdateEmptyView(size: Int) {
if (size > 0) { if (size > 0) {
empty_view?.hide() binding.emptyView.hide()
} else { } 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 shouldMoveItem(fromPosition: Int, toPosition: Int) = true
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { 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. * @param download [Download] object containing download progress.
*/ */
private fun getHolder(download: Download): RecentChapterHolder? { private fun getHolder(download: Download): RecentChapterHolder? {
return recycler?.findViewHolderForItemId(download.chapter.id!!) as? RecentChapterHolder return binding.recycler.findViewHolderForItemId(download.chapter.id!!) as? RecentChapterHolder
} }
/** /**

View File

@ -25,7 +25,6 @@ import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.scrollViewWith
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
import kotlinx.android.synthetic.main.recently_read_controller.*
/** /**
* Fragment that shows recently read manga. * Fragment that shows recently read manga.
@ -77,12 +76,12 @@ class RecentlyReadController(bundle: Bundle? = null) :
// view.applyWindowInsetsForController() // view.applyWindowInsetsForController()
// Initialize adapter // Initialize adapter
adapter = RecentlyReadAdapter(this) adapter = RecentlyReadAdapter(this)
recycler.adapter = adapter binding.recycler.adapter = adapter
recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.layoutManager = LinearLayoutManager(view.context)
recycler.setHasFixedSize(true) binding.recycler.setHasFixedSize(true)
recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) binding.recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener)
resetProgressItem() resetProgressItem()
scrollViewWith(recycler, padBottom = true) scrollViewWith(binding.recycler, padBottom = true)
if (recentItems != null) { if (recentItems != null) {
adapter?.updateDataSet(recentItems!!.toList()) adapter?.updateDataSet(recentItems!!.toList())
@ -129,9 +128,9 @@ class RecentlyReadController(bundle: Bundle? = null) :
override fun onUpdateEmptyView(size: Int) { override fun onUpdateEmptyView(size: Int) {
if (size > 0) { if (size > 0) {
empty_view?.hide() binding.emptyView.hide()
} else { } else {
empty_view.show( binding.emptyView.show(
R.drawable.ic_history_24dp, R.drawable.ic_history_24dp,
R.string R.string
.no_recently_read_manga .no_recently_read_manga