Current branch now uses bold fontWeight

This commit is contained in:
Abdelilah El Aissaoui 2021-09-27 00:36:01 +02:00
parent 9a76d13483
commit e3a2b0b31a
4 changed files with 34 additions and 14 deletions

View File

@ -1,39 +1,29 @@
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Build
import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.MoreVert
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.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.useResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
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 extensions.filePath import extensions.simpleName
import extensions.icon
import extensions.toByteArray
import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Ref
import org.jetbrains.skija.Image
import theme.headerBackground import theme.headerBackground
@Composable @Composable
fun Branches(gitManager: GitManager) { fun Branches(gitManager: GitManager) {
val branches by gitManager.branches.collectAsState() val branches by gitManager.branches.collectAsState()
val currentBranch by gitManager.currentBranch.collectAsState()
Card( Card(
modifier = Modifier modifier = Modifier
@ -58,6 +48,7 @@ fun Branches(gitManager: GitManager) {
itemsIndexed(branches) { _, branch -> itemsIndexed(branches) { _, branch ->
BranchRow( BranchRow(
branch = branch, branch = branch,
isCurrentBranch = currentBranch == branch.name
) )
} }
@ -67,7 +58,15 @@ fun Branches(gitManager: GitManager) {
} }
@Composable @Composable
private fun BranchRow(branch: Ref) { private fun BranchRow(
branch: Ref,
isCurrentBranch: Boolean
) {
val fontWeight = if(isCurrentBranch)
FontWeight.Bold
else
FontWeight.Normal
Row( Row(
modifier = Modifier modifier = Modifier
.height(56.dp) .height(56.dp)
@ -86,7 +85,8 @@ private fun BranchRow(branch: Ref) {
) )
Text( Text(
text = branch.name, text = branch.simpleName,
fontWeight = fontWeight,
modifier = Modifier.weight(1f, fill = true), modifier = Modifier.weight(1f, fill = true),
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,

View File

@ -44,6 +44,9 @@ class GitManager {
val branches: StateFlow<List<Ref>> val branches: StateFlow<List<Ref>>
get() = branchesManager.branches get() = branchesManager.branches
val currentBranch: StateFlow<String>
get() = branchesManager.currentBranch
val stashStatus: StateFlow<StashStatus> val stashStatus: StateFlow<StashStatus>
get() = stashManager.stashStatus get() = stashManager.stashStatus

View File

@ -0,0 +1,8 @@
package extensions
import org.eclipse.jgit.lib.Ref
val Ref.simpleName: String
get() {
return this.name.split("/").last()
}

View File

@ -12,12 +12,21 @@ class BranchesManager {
val branches: StateFlow<List<Ref>> val branches: StateFlow<List<Ref>>
get() = _branches get() = _branches
private val _currentBranch = MutableStateFlow<String>("")
val currentBranch: StateFlow<String>
get() = _currentBranch
suspend fun loadBranches(git: Git) = withContext(Dispatchers.IO) { suspend fun loadBranches(git: Git) = withContext(Dispatchers.IO) {
val branchList = git val branchList = git
.branchList() .branchList()
.call() .call()
val branchName = git
.repository
.fullBranch
_branches.value = branchList _branches.value = branchList
_currentBranch.value = branchName
} }
suspend fun createBranch(git: Git, branchName: String) = withContext(Dispatchers.IO) { suspend fun createBranch(git: Git, branchName: String) = withContext(Dispatchers.IO) {