Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -190,7 +191,7 @@ fun LocalNetworkServerScreen(
}

// Server URL Card
if (isRunning && serverUrl != null) {
AnimatedVisibility(isRunning && serverUrl != null) {
Card(
modifier = Modifier.fillMaxWidth(),
colors =
Expand Down
23 changes: 19 additions & 4 deletions app/src/main/java/com/yogeshpaliyal/deepr/ui/screens/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import android.content.ClipboardManager
import android.content.Context
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandVertically
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -115,11 +120,11 @@ fun HomeScreen(
val selectedTag = viewModel.selectedTagFilter.collectAsStateWithLifecycle()
val hazeState = rememberHazeState()
val context = LocalContext.current
val contextCoroutine = rememberCoroutineScope()
val scrollBehavior = SearchBarDefaults.enterAlwaysSearchBarScrollBehavior()
val searchBarState = rememberSearchBarState()
val textFieldState = rememberTextFieldState()
val scope = rememberCoroutineScope()
val totalLinks = viewModel.countOfLinks.collectAsStateWithLifecycle()

val qrScanner =
rememberLauncherForActivityResult(
Expand Down Expand Up @@ -166,7 +171,7 @@ fun HomeScreen(
if (searchBarState.currentValue == SearchBarValue.Collapsed) {
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.search),
text = stringResource(R.string.search) + " (" + totalLinks.value + ")",
textAlign = TextAlign.Center,
)
}
Expand Down Expand Up @@ -456,7 +461,11 @@ fun DeeprList(
onTagClick: (String) -> Unit,
modifier: Modifier = Modifier,
) {
if (accounts.isEmpty()) {
AnimatedVisibility(
accounts.isEmpty(),
enter = scaleIn() + expandVertically(expandFrom = Alignment.CenterVertically),
exit = scaleOut() + shrinkVertically(shrinkTowards = Alignment.CenterVertically),
) {
// When empty, use a Column with weights to ensure vertical centering
Column(
modifier = modifier.fillMaxSize(),
Expand Down Expand Up @@ -495,14 +504,20 @@ fun DeeprList(

Spacer(modifier = Modifier.weight(1f)) // Push content up
}
} else {
}
AnimatedVisibility(
accounts.isNotEmpty(),
enter = scaleIn() + expandVertically(expandFrom = Alignment.CenterVertically),
exit = scaleOut() + shrinkVertically(shrinkTowards = Alignment.CenterVertically),
) {
LazyColumn(
modifier = modifier,
contentPadding = contentPaddingValues,
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
items(accounts) { account ->
DeeprItem(
modifier = Modifier.animateItem(),
account = account,
selectedTag = selectedTag,
onItemClick = onItemClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.cash.sqldelight.coroutines.asFlow
import app.cash.sqldelight.coroutines.mapToList
import app.cash.sqldelight.coroutines.mapToOneOrNull
import com.yogeshpaliyal.deepr.DeeprQueries
import com.yogeshpaliyal.deepr.GetLinksAndTags
import com.yogeshpaliyal.deepr.Tags
Expand Down Expand Up @@ -81,6 +82,14 @@ class AccountViewModel(
viewModelScope.coroutineContext,
).stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), listOf())

val countOfLinks: StateFlow<Long?> =
deeprQueries
.countOfLinks()
.asFlow()
.mapToOneOrNull(
viewModelScope.coroutineContext,
).stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0L)

private val sortOrder: Flow<@SortType String> =
preferenceDataStore.getSortingOrder

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/sqldelight/com/yogeshpaliyal/deepr/Deepr.sq
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ SELECT * FROM Tags WHERE name = ?;
getAllTags:
SELECT * FROM Tags ORDER BY name;

countOfLinks:
SELECT count(*) FROM Deepr;


-- Link-Tag relations
addTagToLink:
Expand Down