Skip to content

Commit

Permalink
Merge pull request #24 from jkj8790/feature/improve-visual
Browse files Browse the repository at this point in the history
Feature/improve visual
  • Loading branch information
jerry-jeon authored Jun 4, 2023
2 parents 90477c2 + e88c260 commit 81f5142
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 399 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 30 additions & 11 deletions src/main/kotlin/com/jerryjeon/logjerry/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.*
import androidx.compose.ui.window.MenuBar
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import com.jerryjeon.logjerry.log.Log
import com.jerryjeon.logjerry.parse.ParseStatus
import com.jerryjeon.logjerry.preferences.ColorTheme
Expand Down Expand Up @@ -106,6 +109,7 @@ private fun GettingStartedView(notStarted: ParseStatus.NotStarted, changeSource:
?.let { changeSource(Source.Text(it.toString())) }
true
}

else -> {
false
}
Expand Down Expand Up @@ -296,16 +300,31 @@ private fun TabView(tabs: Tabs, activate: (Tab) -> Unit, close: (Tab) -> Unit) {
val scrollState = rememberScrollState()
Row(modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min).horizontalScroll(scrollState)) {
tabList.forEach { tab ->
Row(
modifier = Modifier
.background(if (tab === activated) MaterialTheme.colors.secondary else Color.Transparent)
.clickable { activate(tab) }
.padding(8.dp)
) {
Text(tab.name, modifier = Modifier.align(Alignment.CenterVertically), style = MaterialTheme.typography.body2)
Spacer(Modifier.width(8.dp))
IconButton(modifier = Modifier.size(16.dp).align(Alignment.CenterVertically), onClick = { close(tab) }) {
Icon(Icons.Default.Close, "Close tab")
Column(modifier = Modifier.width(IntrinsicSize.Max).clickable { activate(tab) }) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 12.dp, end = 12.dp, top = 12.dp)
) {
Text(
tab.name,
modifier = Modifier.align(Alignment.CenterVertically),
style = MaterialTheme.typography.body2,
maxLines = 1
)
Spacer(Modifier.width(8.dp))
IconButton(
modifier = Modifier.size(16.dp).align(Alignment.CenterVertically),
onClick = { close(tab) }
) {
Icon(Icons.Default.Close, "Close tab")
}
}
if (tab === activated) {
Box(modifier = Modifier.fillMaxWidth().height(7.dp))
Divider(modifier = Modifier.fillMaxWidth().height(5.dp), color = MaterialTheme.colors.primary)
} else {
Box(modifier = Modifier.fillMaxWidth().height(12.dp))
}
}
Divider(modifier = Modifier.fillMaxHeight().width(1.dp))
Expand Down
33 changes: 33 additions & 0 deletions src/main/kotlin/com/jerryjeon/logjerry/log/Log.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package com.jerryjeon.logjerry.log

import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.DateTimeFormatter

data class Log(
val number: Int,
val date: String?,
Expand All @@ -12,6 +19,32 @@ data class Log(
) {
val index = number - 1
val priority = Priority.find(priorityText)

val localDateTime: LocalDateTime?
get() = try {
if (date != null && time != null) {
LocalDateTime.parse("$date $time", formatter)
} else if (time != null) {
// Assume date is today.
LocalTime.parse(time, timeFormatter).atDate(LocalDate.now())
} else {
null
}
} catch (e: Exception) {
e.printStackTrace()
null
}

fun durationBetween(other: Log): Duration? {
val thisLocalDateTime = localDateTime ?: return null
val otherLocalDateTime = other.localDateTime ?: return null
return Duration.between(thisLocalDateTime, otherLocalDateTime)
}

companion object {
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
val timeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")
}
}

enum class Priority(val text: String, val fullText: String, val level: Int) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/com/jerryjeon/logjerry/log/ParseCompleted.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ParseCompleted(
detectionFinishedFlow
) { filteredLogs, detectionFinished ->
val allDetections = mutableMapOf<DetectorKey, List<Detection>>()
var lastRefinedLog: RefinedLog? = null
val refinedLogs = filteredLogs.map { log ->
val detections = detectionFinished.detectionsByLog[log] ?: emptyMap()
detections.forEach { (key, newValue) ->
Expand All @@ -69,7 +70,10 @@ class ParseCompleted(
// TODO don't want to repeat all annotate if just one log has changed. How can I achieve it
val logContents =
LogAnnotation.separateAnnotationStrings(log, detections.values.flatten())
RefinedLog(log, detections, LogAnnotation.annotate(log, logContents, detectionFinished.detectors))
val timeGap = lastRefinedLog?.log?.durationBetween(log)?.takeIf { it.toSeconds() >= 3 }
RefinedLog(log, detections, LogAnnotation.annotate(log, logContents, detectionFinished.detectors), timeGap).also {
lastRefinedLog = it
}
}
RefineResult(refinedLogs, allDetections)
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/com/jerryjeon/logjerry/logview/MarkInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.jerryjeon.logjerry.logview

sealed class MarkInfo {
class Marked(
val markedLog: RefinedLog,
) : MarkInfo()

class StatBetweenMarks(
val logCount: Int,
val duration: String?, // ex) 1h 2m 3s, and null if it's not able to calculate
) : MarkInfo()
}
40 changes: 36 additions & 4 deletions src/main/kotlin/com/jerryjeon/logjerry/logview/RefineResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.jerryjeon.logjerry.logview
import com.jerryjeon.logjerry.detector.Detection
import com.jerryjeon.logjerry.detector.DetectionStatus
import com.jerryjeon.logjerry.detector.DetectorKey
import com.jerryjeon.logjerry.detector.MarkDetection
import com.jerryjeon.logjerry.ui.focus.DetectionFocus
import com.jerryjeon.logjerry.ui.focus.LogFocus
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -13,8 +12,6 @@ data class RefineResult(
val refinedLogs: List<RefinedLog>,
val allDetections: Map<DetectorKey, List<Detection>>
) {
val markedRows = refinedLogs.filter { it.marked }

val currentFocus = MutableStateFlow<LogFocus?>(null)

val statusByKey = MutableStateFlow(
Expand All @@ -28,6 +25,41 @@ data class RefineResult(
}
)

val markInfos: List<MarkInfo>

init {
val markedLogs = refinedLogs.filter { it.marked }
markInfos = if (markedLogs.isEmpty()) {
emptyList()
} else {
val markInfos = mutableListOf<MarkInfo>()
markedLogs
.scan(refinedLogs.first()) { prevRefinedLog, refinedLog ->
val duration = prevRefinedLog.durationBetween(refinedLog)
markInfos.add(
MarkInfo.StatBetweenMarks(
logCount = refinedLogs.indexOf(refinedLog) - refinedLogs.indexOf(prevRefinedLog),
duration = duration?.toHumanReadable()
)
)
markInfos.add(MarkInfo.Marked(refinedLog))
refinedLog
}

val lastLog = refinedLogs.last()
val lastMarkedLogs = markedLogs.last()
val duration = lastMarkedLogs.durationBetween(lastLog)

markInfos.add(
MarkInfo.StatBetweenMarks(
logCount = refinedLogs.indexOf(lastLog) - refinedLogs.indexOf(lastMarkedLogs),
duration = duration?.toHumanReadable()
)
)
markInfos
}
}

fun selectPreviousDetection(status: DetectionStatus) {
val previousIndex = if (status.currentIndex <= 0) {
status.allDetections.size - 1
Expand Down Expand Up @@ -68,7 +100,7 @@ data class RefineResult(
statusByKey.value[key]?.let { selectNextDetection(it) }
}

fun selectDetection(detection: MarkDetection) {
fun selectDetection(detection: Detection) {
statusByKey.update {
val status = it[detection.key] ?: return@update it
val index = status.allDetections.indexOf(detection)
Expand Down
26 changes: 25 additions & 1 deletion src/main/kotlin/com/jerryjeon/logjerry/logview/RefinedLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,36 @@ import com.jerryjeon.logjerry.detector.DetectorKey
import com.jerryjeon.logjerry.detector.MarkDetection
import com.jerryjeon.logjerry.log.Log
import com.jerryjeon.logjerry.log.LogContentView
import java.time.Duration

class RefinedLog(
val log: Log,
val detections: Map<DetectorKey, List<Detection>>,
val logContentViews: List<LogContentView>
val logContentViews: List<LogContentView>,
val timeGap: Duration?
) {
val mark = detections[DetectorKey.Mark]?.firstOrNull() as? MarkDetection
val marked = mark != null

fun durationBetween(other: RefinedLog): Duration? {
return this.log.durationBetween(other.log)
}
}

fun Duration.toHumanReadable(): String {
val hours: Long = toHours()
val minutes: Long = toMinutes() % 60
val seconds: Long = seconds % 60

return when {
hours > 0 -> {
"${hours}h ${minutes}m ${seconds}s"
}
minutes > 0 -> {
"${minutes}m ${seconds}s"
}
else -> {
"${toMillis()}ms"
}
}
}
53 changes: 53 additions & 0 deletions src/main/kotlin/com/jerryjeon/logjerry/ui/AppliedTextFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.jerryjeon.logjerry.ui

import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.jerryjeon.logjerry.filter.TextFilter

@Composable
fun AppliedTextFilter(textFilter: TextFilter, removeFilter: (TextFilter) -> Unit) {
Box(
Modifier
.padding(horizontal = 4.dp, vertical = 8.dp)
.border(1.dp, Color.LightGray, RoundedCornerShape(8.dp))
) {
Row(modifier = Modifier.height(30.dp)) {
Spacer(Modifier.width(8.dp))
Text(
textFilter.columnType.text,
modifier = Modifier.align(Alignment.CenterVertically),
)
Spacer(Modifier.width(8.dp))
Divider(Modifier.width(1.dp).fillMaxHeight())
Spacer(Modifier.width(8.dp))
Text(textFilter.text, modifier = Modifier.align(Alignment.CenterVertically))
Spacer(Modifier.width(8.dp))
Box(
Modifier
.clickable { removeFilter(textFilter) }
.align(Alignment.CenterVertically)
.fillMaxHeight()
.aspectRatio(1f)
) {
Icon(
Icons.Default.Close,
contentDescription = "Remove a filter",
modifier = Modifier.size(ButtonDefaults.IconSize).align(Alignment.Center)
)
}
}
}
}
58 changes: 0 additions & 58 deletions src/main/kotlin/com/jerryjeon/logjerry/ui/DetectionView.kt

This file was deleted.

Loading

0 comments on commit 81f5142

Please sign in to comment.