-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from tberchanov/highlight_details_stacktrace
Highlight stacktrace items on detail screen.
- Loading branch information
Showing
10 changed files
with
192 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
strictpro-ui/src/main/java/com/strictpro/ui/domain/usecase/FilterStackTraceUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.strictpro.ui.domain.usecase | ||
|
||
internal class FilterStackTraceUseCase( | ||
private val getAppPackageNameUseCase: GetAppPackageNameUseCase, | ||
) { | ||
|
||
private val packageName by lazy { getAppPackageNameUseCase.execute() } | ||
|
||
fun execute(stackTrace: Array<StackTraceElement>): List<StackTraceElement> { | ||
return stackTrace.filter { | ||
it.className.startsWith(packageName) | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
strictpro-ui/src/main/java/com/strictpro/ui/presentation/ui/common/StackTrace.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.strictpro.ui.presentation.ui.common | ||
|
||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.onGloballyPositioned | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.font.FontWeight.Companion | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
internal fun StackTraceItems( | ||
stackTraceItems: List<String>, | ||
modifier: Modifier = Modifier, | ||
cutLast: Boolean = false, | ||
highlightPredicate: (String) -> Boolean = { false }, | ||
) { | ||
val localDensity = LocalDensity.current | ||
Column(modifier = modifier) { | ||
stackTraceItems.forEach { item -> | ||
var columnHeightDp by remember { | ||
mutableStateOf(0.dp) | ||
} | ||
Row( | ||
modifier = Modifier | ||
.onGloballyPositioned { coordinates -> | ||
columnHeightDp = with(localDensity) { coordinates.size.height.toDp() } | ||
} | ||
.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
StackTraceItemMarker( | ||
cutBottom = cutLast && stackTraceItems.last() == item, | ||
modifier = Modifier | ||
.size(width = 30.dp, height = columnHeightDp) | ||
.padding(end = 8.dp), | ||
) | ||
val isHighlighted = remember(item) { highlightPredicate(item) } | ||
Text( | ||
modifier = Modifier.padding(vertical = 4.dp), | ||
fontWeight = if (isHighlighted) FontWeight.Bold else Companion.Normal, | ||
text = item, | ||
color = Color.White, | ||
fontSize = if (isHighlighted) 14.sp else 12.sp, | ||
lineHeight = 14.sp | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun StackTraceItemsPreview() { | ||
StackTraceItems( | ||
cutLast = true, | ||
stackTraceItems = listOf( | ||
"violation1", | ||
"violation2", | ||
"violation3", | ||
"violation4", | ||
), | ||
highlightPredicate = { it == "violation2" }, | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun StackTraceItemMarkerPreview() { | ||
StackTraceItemMarker(modifier = Modifier.size(240.dp), cutBottom = true) | ||
} | ||
|
||
@Composable | ||
internal fun StackTraceItemMarker( | ||
cutBottom: Boolean = false, | ||
modifier: Modifier = Modifier, | ||
color: Color = Color.Red, | ||
thickness: Dp = 2.dp, | ||
) { | ||
val cutBottomCoefficient = if (cutBottom) 2 else 1 | ||
Canvas(modifier = modifier) { | ||
drawLine( | ||
color = color, | ||
start = Offset(thickness.toPx(), 0F), | ||
end = Offset(thickness.toPx(), size.height / cutBottomCoefficient), | ||
strokeWidth = thickness.toPx(), | ||
) | ||
drawLine( | ||
color = color, | ||
start = Offset(thickness.toPx(), size.height / 2), | ||
end = Offset(size.width, size.height / 2), | ||
strokeWidth = thickness.toPx(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
...ain/java/com/strictpro/ui/presentation/violations/history/model/ViolationHistoryItemUI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,9 @@ | ||
package com.strictpro.ui.presentation.violations.history.model | ||
|
||
import android.os.Build.VERSION | ||
import android.os.Build.VERSION_CODES | ||
import android.os.strictmode.Violation | ||
import com.strictpro.ui.domain.model.StrictProViolation | ||
import com.strictpro.ui.domain.model.getViolationName | ||
import com.strictpro.ui.presentation.violations.history.util.formatViolationDate | ||
|
||
data class ViolationHistoryItemUI( | ||
val dateMillis: Long, | ||
val formattedDate: String, | ||
val violationName: String, | ||
val filteredStackTraceItems: List<String>, | ||
val violationId: String, | ||
) | ||
|
||
fun StrictProViolation.toViolationHistoryItemUI(packageName: String): ViolationHistoryItemUI { | ||
val formattedDate = formatViolationDate(dateMillis) | ||
val filteredStackTraceItems = if (VERSION.SDK_INT >= VERSION_CODES.P) { | ||
violation.stackTrace | ||
.filter { | ||
it.className.startsWith(packageName) | ||
} | ||
.take(3) | ||
.map { it.toString() } | ||
} else { | ||
emptyList() | ||
} | ||
|
||
return ViolationHistoryItemUI( | ||
dateMillis = dateMillis, | ||
formattedDate = formattedDate, | ||
violationName = getViolationName(), | ||
filteredStackTraceItems = filteredStackTraceItems, | ||
violationId = id, | ||
) | ||
} |
Oops, something went wrong.