Fixes to manga details when app is locked + scrolling toolbar fixes

This commit is contained in:
Jay 2020-03-28 19:11:32 -04:00
parent 9e67c00465
commit b48cff63e4
2 changed files with 70 additions and 42 deletions

View File

@ -252,10 +252,15 @@ class MangaDetailsController : BaseController,
if ((!atTop && !toolbarIsColored && (appBarY < (-headerHeight + 1) || (dy < 0 && appBarY == 0f))) || (atTop && toolbarIsColored)) { if ((!atTop && !toolbarIsColored && (appBarY < (-headerHeight + 1) || (dy < 0 && appBarY == 0f))) || (atTop && toolbarIsColored)) {
colorToolbar(!atTop) colorToolbar(!atTop)
} }
if (atTop) {
getHeader()?.backdrop?.translationY = 0f
activity!!.appbar.y = 0f
}
} }
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState) super.onScrollStateChanged(recyclerView, newState)
val atTop = !recycler.canScrollVertically(-1)
if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (newState == RecyclerView.SCROLL_STATE_IDLE) {
if (router?.backstack?.lastOrNull() if (router?.backstack?.lastOrNull()
?.controller() == this@MangaDetailsController && statusBarHeight > -1 && activity != null && ?.controller() == this@MangaDetailsController && statusBarHeight > -1 && activity != null &&
@ -266,7 +271,6 @@ class MangaDetailsController : BaseController,
android.R.integer.config_shortAnimTime android.R.integer.config_shortAnimTime
) ?: 0 ) ?: 0
val closerToTop = abs(activity!!.appbar.y) - halfWay > 0 val closerToTop = abs(activity!!.appbar.y) - halfWay > 0
val atTop = !recycler.canScrollVertically(-1)
activity!!.appbar.animate().y( activity!!.appbar.animate().y(
if (closerToTop && !atTop) (-activity!!.appbar.height.toFloat()) if (closerToTop && !atTop) (-activity!!.appbar.height.toFloat())
else 0f else 0f
@ -275,6 +279,11 @@ class MangaDetailsController : BaseController,
colorToolbar(true) colorToolbar(true)
} }
} }
if (atTop && toolbarIsColored) colorToolbar(false)
if (atTop) {
getHeader()?.backdrop?.translationY = 0f
activity!!.appbar.y = 0f
}
} }
}) })
setPaletteColor() setPaletteColor()
@ -599,6 +608,7 @@ class MangaDetailsController : BaseController,
editItem.title = view?.context?.getString(if (manga?.source == LocalSource.ID) editItem.title = view?.context?.getString(if (manga?.source == LocalSource.ID)
R.string.action_edit else R.string.action_edit_cover) R.string.action_edit else R.string.action_edit_cover)
menu.findItem(R.id.action_download).isVisible = !presenter.isLockedFromSearch menu.findItem(R.id.action_download).isVisible = !presenter.isLockedFromSearch
menu.findItem(R.id.action_add_to_home_screen).isVisible = !presenter.isLockedFromSearch
menu.findItem(R.id.action_mark_all_as_read).isVisible = menu.findItem(R.id.action_mark_all_as_read).isVisible =
presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch
menu.findItem(R.id.action_mark_all_as_unread).isVisible = menu.findItem(R.id.action_mark_all_as_unread).isVisible =
@ -935,11 +945,16 @@ class MangaDetailsController : BaseController,
ChaptersSortBottomSheet(this).show() ChaptersSortBottomSheet(this).show()
} }
override fun favoriteManga(longPress: Boolean) { private fun isLocked(): Boolean {
if (presenter.isLockedFromSearch) { if (presenter.isLockedFromSearch) {
SecureActivityDelegate.promptLockIfNeeded(activity) SecureActivityDelegate.promptLockIfNeeded(activity)
return return true
} }
return false
}
override fun favoriteManga(longPress: Boolean) {
if (isLocked()) return
val manga = presenter.manga val manga = presenter.manga
if (longPress) { if (longPress) {
if (!manga.favorite) { if (!manga.favorite) {
@ -1071,6 +1086,7 @@ class MangaDetailsController : BaseController,
} }
override fun showTrackingSheet() { override fun showTrackingSheet() {
if (isLocked()) return
trackingBottomSheet = trackingBottomSheet =
TrackingBottomSheet(this) TrackingBottomSheet(this)
trackingBottomSheet?.show() trackingBottomSheet?.show()

View File

@ -89,19 +89,28 @@ class MangaHeaderHolder(
val presenter = adapter.delegate.mangaPresenter() val presenter = adapter.delegate.mangaPresenter()
manga_full_title.text = manga.title manga_full_title.text = manga.title
if (manga.genre.isNullOrBlank().not()) if (manga.genre.isNullOrBlank().not()) manga_genres_tags.setTags(
manga_genres_tags.setTags(manga.genre?.split(", ")?.map(String::trim)) manga.genre?.split(", ")?.map(String::trim)
else )
manga_genres_tags.setTags(emptyList()) else manga_genres_tags.setTags(emptyList())
if (manga.author == manga.artist || if (manga.author == manga.artist || manga.artist.isNullOrBlank()) manga_author.text =
manga.artist.isNullOrBlank()) manga.author?.trim()
manga_author.text = manga.author?.trim()
else { else {
manga_author.text = "${manga.author?.trim()}, ${manga.artist}" manga_author.text = "${manga.author?.trim()}, ${manga.artist}"
} }
manga_summary.text = manga.description?.trim() ?: itemView.context.getString(R.string manga_summary.text = manga.description?.trim() ?: itemView.context.getString(
.no_description) R.string.no_description
)
if (item.isLocked) sub_item_group.referencedIds =
intArrayOf(R.id.manga_summary, R.id.manga_summary_label, R.id.button_layout)
else sub_item_group.referencedIds = intArrayOf(
R.id.start_reading_button,
R.id.manga_summary,
R.id.manga_summary_label,
R.id.button_layout
)
manga_summary.post { manga_summary.post {
if (sub_item_group.visibility != View.GONE) { if (sub_item_group.visibility != View.GONE) {
@ -112,8 +121,8 @@ class MangaHeaderHolder(
if (adapter.hasFilter()) collapse() if (adapter.hasFilter()) collapse()
else expand() else expand()
} }
manga_summary_label.text = itemView.context.getString(R.string.about_this, manga_summary_label.text = itemView.context.getString(
itemView.context.getString( R.string.about_this, itemView.context.getString(
when { when {
manga.mangaType() == Manga.TYPE_MANHWA -> R.string.manhwa manga.mangaType() == Manga.TYPE_MANHWA -> R.string.manhwa
manga.mangaType() == Manga.TYPE_MANHUA -> R.string.manhua manga.mangaType() == Manga.TYPE_MANHUA -> R.string.manhua
@ -121,7 +130,8 @@ class MangaHeaderHolder(
manga.mangaType() == Manga.TYPE_WEBTOON -> R.string.webtoon manga.mangaType() == Manga.TYPE_WEBTOON -> R.string.webtoon
else -> R.string.manga else -> R.string.manga
} }
).toLowerCase(Locale.getDefault())) ).toLowerCase(Locale.getDefault())
)
with(favorite_button) { with(favorite_button) {
icon = ContextCompat.getDrawable( icon = ContextCompat.getDrawable(
itemView.context, when { itemView.context, when {
@ -139,18 +149,24 @@ class MangaHeaderHolder(
) )
checked(!item.isLocked && manga.favorite) checked(!item.isLocked && manga.favorite)
} }
true_backdrop.setBackgroundColor(adapter.delegate.coverColor() true_backdrop.setBackgroundColor(
?: itemView.context.getResourceColor(android.R.attr.colorBackground)) adapter.delegate.coverColor()
?: itemView.context.getResourceColor(android.R.attr.colorBackground)
)
val tracked = presenter.isTracked() && !item.isLocked val tracked = presenter.isTracked() && !item.isLocked
with(track_button) { with(track_button) {
visibleIf(presenter.hasTrackers()) visibleIf(presenter.hasTrackers())
text = itemView.context.getString(if (tracked) R.string.action_filter_tracked text = itemView.context.getString(
else R.string.tracking) if (tracked) R.string.action_filter_tracked
else R.string.tracking
)
icon = ContextCompat.getDrawable(itemView.context, if (tracked) R.drawable icon = ContextCompat.getDrawable(
.ic_check_white_24dp else R.drawable.ic_sync_black_24dp) itemView.context,
if (tracked) R.drawable.ic_check_white_24dp else R.drawable.ic_sync_black_24dp
)
checked(tracked) checked(tracked)
} }
@ -158,21 +174,20 @@ class MangaHeaderHolder(
val nextChapter = presenter.getNextUnreadChapter() val nextChapter = presenter.getNextUnreadChapter()
visibleIf(presenter.chapters.isNotEmpty() && !item.isLocked) visibleIf(presenter.chapters.isNotEmpty() && !item.isLocked)
isEnabled = (nextChapter != null) isEnabled = (nextChapter != null)
if (nextChapter != null) { text = if (nextChapter != null) {
val number = adapter.decimalFormat.format(nextChapter.chapter_number.toDouble()) val number = adapter.decimalFormat.format(nextChapter.chapter_number.toDouble())
text = if (nextChapter.chapter_number > 0) resources.getString( if (nextChapter.chapter_number > 0) resources.getString(
if (nextChapter.last_page_read > 0) R.string.continue_reading_chapter if (nextChapter.last_page_read > 0) R.string.continue_reading_chapter
else R.string.start_reading_chapter, number else R.string.start_reading_chapter, number
) )
else { else {
val name = nextChapter.name
resources.getString( resources.getString(
if (nextChapter.last_page_read > 0) R.string.continue_reading if (nextChapter.last_page_read > 0) R.string.continue_reading
else R.string.start_reading else R.string.start_reading
) )
} }
} else { } else {
text = resources.getString(R.string.all_chapters_read) resources.getString(R.string.all_chapters_read)
} }
} }
@ -183,12 +198,14 @@ class MangaHeaderHolder(
height = adapter.delegate.topCoverHeight() height = adapter.delegate.topCoverHeight()
} }
manga_status.text = (itemView.context.getString(when (manga.status) { manga_status.text = (itemView.context.getString(
when (manga.status) {
SManga.ONGOING -> R.string.ongoing SManga.ONGOING -> R.string.ongoing
SManga.COMPLETED -> R.string.completed SManga.COMPLETED -> R.string.completed
SManga.LICENSED -> R.string.licensed SManga.LICENSED -> R.string.licensed
else -> R.string.unknown_status else -> R.string.unknown_status
})) }
))
manga_source.text = presenter.source.toString() manga_source.text = presenter.source.toString()
filters_text.text = presenter.currentFilters() filters_text.text = presenter.currentFilters()
@ -199,16 +216,12 @@ class MangaHeaderHolder(
} }
if (!manga.initialized) return if (!manga.initialized) return
GlideApp.with(view.context).load(manga) GlideApp.with(view.context).load(manga).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())) .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString()))
.into(manga_cover) .into(manga_cover)
GlideApp.with(view.context).load(manga) GlideApp.with(view.context).load(manga).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())).centerCrop()
.signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())) .transition(DrawableTransitionOptions.withCrossFade()).into(backdrop)
.centerCrop()
.transition(DrawableTransitionOptions.withCrossFade())
.into(backdrop)
} }
private fun MaterialButton.checked(checked: Boolean) { private fun MaterialButton.checked(checked: Boolean) {
@ -243,7 +256,7 @@ class MangaHeaderHolder(
} }
fun updateTracking() { fun updateTracking() {
val presenter = adapter.delegate.mangaPresenter() ?: return val presenter = adapter.delegate.mangaPresenter()
val tracked = presenter.isTracked() val tracked = presenter.isTracked()
with(track_button) { with(track_button) {
text = itemView.context.getString(if (tracked) R.string.action_filter_tracked text = itemView.context.getString(if (tracked) R.string.action_filter_tracked
@ -267,8 +280,7 @@ class MangaHeaderHolder(
fun expand() { fun expand() {
sub_item_group.visible() sub_item_group.visible()
if (more_button.visibility == View.VISIBLE || more_button.visibility == View.INVISIBLE) if (more_button.visibility == View.VISIBLE || more_button.visibility == View.INVISIBLE) more_button_group.visible()
more_button_group.visible()
else { else {
less_button.visible() less_button.visible()
manga_genres_tags.visible() manga_genres_tags.visible()