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
91763a21
Unverified
Commit
91763a21
authored
Sep 18, 2018
by
Filipe de Lima Brito
Committed by
GitHub
Sep 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into fix-random-crash-emoji-keyboard
parents
a74e410c
d4ced11a
Changes
38
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
267 additions
and
116 deletions
+267
-116
build.gradle
app/build.gradle
+1
-0
BaseViewHolder.kt
...va/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt
+3
-1
CommandSuggestionsAdapter.kt
...ket/android/chatroom/adapter/CommandSuggestionsAdapter.kt
+3
-3
MessageReactionsAdapter.kt
...ocket/android/chatroom/adapter/MessageReactionsAdapter.kt
+38
-19
PeopleSuggestionsAdapter.kt
...cket/android/chatroom/adapter/PeopleSuggestionsAdapter.kt
+3
-3
RoomSuggestionsAdapter.kt
...rocket/android/chatroom/adapter/RoomSuggestionsAdapter.kt
+3
-3
ReactionUiModel.kt
...a/chat/rocket/android/chatroom/uimodel/ReactionUiModel.kt
+2
-1
UiModelMapper.kt
...ava/chat/rocket/android/chatroom/uimodel/UiModelMapper.kt
+5
-1
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
rounded_background.xml
app/src/main/res/drawable/rounded_background.xml
+2
-2
fragment_chat_room.xml
app/src/main/res/layout/fragment_chat_room.xml
+1
-1
item_reaction.xml
app/src/main/res/layout/item_reaction.xml
+39
-21
dimens.xml
app/src/main/res/values/dimens.xml
+0
-4
build.gradle
build.gradle
+1
-1
EmojiRepository.kt
...rc/main/java/chat/rocket/android/emoji/EmojiRepository.kt
+1
-1
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 @
91763a21
...
...
@@ -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/BaseViewHolder.kt
View file @
91763a21
...
...
@@ -65,7 +65,9 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
val
manager
=
FlexboxLayoutManager
(
context
,
FlexDirection
.
ROW
)
recyclerView
.
layoutManager
=
manager
recyclerView
.
adapter
=
adapter
adapter
.
addReactions
(
it
.
reactions
.
filterNot
{
it
.
unicode
.
startsWith
(
":"
)
})
adapter
.
addReactions
(
it
.
reactions
.
filterNot
{
reactionUiModel
->
reactionUiModel
.
unicode
.
startsWith
(
":"
)
&&
reactionUiModel
.
url
.
isNullOrEmpty
()
})
}
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/CommandSuggestionsAdapter.kt
View file @
91763a21
...
...
@@ -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/MessageReactionsAdapter.kt
View file @
91763a21
...
...
@@ -5,6 +5,7 @@ import android.view.View
import
android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.core.content.ContextCompat
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.uimodel.ReactionUiModel
...
...
@@ -13,15 +14,13 @@ import chat.rocket.android.emoji.Emoji
import
chat.rocket.android.emoji.EmojiKeyboardListener
import
chat.rocket.android.emoji.EmojiPickerPopup
import
chat.rocket.android.emoji.EmojiReactionListener
import
chat.rocket.android.emoji.internal.GlideApp
import
chat.rocket.android.infrastructure.LocalRepository
import
kotlinx.android.synthetic.main.item_reaction.view.*
import
java.util.concurrent.CopyOnWriteArrayList
import
javax.inject.Inject
class
MessageReactionsAdapter
:
RecyclerView
.
Adapter
<
RecyclerView
.
ViewHolder
>()
{
companion
object
{
private
const
val
REACTION_VIEW_TYPE
=
0
private
const
val
ADD_REACTION_VIEW_TYPE
=
1
}
private
val
reactions
=
CopyOnWriteArrayList
<
ReactionUiModel
>()
var
listener
:
EmojiReactionListener
?
=
null
...
...
@@ -74,9 +73,11 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
fun
contains
(
reactionShortname
:
String
)
=
reactions
.
firstOrNull
{
it
.
shortname
==
reactionShortname
}
!=
null
class
SingleReactionViewHolder
(
view
:
View
,
private
val
listener
:
EmojiReactionListener
?)
:
RecyclerView
.
ViewHolder
(
view
),
View
.
OnClickListener
{
class
SingleReactionViewHolder
(
view
:
View
,
private
val
listener
:
EmojiReactionListener
?
)
:
RecyclerView
.
ViewHolder
(
view
),
View
.
OnClickListener
{
@Inject
lateinit
var
localRepository
:
LocalRepository
@Volatile
...
...
@@ -95,23 +96,33 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
clickHandled
=
false
this
.
reaction
=
reaction
with
(
itemView
)
{
val
emojiTextView
=
findViewById
<
TextView
>(
R
.
id
.
text_emoji
)
val
countTextView
=
findViewById
<
TextView
>(
R
.
id
.
text_count
)
emojiTextView
.
text
=
reaction
.
unicode
countTextView
.
text
=
reaction
.
count
.
toString
()
if
(
reaction
.
url
.
isNullOrEmpty
())
{
text_emoji
.
text
=
reaction
.
unicode
view_flipper_reaction
.
displayedChild
=
0
}
else
{
view_flipper_reaction
.
displayedChild
=
1
val
glideRequest
=
if
(
reaction
.
url
!!
.
endsWith
(
"gif"
,
true
))
{
GlideApp
.
with
(
context
).
asGif
()
}
else
{
GlideApp
.
with
(
context
).
asBitmap
()
}
glideRequest
.
load
(
reaction
.
url
).
into
(
image_emoji
)
}
text_count
.
text
=
reaction
.
count
.
toString
()
val
myself
=
localRepository
.
get
(
LocalRepository
.
CURRENT_USERNAME_KEY
)
if
(
reaction
.
usernames
.
contains
(
myself
))
{
val
context
=
itemView
.
context
val
resources
=
context
.
resources
countTextView
.
setTextColor
(
resources
.
getColor
(
R
.
color
.
colorAccent
))
text_count
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorAccent
))
}
emojiTextView
.
setOnClickListener
(
this
@SingleReactionViewHolder
)
countTextView
.
setOnClickListener
(
this
@SingleReactionViewHolder
)
view_flipper_reaction
.
setOnClickListener
(
this
@SingleReactionViewHolder
)
text_count
.
setOnClickListener
(
this
@SingleReactionViewHolder
)
}
}
override
fun
onClick
(
v
:
View
?
)
{
override
fun
onClick
(
v
:
View
)
{
synchronized
(
this
)
{
if
(!
clickHandled
)
{
clickHandled
=
true
...
...
@@ -121,8 +132,11 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
}
}
class
AddReactionViewHolder
(
view
:
View
,
private
val
listener
:
EmojiReactionListener
?)
:
RecyclerView
.
ViewHolder
(
view
)
{
class
AddReactionViewHolder
(
view
:
View
,
private
val
listener
:
EmojiReactionListener
?
)
:
RecyclerView
.
ViewHolder
(
view
)
{
fun
bind
(
messageId
:
String
)
{
itemView
as
ImageView
itemView
.
setOnClickListener
{
...
...
@@ -136,4 +150,9 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
}
}
}
}
\ No newline at end of file
companion
object
{
private
const
val
REACTION_VIEW_TYPE
=
0
private
const
val
ADD_REACTION_VIEW_TYPE
=
1
}
}
app/src/main/java/chat/rocket/android/chatroom/adapter/PeopleSuggestionsAdapter.kt
View file @
91763a21
...
...
@@ -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 @
91763a21
...
...
@@ -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/ReactionUiModel.kt
View file @
91763a21
...
...
@@ -5,5 +5,6 @@ data class ReactionUiModel(
val
shortname
:
String
,
val
unicode
:
CharSequence
,
val
count
:
Int
,
val
usernames
:
List
<
String
>
=
emptyList
()
val
usernames
:
List
<
String
>
=
emptyList
(),
var
url
:
String
?
=
null
)
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/uimodel/UiModelMapper.kt
View file @
91763a21
...
...
@@ -18,6 +18,7 @@ import chat.rocket.android.chatroom.domain.MessageReply
import
chat.rocket.android.dagger.scope.PerFragment
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.emoji.EmojiParser
import
chat.rocket.android.emoji.EmojiRepository
import
chat.rocket.android.helper.MessageHelper
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.helper.UserHelper
...
...
@@ -504,15 +505,18 @@ class UiModelMapper @Inject constructor(
private
fun
getReactions
(
message
:
Message
):
List
<
ReactionUiModel
>
{
val
reactions
=
message
.
reactions
?.
let
{
val
list
=
mutableListOf
<
ReactionUiModel
>()
val
customEmojis
=
EmojiRepository
.
getCustomEmojis
()
it
.
getShortNames
().
forEach
{
shortname
->
val
usernames
=
it
.
getUsernames
(
shortname
)
?:
emptyList
()
val
count
=
usernames
.
size
val
custom
=
customEmojis
.
firstOrNull
{
emoji
->
emoji
.
shortname
==
shortname
}
list
.
add
(
ReactionUiModel
(
messageId
=
message
.
id
,
shortname
=
shortname
,
unicode
=
EmojiParser
.
parse
(
context
,
shortname
),
count
=
count
,
usernames
=
usernames
)
usernames
=
usernames
,
url
=
custom
?.
url
)
)
}
list
...
...
app/src/main/java/chat/rocket/android/chatroom/uimodel/suggestion/ChatRoomSuggestionUiModel.kt
View file @
91763a21
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 @
91763a21
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 @
91763a21
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/drawable/rounded_background.xml
View file @
91763a21
...
...
@@ -5,5 +5,5 @@
android:width=
"24dp"
android:height=
"24dp"
/>
<solid
android:color=
"#efeeee"
/>
<corners
android:radius=
"4dp"
/>
</shape>
\ No newline at end of file
<corners
android:radius=
"4dp"
/>
</shape>
app/src/main/res/layout/fragment_chat_room.xml
View file @
91763a21
...
...
@@ -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/layout/item_reaction.xml
View file @
91763a21
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"2dp"
android:layout_marginRight=
"2dp"
android:layout_marginTop=
"2dp"
android:layout_marginBottom=
"2dp"
android:descendantFocusability=
"beforeDescendants"
android:background=
"@drawable/rounded_background"
android:orientation=
"horizontal"
>
android:background=
"@drawable/rounded_background"
>
<
TextView
android:id=
"@+id/
text_emoji
"
<
ViewFlipper
android:id=
"@+id/
view_flipper_reaction
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:ellipsize=
"end"
android:maxLines=
"1"
android:paddingLeft=
"4dp"
android:paddingStart=
"4dp"
android:textColor=
"#868585"
android:textSize=
"16sp"
tools:text=
":)"
/>
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@+id/text_count"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
>
<TextView
android:id=
"@+id/text_emoji"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:ellipsize=
"end"
android:maxLines=
"1"
android:paddingStart=
"4dp"
android:paddingLeft=
"4dp"
android:textColor=
"#868585"
android:textSize=
"16sp"
tools:text=
":)"
/>
<ImageView
android:id=
"@+id/image_emoji"
android:layout_width=
"@dimen/custom_emoji_small"
android:layout_height=
"@dimen/custom_emoji_small"
android:layout_gravity=
"center"
tools:src=
"@tools:sample/avatars"
/>
</ViewFlipper>
<TextView
android:id=
"@+id/text_count"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"center"
android:paddingBottom=
"4dp"
android:paddingEnd=
"4dp"
android:paddingLeft=
"4dp"
android:paddingRight=
"4dp"
android:paddingStart=
"4dp"
android:paddingLeft=
"4dp"
android:paddingTop=
"4dp"
android:paddingEnd=
"4dp"
android:paddingRight=
"4dp"
android:paddingBottom=
"4dp"
android:textColor=
"#868585"
android:textSize=
"16sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/view_flipper_reaction"
app:layout_constraintTop_toTopOf=
"parent"
tools:text=
"12"
/>
</
Linear
Layout>
</
androidx.constraintlayout.widget.Constraint
Layout>
app/src/main/res/values/dimens.xml
View file @
91763a21
...
...
@@ -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 @
91763a21
...
...
@@ -10,7 +10,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.2.0-rc0
2
'
classpath
'com.android.tools.build:gradle:3.2.0-rc0
3
'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath
"org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}"
classpath
'com.google.gms:google-services:4.0.2'
...
...
emoji/src/main/java/chat/rocket/android/emoji/EmojiRepository.kt
View file @
91763a21
...
...
@@ -210,7 +210,7 @@ object EmojiRepository {
}
}
internal
fun
getCustomEmojis
():
List
<
Emoji
>
=
customEmojis
fun
getCustomEmojis
():
List
<
Emoji
>
=
customEmojis
/**
* Get all recently used emojis ordered by usage count.
...
...
settings.gradle
View file @
91763a21
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 @
91763a21
/build
suggestions/build.gradle
0 → 100644
View file @
91763a21
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 @
91763a21
# 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 @
91763a21
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 @
91763a21
<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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
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 @
91763a21
...
...
@@ -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 @
91763a21
<?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 @
91763a21
<resources>
<string
name=
"app_name"
>
suggestions
</string>
</resources>
suggestions/src/test/java/yampsample/leonardoaramaki/github/com/suggestions/ExampleUnitTest.java
0 → 100644
View file @
91763a21
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