From a2c7705d07a049f8f70a7d3abe17b4e00dc80843 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Wed, 24 Mar 2021 17:29:21 -0400 Subject: [PATCH] Refactoring Tabbed Sheets --- .../ui/library/display/LibraryBadgesView.kt | 3 +- .../ui/library/display/LibraryCategoryView.kt | 3 +- .../ui/library/display/LibraryDisplayView.kt | 3 +- .../library/display/LibraryPreferenceView.kt | 28 -- .../reader/settings/BaseReaderSettingsView.kt | 25 - .../ui/reader/settings/ReaderFilterView.kt | 3 +- .../ui/reader/settings/ReaderGeneralView.kt | 2 +- .../ui/reader/settings/ReaderPagedView.kt | 8 +- .../settings/TabbedReaderSettingsSheet.kt | 10 +- .../tachiyomi/widget/BaseTabbedScrollView.kt | 37 ++ .../tachiyomi/widget/TabbedBottomSheet.kt | 27 +- .../main/res/layout/library_badges_layout.xml | 87 ++-- .../res/layout/library_category_layout.xml | 61 +-- .../res/layout/library_display_layout.xml | 142 +++--- .../main/res/layout/reader_color_filter.xml | 439 +++++++++--------- .../main/res/layout/reader_general_layout.xml | 122 +++-- .../main/res/layout/reader_paged_layout.xml | 149 +++--- 17 files changed, 568 insertions(+), 581 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryPreferenceView.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/BaseReaderSettingsView.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt index cdb839d6e7..5629dc15e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt @@ -3,10 +3,11 @@ package eu.kanade.tachiyomi.ui.library.display import android.content.Context import android.util.AttributeSet import eu.kanade.tachiyomi.util.bindToPreference +import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView import kotlinx.android.synthetic.main.library_badges_layout.view.* class LibraryBadgesView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - LibraryPreferenceView(context, attrs) { + BaseLibraryDisplayView(context, attrs) { override fun initGeneralPreferences() { unread_badge_group.bindToPreference(preferences.unreadBadgeType()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt index 6a43e3e1f3..b9ed64cb8d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt @@ -3,10 +3,11 @@ package eu.kanade.tachiyomi.ui.library.display import android.content.Context import android.util.AttributeSet import eu.kanade.tachiyomi.util.bindToPreference +import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView import kotlinx.android.synthetic.main.library_category_layout.view.* class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - LibraryPreferenceView(context, attrs) { + BaseLibraryDisplayView(context, attrs) { override fun initGeneralPreferences() { show_all.bindToPreference(preferences.showAllCategories()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt index 841d794904..065b94a020 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt @@ -3,10 +3,11 @@ package eu.kanade.tachiyomi.ui.library.display import android.content.Context import android.util.AttributeSet import eu.kanade.tachiyomi.util.bindToPreference +import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView import kotlinx.android.synthetic.main.library_display_layout.view.* class LibraryDisplayView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - LibraryPreferenceView(context, attrs) { + BaseLibraryDisplayView(context, attrs) { override fun initGeneralPreferences() { display_group.bindToPreference(preferences.libraryLayout()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryPreferenceView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryPreferenceView.kt deleted file mode 100644 index 14629dcec4..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryPreferenceView.kt +++ /dev/null @@ -1,28 +0,0 @@ -package eu.kanade.tachiyomi.ui.library.display - -import android.content.Context -import android.os.Bundle -import android.util.AttributeSet -import android.widget.CompoundButton -import android.widget.LinearLayout -import android.widget.RadioButton -import android.widget.RadioGroup -import com.f2prateek.rx.preferences.Preference -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.ui.library.LibraryController -import uy.kohesive.injekt.injectLazy - -abstract class LibraryPreferenceView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - LinearLayout(context, attrs) { - - internal val preferences by injectLazy() - lateinit var controller: LibraryController - - abstract fun initGeneralPreferences() - - override fun onFinishInflate() { - super.onFinishInflate() - initGeneralPreferences() - } -} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/BaseReaderSettingsView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/BaseReaderSettingsView.kt deleted file mode 100644 index a0bd99060b..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/BaseReaderSettingsView.kt +++ /dev/null @@ -1,25 +0,0 @@ -package eu.kanade.tachiyomi.ui.reader.settings - -import android.content.Context -import android.util.AttributeSet -import android.widget.FrameLayout -import android.widget.LinearLayout -import com.google.android.material.tabs.TabLayout -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.ui.library.LibraryController -import eu.kanade.tachiyomi.ui.reader.ReaderActivity -import uy.kohesive.injekt.injectLazy - -abstract class BaseReaderSettingsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - FrameLayout(context, attrs) { - - internal val preferences by injectLazy() - lateinit var activity: ReaderActivity - - abstract fun initGeneralPreferences() - - override fun onFinishInflate() { - super.onFinishInflate() - initGeneralPreferences() - } -} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt index 902e7b0382..054e52a33a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderFilterView.kt @@ -6,11 +6,11 @@ import android.widget.SeekBar import androidx.annotation.ColorInt import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener +import eu.kanade.tachiyomi.widget.BaseReaderSettingsView import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import kotlinx.android.synthetic.main.reader_color_filter.* import kotlinx.android.synthetic.main.reader_color_filter.view.* -import kotlinx.android.synthetic.main.reader_color_filter.view.settings_scroll_view import kotlinx.android.synthetic.main.reader_general_layout.view.* import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -21,7 +21,6 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib override fun initGeneralPreferences() { activity = context as ReaderActivity - settings_scroll_view.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) preferences.colorFilter().asFlow() .onEach { setColorFilter(it) } .launchIn(activity.scope) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt index 3db90555e4..6c37bc6929 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderGeneralView.kt @@ -5,6 +5,7 @@ import android.util.AttributeSet import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.bindToPreference import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener +import eu.kanade.tachiyomi.widget.BaseReaderSettingsView import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import kotlinx.android.synthetic.main.reader_general_layout.view.* @@ -13,7 +14,6 @@ class ReaderGeneralView @JvmOverloads constructor(context: Context, attrs: Attri lateinit var sheet: TabbedReaderSettingsSheet override fun initGeneralPreferences() { - settings_scroll_view.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) viewer_series.onItemSelectedListener = { position -> activity.presenter.setMangaViewer(position) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt index df82b91950..42d53a6b34 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt @@ -4,15 +4,10 @@ import android.content.Context import android.util.AttributeSet import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.ReaderActivity -import eu.kanade.tachiyomi.util.bindToIntPreference import eu.kanade.tachiyomi.util.bindToPreference -import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.view.visibleIf +import eu.kanade.tachiyomi.widget.BaseReaderSettingsView import kotlinx.android.synthetic.main.reader_paged_layout.view.* -import kotlinx.android.synthetic.main.reader_paged_layout.view.crop_borders_webtoon -import kotlinx.android.synthetic.main.reader_paged_layout.view.settings_scroll_view -import kotlinx.android.synthetic.main.reader_paged_layout.view.webtoon_enable_zoom_out -import kotlinx.android.synthetic.main.reader_paged_layout.view.webtoon_side_padding class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : BaseReaderSettingsView(context, attrs) { @@ -23,7 +18,6 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu crop_borders.bindToPreference(preferences.cropBorders()) page_transitions.bindToPreference(preferences.pageTransitions()) - settings_scroll_view.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) val mangaViewer = (context as ReaderActivity).presenter.getMangaViewer() val isWebtoonView = mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS val hasMargins = mangaViewer == ReaderActivity.VERTICAL_PLUS diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt index 6405775075..404b3f0a17 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/TabbedReaderSettingsSheet.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.reader.settings import android.view.View +import androidx.core.widget.NestedScrollView import com.google.android.material.tabs.TabLayout import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.library.display.LibraryBadgesView @@ -66,22 +67,13 @@ class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity): TabbedBotto tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { override fun onTabSelected(tab: TabLayout.Tab?) { window?.setDimAmount(if (tab?.position == 2) 0f else ogDim) - val view = getTabViews()[tab?.position ?: 0] - view.settings_scroll_view?.isNestedScrollingEnabled = true - view.settings_scroll_view?.requestLayout() readerActivity.appbar.visInvisIf(tab?.position != 2) } override fun onTabUnselected(tab: TabLayout.Tab?) { - val view = getTabViews()[tab?.position ?: 0] - view.settings_scroll_view?.isNestedScrollingEnabled = false - view.settings_scroll_view?.requestLayout() } override fun onTabReselected(tab: TabLayout.Tab?) { - val view = getTabViews()[tab?.position ?: 0] - view.settings_scroll_view?.isNestedScrollingEnabled = true - view.settings_scroll_view?.requestLayout() } }) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt new file mode 100644 index 0000000000..d26dd8c6e5 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt @@ -0,0 +1,37 @@ +package eu.kanade.tachiyomi.widget + +import android.content.Context +import android.util.AttributeSet +import androidx.core.widget.NestedScrollView +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.ui.library.LibraryController +import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener +import uy.kohesive.injekt.injectLazy + +abstract class BaseTabbedScrollView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + NestedScrollView(context, attrs) { + + init { + clipToPadding = false + } + internal val preferences by injectLazy() + + abstract fun initGeneralPreferences() + + override fun onFinishInflate() { + super.onFinishInflate() + setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener) + initGeneralPreferences() + } +} + +abstract class BaseLibraryDisplayView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + BaseTabbedScrollView(context, attrs) { + lateinit var controller: LibraryController +} + +abstract class BaseReaderSettingsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + BaseTabbedScrollView(context, attrs) { + lateinit var activity: ReaderActivity +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt index f71087ca51..3f840d7468 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt @@ -3,20 +3,17 @@ package eu.kanade.tachiyomi.widget import android.app.Activity import android.content.Context import android.util.AttributeSet -import android.view.Gravity import android.view.View import android.view.ViewGroup -import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.widget.NestedScrollView import androidx.viewpager.widget.ViewPager import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.tabs.TabLayout import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.setEdgeToEdge -import eu.kanade.tachiyomi.util.view.updateLayoutParams -import kotlinx.android.synthetic.main.library_list_controller.* import kotlinx.android.synthetic.main.tabbed_bottom_sheet.* @@ -48,7 +45,25 @@ abstract class TabbedBottomSheetDialog(private val activity: Activity) : super.onStart() sheetBehavior.skipCollapsed = true sheetBehavior.expand() - val height = activity.window.decorView.rootWindowInsets.systemWindowInsetTop + tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + val view = getTabViews()[tab?.position ?: 0] as? NestedScrollView + view?.isNestedScrollingEnabled = true + view?.requestLayout() + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + val view = getTabViews()[tab?.position ?: 0] as? NestedScrollView + view?.isNestedScrollingEnabled = false + view?.requestLayout() + } + + override fun onTabReselected(tab: TabLayout.Tab?) { + val view = getTabViews()[tab?.position ?: 0] as? NestedScrollView + view?.isNestedScrollingEnabled = true + view?.requestLayout() + } + }) } abstract fun getTabViews(): List diff --git a/app/src/main/res/layout/library_badges_layout.xml b/app/src/main/res/layout/library_badges_layout.xml index 683106ac96..143d6cf7ad 100644 --- a/app/src/main/res/layout/library_badges_layout.xml +++ b/app/src/main/res/layout/library_badges_layout.xml @@ -4,46 +4,53 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - - - - - - - + android:layout_height="match_parent"> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/library_category_layout.xml b/app/src/main/res/layout/library_category_layout.xml index 967555f158..3cdb34fcfe 100644 --- a/app/src/main/res/layout/library_category_layout.xml +++ b/app/src/main/res/layout/library_category_layout.xml @@ -4,35 +4,42 @@ android:layout_height="match_parent" android:orientation="vertical"> - + android:layout_height="match_parent"> - + - + - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/library_display_layout.xml b/app/src/main/res/layout/library_display_layout.xml index 3d30e71497..6ac64debad 100644 --- a/app/src/main/res/layout/library_display_layout.xml +++ b/app/src/main/res/layout/library_display_layout.xml @@ -4,84 +4,90 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - - - - - - + android:layout_height="match_parent"> - - - + android:orientation="vertical" + android:paddingStart="12dp" + android:paddingEnd="12dp"> - + + + + + + + + + - android:text="@string/small" /> + - + + + + + + + + + - - - - - - - - + android:layout_marginEnd="12dp" + android:text="@string/uniform_covers" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/reader_color_filter.xml b/app/src/main/res/layout/reader_color_filter.xml index 8356768432..6931a7fe2f 100644 --- a/app/src/main/res/layout/reader_color_filter.xml +++ b/app/src/main/res/layout/reader_color_filter.xml @@ -6,240 +6,233 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bottom_sheet_rounded_background" - android:forceDarkAllowed="false"> + android:clipToPadding="false"> - + android:layout_height="wrap_content" + android:paddingStart="@dimen/material_component_dialogs_padding_around_content_area" + android:paddingTop="0dp" + android:paddingEnd="@dimen/material_component_dialogs_padding_around_content_area"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + app:title="@string/color_filter_blend_mode" + android:entries="@array/color_filter_modes" + app:layout_constraintTop_toBottomOf="@id/seekbar_color_filter_alpha" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="@id/spinner_end" /> - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/reader_general_layout.xml b/app/src/main/res/layout/reader_general_layout.xml index 1e881e505e..98060079c7 100644 --- a/app/src/main/res/layout/reader_general_layout.xml +++ b/app/src/main/res/layout/reader_general_layout.xml @@ -5,82 +5,76 @@ android:id="@+id/filter_bottom_sheet" android:layout_width="match_parent" android:layout_height="wrap_content" + android:clipToPadding="false" android:background="@drawable/bottom_sheet_rounded_background" android:forceDarkAllowed="false"> - + android:orientation="vertical" + android:paddingStart="@dimen/material_component_dialogs_padding_around_content_area" + android:paddingTop="0dp" + android:paddingEnd="@dimen/material_component_dialogs_padding_around_content_area"> - + android:layout_marginTop="4dp" + app:title="@string/viewer_for_this_series" + android:entries="@array/viewers_selector" /> - + - + - + - + - + - - - - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/reader_paged_layout.xml b/app/src/main/res/layout/reader_paged_layout.xml index 3ff7e29e98..6e668d88b3 100644 --- a/app/src/main/res/layout/reader_paged_layout.xml +++ b/app/src/main/res/layout/reader_paged_layout.xml @@ -6,99 +6,92 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bottom_sheet_rounded_background" - android:forceDarkAllowed="false"> + android:clipToPadding="false"> - + android:layout_height="wrap_content" + android:paddingStart="@dimen/material_component_dialogs_padding_around_content_area" + android:orientation="vertical" + android:paddingTop="0dp" + android:paddingEnd="@dimen/material_component_dialogs_padding_around_content_area"> - + android:layout_marginTop="4dp" + app:title="@string/scale_type" + android:entries="@array/image_scale_type" /> - - - + - + - + - + - + - + - + - + - + - - + \ No newline at end of file