diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt index 1705d0d91a..7599d9438d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt @@ -10,6 +10,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.model.Download +import eu.kanade.tachiyomi.databinding.DownloadBottomSheetBinding import eu.kanade.tachiyomi.ui.extension.ExtensionDividerItemDecoration import eu.kanade.tachiyomi.ui.recents.RecentsController import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener @@ -21,7 +22,6 @@ import eu.kanade.tachiyomi.util.view.isCollapsed import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isHidden import eu.kanade.tachiyomi.util.view.updateLayoutParams -import kotlinx.android.synthetic.main.download_bottom_sheet.view.* class DownloadBottomSheet @JvmOverloads constructor( context: Context, @@ -45,20 +45,26 @@ class DownloadBottomSheet @JvmOverloads constructor( private var isRunning: Boolean = false private var activity: Activity? = null + lateinit var binding: DownloadBottomSheetBinding + override fun onFinishInflate() { + super.onFinishInflate() + binding = DownloadBottomSheetBinding.bind(this) + } + fun onCreate(controller: RecentsController) { // Initialize adapter, scroll listener and recycler views adapter = DownloadAdapter(this) sheetBehavior = BottomSheetBehavior.from(this) activity = controller.activity // Create recycler and set adapter. - dl_recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context) - dl_recycler.adapter = adapter + binding.dlRecycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context) + binding.dlRecycler.adapter = adapter adapter?.isHandleDragEnabled = true adapter?.isSwipeEnabled = true - adapter?.fastScroller = fast_scroller - dl_recycler.setHasFixedSize(true) - dl_recycler.addItemDecoration(ExtensionDividerItemDecoration(context)) - dl_recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) + adapter?.fastScroller = binding.fastScroller + binding.dlRecycler.setHasFixedSize(true) + binding.dlRecycler.addItemDecoration(ExtensionDividerItemDecoration(context)) + binding.dlRecycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) this.controller = controller updateDLTitle() @@ -66,12 +72,12 @@ class DownloadBottomSheet @JvmOverloads constructor( val array = context.obtainStyledAttributes(attrsArray) val headerHeight = array.getDimensionPixelSize(0, 0) array.recycle() - recycler_layout.doOnApplyWindowInsets { v, windowInsets, _ -> + binding.recyclerLayout.doOnApplyWindowInsets { v, windowInsets, _ -> v.updateLayoutParams { - topMargin = windowInsets.systemWindowInsetTop + headerHeight - sheet_layout.height + topMargin = windowInsets.systemWindowInsetTop + headerHeight - binding.sheetLayout.height } } - sheet_layout.setOnClickListener { + binding.sheetLayout.setOnClickListener { if (!sheetBehavior.isExpanded()) { sheetBehavior?.expand() } else { @@ -93,7 +99,7 @@ class DownloadBottomSheet @JvmOverloads constructor( private fun updateDLTitle() { val extCount = presenter.downloadQueue.firstOrNull() - title_text.text = if (extCount != null) resources.getString( + binding.titleText.text = if (extCount != null) resources.getString( R.string.downloading_, extCount.chapter.name ) @@ -153,7 +159,7 @@ class DownloadBottomSheet @JvmOverloads constructor( * @return the holder of the download or null if it's not bound. */ private fun getHolder(download: Download): DownloadHolder? { - return dl_recycler?.findViewHolderForItemId(download.chapter.id!!) as? DownloadHolder + return binding.dlRecycler?.findViewHolderForItemId(download.chapter.id!!) as? DownloadHolder } /** @@ -163,12 +169,12 @@ class DownloadBottomSheet @JvmOverloads constructor( updateDLTitle() setBottomSheet() if (presenter.downloadQueue.isEmpty()) { - empty_view?.show( + binding.emptyView.show( R.drawable.ic_download_off_24dp, R.string.nothing_is_downloading ) } else { - empty_view?.hide() + binding.emptyView.hide() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt index 19fad598d5..097a87d206 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt @@ -8,10 +8,10 @@ import android.widget.FrameLayout import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download +import eu.kanade.tachiyomi.databinding.DownloadButtonBinding import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.visible -import kotlinx.android.synthetic.main.download_button.view.* class DownloadButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) { @@ -52,53 +52,60 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut private var isAnimating = false private var iconAnimation: ObjectAnimator? = null + lateinit var binding: DownloadButtonBinding + + override fun onFinishInflate() { + super.onFinishInflate() + binding = DownloadButtonBinding.bind(this) + } + fun setDownloadStatus(state: Int, progress: Int = 0) { if (state != Download.DOWNLOADING) { iconAnimation?.cancel() - download_icon.alpha = 1f + binding.downloadIcon.alpha = 1f isAnimating = false } - download_icon.setImageDrawable( + binding.downloadIcon.setImageDrawable( if (state == Download.CHECKED) { checkDrawable } else downloadDrawable ) when (state) { Download.CHECKED -> { - download_progress.gone() - download_border.visible() - download_progress_indeterminate.gone() - download_border.setImageDrawable(filledCircle) - download_border.drawable.setTint(activeColor) - download_icon.drawable.setTint(Color.WHITE) + binding.downloadProgress.gone() + binding.downloadBorder.visible() + binding.downloadProgressIndeterminate.gone() + binding.downloadBorder.setImageDrawable(filledCircle) + binding.downloadBorder.drawable.setTint(activeColor) + binding.downloadIcon.drawable.setTint(Color.WHITE) } Download.NOT_DOWNLOADED -> { - download_border.visible() - download_progress.gone() - download_progress_indeterminate.gone() - download_border.setImageDrawable(borderCircle) - download_border.drawable.setTint(activeColor) - download_icon.drawable.setTint(activeColor) + binding.downloadBorder.visible() + binding.downloadProgress.gone() + binding.downloadProgressIndeterminate.gone() + binding.downloadBorder.setImageDrawable(borderCircle) + binding.downloadBorder.drawable.setTint(activeColor) + binding.downloadIcon.drawable.setTint(activeColor) } Download.QUEUE -> { - download_border.gone() - download_progress.gone() - download_progress_indeterminate.visible() - download_progress.isIndeterminate = true - download_icon.drawable.setTint(disabledColor) + binding.downloadBorder.gone() + binding.downloadProgress.gone() + binding.downloadProgressIndeterminate.visible() + binding.downloadProgress.isIndeterminate = true + binding.downloadIcon.drawable.setTint(disabledColor) } Download.DOWNLOADING -> { - download_border.visible() - download_progress.visible() - download_progress_indeterminate.gone() - download_border.setImageDrawable(borderCircle) - download_progress.isIndeterminate = false - download_progress.progress = progress - download_border.drawable.setTint(progressBGColor) - download_progress.progressDrawable?.setTint(downloadedColor) - download_icon.drawable.setTint(disabledColor) + binding.downloadBorder.visible() + binding.downloadProgress.visible() + binding.downloadProgressIndeterminate.gone() + binding.downloadBorder.setImageDrawable(borderCircle) + binding.downloadProgress.isIndeterminate = false + binding.downloadProgress.progress = progress + binding.downloadBorder.drawable.setTint(progressBGColor) + binding.downloadProgress.progressDrawable?.setTint(downloadedColor) + binding.downloadIcon.drawable.setTint(disabledColor) if (!isAnimating) { - iconAnimation = ObjectAnimator.ofFloat(download_icon, "alpha", 1f, 0f).apply { + iconAnimation = ObjectAnimator.ofFloat(binding.downloadIcon, "alpha", 1f, 0f).apply { duration = 1000 repeatCount = ObjectAnimator.INFINITE repeatMode = ObjectAnimator.REVERSE @@ -108,20 +115,20 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut } } Download.DOWNLOADED -> { - download_progress.gone() - download_border.visible() - download_progress_indeterminate.gone() - download_border.setImageDrawable(filledCircle) - download_border.drawable.setTint(downloadedColor) - download_icon.drawable.setTint(Color.WHITE) + binding.downloadProgress.gone() + binding.downloadBorder.visible() + binding.downloadProgressIndeterminate.gone() + binding.downloadBorder.setImageDrawable(filledCircle) + binding.downloadBorder.drawable.setTint(downloadedColor) + binding.downloadIcon.drawable.setTint(Color.WHITE) } Download.ERROR -> { - download_progress.gone() - download_border.visible() - download_progress_indeterminate.gone() - download_border.setImageDrawable(borderCircle) - download_border.drawable.setTint(errorColor) - download_icon.drawable.setTint(errorColor) + binding.downloadProgress.gone() + binding.downloadBorder.visible() + binding.downloadProgressIndeterminate.gone() + binding.downloadBorder.setImageDrawable(borderCircle) + binding.downloadBorder.drawable.setTint(errorColor) + binding.downloadIcon.drawable.setTint(errorColor) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt index 7d8bfcc47e..035e11707a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt @@ -5,65 +5,66 @@ import android.view.View import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga import eu.kanade.tachiyomi.data.download.model.Download +import eu.kanade.tachiyomi.databinding.RecentMangaItemBinding import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder import eu.kanade.tachiyomi.util.chapter.ChapterUtil import eu.kanade.tachiyomi.util.system.timeSpanFromNow import eu.kanade.tachiyomi.util.view.visibleIf -import kotlinx.android.synthetic.main.download_button.* -import kotlinx.android.synthetic.main.recent_manga_item.* class RecentMangaHolder( view: View, val adapter: RecentMangaAdapter ) : BaseChapterHolder(view, adapter) { + private val binding = RecentMangaItemBinding.bind(view) + init { - card_layout?.setOnClickListener { adapter.delegate.onCoverClick(flexibleAdapterPosition) } + binding.cardLayout.setOnClickListener { adapter.delegate.onCoverClick(flexibleAdapterPosition) } } fun bind(recentsType: Int) { when (recentsType) { RecentMangaHeaderItem.CONTINUE_READING -> { - title.setText(R.string.view_history) + binding.title.setText(R.string.view_history) } RecentMangaHeaderItem.NEW_CHAPTERS -> { - title.setText(R.string.view_all_updates) + binding.title.setText(R.string.view_all_updates) } } } fun bind(item: RecentMangaItem) { - download_button.visibleIf(item.mch.manga.source != LocalSource.ID) + binding.downloadButton.downloadButton.visibleIf(item.mch.manga.source != LocalSource.ID) - title.apply { + binding.title.apply { text = item.chapter.name ChapterUtil.setTextViewForChapter(this, item) } - subtitle.apply { + binding.subtitle.apply { text = item.mch.manga.title setTextColor(ChapterUtil.readColor(context, item)) } val notValidNum = item.mch.chapter.chapter_number <= 0 - body.text = when { - item.mch.chapter.id == null -> body.context.getString( + binding.body.text = when { + item.mch.chapter.id == null -> binding.body.context.getString( R.string.added_, item.mch.manga.date_added.timeSpanFromNow ) - item.mch.history.id == null -> body.context.getString( + item.mch.history.id == null -> binding.body.context.getString( R.string.updated_, item.chapter.date_upload.timeSpanFromNow ) item.chapter.id != item.mch.chapter.id -> - body.context.getString( + binding.body.context.getString( R.string.read_, item.mch.history.last_read.timeSpanFromNow - ) + "\n" + body.context.getString( + ) + "\n" + binding.body.context.getString( if (notValidNum) R.string.last_read_ else R.string.last_read_chapter_, if (notValidNum) item.mch.chapter.name else adapter.decimalFormat.format(item.mch.chapter.chapter_number) ) item.chapter.pages_left > 0 && !item.chapter.read -> - body.context.getString( + binding.body.context.getString( R.string.read_, item.mch.history.last_read.timeSpanFromNow ) + "\n" + itemView.resources.getQuantityString( @@ -71,13 +72,13 @@ class RecentMangaHolder( item.chapter.pages_left, item.chapter.pages_left ) - else -> body.context.getString( + else -> binding.body.context.getString( R.string.read_, item.mch.history.last_read.timeSpanFromNow ) } if ((itemView.context as? Activity)?.isDestroyed != true) { - cover_thumbnail.loadLibraryManga(item.mch.manga) + binding.coverThumbnail.loadLibraryManga(item.mch.manga) } notifyStatus( if (adapter.isSelected(flexibleAdapterPosition)) Download.CHECKED else item.status, @@ -87,7 +88,7 @@ class RecentMangaHolder( } private fun resetFrontView() { - if (front_view.translationX != 0f) itemView.post { adapter.notifyItemChanged(flexibleAdapterPosition) } + if (binding.frontView.translationX != 0f) itemView.post { adapter.notifyItemChanged(flexibleAdapterPosition) } } override fun onLongClick(view: View?): Boolean { @@ -97,13 +98,13 @@ class RecentMangaHolder( } fun notifyStatus(status: Int, progress: Int) = - download_button.setDownloadStatus(status, progress) + binding.downloadButton.downloadButton.setDownloadStatus(status, progress) override fun getFrontView(): View { - return front_view + return binding.frontView } override fun getRearRightView(): View { - return right_view + return binding.rightView } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index c4e4f70c2a..662a0344ed 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -51,16 +51,6 @@ import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.withFadeTransaction -import kotlinx.android.synthetic.main.download_bottom_sheet.* -import kotlinx.android.synthetic.main.download_bottom_sheet.sheet_layout -import kotlinx.android.synthetic.main.download_bottom_sheet.view.* -import kotlinx.android.synthetic.main.extensions_bottom_sheet.* -import kotlinx.android.synthetic.main.main_activity.* -import kotlinx.android.synthetic.main.recents_controller.* -import kotlinx.android.synthetic.main.recents_controller.recycler -import kotlinx.android.synthetic.main.recents_controller.shadow -import kotlinx.android.synthetic.main.recents_controller.shadow2 -import kotlinx.android.synthetic.main.source_controller.* import kotlin.math.abs import kotlin.math.max @@ -102,7 +92,8 @@ class RecentsController(bundle: Bundle? = null) : } override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - return inflater.inflate(R.layout.recents_controller, container, false) + binding = RecentsControllerBinding.inflate(inflater) + return binding.root } /** @@ -114,11 +105,11 @@ class RecentsController(bundle: Bundle? = null) : super.onViewCreated(view) // Initialize adapter adapter = RecentMangaAdapter(this) - recycler.adapter = adapter - recycler.layoutManager = LinearLayoutManager(view.context) - recycler.setHasFixedSize(true) - recycler.recycledViewPool.setMaxRecycledViews(0, 0) - recycler.addItemDecoration( + binding.recycler.adapter = adapter + binding.recycler.layoutManager = LinearLayoutManager(view.context) + binding.recycler.setHasFixedSize(true) + binding.recycler.recycledViewPool.setMaxRecycledViews(0, 0) + binding.recycler.addItemDecoration( RecentMangaDivider(view.context) ) adapter.isSwipeEnabled = true @@ -129,13 +120,13 @@ class RecentsController(bundle: Bundle? = null) : val array = view.context.obtainStyledAttributes(attrsArray) val appBarHeight = array.getDimensionPixelSize(0, 0) array.recycle() - swipe_refresh.setStyle() + binding.swipeRefresh.setStyle() scrollViewWith( - recycler, - swipeRefreshLayout = swipe_refresh, + binding.recycler, + swipeRefreshLayout = binding.swipeRefresh, afterInsets = { headerHeight = it.systemWindowInsetTop + appBarHeight - recycler.updatePaddingRelative(bottom = activity!!.bottom_nav.height) + binding.recycler.updatePaddingRelative(bottom = activityBinding?.bottomNav?.height ?: 0) }, onBottomNavUpdate = { setBottomPadding() @@ -150,25 +141,24 @@ class RecentsController(bundle: Bundle? = null) : } } - dl_bottom_sheet.onCreate(this) + binding.downloadBottomSheet.dlBottomSheet.onCreate(this) - shadow2.alpha = - if (dl_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f - shadow.alpha = - if (dl_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_COLLAPSED) 0.5f else 0f + binding.shadow2.alpha = + if (binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f + binding.shadow.alpha = + if (binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state == BottomSheetBehavior.STATE_COLLAPSED) 0.5f else 0f - dl_bottom_sheet.sheetBehavior?.addBottomSheetCallback( + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.addBottomSheetCallback( object : BottomSheetBehavior.BottomSheetCallback() { override fun onSlide(bottomSheet: View, progress: Float) { - val shadow2 = shadow2 ?: return - shadow2.alpha = (1 - abs(progress)) * 0.25f - shadow.alpha = (1 - abs(progress)) * 0.5f + binding.shadow2.alpha = (1 - abs(progress)) * 0.25f + binding.shadow.alpha = (1 - abs(progress)) * 0.5f if (progress >= 0) activityBinding?.appBar?.elevation = max( progress * 15f, - if (recycler.canScrollVertically(-1)) 15f else 0f + if (binding.recycler.canScrollVertically(-1)) 15f else 0f ) - sheet_layout.alpha = 1 - progress + binding.downloadBottomSheet.sheetLayout.alpha = 1 - progress activityBinding?.appBar?.y = max(activityBinding!!.appBar.y, -headerHeight * (1 - progress)) val oldShow = showingDownloads showingDownloads = progress > 0.92f @@ -182,7 +172,7 @@ class RecentsController(bundle: Bundle? = null) : if (this@RecentsController.view == null) return if (state == BottomSheetBehavior.STATE_EXPANDED) activityBinding?.appBar?.y = 0f if (state == BottomSheetBehavior.STATE_EXPANDED || state == BottomSheetBehavior.STATE_COLLAPSED) { - sheet_layout.alpha = + binding.downloadBottomSheet.sheetLayout.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 1f else 0f showingDownloads = state == BottomSheetBehavior.STATE_EXPANDED setTitle() @@ -191,64 +181,63 @@ class RecentsController(bundle: Bundle? = null) : if (state == BottomSheetBehavior.STATE_COLLAPSED) { if (hasQueue()) { - dl_bottom_sheet.sheetBehavior?.isHideable = false + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable = false } else { - dl_bottom_sheet.sheetBehavior?.isHideable = true - dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable = true + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN } } else if (state == BottomSheetBehavior.STATE_HIDDEN) { if (!hasQueue()) { - dl_bottom_sheet.sheetBehavior?.skipCollapsed = true + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.skipCollapsed = true } else { - dl_bottom_sheet.sheetBehavior?.skipCollapsed = false - dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.skipCollapsed = false + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED } } if (state == BottomSheetBehavior.STATE_HIDDEN || state == BottomSheetBehavior.STATE_COLLAPSED) { - shadow2.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f - shadow.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.5f else 0f + binding.shadow2.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f + binding.shadow.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.5f else 0f } - sheet_layout?.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED - sheet_layout?.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED - setPadding(dl_bottom_sheet.sheetBehavior?.isHideable == true) + binding.downloadBottomSheet.sheetLayout.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED + binding.downloadBottomSheet.sheetLayout.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED + setPadding(binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == true) } } ) - swipe_refresh.isRefreshing = LibraryUpdateService.isRunning() - swipe_refresh.setOnRefreshListener { + binding.swipeRefresh.isRefreshing = LibraryUpdateService.isRunning() + binding.swipeRefresh.setOnRefreshListener { if (!LibraryUpdateService.isRunning()) { LibraryUpdateService.start(view.context) } } if (showingDownloads) { - dl_bottom_sheet.sheetBehavior?.expand() + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.expand() } - setPadding(dl_bottom_sheet.sheetBehavior?.isHideable == true) + setPadding(binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == true) requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301) } fun setBottomPadding() { - val bottomBar = activity?.bottom_nav ?: return - dl_bottom_sheet ?: return + val bottomBar = activityBinding?.bottomNav ?: return val pad = bottomBar.translationY - bottomBar.height val padding = max( (-pad).toInt(), - if (dl_bottom_sheet.sheetBehavior.isExpanded()) 0 else { + if (binding.downloadBottomSheet.dlBottomSheet.sheetBehavior.isExpanded()) 0 else { view?.rootWindowInsets?.systemWindowInsetBottom ?: 0 } ) - shadow2.translationY = pad - dl_bottom_sheet.sheetBehavior?.peekHeight = 48.spToPx + padding - dl_bottom_sheet.fast_scroller.updateLayoutParams { + binding.shadow2.translationY = pad + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.peekHeight = 48.spToPx + padding + binding.downloadBottomSheet.fastScroller.updateLayoutParams { bottomMargin = -pad.toInt() } } fun setRefreshing(refresh: Boolean) { - swipe_refresh?.isRefreshing = refresh + binding.swipeRefresh.isRefreshing = refresh } override fun onItemMove(fromPosition: Int, toPosition: Int) { } @@ -256,21 +245,21 @@ class RecentsController(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 || - swipe_refresh.isRefreshing + binding.swipeRefresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_SWIPE || + binding.swipeRefresh.isRefreshing } override fun handleSheetBack(): Boolean { - if (dl_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { - dl_bottom_sheet.dismiss() + if (binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { + binding.downloadBottomSheet.dlBottomSheet.dismiss() return true } return false } fun setPadding(sheetIsHidden: Boolean) { - recycler?.updatePaddingRelative(bottom = if (sheetIsHidden) 0 else 20.dpToPx) - recycler?.updateLayoutParams { + binding.recycler.updatePaddingRelative(bottom = if (sheetIsHidden) 0 else 20.dpToPx) + binding.recycler.updateLayoutParams { bottomMargin = if (sheetIsHidden) 0 else 30.dpToPx } } @@ -279,7 +268,7 @@ class RecentsController(bundle: Bundle? = null) : super.onActivityResumed(activity) if (view != null) { refresh() - dl_bottom_sheet?.update() + binding.downloadBottomSheet.dlBottomSheet.update() } } @@ -294,7 +283,7 @@ class RecentsController(bundle: Bundle? = null) : fun showLists(recents: List) { if (view == null) return - swipe_refresh.isRefreshing = LibraryUpdateService.isRunning() + binding.swipeRefresh.isRefreshing = LibraryUpdateService.isRunning() adapter.updateItems(recents) adapter.removeAllScrollableHeaders() if (presenter.viewType > 0) { @@ -308,11 +297,11 @@ class RecentsController(bundle: Bundle? = null) : fun updateChapterDownload(download: Download) { if (view == null) return - dl_bottom_sheet.update() - dl_bottom_sheet.onUpdateProgress(download) - dl_bottom_sheet.onUpdateDownloadedPages(download) + binding.downloadBottomSheet.dlBottomSheet.update() + binding.downloadBottomSheet.dlBottomSheet.onUpdateProgress(download) + binding.downloadBottomSheet.dlBottomSheet.onUpdateDownloadedPages(download) val id = download.chapter.id ?: return - val holder = recycler.findViewHolderForItemId(id) as? RecentMangaHolder ?: return + val holder = binding.recycler.findViewHolderForItemId(id) as? RecentMangaHolder ?: return holder.notifyStatus(download.status, download.progress) } @@ -399,7 +388,7 @@ class RecentsController(bundle: Bundle? = null) : lastChapterId = chapter.id presenter.markChapterRead(chapter, true) snack = view?.snack(R.string.marked_as_read, Snackbar.LENGTH_INDEFINITE) { - anchorView = activity?.bottom_nav + anchorView = activityBinding?.bottomNav var undoing = false setAction(R.string.undo) { presenter.markChapterRead(chapter, false, lastRead, pagesLeft) @@ -457,14 +446,14 @@ class RecentsController(bundle: Bundle? = null) : override fun onPrepareOptionsMenu(menu: Menu) { super.onPrepareOptionsMenu(menu) - if (showingDownloads) dl_bottom_sheet.prepareMenu(menu) + if (showingDownloads) binding.downloadBottomSheet.dlBottomSheet.prepareMenu(menu) } override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { if (type == ControllerChangeType.POP_ENTER) presenter.onCreate() - dl_bottom_sheet.dismiss() + binding.downloadBottomSheet.dlBottomSheet.dismiss() } else { if (type == ControllerChangeType.POP_EXIT) presenter.onDestroy() snack?.dismiss() @@ -480,29 +469,29 @@ class RecentsController(bundle: Bundle? = null) : fun hasQueue() = presenter.downloadManager.hasQueue() override fun showSheet() { - if (dl_bottom_sheet.sheetBehavior?.isHideable == false || hasQueue()) { - dl_bottom_sheet.sheetBehavior?.expand() + if (binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == false || hasQueue()) { + binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.expand() } } override fun toggleSheet() { - if (showingDownloads) dl_bottom_sheet.dismiss() - else dl_bottom_sheet.sheetBehavior?.expand() + if (showingDownloads) binding.downloadBottomSheet.dlBottomSheet.dismiss() + else binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.expand() } - override fun sheetIsExpanded(): Boolean = dl_bottom_sheet.sheetBehavior.isExpanded() + override fun sheetIsExpanded(): Boolean = binding.downloadBottomSheet.dlBottomSheet.sheetBehavior.isExpanded() override fun expandSearch() { if (showingDownloads) { - dl_bottom_sheet.dismiss() + binding.downloadBottomSheet.dlBottomSheet.dismiss() } else { - activity?.toolbar?.menu?.findItem(R.id.action_search)?.expandActionView() + activityBinding?.toolbar?.menu?.findItem(R.id.action_search)?.expandActionView() } } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (showingDownloads) { - return dl_bottom_sheet.onOptionsItemSelected(item) + return binding.downloadBottomSheet.dlBottomSheet.onOptionsItemSelected(item) } when (item.itemId) { R.id.action_group_all, R.id.action_ungroup_all, R.id.action_only_history, diff --git a/app/src/main/res/layout/recent_manga_item.xml b/app/src/main/res/layout/recent_manga_item.xml index e14210c2c5..8a4d5bd022 100644 --- a/app/src/main/res/layout/recent_manga_item.xml +++ b/app/src/main/res/layout/recent_manga_item.xml @@ -25,7 +25,7 @@ android:layout_gravity="end|center" android:layout_marginEnd="21dp" android:src="@drawable/ic_eye_24dp" - android:tint="@color/md_white_1000" /> + app:tint="@color/md_white_1000" /> - +