Skip to content

Commit

Permalink
Improve the result display
Browse files Browse the repository at this point in the history
  • Loading branch information
Coccodrillo committed Feb 19, 2019
1 parent db7b0e6 commit 65ff9b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 -> {
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand All @@ -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 -> {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 65ff9b0

Please sign in to comment.