11package org.torproject.android.ui
22
33import android.annotation.SuppressLint
4+ import android.app.Activity
45import android.app.Dialog
56import android.graphics.Color
67import android.os.Bundle
@@ -22,37 +23,37 @@ bottom sheets to come
2223 */
2324open class OrbotBottomSheetDialogFragment : BottomSheetDialogFragment () {
2425 override fun onCreateDialog (savedInstanceState : Bundle ? ): Dialog {
25- val dialog = BottomSheetDialog (requireActivity(), theme)
26- dialog.setOnShowListener {
27- val bottomSheet = dialog.findViewById<View >(com.google.android.material.R .id.design_bottom_sheet) as ? FrameLayout
28- bottomSheet?.let {
29- it.setBackgroundResource(R .drawable.bottom_sheet_rounded)
30- it.setBackgroundColor(Color .TRANSPARENT )
31- val layoutParams = it.layoutParams
32- layoutParams.height = getHeight()
33- bottomSheet.layoutParams = layoutParams
34- val behavior = BottomSheetBehavior .from<FrameLayout >(bottomSheet)
35- behavior.state = BottomSheetBehavior .STATE_EXPANDED
36- }
26+ val dialog = BottomSheetDialog (requireActivity(), theme)
27+ dialog.setOnShowListener {
28+ val bottomSheetView =
29+ dialog.findViewById<View >(com.google.android.material.R .id.design_bottom_sheet) as ? FrameLayout
30+ bottomSheetView?.let {
31+ it.setBackgroundResource(R .drawable.bottom_sheet_rounded)
32+ it.setBackgroundColor(Color .TRANSPARENT )
33+ setHeightIfAttached(activity, it)
34+ val behavior = BottomSheetBehavior .from<FrameLayout >(it)
35+ behavior.state = BottomSheetBehavior .STATE_EXPANDED
3736 }
37+ }
3838
39- return dialog
40- }
41-
42- protected fun closeAllSheets () {
43- dismiss()
39+ return dialog
4440 }
4541
46- private fun getHeight () : Int {
47- val displayMetrics = DisplayMetrics ()
48- requireActivity().windowManager.defaultDisplay.getMetrics(displayMetrics)
49- return displayMetrics.heightPixels * 80 / 100
42+ private fun setHeightIfAttached (activity : Activity ? , bottomSheet : View ) {
43+ activity?.let {
44+ val displayMetrics = DisplayMetrics ()
45+ requireActivity().windowManager.defaultDisplay.getMetrics(displayMetrics)
46+ val height = displayMetrics.heightPixels * 4 / 5
47+ val layoutParams = bottomSheet.layoutParams
48+ layoutParams.height = height
49+ bottomSheet.layoutParams = layoutParams
50+ }
5051 }
5152
5253 @SuppressLint(" ClickableViewAccessibility" )
5354 protected fun configureMultilineEditTextScrollEvent (editText : EditText ) {
5455 // need this for scrolling an edittext in a BSDF
55- editText.setOnTouchListener {v , event ->
56+ editText.setOnTouchListener { v , event ->
5657 v.parent.requestDisallowInterceptTouchEvent(true )
5758 when (event.action and MotionEvent .ACTION_MASK ) {
5859 MotionEvent .ACTION_UP -> v.parent.requestDisallowInterceptTouchEvent(false )
0 commit comments