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
906fcb27
Commit
906fcb27
authored
Dec 14, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some improvements on autocomplete speed
parent
b405a032
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 @
906fcb27
...
...
@@ -29,6 +29,9 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
notifyDataSetChanged
()
}
private
var
currentCount
=
0
;
private
var
currentItems
=
listOf
<
SuggestionModel
>()
init
{
setHasStableIds
(
true
)
}
...
...
@@ -41,10 +44,10 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
holder
.
bind
(
getItem
(
position
),
itemClickListener
)
}
override
fun
getItemCount
()
=
strategy
.
autocompleteItems
(
currentTerm
).
size
override
fun
getItemCount
()
=
currentCount
private
fun
getItem
(
position
:
Int
):
SuggestionModel
{
return
strategy
.
autocompleteItems
(
currentTerm
)
[
position
]
return
currentItems
[
position
]
}
/**
...
...
@@ -58,12 +61,15 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
fun
autocomplete
(
newTerm
:
String
)
{
this
.
currentTerm
=
newTerm
.
toLowerCase
().
trim
()
currentItems
=
strategy
.
autocompleteItems
(
currentTerm
)
currentCount
=
currentItems
.
size
}
fun
addItems
(
list
:
List
<
SuggestionModel
>)
{
strategy
.
addAll
(
list
)
// Since we've just added new items we should check for possible new completion suggestions.
strategy
.
autocompleteItems
(
currentTerm
)
//strategy.autocompleteItems(currentTerm)
autocomplete
(
currentTerm
)
notifyDataSetChanged
()
}
...
...
suggestions/src/main/java/chat/rocket/android/suggestions/ui/SuggestionsView.kt
View file @
906fcb27
...
...
@@ -10,6 +10,7 @@ import android.text.TextWatcher
import
android.transition.Slide
import
android.transition.TransitionManager
import
android.util.AttributeSet
import
android.util.Log
import
android.view.Gravity
import
android.view.View
import
android.widget.EditText
...
...
@@ -24,6 +25,7 @@ import chat.rocket.android.suggestions.model.SuggestionModel
import
chat.rocket.android.suggestions.ui.SuggestionsAdapter.Companion.CONSTRAINT_BOUND_TO_START
import
java.lang.ref.WeakReference
import
java.util.concurrent.atomic.AtomicInteger
import
kotlin.system.measureTimeMillis
// This is a special index that means we're not at an autocompleting state.
private
const
val
NO_STATE_INDEX
=
0
...
...
@@ -101,22 +103,32 @@ class SuggestionsView : FrameLayout, TextWatcher {
return
}
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
?.
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
)
}
if
(
completionOffset
.
get
()
==
NO_STATE_INDEX
)
{
return
}
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
)
{
...
...
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