-
Notifications
You must be signed in to change notification settings - Fork 184
Do Not Merge WIP with places autocomplete working in the reference browser #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2679edc
WIP with places autocomplete working in the reference browser
mhammond 64caeae
Merge branch 'master' into autocomplete-places
mhammond 4519149
Merge remote-tracking branch 'origin/master' into autocomplete-places
mhammond fcc6325
Update to work with https://github.com/mozilla-mobile/android-compone…
mhammond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| This branch is a WIP for hooking up the "places" component in the reference | ||
| browser. It will only work with | ||
| [this android-components branch](https://github.com/mhammond/android-components/tree/autocomplete-places), | ||
| and in particular, after following | ||
| [these instructions](https://github.com/mhammond/android-components/blob/autocomplete-places/components/service/sync-places/README.md) | ||
|
|
||
| There's a new `BrowserAutocompleteProvider.kt` which wraps both the | ||
| `DomainAutocompleteProvider` and the places component. It first tries to | ||
| find matches using places, then using the `DomainAutocompleteProvider`. | ||
|
|
||
| Note that because we don't yet have geckoview hooked up to collect visit | ||
| information and write them to the places database. the places database will | ||
| be empty - meaning only | ||
| suggestions from `DomainAutocompleteProvider` will be shown. However, there's | ||
| a trick you can use to import your desktop places database and have it use | ||
| that. | ||
|
|
||
| * You will need to check out the application-services repo, and from the | ||
| `places` directory (soon to be `components/places`), execute: | ||
|
|
||
| `cargo run --release --example autocomplete -- --import-places auto` | ||
|
|
||
| (alternatively, in the place of `auto`, specify the full path to a desktop | ||
| `places.sqlite`) | ||
|
|
||
| This will also start a demo-app where you can perform auto-complete queries. | ||
| Press ESC to exit the app, and note that in the same directory you will have | ||
| a file `new-places.db` - rename this file to `places.sqlite` | ||
|
|
||
| * Kill the app in the emulator. | ||
|
|
||
| * Use the "Device File Explorer" in Android Studio, and navigate to the | ||
| `sdcard/Android/data/org.mozilla.reference.browser/files` directory - if | ||
| you've run the app before, you should already find a `places.sqlite` there. | ||
| Upload the file created above here and restart the app. | ||
|
|
||
| Note that if you have many many visits (eg, mine has ~170k places with ~230k | ||
| visits with a db size of ~75MB) a search for a full domain may take a couple | ||
| of seconds, but we know how to fix this. Even with a database this size, | ||
| searches of small substrings (eg, a few letters) are fast. We never expect a | ||
| "real" mobile device database to be this large, but it's a nice stress-test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/org/mozilla/reference/browser/browser/BrowserAutocompleteProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| // This is, roughly, an "auto-complete aggregator" - it first tries to find a match via "places", | ||
| // and if that fails, falls back to the "domain" provider. | ||
| package org.mozilla.reference.browser.browser | ||
|
|
||
| import android.app.Activity | ||
| import android.content.Context | ||
| import kotlinx.coroutines.experimental.launch | ||
| import mozilla.components.browser.domains.DomainAutoCompleteProvider | ||
| import mozilla.components.browser.toolbar.BrowserToolbar | ||
| import mozilla.components.ui.autocomplete.InlineAutocompleteEditText | ||
| import mozilla.components.service.sync.places.PlacesAwesomeBarProvider | ||
|
|
||
| // NOTE: this should be updated or replaced once mozilla.components.concept.awesomebar is in-place | ||
| // and has an implementation. Consider this a proof-of-concept only. | ||
| class BrowserAutocompleteProvider ( | ||
| context: Context, | ||
| toolbar: BrowserToolbar, | ||
| sessionId: String? = null) { | ||
|
|
||
| private val domainAutoCompleteProvider = DomainAutoCompleteProvider().apply { | ||
| initialize(context) | ||
| } | ||
|
|
||
| // XXX - this should be in the "profile" dir, but I'm not sure how to fetch that. | ||
| private val placesProvider = PlacesAwesomeBarProvider(context) | ||
|
|
||
| init { | ||
| toolbar.setAutocompleteFilter { value, view -> | ||
| view?.let { _ -> | ||
| // use a coroutine to do this off the main thread. | ||
| launch { | ||
| // First try places. | ||
| // XXX - given the inlineautocomplete functionality, we eventually want to perform | ||
| // an OriginOrUrl search - however, for now, we just perform a "normal" search, | ||
| // then iterate the results until we find one that matches at the start. | ||
| var finalResult: String? = null | ||
| var finalSource: String? = null | ||
| var finalSize: Int? = 0; | ||
|
|
||
| val placesResult = placesProvider.getSuggestion(value) | ||
| if (placesResult != null) { | ||
| finalResult = placesResult | ||
| finalSource = "places" | ||
| finalSize = 1 | ||
| } else { | ||
| val result = domainAutoCompleteProvider.autocomplete(value) | ||
| finalResult = result.text | ||
| finalSource = result.source | ||
| finalSize = result.size | ||
| } | ||
| // domainAutoCompleteProvider always provides a result, even if it is empty strings. | ||
| val activity = view.context as Activity | ||
| activity.runOnUiThread { | ||
| view.applyAutocompleteResult( | ||
| InlineAutocompleteEditText.AutocompleteResult(finalResult, finalSource!!, finalSize!!) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ plugins { | |
|
|
||
| allprojects { | ||
| repositories { | ||
| mavenLocal() | ||
|
|
||
| google() | ||
|
|
||
| maven { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this type should ultimately live in the components repo. Likely, part of this component:
mozilla-mobile/android-components#1109
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PlacesConnectioncould live in the services/sync-places component using themozilla.componentspackage.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PlacesConnection has an unsafe implementation so it should live in a-s. (Although maybe there will be a very similar type in mozilla.components, as with the recent fxa work)