Skip to content

Commit d8619c9

Browse files
committed
Implement plug-and-play debug drawer integration
🚀 MAJOR ENHANCEMENT: True Plug-and-Play Integration ✨ What's New: - DebugDrawerApplication: Extend instead of Application for auto-setup - Gesture-based activation: Long press or double tap anywhere to open - Zero MainActivity code required: No manual setup needed - Auto-initialization: Works across all activities automatically - DebugDrawerUtils: Simple static methods for manual control 🔧 New Classes: - DebugDrawerAutoSetup: Handles automatic initialization and module registration - DebugDrawerInitializer: Annotation-based setup detection - DebugDrawerApplication: Base Application class with auto-setup - DebugDrawerUtils: Static utility methods for manual control - @EnableDebugDrawer: Annotation for automatic setup 📱 Developer Experience Revolution: - Before: 6+ @Inject declarations + manual setup + cleanup - After: 1 line: extend DebugDrawerApplication - Gesture activation: No button required - Auto-cleanup: No manual lifecycle management - Zero boilerplate: True plug-and-play experience 🎯 Integration Examples: - Super Simple: Extend DebugDrawerApplication - Advanced: Use DebugDrawerInitializer manually - Manual Control: Use DebugDrawerUtils static methods 📚 Updated README with comprehensive examples and comparison table
1 parent 607aeea commit d8619c9

11 files changed

Lines changed: 554 additions & 91 deletions

File tree

README.md

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ For contributing or custom modifications:
126126

127127
### 2. Setup
128128

129-
#### **Prerequisites**
130-
Ensure you have Hilt set up in your project. If not, add to your `build.gradle.kts`:
129+
#### **🚀 Super Simple Integration (Recommended)**
130+
131+
**Step 1:** Add Hilt to your project (if not already added):
131132
```kotlin
132133
plugins {
133134
id("com.google.dagger.hilt.android")
@@ -140,70 +141,96 @@ dependencies {
140141
}
141142
```
142143

143-
#### **Application Setup**
144+
**Step 2:** Update your Application class:
144145
```kotlin
145146
@HiltAndroidApp
146-
class MyApplication : Application() {
147-
@Inject
148-
lateinit var debugDrawer: com.abualzait.debugdrawer.DebugDrawer
149-
150-
override fun onCreate() {
151-
super.onCreate()
152-
// Debug drawer auto-initializes when first accessed
153-
}
147+
class MyApplication : com.abualzait.debugdrawer.DebugDrawerApplication() {
148+
// That's it! No additional code needed!
154149
}
155150
```
156151

157-
#### **Activity Integration**
152+
**Step 3:** Your MainActivity requires ZERO debug drawer code:
158153
```kotlin
159154
@AndroidEntryPoint
160155
class MainActivity : AppCompatActivity() {
161-
162-
@Inject lateinit var debugDrawer: com.abualzait.debugdrawer.DebugDrawer
163-
@Inject lateinit var appInfoModule: com.abualzait.debugdrawer.modules.AppInfoModule
164-
@Inject lateinit var networkModule: com.abualzait.debugdrawer.modules.NetworkModule
165-
@Inject lateinit var logsModule: com.abualzait.debugdrawer.modules.LogsModule
166-
@Inject lateinit var featureFlagsModule: com.abualzait.debugdrawer.modules.FeatureFlagsModule
167-
@Inject lateinit var settingsModule: com.abualzait.debugdrawer.modules.SettingsModule
168-
@Inject lateinit var clipboardModule: com.abualzait.debugdrawer.modules.ClipboardModule
169-
170156
override fun onCreate(savedInstanceState: Bundle?) {
171157
super.onCreate(savedInstanceState)
172158
setContentView(R.layout.activity_main)
173-
setupDebugDrawer()
159+
// No debug drawer setup needed!
174160
}
175-
176-
private fun setupDebugDrawer() {
177-
debugDrawer.initialize(this)
178-
179-
// Add modules (pick only what you need)
180-
debugDrawer.addModule(appInfoModule)
181-
debugDrawer.addModule(networkModule)
182-
debugDrawer.addModule(logsModule)
183-
debugDrawer.addModule(featureFlagsModule)
184-
debugDrawer.addModule(settingsModule)
185-
debugDrawer.addModule(clipboardModule)
186-
187-
// Add toggle button
188-
findViewById<Button>(R.id.btn_toggle_debug)?.setOnClickListener {
189-
debugDrawer.toggle()
190-
}
161+
}
162+
```
163+
164+
**🎉 Done!** The debug drawer is now automatically available with:
165+
- **Gesture activation:** Long press or double tap anywhere on screen
166+
- **All modules included:** App info, network monitoring, logcat, feature flags, settings, clipboard
167+
- **Auto-initialization:** Works across all activities
168+
- **Zero boilerplate:** No manual setup required
169+
170+
#### **✨ What Changed - Developer Experience Revolution**
171+
172+
| **Before (Old Way)** | **After (New Way)** |
173+
|---------------------|-------------------|
174+
| ❌ 6+ @Inject declarations | ✅ 0 declarations needed |
175+
| ❌ Manual initialization | ✅ Automatic initialization |
176+
| ❌ Manual module registration | ✅ Auto-registered modules |
177+
| ❌ Manual cleanup in onDestroy | ✅ Automatic cleanup |
178+
| ❌ 20+ lines of setup code | ✅ 1 line: extend DebugDrawerApplication |
179+
| ❌ Button required for activation | ✅ Gesture-based activation |
180+
| ❌ Complex integration | ✅ True plug-and-play |
181+
182+
#### **🔧 Advanced Integration (Optional)**
183+
184+
If you need custom control, you can still use the traditional approach:
185+
186+
```kotlin
187+
@HiltAndroidApp
188+
class MyApplication : Application() {
189+
@Inject
190+
lateinit var debugDrawerInitializer: com.abualzait.debugdrawer.DebugDrawerInitializer
191+
192+
override fun onCreate() {
193+
super.onCreate()
194+
debugDrawerInitializer.initializeIfEnabled(this)
191195
}
192196
}
193197
```
194198

199+
#### **🎮 Manual Control (When Needed)**
200+
201+
```kotlin
202+
// Show/hide programmatically
203+
com.abualzait.debugdrawer.DebugDrawerUtils.toggle(context)
204+
com.abualzait.debugdrawer.DebugDrawerUtils.show(context)
205+
com.abualzait.debugdrawer.DebugDrawerUtils.hide(context)
206+
207+
// Check visibility
208+
val isVisible = com.abualzait.debugdrawer.DebugDrawerUtils.isVisible(context)
209+
```
210+
195211
### 3. Usage
196212

197-
#### **Opening the Debug Drawer**
213+
#### **🎮 Activation Methods**
214+
215+
**Automatic Gestures (Zero Code Required):**
216+
- **Long press** anywhere on the screen
217+
- **Double tap** anywhere on the screen
218+
219+
**Programmatic Control (When Needed):**
198220
```kotlin
199-
// Programmatically
200-
debugDrawer.toggle() // Show/hide
201-
debugDrawer.show() // Show only
202-
debugDrawer.hide() // Hide only
221+
// Show/hide programmatically
222+
com.abualzait.debugdrawer.DebugDrawerUtils.toggle(context)
223+
com.abualzait.debugdrawer.DebugDrawerUtils.show(context)
224+
com.abualzait.debugdrawer.DebugDrawerUtils.hide(context)
225+
226+
// Check visibility
227+
val isVisible = com.abualzait.debugdrawer.DebugDrawerUtils.isVisible(context)
228+
```
203229

204-
// Via UI button
230+
**UI Button (Optional):**
231+
```kotlin
205232
findViewById<Button>(R.id.btn_toggle_debug)?.setOnClickListener {
206-
debugDrawer.toggle()
233+
com.abualzait.debugdrawer.DebugDrawerUtils.toggle(this)
207234
}
208235
```
209236

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ internal class DebugOverlay(
115115
private var currentModule: DebugModule? = null
116116
private var moduleAdapter: DebugModuleAdapter? = null
117117

118-
fun addModule(module: DebugModule) {
118+
fun addModule(_module: DebugModule) {
119119
// Module will be added to the adapter when it's shown
120120
moduleAdapter?.notifyDataSetChanged()
121121
}
122122

123-
fun removeModule(module: DebugModule) {
123+
fun removeModule(_module: DebugModule) {
124124
// Module will be removed from the adapter when it's shown
125125
moduleAdapter?.notifyDataSetChanged()
126126
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.abualzait.debugdrawer
2+
3+
import android.app.Application
4+
import com.abualzait.debugdrawer.annotations.EnableDebugDrawer
5+
import com.abualzait.debugdrawer.utils.Logger
6+
import dagger.hilt.android.HiltAndroidApp
7+
import javax.inject.Inject
8+
9+
/**
10+
* Base Application class that automatically sets up the debug drawer.
11+
*
12+
* Usage:
13+
* 1. Extend this class instead of Application
14+
* 2. Add @HiltAndroidApp annotation to your class
15+
* 3. The debug drawer will be automatically initialized
16+
*
17+
* Example:
18+
* ```kotlin
19+
* @HiltAndroidApp
20+
* class MyApplication : DebugDrawerApplication() {
21+
* // No additional code needed!
22+
* }
23+
* ```
24+
*/
25+
@EnableDebugDrawer
26+
abstract class DebugDrawerApplication : Application() {
27+
28+
@Inject
29+
lateinit var debugDrawerInitializer: DebugDrawerInitializer
30+
31+
@Inject
32+
lateinit var logger: Logger
33+
34+
override fun onCreate() {
35+
super.onCreate()
36+
37+
// Automatically initialize debug drawer
38+
debugDrawerInitializer.initializeIfEnabled(this)
39+
40+
logger.d("DebugDrawerApplication", "Application started with debug drawer auto-setup")
41+
}
42+
}

0 commit comments

Comments
 (0)