Skip to content

Commit 2377f0e

Browse files
committed
feature: add kdoc to main entites
1 parent 095f456 commit 2377f0e

29 files changed

Lines changed: 332 additions & 7 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
package com.redmadrobot.debug.core
22

3+
/**
4+
* Marker interface for events emitted by plugins.
5+
*
6+
* Plugins send events via [com.redmadrobot.debug.core.plugin.Plugin.pushEvent],
7+
* consumers subscribe via [DebugPanel.subscribeToEvents] or [DebugPanel.observeEvents].
8+
*
9+
* Example:
10+
* ```
11+
* data class ServerSelectedEvent(val server: DebugServer) : DebugEvent
12+
* ```
13+
*
14+
* @see com.redmadrobot.debug.core.plugin.Plugin.pushEvent
15+
* @see DebugPanel.observeEvents
16+
*/
317
public interface DebugEvent

panel-core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanel.kt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,41 @@ import com.redmadrobot.debug.core.util.ApplicationLifecycleHandler
1212
import kotlinx.coroutines.flow.Flow
1313
import kotlinx.coroutines.flow.emptyFlow
1414

15+
/**
16+
* Main entry point for working with the debug panel.
17+
*
18+
* Before use, [initialize] must be called in [Application.onCreate].
19+
*
20+
* Initialization example:
21+
* ```
22+
* DebugPanel.initialize(
23+
* application = this,
24+
* plugins = listOf(
25+
* ServersPlugin(preInstalledServers),
26+
* KonfeaturePlugin(interceptor, konfeature),
27+
* )
28+
* )
29+
* ```
30+
*
31+
* @see Plugin
32+
*/
1533
@OptIn(DebugPanelInternal::class)
1634
public object DebugPanel {
1735
@Volatile
1836
private var instance: DebugPanelInstance? = null
37+
38+
/** Returns `true` if the panel has been initialized via [initialize]. */
1939
public val isInitialized: Boolean
2040
get() = instance != null
2141

42+
/**
43+
* Initializes the debug panel with the provided set of plugins.
44+
*
45+
* Must be called **once** in [Application.onCreate].
46+
*
47+
* @param application the [Application] instance
48+
* @param plugins list of plugins to be displayed in the panel
49+
*/
2250
public fun initialize(
2351
application: Application,
2452
plugins: List<Plugin>,
@@ -27,14 +55,32 @@ public object DebugPanel {
2755
ApplicationLifecycleHandler(application).start()
2856
}
2957

58+
/**
59+
* Subscribes to plugin events with lifecycle binding.
60+
*
61+
* @param lifecycleOwner lifecycle owner (Activity, Fragment)
62+
* @param onEvent callback invoked when an event is received
63+
*/
3064
public fun subscribeToEvents(lifecycleOwner: LifecycleOwner, onEvent: (DebugEvent) -> Unit) {
3165
instance?.getEventLiveData()?.observe(lifecycleOwner, Observer { onEvent.invoke(it) })
3266
}
3367

68+
/**
69+
* Returns a [Flow] of events from plugins.
70+
*
71+
* If the panel is not initialized, returns an empty Flow.
72+
*/
3473
public fun observeEvents(): Flow<DebugEvent> {
3574
return instance?.getEventFlow() ?: emptyFlow()
3675
}
3776

77+
/**
78+
* Opens the Activity containing the debug panel.
79+
*
80+
* Does nothing if the panel has not been initialized.
81+
*
82+
* @param activity the Activity from which the panel will be launched
83+
*/
3884
public fun showPanel(activity: Activity) {
3985
if (isInitialized) {
4086
openDebugPanel(activity)

panel-core/src/main/kotlin/com/redmadrobot/debug/core/annotation/DebugPanelInternal.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.redmadrobot.debug.core.annotation
22

3+
/**
4+
* Marks an API as internal to the debug panel.
5+
*
6+
* Entities with this annotation are intended for use only within the library's modules and may change without notice.
7+
*
8+
* Using a marked API outside the library will produce a compilation error.
9+
*/
310
@RequiresOptIn(
411
level = RequiresOptIn.Level.ERROR,
512
message = "This is an internal part of DebugPanel. You shouldn't use it, cause it can be changed in future"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
package com.redmadrobot.debug.core.data
22

3+
/**
4+
* Functional interface for lazy data supply to plugins.
5+
*
6+
* Allows passing data into a plugin through a provider rather than directly,
7+
* which is useful when data is produced lazily.
8+
*
9+
* Example usage with [com.redmadrobot.debug.plugin.servers.ServersPlugin]:
10+
* ```
11+
* val provider = DebugDataProvider<List<DebugServer>> {
12+
* listOf(DebugServer("Prod", "https://api.example.com", isDefault = true))
13+
* }
14+
* ServersPlugin(preInstalledServers = provider)
15+
* ```
16+
*
17+
* @param T type of provided data
18+
*/
319
public interface DebugDataProvider<T> {
20+
/** Returns data of type [T]. */
421
public fun provideData(): T
522
}

panel-core/src/main/kotlin/com/redmadrobot/debug/core/extension/CoroutinesExtension.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import kotlinx.coroutines.launch
66
import timber.log.Timber
77

88
/**
9-
* Запуск корутины с встроенной обработкой ошибки
10-
* */
9+
* Launches a coroutine with error handling.
10+
*
11+
* Catches all exceptions except [CancellationException], logs them via Timber.
12+
*
13+
* @param block suspend block to execute
14+
* @param onError callback invoked when an error occurs
15+
*/
1116
@Suppress("TooGenericExceptionCaught")
1217
public fun CoroutineScope.safeLaunch(
1318
block: suspend CoroutineScope.() -> Unit,
@@ -26,8 +31,13 @@ public fun CoroutineScope.safeLaunch(
2631
}
2732

2833
/**
29-
* Запуск корутины с встроенным логированием ошибки
30-
* */
34+
* Launches a coroutine with error logging.
35+
*
36+
* Equivalent to [safeLaunch] with an empty error handler --
37+
* exceptions are only logged via Timber.
38+
*
39+
* @param block suspend block to execute
40+
*/
3141
public fun CoroutineScope.safeLaunch(
3242
block: suspend CoroutineScope.() -> Unit
3343
) {

panel-core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ internal fun getAllPlugins(): List<Plugin> {
1414
return DebugPanel.getInstance()?.getPluginManager()?.plugins ?: emptyList()
1515
}
1616

17+
/**
18+
* Returns the registered plugin of the specified type.
19+
*
20+
* @throws IllegalArgumentException if the plugin is not found in the registry
21+
* @see DebugPanel
22+
*/
1723
@DebugPanelInternal
1824
public inline fun <reified T : Plugin> getPlugin(): T {
1925
val plugin = getPlugin(T::class.java.name)

panel-core/src/main/kotlin/com/redmadrobot/debug/core/internal/CommonContainer.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ package com.redmadrobot.debug.core.internal
33
import android.content.Context
44
import com.redmadrobot.debug.core.annotation.DebugPanelInternal
55

6+
/**
7+
* Container with shared dependencies, available to all plugins.
8+
*
9+
* Passed into [com.redmadrobot.debug.core.plugin.Plugin.getPluginContainer]
10+
* when a plugin is initialized.
11+
*
12+
* @property context application context
13+
*/
614
@DebugPanelInternal
715
public class CommonContainer(public val context: Context) : PluginDependencyContainer

panel-core/src/main/kotlin/com/redmadrobot/debug/core/internal/EditablePlugin.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ import androidx.compose.runtime.Composable
44
import com.redmadrobot.debug.core.annotation.DebugPanelInternal
55

66
/**
7-
* Plugin that will be displayed when opening the settings
7+
* Interface for plugins providing a settings screen.
8+
*
9+
* A plugin implementing this interface will be displayed
10+
* in the settings section of the debug panel.
11+
*
12+
* @see com.redmadrobot.debug.plugin.servers.ServersPlugin -- example implementation
813
*/
914
@DebugPanelInternal
1015
public interface EditablePlugin {
16+
/**
17+
* Composable function rendering the plugin's settings UI.
18+
*/
1119
@Suppress("TopLevelComposableFunctions", "ComposableFunctionName")
1220
@Composable
1321
public fun settingsContent() {

panel-core/src/main/kotlin/com/redmadrobot/debug/core/internal/PluginDependencyContainer.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@ package com.redmadrobot.debug.core.internal
22

33
import com.redmadrobot.debug.core.annotation.DebugPanelInternal
44

5+
/**
6+
* Marker interface for plugin dependency containers.
7+
*
8+
* Each plugin implements its own container, extending this interface, to hold repositories, interactors, and other dependencies.
9+
*
10+
* @see com.redmadrobot.debug.core.plugin.Plugin.getPluginContainer
11+
* @see CommonContainer
12+
*/
513
@DebugPanelInternal
614
public interface PluginDependencyContainer

panel-core/src/main/kotlin/com/redmadrobot/debug/core/plugin/Plugin.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import com.redmadrobot.debug.core.DebugPanel
66
import com.redmadrobot.debug.core.internal.CommonContainer
77
import com.redmadrobot.debug.core.internal.PluginDependencyContainer
88

9+
/**
10+
* Base class for all debug panel plugins.
11+
*
12+
* Each plugin is an isolated module with its own UI and dependencies.
13+
* To create a plugin, you need to:
14+
* 1. Extend [Plugin]
15+
* 2. Implement [getName] and [getPluginContainer]
16+
* 3. Override [content] to render the UI
17+
*
18+
* @see DebugPanel.initialize
19+
* @see PluginDependencyContainer
20+
*/
921
public abstract class Plugin {
1022
private lateinit var pluginContainer: PluginDependencyContainer
1123

@@ -14,18 +26,46 @@ public abstract class Plugin {
1426
return this
1527
}
1628

29+
/**
30+
* Sends an event to the debug panel's shared event bus.
31+
*
32+
* Subscribers will receive the event via [DebugPanel.subscribeToEvents] or [DebugPanel.observeEvents].
33+
*
34+
* @param debugEvent event to send
35+
*/
1736
public fun pushEvent(debugEvent: DebugEvent) {
1837
DebugPanel.getInstance()?.pushEvent(debugEvent)
1938
}
2039

40+
/**
41+
* Returns the plugin's dependency container, cast to type [T].
42+
*
43+
* @throws ClassCastException if the container does not match the requested type
44+
*/
2145
public fun <T> getContainer(): T = pluginContainer as T
2246

47+
/**
48+
* Composable function that renders the plugin's main UI in the debug panel.
49+
*/
2350
@Suppress("TopLevelComposableFunctions", "ComposableFunctionName")
2451
@Composable
2552
public open fun content() {
2653
}
2754

55+
/**
56+
* Creates and returns the plugin's dependency container.
57+
*
58+
* Called during plugin initialization. Use [commonContainer] to access shared dependencies (e.g., [android.content.Context]).
59+
*
60+
* @param commonContainer container with the panel's shared dependencies
61+
* @return the dependency container for this plugin
62+
*/
2863
public abstract fun getPluginContainer(commonContainer: CommonContainer): PluginDependencyContainer
2964

65+
/**
66+
* Returns the plugin's unique name.
67+
*
68+
* Used to identify the plugin in the registry.
69+
*/
3070
public abstract fun getName(): String
3171
}

0 commit comments

Comments
 (0)