mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Makes bottom sheets inherit VectorBaseBottomSheetDialogFragment
This commit is contained in:
parent
e0f327e8f6
commit
f4b5cfc71f
4 changed files with 26 additions and 47 deletions
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.core.extensions
|
||||
|
||||
import androidx.annotation.FloatRange
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import io.github.hyuwah.draggableviewlib.Utils.getScreenHeight
|
||||
|
||||
fun BottomSheetDialog.setPeekHeightAsScreenPercentage(@FloatRange(from = 0.0, to = 1.0) percentage: Float) {
|
||||
val screenHeight = getScreenHeight(context)
|
||||
behavior.setPeekHeight((screenHeight * percentage).toInt(), true)
|
||||
}
|
|
@ -25,6 +25,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
@ -39,6 +40,7 @@ import im.vector.app.core.extensions.toMvRxBundle
|
|||
import im.vector.app.core.utils.DimensionConverter
|
||||
import im.vector.app.features.analytics.AnalyticsTracker
|
||||
import im.vector.app.features.analytics.plan.MobileScreen
|
||||
import io.github.hyuwah.draggableviewlib.Utils
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
@ -165,6 +167,13 @@ abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : BottomShe
|
|||
forceExpandState()
|
||||
}
|
||||
|
||||
protected fun setPeekHeightAsScreenPercentage(@FloatRange(from = 0.0, to = 1.0) percentage: Float) {
|
||||
context?.let {
|
||||
val screenHeight = Utils.getScreenHeight(it)
|
||||
bottomSheetBehavior?.setPeekHeight((screenHeight * percentage).toInt(), true)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun forceExpandState() {
|
||||
if (showExpanded) {
|
||||
// Force the bottom sheet to be expanded
|
||||
|
|
|
@ -21,44 +21,42 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.core.extensions.setPeekHeightAsScreenPercentage
|
||||
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
|
||||
import im.vector.app.databinding.FragmentNewChatBottomSheetBinding
|
||||
import im.vector.app.features.navigation.Navigator
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class NewChatBottomSheet @Inject constructor() : BottomSheetDialogFragment() {
|
||||
class NewChatBottomSheet @Inject constructor() : VectorBaseBottomSheetDialogFragment<FragmentNewChatBottomSheetBinding>() {
|
||||
|
||||
@Inject lateinit var navigator: Navigator
|
||||
|
||||
private lateinit var binding: FragmentNewChatBottomSheetBinding
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentNewChatBottomSheetBinding {
|
||||
return FragmentNewChatBottomSheetBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentNewChatBottomSheetBinding.inflate(inflater, container, false)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
initFABs()
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun initFABs() {
|
||||
binding.startChat.setOnClickListener {
|
||||
views.startChat.debouncedClicks {
|
||||
navigator.openCreateDirectRoom(requireActivity())
|
||||
}
|
||||
|
||||
binding.createRoom.setOnClickListener {
|
||||
views.createRoom.debouncedClicks {
|
||||
navigator.openCreateRoom(requireActivity())
|
||||
}
|
||||
|
||||
binding.exploreRooms.setOnClickListener {
|
||||
views.exploreRooms.debouncedClicks {
|
||||
navigator.openRoomDirectory(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return super.onCreateDialog(savedInstanceState).apply {
|
||||
(this as BottomSheetDialog).setPeekHeightAsScreenPercentage(0.5f)
|
||||
setPeekHeightAsScreenPercentage(0.5f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,28 +21,26 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.replaceChildFragment
|
||||
import im.vector.app.core.extensions.setPeekHeightAsScreenPercentage
|
||||
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
|
||||
import im.vector.app.databinding.FragmentSpacesBottomSheetBinding
|
||||
|
||||
class SpaceListBottomSheet : BottomSheetDialogFragment() {
|
||||
class SpaceListBottomSheet : VectorBaseBottomSheetDialogFragment<FragmentSpacesBottomSheetBinding>() {
|
||||
|
||||
private lateinit var binding: FragmentSpacesBottomSheetBinding
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSpacesBottomSheetBinding {
|
||||
return FragmentSpacesBottomSheetBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentSpacesBottomSheetBinding.inflate(inflater, container, false)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
if (savedInstanceState == null) {
|
||||
replaceChildFragment(R.id.space_list, SpaceListFragment::class.java)
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return super.onCreateDialog(savedInstanceState).apply {
|
||||
(this as BottomSheetDialog).setPeekHeightAsScreenPercentage(0.75f)
|
||||
setPeekHeightAsScreenPercentage(0.75f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue