mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 05:47:57 +01:00 
			
		
		
		
	Refactor BaseBottomSheetDialog to set maxWidth with newer API
This commit is contained in:
		| @@ -4,6 +4,7 @@ import android.app.Activity | ||||
| import android.content.Context | ||||
| import android.util.AttributeSet | ||||
| import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import com.google.android.material.bottomsheet.BottomSheetBehavior | ||||
| import eu.davidea.flexibleadapter.FlexibleAdapter | ||||
| @@ -14,23 +15,20 @@ import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog | ||||
|  | ||||
| class SourceFilterSheet( | ||||
|     activity: Activity, | ||||
|     onFilterClicked: () -> Unit, | ||||
|     onResetClicked: () -> Unit | ||||
|     private val onFilterClicked: () -> Unit, | ||||
|     private val onResetClicked: () -> Unit | ||||
| ) : BaseBottomSheetDialog(activity) { | ||||
|  | ||||
|     private var filterNavView: FilterNavigationView = FilterNavigationView(activity) | ||||
|     private val sheetBehavior: BottomSheetBehavior<*> | ||||
|  | ||||
|     init { | ||||
|     override fun createView(inflater: LayoutInflater): View { | ||||
|         filterNavView.onFilterClicked = { | ||||
|             onFilterClicked() | ||||
|             this.dismiss() | ||||
|         } | ||||
|         filterNavView.onResetClicked = onResetClicked | ||||
|  | ||||
|         setContentView(filterNavView) | ||||
|  | ||||
|         sheetBehavior = BottomSheetBehavior.from(filterNavView.parent as ViewGroup) | ||||
|         return filterNavView | ||||
|     } | ||||
|  | ||||
|     override fun show() { | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package eu.kanade.tachiyomi.ui.manga.chapter | ||||
|  | ||||
| import android.content.Context | ||||
| import android.os.Bundle | ||||
| import android.util.AttributeSet | ||||
| import android.view.View | ||||
| import androidx.core.view.isVisible | ||||
| @@ -16,21 +17,18 @@ import eu.kanade.tachiyomi.widget.sheet.TabbedBottomSheetDialog | ||||
| class ChaptersSettingsSheet( | ||||
|     private val router: Router, | ||||
|     private val presenter: MangaPresenter, | ||||
|     onGroupClickListener: (ExtendedNavigationView.Group) -> Unit | ||||
|     private val onGroupClickListener: (ExtendedNavigationView.Group) -> Unit | ||||
| ) : TabbedBottomSheetDialog(router.activity!!) { | ||||
|  | ||||
|     val filters: Filter | ||||
|     private val sort: Sort | ||||
|     private val display: Display | ||||
|     val filters = Filter(router.activity!!) | ||||
|     private val sort = Sort(router.activity!!) | ||||
|     private val display = Display(router.activity!!) | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|  | ||||
|     init { | ||||
|         filters = Filter(router.activity!!) | ||||
|         filters.onGroupClicked = onGroupClickListener | ||||
|  | ||||
|         sort = Sort(router.activity!!) | ||||
|         sort.onGroupClicked = onGroupClickListener | ||||
|  | ||||
|         display = Display(router.activity!!) | ||||
|         display.onGroupClicked = onGroupClickListener | ||||
|  | ||||
|         binding.menu.isVisible = true | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| package eu.kanade.tachiyomi.ui.manga.track | ||||
|  | ||||
| import android.os.Bundle | ||||
| import android.view.ViewGroup | ||||
| import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import androidx.recyclerview.widget.LinearLayoutManager | ||||
| import com.google.android.material.bottomsheet.BottomSheetBehavior | ||||
| import eu.kanade.tachiyomi.data.database.models.Manga | ||||
| @@ -23,22 +24,20 @@ class TrackSheet( | ||||
|  | ||||
|     private lateinit var binding: TrackControllerBinding | ||||
|  | ||||
|     private lateinit var sheetBehavior: BottomSheetBehavior<*> | ||||
|  | ||||
|     private lateinit var adapter: TrackAdapter | ||||
|  | ||||
|     override fun createView(inflater: LayoutInflater): View { | ||||
|         binding = TrackControllerBinding.inflate(layoutInflater) | ||||
|         return binding.root | ||||
|     } | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|  | ||||
|         binding = TrackControllerBinding.inflate(layoutInflater) | ||||
|         setContentView(binding.root) | ||||
|  | ||||
|         adapter = TrackAdapter(this) | ||||
|         binding.trackRecycler.layoutManager = LinearLayoutManager(context) | ||||
|         binding.trackRecycler.adapter = adapter | ||||
|  | ||||
|         sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup) | ||||
|  | ||||
|         adapter.items = controller.presenter.trackList | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| package eu.kanade.tachiyomi.ui.reader | ||||
|  | ||||
| import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import com.afollestad.materialdialogs.MaterialDialog | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.databinding.ReaderPageSheetBinding | ||||
| @@ -15,14 +17,16 @@ class ReaderPageSheet( | ||||
|     private val page: ReaderPage | ||||
| ) : BaseBottomSheetDialog(activity) { | ||||
|  | ||||
|     private val binding = ReaderPageSheetBinding.inflate(activity.layoutInflater, null, false) | ||||
|     private lateinit var binding: ReaderPageSheetBinding | ||||
|  | ||||
|     init { | ||||
|         setContentView(binding.root) | ||||
|     override fun createView(inflater: LayoutInflater): View { | ||||
|         binding = ReaderPageSheetBinding.inflate(activity.layoutInflater, null, false) | ||||
|  | ||||
|         binding.setAsCoverLayout.setOnClickListener { setAsCover() } | ||||
|         binding.shareLayout.setOnClickListener { share() } | ||||
|         binding.saveLayout.setOnClickListener { save() } | ||||
|  | ||||
|         return binding.root | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| package eu.kanade.tachiyomi.ui.reader.setting | ||||
|  | ||||
| import android.view.ViewGroup | ||||
| import com.google.android.material.bottomsheet.BottomSheetBehavior | ||||
| import android.os.Bundle | ||||
| import com.google.android.material.tabs.TabLayout | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.ui.reader.ReaderActivity | ||||
| @@ -10,20 +9,21 @@ import eu.kanade.tachiyomi.widget.sheet.TabbedBottomSheetDialog | ||||
|  | ||||
| class ReaderSettingsSheet( | ||||
|     private val activity: ReaderActivity, | ||||
|     showColorFilterSettings: Boolean = false, | ||||
|     private val showColorFilterSettings: Boolean = false, | ||||
| ) : TabbedBottomSheetDialog(activity) { | ||||
|  | ||||
|     private val readingModeSettings = ReaderReadingModeSettings(activity) | ||||
|     private val generalSettings = ReaderGeneralSettings(activity) | ||||
|     private val colorFilterSettings = ReaderColorFilterSettings(activity) | ||||
|  | ||||
|     private val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|  | ||||
|     init { | ||||
|         val sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup) | ||||
|         sheetBehavior.isFitToContents = false | ||||
|         sheetBehavior.halfExpandedRatio = 0.25f | ||||
|  | ||||
|         val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f | ||||
|  | ||||
|         val filterTabIndex = getTabViews().indexOf(colorFilterSettings) | ||||
|         binding.tabs.addOnTabSelectedListener(object : SimpleTabSelectedListener() { | ||||
|             override fun onTabSelected(tab: TabLayout.Tab?) { | ||||
|   | ||||
| @@ -2,17 +2,31 @@ package eu.kanade.tachiyomi.widget.sheet | ||||
|  | ||||
| import android.content.Context | ||||
| import android.os.Bundle | ||||
| import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import com.google.android.material.bottomsheet.BottomSheetBehavior | ||||
| import com.google.android.material.bottomsheet.BottomSheetDialog | ||||
| import eu.kanade.tachiyomi.R | ||||
|  | ||||
| open class BaseBottomSheetDialog(context: Context) : BottomSheetDialog(context) { | ||||
| abstract class BaseBottomSheetDialog(context: Context) : BottomSheetDialog(context) { | ||||
|  | ||||
|     internal lateinit var sheetBehavior: BottomSheetBehavior<*> | ||||
|  | ||||
|     abstract fun createView(inflater: LayoutInflater): View | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|  | ||||
|         val rootView = createView(layoutInflater) | ||||
|         setContentView(rootView) | ||||
|  | ||||
|         sheetBehavior = BottomSheetBehavior.from(rootView.parent as ViewGroup) | ||||
|  | ||||
|         // Enforce max width for tablets | ||||
|         val width = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_width) | ||||
|         if (width > 0) { | ||||
|             window?.setLayout(width, ViewGroup.LayoutParams.MATCH_PARENT) | ||||
|             sheetBehavior.maxWidth = width | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| 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 | ||||
| @@ -8,15 +9,17 @@ import eu.kanade.tachiyomi.widget.ViewPagerAdapter | ||||
|  | ||||
| abstract class TabbedBottomSheetDialog(private val activity: Activity) : BaseBottomSheetDialog(activity) { | ||||
|  | ||||
|     val binding = CommonTabbedSheetBinding.inflate(activity.layoutInflater) | ||||
|     lateinit var binding: CommonTabbedSheetBinding | ||||
|  | ||||
|     override fun createView(inflater: LayoutInflater): View { | ||||
|         binding = CommonTabbedSheetBinding.inflate(activity.layoutInflater) | ||||
|  | ||||
|     init { | ||||
|         val adapter = LibrarySettingsSheetAdapter() | ||||
|         binding.pager.offscreenPageLimit = 2 | ||||
|         binding.pager.adapter = adapter | ||||
|         binding.tabs.setupWithViewPager(binding.pager) | ||||
|  | ||||
|         setContentView(binding.root) | ||||
|         return binding.root | ||||
|     } | ||||
|  | ||||
|     abstract fun getTabViews(): List<View> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user