From d612c625b93d98428f7efdbfb531aeb977865ec8 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Wed, 7 Jan 2026 17:07:02 +0100 Subject: [PATCH 1/2] ff --- .../gitnote/manager/StorageManager.kt | 9 ++ .../gitnote/ui/screen/app/grid/TopGrid.kt | 137 +++++++++++------- 2 files changed, 95 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/io/github/wiiznokes/gitnote/manager/StorageManager.kt b/app/src/main/java/io/github/wiiznokes/gitnote/manager/StorageManager.kt index 462aee5..62220b7 100644 --- a/app/src/main/java/io/github/wiiznokes/gitnote/manager/StorageManager.kt +++ b/app/src/main/java/io/github/wiiznokes/gitnote/manager/StorageManager.kt @@ -29,6 +29,15 @@ sealed interface SyncState { fun isLoading(): Boolean { return this is Pull || this is Push } + + fun message(): String { + return when (this) { + is Error -> this.msg ?: "Unknow Error" + is Ok -> "Sync done" + Pull -> "Pulling" + Push -> "Pushing" + } + } } sealed class Progress { diff --git a/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt b/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt index 3501bfe..a47e5a5 100644 --- a/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt +++ b/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt @@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.ViewList @@ -71,6 +72,9 @@ import io.github.wiiznokes.gitnote.BuildConfig import io.github.wiiznokes.gitnote.R import io.github.wiiznokes.gitnote.data.AppPreferences import io.github.wiiznokes.gitnote.manager.SyncState +import io.github.wiiznokes.gitnote.manager.SyncState.Ok +import io.github.wiiznokes.gitnote.manager.SyncState.Pull +import io.github.wiiznokes.gitnote.manager.SyncState.Push import io.github.wiiznokes.gitnote.ui.component.CustomDropDown import io.github.wiiznokes.gitnote.ui.component.CustomDropDownModel import io.github.wiiznokes.gitnote.ui.component.SimpleIcon @@ -82,6 +86,8 @@ import kotlin.math.roundToInt private const val TAG = "TopGridScreen" +private val ButtonSize = 35.dp + @Composable fun TopBar( padding: PaddingValues, @@ -225,15 +231,17 @@ private fun SearchBar( verticalAlignment = Alignment.CenterVertically ) { - val isEmpty = queryTextField.value.text.isEmpty() + val isEmpty = query.isEmpty() if (isEmpty) { - SyncStateIcon(syncState) { - consumeOkSyncState() - } + SyncStateIcon( + state = syncState, + onConsumeOkSyncState = consumeOkSyncState + ) } IconButton( + modifier = Modifier.size(ButtonSize), onClick = { updateSettings { this.noteViewType.update( @@ -266,7 +274,8 @@ private fun SearchBar( Box { val expanded = remember { mutableStateOf(false) } IconButton( - onClick = { expanded.value = true } + modifier = Modifier.size(ButtonSize), + onClick = { expanded.value = true }, ) { SimpleIcon( imageVector = Icons.Rounded.MoreVert, @@ -426,44 +435,76 @@ private fun SyncStateIcon( modifier = modifier.alpha(alpha.value) } - when (state) { - is SyncState.Error -> { - val tooltipState = rememberTooltipState(isPersistent = true) - val scope = rememberCoroutineScope() + @Composable + fun icon() { + when (state) { + is SyncState.Error -> Icon( + painter = painterResource(R.drawable.cloud_alert_24px), + contentDescription = "Sync Error", + modifier = modifier + ) + is Ok -> Icon( + imageVector = Icons.Default.CloudDone, + contentDescription = "Sync Done", + modifier = modifier, + ) + Pull -> Icon( + imageVector = Icons.Default.CloudDownload, + contentDescription = "Pulling", + modifier = modifier, + ) + Push -> Icon( + imageVector = Icons.Default.CloudUpload, + contentDescription = "Pushing", + modifier = modifier, + ) + } + } - TooltipBox( - positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), - tooltip = { - if (state.msg != null) { - PlainTooltip { - Text(state.msg) - } - } - }, - state = tooltipState - ) { - IconButton( - onClick = { - scope.launch { - if (tooltipState.isVisible) { - tooltipState.dismiss() - } else { - tooltipState.show() - } + val tooltipState = rememberTooltipState(isPersistent = true) + + @Composable + fun TooltipBoxCustom( + icon: @Composable () -> Unit + ) { + val scope = rememberCoroutineScope() + + TooltipBox( + positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), + tooltip = { + PlainTooltip { + Text(state.message()) + } + }, + state = tooltipState + ) { + IconButton( + modifier = Modifier.size(ButtonSize), + onClick = { + scope.launch { + if (tooltipState.isVisible) { + tooltipState.dismiss() + } else { + tooltipState.show() } } - ) { - Icon( - painter = painterResource(R.drawable.cloud_alert_24px), - contentDescription = "Sync Error", - modifier = modifier - ) } + ) { + icon() + } + + } + } + + when (state) { + is SyncState.Error -> { + TooltipBoxCustom { + icon() } } - is SyncState.Ok -> { + is Ok -> { var visible by remember { mutableStateOf(!state.isConsumed) } LaunchedEffect(visible) { @@ -476,25 +517,19 @@ private fun SyncStateIcon( visible = visible, exit = fadeOut(animationSpec = tween(durationMillis = 500)) ) { - Icon( - imageVector = Icons.Default.CloudDone, - contentDescription = "Sync Done", - modifier = modifier, - ) + TooltipBoxCustom { + icon() + } } } - is SyncState.Pull -> Icon( - imageVector = Icons.Default.CloudDownload, - contentDescription = "Pulling", - modifier = modifier, - ) + is Pull -> TooltipBoxCustom { + icon() + } - is SyncState.Push -> Icon( - imageVector = Icons.Default.CloudUpload, - contentDescription = "Pushing", - modifier = modifier, - ) + is Push -> TooltipBoxCustom { + icon() + } } } @@ -513,7 +548,7 @@ private fun TopBarPreview() { clearQuery = { }, search = {}, noteViewType = NoteViewType.Grid, - syncState = SyncState.Ok(false), + syncState = SyncState.Error("hello"), consumeOkSyncState = {}, isReadOnlyModeActive = true, updateSettings = { }, From 5b11282299e31ede51bcc23a4a846a99660c9d2b Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Wed, 7 Jan 2026 17:15:40 +0100 Subject: [PATCH 2/2] Update TopGrid.kt --- .../gitnote/ui/screen/app/grid/TopGrid.kt | 97 +++++++------------ 1 file changed, 33 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt b/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt index a47e5a5..7659edb 100644 --- a/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt +++ b/app/src/main/java/io/github/wiiznokes/gitnote/ui/screen/app/grid/TopGrid.kt @@ -435,37 +435,21 @@ private fun SyncStateIcon( modifier = modifier.alpha(alpha.value) } - @Composable - fun icon() { - when (state) { - is SyncState.Error -> Icon( - painter = painterResource(R.drawable.cloud_alert_24px), - contentDescription = "Sync Error", - modifier = modifier - ) - is Ok -> Icon( - imageVector = Icons.Default.CloudDone, - contentDescription = "Sync Done", - modifier = modifier, - ) - Pull -> Icon( - imageVector = Icons.Default.CloudDownload, - contentDescription = "Pulling", - modifier = modifier, - ) - Push -> Icon( - imageVector = Icons.Default.CloudUpload, - contentDescription = "Pushing", - modifier = modifier, - ) + val tooltipState = rememberTooltipState(isPersistent = true) + var visible by remember(state) { if (state is Ok) mutableStateOf(!state.isConsumed) else mutableStateOf(true) } + + if (state is Ok) { + LaunchedEffect(visible) { + delay(1000) + visible = false + onConsumeOkSyncState() + tooltipState.dismiss() } } - val tooltipState = rememberTooltipState(isPersistent = true) - - @Composable - fun TooltipBoxCustom( - icon: @Composable () -> Unit + AnimatedVisibility( + visible = visible, + exit = fadeOut(animationSpec = tween(durationMillis = 500)) ) { val scope = rememberCoroutineScope() @@ -490,45 +474,30 @@ private fun SyncStateIcon( } } ) { - icon() - } - - } - } - - - when (state) { - is SyncState.Error -> { - TooltipBoxCustom { - icon() - } - } - - is Ok -> { - var visible by remember { mutableStateOf(!state.isConsumed) } - - LaunchedEffect(visible) { - delay(1000) - visible = false - onConsumeOkSyncState() - } - - AnimatedVisibility( - visible = visible, - exit = fadeOut(animationSpec = tween(durationMillis = 500)) - ) { - TooltipBoxCustom { - icon() + when (state) { + is SyncState.Error -> Icon( + painter = painterResource(R.drawable.cloud_alert_24px), + contentDescription = "Sync Error", + modifier = modifier + ) + is Ok -> Icon( + imageVector = Icons.Default.CloudDone, + contentDescription = "Sync Done", + modifier = modifier, + ) + Pull -> Icon( + imageVector = Icons.Default.CloudDownload, + contentDescription = "Pulling", + modifier = modifier, + ) + Push -> Icon( + imageVector = Icons.Default.CloudUpload, + contentDescription = "Pushing", + modifier = modifier, + ) } } - } - - is Pull -> TooltipBoxCustom { - icon() - } - is Push -> TooltipBoxCustom { - icon() } } }