Commit b3382b08 authored by Tiago Cunha's avatar Tiago Cunha

PR based improvements

parent 0a926198
...@@ -7,6 +7,7 @@ import android.os.Bundle; ...@@ -7,6 +7,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
...@@ -66,7 +67,10 @@ import permissions.dispatcher.RuntimePermissions; ...@@ -66,7 +67,10 @@ import permissions.dispatcher.RuntimePermissions;
*/ */
@RuntimePermissions @RuntimePermissions
public class RoomFragment extends AbstractChatRoomFragment 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 String serverConfigId;
private RealmHelper realmHelper; private RealmHelper realmHelper;
...@@ -199,6 +203,14 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -199,6 +203,14 @@ public class RoomFragment extends AbstractChatRoomFragment
setupSideMenu(); setupSideMenu();
setupMessageComposer(); 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() { private void scrollToLatestMessage() {
...@@ -301,11 +313,6 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -301,11 +313,6 @@ public class RoomFragment extends AbstractChatRoomFragment
} }
private void setupMessageComposer() { private void setupMessageComposer() {
extraActionItems = new ArrayList<>(3); // fixed number as of now
extraActionItems.add(new ImageUploadActionItem());
extraActionItems.add(new AudioUploadActionItem());
extraActionItems.add(new VideoUploadActionItem());
final MessageFormLayout messageFormLayout = final MessageFormLayout messageFormLayout =
(MessageFormLayout) rootView.findViewById(R.id.message_composer); (MessageFormLayout) rootView.findViewById(R.id.message_composer);
messageFormManager = messageFormManager =
...@@ -343,7 +350,7 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -343,7 +350,7 @@ public class RoomFragment extends AbstractChatRoomFragment
FileUploadProgressDialogFragment.create(serverConfigId, roomId, uplId) FileUploadProgressDialogFragment.create(serverConfigId, roomId, uplId)
.show(getFragmentManager(), FileUploadProgressDialogFragment.class.getSimpleName()); .show(getFragmentManager(), FileUploadProgressDialogFragment.class.getSimpleName());
} else { } else {
//show error. //onClick error.
} }
} }
...@@ -450,12 +457,14 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -450,12 +457,14 @@ public class RoomFragment extends AbstractChatRoomFragment
} }
private void showExtraActionSelectionDialog() { private void showExtraActionSelectionDialog() {
ExtraActionPickerDialogFragment final DialogFragment fragment = ExtraActionPickerDialogFragment
.create(new ArrayList<>(extraActionItems), this::onExtraItemSelected) .create(new ArrayList<>(extraActionItems));
.show(getFragmentManager(), "ExtraActionPickerDialogFragment"); fragment.setTargetFragment(this, DIALOG_ID);
fragment.show(getFragmentManager(), "ExtraActionPickerDialogFragment");
} }
private void onExtraItemSelected(int itemId) { @Override
public void onItemSelected(int itemId) {
for (AbstractExtraActionItem extraActionItem : extraActionItems) { for (AbstractExtraActionItem extraActionItem : extraActionItems) {
if (extraActionItem.getItemId() == itemId) { if (extraActionItem.getItemId() == itemId) {
RoomFragmentPermissionsDispatcher RoomFragmentPermissionsDispatcher
......
...@@ -23,7 +23,7 @@ import chat.rocket.android.realm_helper.RealmObjectObserver; ...@@ -23,7 +23,7 @@ import chat.rocket.android.realm_helper.RealmObjectObserver;
import chat.rocket.android.service.RocketChatService; import chat.rocket.android.service.RocketChatService;
/** /**
* Dialog to show members in a room. * Dialog to onClick members in a room.
*/ */
public class UsersOfRoomDialogFragment extends AbstractChatRoomDialogFragment { public class UsersOfRoomDialogFragment extends AbstractChatRoomDialogFragment {
......
...@@ -11,14 +11,14 @@ public class MessageFormManager { ...@@ -11,14 +11,14 @@ public class MessageFormManager {
private SendMessageCallback sendMessageCallback; private SendMessageCallback sendMessageCallback;
public MessageFormManager(MessageFormLayout messageFormLayout, public MessageFormManager(MessageFormLayout messageFormLayout,
MessageFormLayout.ShowExtraActionSelectionCallback callback) { MessageFormLayout.ExtraActionSelectionClickListener callback) {
this.messageFormLayout = messageFormLayout; this.messageFormLayout = messageFormLayout;
init(callback); init(callback);
} }
private void init(MessageFormLayout.ShowExtraActionSelectionCallback callback) { private void init(MessageFormLayout.ExtraActionSelectionClickListener listener) {
messageFormLayout.setShowExtraActionSelectionCallback(callback); messageFormLayout.setExtraActionSelectionClickListener(listener);
messageFormLayout.setTextListener(this::sendMessage); messageFormLayout.setSubmitTextListener(this::sendMessage);
} }
public void setSendMessageCallback(SendMessageCallback sendMessageCallback) { public void setSendMessageCallback(SendMessageCallback sendMessageCallback) {
......
...@@ -27,7 +27,7 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -27,7 +27,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
} }
/** /**
* show Avatar image. * onClick Avatar image.
*/ */
public MessageRenderer avatarInto(ImageView imageView, String hostname) { public MessageRenderer avatarInto(ImageView imageView, String hostname) {
switch (object.getSyncState()) { switch (object.getSyncState()) {
...@@ -42,7 +42,7 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -42,7 +42,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
} }
/** /**
* show Username in textView. * onClick Username in textView.
*/ */
public MessageRenderer usernameInto(TextView textView) { public MessageRenderer usernameInto(TextView textView) {
userRenderer.usernameInto(textView); userRenderer.usernameInto(textView);
...@@ -50,7 +50,7 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -50,7 +50,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
} }
/** /**
* show timestamp in textView. * onClick timestamp in textView.
*/ */
public MessageRenderer timestampInto(TextView textView) { public MessageRenderer timestampInto(TextView textView) {
if (!shouldHandle(textView)) { if (!shouldHandle(textView)) {
...@@ -71,7 +71,7 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -71,7 +71,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
} }
/** /**
* show body in RocketChatMessageLayout. * onClick body in RocketChatMessageLayout.
*/ */
public MessageRenderer bodyInto(RocketChatMessageLayout rocketChatMessageLayout) { public MessageRenderer bodyInto(RocketChatMessageLayout rocketChatMessageLayout) {
if (!shouldHandle(rocketChatMessageLayout)) { if (!shouldHandle(rocketChatMessageLayout)) {
...@@ -84,7 +84,7 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -84,7 +84,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
} }
/** /**
* show urls in RocketChatMessageUrlsLayout. * onClick urls in RocketChatMessageUrlsLayout.
*/ */
public MessageRenderer urlsInto(RocketChatMessageUrlsLayout urlsLayout) { public MessageRenderer urlsInto(RocketChatMessageUrlsLayout urlsLayout) {
if (!shouldHandle(urlsLayout)) { if (!shouldHandle(urlsLayout)) {
...@@ -103,7 +103,7 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -103,7 +103,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
} }
/** /**
* show urls in RocketChatMessageUrlsLayout. * onClick urls in RocketChatMessageUrlsLayout.
*/ */
public MessageRenderer attachmentsInto(RocketChatMessageAttachmentsLayout attachmentsLayout, public MessageRenderer attachmentsInto(RocketChatMessageAttachmentsLayout attachmentsLayout,
String hostname, String userId, String token) { String hostname, String userId, String token) {
......
...@@ -19,7 +19,7 @@ public class UserRenderer extends AbstractRenderer<User> { ...@@ -19,7 +19,7 @@ public class UserRenderer extends AbstractRenderer<User> {
} }
/** /**
* show Avatar image. * onClick Avatar image.
*/ */
public UserRenderer avatarInto(ImageView imageView, String hostname) { public UserRenderer avatarInto(ImageView imageView, String hostname) {
if (!shouldHandle(imageView)) { if (!shouldHandle(imageView)) {
...@@ -33,7 +33,7 @@ public class UserRenderer extends AbstractRenderer<User> { ...@@ -33,7 +33,7 @@ public class UserRenderer extends AbstractRenderer<User> {
} }
/** /**
* show Username in textView. * onClick Username in textView.
*/ */
public UserRenderer usernameInto(TextView textView) { public UserRenderer usernameInto(TextView textView) {
if (!shouldHandle(textView)) { if (!shouldHandle(textView)) {
...@@ -45,7 +45,7 @@ public class UserRenderer extends AbstractRenderer<User> { ...@@ -45,7 +45,7 @@ public class UserRenderer extends AbstractRenderer<User> {
} }
/** /**
* show user's status color into imageView. * onClick user's status color into imageView.
*/ */
public UserRenderer statusColorInto(ImageView imageView) { public UserRenderer statusColorInto(ImageView imageView) {
if (!shouldHandle(imageView)) { if (!shouldHandle(imageView)) {
......
...@@ -2,6 +2,7 @@ package chat.rocket.android.widget.internal; ...@@ -2,6 +2,7 @@ package chat.rocket.android.widget.internal;
import android.app.Dialog; import android.app.Dialog;
import android.support.design.widget.BottomSheetDialogFragment; import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import java.util.List; import java.util.List;
...@@ -12,13 +13,11 @@ import chat.rocket.android.widget.message.MessageExtraActionItemPresenter; ...@@ -12,13 +13,11 @@ import chat.rocket.android.widget.message.MessageExtraActionItemPresenter;
public class ExtraActionPickerDialogFragment extends BottomSheetDialogFragment { public class ExtraActionPickerDialogFragment extends BottomSheetDialogFragment {
private List<MessageExtraActionItemPresenter> actionItems; private List<MessageExtraActionItemPresenter> actionItems;
private Callback callback;
public static ExtraActionPickerDialogFragment create( public static ExtraActionPickerDialogFragment create(
List<MessageExtraActionItemPresenter> actionItems, Callback callback) { List<MessageExtraActionItemPresenter> actionItems) {
ExtraActionPickerDialogFragment fragment = new ExtraActionPickerDialogFragment(); ExtraActionPickerDialogFragment fragment = new ExtraActionPickerDialogFragment();
fragment.setActionItems(actionItems); fragment.setActionItems(actionItems);
fragment.setCallback(callback);
return fragment; return fragment;
} }
...@@ -27,10 +26,6 @@ public class ExtraActionPickerDialogFragment extends BottomSheetDialogFragment { ...@@ -27,10 +26,6 @@ public class ExtraActionPickerDialogFragment extends BottomSheetDialogFragment {
this.actionItems = actionItems; this.actionItems = actionItems;
} }
public void setCallback(Callback callback) {
this.callback = callback;
}
@Override @Override
public final void setupDialog(Dialog dialog, int style) { public final void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style); super.setupDialog(dialog, style);
...@@ -51,8 +46,9 @@ public class ExtraActionPickerDialogFragment extends BottomSheetDialogFragment { ...@@ -51,8 +46,9 @@ public class ExtraActionPickerDialogFragment extends BottomSheetDialogFragment {
} }
private void callbackOnItemSelected(int itemId) { private void callbackOnItemSelected(int itemId) {
if (callback != null) { final Fragment fragment = getTargetFragment();
callback.onItemSelected(itemId); if (fragment instanceof Callback) {
((Callback) fragment).onItemSelected(itemId);
} }
} }
......
...@@ -14,7 +14,6 @@ import android.widget.EditText; ...@@ -14,7 +14,6 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList;
import chat.rocket.android.widget.R; import chat.rocket.android.widget.R;
public class MessageFormLayout extends LinearLayout { public class MessageFormLayout extends LinearLayout {
...@@ -24,8 +23,8 @@ public class MessageFormLayout extends LinearLayout { ...@@ -24,8 +23,8 @@ public class MessageFormLayout extends LinearLayout {
private View btnExtra; private View btnExtra;
private View btnSubmit; private View btnSubmit;
private ShowExtraActionSelectionCallback showExtraActionSelectionCallback; private ExtraActionSelectionClickListener extraActionSelectionClickListener;
private TextListener textListener; private SubmitTextListener submitTextListener;
public MessageFormLayout(Context context) { public MessageFormLayout(Context context) {
super(context); super(context);
...@@ -57,7 +56,7 @@ public class MessageFormLayout extends LinearLayout { ...@@ -57,7 +56,7 @@ public class MessageFormLayout extends LinearLayout {
btnExtra.setOnClickListener(new OnClickListener() { btnExtra.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
showExtraActionSelectionDialog(); onExtraActionSelectionClick();
} }
}); });
...@@ -67,8 +66,8 @@ public class MessageFormLayout extends LinearLayout { ...@@ -67,8 +66,8 @@ public class MessageFormLayout extends LinearLayout {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
String messageText = getText(); String messageText = getText();
if (messageText.length() > 0 && textListener != null) { if (messageText.length() > 0 && submitTextListener != null) {
textListener.onSubmitText(messageText); submitTextListener.onSubmitText(messageText);
} }
} }
}); });
...@@ -101,18 +100,18 @@ public class MessageFormLayout extends LinearLayout { ...@@ -101,18 +100,18 @@ public class MessageFormLayout extends LinearLayout {
addView(composer); addView(composer);
} }
public void setShowExtraActionSelectionCallback( public void setExtraActionSelectionClickListener(
ShowExtraActionSelectionCallback showExtraActionSelectionCallback) { ExtraActionSelectionClickListener extraActionSelectionClickListener) {
this.showExtraActionSelectionCallback = showExtraActionSelectionCallback; this.extraActionSelectionClickListener = extraActionSelectionClickListener;
} }
public void setTextListener(TextListener textListener) { public void setSubmitTextListener(SubmitTextListener submitTextListener) {
this.textListener = textListener; this.submitTextListener = submitTextListener;
} }
private void showExtraActionSelectionDialog() { private void onExtraActionSelectionClick() {
if (showExtraActionSelectionCallback != null) { if (extraActionSelectionClickListener != null) {
showExtraActionSelectionCallback.show(); extraActionSelectionClickListener.onClick();
} }
} }
...@@ -151,11 +150,11 @@ public class MessageFormLayout extends LinearLayout { ...@@ -151,11 +150,11 @@ public class MessageFormLayout extends LinearLayout {
}); });
} }
public interface ShowExtraActionSelectionCallback { public interface ExtraActionSelectionClickListener {
void show(); void onClick();
} }
public interface TextListener { public interface SubmitTextListener {
void onSubmitText(String message); void onSubmitText(String message);
} }
} }
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