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
3 changes: 3 additions & 0 deletions debugoverlay-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ dependencies {

debugImplementation(libs.androidx.compose.ui.tooling)

// Json
implementation(libs.kotlinx.serialization.json)

// Lifecycle for synthetic lifecycle owner
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.runtime.ktx)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ms.square.debugoverlay.internal.data

internal enum class TextType {
JSON,
HTML,
XML,
PLAIN,
;

companion object Companion {

/**
* Detect text type from http content-type header and content.
*/
fun from(body: String, contentType: String?): TextType {
// Check content-type header first
contentType?.lowercase()?.let { ct ->
when {
ct.contains("json") -> return JSON
ct.contains("html") -> return HTML
ct.contains("xml") -> return XML
}
}
// Fallback: Detect from content
val trimmed = body.trimStart()
return when {
trimmed.startsWith("{") || trimmed.startsWith("[") -> JSON
trimmed.startsWith(
"<!DOCTYPE html",
ignoreCase = true
) || trimmed.startsWith("<html", ignoreCase = true) -> HTML
trimmed.startsWith("<?xml") || trimmed.startsWith("<") -> XML
else -> PLAIN
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ms.square.debugoverlay.internal.data

import androidx.core.net.toUri

internal data class UrlParts(val scheme: String, val domain: String, val path: String) {
companion object {
fun from(url: String): UrlParts {
val uri = url.toUri()
return UrlParts(
scheme = uri.scheme ?: "",
domain = uri.host ?: "",
path = uri.path ?: "/"
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.ms.square.debugoverlay.internal.ui

import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.ms.square.debugoverlay.internal.util.httpMethodColor
import com.ms.square.debugoverlay.internal.util.httpStatusColor

/**
* HTTP method badge (GET, POST, etc.)
*/
@Composable
internal fun MethodBadge(method: String, modifier: Modifier = Modifier) {
Surface(
modifier = modifier,
color = method.httpMethodColor,
shape = RoundedCornerShape(4.dp)
) {
Text(
text = method,
modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp),
style = MaterialTheme.typography.labelSmall,
color = Color.Black,
fontWeight = FontWeight.Bold,
fontSize = 10.sp
)
}
}

/**
* Status code badge with color coding.
*/
@Composable
internal fun StatusCodeBadge(statusCode: Int?, modifier: Modifier = Modifier) {
Text(
text = statusCode?.toString() ?: "ERR",
modifier = modifier,
style = MaterialTheme.typography.titleMedium,
color = statusCode.httpStatusColor,
fontWeight = FontWeight.Bold,
fontFamily = FontFamily.Monospace
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ms.square.debugoverlay.internal.ui

import android.content.ClipData
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -28,7 +27,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ClipEntry
import androidx.compose.ui.platform.LocalClipboard
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
Expand All @@ -39,7 +37,7 @@ import androidx.compose.ui.unit.sp
import com.ms.square.debugoverlay.core.R
import com.ms.square.debugoverlay.internal.data.model.LogcatEntry
import com.ms.square.debugoverlay.internal.data.model.toColor
import kotlinx.coroutines.launch
import com.ms.square.debugoverlay.internal.util.copyToClipboard

private const val BOTTOM_SHEET_HEIGHT_FRACTION = 0.8f
private const val TIMESTAMP_DISPLAY_LENGTH = 12 // HH:MM:SS.mmm
Expand Down Expand Up @@ -236,11 +234,8 @@ private fun DetailActionButtons(logEntry: LogcatEntry, onFilterTag: (String) ->
// Copy button
Button(
onClick = {
scope.launch {
val clipboardLabel = context.getString(R.string.debugoverlay_clipboard_label)
val clipEntry = ClipEntry(ClipData.newPlainText(clipboardLabel, logEntry.rawLine))
clipboard.setClipEntry(clipEntry)
}
val clipboardLabel = context.getString(R.string.debugoverlay_clipboard_label_logcat)
scope.copyToClipboard(clipboard, logEntry.rawLine, clipboardLabel)
},
modifier = Modifier.weight(1f)
) {
Expand Down
Loading
Loading