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
8f037814
Commit
8f037814
authored
Jan 25, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial support for image keyboard accepting only gif
parent
d13702d9
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
163 additions
and
17 deletions
+163
-17
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+69
-15
dependencies.gradle
dependencies.gradle
+1
-0
build.gradle
rocket-chat-android-widgets/build.gradle
+1
-0
MessageFormLayout.java
...chat/rocket/android/widget/message/MessageFormLayout.java
+21
-1
RocketChatEditText.java
...hat/rocket/android/widget/message/RocketChatEditText.java
+70
-0
message_composer.xml
...-android-widgets/src/main/res/layout/message_composer.xml
+1
-1
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
8f037814
...
...
@@ -3,11 +3,15 @@ package chat.rocket.android.fragment.chatroom;
import
android.Manifest
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.Snackbar
;
import
android.support.v13.view.inputmethod.InputConnectionCompat
;
import
android.support.v13.view.inputmethod.InputContentInfoCompat
;
import
android.support.v4.app.DialogFragment
;
import
android.support.v4.os.BuildCompat
;
import
android.support.v4.view.GravityCompat
;
import
android.support.v4.widget.DrawerLayout
;
import
android.support.v4.widget.SlidingPaneLayout
;
...
...
@@ -138,6 +142,7 @@ public class RoomFragment extends AbstractChatRoomFragment
.
createObjectObserver
(
realm
->
realm
.
where
(
LoadMessageProcedure
.
class
).
equalTo
(
LoadMessageProcedure
.
ID
,
roomId
))
.
setOnUpdateListener
(
this
::
onUpdateLoadMessageProcedure
);
if
(
savedInstanceState
==
null
)
{
initialRequest
();
}
...
...
@@ -317,20 +322,11 @@ public class RoomFragment extends AbstractChatRoomFragment
(
MessageFormLayout
)
rootView
.
findViewById
(
R
.
id
.
message_composer
);
messageFormManager
=
new
MessageFormManager
(
messageFormLayout
,
this
::
showExtraActionSelectionDialog
);
messageFormManager
.
setSendMessageCallback
(
messageText
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
.
put
(
Message
.
ID
,
UUID
.
randomUUID
().
toString
())
.
put
(
Message
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
put
(
Message
.
TIMESTAMP
,
System
.
currentTimeMillis
())
.
put
(
Message
.
ROOM_ID
,
roomId
)
.
put
(
Message
.
USER
,
new
JSONObject
()
.
put
(
User
.
ID
,
userId
))
.
put
(
Message
.
MESSAGE
,
messageText
)))
.
onSuccess
(
_task
->
{
scrollToLatestMessage
();
messageFormManager
.
setSendMessageCallback
(
messageText
->
{
sendMessage
(
messageText
);
return
null
;
}));
});
messageFormLayout
.
setEditTextContentListener
(
this
::
onCommitContent
);
}
@Override
...
...
@@ -344,8 +340,12 @@ public class RoomFragment extends AbstractChatRoomFragment
return
;
}
uploadFile
(
data
.
getData
());
}
private
void
uploadFile
(
Uri
uri
)
{
String
uplId
=
new
FileUploadHelper
(
getContext
(),
realmHelper
)
.
requestUploading
(
roomId
,
data
.
getData
()
);
.
requestUploading
(
roomId
,
uri
);
if
(!
TextUtils
.
isEmpty
(
uplId
))
{
FileUploadProgressDialogFragment
.
create
(
serverConfigId
,
roomId
,
uplId
)
.
show
(
getFragmentManager
(),
FileUploadProgressDialogFragment
.
class
.
getSimpleName
());
...
...
@@ -490,4 +490,58 @@ public class RoomFragment extends AbstractChatRoomFragment
protected
void
onExtraActionSelected
(
MessageExtraActionBehavior
action
)
{
action
.
handleItemSelectedOnFragment
(
RoomFragment
.
this
);
}
private
boolean
onCommitContent
(
InputContentInfoCompat
inputContentInfo
,
int
flags
,
Bundle
opts
,
String
[]
supportedMimeTypes
)
{
boolean
supported
=
false
;
for
(
final
String
mimeType
:
supportedMimeTypes
)
{
if
(
inputContentInfo
.
getDescription
().
hasMimeType
(
mimeType
))
{
supported
=
true
;
break
;
}
}
if
(!
supported
)
{
return
false
;
}
if
(
BuildCompat
.
isAtLeastNMR1
()
&&
(
flags
&
InputConnectionCompat
.
INPUT_CONTENT_GRANT_READ_URI_PERMISSION
)
!=
0
)
{
try
{
inputContentInfo
.
requestPermission
();
}
catch
(
Exception
e
)
{
return
false
;
}
}
Uri
linkUri
=
inputContentInfo
.
getLinkUri
();
if
(
linkUri
==
null
)
{
return
false
;
}
sendMessage
(
linkUri
.
toString
());
try
{
inputContentInfo
.
releasePermission
();
}
catch
(
Exception
e
)
{
}
return
true
;
}
private
void
sendMessage
(
String
messageText
)
{
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
.
put
(
Message
.
ID
,
UUID
.
randomUUID
().
toString
())
.
put
(
Message
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
put
(
Message
.
TIMESTAMP
,
System
.
currentTimeMillis
())
.
put
(
Message
.
ROOM_ID
,
roomId
)
.
put
(
Message
.
USER
,
new
JSONObject
()
.
put
(
User
.
ID
,
userId
))
.
put
(
Message
.
MESSAGE
,
messageText
)))
.
onSuccess
(
_task
->
{
scrollToLatestMessage
();
return
null
;
});
}
}
dependencies.gradle
View file @
8f037814
...
...
@@ -11,6 +11,7 @@ ext {
supportAnnotations
=
"com.android.support:support-annotations:$supportVersion"
supportRecyclerView
=
"com.android.support:recyclerview-v7:$supportVersion"
supportAppCompat
=
"com.android.support:appcompat-v7:$supportVersion"
supportV13
=
"com.android.support:support-v13:$supportVersion"
supportDesign
=
"com.android.support:design:$supportVersion"
rxJava
=
'io.reactivex:rxjava:1.2.2'
...
...
rocket-chat-android-widgets/build.gradle
View file @
8f037814
...
...
@@ -33,6 +33,7 @@ dependencies {
testCompile
'junit:junit:4.12'
compile
rootProject
.
ext
.
supportAnnotations
compile
rootProject
.
ext
.
supportAppCompat
compile
rootProject
.
ext
.
supportV13
compile
rootProject
.
ext
.
supportDesign
compile
'org.nibor.autolink:autolink:0.5.0'
compile
rootProject
.
ext
.
textDrawable
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/MessageFormLayout.java
View file @
8f037814
...
...
@@ -3,6 +3,8 @@ package chat.rocket.android.widget.message;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.support.v13.view.inputmethod.InputContentInfoCompat
;
import
android.text.Editable
;
import
android.text.TextUtils
;
import
android.text.TextWatcher
;
...
...
@@ -25,6 +27,7 @@ public class MessageFormLayout extends LinearLayout {
private
ExtraActionSelectionClickListener
extraActionSelectionClickListener
;
private
SubmitTextListener
submitTextListener
;
private
RocketChatEditText
.
ContentListener
listener
;
public
MessageFormLayout
(
Context
context
)
{
super
(
context
);
...
...
@@ -76,7 +79,9 @@ public class MessageFormLayout extends LinearLayout {
btnSubmit
.
setScaleY
(
0
);
btnSubmit
.
setVisibility
(
GONE
);
((
EditText
)
composer
.
findViewById
(
R
.
id
.
editor
)).
addTextChangedListener
(
new
TextWatcher
()
{
RocketChatEditText
editText
=
(
RocketChatEditText
)
composer
.
findViewById
(
R
.
id
.
editor
);
editText
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
}
...
...
@@ -97,6 +102,17 @@ public class MessageFormLayout extends LinearLayout {
}
});
editText
.
setContentListener
(
new
RocketChatEditText
.
ContentListener
()
{
@Override
public
boolean
onCommitContent
(
InputContentInfoCompat
inputContentInfo
,
int
flags
,
Bundle
opts
,
String
[]
supportedMimeTypes
)
{
if
(
listener
!=
null
)
{
return
listener
.
onCommitContent
(
inputContentInfo
,
flags
,
opts
,
supportedMimeTypes
);
}
return
false
;
}
});
addView
(
composer
);
}
...
...
@@ -132,6 +148,10 @@ public class MessageFormLayout extends LinearLayout {
composer
.
findViewById
(
R
.
id
.
btn_submit
).
setEnabled
(
enabled
);
}
public
void
setEditTextContentListener
(
RocketChatEditText
.
ContentListener
listener
)
{
this
.
listener
=
listener
;
}
private
void
animateHide
(
final
View
view
)
{
view
.
animate
().
scaleX
(
0
).
scaleY
(
0
).
setDuration
(
150
).
withEndAction
(
new
Runnable
()
{
@Override
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatEditText.java
0 → 100644
View file @
8f037814
package
chat
.
rocket
.
android
.
widget
.
message
;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.support.v13.view.inputmethod.EditorInfoCompat
;
import
android.support.v13.view.inputmethod.InputConnectionCompat
;
import
android.support.v13.view.inputmethod.InputContentInfoCompat
;
import
android.util.AttributeSet
;
import
android.view.inputmethod.EditorInfo
;
import
android.view.inputmethod.InputConnection
;
import
android.widget.EditText
;
public
class
RocketChatEditText
extends
EditText
{
private
final
String
[]
mimeTypes
=
{
"image/gif"
};
final
InputConnectionCompat
.
OnCommitContentListener
inputConnectionListener
=
new
InputConnectionCompat
.
OnCommitContentListener
()
{
@Override
public
boolean
onCommitContent
(
InputContentInfoCompat
inputContentInfo
,
int
flags
,
Bundle
opts
)
{
if
(
listener
!=
null
)
{
return
listener
.
onCommitContent
(
inputContentInfo
,
flags
,
opts
,
mimeTypes
);
}
return
false
;
}
};
private
ContentListener
listener
;
public
RocketChatEditText
(
Context
context
)
{
super
(
context
);
}
public
RocketChatEditText
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
}
public
RocketChatEditText
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
public
RocketChatEditText
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
,
int
defStyleRes
)
{
super
(
context
,
attrs
,
defStyleAttr
,
defStyleRes
);
}
@Override
public
InputConnection
onCreateInputConnection
(
EditorInfo
editorInfo
)
{
final
InputConnection
inputConnection
=
super
.
onCreateInputConnection
(
editorInfo
);
EditorInfoCompat
.
setContentMimeTypes
(
editorInfo
,
mimeTypes
);
return
InputConnectionCompat
.
createWrapper
(
inputConnection
,
editorInfo
,
inputConnectionListener
);
}
public
void
setContentListener
(
ContentListener
listener
)
{
this
.
listener
=
listener
;
}
public
interface
ContentListener
{
boolean
onCommitContent
(
InputContentInfoCompat
inputContentInfo
,
int
flags
,
Bundle
opts
,
String
[]
supportedMimeTypes
);
}
}
rocket-chat-android-widgets/src/main/res/layout/message_composer.xml
View file @
8f037814
...
...
@@ -21,7 +21,7 @@
android:layout_height=
"32dp"
android:layout_margin=
"8dp"
/>
<EditText
<
chat.rocket.android.widget.message.RocketChat
EditText
android:id=
"@+id/editor"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
...
...
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