Improved diff design
Also removed unecessary information and reduced font size to match better a desktop design
This commit is contained in:
parent
9e5627d5e9
commit
790845b3ec
@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import theme.primaryTextColor
|
import theme.primaryTextColor
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -37,28 +38,45 @@ fun Diff(gitManager: GitManager, diffEntryType: DiffEntryType, onCloseDiffView:
|
|||||||
) {
|
) {
|
||||||
Text("Close diff")
|
Text("Close diff")
|
||||||
}
|
}
|
||||||
val textLines = text.split("\n", "\r\n")
|
SelectionContainer {
|
||||||
LazyColumn(modifier = Modifier
|
LazyColumn(
|
||||||
.fillMaxSize()
|
modifier = Modifier
|
||||||
.padding(16.dp)) {
|
.fillMaxSize()
|
||||||
items(textLines) { line ->
|
.padding(16.dp)
|
||||||
val backgroundColor = if (line.startsWith("+")) {
|
) {
|
||||||
Color(0x77a9d49b)
|
items(text) { line ->
|
||||||
} else if (line.startsWith("-")) {
|
val isHunkLine = line.startsWith("@@") && line.endsWith("@@")
|
||||||
Color(0x77dea2a2)
|
|
||||||
} else {
|
val backgroundColor = when {
|
||||||
MaterialTheme.colors.surface
|
line.startsWith("+") -> {
|
||||||
}
|
Color(0x77a9d49b)
|
||||||
|
}
|
||||||
|
line.startsWith("-") -> {
|
||||||
|
Color(0x77dea2a2)
|
||||||
|
}
|
||||||
|
isHunkLine -> {
|
||||||
|
MaterialTheme.colors.background
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
MaterialTheme.colors.surface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val paddingTop = if (isHunkLine)
|
||||||
|
32.dp
|
||||||
|
else
|
||||||
|
0.dp
|
||||||
|
|
||||||
SelectionContainer {
|
|
||||||
Text(
|
Text(
|
||||||
text = line,
|
text = line,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
.padding(top = paddingTop)
|
||||||
.background(backgroundColor)
|
.background(backgroundColor)
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
color = MaterialTheme.colors.primaryTextColor,
|
color = MaterialTheme.colors.primaryTextColor,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
fontFamily = FontFamily.Monospace,
|
fontFamily = FontFamily.Monospace,
|
||||||
|
fontSize = 14.sp,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ class GitManager {
|
|||||||
val hasUncommitedChanges: StateFlow<Boolean>
|
val hasUncommitedChanges: StateFlow<Boolean>
|
||||||
get() = statusManager.hasUncommitedChanges
|
get() = statusManager.hasUncommitedChanges
|
||||||
|
|
||||||
fun diffFormat(diffEntryType: DiffEntryType): String {
|
fun diffFormat(diffEntryType: DiffEntryType): List<String> {
|
||||||
val diffEntry = diffEntryType.diffEntry
|
val diffEntry = diffEntryType.diffEntry
|
||||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
|
|
||||||
@ -144,7 +144,13 @@ class GitManager {
|
|||||||
formatter.flush()
|
formatter.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
return byteArrayOutputStream.toString(Charsets.UTF_8)
|
val diff = byteArrayOutputStream.toString(Charsets.UTF_8)
|
||||||
|
|
||||||
|
// TODO This is just a workaround, try to find properly which lines have to be displayed by using a custom diff
|
||||||
|
|
||||||
|
return diff.split("\n", "\r\n").filterNot {
|
||||||
|
it.startsWith("diff --git")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pull() = managerScope.launch {
|
fun pull() = managerScope.launch {
|
||||||
|
Loading…
Reference in New Issue
Block a user