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
2631f48b
Commit
2631f48b
authored
Sep 18, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete RoomPinnedMessagesAdapter.kt
parent
fd1ff332
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
525 additions
and
576 deletions
+525
-576
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+525
-527
RoomPinnedMessagesAdapter.kt
...d/layouthelper/chatroom/list/RoomPinnedMessagesAdapter.kt
+0
-49
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
2631f48b
...
...
@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.chatroom;
import
android.Manifest
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
...
...
@@ -28,6 +29,7 @@ import java.util.List;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.R
;
import
chat.rocket.android.activity.MainActivity
;
import
chat.rocket.android.activity.room.RoomActivity
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.fragment.chatroom.dialog.FileUploadProgressDialogFragment
;
import
chat.rocket.android.fragment.chatroom.dialog.MessageOptionsDialogFragment
;
...
...
@@ -94,571 +96,567 @@ public class RoomFragment extends AbstractChatRoomFragment implements
ModelListAdapter
.
OnItemLongClickListener
<
PairedMessage
>,
RoomContract
.
View
{
private
static
final
int
DIALOG_ID
=
1
;
private
static
final
String
HOSTNAME
=
"hostname"
;
private
static
final
String
ROOM_ID
=
"roomId"
;
private
String
hostname
;
private
String
token
;
private
String
userId
;
private
String
roomId
;
private
String
roomType
;
private
LoadMoreScrollListener
scrollListener
;
private
MessageFormManager
messageFormManager
;
private
RecyclerView
messageRecyclerView
;
private
RecyclerViewAutoScrollManager
recyclerViewAutoScrollManager
;
protected
AbstractNewMessageIndicatorManager
newMessageIndicatorManager
;
protected
Snackbar
unreadIndicator
;
private
boolean
previousUnreadMessageExists
;
private
MessageListAdapter
messageListAdapter
;
private
AutocompleteManager
autocompleteManager
;
private
List
<
AbstractExtraActionItem
>
extraActionItems
;
private
CompositeDisposable
compositeDisposable
=
new
CompositeDisposable
();
protected
RoomContract
.
Presenter
presenter
;
private
RealmRoomRepository
roomRepository
;
private
RealmUserRepository
userRepository
;
private
MethodCallHelper
methodCallHelper
;
private
AbsoluteUrlHelper
absoluteUrlHelper
;
private
Message
edittingMessage
=
null
;
private
RoomToolbar
toolbar
;
private
SlidingPaneLayout
pane
;
private
SidebarMainFragment
sidebarFragment
;
public
RoomFragment
()
{}
/**
* create fragment with roomId.
*/
public
static
RoomFragment
create
(
String
hostname
,
String
roomId
)
{
Bundle
args
=
new
Bundle
();
args
.
putString
(
HOSTNAME
,
hostname
);
args
.
putString
(
ROOM_ID
,
roomId
);
RoomFragment
fragment
=
new
RoomFragment
();
fragment
.
setArguments
(
args
);
return
fragment
;
}
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setHasOptionsMenu
(
true
);
Bundle
args
=
getArguments
();
hostname
=
args
.
getString
(
HOSTNAME
);
roomId
=
args
.
getString
(
ROOM_ID
);
roomRepository
=
new
RealmRoomRepository
(
hostname
);
MessageInteractor
messageInteractor
=
new
MessageInteractor
(
new
RealmMessageRepository
(
hostname
),
roomRepository
);
userRepository
=
new
RealmUserRepository
(
hostname
);
absoluteUrlHelper
=
new
AbsoluteUrlHelper
(
hostname
,
new
RealmServerInfoRepository
(),
userRepository
,
new
SessionInteractor
(
new
RealmSessionRepository
(
hostname
))
);
methodCallHelper
=
new
MethodCallHelper
(
getContext
(),
hostname
);
presenter
=
new
RoomPresenter
(
roomId
,
userRepository
,
messageInteractor
,
roomRepository
,
absoluteUrlHelper
,
methodCallHelper
,
ConnectivityManager
.
getInstance
(
getContext
())
);
if
(
savedInstanceState
==
null
)
{
presenter
.
loadMessages
();
}
}
@Override
protected
int
getLayout
()
{
return
R
.
layout
.
fragment_room
;
}
@Override
protected
void
onSetupView
()
{
pane
=
getActivity
().
findViewById
(
R
.
id
.
sliding_pane
);
messageRecyclerView
=
rootView
.
findViewById
(
R
.
id
.
messageRecyclerView
);
messageListAdapter
=
new
MessageListAdapter
(
getContext
(),
hostname
);
messageRecyclerView
.
setAdapter
(
messageListAdapter
);
messageListAdapter
.
setOnItemClickListener
(
this
);
messageListAdapter
.
setOnItemLongClickListener
(
this
);
LinearLayoutManager
linearLayoutManager
=
new
LinearLayoutManager
(
getContext
(),
LinearLayoutManager
.
VERTICAL
,
true
);
messageRecyclerView
.
setLayoutManager
(
linearLayoutManager
);
private
static
final
int
DIALOG_ID
=
1
;
private
static
final
String
HOSTNAME
=
"hostname"
;
private
static
final
String
ROOM_ID
=
"roomId"
;
recyclerViewAutoScrollManager
=
new
RecyclerViewAutoScrollManager
(
linearLayoutManager
)
{
@Override
protected
void
onAutoScrollMissed
()
{
if
(
newMessageIndicatorManager
!=
null
)
{
presenter
.
onUnreadCount
();
}
}
};
messageListAdapter
.
registerAdapterDataObserver
(
recyclerViewAutoScrollManager
);
scrollListener
=
new
LoadMoreScrollListener
(
linearLayoutManager
,
40
)
{
@Override
public
void
requestMoreItem
()
{
presenter
.
loadMoreMessages
();
}
};
messageRecyclerView
.
addOnScrollListener
(
scrollListener
);
messageRecyclerView
.
addOnScrollListener
(
new
RecyclerViewScrolledToBottomListener
(
linearLayoutManager
,
1
,
this
::
markAsReadIfNeeded
));
newMessageIndicatorManager
=
new
AbstractNewMessageIndicatorManager
()
{
@Override
protected
void
onShowIndicator
(
int
count
,
boolean
onlyAlreadyShown
)
{
if
((
onlyAlreadyShown
&&
unreadIndicator
!=
null
&&
unreadIndicator
.
isShown
())
||
!
onlyAlreadyShown
)
{
unreadIndicator
=
getUnreadCountIndicatorView
(
count
);
unreadIndicator
.
show
();
private
String
hostname
;
private
String
token
;
private
String
userId
;
private
String
roomId
;
private
String
roomType
;
private
LoadMoreScrollListener
scrollListener
;
private
MessageFormManager
messageFormManager
;
private
RecyclerView
messageRecyclerView
;
private
RecyclerViewAutoScrollManager
recyclerViewAutoScrollManager
;
protected
AbstractNewMessageIndicatorManager
newMessageIndicatorManager
;
protected
Snackbar
unreadIndicator
;
private
boolean
previousUnreadMessageExists
;
private
MessageListAdapter
messageListAdapter
;
private
AutocompleteManager
autocompleteManager
;
private
List
<
AbstractExtraActionItem
>
extraActionItems
;
private
CompositeDisposable
compositeDisposable
=
new
CompositeDisposable
();
protected
RoomContract
.
Presenter
presenter
;
private
RealmRoomRepository
roomRepository
;
private
RealmUserRepository
userRepository
;
private
MethodCallHelper
methodCallHelper
;
private
AbsoluteUrlHelper
absoluteUrlHelper
;
private
Message
edittingMessage
=
null
;
private
RoomToolbar
toolbar
;
private
SlidingPaneLayout
pane
;
private
SidebarMainFragment
sidebarFragment
;
public
RoomFragment
()
{
}
/**
* create fragment with roomId.
*/
public
static
RoomFragment
create
(
String
hostname
,
String
roomId
)
{
Bundle
args
=
new
Bundle
();
args
.
putString
(
HOSTNAME
,
hostname
);
args
.
putString
(
ROOM_ID
,
roomId
);
RoomFragment
fragment
=
new
RoomFragment
();
fragment
.
setArguments
(
args
);
return
fragment
;
}
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setHasOptionsMenu
(
true
);
Bundle
args
=
getArguments
();
hostname
=
args
.
getString
(
HOSTNAME
);
roomId
=
args
.
getString
(
ROOM_ID
);
roomRepository
=
new
RealmRoomRepository
(
hostname
);
MessageInteractor
messageInteractor
=
new
MessageInteractor
(
new
RealmMessageRepository
(
hostname
),
roomRepository
);
userRepository
=
new
RealmUserRepository
(
hostname
);
absoluteUrlHelper
=
new
AbsoluteUrlHelper
(
hostname
,
new
RealmServerInfoRepository
(),
userRepository
,
new
SessionInteractor
(
new
RealmSessionRepository
(
hostname
))
);
methodCallHelper
=
new
MethodCallHelper
(
getContext
(),
hostname
);
presenter
=
new
RoomPresenter
(
roomId
,
userRepository
,
messageInteractor
,
roomRepository
,
absoluteUrlHelper
,
methodCallHelper
,
ConnectivityManager
.
getInstance
(
getContext
())
);
if
(
savedInstanceState
==
null
)
{
presenter
.
loadMessages
();
}
}
}
@Override
protected
int
getLayout
()
{
return
R
.
layout
.
fragment_room
;
}
@Override
protected
void
onSetupView
()
{
pane
=
getActivity
().
findViewById
(
R
.
id
.
sliding_pane
);
messageRecyclerView
=
rootView
.
findViewById
(
R
.
id
.
messageRecyclerView
);
messageListAdapter
=
new
MessageListAdapter
(
getContext
(),
hostname
);
messageRecyclerView
.
setAdapter
(
messageListAdapter
);
messageListAdapter
.
setOnItemClickListener
(
this
);
messageListAdapter
.
setOnItemLongClickListener
(
this
);
LinearLayoutManager
linearLayoutManager
=
new
LinearLayoutManager
(
getContext
(),
LinearLayoutManager
.
VERTICAL
,
true
);
messageRecyclerView
.
setLayoutManager
(
linearLayoutManager
);
recyclerViewAutoScrollManager
=
new
RecyclerViewAutoScrollManager
(
linearLayoutManager
)
{
@Override
protected
void
onAutoScrollMissed
()
{
if
(
newMessageIndicatorManager
!=
null
)
{
presenter
.
onUnreadCount
();
}
}
};
messageListAdapter
.
registerAdapterDataObserver
(
recyclerViewAutoScrollManager
);
scrollListener
=
new
LoadMoreScrollListener
(
linearLayoutManager
,
40
)
{
@Override
public
void
requestMoreItem
()
{
presenter
.
loadMoreMessages
();
}
};
messageRecyclerView
.
addOnScrollListener
(
scrollListener
);
messageRecyclerView
.
addOnScrollListener
(
new
RecyclerViewScrolledToBottomListener
(
linearLayoutManager
,
1
,
this
::
markAsReadIfNeeded
));
newMessageIndicatorManager
=
new
AbstractNewMessageIndicatorManager
()
{
@Override
protected
void
onShowIndicator
(
int
count
,
boolean
onlyAlreadyShown
)
{
if
((
onlyAlreadyShown
&&
unreadIndicator
!=
null
&&
unreadIndicator
.
isShown
())
||
!
onlyAlreadyShown
)
{
unreadIndicator
=
getUnreadCountIndicatorView
(
count
);
unreadIndicator
.
show
();
}
}
@Override
protected
void
onHideIndicator
()
{
if
(
unreadIndicator
!=
null
&&
unreadIndicator
.
isShown
())
{
unreadIndicator
.
dismiss
();
}
}
};
setupToolbar
();
setupSidebar
();
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
()
{
if
(
messageRecyclerView
!=
null
)
messageRecyclerView
.
scrollToPosition
(
0
);
}
@Override
protected
void
onHideIndicator
()
{
if
(
unreadIndicator
!=
null
&&
unreadIndicator
.
isShown
())
{
unreadIndicator
.
dismiss
();
protected
Snackbar
getUnreadCountIndicatorView
(
int
count
)
{
// TODO: replace with another custom View widget, not to hide message composer.
final
String
caption
=
getResources
().
getQuantityString
(
R
.
plurals
.
fmt_dialog_view_latest_message_title
,
count
,
count
);
return
Snackbar
.
make
(
rootView
,
caption
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
R
.
string
.
dialog_view_latest_message_action
,
view
->
scrollToLatestMessage
());
}
@Override
public
void
onDestroyView
()
{
RecyclerView
.
Adapter
adapter
=
messageRecyclerView
.
getAdapter
();
if
(
adapter
!=
null
)
adapter
.
unregisterAdapterDataObserver
(
recyclerViewAutoScrollManager
);
compositeDisposable
.
clear
();
if
(
autocompleteManager
!=
null
)
{
autocompleteManager
.
dispose
();
autocompleteManager
=
null
;
}
}
};
setupToolbar
();
setupSidebar
();
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
()
{
if
(
messageRecyclerView
!=
null
)
messageRecyclerView
.
scrollToPosition
(
0
);
}
protected
Snackbar
getUnreadCountIndicatorView
(
int
count
)
{
// TODO: replace with another custom View widget, not to hide message composer.
final
String
caption
=
getResources
().
getQuantityString
(
R
.
plurals
.
fmt_dialog_view_latest_message_title
,
count
,
count
);
return
Snackbar
.
make
(
rootView
,
caption
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
R
.
string
.
dialog_view_latest_message_action
,
view
->
scrollToLatestMessage
());
}
@Override
public
void
onDestroyView
()
{
RecyclerView
.
Adapter
adapter
=
messageRecyclerView
.
getAdapter
();
if
(
adapter
!=
null
)
adapter
.
unregisterAdapterDataObserver
(
recyclerViewAutoScrollManager
);
compositeDisposable
.
clear
();
if
(
autocompleteManager
!=
null
)
{
autocompleteManager
.
dispose
();
autocompleteManager
=
null
;
}
super
.
onDestroyView
();
}
@Override
public
void
onItemClick
(
PairedMessage
pairedMessage
)
{
presenter
.
onMessageSelected
(
pairedMessage
.
target
);
}
@Override
public
boolean
onItemLongClick
(
PairedMessage
pairedMessage
)
{
MessageOptionsDialogFragment
messageOptionsDialogFragment
=
MessageOptionsDialogFragment
.
create
(
pairedMessage
.
target
);
messageOptionsDialogFragment
.
setOnMessageOptionSelectedListener
(
message
->
{
messageOptionsDialogFragment
.
dismiss
();
onEditMessage
(
message
);
});
messageOptionsDialogFragment
.
show
(
getChildFragmentManager
(),
"MessageOptionsDialogFragment"
);
return
true
;
}
private
void
setupToolbar
()
{
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
activity_main_toolbar
);
toolbar
.
getMenu
().
clear
();
toolbar
.
inflateMenu
(
R
.
menu
.
menu_room
);
toolbar
.
setNavigationOnClickListener
(
view
->
{
if
(
pane
.
isSlideable
()
&&
!
pane
.
isOpen
())
{
pane
.
openPane
();
}
});
toolbar
.
setOnMenuItemClickListener
(
menuItem
->
{
switch
(
menuItem
.
getItemId
())
{
case
R
.
id
.
action_pinned_messages
:
showRoomListFragment
(
R
.
id
.
action_pinned_messages
);
break
;
case
R
.
id
.
action_favorite_messages
:
showRoomListFragment
(
R
.
id
.
action_favorite_messages
);
break
;
case
R
.
id
.
action_file_list
:
showRoomListFragment
(
R
.
id
.
action_file_list
);
break
;
case
R
.
id
.
action_member_list
:
showRoomListFragment
(
R
.
id
.
action_member_list
);
break
;
default
:
return
super
.
onOptionsItemSelected
(
menuItem
);
}
return
true
;
});
}
private
void
setupSidebar
()
{
SlidingPaneLayout
subPane
=
getActivity
().
findViewById
(
R
.
id
.
sub_sliding_pane
);
sidebarFragment
=
(
SidebarMainFragment
)
getActivity
().
getSupportFragmentManager
().
findFragmentById
(
R
.
id
.
sidebar_fragment_container
);
pane
.
setPanelSlideListener
(
new
SlidingPaneLayout
.
PanelSlideListener
()
{
@Override
public
void
onPanelSlide
(
View
view
,
float
v
)
{
messageFormManager
.
enableComposingText
(
false
);
sidebarFragment
.
clearSearchViewFocus
();
//Ref: ActionBarDrawerToggle#setProgress
toolbar
.
setNavigationIconProgress
(
v
);
}
@Override
public
void
onPanelOpened
(
View
view
)
{
toolbar
.
setNavigationIconVerticalMirror
(
true
);
}
@Override
public
void
onPanelClosed
(
View
view
)
{
messageFormManager
.
enableComposingText
(
true
);
toolbar
.
setNavigationIconVerticalMirror
(
false
);
subPane
.
closePane
();
closeUserActionContainer
();
}
});
}
public
void
closeUserActionContainer
()
{
sidebarFragment
.
closeUserActionContainer
();
}
private
void
setupMessageComposer
()
{
final
MessageFormLayout
messageFormLayout
=
rootView
.
findViewById
(
R
.
id
.
messageComposer
);
messageFormManager
=
new
MessageFormManager
(
messageFormLayout
,
this
::
showExtraActionSelectionDialog
);
messageFormManager
.
setSendMessageCallback
(
this
::
sendMessage
);
messageFormLayout
.
setEditTextCommitContentListener
(
this
::
onCommitContent
);
autocompleteManager
=
new
AutocompleteManager
(
rootView
.
findViewById
(
R
.
id
.
messageListRelativeLayout
));
autocompleteManager
.
registerSource
(
new
ChannelSource
(
new
AutocompleteChannelInteractor
(
roomRepository
,
new
RealmSpotlightRoomRepository
(
hostname
),
new
DeafultTempSpotlightRoomCaller
(
methodCallHelper
)
),
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()),
AndroidSchedulers
.
mainThread
()
)
);
Disposable
disposable
=
Single
.
zip
(
absoluteUrlHelper
.
getRocketChatAbsoluteUrl
(),
roomRepository
.
getById
(
roomId
).
first
(
Optional
.
absent
()),
Pair:
:
create
)
.
subscribe
(
pair
->
{
if
(
pair
.
first
.
isPresent
()
&&
pair
.
second
.
isPresent
())
{
autocompleteManager
.
registerSource
(
new
UserSource
(
new
AutocompleteUserInteractor
(
pair
.
second
.
get
(),
userRepository
,
new
RealmMessageRepository
(
hostname
),
new
RealmSpotlightUserRepository
(
hostname
),
new
DefaultTempSpotlightUserCaller
(
methodCallHelper
)
super
.
onDestroyView
();
}
@Override
public
void
onItemClick
(
PairedMessage
pairedMessage
)
{
presenter
.
onMessageSelected
(
pairedMessage
.
target
);
}
@Override
public
boolean
onItemLongClick
(
PairedMessage
pairedMessage
)
{
MessageOptionsDialogFragment
messageOptionsDialogFragment
=
MessageOptionsDialogFragment
.
create
(
pairedMessage
.
target
);
messageOptionsDialogFragment
.
setOnMessageOptionSelectedListener
(
message
->
{
messageOptionsDialogFragment
.
dismiss
();
onEditMessage
(
message
);
});
messageOptionsDialogFragment
.
show
(
getChildFragmentManager
(),
"MessageOptionsDialogFragment"
);
return
true
;
}
private
void
setupToolbar
()
{
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
activity_main_toolbar
);
toolbar
.
getMenu
().
clear
();
toolbar
.
inflateMenu
(
R
.
menu
.
menu_room
);
toolbar
.
setNavigationOnClickListener
(
view
->
{
if
(
pane
.
isSlideable
()
&&
!
pane
.
isOpen
())
{
pane
.
openPane
();
}
});
toolbar
.
setOnMenuItemClickListener
(
menuItem
->
{
switch
(
menuItem
.
getItemId
())
{
case
R
.
id
.
action_pinned_messages
:
showRoomListFragment
(
R
.
id
.
action_pinned_messages
);
break
;
case
R
.
id
.
action_favorite_messages
:
showRoomListFragment
(
R
.
id
.
action_favorite_messages
);
break
;
case
R
.
id
.
action_file_list
:
showRoomListFragment
(
R
.
id
.
action_file_list
);
break
;
case
R
.
id
.
action_member_list
:
showRoomListFragment
(
R
.
id
.
action_member_list
);
break
;
default
:
return
super
.
onOptionsItemSelected
(
menuItem
);
}
return
true
;
});
}
private
void
setupSidebar
()
{
SlidingPaneLayout
subPane
=
getActivity
().
findViewById
(
R
.
id
.
sub_sliding_pane
);
sidebarFragment
=
(
SidebarMainFragment
)
getActivity
().
getSupportFragmentManager
().
findFragmentById
(
R
.
id
.
sidebar_fragment_container
);
pane
.
setPanelSlideListener
(
new
SlidingPaneLayout
.
PanelSlideListener
()
{
@Override
public
void
onPanelSlide
(
View
view
,
float
v
)
{
messageFormManager
.
enableComposingText
(
false
);
sidebarFragment
.
clearSearchViewFocus
();
//Ref: ActionBarDrawerToggle#setProgress
toolbar
.
setNavigationIconProgress
(
v
);
}
@Override
public
void
onPanelOpened
(
View
view
)
{
toolbar
.
setNavigationIconVerticalMirror
(
true
);
}
@Override
public
void
onPanelClosed
(
View
view
)
{
messageFormManager
.
enableComposingText
(
true
);
toolbar
.
setNavigationIconVerticalMirror
(
false
);
subPane
.
closePane
();
closeUserActionContainer
();
}
});
}
public
void
closeUserActionContainer
()
{
sidebarFragment
.
closeUserActionContainer
();
}
private
void
setupMessageComposer
()
{
final
MessageFormLayout
messageFormLayout
=
rootView
.
findViewById
(
R
.
id
.
messageComposer
);
messageFormManager
=
new
MessageFormManager
(
messageFormLayout
,
this
::
showExtraActionSelectionDialog
);
messageFormManager
.
setSendMessageCallback
(
this
::
sendMessage
);
messageFormLayout
.
setEditTextCommitContentListener
(
this
::
onCommitContent
);
autocompleteManager
=
new
AutocompleteManager
(
rootView
.
findViewById
(
R
.
id
.
messageListRelativeLayout
));
autocompleteManager
.
registerSource
(
new
ChannelSource
(
new
AutocompleteChannelInteractor
(
roomRepository
,
new
RealmSpotlightRoomRepository
(
hostname
),
new
DeafultTempSpotlightRoomCaller
(
methodCallHelper
)
),
pair
.
first
.
get
(),
RocketChatUserStatusProvider
.
INSTANCE
,
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()),
AndroidSchedulers
.
mainThread
()
)
)
);
Disposable
disposable
=
Single
.
zip
(
absoluteUrlHelper
.
getRocketChatAbsoluteUrl
(),
roomRepository
.
getById
(
roomId
).
first
(
Optional
.
absent
()),
Pair:
:
create
)
.
subscribe
(
pair
->
{
if
(
pair
.
first
.
isPresent
()
&&
pair
.
second
.
isPresent
())
{
autocompleteManager
.
registerSource
(
new
UserSource
(
new
AutocompleteUserInteractor
(
pair
.
second
.
get
(),
userRepository
,
new
RealmMessageRepository
(
hostname
),
new
RealmSpotlightUserRepository
(
hostname
),
new
DefaultTempSpotlightUserCaller
(
methodCallHelper
)
),
pair
.
first
.
get
(),
RocketChatUserStatusProvider
.
INSTANCE
,
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()),
AndroidSchedulers
.
mainThread
()
)
);
}
},
throwable
->
{
}
);
}
},
throwable
->
{
}
compositeDisposable
.
add
(
disposable
);
autocompleteManager
.
bindTo
(
messageFormLayout
.
getEditText
(),
messageFormLayout
);
}
compositeDisposable
.
add
(
disposable
);
autocompleteManager
.
bindTo
(
messageFormLayout
.
getEditText
(),
messageFormLayout
);
}
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
!=
AbstractUploadActionItem
.
RC_UPL
||
resultCode
!=
Activity
.
RESULT_OK
)
{
return
;
}
if
(
data
==
null
||
data
.
getData
()
==
null
)
{
return
;
}
uploadFile
(
data
.
getData
());
}
private
void
uploadFile
(
Uri
uri
)
{
String
uplId
=
new
FileUploadHelper
(
getContext
(),
RealmStore
.
get
(
hostname
))
.
requestUploading
(
roomId
,
uri
);
if
(!
TextUtils
.
isEmpty
(
uplId
))
{
FileUploadProgressDialogFragment
.
create
(
hostname
,
roomId
,
uplId
)
.
show
(
getFragmentManager
(),
"FileUploadProgressDialogFragment"
);
}
else
{
// show error.
}
}
private
void
markAsReadIfNeeded
()
{
presenter
.
onMarkAsRead
();
}
@Override
public
void
onResume
()
{
super
.
onResume
();
presenter
.
bindView
(
this
);
}
@Override
public
void
onPause
()
{
presenter
.
release
();
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
()
{
if
(
edittingMessage
!=
null
)
{
edittingMessage
=
null
;
messageFormManager
.
clearComposingText
();
}
return
false
;
}
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
RoomFragmentPermissionsDispatcher
.
onRequestPermissionsResult
(
this
,
requestCode
,
grantResults
);
}
@NeedsPermission
(
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
protected
void
onExtraActionSelected
(
MessageExtraActionBehavior
action
)
{
action
.
handleItemSelectedOnFragment
(
RoomFragment
.
this
);
}
private
boolean
onCommitContent
(
InputContentInfoCompat
inputContentInfo
,
int
flags
,
Bundle
opts
,
String
[]
supportedMimeTypes
)
{
boolean
supported
=
false
;
for
(
final
String
mimeType
:
supportedMimeTypes
)
{
if
(
inputContentInfo
.
getDescription
().
hasMimeType
(
mimeType
))
{
supported
=
true
;
break
;
}
}
if
(!
supported
)
{
return
false
;
}
if
(
BuildCompat
.
isAtLeastNMR1
()
&&
(
flags
&
InputConnectionCompat
.
INPUT_CONTENT_GRANT_READ_URI_PERMISSION
)
!=
0
)
{
try
{
inputContentInfo
.
requestPermission
();
}
catch
(
Exception
e
)
{
return
false
;
}
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
!=
AbstractUploadActionItem
.
RC_UPL
||
resultCode
!=
Activity
.
RESULT_OK
)
{
return
;
}
if
(
data
==
null
||
data
.
getData
()
==
null
)
{
return
;
}
uploadFile
(
data
.
getData
());
}
Uri
linkUri
=
inputContentInfo
.
getLinkUri
();
if
(
linkUri
==
null
)
{
return
false
;
private
void
uploadFile
(
Uri
uri
)
{
String
uplId
=
new
FileUploadHelper
(
getContext
(),
RealmStore
.
get
(
hostname
))
.
requestUploading
(
roomId
,
uri
);
if
(!
TextUtils
.
isEmpty
(
uplId
))
{
FileUploadProgressDialogFragment
.
create
(
hostname
,
roomId
,
uplId
)
.
show
(
getFragmentManager
(),
"FileUploadProgressDialogFragment"
);
}
else
{
// show error.
}
}
sendMessage
(
linkUri
.
toString
());
private
void
markAsReadIfNeeded
()
{
presenter
.
onMarkAsRead
();
}
try
{
inputContentInfo
.
releasePermission
();
}
catch
(
Exception
e
)
{
@Override
public
void
onResume
()
{
super
.
onResume
();
presenter
.
bindView
(
this
);
}
return
true
;
}
@Override
public
void
onPause
()
{
presenter
.
release
();
super
.
onPause
();
}
private
void
sendMessage
(
String
messageText
)
{
if
(
edittingMessage
==
null
)
{
presenter
.
sendMessage
(
messageText
);
}
else
{
presenter
.
updateMessage
(
edittingMessage
,
messageText
);
private
void
showExtraActionSelectionDialog
(
)
{
final
DialogFragment
fragment
=
ExtraActionPickerDialogFragment
.
create
(
new
ArrayList
<>(
extraActionItems
)
);
fragment
.
setTargetFragment
(
this
,
DIALOG_ID
);
fragment
.
show
(
getFragmentManager
(),
"ExtraActionPickerDialogFragment"
);
}
}
@Override
public
void
setupWith
(
RocketChatAbsoluteUrl
rocketChatAbsoluteUrl
)
{
token
=
rocketChatAbsoluteUrl
.
getToken
();
userId
=
rocketChatAbsoluteUrl
.
getUserId
();
messageListAdapter
.
setAbsoluteUrl
(
rocketChatAbsoluteUrl
);
}
@Override
public
void
onItemSelected
(
int
itemId
)
{
for
(
AbstractExtraActionItem
extraActionItem
:
extraActionItems
)
{
if
(
extraActionItem
.
getItemId
()
==
itemId
)
{
RoomFragmentPermissionsDispatcher
.
onExtraActionSelectedWithCheck
(
RoomFragment
.
this
,
extraActionItem
);
return
;
}
}
}
@Override
public
void
render
(
Room
room
)
{
roomType
=
room
.
getType
();
setToolbarTitle
(
room
.
getName
());
@Override
public
boolean
onBackPressed
()
{
if
(
edittingMessage
!=
null
)
{
edittingMessage
=
null
;
messageFormManager
.
clearComposingText
();
}
return
false
;
}
boolean
unreadMessageExists
=
room
.
isAlert
();
if
(
newMessageIndicatorManager
!=
null
&&
previousUnreadMessageExists
&&
!
unreadMessageExists
)
{
newMessageIndicatorManager
.
reset
();
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
RoomFragmentPermissionsDispatcher
.
onRequestPermissionsResult
(
this
,
requestCode
,
grantResults
);
}
previousUnreadMessageExists
=
unreadMessageExists
;
if
(
room
.
isChannel
())
{
showToolbarPublicChannelIcon
();
return
;
@NeedsPermission
(
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
protected
void
onExtraActionSelected
(
MessageExtraActionBehavior
action
)
{
action
.
handleItemSelectedOnFragment
(
RoomFragment
.
this
)
;
}
if
(
room
.
isPrivate
())
{
showToolbarPrivateChannelIcon
();
private
boolean
onCommitContent
(
InputContentInfoCompat
inputContentInfo
,
int
flags
,
Bundle
opts
,
String
[]
supportedMimeTypes
)
{
boolean
supported
=
false
;
for
(
final
String
mimeType
:
supportedMimeTypes
)
{
if
(
inputContentInfo
.
getDescription
().
hasMimeType
(
mimeType
))
{
supported
=
true
;
break
;
}
}
if
(!
supported
)
{
return
false
;
}
if
(
BuildCompat
.
isAtLeastNMR1
()
&&
(
flags
&
InputConnectionCompat
.
INPUT_CONTENT_GRANT_READ_URI_PERMISSION
)
!=
0
)
{
try
{
inputContentInfo
.
requestPermission
();
}
catch
(
Exception
e
)
{
return
false
;
}
}
Uri
linkUri
=
inputContentInfo
.
getLinkUri
();
if
(
linkUri
==
null
)
{
return
false
;
}
sendMessage
(
linkUri
.
toString
());
try
{
inputContentInfo
.
releasePermission
();
}
catch
(
Exception
e
)
{
}
return
true
;
}
if
(
room
.
isLivechat
())
{
showToolbarLivechatChannelIcon
();
private
void
sendMessage
(
String
messageText
)
{
if
(
edittingMessage
==
null
)
{
presenter
.
sendMessage
(
messageText
);
}
else
{
presenter
.
updateMessage
(
edittingMessage
,
messageText
);
}
}
}
@Override
public
void
showUserStatus
(
User
user
)
{
showToolbarUserStatuslIcon
(
user
.
getStatus
());
}
@Override
public
void
setupWith
(
RocketChatAbsoluteUrl
rocketChatAbsoluteUrl
)
{
token
=
rocketChatAbsoluteUrl
.
getToken
();
userId
=
rocketChatAbsoluteUrl
.
getUserId
();
messageListAdapter
.
setAbsoluteUrl
(
rocketChatAbsoluteUrl
);
}
@Override
public
void
updateHistoryState
(
boolean
hasNext
,
boolean
isLoaded
)
{
if
(
messageRecyclerView
==
null
||
!(
messageRecyclerView
.
getAdapter
()
instanceof
MessageListAdapter
))
{
return
;
@Override
public
void
render
(
Room
room
)
{
roomType
=
room
.
getType
();
setToolbarTitle
(
room
.
getName
());
boolean
unreadMessageExists
=
room
.
isAlert
();
if
(
newMessageIndicatorManager
!=
null
&&
previousUnreadMessageExists
&&
!
unreadMessageExists
)
{
newMessageIndicatorManager
.
reset
();
}
previousUnreadMessageExists
=
unreadMessageExists
;
if
(
room
.
isChannel
())
{
showToolbarPublicChannelIcon
();
return
;
}
if
(
room
.
isPrivate
())
{
showToolbarPrivateChannelIcon
();
}
if
(
room
.
isLivechat
())
{
showToolbarLivechatChannelIcon
();
}
}
MessageListAdapter
adapter
=
(
MessageListAdapter
)
messageRecyclerView
.
getAdapter
();
if
(
isLoaded
)
{
scrollListener
.
setLoadingDone
(
);
@Override
public
void
showUserStatus
(
User
user
)
{
showToolbarUserStatuslIcon
(
user
.
getStatus
()
);
}
adapter
.
updateFooter
(
hasNext
,
isLoaded
);
}
@Override
public
void
onMessageSendSuccessfully
()
{
scrollToLatestMessage
();
messageFormManager
.
onMessageSend
();
edittingMessage
=
null
;
}
@Override
public
void
updateHistoryState
(
boolean
hasNext
,
boolean
isLoaded
)
{
if
(
messageRecyclerView
==
null
||
!(
messageRecyclerView
.
getAdapter
()
instanceof
MessageListAdapter
))
{
return
;
}
MessageListAdapter
adapter
=
(
MessageListAdapter
)
messageRecyclerView
.
getAdapter
();
if
(
isLoaded
)
{
scrollListener
.
setLoadingDone
();
}
adapter
.
updateFooter
(
hasNext
,
isLoaded
);
}
@Override
public
void
onMessageSendSuccessfully
()
{
scrollToLatestMessage
();
messageFormManager
.
onMessageSend
();
edittingMessage
=
null
;
}
@Override
public
void
showUnreadCount
(
int
count
)
{
newMessageIndicatorManager
.
updateNewMessageCount
(
count
);
}
@Override
public
void
showUnreadCount
(
int
count
)
{
newMessageIndicatorManager
.
updateNewMessageCount
(
count
);
}
@Override
public
void
showMessages
(
List
<
Message
>
messages
)
{
if
(
messageListAdapter
==
null
)
{
return
;
}
messageListAdapter
.
updateData
(
messages
);
}
@Override
public
void
showMessageSendFailure
(
Message
message
)
{
new
AlertDialog
.
Builder
(
getContext
())
.
setPositiveButton
(
R
.
string
.
resend
,
(
dialog
,
which
)
->
presenter
.
resendMessage
(
message
))
.
setNegativeButton
(
android
.
R
.
string
.
cancel
,
null
)
.
setNeutralButton
(
R
.
string
.
discard
,
(
dialog
,
which
)
->
presenter
.
deleteMessage
(
message
))
.
show
();
}
@Override
public
void
showMessages
(
List
<
Message
>
messages
)
{
if
(
messageListAdapter
==
null
)
{
return
;
@Override
public
void
autoloadImages
()
{
messageListAdapter
.
setAutoloadImages
(
true
);
}
messageListAdapter
.
updateData
(
messages
);
}
@Override
public
void
showMessageSendFailure
(
Message
message
)
{
new
AlertDialog
.
Builder
(
getContext
())
.
setPositiveButton
(
R
.
string
.
resend
,
(
dialog
,
which
)
->
presenter
.
resendMessage
(
message
))
.
setNegativeButton
(
android
.
R
.
string
.
cancel
,
null
)
.
setNeutralButton
(
R
.
string
.
discard
,
(
dialog
,
which
)
->
presenter
.
deleteMessage
(
message
))
.
show
();
}
@Override
public
void
manualLoadImages
()
{
messageListAdapter
.
setAutoloadImages
(
false
);
}
private
void
onEditMessage
(
Message
message
)
{
edittingMessage
=
message
;
messageFormManager
.
setEditMessage
(
message
.
getMessage
());
}
@Override
public
void
autoloadImages
()
{
messageListAdapter
.
setAutoloadImages
(
true
);
}
@Override
public
void
manualLoadImages
()
{
messageListAdapter
.
setAutoloadImages
(
false
);
}
private
void
onEditMessage
(
Message
message
)
{
edittingMessage
=
message
;
messageFormManager
.
setEditMessage
(
message
.
getMessage
());
}
private
void
showRoomListFragment
(
int
actionId
)
{
RoomListFragment
roomListFragment
=
RoomListFragment
.
Companion
.
newInstance
(
actionId
,
roomId
,
roomType
,
hostname
,
token
,
userId
);
MainActivity
activity
=
((
MainActivity
)
getActivity
());
FragmentTransaction
ft
=
activity
.
getSupportFragmentManager
().
beginTransaction
();
ft
.
replace
(
activity
.
getLayoutContainerForFragment
(),
roomListFragment
,
"roomListFragment"
);
ft
.
addToBackStack
(
null
);
ft
.
commit
();
}
private
void
showRoomListFragment
(
int
actionId
)
{
Intent
intent
=
new
Intent
(
getActivity
(),
RoomActivity
.
class
).
putExtra
(
"actionId"
,
actionId
)
.
putExtra
(
"roomId"
,
roomId
)
.
putExtra
(
"roomType"
,
roomType
)
.
putExtra
(
"hostname"
,
hostname
)
.
putExtra
(
"token"
,
token
)
.
putExtra
(
"userId"
,
userId
);
startActivity
(
intent
);
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/layouthelper/chatroom/list/RoomPinnedMessagesAdapter.kt
deleted
100644 → 0
View file @
fd1ff332
package
chat.rocket.android.layouthelper.chatroom.list
import
android.support.v7.widget.RecyclerView
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.helper.DateTime
import
chat.rocket.android.widget.RocketChatAvatar
import
chat.rocket.android.widget.helper.UserAvatarHelper
import
chat.rocket.android.widget.message.RocketChatMessageLayout
import
chat.rocket.core.models.Message
import
kotlinx.android.synthetic.main.list_item_message_newday.view.*
import
kotlinx.android.synthetic.main.list_item_normal_message.view.*
class
RoomPinnedMessagesAdapter
(
private
val
dataSet
:
List
<
Message
>,
private
val
hostname
:
String
)
:
RecyclerView
.
Adapter
<
RoomPinnedMessagesAdapter
.
ViewHolder
>()
{
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
R
.
layout
.
list_item_normal_message
,
parent
,
false
)
return
ViewHolder
(
view
)
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
message
=
dataSet
[
position
]
val
username
=
message
.
user
?.
username
if
(
username
!=
null
)
{
val
placeholderDrawable
=
UserAvatarHelper
.
getTextDrawable
(
username
,
holder
.
userAvatar
.
context
)
holder
.
userAvatar
.
loadImage
(
UserAvatarHelper
.
getUri
(
hostname
,
username
),
placeholderDrawable
)
holder
.
usernameText
.
text
=
username
}
else
{
holder
.
userAvatar
.
visibility
=
View
.
GONE
holder
.
usernameText
.
visibility
=
View
.
GONE
}
holder
.
newDayText
.
text
=
DateTime
.
fromEpocMs
(
message
.
timestamp
,
DateTime
.
Format
.
DATE
)
holder
.
messageBody
.
setText
(
message
.
message
)
}
override
fun
getItemCount
():
Int
=
dataSet
.
size
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
val
userAvatar
:
RocketChatAvatar
=
itemView
.
user_avatar
val
usernameText
:
TextView
=
itemView
.
username
val
messageBody
:
RocketChatMessageLayout
=
itemView
.
message_body
val
newDayText
:
TextView
=
itemView
.
newday_text
}
}
\ 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