Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.emptyFlow

@OptIn(DebugPanelInternal::class)
public object DebugPanel {
@Volatile
private var instance: DebugPanelInstance? = null
public val isInitialized: Boolean
get() = instance != null
Expand All @@ -40,6 +41,8 @@ public object DebugPanel {
}
}

internal fun getInstance(): DebugPanelInstance? = instance

private fun openDebugPanel(activity: Activity) {
val intent = Intent(activity, DebugPanelActivity::class.java)
activity.startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal class DebugPanelInstance(
init {
initContainer(application.applicationContext)
initPluginManager(plugins, requireNotNull(commonContainer))
instance = this
}

internal fun getEventLiveData(): LiveData<DebugEvent> {
Expand All @@ -42,7 +41,7 @@ internal class DebugPanelInstance(
eventSharedFlow.tryEmit(debugEvent)
}

internal fun getPluginManger(): PluginManager {
internal fun getPluginManager(): PluginManager {
return pluginManager
?: error("PluginManager not initialised")
}
Expand All @@ -59,8 +58,4 @@ internal class DebugPanelInstance(
start(commonContainer)
}
}

companion object {
var instance: DebugPanelInstance? = null
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.redmadrobot.debug.core.extension

import com.redmadrobot.debug.core.DebugPanelInstance
import com.redmadrobot.debug.core.DebugPanel
import com.redmadrobot.debug.core.annotation.DebugPanelInternal
import com.redmadrobot.debug.core.plugin.Plugin

@PublishedApi
internal fun getPlugin(pluginName: String): Plugin {
val plugin = DebugPanelInstance.instance?.getPluginManger()?.findPluginByName(pluginName)
val plugin = DebugPanel.getInstance()?.getPluginManager()?.findPluginByName(pluginName)
return requireNotNull(plugin)
}

internal fun getAllPlugins(): List<Plugin> {
return DebugPanelInstance.instance?.getPluginManger()?.plugins ?: emptyList()
return DebugPanel.getInstance()?.getPluginManager()?.plugins ?: emptyList()
}

@DebugPanelInternal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.redmadrobot.debug.core.plugin

import androidx.compose.runtime.Composable
import com.redmadrobot.debug.core.DebugEvent
import com.redmadrobot.debug.core.DebugPanelInstance
import com.redmadrobot.debug.core.DebugPanel
import com.redmadrobot.debug.core.internal.CommonContainer
import com.redmadrobot.debug.core.internal.PluginDependencyContainer

Expand All @@ -15,7 +15,7 @@ public abstract class Plugin {
}

public fun pushEvent(debugEvent: DebugEvent) {
DebugPanelInstance.instance?.pushEvent(debugEvent)
DebugPanel.getInstance()?.pushEvent(debugEvent)
}

public fun <T> getContainer(): T = pluginContainer as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import android.content.IntentFilter
import androidx.activity.ComponentActivity
import androidx.core.content.ContextCompat
import timber.log.Timber
import java.util.concurrent.atomic.AtomicInteger

internal class ApplicationLifecycleHandler(
private val application: Application,
) {
// open Activity counter
private var openActivityCount = 0
private val openActivityCounter = AtomicInteger(0)

private var debugPanelBroadcastReceiver: BroadcastReceiver? = null
private val debugPanelNotification = DebugPanelNotification(application.applicationContext)
Expand All @@ -25,8 +26,7 @@ internal class ApplicationLifecycleHandler(
application.registerActivityLifecycleCallbacks(
object : ActivityLifecycleCallbacksAdapter() {
override fun onActivityResumed(activity: Activity) {
if (openActivityCount == 0) onAppResumed()
++openActivityCount
if (openActivityCounter.getAndIncrement() == 0) onAppResumed()

// register BroadcastReceiver for debug panel inner actions
debugPanelBroadcastReceiver = DebugPanelBroadcastReceiver(activity)
Expand All @@ -41,11 +41,10 @@ internal class ApplicationLifecycleHandler(
}

override fun onActivityPaused(activity: Activity) {
--openActivityCount
(activity as? ComponentActivity)?.let {
activity.unregisterReceiver(debugPanelBroadcastReceiver)
}
if (openActivityCount == 0) onAppPaused()
if (openActivityCounter.decrementAndGet() == 0) onAppPaused()
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ internal class DebugPanelNotification(private val context: Context) {
}

fun show() {
val isPermissionGranted = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
val isPermissionDenied = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
ContextCompat.checkSelfPermission(context, POST_NOTIFICATIONS) != PERMISSION_GRANTED
if (isPermissionGranted) return
if (isPermissionDenied) return

notificationManager = NotificationManagerCompat.from(context)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand Down
1 change: 1 addition & 0 deletions panel-no-op/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ android {

kotlin {
jvmToolchain(17)
explicitApi()
}

namespace = "com.redmadrobot.debug.noop"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.redmadrobot.debug.core.data

interface DebugDataProvider<T> {
fun provideData(): T
public interface DebugDataProvider<T> {
public fun provideData(): T
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.redmadrobot.debug.core.internal

interface DebugEvent
public interface DebugEvent
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow

@Suppress("UnusedParameter", "OptionalUnit")
object DebugPanel {
fun initialize(
application: Application,
plugins: List<Any>,
) = Unit
public object DebugPanel {
public fun initialize(application: Application, plugins: List<Any>): Unit = Unit

fun subscribeToEvents(lifecycleOwner: LifecycleOwner, onEvent: (DebugEvent) -> Unit) = Unit
public fun subscribeToEvents(lifecycleOwner: LifecycleOwner, onEvent: (DebugEvent) -> Unit): Unit = Unit

fun observeEvents(): Flow<DebugEvent> = emptyFlow()
public fun observeEvents(): Flow<DebugEvent> = emptyFlow()

fun showPanel(fragmentManager: FragmentManager) = Unit
public fun showPanel(fragmentManager: FragmentManager): Unit = Unit

fun showPanel(activity: Activity) = Unit
public fun showPanel(activity: Activity): Unit = Unit
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.redmadrobot.debug.plugin.aboutapp

data class AboutAppInfo(
public data class AboutAppInfo(
val title: String,
val value: String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.redmadrobot.debug.plugin.aboutapp

@Suppress("UnusedPrivateProperty")
class AboutAppPlugin(
public class AboutAppPlugin(
private val appInfoList: List<AboutAppInfo>
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.redmadrobot.debug.plugin.servers.data.model

data class DebugServer(
public data class DebugServer(
val name: String,
val url: String,
val isDefault: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.redmadrobot.debug.plugin.servers
import com.redmadrobot.debug.core.internal.DebugEvent
import com.redmadrobot.debug.plugin.servers.data.model.DebugServer

data class ServerSelectedEvent(val debugServer: DebugServer) : DebugEvent
public data class ServerSelectedEvent(val debugServer: DebugServer) : DebugEvent
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.redmadrobot.debug.core.data.DebugDataProvider
import com.redmadrobot.debug.plugin.servers.data.model.DebugServer
import java.util.Collections.emptyList

class ServersPlugin(
public class ServersPlugin(
private val preInstalledServers: List<Any> = emptyList()
) {
constructor(debugDataProvider: DebugDataProvider<List<DebugServer>>) : this(
public constructor(debugDataProvider: DebugDataProvider<List<DebugServer>>) : this(
preInstalledServers = debugDataProvider.provideData()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

class DebugServerInterceptor : Interceptor {
public class DebugServerInterceptor : Interceptor {
@Suppress("UnusedParameter")
fun modifyRequest(block: (Request, DebugServer) -> Request): DebugServerInterceptor {
public fun modifyRequest(block: (Request, DebugServer) -> Request): DebugServerInterceptor {
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.runtime.Composable
import com.redmadrobot.debug.core.internal.CommonContainer
import com.redmadrobot.debug.core.internal.PluginDependencyContainer
import com.redmadrobot.debug.core.plugin.Plugin
import com.redmadrobot.debug.plugin.konfeaure.ui.KonfeatureScreen
import com.redmadrobot.debug.plugin.konfeature.ui.KonfeatureScreen
import com.redmadrobot.konfeature.Konfeature

public class KonfeaturePlugin(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redmadrobot.debug.plugin.konfeaure.ui
package com.redmadrobot.debug.plugin.konfeature.ui

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
Expand Down Expand Up @@ -32,8 +32,6 @@ import com.redmadrobot.debug.core.extension.provideViewModel
import com.redmadrobot.debug.plugin.konfeature.KonfeaturePlugin
import com.redmadrobot.debug.plugin.konfeature.KonfeaturePluginContainer
import com.redmadrobot.debug.plugin.konfeature.R
import com.redmadrobot.debug.plugin.konfeature.ui.EditConfigValueDialog
import com.redmadrobot.debug.plugin.konfeature.ui.KonfeatureViewModel
import com.redmadrobot.debug.plugin.konfeature.ui.data.KonfeatureItem
import com.redmadrobot.debug.plugin.konfeature.ui.data.KonfeatureViewState
import com.redmadrobot.debug.core.R as CoreR
Expand Down
Loading