Now uncommited changes shows which diff entry has been clicked

Also refactored selected index from commit changes to use the same logic as uncommited changes
This commit is contained in:
Abdelilah El Aissaoui 2022-02-24 15:41:10 +01:00
parent 970132f1d7
commit dd56ccf2fc
3 changed files with 42 additions and 29 deletions

View File

@ -3,6 +3,7 @@ package app.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.SelectionContainer
@ -18,6 +19,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import app.extensions.*
import app.git.DiffEntryType
import app.theme.*
import app.ui.components.AvatarImage
import app.ui.components.ScrollableLazyColumn
@ -30,8 +32,9 @@ import org.eclipse.jgit.revwalk.RevCommit
@Composable
fun CommitChanges(
commitChangesViewModel: CommitChangesViewModel,
selectedItem: SelectedItem.CommitBasedItem,
onDiffSelected: (DiffEntry) -> Unit,
selectedItem: SelectedItem.CommitBasedItem
diffSelected: DiffEntryType?
) {
LaunchedEffect(selectedItem) {
commitChangesViewModel.loadChanges(selectedItem.revCommit)
@ -45,6 +48,7 @@ fun CommitChanges(
}
is CommitChangesStatus.Loaded -> {
CommitChangesView(
diffSelected = diffSelected,
commit = commitChangesStatus.commit,
changes = commitChangesStatus.changes,
onDiffSelected = onDiffSelected,
@ -57,7 +61,8 @@ fun CommitChanges(
fun CommitChangesView(
commit: RevCommit,
changes: List<DiffEntry>,
onDiffSelected: (DiffEntry) -> Unit
onDiffSelected: (DiffEntry) -> Unit,
diffSelected: DiffEntryType?
) {
Column(
modifier = Modifier
@ -110,7 +115,11 @@ fun CommitChangesView(
)
CommitLogChanges(changes, onDiffSelected = onDiffSelected)
CommitLogChanges(
diffSelected = diffSelected,
diffEntries = changes,
onDiffSelected = onDiffSelected
)
}
}
}
@ -175,18 +184,20 @@ fun Author(commit: RevCommit) {
}
@Composable
fun CommitLogChanges(diffEntries: List<DiffEntry>, onDiffSelected: (DiffEntry) -> Unit) {
val selectedIndex = remember(diffEntries) { mutableStateOf(-1) }
fun CommitLogChanges(
diffEntries: List<DiffEntry>,
onDiffSelected: (DiffEntry) -> Unit,
diffSelected: DiffEntryType?
) {
ScrollableLazyColumn(
modifier = Modifier
.fillMaxSize()
) {
itemsIndexed(items = diffEntries) { index, diffEntry ->
items(items = diffEntries) { diffEntry ->
val textColor: Color
val secondaryTextColor: Color
if (selectedIndex.value == index) {
if (diffSelected?.diffEntry == diffEntry) {
textColor = MaterialTheme.colors.primary
secondaryTextColor = MaterialTheme.colors.halfPrimary
} else {
@ -199,7 +210,6 @@ fun CommitLogChanges(diffEntries: List<DiffEntry>, onDiffSelected: (DiffEntry) -
.height(40.dp)
.fillMaxWidth()
.clickable {
selectedIndex.value = index
onDiffSelected(diffEntry)
},
verticalArrangement = Arrangement.Center,

View File

@ -132,6 +132,7 @@ fun RepositoryOpenPage(tabViewModel: TabViewModel) {
CommitChanges(
commitChangesViewModel = tabViewModel.commitChangesViewModel,
selectedItem = safeSelectedItem,
diffSelected = diffSelected,
onDiffSelected = { diffEntry ->
tabViewModel.newDiffSelected = DiffEntryType.CommitDiff(diffEntry)
}

View File

@ -32,9 +32,8 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import app.extensions.fileName
import app.extensions.filePath
import app.extensions.parentDirectoryPath
import app.extensions.isMerging
import app.extensions.parentDirectoryPath
import app.git.DiffEntryType
import app.git.StatusEntry
import app.theme.*
@ -110,6 +109,7 @@ fun UncommitedChanges(
title = "Staged",
allActionTitle = "Unstage all",
actionTitle = "Unstage",
selectedEntryType = selectedEntryType,
actionColor = MaterialTheme.colors.unstageButton,
diffEntries = staged,
onDiffEntrySelected = onStagedDiffEntrySelected,
@ -153,10 +153,11 @@ fun UncommitedChanges(
}
)
},
allActionTitle = "Stage all",
onAllAction = {
statusViewModel.stageAll()
}
},
allActionTitle = "Stage all",
selectedEntryType = selectedEntryType
)
Column(
@ -223,7 +224,6 @@ fun UncommitedChangesButtons(
) {
var showDropDownMenu by remember { mutableStateOf(false) }
Row(
modifier = Modifier
.padding(top = 2.dp)
@ -237,19 +237,6 @@ fun UncommitedChangesButtons(
enabled = canCommit,
shape = MaterialTheme.shapes.small.copy(topEnd = CornerSize(0.dp), bottomEnd = CornerSize(0.dp))
)
// Button(
// modifier = Modifier
// .weight(1f)
// .height(40.dp),
// onClick = { onCommit(false) },
// enabled = canCommit,
// shape = RectangleShape,
// ) {
// Text(
// text = "Commit",
// fontSize = 14.sp,
// )
// }
Spacer(
modifier = Modifier
.width(1.dp)
@ -454,6 +441,7 @@ private fun EntriesList(
onGenerateContextMenu: (DiffEntry) -> List<ContextMenuItem>,
onAllAction: () -> Unit,
allActionTitle: String,
selectedEntryType: DiffEntryType?,
) {
Column(
modifier = modifier
@ -487,8 +475,10 @@ private fun EntriesList(
) {
itemsIndexed(diffEntries) { index, statusEntry ->
val diffEntry = statusEntry.diffEntry
val isEntrySelected = selectedEntryType?.diffEntry == diffEntry
FileEntry(
statusEntry = statusEntry,
isSelected = isEntrySelected,
actionTitle = actionTitle,
actionColor = actionColor,
onClick = {
@ -515,6 +505,7 @@ private fun EntriesList(
@Composable
private fun FileEntry(
statusEntry: StatusEntry,
isSelected: Boolean,
actionTitle: String,
actionColor: Color,
onClick: () -> Unit,
@ -524,6 +515,17 @@ private fun FileEntry(
var active by remember { mutableStateOf(false) }
val diffEntry = statusEntry.diffEntry
val textColor: Color
val secondaryTextColor: Color
if (isSelected) {
textColor = MaterialTheme.colors.primary
secondaryTextColor = MaterialTheme.colors.halfPrimary
} else {
textColor = MaterialTheme.colors.primaryTextColor
secondaryTextColor = MaterialTheme.colors.secondaryTextColor
}
Box(
modifier = Modifier
.clickable { onClick() }
@ -567,7 +569,7 @@ private fun FileEntry(
softWrap = false,
fontSize = 13.sp,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colors.secondaryTextColor,
color = secondaryTextColor,
)
Text(
text = diffEntry.fileName,
@ -575,7 +577,7 @@ private fun FileEntry(
maxLines = 1,
softWrap = false,
fontSize = 13.sp,
color = MaterialTheme.colors.primaryTextColor,
color = textColor,
)
}
}