Commit b3382b08 authored by Tiago Cunha's avatar Tiago Cunha

PR based improvements

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