Remove abstract TabeedBottomSheetDialog class

This commit is contained in:
arkon 2023-04-19 22:43:36 -04:00
parent 2c6e025063
commit add228407f
2 changed files with 39 additions and 59 deletions

View File

@ -2,20 +2,27 @@ package eu.kanade.tachiyomi.ui.reader.setting
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.CommonTabbedSheetBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
import eu.kanade.tachiyomi.widget.listener.SimpleTabSelectedListener import eu.kanade.tachiyomi.widget.listener.SimpleTabSelectedListener
import eu.kanade.tachiyomi.widget.sheet.TabbedBottomSheetDialog import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog
class ReaderSettingsSheet( class ReaderSettingsSheet(
private val activity: ReaderActivity, private val activity: ReaderActivity,
private val showColorFilterSettings: Boolean = false, private val showColorFilterSettings: Boolean = false,
) : TabbedBottomSheetDialog(activity) { ) : BaseBottomSheetDialog(activity) {
private val readingModeSettings = ReaderReadingModeSettings(activity) private val tabs = listOf(
private val generalSettings = ReaderGeneralSettings(activity) ReaderReadingModeSettings(activity) to R.string.pref_category_reading_mode,
private val colorFilterSettings = ReaderColorFilterSettings(activity) ReaderGeneralSettings(activity) to R.string.pref_category_general,
ReaderColorFilterSettings(activity) to R.string.custom_filter,
)
private val backgroundDimAnimator by lazy { private val backgroundDimAnimator by lazy {
val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f
@ -27,13 +34,26 @@ class ReaderSettingsSheet(
} }
} }
private lateinit var binding: CommonTabbedSheetBinding
override fun createView(inflater: LayoutInflater): View {
binding = CommonTabbedSheetBinding.inflate(activity.layoutInflater)
val adapter = Adapter()
binding.pager.offscreenPageLimit = 2
binding.pager.adapter = adapter
binding.tabs.setupWithViewPager(binding.pager)
return binding.root
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
behavior.isFitToContents = false behavior.isFitToContents = false
behavior.halfExpandedRatio = 0.25f behavior.halfExpandedRatio = 0.25f
val filterTabIndex = getTabViews().indexOf(colorFilterSettings) val filterTabIndex = tabs.indexOfFirst { it.first is ReaderColorFilterSettings }
binding.tabs.addOnTabSelectedListener( binding.tabs.addOnTabSelectedListener(
object : SimpleTabSelectedListener() { object : SimpleTabSelectedListener() {
override fun onTabSelected(tab: TabLayout.Tab?) { override fun onTabSelected(tab: TabLayout.Tab?) {
@ -63,15 +83,18 @@ class ReaderSettingsSheet(
} }
} }
override fun getTabViews() = listOf( private inner class Adapter : ViewPagerAdapter() {
readingModeSettings,
generalSettings,
colorFilterSettings,
)
override fun getTabTitles() = listOf( override fun createView(container: ViewGroup, position: Int): View {
R.string.pref_category_reading_mode, return tabs[position].first
R.string.pref_category_general, }
R.string.custom_filter,
) override fun getCount(): Int {
return tabs.size
}
override fun getPageTitle(position: Int): CharSequence {
return activity.resources!!.getString(tabs[position].second)
}
}
} }

View File

@ -1,43 +0,0 @@
package eu.kanade.tachiyomi.widget.sheet
import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import eu.kanade.tachiyomi.databinding.CommonTabbedSheetBinding
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
abstract class TabbedBottomSheetDialog(private val activity: Activity) : BaseBottomSheetDialog(activity) {
lateinit var binding: CommonTabbedSheetBinding
override fun createView(inflater: LayoutInflater): View {
binding = CommonTabbedSheetBinding.inflate(activity.layoutInflater)
val adapter = LibrarySettingsSheetAdapter()
binding.pager.offscreenPageLimit = 2
binding.pager.adapter = adapter
binding.tabs.setupWithViewPager(binding.pager)
return binding.root
}
abstract fun getTabViews(): List<View>
abstract fun getTabTitles(): List<Int>
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])
}
}
}