Skip to content

Commit

Permalink
Response search fixes (#256)
Browse files Browse the repository at this point in the history
* Fix response search to be case insensitive
* Add minimum required symbols
* Fix invalid options menu in response fragment
  • Loading branch information
vbuberen authored Feb 28, 2020
1 parent ad65dd5 commit 5142af2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.text.style.ForegroundColorSpan
import android.text.style.UnderlineSpan

/**
* Hightlight parts of the String when it matches the search.
* Highlight parts of the String when it matches the search.
*
* @param search the text to highlight
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal class TransactionBodyAdapter(
bodyItems.filterIsInstance<TransactionPayloadItem.BodyLineItem>()
.withIndex()
.forEach { (index, item) ->
if (newText in item.line) {
if (item.line.contains(newText, ignoreCase = true)) {
item.line.clearSpans()
item.line = item.line.toString()
.highlightWithDefinedColors(newText, backgroundColor, foregroundColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ internal class TransactionPayloadFragment :

override fun onQueryTextChange(newText: String): Boolean {
val adapter = (transactionContentList.adapter as TransactionBodyAdapter)
if (newText.isNotBlank()) {
if (newText.isNotBlank() && newText.length > NUMBER_OF_IGNORED_SYMBOLS) {
adapter.highlightQueryWithColors(newText, backgroundSpanColor, foregroundSpanColor)
} else {
adapter.resetHighlight()
Expand Down Expand Up @@ -241,6 +241,7 @@ internal class TransactionPayloadFragment :
progressBar?.visibility = View.INVISIBLE
recyclerView?.visibility = View.VISIBLE
recyclerView?.adapter = TransactionBodyAdapter(result)
fragment.requireActivity().invalidateOptionsMenu()
}
}

Expand Down Expand Up @@ -298,6 +299,8 @@ internal class TransactionPayloadFragment :
private const val ARG_TYPE = "type"
private const val TRANSACTION_EXCEPTION = "Transaction not ready"

private const val NUMBER_OF_IGNORED_SYMBOLS = 1

const val TYPE_REQUEST = 0
const val TYPE_RESPONSE = 1

Expand Down

0 comments on commit 5142af2

Please sign in to comment.