UI improvements + code cleanup in side panels

This commit is contained in:
Abdelilah El Aissaoui 2022-02-02 20:24:22 +01:00
parent 13684e4f90
commit dabdaca3b1
11 changed files with 104 additions and 83 deletions

View File

@ -1,3 +0,0 @@
package app
const val MAX_SIDE_PANEL_ITEMS_HEIGHT = 300

View File

@ -0,0 +1,13 @@
package app
const val MAX_SIDE_PANEL_ITEMS_HEIGHT = 300
const val ENTRY_HEIGHT = 40
fun maxSidePanelHeight(itemsCount: Int): Int {
val itemsHeight = itemsCount * ENTRY_HEIGHT
return if (itemsHeight < MAX_SIDE_PANEL_ITEMS_HEIGHT)
itemsHeight
else
MAX_SIDE_PANEL_ITEMS_HEIGHT
}

View File

@ -19,7 +19,8 @@ val backgroundColorDark = Color(0xFF0E1621)
val surfaceColorLight = Color(0xFFe9ecf7) val surfaceColorLight = Color(0xFFe9ecf7)
val surfaceColorDark = Color(0xFF182533) val surfaceColorDark = Color(0xFF182533)
val headerBackgroundLight = Color(0xFFF4F6FA) val headerBackgroundLight = Color(0xFFF4F6FA)
val headerBackgroundDark = Color(0xFF303132) val graphHeaderBackgroundDark = Color(0xFF303132)
val headerBackgroundDark = Color(0xFF0a2b4a)
val addFileLight = Color(0xFF32A852) val addFileLight = Color(0xFF32A852)
val deleteFileLight = errorColor val deleteFileLight = errorColor

View File

@ -53,18 +53,6 @@ val Colors.inversePrimaryTextColor: Color
val Colors.secondaryTextColor: Color val Colors.secondaryTextColor: Color
get() = if (isLight) secondaryText else secondaryTextDark get() = if (isLight) secondaryText else secondaryTextDark
@get:Composable
val Colors.accent: Color
get() = primaryLight
@get:Composable
val Colors.primaryGray: Color
get() = primaryGrayLight
@get:Composable
val Colors.accentGray: Color
get() = accentGrayLight
@get:Composable @get:Composable
val Colors.headerBackground: Color val Colors.headerBackground: Color
get() { get() {
@ -74,6 +62,15 @@ val Colors.headerBackground: Color
headerBackgroundDark headerBackgroundDark
} }
@get:Composable
val Colors.graphHeaderBackground: Color
get() {
return if (isLight)
headerBackgroundLight
else
graphHeaderBackgroundDark
}
@get:Composable @get:Composable
val Colors.addFile: Color val Colors.addFile: Color
get() = addFileLight get() = addFileLight

View File

@ -2,7 +2,11 @@ package app.ui
import androidx.compose.foundation.ContextMenuArea import androidx.compose.foundation.ContextMenuArea
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.* import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
@ -10,13 +14,12 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import app.MAX_SIDE_PANEL_ITEMS_HEIGHT
import app.extensions.isLocal import app.extensions.isLocal
import app.extensions.simpleName import app.extensions.simpleName
import app.maxSidePanelHeight
import app.ui.components.ScrollableLazyColumn import app.ui.components.ScrollableLazyColumn
import app.ui.components.SideMenuEntry import app.ui.components.SideMenuEntry
import app.ui.components.SideMenuSubentry import app.ui.components.SideMenuSubentry
import app.ui.components.entryHeight
import app.ui.context_menu.branchContextMenuItems import app.ui.context_menu.branchContextMenuItems
import app.ui.dialogs.MergeDialog import app.ui.dialogs.MergeDialog
import app.ui.dialogs.RebaseDialog import app.ui.dialogs.RebaseDialog
@ -32,29 +35,27 @@ fun Branches(
val currentBranch by branchesViewModel.currentBranch.collectAsState() val currentBranch by branchesViewModel.currentBranch.collectAsState()
val (mergeBranch, setMergeBranch) = remember { mutableStateOf<Ref?>(null) } val (mergeBranch, setMergeBranch) = remember { mutableStateOf<Ref?>(null) }
val (rebaseBranch, setRebaseBranch) = remember { mutableStateOf<Ref?>(null) } val (rebaseBranch, setRebaseBranch) = remember { mutableStateOf<Ref?>(null) }
val maxHeight = remember(branches) { maxSidePanelHeight(branches.count()) }
Column { Column {
SideMenuEntry("Local branches") SideMenuEntry("Local branches")
val branchesHeight = branches.count() * entryHeight ScrollableLazyColumn(
val maxHeight = if (branchesHeight < MAX_SIDE_PANEL_ITEMS_HEIGHT) modifier = Modifier
branchesHeight .fillMaxWidth()
else .heightIn(max = maxHeight.dp)
MAX_SIDE_PANEL_ITEMS_HEIGHT .background(MaterialTheme.colors.background)
) {
Box(modifier = Modifier.heightIn(max = maxHeight.dp)) { itemsIndexed(branches) { _, branch ->
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) { BranchLineEntry(
itemsIndexed(branches) { _, branch -> branch = branch,
BranchLineEntry( isCurrentBranch = currentBranch == branch.name,
branch = branch, onBranchClicked = { onBranchClicked(branch) },
isCurrentBranch = currentBranch == branch.name, onCheckoutBranch = { branchesViewModel.checkoutRef(branch) },
onBranchClicked = { onBranchClicked(branch) }, onMergeBranch = { setMergeBranch(branch) },
onCheckoutBranch = { branchesViewModel.checkoutRef(branch) }, onRebaseBranch = { branchesViewModel.deleteBranch(branch) },
onMergeBranch = { setMergeBranch(branch) }, onDeleteBranch = { setRebaseBranch(branch) },
onRebaseBranch = { branchesViewModel.deleteBranch(branch) }, )
onDeleteBranch = { setRebaseBranch(branch) },
)
}
} }
} }
} }

View File

@ -1,45 +1,45 @@
package app.ui package app.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import app.MAX_SIDE_PANEL_ITEMS_HEIGHT
import app.extensions.simpleVisibleName import app.extensions.simpleVisibleName
import app.git.RemoteInfo import app.git.RemoteInfo
import app.maxSidePanelHeight
import app.ui.components.ScrollableLazyColumn import app.ui.components.ScrollableLazyColumn
import app.ui.components.SideMenuEntry import app.ui.components.SideMenuEntry
import app.ui.components.SideMenuSubentry import app.ui.components.SideMenuSubentry
import app.ui.components.entryHeight
import app.viewmodels.RemotesViewModel import app.viewmodels.RemotesViewModel
@Composable @Composable
fun Remotes(remotesViewModel: RemotesViewModel) { fun Remotes(remotesViewModel: RemotesViewModel) {
val remotes by remotesViewModel.remotes.collectAsState() val remotes by remotesViewModel.remotes.collectAsState()
val allBranches = remotes.map { it.branchesList }.flatten()
val maxHeight = remember(remotes) { maxSidePanelHeight(allBranches.count() + remotes.count()) }
Column { Column {
SideMenuEntry("Remotes") SideMenuEntry("Remotes")
val allBranches = remotes.map { it.branchesList }.flatten() ScrollableLazyColumn(
val remotesHeight = (allBranches.count() + remotes.count()) * entryHeight modifier = Modifier
val maxHeight = if (remotesHeight < MAX_SIDE_PANEL_ITEMS_HEIGHT) .fillMaxWidth()
remotesHeight .heightIn(max = maxHeight.dp)
else .background(MaterialTheme.colors.background)
MAX_SIDE_PANEL_ITEMS_HEIGHT ) {
items(remotes) { remote ->
Box(modifier = Modifier.heightIn(max = maxHeight.dp)) { RemoteRow(
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) { remote = remote,
items(remotes) { remote -> )
RemoteRow(
remote = remote,
)
}
} }
} }
} }

View File

@ -1,11 +1,17 @@
package app.ui package app.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import app.maxSidePanelHeight
import app.ui.components.ScrollableLazyColumn import app.ui.components.ScrollableLazyColumn
import app.ui.components.SideMenuEntry import app.ui.components.SideMenuEntry
import app.ui.components.SideMenuSubentry import app.ui.components.SideMenuSubentry
@ -26,13 +32,19 @@ fun Stashes(
else else
listOf() listOf()
val maxHeight = remember(stashList) { maxSidePanelHeight(stashList.count()) }
Column { Column {
SideMenuEntry( SideMenuEntry(
text = "Stashes", text = "Stashes",
) )
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) { ScrollableLazyColumn(
modifier = Modifier
.fillMaxWidth()
.heightIn(max = maxHeight.dp)
.background(MaterialTheme.colors.background)
) {
items(items = stashList) { stash -> items(items = stashList) { stash ->
StashRow( StashRow(
stash = stash, stash = stash,

View File

@ -2,21 +2,22 @@ package app.ui
import androidx.compose.foundation.ContextMenuArea import androidx.compose.foundation.ContextMenuArea
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import app.MAX_SIDE_PANEL_ITEMS_HEIGHT
import app.extensions.simpleName import app.extensions.simpleName
import app.maxSidePanelHeight
import app.ui.components.ScrollableLazyColumn import app.ui.components.ScrollableLazyColumn
import app.ui.components.SideMenuEntry import app.ui.components.SideMenuEntry
import app.ui.components.SideMenuSubentry import app.ui.components.SideMenuSubentry
import app.ui.components.entryHeight
import app.ui.context_menu.tagContextMenuItems import app.ui.context_menu.tagContextMenuItems
import app.viewmodels.TagsViewModel import app.viewmodels.TagsViewModel
import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Ref
@ -28,30 +29,29 @@ fun Tags(
) { ) {
val tagsState = tagsViewModel.tags.collectAsState() val tagsState = tagsViewModel.tags.collectAsState()
val tags = tagsState.value val tags = tagsState.value
val maxHeight = remember(tags) { maxSidePanelHeight(tags.count()) }
Column { Column {
SideMenuEntry( SideMenuEntry(
text = "Tags", text = "Tags",
) )
val tagsHeight = tags.count() * entryHeight ScrollableLazyColumn(
val maxHeight = if (tagsHeight < MAX_SIDE_PANEL_ITEMS_HEIGHT) modifier = Modifier
tagsHeight .fillMaxWidth()
else .heightIn(max = maxHeight.dp)
MAX_SIDE_PANEL_ITEMS_HEIGHT .background(MaterialTheme.colors.background)
) {
Box(modifier = Modifier.heightIn(max = maxHeight.dp)) { items(items = tags) { tag ->
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) { TagRow(
items(items = tags) { tag -> tag = tag,
TagRow( onTagClicked = { onTagClicked(tag) },
tag = tag, onCheckoutTag = { tagsViewModel.checkoutRef(tag) },
onTagClicked = { onTagClicked(tag) }, onDeleteTag = { tagsViewModel.deleteTag(tag) }
onCheckoutTag = { tagsViewModel.checkoutRef(tag) }, )
onDeleteTag = { tagsViewModel.deleteTag(tag) }
)
}
} }
} }
} }
} }

View File

@ -1,5 +1,6 @@
package app.ui.components package app.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
@ -12,6 +13,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import app.theme.headerBackground
import app.theme.primaryTextColor
import app.theme.secondaryTextColor import app.theme.secondaryTextColor
@Composable @Composable
@ -21,17 +24,17 @@ fun SideMenuEntry(
Row( Row(
modifier = Modifier modifier = Modifier
.height(32.dp) .height(32.dp)
.fillMaxWidth(), .fillMaxWidth()
.background(color = MaterialTheme.colors.headerBackground),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
Text( Text(
text = text, text = text,
modifier = Modifier modifier = Modifier
.padding(horizontal = 8.dp), .padding(horizontal = 8.dp),
maxLines = 1, maxLines = 1,
fontSize = 14.sp, fontSize = 14.sp,
color = MaterialTheme.colors.secondaryTextColor, color = MaterialTheme.colors.primaryTextColor,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
} }

View File

@ -16,10 +16,9 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import app.ENTRY_HEIGHT
import app.theme.primaryTextColor import app.theme.primaryTextColor
const val entryHeight = 40
@Composable @Composable
fun SideMenuSubentry( fun SideMenuSubentry(
text: String, text: String,
@ -31,7 +30,7 @@ fun SideMenuSubentry(
) { ) {
Row( Row(
modifier = Modifier modifier = Modifier
.height(entryHeight.dp) .height(ENTRY_HEIGHT.dp)
.fillMaxWidth() .fillMaxWidth()
.clickable(onClick = onClick) .clickable(onClick = onClick)
.padding(start = extraPadding), .padding(start = extraPadding),

View File

@ -236,7 +236,7 @@ fun GraphHeader(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(32.dp) .height(32.dp)
.background(MaterialTheme.colors.headerBackground), .background(MaterialTheme.colors.graphHeaderBackground),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
Text( Text(
@ -244,7 +244,6 @@ fun GraphHeader(
.width(graphWidth) .width(graphWidth)
.padding(start = 8.dp), .padding(start = 8.dp),
text = "Graph", text = "Graph",
fontWeight = FontWeight.Bold,
color = MaterialTheme.colors.headerText, color = MaterialTheme.colors.headerText,
fontSize = 14.sp, fontSize = 14.sp,
maxLines = 1, maxLines = 1,
@ -261,7 +260,6 @@ fun GraphHeader(
.padding(start = 8.dp) .padding(start = 8.dp)
.width(graphWidth), .width(graphWidth),
text = "Message", text = "Message",
fontWeight = FontWeight.Bold,
color = MaterialTheme.colors.headerText, color = MaterialTheme.colors.headerText,
fontSize = 14.sp, fontSize = 14.sp,
maxLines = 1, maxLines = 1,