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
88711265
Commit
88711265
authored
Sep 11, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modularize all suggestions autocompletion code
parent
93d43d3b
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
177 additions
and
69 deletions
+177
-69
build.gradle
app/build.gradle
+1
-0
CommandSuggestionsAdapter.kt
...ket/android/chatroom/adapter/CommandSuggestionsAdapter.kt
+3
-3
PeopleSuggestionsAdapter.kt
...cket/android/chatroom/adapter/PeopleSuggestionsAdapter.kt
+3
-3
RoomSuggestionsAdapter.kt
...rocket/android/chatroom/adapter/RoomSuggestionsAdapter.kt
+3
-3
ChatRoomSuggestionUiModel.kt
.../chatroom/uimodel/suggestion/ChatRoomSuggestionUiModel.kt
+1
-1
CommandSuggestionUiModel.kt
...d/chatroom/uimodel/suggestion/CommandSuggestionUiModel.kt
+1
-1
PeopleSuggestionUiModel.kt
...id/chatroom/uimodel/suggestion/PeopleSuggestionUiModel.kt
+1
-1
fragment_chat_room.xml
app/src/main/res/layout/fragment_chat_room.xml
+1
-1
dimens.xml
app/src/main/res/values/dimens.xml
+0
-4
build.gradle
build.gradle
+1
-0
settings.gradle
settings.gradle
+1
-1
.gitignore
suggestions/.gitignore
+1
-0
build.gradle
suggestions/build.gradle
+34
-0
proguard-rules.pro
suggestions/proguard-rules.pro
+21
-0
ExampleInstrumentedTest.java
...amaki/github/com/suggestions/ExampleInstrumentedTest.java
+26
-0
AndroidManifest.xml
suggestions/src/main/AndroidManifest.xml
+2
-0
SuggestionModel.kt
.../chat/rocket/android/suggestions/model/SuggestionModel.kt
+2
-2
LocalSuggestionProvider.kt
...android/suggestions/repository/LocalSuggestionProvider.kt
+1
-1
CompletionStrategy.kt
...rocket/android/suggestions/strategy/CompletionStrategy.kt
+3
-3
StringMatchingCompletionStrategy.kt
...stions/strategy/regex/StringMatchingCompletionStrategy.kt
+5
-5
TrieCompletionStrategy.kt
...droid/suggestions/strategy/trie/TrieCompletionStrategy.kt
+5
-6
Trie.kt
...hat/rocket/android/suggestions/strategy/trie/data/Trie.kt
+3
-3
TrieNode.kt
...rocket/android/suggestions/strategy/trie/data/TrieNode.kt
+3
-3
BaseSuggestionViewHolder.kt
...rocket/android/suggestions/ui/BaseSuggestionViewHolder.kt
+4
-4
PopupRecyclerView.kt
...a/chat/rocket/android/suggestions/ui/PopupRecyclerView.kt
+3
-3
SuggestionsAdapter.kt
.../chat/rocket/android/suggestions/ui/SuggestionsAdapter.kt
+6
-6
SuggestionsView.kt
...ava/chat/rocket/android/suggestions/ui/SuggestionsView.kt
+16
-14
suggestions_menu_decorator.xml
...ions/src/main/res/drawable/suggestions_menu_decorator.xml
+1
-1
dimens.xml
suggestions/src/main/res/values/dimens.xml
+5
-0
strings.xml
suggestions/src/main/res/values/strings.xml
+3
-0
ExampleUnitTest.java
...onardoaramaki/github/com/suggestions/ExampleUnitTest.java
+17
-0
No files found.
app/build.gradle
View file @
88711265
...
...
@@ -93,6 +93,7 @@ dependencies {
implementation
project
(
':draw'
)
implementation
project
(
':util'
)
implementation
project
(
':core'
)
implementation
project
(
':suggestions'
)
implementation
libraries
.
kotlin
implementation
libraries
.
coroutines
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/CommandSuggestionsAdapter.kt
View file @
88711265
...
...
@@ -7,9 +7,9 @@ import android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.adapter.CommandSuggestionsAdapter.CommandSuggestionsViewHolder
import
chat.rocket.android.chatroom.uimodel.suggestion.CommandSuggestionUiModel
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
widget.autocompletion
.ui.BaseSuggestionViewHolder
import
chat.rocket.android.
widget.autocompletion
.ui.SuggestionsAdapter
import
chat.rocket.android.
suggestions
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.ui.BaseSuggestionViewHolder
import
chat.rocket.android.
suggestions
.ui.SuggestionsAdapter
class
CommandSuggestionsAdapter
:
SuggestionsAdapter
<
CommandSuggestionsViewHolder
>(
token
=
"/"
,
constraint
=
CONSTRAINT_BOUND_TO_START
,
threshold
=
RESULT_COUNT_UNLIMITED
)
{
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/PeopleSuggestionsAdapter.kt
View file @
88711265
...
...
@@ -11,9 +11,9 @@ import chat.rocket.android.R
import
chat.rocket.android.chatroom.adapter.PeopleSuggestionsAdapter.PeopleSuggestionViewHolder
import
chat.rocket.android.chatroom.uimodel.suggestion.PeopleSuggestionUiModel
import
chat.rocket.android.util.extensions.setVisible
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
widget.autocompletion
.ui.BaseSuggestionViewHolder
import
chat.rocket.android.
widget.autocompletion
.ui.SuggestionsAdapter
import
chat.rocket.android.
suggestions
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.ui.BaseSuggestionViewHolder
import
chat.rocket.android.
suggestions
.ui.SuggestionsAdapter
import
com.facebook.drawee.view.SimpleDraweeView
class
PeopleSuggestionsAdapter
(
context
:
Context
)
:
SuggestionsAdapter
<
PeopleSuggestionViewHolder
>(
"@"
)
{
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/RoomSuggestionsAdapter.kt
View file @
88711265
...
...
@@ -7,9 +7,9 @@ import android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.adapter.RoomSuggestionsAdapter.RoomSuggestionsViewHolder
import
chat.rocket.android.chatroom.uimodel.suggestion.ChatRoomSuggestionUiModel
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
widget.autocompletion
.ui.BaseSuggestionViewHolder
import
chat.rocket.android.
widget.autocompletion
.ui.SuggestionsAdapter
import
chat.rocket.android.
suggestions
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.ui.BaseSuggestionViewHolder
import
chat.rocket.android.
suggestions
.ui.SuggestionsAdapter
class
RoomSuggestionsAdapter
:
SuggestionsAdapter
<
RoomSuggestionsViewHolder
>(
"#"
)
{
...
...
app/src/main/java/chat/rocket/android/chatroom/uimodel/suggestion/ChatRoomSuggestionUiModel.kt
View file @
88711265
package
chat.rocket.android.chatroom.uimodel.suggestion
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.model.SuggestionModel
class
ChatRoomSuggestionUiModel
(
text
:
String
,
val
fullName
:
String
,
...
...
app/src/main/java/chat/rocket/android/chatroom/uimodel/suggestion/CommandSuggestionUiModel.kt
View file @
88711265
package
chat.rocket.android.chatroom.uimodel.suggestion
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.model.SuggestionModel
class
CommandSuggestionUiModel
(
text
:
String
,
val
description
:
String
,
...
...
app/src/main/java/chat/rocket/android/chatroom/uimodel/suggestion/PeopleSuggestionUiModel.kt
View file @
88711265
package
chat.rocket.android.chatroom.uimodel.suggestion
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.model.SuggestionModel
import
chat.rocket.common.model.UserStatus
class
PeopleSuggestionUiModel
(
val
imageUri
:
String
?,
...
...
app/src/main/res/layout/fragment_chat_room.xml
View file @
88711265
...
...
@@ -74,7 +74,7 @@
app:layout_constraintTop_toTopOf=
"parent"
tools:visibility=
"visible"
/>
<chat.rocket.android.
widget.autocompletion
.ui.SuggestionsView
<chat.rocket.android.
suggestions
.ui.SuggestionsView
android:id=
"@+id/suggestions_view"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
...
...
app/src/main/res/values/dimens.xml
View file @
88711265
...
...
@@ -41,10 +41,6 @@
<dimen
name=
"padding_mention"
>
4dp
</dimen>
<dimen
name=
"radius_mention"
>
6dp
</dimen>
<!-- Autocomplete Popup -->
<dimen
name=
"popup_max_height"
>
150dp
</dimen>
<dimen
name=
"suggestions_box_max_height"
>
250dp
</dimen>
<dimen
name=
"viewer_toolbar_padding"
>
16dp
</dimen>
<dimen
name=
"viewer_toolbar_title"
>
16sp
</dimen>
...
...
build.gradle
View file @
88711265
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
{
ext
.
kotlin_version
=
'1.0.0'
apply
from:
rootProject
.
file
(
'dependencies.gradle'
)
repositories
{
...
...
settings.gradle
View file @
88711265
include
':app'
,
':player'
,
':emoji'
,
':draw'
,
':util'
,
':core'
//, ':wear'
\ No newline at end of file
include
':app'
,
':player'
,
':emoji'
,
':draw'
,
':util'
,
':core'
,
':suggestions'
//, ':wear'
\ No newline at end of file
suggestions/.gitignore
0 → 100644
View file @
88711265
/build
suggestions/build.gradle
0 → 100644
View file @
88711265
apply
plugin:
'com.android.library'
apply
plugin:
'kotlin-android'
apply
plugin:
'kotlin-android-extensions'
android
{
compileSdkVersion
versions
.
compileSdk
buildToolsVersion
versions
.
buildTools
defaultConfig
{
minSdkVersion
versions
.
minSdk
targetSdkVersion
versions
.
targetSdk
versionCode
1
versionName
"1.0.0"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
}
buildTypes
{
release
{
minifyEnabled
false
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
}
}
}
dependencies
{
implementation
libraries
.
kotlin
implementation
libraries
.
recyclerview
implementation
libraries
.
appCompat
implementation
libraries
.
material
}
androidExtensions
{
experimental
=
true
}
suggestions/proguard-rules.pro
0 → 100644
View file @
88711265
# Add project specific ProGuard rules here.
#
You
can
control
the
set
of
applied
configuration
files
using
the
#
proguardFiles
setting
in
build
.
gradle
.
#
#
For
more
details
,
see
#
http
://
developer
.
android
.
com
/
guide
/
developing
/
tools
/
proguard
.
html
#
If
your
project
uses
WebView
with
JS
,
uncomment
the
following
#
and
specify
the
fully
qualified
class
name
to
the
JavaScript
interface
#
class
:
#-
keepclassmembers
class
fqcn
.
of
.
javascript
.
interface
.
for
.
webview
{
#
public
*
;
#
}
#
Uncomment
this
to
preserve
the
line
number
information
for
#
debugging
stack
traces
.
#-
keepattributes
SourceFile
,
LineNumberTable
#
If
you
keep
the
line
number
information
,
uncomment
this
to
#
hide
the
original
source
file
name
.
#-
renamesourcefileattribute
SourceFile
suggestions/src/androidTest/java/yampsample/leonardoaramaki/github/com/suggestions/ExampleInstrumentedTest.java
0 → 100644
View file @
88711265
package
yampsample
.
leonardoaramaki
.
github
.
com
.
suggestions
;
import
android.content.Context
;
import
android.support.test.InstrumentationRegistry
;
import
android.support.test.runner.AndroidJUnit4
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
junit
.
Assert
.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith
(
AndroidJUnit4
.
class
)
public
class
ExampleInstrumentedTest
{
@Test
public
void
useAppContext
()
{
// Context of the app under test.
Context
appContext
=
InstrumentationRegistry
.
getTargetContext
();
assertEquals
(
"yampsample.leonardoaramaki.github.com.suggestions.test"
,
appContext
.
getPackageName
());
}
}
suggestions/src/main/AndroidManifest.xml
0 → 100644
View file @
88711265
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"chat.rocket.android.suggestions"
/>
app/src/main/java/chat/rocket/android/widget/autocompletion
/model/SuggestionModel.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/model/SuggestionModel.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.model
package
chat.rocket.android.
suggestions
.model
abstract
class
SuggestionModel
(
val
text
:
String
,
// This is the text key for searches, must be unique.
val
searchList
:
List
<
String
>
=
emptyList
(),
// Where to search for matches.
...
...
@@ -15,4 +15,4 @@ abstract class SuggestionModel(val text: String, // This is the text key for sea
override
fun
hashCode
():
Int
{
return
text
.
hashCode
()
}
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/repository/LocalSuggestionProvider.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/repository/LocalSuggestionProvider.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.repository
package
chat.rocket.android.
suggestions
.repository
interface
LocalSuggestionProvider
{
fun
find
(
prefix
:
String
)
...
...
app/src/main/java/chat/rocket/android/widget/autocompletion
/strategy/CompletionStrategy.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/strategy/CompletionStrategy.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.strategy
package
chat.rocket.android.
suggestions
.strategy
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.model.SuggestionModel
interface
CompletionStrategy
{
fun
getItem
(
prefix
:
String
,
position
:
Int
):
SuggestionModel
...
...
@@ -8,4 +8,4 @@ interface CompletionStrategy {
fun
addAll
(
list
:
List
<
SuggestionModel
>)
fun
addPinned
(
list
:
List
<
SuggestionModel
>)
fun
size
():
Int
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/strategy/regex/StringMatchingCompletionStrategy.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/strategy/regex/StringMatchingCompletionStrategy.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.strategy.regex
package
chat.rocket.android.
suggestions
.strategy.regex
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
widget.autocompletion
.strategy.CompletionStrategy
import
chat.rocket.android.
widget.autocompletion
.ui.SuggestionsAdapter.Companion.RESULT_COUNT_UNLIMITED
import
chat.rocket.android.
suggestions
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.strategy.CompletionStrategy
import
chat.rocket.android.
suggestions
.ui.SuggestionsAdapter.Companion.RESULT_COUNT_UNLIMITED
import
java.util.concurrent.CopyOnWriteArrayList
internal
class
StringMatchingCompletionStrategy
(
private
val
threshold
:
Int
=
RESULT_COUNT_UNLIMITED
)
:
CompletionStrategy
{
...
...
@@ -46,4 +46,4 @@ internal class StringMatchingCompletionStrategy(private val threshold: Int = RES
override
fun
size
():
Int
{
return
list
.
size
}
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/strategy/trie/TrieCompletionStrategy.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/strategy/trie/TrieCompletionStrategy.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.strategy.trie
package
chat.rocket.android.
suggestions
.strategy.trie
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
widget.autocompletion
.strategy.CompletionStrategy
import
chat.rocket.android.
widget.autocompletion
.strategy.trie.data.Trie
import
chat.rocket.android.
suggestions
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.strategy.CompletionStrategy
import
chat.rocket.android.
suggestions
.strategy.trie.data.Trie
class
TrieCompletionStrategy
:
CompletionStrategy
{
private
val
items
=
mutableListOf
<
SuggestionModel
>()
...
...
@@ -28,8 +28,7 @@ class TrieCompletionStrategy : CompletionStrategy {
}
override
fun
addPinned
(
list
:
List
<
SuggestionModel
>)
{
}
override
fun
size
()
=
items
.
size
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/strategy/trie/data/Trie.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/strategy/trie/data/Trie.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.strategy.trie.data
package
chat.rocket.android.
suggestions
.strategy.trie.data
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.model.SuggestionModel
internal
class
Trie
{
private
val
root
=
TrieNode
(
' '
)
...
...
@@ -67,4 +67,4 @@ internal class Trie {
}
fun
getCount
()
=
count
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/strategy/trie/data/TrieNode.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/strategy/trie/data/TrieNode.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.strategy.trie.data
package
chat.rocket.android.
suggestions
.strategy.trie.data
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.model.SuggestionModel
internal
class
TrieNode
(
internal
var
data
:
Char
,
internal
var
parent
:
TrieNode
?
=
null
,
...
...
@@ -44,4 +44,4 @@ internal class TrieNode(internal var data: Char,
}
override
fun
toString
():
String
=
if
(
parent
==
null
)
""
else
"${parent.toString()}$data"
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/ui/BaseSuggestionViewHolder.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/ui/BaseSuggestionViewHolder.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.ui
package
chat.rocket.android.
suggestions
.ui
import
androidx.recyclerview.widget.RecyclerView
import
android.view.View
import
chat.rocket.android.widget.autocompletion.model.SuggestionModel
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.suggestions.model.SuggestionModel
abstract
class
BaseSuggestionViewHolder
(
view
:
View
)
:
RecyclerView
.
ViewHolder
(
view
)
{
abstract
fun
bind
(
item
:
SuggestionModel
,
itemClickListener
:
SuggestionsAdapter
.
ItemClickListener
?)
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/ui/PopupRecyclerView.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/ui/PopupRecyclerView.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.ui
package
chat.rocket.android.
suggestions
.ui
import
android.content.Context
import
android.util.AttributeSet
import
android.util.DisplayMetrics
import
android.view.WindowManager
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.R
import
chat.rocket.android.
suggestions.
R
internal
class
PopupRecyclerView
:
RecyclerView
{
private
var
displayWidth
:
Int
=
0
...
...
@@ -38,4 +38,4 @@ internal class PopupRecyclerView : RecyclerView {
override
fun
onLayout
(
changed
:
Boolean
,
l
:
Int
,
t
:
Int
,
r
:
Int
,
b
:
Int
)
{
super
.
onLayout
(
changed
,
l
+
40
,
t
,
r
-
40
,
b
)
}
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/widget/autocompletion
/ui/SuggestionsAdapter.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/ui/SuggestionsAdapter.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.ui
package
chat.rocket.android.
suggestions
.ui
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.
widget.autocompletion
.model.SuggestionModel
import
chat.rocket.android.
widget.autocompletion
.strategy.CompletionStrategy
import
chat.rocket.android.
widget.autocompletion
.strategy.regex.StringMatchingCompletionStrategy
import
chat.rocket.android.
suggestions
.model.SuggestionModel
import
chat.rocket.android.
suggestions
.strategy.CompletionStrategy
import
chat.rocket.android.
suggestions
.strategy.regex.StringMatchingCompletionStrategy
import
java.lang.reflect.Type
import
kotlin.properties.Delegates
...
...
@@ -32,10 +32,10 @@ abstract class SuggestionsAdapter<VH : BaseSuggestionViewHolder>(
// The strategy used for suggesting completions.
private
val
strategy
:
CompletionStrategy
=
StringMatchingCompletionStrategy
(
resultsThreshold
)
// Current input term to look up for suggestions.
private
var
currentTerm
:
String
by
Delegates
.
observable
(
""
,
{
_
,
_
,
newTerm
->
private
var
currentTerm
:
String
by
Delegates
.
observable
(
""
)
{
_
,
_
,
newTerm
->
val
items
=
strategy
.
autocompleteItems
(
newTerm
)
notifyDataSetChanged
()
}
)
}
init
{
setHasStableIds
(
true
)
...
...
app/src/main/java/chat/rocket/android/widget/autocompletion
/ui/SuggestionsView.kt
→
suggestions/src/main/java/chat/rocket/android/suggestions
/ui/SuggestionsView.kt
View file @
88711265
package
chat.rocket.android.
widget.autocompletion
.ui
package
chat.rocket.android.
suggestions
.ui
import
android.content.Context
import
android.graphics.Canvas
import
android.graphics.Rect
import
android.graphics.drawable.Drawable
import
androidx.annotation.DrawableRes
import
androidx.transition.Slide
import
androidx.transition.TransitionManager
import
androidx.core.content.ContextCompat
import
androidx.recyclerview.widget.DefaultItemAnimator
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
android.text.Editable
import
android.text.InputType
import
android.text.TextWatcher
import
android.transition.Slide
import
android.transition.TransitionManager
import
android.util.AttributeSet
import
android.view.Gravity
import
android.view.View
import
android.widget.EditText
import
android.widget.FrameLayout
import
chat.rocket.android.R
import
chat.rocket.android.widget.autocompletion.model.SuggestionModel
import
chat.rocket.android.widget.autocompletion.ui.SuggestionsAdapter.Companion.CONSTRAINT_BOUND_TO_START
import
androidx.annotation.DrawableRes
import
androidx.core.content.ContextCompat
import
androidx.recyclerview.widget.DefaultItemAnimator
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.suggestions.R
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
...
...
@@ -103,7 +103,8 @@ class SuggestionsView : FrameLayout, TextWatcher {
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
()
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 '@'
...
...
@@ -156,7 +157,7 @@ class SuggestionsView : FrameLayout, TextWatcher {
if
(
list
.
isNotEmpty
())
{
val
adapter
=
adapter
(
token
)
localProvidersByToken
.
getOrPut
(
token
,
{
hashMapOf
()
})
.
put
(
adapter
.
term
(),
list
)
.
put
(
adapter
.
term
(),
list
)
if
(
completionOffset
.
get
()
>
NO_STATE_INDEX
&&
adapter
.
itemCount
==
0
)
expand
()
adapter
.
addItems
(
list
)
}
...
...
@@ -192,7 +193,8 @@ class SuggestionsView : FrameLayout, TextWatcher {
}
private
fun
adapter
(
token
:
String
):
SuggestionsAdapter
<
*
>
{
return
adaptersByToken
[
token
]
?:
throw
IllegalStateException
(
"no adapter binds to token \"$token\""
)
return
adaptersByToken
[
token
]
?:
throw
IllegalStateException
(
"no adapter binds to token \"$token\""
)
}
private
fun
cancelSuggestions
(
haltCompletion
:
Boolean
)
{
...
...
app
/src/main/res/drawable/suggestions_menu_decorator.xml
→
suggestions
/src/main/res/drawable/suggestions_menu_decorator.xml
View file @
88711265
...
...
@@ -8,4 +8,4 @@
<size
android:height=
"2dp"
/>
</shape>
\ No newline at end of file
</shape>
suggestions/src/main/res/values/dimens.xml
0 → 100644
View file @
88711265
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen
name=
"popup_max_height"
>
150dp
</dimen>
<dimen
name=
"suggestions_box_max_height"
>
250dp
</dimen>
</resources>
\ No newline at end of file
suggestions/src/main/res/values/strings.xml
0 → 100644
View file @
88711265
<resources>
<string
name=
"app_name"
>
suggestions
</string>
</resources>
suggestions/src/test/java/yampsample/leonardoaramaki/github/com/suggestions/ExampleUnitTest.java
0 → 100644
View file @
88711265
package
yampsample
.
leonardoaramaki
.
github
.
com
.
suggestions
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public
class
ExampleUnitTest
{
@Test
public
void
addition_isCorrect
()
{
assertEquals
(
4
,
2
+
2
);
}
}
\ No newline at end of file
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