Skip to content

Commit a583783

Browse files
authored
Merge pull request #1 from mabualzait/feature/logcat
Feature/logcat
2 parents d3cb79c + 73a7902 commit a583783

12 files changed

Lines changed: 802 additions & 138 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master, develop ]
65
pull_request:
7-
branches: [ master, develop ]
6+
workflow_dispatch: # Allow manual triggering
87

98
jobs:
109
test:

debugdrawer/src/main/java/com/abualzait/debugdrawer/DebugDrawer.kt

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.abualzait.debugdrawer
22

33
import android.app.Activity
4+
import android.view.LayoutInflater
45
import android.view.View
56
import android.view.ViewGroup
67
import 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
712
import com.abualzait.debugdrawer.modules.DebugModule
813
import com.abualzait.debugdrawer.utils.Logger
914
import 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
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.abualzait.debugdrawer.adapter
2+
3+
import android.content.Context
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.widget.BaseAdapter
8+
import android.widget.ImageView
9+
import android.widget.TextView
10+
import com.abualzait.debugdrawer.R
11+
import com.abualzait.debugdrawer.modules.DebugModule
12+
13+
/**
14+
* Adapter for displaying debug modules in a grid view.
15+
*/
16+
class DebugModuleAdapter(
17+
private val context: Context,
18+
private val modules: List<DebugModule>,
19+
private val onModuleClick: (DebugModule) -> Unit
20+
) : BaseAdapter() {
21+
22+
override fun getCount(): Int = modules.size
23+
24+
override fun getItem(position: Int): DebugModule = modules[position]
25+
26+
override fun getItemId(position: Int): Long = position.toLong()
27+
28+
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
29+
val view = convertView ?: LayoutInflater.from(context)
30+
.inflate(R.layout.debug_module_item, parent, false)
31+
32+
val module = getItem(position)
33+
val iconView = view.findViewById<ImageView>(R.id.iv_module_icon)
34+
val titleView = view.findViewById<TextView>(R.id.tv_module_title)
35+
val descriptionView = view.findViewById<TextView>(R.id.tv_module_description)
36+
37+
// Set module icon based on module type
38+
iconView.setImageResource(getModuleIcon(module.name))
39+
40+
titleView.text = module.title
41+
descriptionView.text = module.description
42+
43+
// Set click listener
44+
view.setOnClickListener {
45+
onModuleClick(module)
46+
}
47+
48+
return view
49+
}
50+
51+
private fun getModuleIcon(moduleName: String): Int {
52+
return when (moduleName) {
53+
"app_info" -> android.R.drawable.ic_menu_info_details
54+
"network" -> android.R.drawable.ic_menu_share
55+
"feature_flags" -> android.R.drawable.ic_menu_preferences
56+
"logcat" -> android.R.drawable.ic_menu_edit
57+
"settings" -> android.R.drawable.ic_menu_manage
58+
"clipboard" -> android.R.drawable.ic_menu_edit
59+
else -> android.R.drawable.ic_menu_info_details
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)