Skip to content

Commit

Permalink
- Repair bugs in SearchBar
Browse files Browse the repository at this point in the history
  • Loading branch information
DesarrolloAntonio committed Apr 19, 2024
1 parent ad81dd0 commit b19f5d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android.nonTransitiveRClass=true
compileSdkVersion=34
minSdkVersion=21
targetSdkVersion=34
versionCode=32
versionName=1.19.2
versionCode=33
versionName=1.20
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.desarrollodroide.pagekeeper.ui.feed

import android.widget.Toast
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -35,6 +36,7 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextOverflow
import com.desarrollodroide.data.helpers.BookmarkViewType
import com.desarrollodroide.pagekeeper.ui.components.Categories
Expand Down Expand Up @@ -63,8 +65,7 @@ fun FeedContent(
isSearchBarVisible: MutableState<Boolean>,
selectedTags: MutableState<List<Tag>>,
) {
val searchTextState = rememberSaveable { mutableStateOf("") }
val isActive = rememberSaveable { mutableStateOf(true) }

val sheetState = rememberModalBottomSheetState(
skipPartiallyExpanded = true
)
Expand Down Expand Up @@ -141,7 +142,6 @@ fun FeedContent(
}
}


PullRefreshIndicator(
modifier = Modifier.align(alignment = Alignment.TopCenter),
refreshing = isRefreshing,
Expand All @@ -161,10 +161,8 @@ fun FeedContent(
dragHandle = null
) {
SearchBar(
searchText = searchTextState,
isActive = isActive,
bookmarks = bookmarks,
onBookmarkClick = actions.onBookmarkSelect,
onBookmarkClick = actions.onBookmarkSelect,
onDismiss = {
scope.launch {
sheetState.hide()
Expand All @@ -179,12 +177,13 @@ fun FeedContent(
@Composable
@OptIn(ExperimentalMaterial3Api::class)
private fun SearchBar(
searchText: MutableState<String>,
isActive: MutableState<Boolean>,
onBookmarkClick: (Bookmark) -> Unit,
onDismiss: () -> Unit,
bookmarks: List<Bookmark>,
) {
val searchText = rememberSaveable { mutableStateOf("") }
val isActive = rememberSaveable { mutableStateOf(true) }
val context = LocalContext.current
val filteredBookmarks =
bookmarks.filter { it.title.contains(searchText.value, ignoreCase = true) }
Box(Modifier
Expand All @@ -194,7 +193,9 @@ private fun SearchBar(
.align(Alignment.TopCenter),
query = searchText.value,
onQueryChange = { searchText.value = it },
onSearch = { isActive.value = false },
onSearch = {
Toast.makeText(context, "Select bookmark from list", Toast.LENGTH_SHORT).show()
},
active = isActive.value,
onActiveChange = { isActive.value = it },
placeholder = { Text("Search...") },
Expand All @@ -219,7 +220,6 @@ private fun SearchBar(
) {
BookmarkSuggestions(
bookmarks = filteredBookmarks,
isActive = isActive,
onClickSuggestion = onBookmarkClick
)
}
Expand All @@ -229,7 +229,6 @@ private fun SearchBar(
@Composable
private fun BookmarkSuggestions(
bookmarks: List<Bookmark>,
isActive: MutableState<Boolean>,
onClickSuggestion: (Bookmark) -> Unit
) {
LazyColumn(
Expand All @@ -245,7 +244,6 @@ private fun BookmarkSuggestions(
modifier = Modifier
.clickable {
onClickSuggestion(bookmark)
isActive.value = false
}
.background(Color.Transparent),
headlineContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ fun FeedScreen(
},
onBookmarkSelect = { bookmark ->
Log.v("FeedContent", feedViewModel.getUrl(bookmark))
isSearchBarVisible.value = false
openUrlInBrowser(feedViewModel.getUrl(bookmark))
},
onRefreshFeed = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.desarrollodroide.pagekeeper.ui.feed

import android.util.Log
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.desarrollodroide.pagekeeper.ui.components.UiState
Expand Down Expand Up @@ -59,6 +60,8 @@ class FeedViewModel(
val isCompactView = MutableStateFlow<Boolean>(false)
val selectedCategories = mutableStateOf<List<Tag>>(emptyList())
val uniqueCategories = mutableStateOf<List<Tag>>(emptyList())
val searchTextState = mutableStateOf("")
val isActive = mutableStateOf(true)

init {
viewModelScope.launch {
Expand Down

0 comments on commit b19f5d2

Please sign in to comment.