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 @@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
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.rounded.Star
import androidx.compose.material.icons.rounded.StarBorder
Expand Down Expand Up @@ -253,6 +254,7 @@ fun DeeprItem(
selected = isSelected,
onClick = { onTagClick(tag.trim()) },
label = { Text(tag.trim()) },
shape = RoundedCornerShape(percent = 50),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,8 @@ fun DeeprItemCompact(
style = MaterialTheme.typography.bodySmall,
color = getDeeprItemTextColor(account.isFavourite),
)
Row(modifier = Modifier.fillMaxWidth()) {
Text(
text = stringResource(R.string.opened_count, account.openedCount),
style = MaterialTheme.typography.labelSmall,
color = getDeeprItemTextColor(account.isFavourite),
)
Spacer(modifier = Modifier.weight(1f))
account.tagsIds?.split(",")?.size?.let { tagsCount ->
if (tagsCount > 0) {
Text(
text = stringResource(R.string.number_tags, tagsCount),
style = MaterialTheme.typography.labelSmall,
color = getDeeprItemTextColor(account.isFavourite),
)
}
}
}

OpenCountAndTags(account, Modifier.fillMaxWidth())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fun DeeprItemGrid(
modifier =
Modifier
.fillMaxWidth()
.aspectRatio(1f)
.aspectRatio(1.91f)
.background(MaterialTheme.colorScheme.surfaceVariant),
placeholder = null,
error = null,
Expand All @@ -88,7 +88,7 @@ fun DeeprItemGrid(
text = account.name,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.titleMedium,
style = MaterialTheme.typography.titleSmall,
color = getDeeprItemTextColor(account.isFavourite),
)
Spacer(modifier = Modifier.height(4.dp))
Expand All @@ -109,22 +109,7 @@ fun DeeprItemGrid(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = stringResource(R.string.opened_count, account.openedCount),
style = MaterialTheme.typography.bodySmall,
color = getDeeprItemTextColor(account.isFavourite),
)
account.tagsIds?.split(",")?.size?.let { tagsCount ->
if (tagsCount > 0) {
Text(
text = stringResource(R.string.number_tags, tagsCount),
style = MaterialTheme.typography.labelSmall,
color = getDeeprItemTextColor(account.isFavourite),
)
}
}
}
OpenCountAndTags(account, Modifier.weight(1f))
IconButton(onClick = {
onItemClick(MenuItem.MoreOptionsBottomSheet(account))
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import androidx.compose.ui.res.stringResource
import com.yogeshpaliyal.deepr.R
import com.yogeshpaliyal.deepr.viewmodel.SortType
import compose.icons.TablerIcons
import compose.icons.tablericons.ArrowsSort
import compose.icons.tablericons.Calendar
import compose.icons.tablericons.CalendarEvent
import compose.icons.tablericons.Eye
import compose.icons.tablericons.EyeOff
import compose.icons.tablericons.Filter
import compose.icons.tablericons.SortAscending
import compose.icons.tablericons.SortDescending

Expand All @@ -32,7 +32,7 @@ fun FilterMenu(
var expanded by remember { mutableStateOf(false) }
Box(modifier) {
IconButton(onClick = { expanded = true }) {
Icon(TablerIcons.Filter, contentDescription = stringResource(R.string.filter))
Icon(TablerIcons.ArrowsSort, contentDescription = stringResource(R.string.filter))
}
DropdownMenu(
expanded = expanded,
Expand Down
143 changes: 74 additions & 69 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 @@ -29,6 +29,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
Expand Down Expand Up @@ -59,9 +61,6 @@ import androidx.compose.material3.PlainTooltip
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SearchBarDefaults
import androidx.compose.material3.SearchBarValue
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
Expand Down Expand Up @@ -139,7 +138,6 @@ import compose.icons.tablericons.Refresh
import compose.icons.tablericons.Search
import compose.icons.tablericons.Tag
import compose.icons.tablericons.Trash
import compose.icons.tablericons.X
import dev.chrisbanes.haze.HazeState
import dev.chrisbanes.haze.hazeEffect
import dev.chrisbanes.haze.hazeSource
Expand Down Expand Up @@ -181,6 +179,12 @@ class Dashboard2(
}
}

data class FilterTagItem(
val name: String,
val count: Long,
val isSelected: Boolean,
)

@OptIn(
ExperimentalMaterial3Api::class,
ExperimentalHazeMaterialsApi::class,
Expand All @@ -200,6 +204,7 @@ fun HomeScreen(
val currentViewType by viewModel.viewType.collectAsStateWithLifecycle()
val localNavigator = LocalNavigator.current
val hapticFeedback = LocalHapticFeedback.current
val tags = viewModel.allTagsWithCount.collectAsStateWithLifecycle()

var selectedLink by remember { mutableStateOf<GetLinksAndTags?>(mSelectedLink) }
val selectedTag by viewModel.selectedTagFilter.collectAsStateWithLifecycle()
Expand All @@ -212,7 +217,9 @@ fun HomeScreen(
val totalLinks by viewModel.countOfLinks.collectAsStateWithLifecycle()
val favouriteLinks by viewModel.countOfFavouriteLinks.collectAsStateWithLifecycle()
val favouriteFilter by viewModel.favouriteFilter.collectAsStateWithLifecycle()
val listState = if (currentViewType == ViewType.GRID) rememberLazyStaggeredGridState() else rememberLazyListState()
var finalTagsInfo by remember { mutableStateOf<List<FilterTagItem>?>(listOf()) }
val listState =
if (currentViewType == ViewType.GRID) rememberLazyStaggeredGridState() else rememberLazyListState()
val isExpanded by remember(listState) {
// Example: expanded only when at the very top of the list
derivedStateOf {
Expand Down Expand Up @@ -252,6 +259,33 @@ fun HomeScreen(
}
}

LaunchedEffect(selectedTag, tags.value) {
// Get unique tags by merging both but first items should be selected tag and then tags
val allTagsList = tags.value
val mergedList = mutableListOf<FilterTagItem>()
val mapOfSelectedList = HashMap<String, Long>()

val alreadyAdded = HashSet<String>()

allTagsList.forEach { tag ->
mapOfSelectedList.put(tag.name, tag.linkCount)
}

selectedTag.forEach { tag ->
alreadyAdded.add(tag.name)
val count = mapOfSelectedList[tag.name] ?: 0L
mergedList.add(FilterTagItem(tag.name, count, true))
}

allTagsList.forEach { tag ->
if (alreadyAdded.contains(tag.name).not()) {
alreadyAdded.add(tag.name)
mergedList.add(FilterTagItem(tag.name, tag.linkCount, false))
}
}
finalTagsInfo = mergedList
}

LaunchedEffect(textFieldState.text) {
viewModel.search(textFieldState.text.toString())
}
Expand Down Expand Up @@ -311,11 +345,11 @@ fun HomeScreen(
TooltipDefaults.rememberTooltipPositionProvider(
TooltipAnchorPosition.Below,
),
tooltip = { PlainTooltip { Text(stringResource(R.string.sorting)) } },
tooltip = { PlainTooltip { Text("View Type") } },
state = rememberTooltipState(),
) {
FilterMenu(onSortOrderChange = {
viewModel.setSortOrder(it)
ViewTypeMenu(currentViewType, {
viewModel.setViewType(it)
})
}

Expand All @@ -324,11 +358,11 @@ fun HomeScreen(
TooltipDefaults.rememberTooltipPositionProvider(
TooltipAnchorPosition.Below,
),
tooltip = { PlainTooltip { Text("View Type") } },
tooltip = { PlainTooltip { Text(stringResource(R.string.sorting)) } },
state = rememberTooltipState(),
) {
ViewTypeMenu(currentViewType, {
viewModel.setViewType(it)
FilterMenu(onSortOrderChange = {
viewModel.setSortOrder(it)
})
}
}
Expand Down Expand Up @@ -376,69 +410,37 @@ fun HomeScreen(
},
)

// Favourite filter tabs
SingleChoiceSegmentedButtonRow(
LazyRow(
modifier =
Modifier
.fillMaxWidth()
.padding(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 8.dp),
) {
SegmentedButton(
shape =
SegmentedButtonDefaults.itemShape(
index = 0,
count = 2,
),
onClick = { viewModel.setFavouriteFilter(-1) },
selected = favouriteFilter == -1,
label = { Text(stringResource(R.string.all) + " (${totalLinks ?: 0})") },
)
SegmentedButton(
shape =
SegmentedButtonDefaults.itemShape(
index = 1,
count = 2,
),
onClick = { viewModel.setFavouriteFilter(1) },
selected = favouriteFilter == 1,
label = { Text(stringResource(R.string.favourites) + " (${favouriteLinks ?: 0})") },
)
}
item {
FilterChip(selectedTag.isEmpty() && favouriteFilter == -1, {
viewModel.setFavouriteFilter(-1)
viewModel.setTagFilter(null)
}, label = {
Text(stringResource(R.string.all) + " (${totalLinks ?: 0})")
}, modifier = Modifier.animateItem(), shape = RoundedCornerShape(percent = 50))
}
item {
FilterChip(selectedTag.isEmpty() && favouriteFilter == 1, {
viewModel.setFavouriteFilter(1)
viewModel.setTagFilter(null)
}, label = {
Text(stringResource(R.string.favourites) + " (${favouriteLinks ?: 0})")
}, modifier = Modifier.animateItem(), shape = RoundedCornerShape(percent = 50))
}

// Selected tags filter chips
AnimatedVisibility(
visible = selectedTag.isNotEmpty(),
enter = expandVertically(expandFrom = Alignment.Top),
exit = shrinkVertically(shrinkTowards = Alignment.Top),
) {
FlowRow(
modifier =
Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
selectedTag.forEach { tag ->
FilterChip(
selected = true,
onClick = { viewModel.setTagFilter(tag) },
label = { Text(tag.name) },
leadingIcon = {
Icon(
TablerIcons.Tag,
contentDescription = null,
modifier = Modifier.size(16.dp),
)
},
trailingIcon = {
Icon(
TablerIcons.X,
contentDescription = stringResource(R.string.remove_tag),
modifier = Modifier.size(18.dp),
)
},
)
}
items(finalTagsInfo ?: listOf()) {
FilterChip(it.isSelected, {
viewModel.setSelectedTagByName(it.name)
}, label = {
Text(it.name + " (${it.count})")
}, modifier = Modifier.animateItem(), shape = RoundedCornerShape(percent = 50))
}
}
}
Expand Down Expand Up @@ -818,6 +820,7 @@ fun Content(
showMoreSelectedItem = null
},
label = { Text(tag.trim()) },
shape = RoundedCornerShape(percent = 50),
)
}
}
Expand Down Expand Up @@ -1019,7 +1022,9 @@ fun DeeprList(

ViewType.GRID -> {
LazyVerticalStaggeredGrid(
state = listState as? LazyStaggeredGridState ?: rememberLazyStaggeredGridState(),
state =
listState as? LazyStaggeredGridState
?: rememberLazyStaggeredGridState(),
columns = StaggeredGridCells.Adaptive(minSize = 160.dp),
modifier = modifier,
contentPadding = contentPaddingValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ fun HomeBottomContent(
)
}
},
shape = RoundedCornerShape(percent = 50),
)
}
}
Expand Down Expand Up @@ -454,6 +455,7 @@ fun HomeBottomContent(
SuggestionChip(
onClick = { selectedTags.add(tag) },
label = { Text(tag.name) },
shape = RoundedCornerShape(percent = 50),
)
}
}
Expand Down
Loading