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
0b3f313e
Commit
0b3f313e
authored
Dec 24, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
baa0ddaf
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
453 additions
and
239 deletions
+453
-239
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+16
-29
MessageSelectionDialogFragment.java
...gment/chatroom/dialog/MessageSelectionDialogFragment.java
+0
-52
MessageFormManager.java
...ket/android/layouthelper/chatroom/MessageFormManager.java
+22
-20
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
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
+40
-9
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 @
0b3f313e
...
...
@@ -22,7 +22,6 @@ 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
;
...
...
@@ -32,12 +31,12 @@ import chat.rocket.android.helper.TextUtils;
import
chat.rocket.android.layouthelper.chatroom.MessageFormManager
;
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
;
...
...
@@ -70,11 +69,7 @@ public class RoomFragment extends AbstractChatRoomFragment
private
String
token
;
private
LoadMoreScrollListener
scrollListener
;
private
RealmObjectObserver
<
LoadMessageProcedure
>
procedureObserver
;
private
MessageFormManager
messageComposerManager
;
private
MessageSelectionDialogFragment
.
ClickListener
messageSelectionClickListener
=
messageSpec
->
RoomFragmentPermissionsDispatcher
.
onMessageSpecSelectedWithCheck
(
RoomFragment
.
this
,
messageSpec
);
private
MessageFormManager
messageFormManager
;
public
RoomFragment
()
{
}
...
...
@@ -226,8 +221,8 @@ public class RoomFragment extends AbstractChatRoomFragment
private
void
setupMessageComposer
()
{
final
MessageFormLayout
messageFormLayout
=
(
MessageFormLayout
)
rootView
.
findViewById
(
R
.
id
.
message_composer
);
message
Composer
Manager
=
new
MessageFormManager
(
messageFormLayout
);
message
Composer
Manager
.
setSendMessageCallback
(
messageText
->
message
Form
Manager
=
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 @
baa0ddaf
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/MessageFormManager.java
View file @
0b3f313e
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
;
/**
...
...
@@ -9,27 +11,30 @@ import chat.rocket.android.widget.message.MessageFormLayout;
public
class
MessageFormManager
{
private
final
MessageFormLayout
messageFormLayout
;
private
SendMessageCallback
sendMessageCallback
;
private
ExtrasPickerListener
extrasPickerListener
;
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
onSubmit
(
String
message
)
{
public
void
onSubmit
Text
(
String
message
)
{
sendMessage
(
message
);
}
@Override
public
void
onExtra
()
{
openExtras
();
public
void
onExtraActionSelected
(
int
itemId
)
{
if
(
extraActionItemMap
.
containsKey
(
itemId
))
{
AbstractExtraActionItem
item
=
extraActionItemMap
.
get
(
itemId
);
if
(
extraActionPickerCallback
!=
null
)
{
extraActionPickerCallback
.
onExtraActionSelected
(
item
);
}
}
@Override
public
void
onCancel
()
{
}
});
}
...
...
@@ -38,8 +43,8 @@ public class MessageFormManager {
this
.
sendMessageCallback
=
sendMessageCallback
;
}
public
void
setExtra
sPickerListener
(
ExtrasPickerListener
listener
)
{
extrasPickerListener
=
listener
;
public
void
setExtra
ActionPickerCallback
(
ExtraActionPickerCallback
extraActionPickerCallback
)
{
this
.
extraActionPickerCallback
=
extraActionPickerCallback
;
}
public
void
clearComposingText
()
{
...
...
@@ -52,7 +57,7 @@ public class MessageFormManager {
}
messageFormLayout
.
setEnabled
(
false
);
sendMessageCallback
.
onSubmit
(
message
).
onSuccess
(
task
->
{
sendMessageCallback
.
onSubmit
Text
(
message
).
onSuccess
(
task
->
{
clearComposingText
();
return
null
;
}).
continueWith
(
task
->
{
...
...
@@ -61,19 +66,16 @@ public class MessageFormManager {
});
}
private
void
openExtras
()
{
if
(
extrasPickerListener
==
null
)
{
return
;
}
extrasPickerListener
.
onOpen
();
public
void
registerExtraActionItem
(
AbstractExtraActionItem
actionItem
)
{
messageFormLayout
.
addExtraActionItem
(
actionItem
);
extraActionItemMap
.
put
(
actionItem
.
getItemId
(),
actionItem
);
}
public
interface
SendMessageCallback
{
Task
<
Void
>
onSubmit
(
String
messageText
);
Task
<
Void
>
onSubmit
Text
(
String
messageText
);
}
public
interface
Extra
sPickerListener
{
void
on
Open
(
);
public
interface
Extra
ActionPickerCallback
{
void
on
ExtraActionSelected
(
AbstractExtraActionItem
item
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/dialog/MessageSelectionAdapter.java
deleted
100644 → 0
View file @
baa0ddaf
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 @
0b3f313e
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 @
0b3f313e
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 @
0b3f313e
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 @
0b3f313e
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 @
0b3f313e
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 @
0b3f313e
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 @
baa0ddaf
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 @
baa0ddaf
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
();
}
rocket-chat-android-widgets/build.gradle
View file @
0b3f313e
...
...
@@ -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 @
0b3f313e
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 @
0b3f313e
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 @
0b3f313e
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 @
0b3f313e
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/MessageFormLayout.java
View file @
0b3f313e
...
...
@@ -15,7 +15,12 @@ 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
MessageFormLayout
extends
LinearLayout
{
...
...
@@ -24,6 +29,7 @@ public class MessageFormLayout extends LinearLayout {
private
View
btnExtra
;
private
View
btnSubmit
;
private
List
<
MessageExtraActionItemPresenter
>
extraActionItems
;
public
MessageFormLayout
(
Context
context
)
{
super
(
context
);
...
...
@@ -51,6 +57,7 @@ public class MessageFormLayout 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 MessageFormLayout extends LinearLayout {
btnExtra
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
if
(
actionListener
!=
null
)
{
actionListener
.
onExtra
();
}
public
void
onClick
(
View
view
)
{
showExtraActionSelectionDialog
();
}
});
...
...
@@ -72,7 +77,7 @@ public class MessageFormLayout extends LinearLayout {
public
void
onClick
(
View
view
)
{
String
messageText
=
getText
();
if
(
messageText
.
length
()
>
0
&&
actionListener
!=
null
)
{
actionListener
.
onSubmit
(
messageText
);
actionListener
.
onSubmit
Text
(
messageText
);
}
}
});
...
...
@@ -105,6 +110,20 @@ public class MessageFormLayout 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
);
}
...
...
@@ -140,11 +159,23 @@ public class MessageFormLayout 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 @
0b3f313e
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 @
0b3f313e
<?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 @
0b3f313e
<?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