mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Refactor tabbed bottom sheet
This commit is contained in:
parent
1972cc25a9
commit
3374481912
3 changed files with 63 additions and 35 deletions
|
@ -4,54 +4,43 @@ import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.databinding.LibrarySettingsSheetBinding
|
|
||||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
|
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
|
||||||
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class LibrarySettingsSheet(
|
class LibrarySettingsSheet(
|
||||||
private val activity: Activity,
|
private val activity: Activity,
|
||||||
private val onGroupClickListener: (ExtendedNavigationView.Group) -> Unit
|
onGroupClickListener: (ExtendedNavigationView.Group) -> Unit
|
||||||
) : BottomSheetDialog(activity) {
|
) : TabbedBottomSheetDialog(activity) {
|
||||||
|
|
||||||
val filters = Filter(activity)
|
val filters: Filter
|
||||||
|
private val sort: Sort
|
||||||
private val tabItems = listOf(
|
private val display: Display
|
||||||
Pair(R.string.action_filter, filters),
|
|
||||||
Pair(R.string.action_sort, Sort(activity)),
|
|
||||||
Pair(R.string.action_display, Display(activity))
|
|
||||||
)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val binding: LibrarySettingsSheetBinding = LibrarySettingsSheetBinding.inflate(activity.layoutInflater)
|
filters = Filter(activity)
|
||||||
|
filters.onGroupClicked = onGroupClickListener
|
||||||
|
|
||||||
val adapter = LibrarySettingsSheetAdapter()
|
sort = Sort(activity)
|
||||||
binding.librarySettingsPager.adapter = adapter
|
sort.onGroupClicked = onGroupClickListener
|
||||||
binding.librarySettingsTabs.setupWithViewPager(binding.librarySettingsPager)
|
|
||||||
|
|
||||||
setContentView(binding.root)
|
display = Display(activity)
|
||||||
|
display.onGroupClicked = onGroupClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class LibrarySettingsSheetAdapter : ViewPagerAdapter() {
|
override fun getTabViews(): List<View> = listOf(
|
||||||
|
filters,
|
||||||
|
sort,
|
||||||
|
display
|
||||||
|
)
|
||||||
|
|
||||||
override fun createView(container: ViewGroup, position: Int): View {
|
override fun getTabTitles(): List<Int> = listOf(
|
||||||
val view = tabItems[position].second
|
R.string.action_filter,
|
||||||
view.onGroupClicked = onGroupClickListener
|
R.string.action_sort,
|
||||||
return view
|
R.string.action_display
|
||||||
}
|
)
|
||||||
|
|
||||||
override fun getCount(): Int {
|
|
||||||
return tabItems.size
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getPageTitle(position: Int): CharSequence {
|
|
||||||
return activity.resources!!.getString(tabItems[position].first)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters group (unread, downloaded, ...).
|
* Filters group (unread, downloaded, ...).
|
||||||
|
|
|
@ -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<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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
android:id="@+id/library_settings_tabs"
|
android:id="@+id/tabs"
|
||||||
style="@style/Theme.Widget.Tabs"
|
style="@style/Theme.Widget.Tabs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
app:tabMode="fixed" />
|
app:tabMode="fixed" />
|
||||||
|
|
||||||
<eu.kanade.tachiyomi.widget.MaxHeightViewPager
|
<eu.kanade.tachiyomi.widget.MaxHeightViewPager
|
||||||
android:id="@+id/library_settings_pager"
|
android:id="@+id/pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
Loading…
Reference in a new issue