Skip to content

Commit

Permalink
extended compose viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Apr 24, 2024
1 parent 4c78675 commit dcabfbc
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 49 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ buildscript {
maven("https://jitpack.io")
}
dependencies {
classpath("com.android.tools.build:gradle:" + tools.versions.gradle.get())
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:" + tools.versions.kotlin.get())
classpath("org.jetbrains.kotlin:kotlin-serialization:" + tools.versions.kotlin.get())
classpath(libs.gradle)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.kotlin.serialization)
}
}

Expand Down
5 changes: 5 additions & 0 deletions gradle/app.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[versions]

compileSdk = "34"
minSdk = "21"
targetSdk = "34"
2 changes: 1 addition & 1 deletion gradle/compose.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
composeBom = "2024.04.00"
compiler = "1.5.11"
compiler = "1.5.12"

activity = "1.8.2"
accompanist = "0.32.0"
Expand Down
17 changes: 17 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[versions]

gradle = "8.3.2"
kotlin = "1.9.23"
kotlinx-coroutines = "1.8.0"

[plugins]

[libraries]

gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }

kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }

kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
import androidx.compose.material.icons.filled.CheckBox
import androidx.compose.material.icons.filled.CheckBoxOutlineBlank
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.InsertDriveFile
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Mail
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.Divider
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -80,7 +81,8 @@ object LumberjackView {
class Style internal constructor(
val useAlternatingRowColors: Boolean,
val color1: Color,
val color2: Color
val color2: Color,
val singleScrollableLineView: Boolean
)
}

Expand All @@ -91,10 +93,12 @@ object LumberjackViewDefaults {
useAlternatingRowColors: Boolean = true,
color1: Color = MaterialTheme.colorScheme.background,
color2: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = .1f),
singleScrollableLineView: Boolean = false
) = LumberjackView.Style(
useAlternatingRowColors = useAlternatingRowColors,
color1 = color1,
color2 = color2
color2 = color2,
singleScrollableLineView = singleScrollableLineView
)

}
Expand Down Expand Up @@ -125,6 +129,7 @@ fun LumberjackDialog(
val listState = rememberLazyListState()
var showMenu by remember { mutableStateOf(false) }
var showMenu2 by remember { mutableStateOf(false) }
val useScrollableLines = remember { mutableStateOf(style.singleScrollableLineView) }
val logFile = rememberLogFile()
val logFileData = rememberLogFileData()
Column {
Expand Down Expand Up @@ -182,7 +187,7 @@ fun LumberjackDialog(
text = { Text("Select Log File") },
leadingIcon = {
Icon(
Icons.Default.InsertDriveFile,
Icons.AutoMirrored.Filled.InsertDriveFile,
null
)
},
Expand All @@ -191,6 +196,19 @@ fun LumberjackDialog(
showMenu2 = true
}
)
HorizontalDivider()
DropdownMenuItem(
text = { Text("Scrollable Lines") },
leadingIcon = {
Icon(
if (useScrollableLines.value) Icons.Default.CheckBox else Icons.Default.CheckBoxOutlineBlank,
null
)
},
onClick = {
useScrollableLines.value = !useScrollableLines.value
}
)
if (mail != null) {
HorizontalDivider()
DropdownMenuItem(
Expand Down Expand Up @@ -238,7 +256,7 @@ fun LumberjackDialog(
text = { Text(file.name) },
leadingIcon = {
Icon(
Icons.Default.InsertDriveFile,
Icons.AutoMirrored.Filled.InsertDriveFile,
null
)
},
Expand All @@ -261,7 +279,8 @@ fun LumberjackDialog(
data = logFileData,
modifier = Modifier.weight(1f),
state = listState,
darkTheme = darkTheme
darkTheme = darkTheme,
useScrollableLines = useScrollableLines
)
}
}
Expand Down Expand Up @@ -290,6 +309,7 @@ fun LumberjackView(
state: LazyListState = rememberLazyListState(),
darkTheme: Boolean = isSystemInDarkTheme(),
style: LumberjackView.Style = LumberjackViewDefaults.style(),
useScrollableLines: MutableState<Boolean>,
) {
LaunchedEffect(data.value, file.value) {
if (file.value == null) {
Expand Down Expand Up @@ -317,7 +337,7 @@ fun LumberjackView(
}

val filterOptions by remember {
derivedStateOf { listOf(null) + Level.values().toList().filter { it.priority >= 0 } }
derivedStateOf { listOf(null) + Level.entries.filter { it.priority >= 0 } }
}
val filter = rememberSaveable {
mutableStateOf(filterOptions.first())
Expand Down Expand Up @@ -379,7 +399,14 @@ fun LumberjackView(
) {
filteredEntries.forEach {
item(key = it.lineNumber) {
LogEntry(it, filter2.value, darkTheme, spanStyle, style)
LogEntry(
it,
filter2.value,
darkTheme,
spanStyle,
style,
useScrollableLines
)
}
}
}
Expand Down Expand Up @@ -511,7 +538,8 @@ private fun LogEntry(
filter: String,
darkTheme: Boolean,
spanStyle: SpanStyle,
style: LumberjackView.Style
style: LumberjackView.Style,
useScrollableLines: MutableState<Boolean>
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -544,6 +572,7 @@ private fun LogEntry(
Spacer(modifier = Modifier.weight(1f))
Text(text = entry.date, style = MaterialTheme.typography.labelSmall)
}

val plainText by remember(entry.lines) {
derivedStateOf { entry.lines.joinToString("\n") }
}
Expand All @@ -552,15 +581,25 @@ private fun LogEntry(
getHighlightedText(plainText, filter, true, spanStyle)
}
}
if (useScrollableLines.value) {
Text(
text = text,
modifier = Modifier
.fillMaxWidth()
.padding(start = INSET)
.horizontalScroll(rememberScrollState()),
style = MaterialTheme.typography.bodySmall
)
} else {
Text(
text = text,
modifier = Modifier
.fillMaxWidth()
.padding(start = INSET),
style = MaterialTheme.typography.bodySmall
)
}

Text(
text = text,
modifier = Modifier
.fillMaxWidth()
.padding(start = INSET)
.horizontalScroll(rememberScrollState()),
style = MaterialTheme.typography.bodySmall
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/implementations/lumberjack/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
// ------------------------

implementation(libs.kotlin)
implementation(libs.kotlin.coroutines)
implementation(libs.kotlinx.coroutines)

// ------------------------
// Library
Expand Down
2 changes: 1 addition & 1 deletion library/loggers/lumberjack/console/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
// ------------------------

implementation(libs.kotlin)
implementation(libs.kotlin.coroutines)
implementation(libs.kotlinx.coroutines)

// ------------------------
// Library
Expand Down
2 changes: 1 addition & 1 deletion library/loggers/lumberjack/file/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
// ------------------------

implementation(libs.kotlin)
implementation(libs.kotlin.coroutines)
implementation(libs.kotlinx.coroutines)

// ------------------------
// Library
Expand Down
2 changes: 1 addition & 1 deletion library/loggers/timber/file/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
// ------------------------

implementation(libs.kotlin)
implementation(libs.kotlin.coroutines)
implementation(libs.kotlinx.coroutines)

// ------------------------
// Library
Expand Down
24 changes: 1 addition & 23 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ dependencyResolutionManagement {
maven("https://jitpack.io")
}
versionCatalogs {

val kotlin = "1.9.23"
val ksp = "1.9.23-1.0.20"
val coroutines = "1.7.3"
val gradle = "8.3.1"

// TOML Files
create("androidx") {
from(files("gradle/androidx.versions.toml"))
}
Expand All @@ -22,23 +15,8 @@ dependencyResolutionManagement {
create("compose") {
from(files("gradle/compose.versions.toml"))
}

// Rest
create("tools") {
version("kotlin", kotlin)
version("gradle", gradle)
version("ksp", ksp)
}
create("app") {
version("compileSdk", "34")
version("minSdk", "21")
version("targetSdk", "34")
}
create("libs") {
// Kotlin
library("kotlin", "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin")
library("kotlin.coroutines", "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines")
library("kotlin.reflect", "org.jetbrains.kotlin:kotlin-reflect:$kotlin")
from(files("gradle/app.versions.toml"))
}
}
}
Expand Down

0 comments on commit dcabfbc

Please sign in to comment.