11package com.abualzait.debugdrawer
22
33import android.app.Activity
4+ import android.view.LayoutInflater
45import android.view.View
56import android.view.ViewGroup
67import android.widget.FrameLayout
8+ import android.widget.GridView
9+ import android.widget.LinearLayout
10+ import com.abualzait.debugdrawer.R
11+ import com.abualzait.debugdrawer.adapter.DebugModuleAdapter
712import com.abualzait.debugdrawer.modules.DebugModule
813import com.abualzait.debugdrawer.utils.Logger
914import javax.inject.Inject
@@ -20,6 +25,7 @@ class DebugDrawer @Inject constructor(
2025 private var isInitialized = false
2126 private var debugOverlay: DebugOverlay ? = null
2227 private val modules = mutableListOf<DebugModule >()
28+ private var currentModule: DebugModule ? = null
2329
2430 /* *
2531 * Initialize the debug drawer with the given activity.
@@ -103,15 +109,20 @@ internal class DebugOverlay(
103109 private val modules : MutableList <DebugModule >,
104110) {
105111 private var overlayView: View ? = null
106- private var drawerContainer: View ? = null
112+ private var mainMenuView: View ? = null
113+ private var moduleView: View ? = null
107114 private var isVisible = false
115+ private var currentModule: DebugModule ? = null
116+ private var moduleAdapter: DebugModuleAdapter ? = null
108117
109118 fun addModule (module : DebugModule ) {
110- // Module will be added to the drawer when it's shown
119+ // Module will be added to the adapter when it's shown
120+ moduleAdapter?.notifyDataSetChanged()
111121 }
112122
113123 fun removeModule (module : DebugModule ) {
114- // Module will be removed from the drawer when it's shown
124+ // Module will be removed from the adapter when it's shown
125+ moduleAdapter?.notifyDataSetChanged()
115126 }
116127
117128 fun show () {
@@ -122,6 +133,7 @@ internal class DebugOverlay(
122133 val rootView = activity.findViewById<ViewGroup >(android.R .id.content)
123134 rootView.addView(view)
124135 isVisible = true
136+ showMainMenu()
125137 android.util.Log .d(" DebugDrawer" , " Debug drawer shown with ${modules.size} modules" )
126138 }
127139 }
@@ -143,7 +155,10 @@ internal class DebugOverlay(
143155 fun destroy () {
144156 hide()
145157 overlayView = null
146- drawerContainer = null
158+ mainMenuView = null
159+ moduleView = null
160+ moduleAdapter = null
161+ currentModule = null
147162 }
148163
149164 private fun createOverlayView () {
@@ -155,50 +170,58 @@ internal class DebugOverlay(
155170 )
156171 }
157172
158- // Set up the drawer container
159- drawerContainer = overlayView?.findViewById(R .id.debug_drawer_container)
160-
161- // Add modules to the drawer
162- setupModules()
163-
164- // Set up close button
165- overlayView?.findViewById<View >(R .id.btn_close_drawer)?.setOnClickListener {
166- hide()
167- }
168-
169173 // Set up overlay click to close
170174 overlayView?.findViewById<View >(R .id.debug_overlay_background)?.setOnClickListener {
171175 hide()
172176 }
173177 }
174178
175- private fun setupModules () {
176- val modulesContainer = drawerContainer?.findViewById< android.widget.LinearLayout > (R .id.ll_modules_container)
177- modulesContainer?.removeAllViews()
179+ private fun showMainMenu () {
180+ val inflater = activity.layoutInflater
181+ mainMenuView = inflater.inflate(R .layout.debug_drawer_main_menu, null )
182+
183+ val drawerContainer = overlayView?.findViewById<ViewGroup >(R .id.debug_drawer_container)
184+ drawerContainer?.removeAllViews()
185+ drawerContainer?.addView(mainMenuView)
186+
187+ // Set up modules grid
188+ val modulesGrid = mainMenuView?.findViewById<GridView >(R .id.gv_modules)
189+ moduleAdapter = DebugModuleAdapter (activity, modules) { module ->
190+ showModule(module)
191+ }
192+ modulesGrid?.adapter = moduleAdapter
178193
179- android.util.Log .d(" DebugDrawer" , " Setting up ${modules.size} modules" )
180- modules.forEach { module ->
181- android.util.Log .d(" DebugDrawer" , " Adding module: ${module.name} " )
182- val moduleView = createModuleView(module)
183- modulesContainer?.addView(moduleView)
194+ // Set up close button
195+ mainMenuView?.findViewById<View >(R .id.btn_close_drawer)?.setOnClickListener {
196+ hide()
184197 }
185198 }
186199
187- private fun createModuleView (module : DebugModule ): View {
200+ private fun showModule (module : DebugModule ) {
201+ currentModule = module
188202 val inflater = activity.layoutInflater
189- val moduleContainer = inflater.inflate(R .layout.debug_module_container, null )
203+ moduleView = inflater.inflate(R .layout.debug_module_view, null )
204+
205+ val drawerContainer = overlayView?.findViewById<ViewGroup >(R .id.debug_drawer_container)
206+ drawerContainer?.removeAllViews()
207+ drawerContainer?.addView(moduleView)
190208
191209 // Set module title
192- moduleContainer.findViewById< android.widget.TextView > (R .id.tv_module_title).text = module.title
193-
194- // Set module description
195- moduleContainer.findViewById< android.widget.TextView > (R .id.tv_module_description).text = module.description
210+ moduleView?.findViewById< android.widget.TextView > (R .id.tv_module_title)?.text = module.title
196211
197212 // Add module content
198- val contentContainer = moduleContainer .findViewById< android.widget. LinearLayout > (R .id.ll_module_content )
213+ val contentContainer = moduleView? .findViewById<FrameLayout >(R .id.fl_module_content )
199214 val moduleContentView = module.createView()
200- contentContainer.addView(moduleContentView)
215+ contentContainer?.addView(moduleContentView)
216+
217+ // Set up back button
218+ moduleView?.findViewById<View >(R .id.btn_back_to_menu)?.setOnClickListener {
219+ showMainMenu()
220+ }
201221
202- return moduleContainer
222+ // Set up close button
223+ moduleView?.findViewById<View >(R .id.btn_close_drawer)?.setOnClickListener {
224+ hide()
225+ }
203226 }
204227}
0 commit comments