From 10c6d4f8f272307ee1b37f5079d34902e4a41c1c Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 22 Nov 2019 19:40:26 -0800 Subject: [PATCH] Better Tablet support --- app/build.gradle | 1 + .../eu/kanade/tachiyomi/data/database/models/MangaImpl.kt | 8 ++++++++ .../main/java/eu/kanade/tachiyomi/source/model/SManga.kt | 2 -- .../kanade/tachiyomi/ui/manga/info/MangaInfoController.kt | 4 ++++ .../java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt | 7 +++++++ .../java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt | 7 +++++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 790859affd..be30aff7f0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -251,6 +251,7 @@ buildscript { } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt index 615b97b13c..b5a4754486 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt @@ -1,5 +1,7 @@ package eu.kanade.tachiyomi.data.database.models +import eu.kanade.tachiyomi.source.model.SManga + open class MangaImpl : Manga { override var id: Long? = null @@ -34,6 +36,12 @@ open class MangaImpl : Manga { override var hide_title: Boolean = false + override fun copyFrom(other: SManga) { + if (other is MangaImpl && (other as MangaImpl)::title.isInitialized && other.title != title) + title = other.title + super.copyFrom(other) + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || javaClass != other.javaClass) return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt index 6b2d95c26b..b05ab53ecd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt @@ -23,8 +23,6 @@ interface SManga : Serializable { var initialized: Boolean fun copyFrom(other: SManga) { - if (other.title != title) - title = other.title if (other.author != null) author = other.author diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index ee1cb9b8a6..7f744e23fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -151,11 +151,15 @@ class MangaInfoController : NucleusController(), container = (view as ViewGroup).findViewById(R.id.manga_info_layout) as? View val bottomM = manga_genres_tags.marginBottom val fabBaseMarginBottom = fab_favorite.marginBottom + val manga_coverMarginBottom = fab_favorite.marginBottom container?.doOnApplyWindowInsets { v, insets, padding -> if (resources?.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) { fab_favorite?.updateLayoutParams { bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom } + manga_cover?.updateLayoutParams { + bottomMargin = manga_coverMarginBottom + insets.systemWindowInsetBottom + } } else { manga_genres_tags?.updateLayoutParams { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt index 6828382b56..6b0853490d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.widget import android.content.Context +import android.content.res.Configuration import android.graphics.Rect import android.util.AttributeSet import android.view.View @@ -55,11 +56,17 @@ class FABAnimationUpDown @JvmOverloads constructor(ctx: Context, attrs: Attribut } override fun onDependentViewChanged(parent: CoordinatorLayout, child: FloatingActionButton, dependency: View): Boolean { + if (isTablet(child.context)) return true val translationY = getFabTranslationYForSnackbar(parent, child) child.translationY = translationY return true } + private fun isTablet(context: Context): Boolean { + return (context.resources.configuration.screenLayout and Configuration + .SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE + } + private fun getFabTranslationYForSnackbar(parent: CoordinatorLayout, fab: FloatingActionButton): Float { var minOffset = 0f diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt index 8d7d0ad25d..0417d3ac45 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.widget import android.content.Context +import android.content.res.Configuration import android.util.AttributeSet import android.view.View import androidx.coordinatorlayout.widget.CoordinatorLayout @@ -15,11 +16,17 @@ class FABMoveBehaviour(context: Context, attrs: AttributeSet) : return dependency is Snackbar.SnackbarLayout } override fun onDependentViewChanged(parent: CoordinatorLayout, child: FloatingActionButton, dependency: View): Boolean { + if (isTablet(child.context)) return true val translationY = getFabTranslationYForSnackbar(parent, child) child.translationY = translationY return true } + private fun isTablet(context: Context): Boolean { + return (context.resources.configuration.screenLayout and Configuration + .SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE + } + private fun getFabTranslationYForSnackbar(parent: CoordinatorLayout, fab: FloatingActionButton): Float { var minOffset = 0f val dependencies = parent.getDependencies(fab)