Started side menu desgin change and added tags support

This commit is contained in:
Abdelilah El Aissaoui 2021-11-18 02:01:17 +01:00
parent 3dd9b4a2cd
commit 713fba6ab9
9 changed files with 215 additions and 127 deletions

View File

@ -59,6 +59,9 @@ class GitManager @Inject constructor(
val branches: StateFlow<List<Ref>>
get() = branchesManager.branches
val tags: StateFlow<List<Ref>>
get() = tagsManager.tags
val currentBranch: StateFlow<String>
get() = branchesManager.currentBranch
@ -177,6 +180,7 @@ class GitManager @Inject constructor(
private suspend fun refreshRepositoryInfo() {
statusManager.loadHasUncommitedChanges(safeGit)
branchesManager.loadBranches(safeGit)
tagsManager.loadTags(safeGit)
stashManager.loadStashList(safeGit)
coLoadLog()
}

View File

@ -1,12 +1,27 @@
package app.git
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.revwalk.RevCommit
import javax.inject.Inject
class TagsManager @Inject constructor() {
private val _tags = MutableStateFlow<List<Ref>>(listOf())
val tags: StateFlow<List<Ref>>
get() = _tags
suspend fun loadTags(git: Git) = withContext(Dispatchers.IO) {
val branchList = git.tagList().call()
_tags.value = branchList
}
suspend fun createTagOnCommit(git: Git, tag: String, revCommit: RevCommit) = withContext(Dispatchers.IO) {
git
.tag()

View File

@ -8,7 +8,7 @@ val primaryDark = Color(0xFF014F97)
val secondary = Color(0xFFAB02E9)
val mainText = Color(0xFF212934)
val mainTextDark = Color(0xFFFFFFFF)
val secondaryText = Color(0xFF8F8F8F)
val secondaryText = Color(0xFF595858)
val secondaryTextDark = Color(0xFFCCCBCB)
val errorColor = Color(0xFFFA4B4B)
val primaryGrayLight = Color(0xFF464646)

View File

@ -24,33 +24,25 @@ import app.git.GitManager
import org.eclipse.jgit.lib.Ref
import app.theme.headerBackground
import app.theme.headerText
import app.ui.components.SideMenuEntry
import app.ui.components.SideMenuSubentry
@Composable
fun Branches(gitManager: GitManager) {
val branches by gitManager.branches.collectAsState()
val currentBranch by gitManager.currentBranch.collectAsState()
Card(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.5f)
.padding(8.dp)
) {
Column {
Text(
modifier = Modifier
.background(MaterialTheme.colors.headerBackground)
.padding(vertical = 8.dp)
.fillMaxWidth(),
text = "Local branches",
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center,
color = MaterialTheme.colors.headerText,
fontSize = 14.sp,
maxLines = 1,
)
Column {
SideMenuEntry("Branches")
ScrollableLazyColumn(modifier = Modifier.weight(5f)) {
val branchesHeight = branches.count() * 40
val maxHeight = if(branchesHeight < 300)
branchesHeight
else
300
Box(modifier = Modifier.heightIn(max = maxHeight.dp)) {
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) {
itemsIndexed(branches) { _, branch ->
BranchRow(
branch = branch,
@ -68,48 +60,12 @@ private fun BranchRow(
branch: Ref,
isCurrentBranch: Boolean
) {
val fontWeight = if(isCurrentBranch)
FontWeight.Bold
else
FontWeight.Normal
Row(
modifier = Modifier
.height(40.dp)
.fillMaxWidth()
.clickable(onClick = {}),
verticalAlignment = Alignment.CenterVertically,
SideMenuSubentry(
text = branch.simpleName,
iconResourcePath = "branch.svg"
) {
Icon(
painter = painterResource("branch.svg"),
contentDescription = null,
modifier = Modifier
.padding(horizontal = 8.dp)
.size(16.dp),
tint = MaterialTheme.colors.primary,
)
Text(
text = branch.simpleName,
fontWeight = fontWeight,
modifier = Modifier.weight(1f, fill = true),
maxLines = 1,
fontSize = 14.sp,
overflow = TextOverflow.Ellipsis,
)
IconButton(
onClick = {},
modifier = Modifier
.padding(horizontal = 16.dp)
.size(16.dp)
) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = null,
tint = MaterialTheme.colors.primary,
)
if (isCurrentBranch) {
Text("***")
}
}
}

View File

@ -2,6 +2,7 @@ package app.ui
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
@ -93,6 +94,7 @@ fun RepositoryOpenPage(gitManager: GitManager, dialogManager: DialogManager) {
.fillMaxHeight()
) {
Branches(gitManager = gitManager)
Tags(gitManager = gitManager)
Stashes(gitManager = gitManager)
}
Box(

View File

@ -21,6 +21,8 @@ import app.git.StashStatus
import org.eclipse.jgit.revwalk.RevCommit
import app.theme.headerBackground
import app.theme.headerText
import app.ui.components.SideMenuEntry
import app.ui.components.SideMenuSubentry
@Composable
fun Stashes(gitManager: GitManager) {
@ -32,78 +34,28 @@ fun Stashes(gitManager: GitManager) {
else
listOf()
Card(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.5f)
.padding(8.dp)
) {
Column {
Text(
modifier = Modifier
.background(MaterialTheme.colors.headerBackground)
.padding(vertical = 8.dp)
.fillMaxWidth(),
text = "Stashes",
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center,
color = MaterialTheme.colors.headerText,
fontSize = 14.sp,
maxLines = 1,
)
ScrollableLazyColumn(modifier = Modifier.weight(5f)) {
items(items = stashList) { stash ->
StashRow(
stash = stash,
)
Column {
SideMenuEntry(
text = "Stashes",
)
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) {
items(items = stashList) { stash ->
StashRow(
stash = stash,
)
}
}
}
}
}
@Composable
private fun StashRow(stash: RevCommit) {
Row(
modifier = Modifier
.height(40.dp)
.fillMaxWidth()
.clickable(onClick = {}),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
painter = painterResource("stash.svg"),
contentDescription = null,
modifier = Modifier
.padding(horizontal = 8.dp)
.size(16.dp),
tint = MaterialTheme.colors.primary,
)
Text(
text = stash.shortMessage,
modifier = Modifier
.weight(1f, fill = true)
.padding(end = 16.dp),
maxLines = 1,
fontSize = 14.sp,
overflow = TextOverflow.Ellipsis,
)
// IconButton(
// onClick = {},
// modifier = Modifier
// .padding(horizontal = 16.dp)
// .size(16.dp)
// ) {
// Icon(
// imageVector = Icons.Default.MoreVert,
// contentDescription = null,
// tint = MaterialTheme.colors.primary,
// )
// }
}
SideMenuSubentry(
text = stash.name,
iconResourcePath = "stash.svg",
)
}

View File

@ -0,0 +1,66 @@
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.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import app.extensions.simpleName
import app.ui.components.ScrollableLazyColumn
import app.git.GitManager
import app.git.StashStatus
import org.eclipse.jgit.revwalk.RevCommit
import app.theme.headerBackground
import app.theme.headerText
import app.ui.components.SideMenuEntry
import app.ui.components.SideMenuSubentry
import org.eclipse.jgit.lib.Ref
@Composable
fun Tags(gitManager: GitManager) {
val tagsState = gitManager.tags.collectAsState()
val tags = tagsState.value
Column {
SideMenuEntry(
text = "Tags",
)
val branchesHeight = tags.count() * 40
val maxHeight = if (branchesHeight < 300)
branchesHeight
else
300
Box(modifier = Modifier.heightIn(max = maxHeight.dp)) {
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) {
items(items = tags) { tag ->
TagRow(
tag = tag,
)
}
}
}
}
}
@Composable
private fun TagRow(tag: Ref) {
SideMenuSubentry(
text = tag.simpleName,
iconResourcePath = "tag.svg",
)
}

View File

@ -0,0 +1,40 @@
package app.ui.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import app.theme.secondaryTextColor
@Composable
fun SideMenuEntry(
text: String,
) {
Row(
modifier = Modifier
.height(40.dp)
.fillMaxWidth()
.clickable(onClick = {}),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = text,
modifier = Modifier
.padding(horizontal = 8.dp),
maxLines = 1,
fontSize = 14.sp,
color = MaterialTheme.colors.secondaryTextColor,
overflow = TextOverflow.Ellipsis,
)
}
}

View File

@ -0,0 +1,53 @@
package app.ui.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
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.sp
import app.extensions.simpleName
import app.theme.primaryTextColor
import app.theme.secondaryTextColor
@Composable
fun SideMenuSubentry(
text: String,
iconResourcePath: String,
additionalInfo: @Composable () -> Unit = {}
) {
Row(
modifier = Modifier
.height(40.dp)
.fillMaxWidth()
.clickable(onClick = {}),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
painter = painterResource(iconResourcePath),
contentDescription = null,
modifier = Modifier
.padding(horizontal = 8.dp)
.size(16.dp),
tint = MaterialTheme.colors.primary,
)
Text(
text = text,
modifier = Modifier.weight(1f, fill = true),
maxLines = 1,
fontSize = 14.sp,
color = MaterialTheme.colors.primaryTextColor,
overflow = TextOverflow.Ellipsis,
)
additionalInfo()
}
}