From 90a65433342f374f32da5a432fbb8bba29beb780 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 22 Mar 2021 22:10:40 -0400 Subject: [PATCH] Separated library display options in *tabs* To all my fellow tab-hating fans: I'm so sorry. Words cannot express the disappointment in myself. I shall be posting a public YouTube apology video soon. --- .../ui/library/DisplayBottomSheet.kt | 158 ----------- .../tachiyomi/ui/library/LibraryController.kt | 5 +- .../ui/library/display/LibraryBadgesView.kt | 22 ++ .../ui/library/display/LibraryDisplayView.kt | 21 ++ .../ui/library/display/LibraryOtherView.kt | 24 ++ .../library/display/LibraryPreferenceView.kt | 66 +++++ .../display/TabbedLibraryDisplaySheet.kt | 50 ++++ .../ui/library/filter/FilterBottomSheet.kt | 21 +- .../tachiyomi/widget/TabbedBottomSheet.kt | 89 +++++++ app/src/main/res/color/tabs_selector.xml | 11 + .../res/color/tabs_selector_background.xml | 10 + app/src/main/res/drawable/tab_indicator.xml | 7 + .../main/res/layout/display_bottom_sheet.xml | 247 ------------------ .../main/res/layout/filter_bottom_sheet.xml | 4 +- .../main/res/layout/library_badges_layout.xml | 49 ++++ .../res/layout/library_display_layout.xml | 87 ++++++ .../main/res/layout/library_other_layout.xml | 38 +++ .../main/res/layout/tabbed_bottom_sheet.xml | 53 ++++ app/src/main/res/values/strings.xml | 7 +- app/src/main/res/values/styles.xml | 21 ++ 20 files changed, 571 insertions(+), 419 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryOtherView.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryPreferenceView.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt create mode 100644 app/src/main/res/color/tabs_selector.xml create mode 100644 app/src/main/res/color/tabs_selector_background.xml create mode 100644 app/src/main/res/drawable/tab_indicator.xml delete mode 100644 app/src/main/res/layout/display_bottom_sheet.xml create mode 100644 app/src/main/res/layout/library_badges_layout.xml create mode 100644 app/src/main/res/layout/library_display_layout.xml create mode 100644 app/src/main/res/layout/library_other_layout.xml create mode 100644 app/src/main/res/layout/tabbed_bottom_sheet.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt deleted file mode 100644 index 0fdf79077f..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt +++ /dev/null @@ -1,158 +0,0 @@ -package eu.kanade.tachiyomi.ui.library - -import android.os.Bundle -import android.view.View -import android.view.ViewGroup -import android.widget.CompoundButton -import android.widget.RadioButton -import android.widget.RadioGroup -import com.f2prateek.rx.preferences.Preference -import com.google.android.material.bottomsheet.BottomSheetBehavior -import com.google.android.material.bottomsheet.BottomSheetDialog -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.ui.setting.SettingsLibraryController -import eu.kanade.tachiyomi.util.system.dpToPx -import eu.kanade.tachiyomi.util.view.expand -import eu.kanade.tachiyomi.util.view.isCollapsed -import eu.kanade.tachiyomi.util.view.setBottomEdge -import eu.kanade.tachiyomi.util.view.setEdgeToEdge -import eu.kanade.tachiyomi.util.view.visibleIf -import eu.kanade.tachiyomi.util.view.withFadeTransaction -import kotlinx.android.synthetic.main.display_bottom_sheet.* -import uy.kohesive.injekt.injectLazy - -class DisplayBottomSheet(private val controller: LibraryController) : BottomSheetDialog -(controller.activity!!, R.style.BottomSheetDialogTheme) { - - val activity = controller.activity!! - - /** - * Preferences helper. - */ - private val preferences by injectLazy() - - private var sheetBehavior: BottomSheetBehavior<*> - - init { - // Use activity theme for this layout - val view = activity.layoutInflater.inflate(R.layout.display_bottom_sheet, null) - setContentView(view) - - sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) - setEdgeToEdge(activity, view) - val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom - sheetBehavior.peekHeight = 220.dpToPx + height - - sheetBehavior.addBottomSheetCallback( - object : BottomSheetBehavior.BottomSheetCallback() { - override fun onSlide(bottomSheet: View, progress: Float) { } - - override fun onStateChanged(p0: View, state: Int) { - if (state == BottomSheetBehavior.STATE_EXPANDED) { - sheetBehavior.skipCollapsed = true - } - } - } - ) - } - - override fun onStart() { - super.onStart() - sheetBehavior.skipCollapsed = true - sheetBehavior.expand() - } - - /** - * Called when the sheet is created. It initializes the listeners and values of the preferences. - */ - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - initGeneralPreferences() - setBottomEdge(display_layout, activity) - close_button.setOnClickListener { dismiss() } - settings_scroll_view.viewTreeObserver.addOnGlobalLayoutListener { - val isScrollable = - settings_scroll_view!!.height < display_layout.height + - settings_scroll_view.paddingTop + settings_scroll_view.paddingBottom - close_button.visibleIf(isScrollable) - } - } - - private fun initGeneralPreferences() { - display_group.bindToPreference(preferences.libraryLayout()) { - controller.reattachAdapter() - if (sheetBehavior.isCollapsed()) dismiss() - } - show_all.bindToPreference(preferences.showAllCategories()) { - controller.presenter.getLibrary() - category_show.isEnabled = it - } - category_show.isEnabled = show_all.isChecked - category_show.bindToPreference(preferences.showCategoryInTitle()) { - controller.showMiniBar() - } - hide_hopper.bindToPreference(preferences.hideHopper()) { - controller.hideHopper(it) - } - uniform_grid.bindToPreference(preferences.uniformGrid()) { - controller.reattachAdapter() - } - grid_size_toggle_group.bindToPreference(preferences.gridSize()) { - controller.reattachAdapter() - } - download_badge.bindToPreference(preferences.downloadBadge()) { - controller.presenter.requestDownloadBadgesUpdate() - } - unread_badge_group.bindToPreference(preferences.unreadBadgeType()) { - controller.presenter.requestUnreadBadgesUpdate() - } - hide_reading.bindToPreference(preferences.hideStartReadingButton()) { - controller.reattachAdapter() - } - hide_filters.bindToPreference(preferences.hideFiltersAtStart()) - more_settings.setOnClickListener { - controller.router.pushController(SettingsLibraryController().withFadeTransaction()) - dismiss() - } - } - - /** - * Binds a checkbox or switch view with a boolean preference. - */ - private fun CompoundButton.bindToPreference(pref: Preference, block: (() -> Unit)? = null) { - isChecked = pref.getOrDefault() - setOnCheckedChangeListener { _, isChecked -> - pref.set(isChecked) - block?.invoke() - } - } - - /** - * Binds a checkbox or switch view with a boolean preference. - */ - private fun CompoundButton.bindToPreference( - pref: com.tfcporciuncula.flow - .Preference, - block: ((Boolean) -> Unit)? = null - ) { - isChecked = pref.get() - setOnCheckedChangeListener { _, isChecked -> - pref.set(isChecked) - block?.invoke(isChecked) - } - } - - /** - * Binds a radio group with a int preference. - */ - private fun RadioGroup.bindToPreference(pref: Preference, block: (() -> Unit)? = null) { - (getChildAt(pref.getOrDefault()) as RadioButton).isChecked = true - setOnCheckedChangeListener { _, checkedId -> - val index = indexOfChild(findViewById(checkedId)) - pref.set(index) - block?.invoke() - } - } -} 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 22669d4b6a..ad2f8671f2 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 @@ -60,6 +60,7 @@ import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_STATUS import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_TAG import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_TRACK_STATUS import eu.kanade.tachiyomi.ui.library.LibraryGroup.UNGROUPED +import eu.kanade.tachiyomi.ui.library.display.TabbedLibraryDisplaySheet import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet import eu.kanade.tachiyomi.ui.main.BottomSheetController import eu.kanade.tachiyomi.ui.main.MainActivity @@ -485,7 +486,7 @@ class LibraryController( FilterBottomSheet.ACTION_REFRESH -> onRefresh() FilterBottomSheet.ACTION_FILTER -> onFilterChanged() FilterBottomSheet.ACTION_HIDE_FILTER_TIP -> showFilterTip() - FilterBottomSheet.ACTION_DISPLAY -> DisplayBottomSheet(this).show() + FilterBottomSheet.ACTION_DISPLAY -> TabbedLibraryDisplaySheet(this).show() FilterBottomSheet.ACTION_EXPAND_COLLAPSE_ALL -> presenter.toggleAllCategoryVisibility() FilterBottomSheet.ACTION_GROUP_BY -> { val groupItems = mutableListOf(BY_DEFAULT, BY_TAG, BY_SOURCE, BY_STATUS) @@ -1287,7 +1288,7 @@ class LibraryController( when { filter_bottom_sheet.sheetBehavior.isHidden() -> filter_bottom_sheet.sheetBehavior?.collapse() !filter_bottom_sheet.sheetBehavior.isExpanded() -> filter_bottom_sheet.sheetBehavior?.expand() - else -> DisplayBottomSheet(this).show() + else -> TabbedLibraryDisplaySheet(this).show() } } 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 new file mode 100644 index 0000000000..c5ef27e6da --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt @@ -0,0 +1,22 @@ +package eu.kanade.tachiyomi.ui.library.display + +import android.content.Context +import android.util.AttributeSet +import eu.kanade.tachiyomi.ui.library.LibraryController +import kotlinx.android.synthetic.main.library_badges_layout.view.* + +class LibraryBadgesView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + LibraryPreferenceView(context, attrs) { + + override fun initGeneralPreferences() { + unread_badge_group.bindToPreference(preferences.unreadBadgeType()) { + controller.presenter.requestUnreadBadgesUpdate() + } + hide_reading.bindToPreference(preferences.hideStartReadingButton()) { + controller.reattachAdapter() + } + download_badge.bindToPreference(preferences.downloadBadge()) { + controller.presenter.requestDownloadBadgesUpdate() + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..45e34b96a0 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt @@ -0,0 +1,21 @@ +package eu.kanade.tachiyomi.ui.library.display + +import android.content.Context +import android.util.AttributeSet +import kotlinx.android.synthetic.main.library_display_layout.view.* + +class LibraryDisplayView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + LibraryPreferenceView(context, attrs) { + + override fun initGeneralPreferences() { + display_group.bindToPreference(preferences.libraryLayout()) { + controller.reattachAdapter() + } + uniform_grid.bindToPreference(preferences.uniformGrid()) { + controller.reattachAdapter() + } + grid_size_toggle_group.bindToPreference(preferences.gridSize()) { + controller.reattachAdapter() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryOtherView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryOtherView.kt new file mode 100644 index 0000000000..42cad1da60 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryOtherView.kt @@ -0,0 +1,24 @@ +package eu.kanade.tachiyomi.ui.library.display + +import android.content.Context +import android.util.AttributeSet +import kotlinx.android.synthetic.main.library_other_layout.view.* + +class LibraryOtherView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + LibraryPreferenceView(context, attrs) { + + override fun initGeneralPreferences() { + show_all.bindToPreference(preferences.showAllCategories()) { + controller.presenter.getLibrary() + category_show.isEnabled = it + } + category_show.isEnabled = show_all.isChecked + category_show.bindToPreference(preferences.showCategoryInTitle()) { + controller.showMiniBar() + } + hide_hopper.bindToPreference(preferences.hideHopper()) { + controller.hideHopper(it) + } + hide_filters.bindToPreference(preferences.hideFiltersAtStart()) + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..3ca80daaa9 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryPreferenceView.kt @@ -0,0 +1,66 @@ +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() + } + + /** + * Binds a checkbox or switch view with a boolean preference. + */ + internal fun CompoundButton.bindToPreference(pref: Preference, block: (() -> Unit)? = null) { + isChecked = pref.getOrDefault() + setOnCheckedChangeListener { _, isChecked -> + pref.set(isChecked) + block?.invoke() + } + } + + /** + * Binds a checkbox or switch view with a boolean preference. + */ + internal fun CompoundButton.bindToPreference( + pref: com.tfcporciuncula.flow + .Preference, + block: ((Boolean) -> Unit)? = null + ) { + isChecked = pref.get() + setOnCheckedChangeListener { _, isChecked -> + pref.set(isChecked) + block?.invoke(isChecked) + } + } + + /** + * Binds a radio group with a int preference. + */ + internal fun RadioGroup.bindToPreference(pref: Preference, block: (() -> Unit)? = null) { + (getChildAt(pref.getOrDefault()) as RadioButton).isChecked = true + setOnCheckedChangeListener { _, checkedId -> + val index = indexOfChild(findViewById(checkedId)) + pref.set(index) + block?.invoke() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt new file mode 100644 index 0000000000..06dbd69c7a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt @@ -0,0 +1,50 @@ +package eu.kanade.tachiyomi.ui.library.display + +import android.view.View +import android.view.View.inflate +import androidx.core.content.ContextCompat +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.library.LibraryController +import eu.kanade.tachiyomi.ui.setting.SettingsLibraryController +import eu.kanade.tachiyomi.util.view.visible +import eu.kanade.tachiyomi.util.view.withFadeTransaction +import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog +import kotlinx.android.synthetic.main.tabbed_bottom_sheet.* + +open class TabbedLibraryDisplaySheet(controller: LibraryController): + TabbedBottomSheetDialog(controller) { + + private val displayView: LibraryDisplayView = inflate(controller.activity!!, R.layout.library_display_layout, null) as LibraryDisplayView + private val badgesView: LibraryBadgesView = inflate(controller.activity!!, R.layout.library_badges_layout, null) as LibraryBadgesView + private val otherView: LibraryOtherView = inflate(controller.activity!!, R.layout.library_other_layout, null) as LibraryOtherView + + init { + displayView.controller = controller + badgesView.controller = controller + otherView.controller = controller + menu.visible() + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + menu.tooltipText = context.getString(R.string.more_library_settings) + } + menu.setImageDrawable(ContextCompat.getDrawable( + context, + R.drawable.ic_settings_24dp + )) + menu.setOnClickListener { + controller.router.pushController(SettingsLibraryController().withFadeTransaction()) + dismiss() + } + } + + override fun getTabViews(): List = listOf( + displayView, + badgesView, + otherView + ) + + override fun getTabTitles(): List = listOf( + R.string.display, + R.string.badges, + R.string.other + ) +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index fc16e92fec..4838c6c31e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -5,6 +5,7 @@ import android.content.res.Configuration import android.os.Parcelable import android.util.AttributeSet import android.view.View +import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout import androidx.recyclerview.widget.LinearLayoutManager @@ -21,7 +22,10 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.ui.library.LibraryController import eu.kanade.tachiyomi.ui.library.LibraryGroup +import eu.kanade.tachiyomi.ui.library.display.LibraryBadgesView +import eu.kanade.tachiyomi.ui.library.display.LibraryDisplayView import eu.kanade.tachiyomi.ui.main.MainActivity +import eu.kanade.tachiyomi.ui.setting.SettingsLibraryController import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.collapse @@ -32,10 +36,13 @@ import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isHidden import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.visibleIf +import eu.kanade.tachiyomi.util.view.withFadeTransaction +import eu.kanade.tachiyomi.widget.ViewPagerAdapter import kotlinx.android.synthetic.main.filter_bottom_sheet.view.* import kotlinx.android.synthetic.main.library_grid_recycler.* import kotlinx.android.synthetic.main.library_list_controller.* import kotlinx.android.synthetic.main.main_activity.* +import kotlinx.android.synthetic.main.tabbed_bottom_sheet.* import kotlinx.android.synthetic.main.track_item.* import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers @@ -95,7 +102,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } var onGroupClicked: (Int) -> Unit = { _ -> } - var pager: View? = null + var libraryRecyler: View? = null var controller: LibraryController? = null var bottomBarHeight = 0 @@ -105,8 +112,8 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri sheetBehavior = BottomSheetBehavior.from(this) sheetBehavior?.isHideable = true this.controller = controller - pager = controller.recycler - pager?.post { + libraryRecyler = controller.recycler + libraryRecyler?.post { bottomBarHeight = (this@FilterBottomSheet.controller?.activity as? MainActivity)?.bottom_nav?.height ?: 0 } val shadow2: View = controller.shadow2 @@ -193,7 +200,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri val shadow = controller?.shadow ?: return if (state == BottomSheetBehavior.STATE_COLLAPSED) { shadow.alpha = 1f - pager?.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0 + 10.dpToPx + bottomBarHeight) + libraryRecyler?.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0 + 10.dpToPx + bottomBarHeight) } if (state == BottomSheetBehavior.STATE_EXPANDED) { pill.alpha = 0f @@ -202,7 +209,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri onGroupClicked(ACTION_HIDE_FILTER_TIP) reSortViews() shadow.alpha = 0f - pager?.updatePaddingRelative(bottom = 10.dpToPx + bottomBarHeight) + libraryRecyler?.updatePaddingRelative(bottom = 10.dpToPx + bottomBarHeight) } } @@ -220,9 +227,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri val percent = (trueProgress * 100).roundToInt() val value = (percent * (maxHeight - minHeight) / 100) + minHeight if (trueProgress >= 0) - pager?.updatePaddingRelative(bottom = value + 10.dpToPx + bottomBarHeight) + libraryRecyler?.updatePaddingRelative(bottom = value + 10.dpToPx + bottomBarHeight) else - pager?.updatePaddingRelative(bottom = (minHeight * (1 + trueProgress)).toInt() + bottomBarHeight) + libraryRecyler?.updatePaddingRelative(bottom = (minHeight * (1 + trueProgress)).toInt() + bottomBarHeight) } fun hasActiveFilters() = filterItems.any { it.isActivated } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt new file mode 100644 index 0000000000..3534055cb5 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheet.kt @@ -0,0 +1,89 @@ +package eu.kanade.tachiyomi.widget + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import android.view.ViewGroup +import androidx.viewpager.widget.ViewPager +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.base.controller.BaseController +import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.setEdgeToEdge +import kotlinx.android.synthetic.main.tabbed_bottom_sheet.* + + +abstract class TabbedBottomSheetDialog(private val controller: BaseController) : + BottomSheetDialog + (controller.activity!!, R.style.BottomSheetDialogTheme) { + + private var sheetBehavior: BottomSheetBehavior<*> + + val activity = controller.activity!! + + init { + // Use activity theme for this layout + val view = activity.layoutInflater.inflate(R.layout.tabbed_bottom_sheet, null) + + setContentView(view) + sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) + setEdgeToEdge(activity, view) + val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom + + val adapter = TabbedSheetAdapter() + pager.offscreenPageLimit = 2 + pager.adapter = adapter + tabs.setupWithViewPager(pager) + } + + override fun onStart() { + super.onStart() + sheetBehavior.skipCollapsed = true + sheetBehavior.expand() + } + + abstract fun getTabViews(): List + + abstract fun getTabTitles(): List + + private inner class TabbedSheetAdapter : ViewPagerAdapter() { + + override fun createView(container: ViewGroup, position: Int): View { + return getTabViews()[position] + } + + override fun getCount(): Int { + return getTabViews().size + } + + override fun getPageTitle(position: Int): CharSequence { + return activity.resources!!.getString(getTabTitles()[position]) + } + } +} + +class MeasuredViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null): ViewPager(context, attrs) { + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + var heightMeasureSpec = heightMeasureSpec + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + var height = 0 + val childWidthSpec = MeasureSpec.makeMeasureSpec( + Math.max( + 0, MeasureSpec.getSize(widthMeasureSpec) - + paddingLeft - paddingRight + ), + MeasureSpec.getMode(widthMeasureSpec) + ) + for (i in 0 until childCount) { + val child = getChildAt(i) + child.measure(childWidthSpec, MeasureSpec.UNSPECIFIED) + val h = child.measuredHeight + if (h > height) height = h + } + if (height != 0) { + heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) + (rootWindowInsets?.systemWindowInsetBottom ?: 0) + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + } +} \ No newline at end of file diff --git a/app/src/main/res/color/tabs_selector.xml b/app/src/main/res/color/tabs_selector.xml new file mode 100644 index 0000000000..34782dcb31 --- /dev/null +++ b/app/src/main/res/color/tabs_selector.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/main/res/color/tabs_selector_background.xml b/app/src/main/res/color/tabs_selector_background.xml new file mode 100644 index 0000000000..8d9eca6f09 --- /dev/null +++ b/app/src/main/res/color/tabs_selector_background.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/app/src/main/res/drawable/tab_indicator.xml b/app/src/main/res/drawable/tab_indicator.xml new file mode 100644 index 0000000000..980493bc55 --- /dev/null +++ b/app/src/main/res/drawable/tab_indicator.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/app/src/main/res/layout/display_bottom_sheet.xml b/app/src/main/res/layout/display_bottom_sheet.xml deleted file mode 100644 index 98672f6978..0000000000 --- a/app/src/main/res/layout/display_bottom_sheet.xml +++ /dev/null @@ -1,247 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/filter_bottom_sheet.xml b/app/src/main/res/layout/filter_bottom_sheet.xml index 8cf4d6e900..cf4ca4d151 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -58,7 +58,7 @@ android:focusable="true" android:padding="3dp" android:src="@drawable/ic_close_24dp" - android:tint="@color/gray_button" /> + app:tint="@color/gray_button" /> @@ -132,7 +132,7 @@ android:alpha="0.25" android:contentDescription="@string/drag_handle" android:src="@drawable/draggable_pill" - android:tint="?android:attr/textColorPrimary" + app:tint="?android:attr/textColorPrimary" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/library_badges_layout.xml b/app/src/main/res/layout/library_badges_layout.xml new file mode 100644 index 0000000000..683106ac96 --- /dev/null +++ b/app/src/main/res/layout/library_badges_layout.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + \ 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 new file mode 100644 index 0000000000..3d30e71497 --- /dev/null +++ b/app/src/main/res/layout/library_display_layout.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/library_other_layout.xml b/app/src/main/res/layout/library_other_layout.xml new file mode 100644 index 0000000000..e134292b33 --- /dev/null +++ b/app/src/main/res/layout/library_other_layout.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/tabbed_bottom_sheet.xml b/app/src/main/res/layout/tabbed_bottom_sheet.xml new file mode 100644 index 0000000000..2faa236481 --- /dev/null +++ b/app/src/main/res/layout/tabbed_bottom_sheet.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 51561191e1..bf14f4970c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -148,6 +148,7 @@ Download badges Hide start reading button Unread badges + Badges Uniform covers XS S @@ -155,9 +156,9 @@ L XL Grid options - Hide badges - Show badges - Show count + Hide unread badges + Show unread badges + Show unread count Tap the Library icon to show filters Display as Hide category hopper diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 2da8b8e203..dcabac4e93 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -104,6 +104,11 @@ ?android:attr/textColorHint + + @@ -199,6 +204,22 @@ ?android:attr/textColorHint + + + + +