Skip to content

Commit 557850a

Browse files
feat: add count of links and improve UI animations in account and home views (#142)
1 parent 75e2226 commit 557850a

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/LocalNetworkServer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.ClipboardManager
66
import android.content.Context
77
import android.os.Build
88
import android.widget.Toast
9+
import androidx.compose.animation.AnimatedVisibility
910
import androidx.compose.foundation.background
1011
import androidx.compose.foundation.layout.Arrangement
1112
import androidx.compose.foundation.layout.Column
@@ -190,7 +191,7 @@ fun LocalNetworkServerScreen(
190191
}
191192

192193
// Server URL Card
193-
if (isRunning && serverUrl != null) {
194+
AnimatedVisibility(isRunning && serverUrl != null) {
194195
Card(
195196
modifier = Modifier.fillMaxWidth(),
196197
colors =

app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/Home.kt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import android.content.ClipboardManager
55
import android.content.Context
66
import android.widget.Toast
77
import androidx.activity.compose.rememberLauncherForActivityResult
8+
import androidx.compose.animation.AnimatedVisibility
9+
import androidx.compose.animation.expandVertically
10+
import androidx.compose.animation.scaleIn
11+
import androidx.compose.animation.scaleOut
12+
import androidx.compose.animation.shrinkVertically
813
import androidx.compose.foundation.layout.Arrangement
914
import androidx.compose.foundation.layout.Box
1015
import androidx.compose.foundation.layout.Column
@@ -115,11 +120,11 @@ fun HomeScreen(
115120
val selectedTag = viewModel.selectedTagFilter.collectAsStateWithLifecycle()
116121
val hazeState = rememberHazeState()
117122
val context = LocalContext.current
118-
val contextCoroutine = rememberCoroutineScope()
119123
val scrollBehavior = SearchBarDefaults.enterAlwaysSearchBarScrollBehavior()
120124
val searchBarState = rememberSearchBarState()
121125
val textFieldState = rememberTextFieldState()
122126
val scope = rememberCoroutineScope()
127+
val totalLinks = viewModel.countOfLinks.collectAsStateWithLifecycle()
123128

124129
val qrScanner =
125130
rememberLauncherForActivityResult(
@@ -166,7 +171,7 @@ fun HomeScreen(
166171
if (searchBarState.currentValue == SearchBarValue.Collapsed) {
167172
Text(
168173
modifier = Modifier.fillMaxWidth(),
169-
text = stringResource(R.string.search),
174+
text = stringResource(R.string.search) + " (" + totalLinks.value + ")",
170175
textAlign = TextAlign.Center,
171176
)
172177
}
@@ -456,7 +461,11 @@ fun DeeprList(
456461
onTagClick: (String) -> Unit,
457462
modifier: Modifier = Modifier,
458463
) {
459-
if (accounts.isEmpty()) {
464+
AnimatedVisibility(
465+
accounts.isEmpty(),
466+
enter = scaleIn() + expandVertically(expandFrom = Alignment.CenterVertically),
467+
exit = scaleOut() + shrinkVertically(shrinkTowards = Alignment.CenterVertically),
468+
) {
460469
// When empty, use a Column with weights to ensure vertical centering
461470
Column(
462471
modifier = modifier.fillMaxSize(),
@@ -495,14 +504,20 @@ fun DeeprList(
495504

496505
Spacer(modifier = Modifier.weight(1f)) // Push content up
497506
}
498-
} else {
507+
}
508+
AnimatedVisibility(
509+
accounts.isNotEmpty(),
510+
enter = scaleIn() + expandVertically(expandFrom = Alignment.CenterVertically),
511+
exit = scaleOut() + shrinkVertically(shrinkTowards = Alignment.CenterVertically),
512+
) {
499513
LazyColumn(
500514
modifier = modifier,
501515
contentPadding = contentPaddingValues,
502516
verticalArrangement = Arrangement.spacedBy(4.dp),
503517
) {
504518
items(accounts) { account ->
505519
DeeprItem(
520+
modifier = Modifier.animateItem(),
506521
account = account,
507522
selectedTag = selectedTag,
508523
onItemClick = onItemClick,

app/src/main/java/com/yogeshpaliyal/deepr/viewmodel/AccountViewModel.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
66
import androidx.lifecycle.viewModelScope
77
import app.cash.sqldelight.coroutines.asFlow
88
import app.cash.sqldelight.coroutines.mapToList
9+
import app.cash.sqldelight.coroutines.mapToOneOrNull
910
import com.yogeshpaliyal.deepr.DeeprQueries
1011
import com.yogeshpaliyal.deepr.GetLinksAndTags
1112
import com.yogeshpaliyal.deepr.Tags
@@ -81,6 +82,14 @@ class AccountViewModel(
8182
viewModelScope.coroutineContext,
8283
).stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), listOf())
8384

85+
val countOfLinks: StateFlow<Long?> =
86+
deeprQueries
87+
.countOfLinks()
88+
.asFlow()
89+
.mapToOneOrNull(
90+
viewModelScope.coroutineContext,
91+
).stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0L)
92+
8493
private val sortOrder: Flow<@SortType String> =
8594
preferenceDataStore.getSortingOrder
8695

app/src/main/sqldelight/com/yogeshpaliyal/deepr/Deepr.sq

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ SELECT * FROM Tags WHERE name = ?;
9595
getAllTags:
9696
SELECT * FROM Tags ORDER BY name;
9797

98+
countOfLinks:
99+
SELECT count(*) FROM Deepr;
100+
98101

99102
-- Link-Tag relations
100103
addTagToLink:

0 commit comments

Comments
 (0)