Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
8d932145
Unverified
Commit
8d932145
authored
Dec 14, 2018
by
Rafael Kellermann Streit
Committed by
GitHub
Dec 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1933 from RocketChat/fix/improve-completion-speed
[FIX] Improve autocomplete speed
parents
d656b1e5
906fcb27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
18 deletions
+36
-18
SuggestionsAdapter.kt
.../chat/rocket/android/suggestions/ui/SuggestionsAdapter.kt
+9
-3
SuggestionsView.kt
...ava/chat/rocket/android/suggestions/ui/SuggestionsView.kt
+27
-15
No files found.
suggestions/src/main/java/chat/rocket/android/suggestions/ui/SuggestionsAdapter.kt
View file @
8d932145
...
@@ -29,6 +29,9 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
...
@@ -29,6 +29,9 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
notifyDataSetChanged
()
notifyDataSetChanged
()
}
}
private
var
currentCount
=
0
;
private
var
currentItems
=
listOf
<
SuggestionModel
>()
init
{
init
{
setHasStableIds
(
true
)
setHasStableIds
(
true
)
}
}
...
@@ -41,10 +44,10 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
...
@@ -41,10 +44,10 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
holder
.
bind
(
getItem
(
position
),
itemClickListener
)
holder
.
bind
(
getItem
(
position
),
itemClickListener
)
}
}
override
fun
getItemCount
()
=
strategy
.
autocompleteItems
(
currentTerm
).
size
override
fun
getItemCount
()
=
currentCount
private
fun
getItem
(
position
:
Int
):
SuggestionModel
{
private
fun
getItem
(
position
:
Int
):
SuggestionModel
{
return
strategy
.
autocompleteItems
(
currentTerm
)
[
position
]
return
currentItems
[
position
]
}
}
/**
/**
...
@@ -58,12 +61,15 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
...
@@ -58,12 +61,15 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
fun
autocomplete
(
newTerm
:
String
)
{
fun
autocomplete
(
newTerm
:
String
)
{
this
.
currentTerm
=
newTerm
.
toLowerCase
().
trim
()
this
.
currentTerm
=
newTerm
.
toLowerCase
().
trim
()
currentItems
=
strategy
.
autocompleteItems
(
currentTerm
)
currentCount
=
currentItems
.
size
}
}
fun
addItems
(
list
:
List
<
SuggestionModel
>)
{
fun
addItems
(
list
:
List
<
SuggestionModel
>)
{
strategy
.
addAll
(
list
)
strategy
.
addAll
(
list
)
// Since we've just added new items we should check for possible new completion suggestions.
// Since we've just added new items we should check for possible new completion suggestions.
strategy
.
autocompleteItems
(
currentTerm
)
//strategy.autocompleteItems(currentTerm)
autocomplete
(
currentTerm
)
notifyDataSetChanged
()
notifyDataSetChanged
()
}
}
...
...
suggestions/src/main/java/chat/rocket/android/suggestions/ui/SuggestionsView.kt
View file @
8d932145
...
@@ -10,6 +10,7 @@ import android.text.TextWatcher
...
@@ -10,6 +10,7 @@ import android.text.TextWatcher
import
android.transition.Slide
import
android.transition.Slide
import
android.transition.TransitionManager
import
android.transition.TransitionManager
import
android.util.AttributeSet
import
android.util.AttributeSet
import
android.util.Log
import
android.view.Gravity
import
android.view.Gravity
import
android.view.View
import
android.view.View
import
android.widget.EditText
import
android.widget.EditText
...
@@ -24,6 +25,7 @@ import chat.rocket.android.suggestions.model.SuggestionModel
...
@@ -24,6 +25,7 @@ import chat.rocket.android.suggestions.model.SuggestionModel
import
chat.rocket.android.suggestions.ui.SuggestionsAdapter.Companion.CONSTRAINT_BOUND_TO_START
import
chat.rocket.android.suggestions.ui.SuggestionsAdapter.Companion.CONSTRAINT_BOUND_TO_START
import
java.lang.ref.WeakReference
import
java.lang.ref.WeakReference
import
java.util.concurrent.atomic.AtomicInteger
import
java.util.concurrent.atomic.AtomicInteger
import
kotlin.system.measureTimeMillis
// This is a special index that means we're not at an autocompleting state.
// This is a special index that means we're not at an autocompleting state.
private
const
val
NO_STATE_INDEX
=
0
private
const
val
NO_STATE_INDEX
=
0
...
@@ -101,22 +103,32 @@ class SuggestionsView : FrameLayout, TextWatcher {
...
@@ -101,22 +103,32 @@ class SuggestionsView : FrameLayout, TextWatcher {
return
return
}
}
val
prefixEndIndex
=
this
.
editor
?.
get
()
?.
selectionStart
?:
NO_STATE_INDEX
if
(
completionOffset
.
get
()
==
NO_STATE_INDEX
)
{
if
(
prefixEndIndex
==
NO_STATE_INDEX
||
prefixEndIndex
<
completionOffset
.
get
())
return
return
val
prefix
=
s
.
subSequence
(
completionOffset
.
get
(),
this
.
editor
?.
get
()
?.
selectionStart
?:
completionOffset
.
get
()).
toString
()
recyclerView
.
adapter
?.
let
{
it
as
SuggestionsAdapter
// we need to look up only after the '@'
it
.
autocomplete
(
prefix
)
val
cacheMap
=
localProvidersByToken
[
it
.
token
]
if
(
cacheMap
!=
null
&&
cacheMap
[
prefix
]
!=
null
)
{
it
.
addItems
(
cacheMap
[
prefix
]
!!
)
}
else
{
// fetch more suggestions from an external source if any
externalProvidersByToken
[
it
.
token
]
?.
invoke
(
prefix
)
}
}
}
measureTimeMillis
{
val
prefixEndIndex
=
this
.
editor
?.
get
()
?.
selectionStart
?:
NO_STATE_INDEX
if
(
prefixEndIndex
==
NO_STATE_INDEX
||
prefixEndIndex
<
completionOffset
.
get
())
return
val
prefix
=
s
.
subSequence
(
completionOffset
.
get
(),
this
.
editor
?.
get
()
?.
selectionStart
?:
completionOffset
.
get
()).
toString
()
recyclerView
.
adapter
?.
also
{
it
as
SuggestionsAdapter
// we need to look up only after the '@'
measureTimeMillis
{
it
.
autocomplete
(
prefix
)
}.
let
{
time
->
Log
.
d
(
"SuggestionsView"
,
"autocomplete($prefix) in $time ms"
)
}
val
cacheMap
=
localProvidersByToken
[
it
.
token
]
if
(
cacheMap
!=
null
&&
cacheMap
[
prefix
]
!=
null
)
{
if
(
it
.
itemCount
==
0
)
{
it
.
addItems
(
cacheMap
[
prefix
]
!!
)
}
}
else
{
// fetch more suggestions from an external source if any
externalProvidersByToken
[
it
.
token
]
?.
invoke
(
prefix
)
}
}
}.
let
{
Log
.
d
(
"SuggestionsView"
,
"whole prefix in $it ms"
)
}
}
}
override
fun
onMeasure
(
widthMeasureSpec
:
Int
,
heightMeasureSpec
:
Int
)
{
override
fun
onMeasure
(
widthMeasureSpec
:
Int
,
heightMeasureSpec
:
Int
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment