mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/507 - Moves the loading of the URL to the fragment
This commit is contained in:
parent
e8392c43fc
commit
dfb4f29848
@ -39,7 +39,7 @@ class ToolbarUIView(
|
||||
view.apply {
|
||||
setOnUrlCommitListener {
|
||||
actionEmitter.onNext(SearchAction.UrlCommitted(it))
|
||||
true
|
||||
false
|
||||
}
|
||||
onUrlClicked = {
|
||||
actionEmitter.onNext(SearchAction.ToolbarTapped)
|
||||
@ -60,7 +60,7 @@ class ToolbarUIView(
|
||||
}
|
||||
|
||||
override fun onStopEditing() {
|
||||
actionEmitter.onNext(SearchAction.UrlCommitted(url))
|
||||
// actionEmitter.onNext(SearchAction.UrlCommitted(url))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.Navigation
|
||||
import kotlinx.android.synthetic.main.fragment_search.view.*
|
||||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.support.ktx.kotlin.isUrl
|
||||
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.toolbar.SearchAction
|
||||
@ -77,7 +80,10 @@ class SearchFragment : Fragment() {
|
||||
getAutoDisposeObservable<SearchAction>()
|
||||
.subscribe {
|
||||
when (it) {
|
||||
is SearchAction.UrlCommitted -> transitionToBrowser()
|
||||
is SearchAction.UrlCommitted -> {
|
||||
transitionToBrowser()
|
||||
load(it.url)
|
||||
}
|
||||
is SearchAction.TextChanged -> {
|
||||
getManagedEmitter<AwesomeBarChange>().onNext(AwesomeBarChange.UpdateQuery(it.query))
|
||||
}
|
||||
@ -92,6 +98,32 @@ class SearchFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun load(text: String) {
|
||||
val sessionId = SearchFragmentArgs.fromBundle(arguments!!).sessionId
|
||||
val isPrivate = SearchFragmentArgs.fromBundle(arguments!!).isPrivateTab
|
||||
|
||||
val loadUrlUseCase = if (sessionId == null) {
|
||||
if (isPrivate) {
|
||||
requireComponents.useCases.tabsUseCases.addPrivateTab
|
||||
} else {
|
||||
requireComponents.useCases.tabsUseCases.addTab
|
||||
}
|
||||
} else requireComponents.useCases.sessionUseCases.loadUrl
|
||||
|
||||
val searchUseCase: (String) -> Unit = { searchTerms ->
|
||||
if (sessionId == null) {
|
||||
requireComponents.useCases.searchUseCases.newTabSearch
|
||||
.invoke(searchTerms, Session.Source.USER_ENTERED, true, isPrivate)
|
||||
} else requireComponents.useCases.searchUseCases.defaultSearch.invoke(searchTerms)
|
||||
}
|
||||
|
||||
if (text.isUrl()) {
|
||||
loadUrlUseCase.invoke(text.toNormalizedUrl())
|
||||
} else {
|
||||
searchUseCase.invoke(text)
|
||||
}
|
||||
}
|
||||
|
||||
private fun transitionToBrowser() {
|
||||
val sessionId = SearchFragmentArgs.fromBundle(arguments!!).sessionId
|
||||
val directions = SearchFragmentDirections.actionSearchFragmentToBrowserFragment(sessionId,
|
||||
|
Loading…
Reference in New Issue
Block a user