@@ -2,45 +2,176 @@ package com.github.creativecodecat.components.views
22
33import android.content.Context
44import android.graphics.Typeface
5- import android.os.Bundle
5+ import android.graphics.drawable.GradientDrawable
6+ import android.view.Gravity
67import android.view.View
78import android.view.ViewGroup
9+ import android.view.WindowManager
10+ import android.widget.FrameLayout
811import android.widget.TextView
12+ import androidx.appcompat.app.AppCompatDialog
13+ import androidx.coordinatorlayout.widget.CoordinatorLayout
14+ import androidx.core.content.ContextCompat
15+ import com.github.droidworksstudio.common.isGestureNavigationEnabled
16+ import com.github.droidworksstudio.mlauncher.R
917import com.github.droidworksstudio.mlauncher.helper.CustomFontView
1018import com.github.droidworksstudio.mlauncher.helper.FontManager
1119import com.google.android.material.bottomsheet.BottomSheetBehavior
12- import com.google.android.material.bottomsheet.BottomSheetDialog
20+ import com.google.android.material.R as MaterialR
1321
1422/* *
1523 * BottomSheetDialog that:
1624 * - Disables swipe-to-dismiss
1725 * - Keeps tap outside, back button, and programmatic `.hide()` working
1826 */
1927
20- class FontBottomSheetDialogLocked (context : Context ) : BottomSheetDialog (context), CustomFontView {
28+ class FontBottomSheetDialogLocked (context : Context ) : AppCompatDialog (context), CustomFontView {
2129
22- override fun onCreate (savedInstanceState : Bundle ? ) {
23- super .onCreate(savedInstanceState)
30+ private var coordinator: CoordinatorLayout = CoordinatorLayout (context).apply {
31+ layoutParams = ViewGroup .LayoutParams (
32+ ViewGroup .LayoutParams .MATCH_PARENT ,
33+ ViewGroup .LayoutParams .MATCH_PARENT
34+ )
35+ }
2436
25- behavior.apply {
26- isDraggable = false // ❌ Prevent swipe-to-dismiss
27- skipCollapsed = true // ✅ Always start expanded
28- // DO NOT set isHideable = false — this allows `.hide()` to still work
37+ private var sheet: FrameLayout = FrameLayout (context).apply {
38+ id = MaterialR .id.design_bottom_sheet
39+ layoutParams = CoordinatorLayout .LayoutParams (
40+ ViewGroup .LayoutParams .MATCH_PARENT ,
41+ ViewGroup .LayoutParams .WRAP_CONTENT
42+ ).apply {
43+ gravity = Gravity .BOTTOM
2944 }
3045
46+ elevation = 16 * context.resources.displayMetrics.density
47+ }
48+
49+ private var behavior: BottomSheetBehavior <FrameLayout >
50+ private var cancelableFlag = true
51+
52+ override fun setCancelable (flag : Boolean ) {
53+ super .setCancelable(flag)
54+ cancelableFlag = flag
55+ }
56+
57+ init {
58+ // Coordinator
59+ coordinator = CoordinatorLayout (context).apply {
60+ layoutParams = ViewGroup .LayoutParams (
61+ ViewGroup .LayoutParams .MATCH_PARENT ,
62+ ViewGroup .LayoutParams .MATCH_PARENT
63+ )
64+ setOnClickListener { if (cancelableFlag) dismiss() }
65+ }
66+
67+
68+ // Bottom sheet layout params with behavior attached
69+ val lp = CoordinatorLayout .LayoutParams (
70+ ViewGroup .LayoutParams .MATCH_PARENT ,
71+ ViewGroup .LayoutParams .WRAP_CONTENT
72+ ).apply {
73+ gravity = Gravity .BOTTOM
74+ width = ViewGroup .LayoutParams .MATCH_PARENT
75+ behavior = BottomSheetBehavior <FrameLayout >()
76+ // optional: no margins
77+ setMargins(0 , 0 , 0 , 0 )
78+ }
79+
80+ // Sheet
81+ sheet = FrameLayout (context).apply {
82+ id = MaterialR .id.design_bottom_sheet
83+ layoutParams = lp
84+ // background drawable (with rounded top corners)
85+ background = GradientDrawable ().apply {
86+ shape = GradientDrawable .RECTANGLE
87+ val radiusPx = 16 * context.resources.displayMetrics.density
88+ cornerRadii = floatArrayOf(
89+ radiusPx, radiusPx, // top-left
90+ radiusPx, radiusPx, // top-right
91+ 0f , 0f , // bottom-right
92+ 0f , 0f // bottom-left
93+ )
94+ setColor(ContextCompat .getColor(context, R .color.colorPrimaryBackground))
95+ }
96+ elevation = 16 * context.resources.displayMetrics.density
97+ }
98+
99+
100+ // Add sheet to coordinator
101+ coordinator.addView(sheet)
102+ super .setContentView(coordinator)
103+
104+ // Get behavior safely
105+ behavior = BottomSheetBehavior .from(sheet).apply {
106+ isDraggable = false
107+ skipCollapsed = true
108+ state = BottomSheetBehavior .STATE_EXPANDED
109+ }
110+
111+ // Window dim
112+ window?.apply {
113+ setBackgroundDrawableResource(android.R .color.transparent)
114+ setLayout(ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT )
115+ setGravity(Gravity .BOTTOM )
116+ attributes = attributes.apply {
117+ dimAmount = 0.5f
118+ flags = flags or WindowManager .LayoutParams .FLAG_DIM_BEHIND
119+ }
120+ }
121+
122+ // Font manager
31123 FontManager .register(this )
32124 }
33125
126+
127+ override fun setContentView (view : View ) {
128+ sheet.removeAllViews()
129+ sheet.addView(
130+ view, FrameLayout .LayoutParams (
131+ ViewGroup .LayoutParams .MATCH_PARENT ,
132+ ViewGroup .LayoutParams .WRAP_CONTENT
133+ )
134+ )
135+ }
136+
34137 override fun onStart () {
35138 super .onStart()
139+
36140 behavior.state = BottomSheetBehavior .STATE_EXPANDED
37141
38- // Apply font after views are attached
142+ // Force full width
143+ sheet.layoutParams = (sheet.layoutParams as CoordinatorLayout .LayoutParams ).apply {
144+ width = ViewGroup .LayoutParams .MATCH_PARENT
145+ gravity = Gravity .BOTTOM
146+ }
147+ sheet.requestLayout()
148+
149+ // Apply font
39150 window?.decorView?.let { rootView ->
40151 FontManager .getTypeface(context)?.let { typeface ->
41152 applyFontRecursively(rootView, typeface)
42153 }
43154 }
155+
156+ val paddingBottom = when (isGestureNavigationEnabled(context)) {
157+ true -> context.resources.getDimensionPixelSize(R .dimen.bottom_margin_gesture_nav)
158+ false -> context.resources.getDimensionPixelSize(R .dimen.bottom_margin_3_button_nav)
159+ }
160+
161+ sheet.setPadding(
162+ sheet.paddingLeft,
163+ sheet.paddingTop,
164+ sheet.paddingRight,
165+ paddingBottom
166+ )
167+
168+ // Determine side margins
169+ val sideMargin = context.resources.getDimensionPixelSize(R .dimen.bottom_sheet_side_margin)
170+
171+ // Update LayoutParams for the sheet
172+ val lp = sheet.layoutParams as CoordinatorLayout .LayoutParams
173+ lp.setMargins(sideMargin, lp.topMargin, sideMargin, lp.bottomMargin)
174+ sheet.layoutParams = lp
44175 }
45176
46177 override fun applyFont (typeface : Typeface ? ) {
@@ -51,7 +182,6 @@ class FontBottomSheetDialogLocked(context: Context) : BottomSheetDialog(context)
51182
52183 private fun applyFontRecursively (view : View , typeface : Typeface ? ) {
53184 if (typeface == null ) return
54-
55185 when (view) {
56186 is TextView -> view.typeface = typeface
57187 is ViewGroup -> {
0 commit comments