From 65ff9b09c448ed9e2fd74db10c08f8034b3249e3 Mon Sep 17 00:00:00 2001 From: Rok Biderman Date: Tue, 19 Feb 2019 00:07:06 -0800 Subject: [PATCH] Improve the result display --- .../presenters/SearchResultPresenter.kt | 16 +++++++++--- .../advancedsearch/views/SearchResultView.kt | 26 ++++++++++++------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/org/secfirst/advancedsearch/presenters/SearchResultPresenter.kt b/library/src/main/java/org/secfirst/advancedsearch/presenters/SearchResultPresenter.kt index bdce2b3..17a39cb 100644 --- a/library/src/main/java/org/secfirst/advancedsearch/presenters/SearchResultPresenter.kt +++ b/library/src/main/java/org/secfirst/advancedsearch/presenters/SearchResultPresenter.kt @@ -77,7 +77,7 @@ class SearchResultPresenter(private val dataProvider: DataProvider, view: View, searchTerm: SearchTerm ) { - Logger.getLogger(tag).info("Searching for ${searchTerm}") + Logger.getLogger(tag).info("Searching for $searchTerm") view.resetResults() view.displaySearchTerm(searchTerm.text) bg { @@ -90,7 +90,16 @@ class SearchResultPresenter(private val dataProvider: DataProvider, view.showResultsView() segmentList.forEach { Logger.getLogger(tag).info("Result $it") } view.addResultsToAdapter(*segmentList.toTypedArray()) - view.displaySearchTermWithResultCount(searchTerm.text, segmentList.size) + view.displayResultCountView(segmentList.size) + val criteria: String = searchTerm + .criteria + ?.filterNot { it.second.isEmpty() } + ?.joinToString( + " " + ) { + "\n${it.first}: ${it.second.joinToString()}" + } ?: "" + view.displaySearchTermWithResultCount(searchTerm.text, segmentList.size, criteria) } } false -> { @@ -134,9 +143,10 @@ class SearchResultPresenter(private val dataProvider: DataProvider, fun addPillboxToLayout(criteria: SearchCriteria) fun addEditTextToLayout(criteria: SearchCriteria) fun addMainTextToLayout(criteria: SearchCriteria) - fun displaySearchTermWithResultCount(searchTerm: String, count: Int) fun emptyFields() fun showApplyResultsView() fun hideApplyResultsView() + fun displayResultCountView(count: Int) + fun displaySearchTermWithResultCount(searchTerm: String, count: Int, criteria: String) } } \ No newline at end of file diff --git a/library/src/main/java/org/secfirst/advancedsearch/views/SearchResultView.kt b/library/src/main/java/org/secfirst/advancedsearch/views/SearchResultView.kt index b9a4230..4c78b4d 100644 --- a/library/src/main/java/org/secfirst/advancedsearch/views/SearchResultView.kt +++ b/library/src/main/java/org/secfirst/advancedsearch/views/SearchResultView.kt @@ -108,12 +108,12 @@ class SearchResultView : FrameLayout, SearchResultPresenter.View { .forEach {criteriaChild -> when(criteriaChild) { is EditText -> { - if (!list.containsKey(criteriaChild.tag as String?)) { + if (!list.containsKey(criteriaChild.tag as String?) && criteriaChild.text.isNotEmpty()) { list[criteriaChild.tag as String] = listOf(criteriaChild.text.toString()) } } is AutoCompleteTextView -> { - if (!list.containsKey(criteriaChild.tag as String?)) { + if (!list.containsKey(criteriaChild.tag as String?) && criteriaChild.text.isNotEmpty()) { list[criteriaChild.tag as String] = listOf(criteriaChild.text.toString()) } } @@ -132,10 +132,12 @@ class SearchResultView : FrameLayout, SearchResultPresenter.View { } is AutoCompleteTextView -> { (linearLayoutChild.tag as String?)?.let { criteria -> - list[criteria] = listOf( - linearLayoutChild.text.toString(), - *list[criteria]?.toTypedArray() ?: arrayOf() - ) + if (linearLayoutChild.text.isNotEmpty()) { + list[criteria] = listOf( + linearLayoutChild.text.toString(), + *list[criteria]?.toTypedArray() ?: arrayOf() + ) + } } } else -> { @@ -170,13 +172,19 @@ class SearchResultView : FrameLayout, SearchResultPresenter.View { } } - override fun displaySearchTermWithResultCount(searchTerm: String, count: Int) { - searchTermView.visibility = View.VISIBLE + override fun displayResultCountView(count: Int) { resultCount.text = context.resources.getQuantityString(R.plurals.results_for_this_query, count, count) - searchTermView.text = context.getString(R.string.results_while_searching, searchTerm) } + override fun displaySearchTermWithResultCount(searchTerm: String, count: Int, criteria: String) { + searchTermView.visibility = View.VISIBLE + searchTermView.text = when(searchTerm.isEmpty()) { + false -> context.getString(R.string.results_while_searching_for, searchTerm, criteria) + true -> context.getString(R.string.results_while_searching, criteria) + } + } + override fun hideSearchTermView() { searchTermView.visibility = View.GONE }