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
e89b3bb2
Commit
e89b3bb2
authored
Jan 19, 2017
by
Tiago Cunha
Committed by
GitHub
Jan 19, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into fix/clean-up-notification-messages
parents
ec6b3ca6
5f6e47ca
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
178 deletions
+124
-178
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+40
-8
MessageFormManager.java
...ket/android/layouthelper/chatroom/MessageFormManager.java
+6
-37
ExtraActionPickerDialog.java
...cket/android/widget/internal/ExtraActionPickerDialog.java
+0
-92
ExtraActionPickerDialogFragment.java
...roid/widget/internal/ExtraActionPickerDialogFragment.java
+58
-0
MessageFormLayout.java
...chat/rocket/android/widget/message/MessageFormLayout.java
+20
-41
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
e89b3bb2
...
...
@@ -7,6 +7,7 @@ import android.os.Bundle;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.app.DialogFragment
;
import
android.support.v4.view.GravityCompat
;
import
android.support.v4.widget.DrawerLayout
;
import
android.support.v4.widget.SlidingPaneLayout
;
...
...
@@ -19,6 +20,8 @@ import io.realm.Sort;
import
org.json.JSONObject
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
chat.rocket.android.R
;
import
chat.rocket.android.api.MethodCallHelper
;
...
...
@@ -35,6 +38,7 @@ import chat.rocket.android.layouthelper.chatroom.MessageFormManager;
import
chat.rocket.android.layouthelper.chatroom.MessageListAdapter
;
import
chat.rocket.android.layouthelper.chatroom.AbstractNewMessageIndicatorManager
;
import
chat.rocket.android.layouthelper.chatroom.PairedMessage
;
import
chat.rocket.android.layouthelper.extra_action.AbstractExtraActionItem
;
import
chat.rocket.android.layouthelper.extra_action.MessageExtraActionBehavior
;
import
chat.rocket.android.layouthelper.extra_action.upload.AbstractUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionItem
;
...
...
@@ -53,6 +57,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.internal.ExtraActionPickerDialogFragment
;
import
chat.rocket.android.widget.message.MessageFormLayout
;
import
permissions.dispatcher.NeedsPermission
;
import
permissions.dispatcher.RuntimePermissions
;
...
...
@@ -62,7 +67,10 @@ import permissions.dispatcher.RuntimePermissions;
*/
@RuntimePermissions
public
class
RoomFragment
extends
AbstractChatRoomFragment
implements
OnBackPressListener
,
RealmModelListAdapter
.
OnItemClickListener
<
PairedMessage
>
{
implements
OnBackPressListener
,
ExtraActionPickerDialogFragment
.
Callback
,
RealmModelListAdapter
.
OnItemClickListener
<
PairedMessage
>
{
private
static
final
int
DIALOG_ID
=
1
;
private
String
serverConfigId
;
private
RealmHelper
realmHelper
;
...
...
@@ -79,6 +87,8 @@ public class RoomFragment extends AbstractChatRoomFragment
private
Snackbar
unreadIndicator
;
private
boolean
previousUnreadMessageExists
;
private
List
<
AbstractExtraActionItem
>
extraActionItems
;
public
RoomFragment
()
{
}
...
...
@@ -193,6 +203,14 @@ public class RoomFragment extends AbstractChatRoomFragment
setupSideMenu
();
setupMessageComposer
();
setupMessageActions
();
}
private
void
setupMessageActions
()
{
extraActionItems
=
new
ArrayList
<>(
3
);
// fixed number as of now
extraActionItems
.
add
(
new
ImageUploadActionItem
());
extraActionItems
.
add
(
new
AudioUploadActionItem
());
extraActionItems
.
add
(
new
VideoUploadActionItem
());
}
private
void
scrollToLatestMessage
()
{
...
...
@@ -297,7 +315,8 @@ public class RoomFragment extends AbstractChatRoomFragment
private
void
setupMessageComposer
()
{
final
MessageFormLayout
messageFormLayout
=
(
MessageFormLayout
)
rootView
.
findViewById
(
R
.
id
.
message_composer
);
messageFormManager
=
new
MessageFormManager
(
messageFormLayout
);
messageFormManager
=
new
MessageFormManager
(
messageFormLayout
,
this
::
showExtraActionSelectionDialog
);
messageFormManager
.
setSendMessageCallback
(
messageText
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
...
...
@@ -312,11 +331,6 @@ public class RoomFragment extends AbstractChatRoomFragment
scrollToLatestMessage
();
return
null
;
}));
messageFormManager
.
registerExtraActionItem
(
new
ImageUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
AudioUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
VideoUploadActionItem
());
messageFormManager
.
setExtraActionPickerCallback
(
item
->
RoomFragmentPermissionsDispatcher
.
onExtraActionSelectedWithCheck
(
RoomFragment
.
this
,
item
));
}
@Override
...
...
@@ -336,7 +350,7 @@ public class RoomFragment extends AbstractChatRoomFragment
FileUploadProgressDialogFragment
.
create
(
serverConfigId
,
roomId
,
uplId
)
.
show
(
getFragmentManager
(),
FileUploadProgressDialogFragment
.
class
.
getSimpleName
());
}
else
{
//show error.
//
show error.
}
}
...
...
@@ -442,6 +456,24 @@ public class RoomFragment extends AbstractChatRoomFragment
super
.
onPause
();
}
private
void
showExtraActionSelectionDialog
()
{
final
DialogFragment
fragment
=
ExtraActionPickerDialogFragment
.
create
(
new
ArrayList
<>(
extraActionItems
));
fragment
.
setTargetFragment
(
this
,
DIALOG_ID
);
fragment
.
show
(
getFragmentManager
(),
"ExtraActionPickerDialogFragment"
);
}
@Override
public
void
onItemSelected
(
int
itemId
)
{
for
(
AbstractExtraActionItem
extraActionItem
:
extraActionItems
)
{
if
(
extraActionItem
.
getItemId
()
==
itemId
)
{
RoomFragmentPermissionsDispatcher
.
onExtraActionSelectedWithCheck
(
RoomFragment
.
this
,
extraActionItem
);
return
;
}
}
}
@Override
public
boolean
onBackPressed
()
{
return
closeSideMenuIfNeeded
();
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageFormManager.java
View file @
e89b3bb2
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
;
/**
...
...
@@ -11,42 +9,22 @@ import chat.rocket.android.widget.message.MessageFormLayout;
public
class
MessageFormManager
{
private
final
MessageFormLayout
messageFormLayout
;
private
SendMessageCallback
sendMessageCallback
;
private
ExtraActionPickerCallback
extraActionPickerCallback
;
private
final
HashMap
<
Integer
,
AbstractExtraActionItem
>
extraActionItemMap
;
public
MessageFormManager
(
MessageFormLayout
messageFormLayout
)
{
public
MessageFormManager
(
MessageFormLayout
messageFormLayout
,
MessageFormLayout
.
ExtraActionSelectionClickListener
callback
)
{
this
.
messageFormLayout
=
messageFormLayout
;
this
.
extraActionItemMap
=
new
HashMap
<>();
init
();
init
(
callback
);
}
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
);
}
}
}
});
private
void
init
(
MessageFormLayout
.
ExtraActionSelectionClickListener
listener
)
{
messageFormLayout
.
setExtraActionSelectionClickListener
(
listener
);
messageFormLayout
.
setSubmitTextListener
(
this
::
sendMessage
);
}
public
void
setSendMessageCallback
(
SendMessageCallback
sendMessageCallback
)
{
this
.
sendMessageCallback
=
sendMessageCallback
;
}
public
void
setExtraActionPickerCallback
(
ExtraActionPickerCallback
extraActionPickerCallback
)
{
this
.
extraActionPickerCallback
=
extraActionPickerCallback
;
}
public
void
clearComposingText
()
{
messageFormLayout
.
setText
(
""
);
}
...
...
@@ -66,16 +44,7 @@ public class MessageFormManager {
});
}
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
);
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/internal/ExtraActionPickerDialog.java
deleted
100644 → 0
View file @
ec6b3ca6
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
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/internal/ExtraActionPickerDialogFragment.java
0 → 100644
View file @
e89b3bb2
package
chat
.
rocket
.
android
.
widget
.
internal
;
import
android.app.Dialog
;
import
android.support.design.widget.BottomSheetDialogFragment
;
import
android.support.v4.app.Fragment
;
import
android.support.v7.widget.RecyclerView
;
import
java.util.List
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.layouthelper.MessageExtraActionListAdapter
;
import
chat.rocket.android.widget.message.MessageExtraActionItemPresenter
;
public
class
ExtraActionPickerDialogFragment
extends
BottomSheetDialogFragment
{
private
List
<
MessageExtraActionItemPresenter
>
actionItems
;
public
static
ExtraActionPickerDialogFragment
create
(
List
<
MessageExtraActionItemPresenter
>
actionItems
)
{
ExtraActionPickerDialogFragment
fragment
=
new
ExtraActionPickerDialogFragment
();
fragment
.
setActionItems
(
actionItems
);
return
fragment
;
}
public
void
setActionItems
(
List
<
MessageExtraActionItemPresenter
>
actionItems
)
{
this
.
actionItems
=
actionItems
;
}
@Override
public
final
void
setupDialog
(
Dialog
dialog
,
int
style
)
{
super
.
setupDialog
(
dialog
,
style
);
dialog
.
setContentView
(
R
.
layout
.
dialog_message_extra_action_picker
);
MessageExtraActionListAdapter
adapter
=
new
MessageExtraActionListAdapter
(
actionItems
);
adapter
.
setOnItemClickListener
(
new
MessageExtraActionListAdapter
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
int
itemId
)
{
callbackOnItemSelected
(
itemId
);
dismiss
();
}
});
RecyclerView
recyclerView
=
(
RecyclerView
)
dialog
.
findViewById
(
R
.
id
.
message_extra_action_listview
);
recyclerView
.
setAdapter
(
adapter
);
}
private
void
callbackOnItemSelected
(
int
itemId
)
{
final
Fragment
fragment
=
getTargetFragment
();
if
(
fragment
instanceof
Callback
)
{
((
Callback
)
fragment
).
onItemSelected
(
itemId
);
}
}
public
interface
Callback
{
void
onItemSelected
(
int
itemId
);
}
}
\ No newline at end of file
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/MessageFormLayout.java
View file @
e89b3bb2
...
...
@@ -3,7 +3,6 @@ package chat.rocket.android.widget.message;
import
android.annotation.TargetApi
;
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
;
...
...
@@ -15,21 +14,17 @@ 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
{
protected
ActionListener
actionListener
;
protected
ViewGroup
composer
;
private
View
btnExtra
;
private
View
btnSubmit
;
private
List
<
MessageExtraActionItemPresenter
>
extraActionItems
;
private
ExtraActionSelectionClickListener
extraActionSelectionClickListener
;
private
SubmitTextListener
submitTextListener
;
public
MessageFormLayout
(
Context
context
)
{
super
(
context
);
...
...
@@ -52,12 +47,7 @@ public class MessageFormLayout extends LinearLayout {
init
();
}
public
final
void
setOnActionListener
(
@Nullable
ActionListener
listener
)
{
actionListener
=
listener
;
}
private
void
init
()
{
extraActionItems
=
new
ArrayList
<>();
composer
=
(
ViewGroup
)
LayoutInflater
.
from
(
getContext
())
.
inflate
(
R
.
layout
.
message_composer
,
this
,
false
);
...
...
@@ -66,7 +56,7 @@ public class MessageFormLayout extends LinearLayout {
btnExtra
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
showExtraActionSelectionDialog
();
onExtraActionSelectionClick
();
}
});
...
...
@@ -76,8 +66,8 @@ public class MessageFormLayout extends LinearLayout {
@Override
public
void
onClick
(
View
view
)
{
String
messageText
=
getText
();
if
(
messageText
.
length
()
>
0
&&
action
Listener
!=
null
)
{
action
Listener
.
onSubmitText
(
messageText
);
if
(
messageText
.
length
()
>
0
&&
submitText
Listener
!=
null
)
{
submitText
Listener
.
onSubmitText
(
messageText
);
}
}
});
...
...
@@ -110,17 +100,18 @@ 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
;
}
}
public
void
setExtraActionSelectionClickListener
(
ExtraActionSelectionClickListener
extraActionSelectionClickListener
)
{
this
.
extraActionSelectionClickListener
=
extraActionSelectionClickListener
;
}
public
void
setSubmitTextListener
(
SubmitTextListener
submitTextListener
)
{
this
.
submitTextListener
=
submitTextListener
;
}
if
(!
found
)
{
extraActionItems
.
add
(
itemPresenter
);
private
void
onExtraActionSelectionClick
()
{
if
(
extraActionSelectionClickListener
!=
null
)
{
extraActionSelectionClickListener
.
onClick
();
}
}
...
...
@@ -159,23 +150,11 @@ public class MessageFormLayout extends LinearLayout {
});
}
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
;
}
});
public
interface
ExtraActionSelectionClickListener
{
void
onClick
();
}
public
interface
Action
Listener
{
public
interface
SubmitText
Listener
{
void
onSubmitText
(
String
message
);
void
onExtraActionSelected
(
int
itemId
);
}
}
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