diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 5616af920f..c93f8cce8e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -4,54 +4,43 @@ import android.app.Activity import android.content.Context import android.util.AttributeSet import android.view.View -import android.view.ViewGroup -import com.google.android.material.bottomsheet.BottomSheetDialog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.databinding.LibrarySettingsSheetBinding import eu.kanade.tachiyomi.widget.ExtendedNavigationView -import eu.kanade.tachiyomi.widget.ViewPagerAdapter +import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog import uy.kohesive.injekt.injectLazy class LibrarySettingsSheet( private val activity: Activity, - private val onGroupClickListener: (ExtendedNavigationView.Group) -> Unit -) : BottomSheetDialog(activity) { + onGroupClickListener: (ExtendedNavigationView.Group) -> Unit +) : TabbedBottomSheetDialog(activity) { - val filters = Filter(activity) - - private val tabItems = listOf( - Pair(R.string.action_filter, filters), - Pair(R.string.action_sort, Sort(activity)), - Pair(R.string.action_display, Display(activity)) - ) + val filters: Filter + private val sort: Sort + private val display: Display init { - val binding: LibrarySettingsSheetBinding = LibrarySettingsSheetBinding.inflate(activity.layoutInflater) + filters = Filter(activity) + filters.onGroupClicked = onGroupClickListener - val adapter = LibrarySettingsSheetAdapter() - binding.librarySettingsPager.adapter = adapter - binding.librarySettingsTabs.setupWithViewPager(binding.librarySettingsPager) + sort = Sort(activity) + sort.onGroupClicked = onGroupClickListener - setContentView(binding.root) + display = Display(activity) + display.onGroupClicked = onGroupClickListener } - private inner class LibrarySettingsSheetAdapter : ViewPagerAdapter() { + override fun getTabViews(): List = listOf( + filters, + sort, + display + ) - override fun createView(container: ViewGroup, position: Int): View { - val view = tabItems[position].second - view.onGroupClicked = onGroupClickListener - return view - } - - override fun getCount(): Int { - return tabItems.size - } - - override fun getPageTitle(position: Int): CharSequence { - return activity.resources!!.getString(tabItems[position].first) - } - } + override fun getTabTitles(): List = listOf( + R.string.action_filter, + R.string.action_sort, + R.string.action_display + ) /** * Filters group (unread, downloaded, ...). diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheetDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheetDialog.kt new file mode 100644 index 0000000000..cc65172c7f --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheetDialog.kt @@ -0,0 +1,39 @@ +package eu.kanade.tachiyomi.widget + +import android.app.Activity +import android.view.View +import android.view.ViewGroup +import com.google.android.material.bottomsheet.BottomSheetDialog +import eu.kanade.tachiyomi.databinding.CommonTabbedSheetBinding + +abstract class TabbedBottomSheetDialog(private val activity: Activity) : BottomSheetDialog(activity) { + + init { + val binding: CommonTabbedSheetBinding = CommonTabbedSheetBinding.inflate(activity.layoutInflater) + + val adapter = LibrarySettingsSheetAdapter() + binding.pager.adapter = adapter + binding.tabs.setupWithViewPager(binding.pager) + + setContentView(binding.root) + } + + abstract fun getTabViews(): List + + abstract fun getTabTitles(): List + + private inner class LibrarySettingsSheetAdapter : 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]) + } + } +} diff --git a/app/src/main/res/layout/library_settings_sheet.xml b/app/src/main/res/layout/common_tabbed_sheet.xml similarity index 87% rename from app/src/main/res/layout/library_settings_sheet.xml rename to app/src/main/res/layout/common_tabbed_sheet.xml index 16d83527aa..22904a7343 100644 --- a/app/src/main/res/layout/library_settings_sheet.xml +++ b/app/src/main/res/layout/common_tabbed_sheet.xml @@ -6,7 +6,7 @@ android:orientation="vertical">