From b9e3e3de557f6389b2cb8261b07930d5ff8deeb3 Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 25 Oct 2019 01:44:47 -0700 Subject: [PATCH] Android 29 SDK + edge to edge --- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 2 + .../browse/BrowseCatalogueController.kt | 9 +++ .../ui/library/LibraryCategoryView.kt | 5 ++ .../tachiyomi/ui/library/LibraryController.kt | 11 ++- .../kanade/tachiyomi/ui/main/MainActivity.kt | 72 ++++++++++++++++++- .../ui/manga/chapter/ChaptersController.kt | 17 +++++ .../ui/manga/info/MangaInfoController.kt | 7 ++ .../ui/reader/PageIndicatorTextView.kt | 10 +-- .../ui/setting/SettingsGeneralController.kt | 13 +++- app/src/main/res/layout/catalogue_drawer.xml | 2 +- .../main/res/layout/chapters_controller.xml | 1 + app/src/main/res/layout/library_drawer.xml | 2 +- app/src/main/res/values-night/themes.xml | 2 +- app/src/main/res/values-v21/themes.xml | 1 - app/src/main/res/values-v29/themes.xml | 4 -- app/src/main/res/values/colors.xml | 4 +- 17 files changed, 147 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c3e57db263..7771286ac1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,14 +29,14 @@ ext { } android { - compileSdkVersion 28 + compileSdkVersion 29 buildToolsVersion '29.0.2' publishNonDefault true defaultConfig { applicationId "eu.kanade.tachiyomi" minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 29 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" versionCode 41 versionName "0.8.4" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eff4c70578..9edb5c0c3c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,8 @@ + + + v.updatePaddingRelative( + bottom = padding.bottom + insets.systemWindowInsetBottom, + top = padding.top + insets.systemWindowInsetTop + ) + } return navView } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index f2969dbce2..691457c5db 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -13,6 +13,8 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets +import eu.kanade.tachiyomi.ui.main.updatePaddingRelative import eu.kanade.tachiyomi.util.inflate import eu.kanade.tachiyomi.util.plusAssign import eu.kanade.tachiyomi.util.toast @@ -87,6 +89,9 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att swipe_refresh.isEnabled = firstPos <= 0 } }) + recycler.doOnApplyWindowInsets { v, insets, padding -> + v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) + } // Double the distance required to trigger sync swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 4f8c9451c0..61b544f428 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -31,10 +31,14 @@ import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.main.MainActivity +import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets +import eu.kanade.tachiyomi.ui.main.updateLayoutParams +import eu.kanade.tachiyomi.ui.main.updatePaddingRelative import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.migration.MigrationController import eu.kanade.tachiyomi.util.inflate import eu.kanade.tachiyomi.util.toast +import kotlinx.android.synthetic.main.chapters_controller.* import kotlinx.android.synthetic.main.library_controller.* import kotlinx.android.synthetic.main.main_activity.* import rx.Subscription @@ -187,7 +191,12 @@ class LibraryController( is LibraryNavigationView.BadgeGroup -> onDownloadBadgeChanged() } } - + view.doOnApplyWindowInsets { v, insets, padding -> + v.updatePaddingRelative( + bottom = padding.bottom + insets.systemWindowInsetBottom, + top = padding.top + insets.systemWindowInsetTop + ) + } return view } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 1c26947662..5381d33eeb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -6,7 +6,11 @@ import android.content.Intent import android.content.res.Configuration import android.graphics.Color import android.os.Bundle +import android.support.annotation.Px +import android.support.annotation.RequiresApi import android.support.v4.view.GravityCompat +import android.support.v4.view.ViewCompat +import android.support.v4.view.WindowInsetsCompat import android.support.v4.widget.DrawerLayout import android.support.v7.app.AppCompatDelegate import android.support.v7.app.AppCompatDelegate.* @@ -307,7 +311,8 @@ class MainActivity : BaseActivity() { object NoopWindowInsetsListener : View.OnApplyWindowInsetsListener { override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets { - v.setPadding(0,insets.systemWindowInsetTop,0,0) + v.setPadding(insets.systemWindowInsetLeft,insets.systemWindowInsetTop,insets.systemWindowInsetRight,0) + //insets.consumeSystemWindowInsets() return insets } } @@ -315,6 +320,71 @@ object NoopWindowInsetsListener : View.OnApplyWindowInsetsListener { object NoopWindowInsetsListener2 : View.OnApplyWindowInsetsListener { override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets { v.setPadding(0,0,0,insets.systemWindowInsetBottom) + insets.consumeSystemWindowInsets() return insets } +} + +fun View.doOnApplyWindowInsets(f: (View, WindowInsetsCompat, ViewPaddingState) -> Unit) { + // Create a snapshot of the view's padding state + val paddingState = createStateForView(this) + ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets -> + f(v, insets, paddingState) + insets + } + requestApplyInsetsWhenAttached() +} + +fun View.requestApplyInsetsWhenAttached() { + if (isAttachedToWindow) { + requestApplyInsets() + } else { + addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener { + override fun onViewAttachedToWindow(v: View) { + v.requestApplyInsets() + } + + override fun onViewDetachedFromWindow(v: View) = Unit + }) + } +} + +inline fun View.updateLayoutParams(block: T.() -> Unit) { + val params = layoutParams as T + block(params) + layoutParams = params +} + +inline val View.marginBottom: Int + get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.bottomMargin ?: 0 + +inline fun View.updatePadding( + @Px left: Int = paddingLeft, + @Px top: Int = paddingTop, + @Px right: Int = paddingRight, + @Px bottom: Int = paddingBottom +) { + setPadding(left, top, right, bottom) +} + +private fun createStateForView(view: View) = ViewPaddingState(view.paddingLeft, + view.paddingTop, view.paddingRight, view.paddingBottom, view.paddingStart, view.paddingEnd) + +data class ViewPaddingState( + val left: Int, + val top: Int, + val right: Int, + val bottom: Int, + val start: Int, + val end: Int +) + +@RequiresApi(17) +inline fun View.updatePaddingRelative( + @Px start: Int = paddingStart, + @Px top: Int = paddingTop, + @Px end: Int = paddingEnd, + @Px bottom: Int = paddingBottom +) { + setPaddingRelative(start, top, end, bottom) } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 8397e0b414..602fcaec9d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -21,6 +21,12 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag +import eu.kanade.tachiyomi.ui.main.NoopWindowInsetsListener2 +import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets +import eu.kanade.tachiyomi.ui.main.marginBottom +import eu.kanade.tachiyomi.ui.main.updateLayoutParams +import eu.kanade.tachiyomi.ui.main.updatePadding +import eu.kanade.tachiyomi.ui.main.updatePaddingRelative import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.getCoordinates @@ -82,6 +88,17 @@ class ChaptersController : NucleusController(), recycler.setHasFixedSize(true) adapter?.fastScroller = fast_scroller + val fabBaseMarginBottom = fab?.marginBottom ?: 0 + recycler.doOnApplyWindowInsets { v, insets, padding -> + v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) + fab?.updateLayoutParams { + bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom + } + fast_scroller?.updateLayoutParams { + bottomMargin = insets.systemWindowInsetBottom + } + } + //fast_scroller.setOnApplyWindowInsetsListener(NoopWindowInsetsListener2) swipe_refresh.refreshes().subscribeUntilDestroy { fetchChaptersFromSource() } fab.clicks().subscribeUntilDestroy { 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 5340627072..0589b8b086 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 @@ -40,6 +40,8 @@ import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.main.MainActivity +import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets +import eu.kanade.tachiyomi.ui.main.updatePaddingRelative import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.getResourceColor import eu.kanade.tachiyomi.util.openInBrowser @@ -128,6 +130,11 @@ class MangaInfoController : NucleusController(), copyToClipboard(view.context.getString(R.string.title), presenter.manga.title) } + view.doOnApplyWindowInsets { v, insets, padding -> + v.updatePaddingRelative( + bottom = padding.bottom + insets.systemWindowInsetBottom + ) + } } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt index 7fa36a2a3e..028ec48488 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt @@ -24,12 +24,14 @@ class PageIndicatorTextView( private val strokeColor = Color.rgb(45, 45, 45) override fun onDraw(canvas: Canvas) { - textColorField.set(this, strokeColor) + setTextColor(strokeColor) + //textColorField.set(this, strokeColor) paint.strokeWidth = 4f paint.style = Paint.Style.STROKE super.onDraw(canvas) - textColorField.set(this, fillColor) + setTextColor(fillColor) + //textColorField.set(this, fillColor) paint.strokeWidth = 0f paint.style = Paint.Style.FILL super.onDraw(canvas) @@ -54,8 +56,8 @@ class PageIndicatorTextView( private companion object { // We need to use reflection to set the text color instead of using [setTextColor], // otherwise the view is invalidated inside [onDraw] and there's an infinite loop - val textColorField = TextView::class.java.getDeclaredField("mCurTextColor").apply { + /* val textColorField = TextView::class.java.getDeclaredField("mCurTextColor").apply { isAccessible = true - }!! + }!!*/ } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index 4afd1ca7b3..87d8a7f7fc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -61,7 +61,18 @@ class SettingsGeneralController : SettingsController() { defaultValue = "5" summary = "%s" - onChange { + onChange {newValue -> + val activity = activity ?: return@onChange false + val app = activity.application + AppCompatDelegate.setDefaultNightMode(when (newValue) { + "1" -> AppCompatDelegate.MODE_NIGHT_NO + "2", "3", "4" -> AppCompatDelegate.MODE_NIGHT_YES + else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + }) + //LocaleHelper.changeLocale(newValue.toString()) + //LocaleHelper.updateConfiguration(app, app.resources.configuration) + //activity?.recreate() + activity?.recreate() true } diff --git a/app/src/main/res/layout/catalogue_drawer.xml b/app/src/main/res/layout/catalogue_drawer.xml index 6a1cc344b5..672161f6c8 100644 --- a/app/src/main/res/layout/catalogue_drawer.xml +++ b/app/src/main/res/layout/catalogue_drawer.xml @@ -5,5 +5,5 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="end" - android:fitsSystemWindows="false"/> + android:fitsSystemWindows="true"/> diff --git a/app/src/main/res/layout/chapters_controller.xml b/app/src/main/res/layout/chapters_controller.xml index 2f2d19d566..5116a70b7a 100644 --- a/app/src/main/res/layout/chapters_controller.xml +++ b/app/src/main/res/layout/chapters_controller.xml @@ -28,6 +28,7 @@ android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" + android:clipToPadding="false" android:descendantFocusability="blocksDescendants" tools:listitem="@layout/chapters_item"> diff --git a/app/src/main/res/layout/library_drawer.xml b/app/src/main/res/layout/library_drawer.xml index 659d66bb9a..914c329ddb 100644 --- a/app/src/main/res/layout/library_drawer.xml +++ b/app/src/main/res/layout/library_drawer.xml @@ -5,4 +5,4 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="end" - android:fitsSystemWindows="false" /> + android:fitsSystemWindows="true" /> diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index b543bf07dc..a34d096b05 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -47,7 +47,7 @@ - diff --git a/app/src/main/res/values-v29/themes.xml b/app/src/main/res/values-v29/themes.xml index bb7e609435..54e5d44548 100644 --- a/app/src/main/res/values-v29/themes.xml +++ b/app/src/main/res/values-v29/themes.xml @@ -8,9 +8,6 @@ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index eab6d88749..9ff1db179d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -2,10 +2,10 @@ #54759E - #435E7E + #54759E #212121 - #1C1C1D + #212121 @color/md_black_1000