Commit 2631f48b authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Delete RoomPinnedMessagesAdapter.kt

parent fd1ff332
...@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.chatroom; ...@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.chatroom;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
...@@ -28,6 +29,7 @@ import java.util.List; ...@@ -28,6 +29,7 @@ import java.util.List;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.activity.MainActivity; import chat.rocket.android.activity.MainActivity;
import chat.rocket.android.activity.room.RoomActivity;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.fragment.chatroom.dialog.FileUploadProgressDialogFragment; import chat.rocket.android.fragment.chatroom.dialog.FileUploadProgressDialogFragment;
import chat.rocket.android.fragment.chatroom.dialog.MessageOptionsDialogFragment; import chat.rocket.android.fragment.chatroom.dialog.MessageOptionsDialogFragment;
...@@ -94,571 +96,567 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -94,571 +96,567 @@ public class RoomFragment extends AbstractChatRoomFragment implements
ModelListAdapter.OnItemLongClickListener<PairedMessage>, ModelListAdapter.OnItemLongClickListener<PairedMessage>,
RoomContract.View { RoomContract.View {
private static final int DIALOG_ID = 1; private static final int DIALOG_ID = 1;
private static final String HOSTNAME = "hostname"; private static final String HOSTNAME = "hostname";
private static final String ROOM_ID = "roomId"; 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);
recyclerViewAutoScrollManager = new RecyclerViewAutoScrollManager(linearLayoutManager) { private String hostname;
@Override private String token;
protected void onAutoScrollMissed() { private String userId;
if (newMessageIndicatorManager != null) { private String roomId;
presenter.onUnreadCount(); private String roomType;
} private LoadMoreScrollListener scrollListener;
} private MessageFormManager messageFormManager;
}; private RecyclerView messageRecyclerView;
messageListAdapter.registerAdapterDataObserver(recyclerViewAutoScrollManager); private RecyclerViewAutoScrollManager recyclerViewAutoScrollManager;
protected AbstractNewMessageIndicatorManager newMessageIndicatorManager;
scrollListener = new LoadMoreScrollListener(linearLayoutManager, 40) { protected Snackbar unreadIndicator;
@Override private boolean previousUnreadMessageExists;
public void requestMoreItem() { private MessageListAdapter messageListAdapter;
presenter.loadMoreMessages(); private AutocompleteManager autocompleteManager;
}
}; private List<AbstractExtraActionItem> extraActionItems;
messageRecyclerView.addOnScrollListener(scrollListener);
messageRecyclerView.addOnScrollListener(new RecyclerViewScrolledToBottomListener(linearLayoutManager, 1, this::markAsReadIfNeeded)); private CompositeDisposable compositeDisposable = new CompositeDisposable();
newMessageIndicatorManager = new AbstractNewMessageIndicatorManager() { protected RoomContract.Presenter presenter;
@Override
protected void onShowIndicator(int count, boolean onlyAlreadyShown) { private RealmRoomRepository roomRepository;
if ((onlyAlreadyShown && unreadIndicator != null && unreadIndicator.isShown()) || !onlyAlreadyShown) { private RealmUserRepository userRepository;
unreadIndicator = getUnreadCountIndicatorView(count); private MethodCallHelper methodCallHelper;
unreadIndicator.show(); 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 Snackbar getUnreadCountIndicatorView(int count) {
protected void onHideIndicator() { // TODO: replace with another custom View widget, not to hide message composer.
if (unreadIndicator != null && unreadIndicator.isShown()) { final String caption = getResources().getQuantityString(
unreadIndicator.dismiss(); 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();
}
setupToolbar();
setupSidebar(); @Override
setupMessageComposer(); public void onItemClick(PairedMessage pairedMessage) {
setupMessageActions(); presenter.onMessageSelected(pairedMessage.target);
} }
private void setupMessageActions() { @Override
extraActionItems = new ArrayList<>(3); // fixed number as of now public boolean onItemLongClick(PairedMessage pairedMessage) {
extraActionItems.add(new ImageUploadActionItem()); MessageOptionsDialogFragment messageOptionsDialogFragment = MessageOptionsDialogFragment
extraActionItems.add(new AudioUploadActionItem()); .create(pairedMessage.target);
extraActionItems.add(new VideoUploadActionItem());
} messageOptionsDialogFragment.setOnMessageOptionSelectedListener(message -> {
messageOptionsDialogFragment.dismiss();
private void scrollToLatestMessage() { onEditMessage(message);
if (messageRecyclerView != null) });
messageRecyclerView.scrollToPosition(0);
} messageOptionsDialogFragment.show(getChildFragmentManager(), "MessageOptionsDialogFragment");
return true;
protected Snackbar getUnreadCountIndicatorView(int count) { }
// TODO: replace with another custom View widget, not to hide message composer.
final String caption = getResources().getQuantityString( private void setupToolbar() {
R.plurals.fmt_dialog_view_latest_message_title, count, count); toolbar = getActivity().findViewById(R.id.activity_main_toolbar);
toolbar.getMenu().clear();
return Snackbar.make(rootView, caption, Snackbar.LENGTH_LONG) toolbar.inflateMenu(R.menu.menu_room);
.setAction(R.string.dialog_view_latest_message_action, view -> scrollToLatestMessage());
} toolbar.setNavigationOnClickListener(view -> {
if (pane.isSlideable() && !pane.isOpen()) {
@Override pane.openPane();
public void onDestroyView() { }
RecyclerView.Adapter adapter = messageRecyclerView.getAdapter(); });
if (adapter != null)
adapter.unregisterAdapterDataObserver(recyclerViewAutoScrollManager); toolbar.setOnMenuItemClickListener(menuItem -> {
switch (menuItem.getItemId()) {
compositeDisposable.clear(); case R.id.action_pinned_messages:
showRoomListFragment(R.id.action_pinned_messages);
if (autocompleteManager != null) { break;
autocompleteManager.dispose(); case R.id.action_favorite_messages:
autocompleteManager = null; showRoomListFragment(R.id.action_favorite_messages);
} break;
case R.id.action_file_list:
super.onDestroyView(); showRoomListFragment(R.id.action_file_list);
} break;
case R.id.action_member_list:
@Override showRoomListFragment(R.id.action_member_list);
public void onItemClick(PairedMessage pairedMessage) { break;
presenter.onMessageSelected(pairedMessage.target); default:
} return super.onOptionsItemSelected(menuItem);
}
@Override return true;
public boolean onItemLongClick(PairedMessage pairedMessage) { });
MessageOptionsDialogFragment messageOptionsDialogFragment = MessageOptionsDialogFragment }
.create(pairedMessage.target);
private void setupSidebar() {
messageOptionsDialogFragment.setOnMessageOptionSelectedListener(message -> { SlidingPaneLayout subPane = getActivity().findViewById(R.id.sub_sliding_pane);
messageOptionsDialogFragment.dismiss(); sidebarFragment = (SidebarMainFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.sidebar_fragment_container);
onEditMessage(message);
}); pane.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {
@Override
messageOptionsDialogFragment.show(getChildFragmentManager(), "MessageOptionsDialogFragment"); public void onPanelSlide(View view, float v) {
return true; messageFormManager.enableComposingText(false);
} sidebarFragment.clearSearchViewFocus();
//Ref: ActionBarDrawerToggle#setProgress
private void setupToolbar() { toolbar.setNavigationIconProgress(v);
toolbar = getActivity().findViewById(R.id.activity_main_toolbar); }
toolbar.getMenu().clear();
toolbar.inflateMenu(R.menu.menu_room); @Override
public void onPanelOpened(View view) {
toolbar.setNavigationOnClickListener(view -> { toolbar.setNavigationIconVerticalMirror(true);
if (pane.isSlideable() && !pane.isOpen()) { }
pane.openPane();
} @Override
}); public void onPanelClosed(View view) {
messageFormManager.enableComposingText(true);
toolbar.setOnMenuItemClickListener(menuItem -> { toolbar.setNavigationIconVerticalMirror(false);
switch (menuItem.getItemId()) { subPane.closePane();
case R.id.action_pinned_messages: closeUserActionContainer();
showRoomListFragment(R.id.action_pinned_messages); }
break; });
case R.id.action_favorite_messages: }
showRoomListFragment(R.id.action_favorite_messages);
break; public void closeUserActionContainer() {
case R.id.action_file_list: sidebarFragment.closeUserActionContainer();
showRoomListFragment(R.id.action_file_list); }
break;
case R.id.action_member_list: private void setupMessageComposer() {
showRoomListFragment(R.id.action_member_list); final MessageFormLayout messageFormLayout = rootView.findViewById(R.id.messageComposer);
break; messageFormManager = new MessageFormManager(messageFormLayout, this::showExtraActionSelectionDialog);
default: messageFormManager.setSendMessageCallback(this::sendMessage);
return super.onOptionsItemSelected(menuItem); messageFormLayout.setEditTextCommitContentListener(this::onCommitContent);
}
return true; autocompleteManager = new AutocompleteManager(rootView.findViewById(R.id.messageListRelativeLayout));
});
} autocompleteManager.registerSource(
new ChannelSource(
private void setupSidebar() { new AutocompleteChannelInteractor(
SlidingPaneLayout subPane = getActivity().findViewById(R.id.sub_sliding_pane); roomRepository,
sidebarFragment = (SidebarMainFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.sidebar_fragment_container); new RealmSpotlightRoomRepository(hostname),
new DeafultTempSpotlightRoomCaller(methodCallHelper)
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)
), ),
pair.first.get(),
RocketChatUserStatusProvider.INSTANCE,
AndroidSchedulers.from(BackgroundLooper.get()), AndroidSchedulers.from(BackgroundLooper.get()),
AndroidSchedulers.mainThread() 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 -> {
}
); );
}
}, compositeDisposable.add(disposable);
throwable -> {
} autocompleteManager.bindTo(
messageFormLayout.getEditText(),
messageFormLayout
); );
}
compositeDisposable.add(disposable); @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
autocompleteManager.bindTo( super.onActivityResult(requestCode, resultCode, data);
messageFormLayout.getEditText(), if (requestCode != AbstractUploadActionItem.RC_UPL || resultCode != Activity.RESULT_OK) {
messageFormLayout return;
); }
}
if (data == null || data.getData() == null) {
@Override return;
public void onActivityResult(int requestCode, int resultCode, Intent data) { }
super.onActivityResult(requestCode, resultCode, data);
if (requestCode != AbstractUploadActionItem.RC_UPL || resultCode != Activity.RESULT_OK) { uploadFile(data.getData());
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;
}
} }
Uri linkUri = inputContentInfo.getLinkUri(); private void uploadFile(Uri uri) {
if (linkUri == null) { String uplId = new FileUploadHelper(getContext(), RealmStore.get(hostname))
return false; .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 { @Override
inputContentInfo.releasePermission(); public void onResume() {
} catch (Exception e) { super.onResume();
presenter.bindView(this);
} }
return true; @Override
} public void onPause() {
presenter.release();
super.onPause();
}
private void sendMessage(String messageText) { private void showExtraActionSelectionDialog() {
if (edittingMessage == null) { final DialogFragment fragment = ExtraActionPickerDialogFragment
presenter.sendMessage(messageText); .create(new ArrayList<>(extraActionItems));
} else { fragment.setTargetFragment(this, DIALOG_ID);
presenter.updateMessage(edittingMessage, messageText); fragment.show(getFragmentManager(), "ExtraActionPickerDialogFragment");
} }
}
@Override @Override
public void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl) { public void onItemSelected(int itemId) {
token = rocketChatAbsoluteUrl.getToken(); for (AbstractExtraActionItem extraActionItem : extraActionItems) {
userId = rocketChatAbsoluteUrl.getUserId(); if (extraActionItem.getItemId() == itemId) {
messageListAdapter.setAbsoluteUrl(rocketChatAbsoluteUrl); RoomFragmentPermissionsDispatcher.onExtraActionSelectedWithCheck(RoomFragment.this, extraActionItem);
} return;
}
}
}
@Override @Override
public void render(Room room) { public boolean onBackPressed() {
roomType = room.getType(); if (edittingMessage != null) {
setToolbarTitle(room.getName()); edittingMessage = null;
messageFormManager.clearComposingText();
}
return false;
}
boolean unreadMessageExists = room.isAlert(); @Override
if (newMessageIndicatorManager != null && previousUnreadMessageExists && !unreadMessageExists) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
newMessageIndicatorManager.reset(); @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
RoomFragmentPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
} }
previousUnreadMessageExists = unreadMessageExists;
if (room.isChannel()) { @NeedsPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
showToolbarPublicChannelIcon(); protected void onExtraActionSelected(MessageExtraActionBehavior action) {
return; action.handleItemSelectedOnFragment(RoomFragment.this);
} }
if (room.isPrivate()) { private boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags,
showToolbarPrivateChannelIcon(); 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()) { private void sendMessage(String messageText) {
showToolbarLivechatChannelIcon(); if (edittingMessage == null) {
presenter.sendMessage(messageText);
} else {
presenter.updateMessage(edittingMessage, messageText);
}
} }
}
@Override @Override
public void showUserStatus(User user) { public void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl) {
showToolbarUserStatuslIcon(user.getStatus()); token = rocketChatAbsoluteUrl.getToken();
} userId = rocketChatAbsoluteUrl.getUserId();
messageListAdapter.setAbsoluteUrl(rocketChatAbsoluteUrl);
}
@Override @Override
public void updateHistoryState(boolean hasNext, boolean isLoaded) { public void render(Room room) {
if (messageRecyclerView == null || !(messageRecyclerView.getAdapter() instanceof MessageListAdapter)) { roomType = room.getType();
return; 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(); @Override
if (isLoaded) { public void showUserStatus(User user) {
scrollListener.setLoadingDone(); showToolbarUserStatuslIcon(user.getStatus());
} }
adapter.updateFooter(hasNext, isLoaded);
}
@Override @Override
public void onMessageSendSuccessfully() { public void updateHistoryState(boolean hasNext, boolean isLoaded) {
scrollToLatestMessage(); if (messageRecyclerView == null || !(messageRecyclerView.getAdapter() instanceof MessageListAdapter)) {
messageFormManager.onMessageSend(); return;
edittingMessage = null; }
}
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 @Override
public void showUnreadCount(int count) { public void showMessages(List<Message> messages) {
newMessageIndicatorManager.updateNewMessageCount(count); 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 @Override
public void showMessages(List<Message> messages) { public void autoloadImages() {
if (messageListAdapter == null) { messageListAdapter.setAutoloadImages(true);
return;
} }
messageListAdapter.updateData(messages);
}
@Override @Override
public void showMessageSendFailure(Message message) { public void manualLoadImages() {
new AlertDialog.Builder(getContext()) messageListAdapter.setAutoloadImages(false);
.setPositiveButton(R.string.resend, }
(dialog, which) -> presenter.resendMessage(message))
.setNegativeButton(android.R.string.cancel, null) private void onEditMessage(Message message) {
.setNeutralButton(R.string.discard, edittingMessage = message;
(dialog, which) -> presenter.deleteMessage(message)) messageFormManager.setEditMessage(message.getMessage());
.show(); }
}
@Override private void showRoomListFragment(int actionId) {
public void autoloadImages() { Intent intent = new Intent(getActivity(), RoomActivity.class).putExtra("actionId", actionId)
messageListAdapter.setAutoloadImages(true); .putExtra("roomId", roomId)
} .putExtra("roomType", roomType)
.putExtra("hostname", hostname)
@Override .putExtra("token", token)
public void manualLoadImages() { .putExtra("userId", userId);
messageListAdapter.setAutoloadImages(false); startActivity(intent);
} }
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();
}
} }
\ No newline at end of file
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment