Skip to content

Commit

Permalink
Merge pull request #1302 from Infomaniak/fix-search-bar-visibility
Browse files Browse the repository at this point in the history
fix: (Search) ApiV3 - Search bar not displayed for the first time
  • Loading branch information
tevincent authored May 22, 2024
2 parents 177889c + fb08cb8 commit 2cf818d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package com.infomaniak.drive.ui.fileList

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.annotation.StringRes
Expand All @@ -37,12 +35,10 @@ import com.infomaniak.drive.data.models.File.SortTypeUsage
import com.infomaniak.drive.data.models.SearchFilter
import com.infomaniak.drive.data.models.SearchFilter.FilterKey
import com.infomaniak.drive.data.models.UiSettings
import com.infomaniak.drive.databinding.RecentSearchesBinding
import com.infomaniak.drive.utils.Utils
import com.infomaniak.drive.utils.getName
import com.infomaniak.drive.utils.showSnackbar
import com.infomaniak.drive.views.DebouncingTextWatcher
import com.infomaniak.lib.core.utils.safeBinding
import com.infomaniak.lib.core.utils.safeNavigate
import com.infomaniak.lib.core.utils.setPagination

Expand All @@ -58,15 +54,9 @@ class SearchFragment : FileListFragment() {

private lateinit var filtersAdapter: SearchFiltersAdapter
private lateinit var recentSearchesAdapter: RecentSearchesAdapter
private var recentSearchesBinding: RecentSearchesBinding by safeBinding()

private var isDownloading = false

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
RecentSearchesBinding.inflate(inflater, container, false).also { recentSearchesBinding = it }.root
return super.onCreateView(inflater, container, savedInstanceState)
}

@SuppressLint("InflateParams")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
downloadFiles = DownloadFiles()
Expand Down Expand Up @@ -212,17 +202,17 @@ class SearchFragment : FileListFragment() {
}

private fun configureRecentSearches() = with(binding) {
fileListLayout.addView(recentSearchesBinding.root, 1)
recentSearchLayout.root.isVisible = true

val recentSearches = UiSettings(requireContext()).recentSearches

recentSearchesAdapter = RecentSearchesAdapter(
searches = ArrayList(recentSearches),
onSearchClicked = searchViewCard.searchView::setText,
onListEmpty = { recentSearchesBinding.root.isGone = true }
onListEmpty = { recentSearchLayout.root.isGone = true }
).also {
recentSearchesBinding.recentSearchesRecyclerView.adapter = it
recentSearchesBinding.recentSearchesContainer.isGone = recentSearches.isEmpty()
recentSearchLayout.recentSearchesRecyclerView.adapter = it
recentSearchLayout.recentSearchesContainer.isGone = recentSearches.isEmpty()
}
}

Expand Down Expand Up @@ -308,16 +298,16 @@ class SearchFragment : FileListFragment() {
}
}

private fun updateMostRecentSearches() {
val newSearch = binding.searchViewCard.searchView.text.toString().trim()
private fun updateMostRecentSearches(): Unit = with(binding) {
val newSearch = searchViewCard.searchView.text.toString().trim()
if (newSearch.isEmpty()) return

val newSearches = (listOf(newSearch) + recentSearchesAdapter.searches)
.distinct()
.take(MAX_MOST_RECENT_SEARCHES)
.also(recentSearchesAdapter::setItems)

recentSearchesBinding.recentSearchesContainer.isGone = newSearches.isEmpty()
recentSearchLayout.recentSearchesContainer.isGone = newSearches.isEmpty()
}

private fun triggerSearch() {
Expand Down Expand Up @@ -356,23 +346,23 @@ class SearchFragment : FileListFragment() {
private fun updateUi(mode: VisibilityMode) = with(binding) {

fun displayRecentSearches() {
recentSearchesBinding.root.isVisible = true
recentSearchLayout.root.isVisible = true
filtersRecyclerView.isGone = true
noFilesLayout.isGone = true
sortLayout.isGone = true
fileRecyclerView.isGone = true
}

fun displayLoadingView() {
recentSearchesBinding.root.isGone = true
recentSearchLayout.root.isGone = true
filtersRecyclerView.isGone = filtersAdapter.filters.isEmpty()
noFilesLayout.isGone = true
sortLayout.isGone = true
fileRecyclerView.isGone = true
}

fun displaySearchResult(mode: VisibilityMode) {
recentSearchesBinding.root.isGone = true
recentSearchLayout.root.isGone = true
filtersRecyclerView.isGone = filtersAdapter.filters.isEmpty()
changeNoFilesLayoutVisibility(mode == VisibilityMode.NO_RESULTS, changeControlsVisibility = false)
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/fragment_file_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@
android:visibility="gone"
tools:visibility="visible" />

<include
android:id="@+id/recent_search_layout"
layout="@layout/recent_searches"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />

<com.github.rubensousa.gravitysnaphelper.GravitySnapRecyclerView
android:id="@+id/filtersRecyclerView"
android:layout_width="match_parent"
Expand Down

0 comments on commit 2cf818d

Please sign in to comment.