From 8b69813f342885d9c4bc33b958d53baf524072f5 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 26 Oct 2019 18:04:52 -0700 Subject: [PATCH] More stuff Cleartext (http sites) support Moved view extensions to view extensions Even more insets support --- app/src/main/AndroidManifest.xml | 3 +- .../browse/BrowseCatalogueController.kt | 18 +++- .../CatalogueSearchController.kt | 2 + .../ui/category/CategoryController.kt | 12 +++ .../ui/download/DownloadController.kt | 2 + .../ui/extension/ExtensionController.kt | 2 + .../ui/library/LibraryCategoryView.kt | 6 +- .../tachiyomi/ui/library/LibraryController.kt | 14 +-- .../kanade/tachiyomi/ui/main/MainActivity.kt | 84 +---------------- .../ui/manga/chapter/ChaptersController.kt | 10 +- .../ui/manga/info/MangaInfoController.kt | 8 +- .../ui/migration/MigrationController.kt | 2 + .../tachiyomi/ui/reader/ReaderActivity.kt | 3 - .../RecentChaptersController.kt | 2 + .../recently_read/RecentlyReadController.kt | 2 + .../ui/setting/SettingsController.kt | 7 +- .../kanade/tachiyomi/util/ViewExtensions.kt | 92 ++++++++++++++++++- .../main/res/layout/categories_controller.xml | 1 + .../main/res/layout/download_controller.xml | 1 + .../main/res/layout/extension_controller.xml | 1 + .../main/res/layout/migration_controller.xml | 3 +- .../res/layout/recent_chapters_controller.xml | 1 + .../main/res/xml/network_security_config.xml | 8 ++ 23 files changed, 157 insertions(+), 127 deletions(-) create mode 100644 app/src/main/res/xml/network_security_config.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9edb5c0c3c..ec34fc628b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,7 +22,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:label="@string/app_name" android:largeHeap="true" - android:theme="@style/Theme.Tachiyomi"> + android:theme="@style/Theme.Tachiyomi" + android:networkSecurityConfig="@xml/network_security_config"> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 9027b12433..26ae3ea108 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -23,13 +23,12 @@ import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.library.HeightTopWindowInsetsListener -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.ui.manga.info.MangaWebViewController import eu.kanade.tachiyomi.util.* import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.catalogue_controller.* +import kotlinx.android.synthetic.main.categories_item.view.* import kotlinx.android.synthetic.main.main_activity.* import rx.Observable import rx.Subscription @@ -155,13 +154,22 @@ open class BrowseCatalogueController(bundle: Bundle) : presenter.sourceFilters = newFilters navView.setFilters(presenter.filterItems) } + drawer.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + val statusScrim = navView.findViewById(R.id.status_bar_scrim) as View statusScrim.setOnApplyWindowInsetsListener(HeightTopWindowInsetsListener) + val titleView = navView.findViewById(R.id.title_background) as View + val titleMarginTop = titleView.marginTop navView.doOnApplyWindowInsets { v, insets, padding -> - navView.recycler.updatePaddingRelative( - bottom = padding.bottom + insets.systemWindowInsetBottom, - top = padding.top + insets.systemWindowInsetTop + v.updatePaddingRelative( + bottom = padding.bottom + insets.systemWindowInsetBottom, + end = padding.right + insets.systemWindowInsetRight ) + titleView.updateLayoutParams { + topMargin = titleMarginTop + insets.systemWindowInsetTop + } } return navView } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchController.kt index a3f7f4ca28..da76c4867c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/global_search/CatalogueSearchController.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.manga.MangaController +import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener import kotlinx.android.synthetic.main.catalogue_global_search_controller.* /** @@ -133,6 +134,7 @@ open class CatalogueSearchController( // Create recycler and set adapter. recycler.layoutManager = LinearLayoutManager(view.context) recycler.adapter = adapter + recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt index c698c2d6e6..1eaff7f067 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt @@ -13,7 +13,11 @@ import eu.davidea.flexibleadapter.helpers.UndoHelper import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.util.doOnApplyWindowInsets +import eu.kanade.tachiyomi.util.marginBottom import eu.kanade.tachiyomi.util.toast +import eu.kanade.tachiyomi.util.updateLayoutParams +import eu.kanade.tachiyomi.util.updatePaddingRelative import kotlinx.android.synthetic.main.categories_controller.* /** @@ -83,6 +87,14 @@ class CategoryController : NucleusController(), fab.clicks().subscribeUntilDestroy { CategoryCreateDialog(this@CategoryController).showDialog(router, null) } + + val fabBaseMarginBottom = fab?.marginBottom ?: 0 + recycler.doOnApplyWindowInsets { v, insets, padding -> + v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) + fab?.updateLayoutParams { + bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom + } + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index 9252374f11..9793b81830 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener import kotlinx.android.synthetic.main.download_controller.* import rx.Observable import rx.Subscription @@ -64,6 +65,7 @@ class DownloadController : NucleusController() { // Set the layout manager for the recycler and fixed size. recycler.layoutManager = LinearLayoutManager(view.context) recycler.setHasFixedSize(true) + recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) // Suscribe to changes DownloadService.runningRelay diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt index 0079c6be00..b14edc78de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener import kotlinx.android.synthetic.main.extension_controller.* @@ -58,6 +59,7 @@ open class ExtensionController : NucleusController(), ext_recycler.layoutManager = LinearLayoutManager(view.context) ext_recycler.adapter = adapter ext_recycler.addItemDecoration(ExtensionDividerItemDecoration(view.context)) + ext_recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) } override fun onDestroyView(view: View) { 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 691457c5db..f58f11e379 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,11 +13,7 @@ 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 +import eu.kanade.tachiyomi.util.* import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.library_category.view.* import rx.subscriptions.CompositeSubscription 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 96962297fe..9d8624b523 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 @@ -32,16 +32,9 @@ 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.marginBottom -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.marginTop -import eu.kanade.tachiyomi.util.toast -import kotlinx.android.synthetic.main.chapters_controller.* +import eu.kanade.tachiyomi.util.* import kotlinx.android.synthetic.main.library_controller.* import kotlinx.android.synthetic.main.main_activity.* import rx.Subscription @@ -202,8 +195,9 @@ class LibraryController( statusScrim.setOnApplyWindowInsetsListener(HeightTopWindowInsetsListener) view.doOnApplyWindowInsets { v, insets, padding -> view.recycler.updatePaddingRelative( - bottom = view.recycler.marginBottom + insets.systemWindowInsetBottom, - top = view.recycler.marginTop + insets.systemWindowInsetTop + bottom = view.recycler.marginBottom + insets.systemWindowInsetBottom, + top = view.recycler.marginTop + insets.systemWindowInsetTop, + end = view.recycler.marginRight + insets.systemWindowInsetRight ) } 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 5f345e1fc8..bb4da456a2 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 @@ -36,7 +36,10 @@ import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController import eu.kanade.tachiyomi.ui.setting.SettingsMainController +import eu.kanade.tachiyomi.util.NoopWindowInsetsListener +import eu.kanade.tachiyomi.util.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.openInBrowser +import eu.kanade.tachiyomi.util.updatePaddingRelative import kotlinx.android.synthetic.main.main_activity.* import uy.kohesive.injekt.injectLazy @@ -320,84 +323,3 @@ class MainActivity : BaseActivity() { } } - -object NoopWindowInsetsListener : View.OnApplyWindowInsetsListener { - override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets { - v.setPadding(insets.systemWindowInsetLeft,insets.systemWindowInsetTop,insets.systemWindowInsetRight,0) - //insets.consumeSystemWindowInsets() - return insets - } -} - -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, WindowInsets, ViewPaddingState) -> Unit) { - // Create a snapshot of the view's padding state - val paddingState = createStateForView(this) - setOnApplyWindowInsetsListener { 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 e5e054c38b..3c1701e6de 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,17 +21,9 @@ 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 -import eu.kanade.tachiyomi.util.snack -import eu.kanade.tachiyomi.util.toast +import eu.kanade.tachiyomi.util.* import kotlinx.android.synthetic.main.chapters_controller.* import timber.log.Timber 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 6e018e3d23..02d44b6a4a 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,14 +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 -import eu.kanade.tachiyomi.util.snack -import eu.kanade.tachiyomi.util.toast -import eu.kanade.tachiyomi.util.truncateCenter +import eu.kanade.tachiyomi.util.* import jp.wasabeef.glide.transformations.CropSquareTransformation import jp.wasabeef.glide.transformations.MaskTransformation import kotlinx.android.synthetic.main.manga_info_controller.* diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt index a72bcc8e5a..f670001bdf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener import kotlinx.android.synthetic.main.migration_controller.* class MigrationController : NucleusController(), @@ -43,6 +44,7 @@ class MigrationController : NucleusController(), adapter = FlexibleAdapter(null, this) migration_recycler.layoutManager = LinearLayoutManager(view.context) migration_recycler.adapter = adapter + migration_recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 1547b863fd..b21cc4ccec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -21,9 +21,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity -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.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index 1b0fef7dbd..4333da5c27 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -19,6 +19,7 @@ import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.toast import kotlinx.android.synthetic.main.recent_chapters_controller.* import timber.log.Timber @@ -90,6 +91,7 @@ class RecentChaptersController : NucleusController(), // It can be a very long operation, so we disable swipe refresh and show a toast. swipe_refresh.isRefreshing = false } + recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index c094c39fc0..cddd8eda1c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.toast import kotlinx.android.synthetic.main.recently_read_controller.* @@ -58,6 +59,7 @@ class RecentlyReadController : NucleusController(), adapter = RecentlyReadAdapter(this@RecentlyReadController) recycler.setHasFixedSize(true) recycler.adapter = adapter + recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index 21af01ca55..b4dabd1972 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -15,6 +15,9 @@ import com.bluelinelabs.conductor.ControllerChangeType import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.BaseController +import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener +import eu.kanade.tachiyomi.util.doOnApplyWindowInsets +import eu.kanade.tachiyomi.util.updatePaddingRelative import rx.Observable import rx.Subscription import rx.subscriptions.CompositeSubscription @@ -32,7 +35,9 @@ abstract class SettingsController : PreferenceController() { if (untilDestroySubscriptions.isUnsubscribed) { untilDestroySubscriptions = CompositeSubscription() } - return super.onCreateView(inflater, container, savedInstanceState) + val view = super.onCreateView(inflater, container, savedInstanceState) + listView.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) + return view } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt index ed5027989c..c8dd10466d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt @@ -7,6 +7,8 @@ import android.graphics.Color import android.graphics.Point import android.graphics.Typeface import android.os.Build +import android.support.annotation.Px +import android.support.annotation.RequiresApi import android.support.design.widget.Snackbar import android.support.v4.view.ViewCompat import android.support.v4.view.WindowInsetsCompat @@ -18,10 +20,6 @@ import android.widget.TextView import com.amulyakhare.textdrawable.TextDrawable import com.amulyakhare.textdrawable.util.ColorGenerator import eu.kanade.tachiyomi.R -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.updatePaddingRelative /** * Returns coordinates of view. @@ -97,3 +95,89 @@ fun View.getRound(text: String, random : Boolean = true): TextDrawable { inline val View.marginTop: Int get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin ?: 0 + +inline val View.marginBottom: Int + get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.bottomMargin ?: 0 + +inline val View.marginRight: Int + get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.rightMargin ?: 0 + +inline val View.marginLeft: Int + get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.leftMargin ?: 0 + +object NoopWindowInsetsListener : View.OnApplyWindowInsetsListener { + override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets { + v.setPadding(insets.systemWindowInsetLeft,insets.systemWindowInsetTop,insets.systemWindowInsetRight,0) + //insets.consumeSystemWindowInsets() + return insets + } +} + +object RecyclerWindowInsetsListener : View.OnApplyWindowInsetsListener { + override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets { + v.setPadding(0,0,0,insets.systemWindowInsetBottom) + //v.updatePaddingRelative(bottom = v.paddingBottom + insets.systemWindowInsetBottom) + return insets + } +} + +fun View.doOnApplyWindowInsets(f: (View, WindowInsets, ViewPaddingState) -> Unit) { + // Create a snapshot of the view's padding state + val paddingState = createStateForView(this) + setOnApplyWindowInsetsListener { 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 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/res/layout/categories_controller.xml b/app/src/main/res/layout/categories_controller.xml index 9bc79a6c39..cc8017ed35 100644 --- a/app/src/main/res/layout/categories_controller.xml +++ b/app/src/main/res/layout/categories_controller.xml @@ -10,6 +10,7 @@ android:layout_height="match_parent" android:id="@+id/recycler" android:choiceMode="multipleChoice" + android:clipToPadding="false" tools:listitem="@layout/categories_item" /> diff --git a/app/src/main/res/layout/download_controller.xml b/app/src/main/res/layout/download_controller.xml index 8b353b1fe6..c8fe6ffb22 100644 --- a/app/src/main/res/layout/download_controller.xml +++ b/app/src/main/res/layout/download_controller.xml @@ -10,6 +10,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/recycler" + android:clipToPadding="false" tools:listitem="@layout/download_item"/> \ No newline at end of file diff --git a/app/src/main/res/layout/migration_controller.xml b/app/src/main/res/layout/migration_controller.xml index 643832cd0a..d3caebbca4 100644 --- a/app/src/main/res/layout/migration_controller.xml +++ b/app/src/main/res/layout/migration_controller.xml @@ -3,4 +3,5 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/migration_recycler" android:layout_width="match_parent" - android:layout_height="match_parent"/> + android:layout_height="match_parent" + android:clipToPadding="false"/> diff --git a/app/src/main/res/layout/recent_chapters_controller.xml b/app/src/main/res/layout/recent_chapters_controller.xml index 6dcca143ed..8b420b6448 100644 --- a/app/src/main/res/layout/recent_chapters_controller.xml +++ b/app/src/main/res/layout/recent_chapters_controller.xml @@ -15,6 +15,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants" + android:clipToPadding="false" tools:listitem="@layout/recent_chapters_item"/> + + + + + + + \ No newline at end of file