Skip to content

Commit

Permalink
Fix rare crash when loading URL
Browse files Browse the repository at this point in the history
Don't perform search filtering when tool bar text is updated during page load.
Close #557
  • Loading branch information
Slion committed Oct 3, 2023
1 parent ea8ed5c commit 57f05e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3373,7 +3373,7 @@ abstract class BrowserActivity : ThemedBrowserActivity(), BrowserView, UIControl
override fun getUiColor(): Int = currentUiColor

/**
*
* Called when current URL needs to be updated
*/
override fun updateUrl(url: String?, isLoading: Boolean) {

Expand All @@ -3390,7 +3390,10 @@ abstract class BrowserActivity : ThemedBrowserActivity(), BrowserView, UIControl

if (!searchView.hasFocus()) {
Timber.d("updateUrl: $currentTitle - $url")
searchView.setText(searchBoxModel.getDisplayContent(url, currentTitle, isLoading))
// Set our text but don't perform filtering
// We don't need filtering as this is just a text update from our engine rather than user performing text input and expecting search results
// Filter deactivation was introduce to prevent https://github.com/Slion/Fulguris/issues/557
searchView.setText(searchBoxModel.getDisplayContent(url, currentTitle, isLoading),false)
}
}

Expand Down Expand Up @@ -3476,8 +3479,11 @@ abstract class BrowserActivity : ThemedBrowserActivity(), BrowserView, UIControl
getUrl.setAdapter(suggestionsAdapter)
}


/**
*
*/
private fun doSearchSuggestionAction(getUrl: AutoCompleteTextView, position: Int) {
Timber.v("doSearchSuggestionAction")
val url = when (val selection = suggestionsAdapter?.getItem(position) as WebPage) {
is HistoryEntry,
is Bookmark.Entry -> selection.url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import dagger.hilt.android.EntryPointAccessors
import io.reactivex.*
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import timber.log.Timber
import java.util.*
import javax.inject.Inject

Expand Down Expand Up @@ -229,19 +230,30 @@ class SuggestionsAdapter(

fun input(): Observable<CharSequence> = publishSubject.hide()

/**
*
*/
override fun performFiltering(constraint: CharSequence?): FilterResults {
Timber.v("performFiltering")
if (constraint?.isBlank() != false) {
return FilterResults()
}
publishSubject.onNext(constraint.trim())

Timber.v("Constraint: $constraint")
publishSubject.onNext(constraint.trim())
return FilterResults().apply { count = 1 }
}

override fun convertResultToString(resultValue: Any) = (resultValue as WebPage).url

override fun publishResults(constraint: CharSequence?, results: FilterResults?) =
suggestionsAdapter.publishResults(null)
/**
*
*/
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
Timber.v("publishResults")
return suggestionsAdapter.publishResults(null)
}

}

}

0 comments on commit 57f05e2

Please sign in to comment.