Added author to commit and UI improvements
This commit is contained in:
parent
3ad0d12503
commit
67d410fd12
176
src/main/kotlin/CommitChanges.kt
Normal file
176
src/main/kotlin/CommitChanges.kt
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
import androidx.compose.foundation.*
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.material.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
|
import androidx.compose.ui.res.useResource
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import extensions.filePath
|
||||||
|
import extensions.icon
|
||||||
|
import extensions.md5
|
||||||
|
import extensions.toByteArray
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import org.eclipse.jgit.diff.DiffEntry
|
||||||
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
|
import org.jetbrains.skija.Image.makeFromEncoded
|
||||||
|
import theme.backgroundColorLight
|
||||||
|
import theme.primaryTextColor
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CommitChanges(commitDiff: Pair<RevCommit, List<DiffEntry>>, onDiffSelected: (DiffEntry) -> Unit) {
|
||||||
|
val commit = commitDiff.first
|
||||||
|
val diff = commitDiff.second
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colors.background),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(all = 8.dp)
|
||||||
|
.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
val scroll = rememberScrollState(0)
|
||||||
|
Text(
|
||||||
|
text = commit.fullMessage,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(8.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(MaterialTheme.colors.surface)
|
||||||
|
.height(120.dp)
|
||||||
|
.verticalScroll(scroll),
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(horizontal = 8.dp, vertical = 8.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(72.dp)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
val url = "https://www.gravatar.com/avatar/${commit.authorIdent.emailAddress.md5}"
|
||||||
|
Image(
|
||||||
|
bitmap = rememberNetworkImage(url),
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(horizontal = 16.dp)
|
||||||
|
.height(40.dp)
|
||||||
|
.clip(CircleShape),
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize(),
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
Text(commit.authorIdent.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CommitLogChanges(diff, onDiffSelected = onDiffSelected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun loadImage(link: String): ByteArray = withContext(Dispatchers.IO) {
|
||||||
|
val url = URL(link)
|
||||||
|
val connection = url.openConnection() as HttpURLConnection
|
||||||
|
connection.connect()
|
||||||
|
|
||||||
|
connection.inputStream.toByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun rememberNetworkImage(url: String): ImageBitmap {
|
||||||
|
var image by remember(url) {
|
||||||
|
mutableStateOf<ImageBitmap>(
|
||||||
|
useResource("image.jpg") {
|
||||||
|
makeFromEncoded(it.toByteArray()).asImageBitmap()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(url) {
|
||||||
|
loadImage(url).let {
|
||||||
|
image = makeFromEncoded(it).asImageBitmap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return image
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CommitLogChanges(diffEntries: List<DiffEntry>, onDiffSelected: (DiffEntry) -> Unit) {
|
||||||
|
val selectedIndex = remember(diffEntries) { mutableStateOf(-1) }
|
||||||
|
|
||||||
|
LazyColumn(
|
||||||
|
modifier = Modifier
|
||||||
|
.background(backgroundColorLight)
|
||||||
|
.fillMaxSize()
|
||||||
|
) {
|
||||||
|
itemsIndexed(items = diffEntries) { index, diffEntry ->
|
||||||
|
val textColor = if (selectedIndex.value == index) {
|
||||||
|
MaterialTheme.colors.primary
|
||||||
|
} else
|
||||||
|
MaterialTheme.colors.primaryTextColor
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.height(56.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable {
|
||||||
|
selectedIndex.value = index
|
||||||
|
onDiffSelected(diffEntry)
|
||||||
|
},
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
) {
|
||||||
|
Spacer(modifier = Modifier.weight(2f))
|
||||||
|
|
||||||
|
|
||||||
|
Row {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(start = 16.dp)
|
||||||
|
.size(24.dp),
|
||||||
|
imageVector = diffEntry.icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colors.primary,
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = diffEntry.filePath,
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp),
|
||||||
|
color = textColor,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.weight(2f))
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,10 +13,8 @@ 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.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import extensions.filePath
|
import extensions.filePath
|
||||||
import extensions.icon
|
|
||||||
import git.LogStatus
|
import git.LogStatus
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.diff.DiffEntry
|
import org.eclipse.jgit.diff.DiffEntry
|
||||||
@ -26,7 +24,7 @@ import org.eclipse.jgit.revwalk.RevTree
|
|||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
import org.eclipse.jgit.treewalk.AbstractTreeIterator
|
import org.eclipse.jgit.treewalk.AbstractTreeIterator
|
||||||
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
||||||
import theme.backgroundColor
|
import theme.backgroundColorLight
|
||||||
import theme.primaryTextColor
|
import theme.primaryTextColor
|
||||||
import theme.secondaryTextColor
|
import theme.secondaryTextColor
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -170,22 +168,6 @@ fun prepareTreeParser(repository: Repository, commit: RevCommit): AbstractTreeIt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun CommitChanges(commitDiff: Pair<RevCommit, List<DiffEntry>>, onDiffSelected: (DiffEntry) -> Unit) {
|
|
||||||
val commit = commitDiff.first
|
|
||||||
val diff = commitDiff.second
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize(),
|
|
||||||
) {
|
|
||||||
Text(commit.fullMessage)
|
|
||||||
Text(commit.commitTime.toString())
|
|
||||||
|
|
||||||
CommitLogChanges(diff, onDiffSelected = onDiffSelected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Log(
|
fun Log(
|
||||||
gitManager: GitManager,
|
gitManager: GitManager,
|
||||||
@ -207,7 +189,7 @@ fun Log(
|
|||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(backgroundColor)
|
.background(MaterialTheme.colors.surface)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
if (gitManager.hasUncommitedChanges())
|
if (gitManager.hasUncommitedChanges())
|
||||||
@ -282,59 +264,4 @@ fun Log(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun CommitLogChanges(diffEntries: List<DiffEntry>, onDiffSelected: (DiffEntry) -> Unit) {
|
|
||||||
val selectedIndex = remember(diffEntries) { mutableStateOf(-1) }
|
|
||||||
|
|
||||||
LazyColumn(
|
|
||||||
modifier = Modifier
|
|
||||||
.background(backgroundColor)
|
|
||||||
.fillMaxSize()
|
|
||||||
) {
|
|
||||||
itemsIndexed(items = diffEntries) { index, diffEntry ->
|
|
||||||
val textColor = if (selectedIndex.value == index) {
|
|
||||||
MaterialTheme.colors.primary
|
|
||||||
} else
|
|
||||||
MaterialTheme.colors.primaryTextColor
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.height(56.dp)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
selectedIndex.value = index
|
|
||||||
onDiffSelected(diffEntry)
|
|
||||||
},
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
) {
|
|
||||||
Spacer(modifier = Modifier.weight(2f))
|
|
||||||
|
|
||||||
|
|
||||||
Row {
|
|
||||||
Icon(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(start = 16.dp)
|
|
||||||
.size(24.dp),
|
|
||||||
imageVector = diffEntry.icon,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colors.primary,
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = diffEntry.filePath,
|
|
||||||
modifier = Modifier.padding(horizontal = 16.dp),
|
|
||||||
color = textColor,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.weight(2f))
|
|
||||||
|
|
||||||
Divider()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
12
src/main/kotlin/extensions/InputStreamExtensions.kt
Normal file
12
src/main/kotlin/extensions/InputStreamExtensions.kt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package extensions
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
fun InputStream.toByteArray(): ByteArray {
|
||||||
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
|
return byteArrayOutputStream.use { byteArrayOutStream ->
|
||||||
|
this.transferTo(byteArrayOutStream)
|
||||||
|
byteArrayOutStream.toByteArray()
|
||||||
|
}
|
||||||
|
}
|
10
src/main/kotlin/extensions/StringExtensions.kt
Normal file
10
src/main/kotlin/extensions/StringExtensions.kt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package extensions
|
||||||
|
|
||||||
|
import java.math.BigInteger
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
|
val String.md5: String
|
||||||
|
get() {
|
||||||
|
val md = MessageDigest.getInstance("MD5")
|
||||||
|
return BigInteger(1, md.digest(this.toByteArray())).toString(16).padStart(32, '0')
|
||||||
|
}
|
@ -14,4 +14,6 @@ val errorColor = Color(0xFFFA4B4B)
|
|||||||
val primaryGrayLight = Color(0xFF464646)
|
val primaryGrayLight = Color(0xFF464646)
|
||||||
val accentGrayLight = Color(0xFFCCCCCC)
|
val accentGrayLight = Color(0xFFCCCCCC)
|
||||||
|
|
||||||
val backgroundColor = Color(0xFFf9f9f9)
|
//val backgroundColorLight = Color(0xFFE8E8E8)
|
||||||
|
val backgroundColorLight = Color(0xFFC2C2C2)
|
||||||
|
val surfaceColorLight = Color(0xFFf9f9f9)
|
@ -14,7 +14,8 @@ private val LightColorPalette = lightColors(
|
|||||||
primary = primary,
|
primary = primary,
|
||||||
primaryVariant = primaryDark,
|
primaryVariant = primaryDark,
|
||||||
secondary = secondary,
|
secondary = secondary,
|
||||||
background = backgroundColor,
|
background = backgroundColorLight,
|
||||||
|
surface = surfaceColorLight,
|
||||||
error = errorColor
|
error = errorColor
|
||||||
/* Other default colors to override
|
/* Other default colors to override
|
||||||
|
|
||||||
|
BIN
src/main/resources/image.jpg
Normal file
BIN
src/main/resources/image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
Loading…
Reference in New Issue
Block a user