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
7db4b7cf
Commit
7db4b7cf
authored
Dec 26, 2016
by
Yusuke Iwaki
Committed by
GitHub
Dec 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #109 from RocketChat/refactor_message_composer
Refactor message composer
parents
8af0b01f
0b3f313e
Changes
23
Show whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
526 additions
and
345 deletions
+526
-345
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+20
-33
MessageSelectionDialogFragment.java
...gment/chatroom/dialog/MessageSelectionDialogFragment.java
+0
-52
MessageComposerManager.java
...android/layouthelper/chatroom/MessageComposerManager.java
+0
-79
MessageFormManager.java
...ket/android/layouthelper/chatroom/MessageFormManager.java
+81
-0
MessageSelectionAdapter.java
...layouthelper/chatroom/dialog/MessageSelectionAdapter.java
+0
-58
AbstractExtraActionItem.java
...id/layouthelper/extra_action/AbstractExtraActionItem.java
+10
-0
MessageExtraActionBehavior.java
...layouthelper/extra_action/MessageExtraActionBehavior.java
+11
-0
AbstractUploadActionItem.java
...thelper/extra_action/upload/AbstractUploadActionItem.java
+30
-0
AudioUploadActionItem.java
...youthelper/extra_action/upload/AudioUploadActionItem.java
+31
-0
ImageUploadActionItem.java
...youthelper/extra_action/upload/ImageUploadActionItem.java
+31
-0
VideoUploadActionItem.java
...youthelper/extra_action/upload/VideoUploadActionItem.java
+31
-0
AbstractMessageSpec.java
...java/chat/rocket/android/message/AbstractMessageSpec.java
+0
-27
AbstractUploadMessageSpec.java
...hat/rocket/android/message/AbstractUploadMessageSpec.java
+0
-34
fragment_room_main.xml
app/src/main/res/layout/fragment_room_main.xml
+1
-1
build.gradle
rocket-chat-android-widgets/build.gradle
+1
-0
ExtraActionPickerDialog.java
...cket/android/widget/internal/ExtraActionPickerDialog.java
+92
-0
MessageExtraActionItemViewHolder.java
...widget/layouthelper/MessageExtraActionItemViewHolder.java
+48
-0
MessageExtraActionListAdapter.java
...id/widget/layouthelper/MessageExtraActionListAdapter.java
+61
-0
MessageExtraActionItemPresenter.java
...droid/widget/message/MessageExtraActionItemPresenter.java
+22
-0
MessageFormLayout.java
...chat/rocket/android/widget/message/MessageFormLayout.java
+49
-51
circle_black.xml
...at-android-widgets/src/main/res/drawable/circle_black.xml
+0
-0
dialog_message_extra_action_picker.xml
...rc/main/res/layout/dialog_message_extra_action_picker.xml
+2
-2
message_extra_action_item.xml
...widgets/src/main/res/layout/message_extra_action_item.xml
+5
-8
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
7db4b7cf
...
...
@@ -22,22 +22,21 @@ import java.util.UUID;
import
chat.rocket.android.R
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.fragment.chatroom.dialog.FileUploadProgressDialogFragment
;
import
chat.rocket.android.fragment.chatroom.dialog.MessageSelectionDialogFragment
;
import
chat.rocket.android.fragment.chatroom.dialog.UsersOfRoomDialogFragment
;
import
chat.rocket.android.helper.FileUploadHelper
;
import
chat.rocket.android.helper.LoadMoreScrollListener
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.OnBackPressListener
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.chatroom.Message
Composer
Manager
;
import
chat.rocket.android.layouthelper.chatroom.Message
Form
Manager
;
import
chat.rocket.android.layouthelper.chatroom.MessageListAdapter
;
import
chat.rocket.android.layouthelper.chatroom.PairedMessage
;
import
chat.rocket.android.layouthelper.extra_action.MessageExtraActionBehavior
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.message.AbstractMessageSpec
;
import
chat.rocket.android.message.AudioUploadMessageSpec
;
import
chat.rocket.android.message.AbstractUploadMessageSpec
;
import
chat.rocket.android.message.ImageUploadMessageSpec
;
import
chat.rocket.android.message.VideoUploadMessageSpec
;
import
chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.AbstractUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.ImageUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.VideoUploadActionItem
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.ddp.Message
;
...
...
@@ -50,7 +49,7 @@ import chat.rocket.android.realm_helper.RealmModelListAdapter;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.service.RocketChatService
;
import
chat.rocket.android.widget.message.Message
Composer
;
import
chat.rocket.android.widget.message.Message
FormLayout
;
import
permissions.dispatcher.NeedsPermission
;
import
permissions.dispatcher.RuntimePermissions
;
...
...
@@ -70,11 +69,7 @@ public class RoomFragment extends AbstractChatRoomFragment
private
String
token
;
private
LoadMoreScrollListener
scrollListener
;
private
RealmObjectObserver
<
LoadMessageProcedure
>
procedureObserver
;
private
MessageComposerManager
messageComposerManager
;
private
MessageSelectionDialogFragment
.
ClickListener
messageSelectionClickListener
=
messageSpec
->
RoomFragmentPermissionsDispatcher
.
onMessageSpecSelectedWithCheck
(
RoomFragment
.
this
,
messageSpec
);
private
MessageFormManager
messageFormManager
;
public
RoomFragment
()
{
}
...
...
@@ -224,10 +219,10 @@ public class RoomFragment extends AbstractChatRoomFragment
}
private
void
setupMessageComposer
()
{
final
Message
Composer
messageComposer
=
(
Message
Composer
)
rootView
.
findViewById
(
R
.
id
.
message_composer
);
message
ComposerManager
=
new
MessageComposerManager
(
messageComposer
);
message
Composer
Manager
.
setSendMessageCallback
(
messageText
->
final
Message
FormLayout
messageFormLayout
=
(
Message
FormLayout
)
rootView
.
findViewById
(
R
.
id
.
message_composer
);
message
FormManager
=
new
MessageFormManager
(
messageFormLayout
);
message
Form
Manager
.
setSendMessageCallback
(
messageText
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
.
put
(
"_id"
,
UUID
.
randomUUID
().
toString
())
...
...
@@ -235,25 +230,17 @@ public class RoomFragment extends AbstractChatRoomFragment
.
put
(
"ts"
,
System
.
currentTimeMillis
())
.
put
(
"rid"
,
roomId
)
.
put
(
"msg"
,
messageText
))));
messageComposerManager
.
setExtrasPickerListener
(()
->
{
MessageSelectionDialogFragment
fragment
=
MessageSelectionDialogFragment
.
create
();
fragment
.
addMessageSpec
(
new
ImageUploadMessageSpec
());
fragment
.
addMessageSpec
(
new
AudioUploadMessageSpec
());
fragment
.
addMessageSpec
(
new
VideoUploadMessageSpec
());
fragment
.
setListener
(
messageSelectionClickListener
);
fragment
.
show
(
getFragmentManager
(),
MessageSelectionDialogFragment
.
TAG
);
closeSideMenuIfNeeded
();
});
messageFormManager
.
registerExtraActionItem
(
new
ImageUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
AudioUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
VideoUploadActionItem
());
messageFormManager
.
setExtraActionPickerCallback
(
item
->
RoomFragmentPermissionsDispatcher
.
onExtraActionSelectedWithCheck
(
RoomFragment
.
this
,
item
));
}
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
!=
AbstractUpload
MessageSpec
.
RC_UPL
||
resultCode
!=
Activity
.
RESULT_OK
)
{
if
(
requestCode
!=
AbstractUpload
ActionItem
.
RC_UPL
||
resultCode
!=
Activity
.
RESULT_OK
)
{
return
;
}
...
...
@@ -381,7 +368,7 @@ public class RoomFragment extends AbstractChatRoomFragment
}
@NeedsPermission
(
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
protected
void
on
MessageSpecSelected
(
AbstractMessageSpec
messageSpec
)
{
messageSpec
.
onSelec
t
(
RoomFragment
.
this
);
protected
void
on
ExtraActionSelected
(
MessageExtraActionBehavior
action
)
{
action
.
handleItemSelectedOnFragmen
t
(
RoomFragment
.
this
);
}
}
app/src/main/java/chat/rocket/android/fragment/chatroom/dialog/MessageSelectionDialogFragment.java
deleted
100644 → 0
View file @
8af0b01f
package
chat
.
rocket
.
android
.
fragment
.
chatroom
.
dialog
;
import
android.support.v7.widget.RecyclerView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.layouthelper.chatroom.dialog.MessageSelectionAdapter
;
import
chat.rocket.android.message.AbstractMessageSpec
;
public
class
MessageSelectionDialogFragment
extends
AbstractChatRoomDialogFragment
{
public
static
final
String
TAG
=
"MessageSelectionDialogFragment"
;
private
MessageSelectionAdapter
adapter
;
private
ClickListener
listener
;
public
static
MessageSelectionDialogFragment
create
()
{
return
new
MessageSelectionDialogFragment
();
}
public
MessageSelectionDialogFragment
()
{
adapter
=
new
MessageSelectionAdapter
();
adapter
.
setListener
(
messageSpec
->
{
if
(
listener
!=
null
)
{
listener
.
onClick
(
messageSpec
);
}
dismiss
();
});
}
public
void
addMessageSpec
(
AbstractMessageSpec
abstractMessageSpec
)
{
adapter
.
addMessageSpec
(
abstractMessageSpec
);
}
public
void
setListener
(
ClickListener
listener
)
{
this
.
listener
=
listener
;
}
@Override
protected
int
getLayout
()
{
return
R
.
layout
.
dialog_message_selection
;
}
@Override
protected
void
onSetupDialog
()
{
RecyclerView
messageSpecList
=
(
RecyclerView
)
getDialog
().
findViewById
(
R
.
id
.
message_spec_list
);
messageSpecList
.
setAdapter
(
adapter
);
}
public
interface
ClickListener
{
void
onClick
(
AbstractMessageSpec
abstractMessageSpec
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageComposerManager.java
deleted
100644 → 0
View file @
8af0b01f
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
;
import
bolts.Task
;
import
chat.rocket.android.widget.message.MessageComposer
;
/**
* handling visibility of FAB-compose and MessageComposer.
*/
public
class
MessageComposerManager
{
private
final
MessageComposer
messageComposer
;
private
SendMessageCallback
sendMessageCallback
;
private
ExtrasPickerListener
extrasPickerListener
;
public
MessageComposerManager
(
MessageComposer
messageComposer
)
{
this
.
messageComposer
=
messageComposer
;
init
();
}
private
void
init
()
{
messageComposer
.
setOnActionListener
(
new
MessageComposer
.
ActionListener
()
{
@Override
public
void
onSubmit
(
String
message
)
{
sendMessage
(
message
);
}
@Override
public
void
onExtra
()
{
openExtras
();
}
@Override
public
void
onCancel
()
{
}
});
}
public
void
setSendMessageCallback
(
SendMessageCallback
sendMessageCallback
)
{
this
.
sendMessageCallback
=
sendMessageCallback
;
}
public
void
setExtrasPickerListener
(
ExtrasPickerListener
listener
)
{
extrasPickerListener
=
listener
;
}
public
void
clearComposingText
()
{
messageComposer
.
setText
(
""
);
}
private
void
sendMessage
(
String
message
)
{
if
(
sendMessageCallback
==
null
)
{
return
;
}
messageComposer
.
setEnabled
(
false
);
sendMessageCallback
.
onSubmit
(
message
).
onSuccess
(
task
->
{
clearComposingText
();
return
null
;
}).
continueWith
(
task
->
{
messageComposer
.
setEnabled
(
true
);
return
null
;
});
}
private
void
openExtras
()
{
if
(
extrasPickerListener
==
null
)
{
return
;
}
extrasPickerListener
.
onOpen
();
}
public
interface
SendMessageCallback
{
Task
<
Void
>
onSubmit
(
String
messageText
);
}
public
interface
ExtrasPickerListener
{
void
onOpen
();
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageFormManager.java
0 → 100644
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
;
import
java.util.HashMap
;
import
bolts.Task
;
import
chat.rocket.android.layouthelper.extra_action.AbstractExtraActionItem
;
import
chat.rocket.android.widget.message.MessageFormLayout
;
/**
* handling MessageForm.
*/
public
class
MessageFormManager
{
private
final
MessageFormLayout
messageFormLayout
;
private
SendMessageCallback
sendMessageCallback
;
private
ExtraActionPickerCallback
extraActionPickerCallback
;
private
final
HashMap
<
Integer
,
AbstractExtraActionItem
>
extraActionItemMap
;
public
MessageFormManager
(
MessageFormLayout
messageFormLayout
)
{
this
.
messageFormLayout
=
messageFormLayout
;
this
.
extraActionItemMap
=
new
HashMap
<>();
init
();
}
private
void
init
()
{
messageFormLayout
.
setOnActionListener
(
new
MessageFormLayout
.
ActionListener
()
{
@Override
public
void
onSubmitText
(
String
message
)
{
sendMessage
(
message
);
}
@Override
public
void
onExtraActionSelected
(
int
itemId
)
{
if
(
extraActionItemMap
.
containsKey
(
itemId
))
{
AbstractExtraActionItem
item
=
extraActionItemMap
.
get
(
itemId
);
if
(
extraActionPickerCallback
!=
null
)
{
extraActionPickerCallback
.
onExtraActionSelected
(
item
);
}
}
}
});
}
public
void
setSendMessageCallback
(
SendMessageCallback
sendMessageCallback
)
{
this
.
sendMessageCallback
=
sendMessageCallback
;
}
public
void
setExtraActionPickerCallback
(
ExtraActionPickerCallback
extraActionPickerCallback
)
{
this
.
extraActionPickerCallback
=
extraActionPickerCallback
;
}
public
void
clearComposingText
()
{
messageFormLayout
.
setText
(
""
);
}
private
void
sendMessage
(
String
message
)
{
if
(
sendMessageCallback
==
null
)
{
return
;
}
messageFormLayout
.
setEnabled
(
false
);
sendMessageCallback
.
onSubmitText
(
message
).
onSuccess
(
task
->
{
clearComposingText
();
return
null
;
}).
continueWith
(
task
->
{
messageFormLayout
.
setEnabled
(
true
);
return
null
;
});
}
public
void
registerExtraActionItem
(
AbstractExtraActionItem
actionItem
)
{
messageFormLayout
.
addExtraActionItem
(
actionItem
);
extraActionItemMap
.
put
(
actionItem
.
getItemId
(),
actionItem
);
}
public
interface
SendMessageCallback
{
Task
<
Void
>
onSubmitText
(
String
messageText
);
}
public
interface
ExtraActionPickerCallback
{
void
onExtraActionSelected
(
AbstractExtraActionItem
item
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/dialog/MessageSelectionAdapter.java
deleted
100644 → 0
View file @
8af0b01f
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
.
dialog
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
java.util.ArrayList
;
import
java.util.List
;
import
chat.rocket.android.R
;
import
chat.rocket.android.message.AbstractMessageSpec
;
public
class
MessageSelectionAdapter
extends
RecyclerView
.
Adapter
<
MessageSelectionViewHolder
>
{
private
List
<
AbstractMessageSpec
>
abstractMessageSpecs
=
new
ArrayList
<>();
private
ClickListener
listener
;
public
void
setListener
(
ClickListener
listener
)
{
this
.
listener
=
listener
;
}
public
void
addMessageSpec
(
AbstractMessageSpec
abstractMessageSpec
)
{
abstractMessageSpecs
.
add
(
abstractMessageSpec
);
notifyDataSetChanged
();
}
@Override
public
MessageSelectionViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
View
itemView
=
LayoutInflater
.
from
(
parent
.
getContext
())
.
inflate
(
R
.
layout
.
dialog_message_selection_item
,
parent
,
false
);
itemView
.
setOnClickListener
(
view
->
{
if
(
listener
!=
null
)
{
listener
.
onClick
((
AbstractMessageSpec
)
itemView
.
getTag
());
}
});
return
new
MessageSelectionViewHolder
(
itemView
);
}
@Override
public
void
onBindViewHolder
(
MessageSelectionViewHolder
holder
,
int
position
)
{
holder
.
onBind
(
abstractMessageSpecs
.
get
(
position
));
}
@Override
public
int
getItemCount
()
{
return
abstractMessageSpecs
.
size
();
}
public
interface
ClickListener
{
void
onClick
(
AbstractMessageSpec
abstractMessageSpec
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/extra_action/AbstractExtraActionItem.java
0 → 100644
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
layouthelper
.
extra_action
;
import
chat.rocket.android.widget.message.MessageExtraActionItemPresenter
;
/**
* Simple base class that implements MessageExtraActionBehavior, MessageExtraActionItemPresenter.
*/
public
abstract
class
AbstractExtraActionItem
implements
MessageExtraActionBehavior
,
MessageExtraActionItemPresenter
{
}
app/src/main/java/chat/rocket/android/layouthelper/extra_action/MessageExtraActionBehavior.java
0 → 100644
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
layouthelper
.
extra_action
;
import
android.app.Activity
;
import
android.support.v4.app.Fragment
;
public
interface
MessageExtraActionBehavior
{
void
handleItemSelectedOnActivity
(
Activity
activity
);
void
handleItemSelectedOnFragment
(
Fragment
fragment
);
}
app/src/main/java/chat/rocket/android/layouthelper/extra_action/upload/AbstractUploadActionItem.java
0 → 100644
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
layouthelper
.
extra_action
.
upload
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.support.v4.app.Fragment
;
import
chat.rocket.android.R
;
import
chat.rocket.android.layouthelper.extra_action.AbstractExtraActionItem
;
public
abstract
class
AbstractUploadActionItem
extends
AbstractExtraActionItem
{
public
static
final
int
RC_UPL
=
0x12
;
@Override
public
void
handleItemSelectedOnActivity
(
Activity
activity
)
{
activity
.
startActivityForResult
(
getIntentForPickFile
(),
RC_UPL
);
}
@Override
public
void
handleItemSelectedOnFragment
(
Fragment
fragment
)
{
fragment
.
startActivityForResult
(
getIntentForPickFile
(),
RC_UPL
);
}
protected
abstract
Intent
getIntentForPickFile
();
@Override
public
int
getBackgroundTint
()
{
return
R
.
color
.
colorAccent
;
}
}
app/src/main/java/chat/rocket/android/
message/AudioUploadMessageSpec
.java
→
app/src/main/java/chat/rocket/android/
layouthelper/extra_action/upload/AudioUploadActionItem
.java
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
message
;
package
chat
.
rocket
.
android
.
layouthelper
.
extra_action
.
upload
;
import
android.content.Intent
;
import
chat.rocket.android.R
;
public
class
AudioUpload
MessageSpec
extends
AbstractUploadMessageSpec
{
public
class
AudioUpload
ActionItem
extends
AbstractUploadActionItem
{
@Override
protected
Intent
getIntent
()
{
public
int
getItemId
()
{
return
11
;
}
@Override
protected
Intent
getIntentForPickFile
()
{
Intent
intent
=
new
Intent
();
intent
.
setType
(
"audio/*"
);
intent
.
setAction
(
Intent
.
ACTION_GET_CONTENT
);
return
Intent
.
createChooser
(
intent
,
"Select Audio to Upload"
);
}
@Override
public
ViewData
getSpecificViewData
()
{
return
new
AudioUploadViewData
();
}
private
static
class
AudioUploadViewData
implements
AbstractMessageSpec
.
ViewData
{
@Override
public
int
getBackgroundTint
()
{
return
R
.
color
.
colorAccent
;
}
@Override
public
int
getIcon
()
{
return
R
.
drawable
.
ic_audiotrack_white_24dp
;
...
...
@@ -34,5 +28,4 @@ public class AudioUploadMessageSpec extends AbstractUploadMessageSpec {
public
int
getTitle
()
{
return
R
.
string
.
audio_upload_message_spec_title
;
}
}
}
app/src/main/java/chat/rocket/android/
message/ImageUploadMessageSpec
.java
→
app/src/main/java/chat/rocket/android/
layouthelper/extra_action/upload/ImageUploadActionItem
.java
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
message
;
package
chat
.
rocket
.
android
.
layouthelper
.
extra_action
.
upload
;
import
android.content.Intent
;
import
chat.rocket.android.R
;
public
class
ImageUpload
MessageSpec
extends
AbstractUploadMessageSpec
{
public
class
ImageUpload
ActionItem
extends
AbstractUploadActionItem
{
@Override
public
ViewData
getSpecificViewData
()
{
return
new
ImageUploadViewData
()
;
public
int
getItemId
()
{
return
10
;
}
@Override
protected
Intent
getIntent
()
{
protected
Intent
getIntent
ForPickFile
()
{
Intent
intent
=
new
Intent
();
intent
.
setType
(
"image/*"
);
intent
.
setAction
(
Intent
.
ACTION_GET_CONTENT
);
return
Intent
.
createChooser
(
intent
,
"Select Picture to Upload"
);
}
private
static
class
ImageUploadViewData
implements
AbstractMessageSpec
.
ViewData
{
@Override
public
int
getBackgroundTint
()
{
return
R
.
color
.
colorAccent
;
}
@Override
public
int
getIcon
()
{
return
R
.
drawable
.
ic_insert_photo_white_24dp
;
...
...
@@ -34,5 +28,4 @@ public class ImageUploadMessageSpec extends AbstractUploadMessageSpec {
public
int
getTitle
()
{
return
R
.
string
.
image_upload_message_spec_title
;
}
}
}
app/src/main/java/chat/rocket/android/
message/VideoUploadMessageSpec
.java
→
app/src/main/java/chat/rocket/android/
layouthelper/extra_action/upload/VideoUploadActionItem
.java
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
message
;
package
chat
.
rocket
.
android
.
layouthelper
.
extra_action
.
upload
;
import
android.content.Intent
;
import
chat.rocket.android.R
;
public
class
VideoUpload
MessageSpec
extends
AbstractUploadMessageSpec
{
public
class
VideoUpload
ActionItem
extends
AbstractUploadActionItem
{
@Override
public
ViewData
getSpecificViewData
()
{
return
new
VideoUploadViewData
()
;
public
int
getItemId
()
{
return
12
;
}
@Override
protected
Intent
getIntent
()
{
protected
Intent
getIntent
ForPickFile
()
{
Intent
intent
=
new
Intent
();
intent
.
setType
(
"video/*"
);
intent
.
setAction
(
Intent
.
ACTION_GET_CONTENT
);
return
Intent
.
createChooser
(
intent
,
"Select Video to Upload"
);
}
private
static
class
VideoUploadViewData
implements
AbstractMessageSpec
.
ViewData
{
@Override
public
int
getBackgroundTint
()
{
return
R
.
color
.
colorAccent
;
}
@Override
public
int
getIcon
()
{
return
R
.
drawable
.
ic_video_call_white_24dp
;
...
...
@@ -34,5 +28,4 @@ public class VideoUploadMessageSpec extends AbstractUploadMessageSpec {
public
int
getTitle
()
{
return
R
.
string
.
video_upload_message_spec_title
;
}
}
}
app/src/main/java/chat/rocket/android/message/AbstractMessageSpec.java
deleted
100644 → 0
View file @
8af0b01f
package
chat
.
rocket
.
android
.
message
;
import
android.app.Activity
;
import
android.support.v4.app.Fragment
;
import
android.support.annotation.ColorRes
;
import
android.support.annotation.DrawableRes
;
import
android.support.annotation.StringRes
;
public
abstract
class
AbstractMessageSpec
{
public
abstract
ViewData
getViewData
();
public
abstract
void
onSelect
(
Activity
activity
);
public
abstract
void
onSelect
(
Fragment
fragment
);
public
interface
ViewData
{
@ColorRes
int
getBackgroundTint
();
@DrawableRes
int
getIcon
();
@StringRes
int
getTitle
();
}
}
app/src/main/java/chat/rocket/android/message/AbstractUploadMessageSpec.java
deleted
100644 → 0
View file @
8af0b01f
package
chat
.
rocket
.
android
.
message
;
import
android.app.Activity
;
import
android.support.v4.app.Fragment
;
import
android.content.Intent
;
public
abstract
class
AbstractUploadMessageSpec
extends
AbstractMessageSpec
{
public
static
final
int
RC_UPL
=
0x12
;
private
ViewData
viewData
;
@Override
public
ViewData
getViewData
()
{
if
(
viewData
==
null
)
{
viewData
=
getSpecificViewData
();
}
return
viewData
;
}
@Override
public
void
onSelect
(
Activity
activity
)
{
activity
.
startActivityForResult
(
getIntent
(),
RC_UPL
);
}
@Override
public
void
onSelect
(
Fragment
fragment
)
{
fragment
.
startActivityForResult
(
getIntent
(),
RC_UPL
);
}
protected
abstract
Intent
getIntent
();
protected
abstract
ViewData
getSpecificViewData
();
}
app/src/main/res/layout/fragment_room_main.xml
View file @
7db4b7cf
...
...
@@ -9,7 +9,7 @@
android:layout_height=
"match_parent"
android:layout_above=
"@+id/message_composer"
/>
<chat.rocket.android.widget.message.Message
Composer
<chat.rocket.android.widget.message.Message
FormLayout
android:id=
"@+id/message_composer"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
...
...
rocket-chat-android-widgets/build.gradle
View file @
7db4b7cf
...
...
@@ -38,4 +38,5 @@ dependencies {
compile
rootProject
.
ext
.
okhttp3
compile
rootProject
.
ext
.
picasso
compile
rootProject
.
ext
.
picasso2Okhttp3Downloader
compile
rootProject
.
ext
.
boltsTask
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/internal/ExtraActionPickerDialog.java
0 → 100644
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
widget
.
internal
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
android.os.OperationCanceledException
;
import
android.support.annotation.NonNull
;
import
android.support.design.widget.BottomSheetDialog
;
import
android.support.v7.widget.RecyclerView
;
import
java.util.List
;
import
bolts.Task
;
import
bolts.TaskCompletionSource
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.layouthelper.MessageExtraActionListAdapter
;
import
chat.rocket.android.widget.message.MessageExtraActionItemPresenter
;
public
class
ExtraActionPickerDialog
{
/**
* show extra actions picker diaog.
*/
public
static
Task
<
Integer
>
showAsTask
(
Context
context
,
List
<
MessageExtraActionItemPresenter
>
actionItems
)
{
final
TaskCompletionSource
<
Integer
>
task
=
new
TaskCompletionSource
<>();
Impl
dialog
=
new
Impl
(
context
,
actionItems
);
dialog
.
setCallback
(
new
Impl
.
Callback
()
{
@Override
public
void
onItemSelected
(
int
itemId
)
{
task
.
setResult
(
itemId
);
}
@Override
public
void
onCanceled
()
{
task
.
setError
(
new
OperationCanceledException
());
}
});
dialog
.
show
();
return
task
.
getTask
();
}
private
static
class
Impl
extends
BottomSheetDialog
{
private
interface
Callback
{
void
onItemSelected
(
int
itemId
);
void
onCanceled
();
}
private
Callback
callback
;
private
final
List
<
MessageExtraActionItemPresenter
>
actionItems
;
public
void
setCallback
(
Callback
callback
)
{
this
.
callback
=
callback
;
}
public
Impl
(
@NonNull
Context
context
,
List
<
MessageExtraActionItemPresenter
>
actionItems
)
{
super
(
context
);
this
.
actionItems
=
actionItems
;
}
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
dialog_message_extra_action_picker
);
MessageExtraActionListAdapter
adapter
=
new
MessageExtraActionListAdapter
(
actionItems
);
adapter
.
setOnItemClickListener
(
new
MessageExtraActionListAdapter
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
int
itemId
)
{
doCallback
(
itemId
);
dismiss
();
}
});
RecyclerView
recyclerView
=
(
RecyclerView
)
findViewById
(
R
.
id
.
message_extra_action_listview
);
recyclerView
.
setAdapter
(
adapter
);
setOnCancelListener
(
new
OnCancelListener
()
{
@Override
public
void
onCancel
(
DialogInterface
dialogInterface
)
{
if
(
callback
!=
null
)
{
callback
.
onCanceled
();
}
}
});
}
private
void
doCallback
(
int
itemId
)
{
if
(
callback
!=
null
)
{
callback
.
onItemSelected
(
itemId
);
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/layouthelper/chatroom/dialog/MessageSelection
ViewHolder.java
→
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/layouthelper/MessageExtraActionItem
ViewHolder.java
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
.
dialog
;
package
chat
.
rocket
.
android
.
widget
.
layouthelper
;
import
android.support.annotation.ColorRes
;
import
android.support.annotation.DrawableRes
;
...
...
@@ -10,40 +10,39 @@ import android.view.View;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.
message.AbstractMessageSpec
;
import
chat.rocket.android.
widget.
R
;
import
chat.rocket.android.
widget.message.MessageExtraActionItemPresenter
;
public
class
Message
Selection
ViewHolder
extends
RecyclerView
.
ViewHolder
{
public
class
Message
ExtraActionItem
ViewHolder
extends
RecyclerView
.
ViewHolder
{
private
ImageView
messageSpecIcon
;
private
TextView
messageSpecTitle
;
private
ImageView
iconView
;
private
TextView
titleView
;
public
Message
Selection
ViewHolder
(
View
itemView
)
{
public
Message
ExtraActionItem
ViewHolder
(
View
itemView
)
{
super
(
itemView
);
messageSpecIcon
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
message_spec_
icon
);
messageSpecTitle
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
message_spec_
title
);
iconView
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
icon
);
titleView
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
title
);
}
public
void
onBind
(
AbstractMessageSpec
abstractMessageSpec
)
{
itemView
.
setTag
(
a
bstractMessageSpec
);
public
void
onBind
(
MessageExtraActionItemPresenter
actionItem
)
{
itemView
.
setTag
(
a
ctionItem
.
getItemId
()
);
AbstractMessageSpec
.
ViewData
viewData
=
abstractMessageSpec
.
getViewData
();
setIconBackgroundColorTint
(
viewData
.
getBackgroundTint
());
setIcon
(
viewData
.
getIcon
());
setTitle
(
viewData
.
getTitle
());
setIconBackgroundColorTint
(
actionItem
.
getBackgroundTint
());
setIcon
(
actionItem
.
getIcon
());
setTitle
(
actionItem
.
getTitle
());
}
public
void
setIconBackgroundColorTint
(
@ColorRes
int
color
)
{
// Drawable background = DrawableCompat.wrap(messageSpecIcon.getBackground());
DrawableCompat
.
setTint
(
messageSpecIcon
.
getBackground
(),
ContextCompat
.
getColor
(
messageSpecIcon
.
getContext
(),
color
));
DrawableCompat
.
setTint
(
iconView
.
getBackground
(),
ContextCompat
.
getColor
(
iconView
.
getContext
(),
color
));
}
public
void
setIcon
(
@DrawableRes
int
icon
)
{
messageSpecIcon
.
setImageResource
(
icon
);
iconView
.
setImageResource
(
icon
);
}
public
void
setTitle
(
@StringRes
int
title
)
{
messageSpecTitle
.
setText
(
title
);
titleView
.
setText
(
title
);
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/layouthelper/MessageExtraActionListAdapter.java
0 → 100644
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
widget
.
layouthelper
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
java.util.List
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.message.MessageExtraActionItemPresenter
;
public
class
MessageExtraActionListAdapter
extends
RecyclerView
.
Adapter
<
MessageExtraActionItemViewHolder
>
{
private
final
List
<
MessageExtraActionItemPresenter
>
actionItems
;
private
OnItemClickListener
listener
;
public
MessageExtraActionListAdapter
(
List
<
MessageExtraActionItemPresenter
>
actionItems
)
{
this
.
actionItems
=
actionItems
;
}
public
void
setOnItemClickListener
(
OnItemClickListener
listener
)
{
this
.
listener
=
listener
;
}
@Override
public
MessageExtraActionItemViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
View
itemView
=
LayoutInflater
.
from
(
parent
.
getContext
())
.
inflate
(
R
.
layout
.
message_extra_action_item
,
parent
,
false
);
itemView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
if
(
listener
!=
null
)
{
if
(
view
.
getTag
()
!=
null
)
{
listener
.
onItemClick
((
int
)
view
.
getTag
());
}
}
}
});
return
new
MessageExtraActionItemViewHolder
(
itemView
);
}
@Override
public
void
onBindViewHolder
(
MessageExtraActionItemViewHolder
holder
,
int
position
)
{
holder
.
onBind
(
actionItems
.
get
(
position
));
}
@Override
public
int
getItemCount
()
{
return
actionItems
.
size
();
}
public
interface
OnItemClickListener
{
void
onItemClick
(
int
itemId
);
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/MessageExtraActionItemPresenter.java
0 → 100644
View file @
7db4b7cf
package
chat
.
rocket
.
android
.
widget
.
message
;
import
android.support.annotation.ColorRes
;
import
android.support.annotation.DrawableRes
;
import
android.support.annotation.StringRes
;
/**
* View Data for message extra action item.
*/
public
interface
MessageExtraActionItemPresenter
{
int
getItemId
();
@ColorRes
int
getBackgroundTint
();
@DrawableRes
int
getIcon
();
@StringRes
int
getTitle
();
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/Message
Composer
.java
→
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/Message
FormLayout
.java
View file @
7db4b7cf
...
...
@@ -5,43 +5,49 @@ import android.content.Context;
import
android.os.Build
;
import
android.support.annotation.Nullable
;
import
android.text.Editable
;
import
android.text.TextUtils
;
import
android.text.TextWatcher
;
import
android.util.AttributeSet
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.EditText
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
java.util.ArrayList
;
import
java.util.List
;
import
bolts.Continuation
;
import
bolts.Task
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.internal.ExtraActionPickerDialog
;
public
class
Message
Composer
extends
LinearLayout
{
public
class
Message
FormLayout
extends
LinearLayout
{
protected
ActionListener
actionListener
;
protected
ViewGroup
composer
;
private
View
btnExtra
;
private
View
btnSubmit
;
private
List
<
MessageExtraActionItemPresenter
>
extraActionItems
;
public
Message
Composer
(
Context
context
)
{
public
Message
FormLayout
(
Context
context
)
{
super
(
context
);
init
();
}
public
Message
Composer
(
Context
context
,
AttributeSet
attrs
)
{
public
Message
FormLayout
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
init
();
}
public
Message
Composer
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
public
Message
FormLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
init
();
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
public
Message
Composer
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
,
int
defStyleRes
)
{
public
Message
FormLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
,
int
defStyleRes
)
{
super
(
context
,
attrs
,
defStyleAttr
,
defStyleRes
);
init
();
}
...
...
@@ -51,6 +57,7 @@ public class MessageComposer extends LinearLayout {
}
private
void
init
()
{
extraActionItems
=
new
ArrayList
<>();
composer
=
(
ViewGroup
)
LayoutInflater
.
from
(
getContext
())
.
inflate
(
R
.
layout
.
message_composer
,
this
,
false
);
...
...
@@ -58,10 +65,8 @@ public class MessageComposer extends LinearLayout {
btnExtra
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
if
(
actionListener
!=
null
)
{
actionListener
.
onExtra
();
}
public
void
onClick
(
View
view
)
{
showExtraActionSelectionDialog
();
}
});
...
...
@@ -72,12 +77,13 @@ public class MessageComposer extends LinearLayout {
public
void
onClick
(
View
view
)
{
String
messageText
=
getText
();
if
(
messageText
.
length
()
>
0
&&
actionListener
!=
null
)
{
actionListener
.
onSubmit
(
messageText
);
actionListener
.
onSubmit
Text
(
messageText
);
}
}
});
btnSubmit
.
animate
().
scaleX
(
0
).
scaleY
(
0
).
setDuration
(
0
);
btnSubmit
.
setScaleX
(
0
);
btnSubmit
.
setScaleY
(
0
);
btnSubmit
.
setVisibility
(
GONE
);
((
EditText
)
composer
.
findViewById
(
R
.
id
.
editor
)).
addTextChangedListener
(
new
TextWatcher
()
{
...
...
@@ -91,7 +97,7 @@ public class MessageComposer extends LinearLayout {
@Override
public
void
afterTextChanged
(
Editable
s
)
{
if
(
s
.
toString
().
trim
().
length
(
)
>
0
)
{
if
(
TextUtils
.
getTrimmedLength
(
s
)
>
0
)
{
animateHide
(
btnExtra
);
animateShow
(
btnSubmit
);
}
else
{
...
...
@@ -104,6 +110,20 @@ public class MessageComposer extends LinearLayout {
addView
(
composer
);
}
public
void
addExtraActionItem
(
MessageExtraActionItemPresenter
itemPresenter
)
{
boolean
found
=
false
;
for
(
MessageExtraActionItemPresenter
item
:
extraActionItems
)
{
if
(
item
.
getItemId
()
==
itemPresenter
.
getItemId
())
{
found
=
true
;
break
;
}
}
if
(!
found
)
{
extraActionItems
.
add
(
itemPresenter
);
}
}
private
TextView
getEditor
()
{
return
(
TextView
)
composer
.
findViewById
(
R
.
id
.
editor
);
}
...
...
@@ -121,40 +141,6 @@ public class MessageComposer extends LinearLayout {
composer
.
findViewById
(
R
.
id
.
btn_submit
).
setEnabled
(
enabled
);
}
protected
final
void
focusToEditor
()
{
final
TextView
editor
=
getEditor
();
editor
.
requestFocus
();
InputMethodManager
imm
=
(
InputMethodManager
)
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
showSoftInput
(
editor
,
InputMethodManager
.
SHOW_IMPLICIT
);
}
protected
final
void
unFocusEditor
()
{
InputMethodManager
imm
=
(
InputMethodManager
)
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
hideSoftInputFromWindow
(
getWindowToken
(),
InputMethodManager
.
HIDE_NOT_ALWAYS
);
}
public
void
show
(
@Nullable
Runnable
callback
)
{
focusToEditor
();
setVisibility
(
View
.
VISIBLE
);
if
(
callback
!=
null
)
{
callback
.
run
();
}
}
public
void
hide
(
@Nullable
Runnable
callback
)
{
unFocusEditor
();
setVisibility
(
View
.
GONE
);
if
(
callback
!=
null
)
{
callback
.
run
();
}
}
public
boolean
isShown
()
{
return
getVisibility
()
==
View
.
VISIBLE
;
}
private
void
animateHide
(
final
View
view
)
{
view
.
animate
().
scaleX
(
0
).
scaleY
(
0
).
setDuration
(
150
).
withEndAction
(
new
Runnable
()
{
@Override
...
...
@@ -173,11 +159,23 @@ public class MessageComposer extends LinearLayout {
});
}
public
interface
ActionListener
{
void
onSubmit
(
String
message
);
private
void
showExtraActionSelectionDialog
()
{
ExtraActionPickerDialog
.
showAsTask
(
getContext
(),
extraActionItems
)
.
onSuccess
(
new
Continuation
<
Integer
,
Object
>()
{
@Override
public
Object
then
(
Task
<
Integer
>
task
)
throws
Exception
{
int
which
=
task
.
getResult
();
if
(
actionListener
!=
null
)
{
actionListener
.
onExtraActionSelected
(
which
);
}
return
null
;
}
});
}
void
onExtra
();
public
interface
ActionListener
{
void
onSubmitText
(
String
message
);
void
on
Cancel
(
);
void
on
ExtraActionSelected
(
int
itemId
);
}
}
app
/src/main/res/drawable/circle_black.xml
→
rocket-chat-android-widgets
/src/main/res/drawable/circle_black.xml
View file @
7db4b7cf
File moved
app/src/main/res/layout/dialog_message_selection
.xml
→
rocket-chat-android-widgets/src/main/res/layout/dialog_message_extra_action_picker
.xml
View file @
7db4b7cf
<?xml version="1.0" encoding="utf-8"?>
<chat.rocket.android.widget.AutofitRecyclerView
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/message_
spec_list
"
android:id=
"@+id/message_
extra_action_listview
"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:columnWidth=
"80dp"
tools:listitem=
"@layout/
dialog_message_sele
ction_item"
tools:listitem=
"@layout/
message_extra_a
ction_item"
android:clipToPadding=
"false"
>
</chat.rocket.android.widget.AutofitRecyclerView>
\ No newline at end of file
app/src/main/res/layout/dialog_message_sele
ction_item.xml
→
rocket-chat-android-widgets/src/main/res/layout/message_extra_a
ction_item.xml
View file @
7db4b7cf
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:orientation=
"vertical"
android:layout_width=
"80dp"
android:layout_height=
"wrap_content"
android:padding=
"
@dimen/margin_8
"
>
android:padding=
"
8dp
"
>
<ImageView
android:id=
"@+id/
message_spec_
icon"
android:id=
"@+id/icon"
android:layout_width=
"64dp"
android:layout_height=
"64dp"
android:padding=
"@dimen/margin_16"
tools:src=
"@drawable/ic_insert_photo_white_24dp"
android:padding=
"16dp"
android:layout_marginBottom=
"4dp"
android:background=
"@drawable/circle_black"
/>
<TextView
android:id=
"@+id/
message_spec_
title"
android:id=
"@+id/title"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_horizontal"
tools:text=
"Attach file"
/>
android:gravity=
"center_horizontal"
/>
</LinearLayout>
\ 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