@@ -38,6 +38,7 @@ import com.nextcloud.client.network.ClientFactory
3838import com.nextcloud.client.preferences.AppPreferences
3939import com.nextcloud.utils.extensions.getTypedActivity
4040import com.nextcloud.utils.extensions.searchFilesByName
41+ import com.nextcloud.utils.extensions.setVisibleIf
4142import com.nextcloud.utils.extensions.typedActivity
4243import com.owncloud.android.R
4344import com.owncloud.android.databinding.ListFragmentBinding
@@ -230,47 +231,41 @@ class UnifiedSearchFragment :
230231 adapter.setData(emptyList())
231232 adapter.setDataCurrentDirItems(listOf ())
232233
233- showStartYourSearch( )
234+ vm.updateScreenState( UnifiedSearchFragmentScreenState . Empty .startSearch() )
234235 showKeyboard(searchView)
235236 }
236237 }
237238
238- private fun makeEmptyListVisible () {
239- binding.emptyList.run {
240- root.visibility = View .VISIBLE
241- emptyListIcon.visibility = View .VISIBLE
242- emptyListViewHeadline.visibility = View .VISIBLE
243- emptyListViewText.visibility = View .VISIBLE
244- emptyListIcon.visibility = View .VISIBLE
239+ private fun handleScreenState (state : UnifiedSearchFragmentScreenState ) {
240+ when (state) {
241+ is UnifiedSearchFragmentScreenState .ShowingContent -> {
242+ toggleEmptyListVisible(show = false )
243+ }
244+ is UnifiedSearchFragmentScreenState .Empty -> {
245+ showEmptyView(state)
246+ }
245247 }
246248 }
247249
248- private fun showStartYourSearch () {
249- makeEmptyListVisible()
250-
250+ private fun toggleEmptyListVisible (show : Boolean ) {
251251 binding.emptyList.run {
252- emptyListViewHeadline.text = getString(R .string.file_list_empty_unified_search_start_search)
253- emptyListViewText.text = getString(R .string.file_list_empty_unified_search_start_search_description)
254- emptyListIcon.setImageDrawable(
255- viewThemeUtils.platform.tintDrawable(
256- requireContext(),
257- R .drawable.ic_search_grey
258- )
259- )
252+ root.setVisibleIf(show)
253+ emptyListIcon.setVisibleIf(show)
254+ emptyListViewHeadline.setVisibleIf(show)
255+ emptyListViewText.setVisibleIf(show)
256+ emptyListIcon.setVisibleIf(show)
260257 }
261258 }
262259
263- private fun showNoResult ( ) {
264- makeEmptyListVisible( )
260+ private fun showEmptyView ( state : UnifiedSearchFragmentScreenState . Empty ) {
261+ toggleEmptyListVisible(show = true )
265262
266263 binding.emptyList.run {
267- emptyListViewHeadline.text =
268- requireContext().getString(R .string.file_list_empty_headline_server_search)
269- emptyListViewText.text =
270- requireContext().getString(R .string.file_list_empty_unified_search_no_results)
271264 emptyListIcon.setImageDrawable(
272- viewThemeUtils.platform.tintDrawable(requireContext(), R .drawable.ic_search_grey )
265+ viewThemeUtils.platform.tintDrawable(requireContext(), state.iconId )
273266 )
267+ emptyListViewHeadline.text = requireContext().getString(state.titleId)
268+ emptyListViewText.text = requireContext().getString(state.descriptionId)
274269 }
275270 }
276271
@@ -317,6 +312,9 @@ class UnifiedSearchFragment :
317312 vm.isLoading.observe(viewLifecycleOwner) { loading ->
318313 binding.swipeContainingList.isRefreshing = loading
319314 }
315+ vm.screenState.observe(viewLifecycleOwner) {
316+ handleScreenState(it)
317+ }
320318
321319 PairMediatorLiveData (vm.searchResults, vm.isLoading).observe(viewLifecycleOwner) { (searchResults, isLoading) ->
322320 if (isLoading == true || searchResults.isNullOrEmpty()) {
@@ -329,7 +327,7 @@ class UnifiedSearchFragment :
329327 ! hasSearchResult &&
330328 ! adapter.hasLocalResults()
331329 ) {
332- showNoResult( )
330+ vm.updateScreenState( UnifiedSearchFragmentScreenState . Empty .noResults() )
333331 }
334332 }
335333
@@ -419,7 +417,11 @@ class UnifiedSearchFragment :
419417 fun onSearchResultChanged (result : List <UnifiedSearchSection >) {
420418 Log_OC .d(TAG , " result" )
421419 binding.emptyList.emptyListView.visibility = View .GONE
422- adapter.setData(result.filterOutHiddenFiles(listOfHiddenFiles))
420+ val newFiles = result.filterOutHiddenFiles(listOfHiddenFiles)
421+ if (newFiles.isNotEmpty()) {
422+ vm.updateScreenState(UnifiedSearchFragmentScreenState .ShowingContent )
423+ }
424+ adapter.setData(newFiles)
423425 }
424426
425427 @VisibleForTesting
@@ -446,6 +448,9 @@ class UnifiedSearchFragment :
446448 val files = storageManager
447449 .searchFilesByName(this , accountManager.user.accountName, query)
448450 .filter { ! it.isEncrypted }
451+ if (files.isNotEmpty()) {
452+ vm.updateScreenState(UnifiedSearchFragmentScreenState .ShowingContent )
453+ }
449454 adapter.setDataCurrentDirItems(files)
450455 }
451456 }
0 commit comments