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
731f286b
Commit
731f286b
authored
Sep 19, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make EmojiSuggestionsAdapter use TrieCompletionStrategy with a result threshold of 5 items
parent
6557738b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
17 deletions
+21
-17
EmojiSuggestionsAdapter.kt
...ocket/android/chatroom/adapter/EmojiSuggestionsAdapter.kt
+2
-0
TrieCompletionStrategy.kt
...droid/suggestions/strategy/trie/TrieCompletionStrategy.kt
+3
-1
Trie.kt
...hat/rocket/android/suggestions/strategy/trie/data/Trie.kt
+2
-5
TrieNode.kt
...rocket/android/suggestions/strategy/trie/data/TrieNode.kt
+12
-10
SuggestionsAdapter.kt
.../chat/rocket/android/suggestions/ui/SuggestionsAdapter.kt
+2
-1
No files found.
app/src/main/java/chat/rocket/android/chatroom/adapter/EmojiSuggestionsAdapter.kt
View file @
731f286b
package
chat.rocket.android.chatroom.adapter
import
android.annotation.SuppressLint
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
...
...
@@ -25,6 +26,7 @@ class EmojiSuggestionsAdapter : SuggestionsAdapter<EmojiSuggestionViewHolder>(
class
EmojiSuggestionViewHolder
(
view
:
View
)
:
BaseSuggestionViewHolder
(
view
)
{
@SuppressLint
(
"SetTextI18n"
)
override
fun
bind
(
item
:
SuggestionModel
,
itemClickListener
:
SuggestionsAdapter
.
ItemClickListener
?)
{
item
as
EmojiSuggestionUiModel
with
(
itemView
)
{
...
...
suggestions/src/main/java/chat/rocket/android/suggestions/strategy/trie/TrieCompletionStrategy.kt
View file @
731f286b
...
...
@@ -18,7 +18,9 @@ class TrieCompletionStrategy : CompletionStrategy {
return
item
}
override
fun
autocompleteItems
(
prefix
:
String
)
=
trie
.
autocompleteItems
(
prefix
)
override
fun
autocompleteItems
(
prefix
:
String
):
List
<
SuggestionModel
>
{
return
trie
.
autocompleteItems
(
prefix
)
}
override
fun
addAll
(
list
:
List
<
SuggestionModel
>)
{
items
.
addAll
(
list
)
...
...
suggestions/src/main/java/chat/rocket/android/suggestions/strategy/trie/data/Trie.kt
View file @
731f286b
...
...
@@ -34,10 +34,7 @@ internal class Trie {
val
sanitizedWord
=
word
.
trim
().
toLowerCase
()
var
current
=
root
sanitizedWord
.
forEach
{
ch
->
val
child
=
current
.
getChild
(
ch
)
if
(
child
==
null
)
{
return
false
}
val
child
=
current
.
getChild
(
ch
)
?:
return
false
current
=
child
}
if
(
current
.
isLeaf
)
{
...
...
@@ -63,7 +60,7 @@ internal class Trie {
lastNode
=
lastNode
?.
getChild
(
ch
)
if
(
lastNode
==
null
)
return
emptyList
()
}
return
lastNode
!!
.
getItems
()
return
lastNode
!!
.
getItems
()
.
take
(
5
).
toList
()
}
fun
getCount
()
=
count
...
...
suggestions/src/main/java/chat/rocket/android/suggestions/strategy/trie/data/TrieNode.kt
View file @
731f286b
package
chat.rocket.android.suggestions.strategy.trie.data
import
chat.rocket.android.suggestions.model.SuggestionModel
import
kotlin.coroutines.experimental.buildSequence
internal
class
TrieNode
(
internal
var
data
:
Char
,
internal
var
parent
:
TrieNode
?
=
null
,
internal
var
isLeaf
:
Boolean
=
false
,
internal
var
item
:
SuggestionModel
?
=
null
)
{
internal
class
TrieNode
(
internal
var
data
:
Char
,
internal
var
parent
:
TrieNode
?
=
null
,
internal
var
isLeaf
:
Boolean
=
false
,
internal
var
item
:
SuggestionModel
?
=
null
)
{
val
children
=
hashMapOf
<
Char
,
TrieNode
>()
fun
getChild
(
c
:
Char
):
TrieNode
?
{
...
...
@@ -28,19 +32,17 @@ internal class TrieNode(internal var data: Char,
return
list
}
class
X
:
SuggestionModel
(
""
)
fun
getItems
():
Sequence
<
SuggestionModel
>
=
buildSequence
{
fun
getItems
():
List
<
SuggestionModel
>
{
val
list
=
arrayListOf
<
SuggestionModel
>()
if
(
isLeaf
)
{
list
.
ad
d
(
item
!!
)
yiel
d
(
item
!!
)
}
children
.
forEach
{
node
->
node
.
value
.
let
{
list
.
ad
dAll
(
it
.
getItems
())
yiel
dAll
(
it
.
getItems
())
}
}
return
list
}
override
fun
toString
():
String
=
if
(
parent
==
null
)
""
else
"${parent.toString()}$data"
...
...
suggestions/src/main/java/chat/rocket/android/suggestions/ui/SuggestionsAdapter.kt
View file @
731f286b
...
...
@@ -11,7 +11,8 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
val
token
:
String
,
val
constraint
:
Int
=
CONSTRAINT_UNBOUND
,
completionStrategy
:
CompletionStrategy
?
=
null
,
threshold
:
Int
=
MAX_RESULT_COUNT
)
:
RecyclerView
.
Adapter
<
VH
>()
{
threshold
:
Int
=
MAX_RESULT_COUNT
)
:
RecyclerView
.
Adapter
<
VH
>()
{
private
var
itemType
:
Type
?
=
null
private
var
itemClickListener
:
ItemClickListener
?
=
null
...
...
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