Commit 0b3f313e authored by Yusuke Iwaki's avatar Yusuke Iwaki

refactor

parent baa0ddaf
......@@ -22,7 +22,6 @@ import java.util.UUID;
import chat.rocket.android.R;
import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.fragment.chatroom.dialog.FileUploadProgressDialogFragment;
import chat.rocket.android.fragment.chatroom.dialog.MessageSelectionDialogFragment;
import chat.rocket.android.fragment.chatroom.dialog.UsersOfRoomDialogFragment;
import chat.rocket.android.helper.FileUploadHelper;
import chat.rocket.android.helper.LoadMoreScrollListener;
......@@ -32,12 +31,12 @@ import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.layouthelper.chatroom.MessageFormManager;
import chat.rocket.android.layouthelper.chatroom.MessageListAdapter;
import chat.rocket.android.layouthelper.chatroom.PairedMessage;
import chat.rocket.android.layouthelper.extra_action.MessageExtraActionBehavior;
import chat.rocket.android.log.RCLog;
import chat.rocket.android.message.AbstractMessageSpec;
import chat.rocket.android.message.AudioUploadMessageSpec;
import chat.rocket.android.message.AbstractUploadMessageSpec;
import chat.rocket.android.message.ImageUploadMessageSpec;
import chat.rocket.android.message.VideoUploadMessageSpec;
import chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionItem;
import chat.rocket.android.layouthelper.extra_action.upload.AbstractUploadActionItem;
import chat.rocket.android.layouthelper.extra_action.upload.ImageUploadActionItem;
import chat.rocket.android.layouthelper.extra_action.upload.VideoUploadActionItem;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.model.SyncState;
import chat.rocket.android.model.ddp.Message;
......@@ -70,11 +69,7 @@ public class RoomFragment extends AbstractChatRoomFragment
private String token;
private LoadMoreScrollListener scrollListener;
private RealmObjectObserver<LoadMessageProcedure> procedureObserver;
private MessageFormManager messageComposerManager;
private MessageSelectionDialogFragment.ClickListener messageSelectionClickListener =
messageSpec -> RoomFragmentPermissionsDispatcher
.onMessageSpecSelectedWithCheck(RoomFragment.this, messageSpec);
private MessageFormManager messageFormManager;
public RoomFragment() {
}
......@@ -226,8 +221,8 @@ public class RoomFragment extends AbstractChatRoomFragment
private void setupMessageComposer() {
final MessageFormLayout messageFormLayout =
(MessageFormLayout) rootView.findViewById(R.id.message_composer);
messageComposerManager = new MessageFormManager(messageFormLayout);
messageComposerManager.setSendMessageCallback(messageText ->
messageFormManager = new MessageFormManager(messageFormLayout);
messageFormManager.setSendMessageCallback(messageText ->
realmHelper.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(Message.class, new JSONObject()
.put("_id", UUID.randomUUID().toString())
......@@ -235,25 +230,17 @@ public class RoomFragment extends AbstractChatRoomFragment
.put("ts", System.currentTimeMillis())
.put("rid", roomId)
.put("msg", messageText))));
messageComposerManager.setExtrasPickerListener(() -> {
MessageSelectionDialogFragment fragment = MessageSelectionDialogFragment.create();
fragment.addMessageSpec(new ImageUploadMessageSpec());
fragment.addMessageSpec(new AudioUploadMessageSpec());
fragment.addMessageSpec(new VideoUploadMessageSpec());
fragment.setListener(messageSelectionClickListener);
fragment.show(getFragmentManager(), MessageSelectionDialogFragment.TAG);
closeSideMenuIfNeeded();
});
messageFormManager.registerExtraActionItem(new ImageUploadActionItem());
messageFormManager.registerExtraActionItem(new AudioUploadActionItem());
messageFormManager.registerExtraActionItem(new VideoUploadActionItem());
messageFormManager.setExtraActionPickerCallback(item ->
RoomFragmentPermissionsDispatcher.onExtraActionSelectedWithCheck(RoomFragment.this, item));
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode != AbstractUploadMessageSpec.RC_UPL || resultCode != Activity.RESULT_OK) {
if (requestCode != AbstractUploadActionItem.RC_UPL || resultCode != Activity.RESULT_OK) {
return;
}
......@@ -381,7 +368,7 @@ public class RoomFragment extends AbstractChatRoomFragment
}
@NeedsPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
protected void onMessageSpecSelected(AbstractMessageSpec messageSpec) {
messageSpec.onSelect(RoomFragment.this);
protected void onExtraActionSelected(MessageExtraActionBehavior action) {
action.handleItemSelectedOnFragment(RoomFragment.this);
}
}
package chat.rocket.android.fragment.chatroom.dialog;
import android.support.v7.widget.RecyclerView;
import chat.rocket.android.R;
import chat.rocket.android.layouthelper.chatroom.dialog.MessageSelectionAdapter;
import chat.rocket.android.message.AbstractMessageSpec;
public class MessageSelectionDialogFragment extends AbstractChatRoomDialogFragment {
public static final String TAG = "MessageSelectionDialogFragment";
private MessageSelectionAdapter adapter;
private ClickListener listener;
public static MessageSelectionDialogFragment create() {
return new MessageSelectionDialogFragment();
}
public MessageSelectionDialogFragment() {
adapter = new MessageSelectionAdapter();
adapter.setListener(messageSpec -> {
if (listener != null) {
listener.onClick(messageSpec);
}
dismiss();
});
}
public void addMessageSpec(AbstractMessageSpec abstractMessageSpec) {
adapter.addMessageSpec(abstractMessageSpec);
}
public void setListener(ClickListener listener) {
this.listener = listener;
}
@Override
protected int getLayout() {
return R.layout.dialog_message_selection;
}
@Override
protected void onSetupDialog() {
RecyclerView messageSpecList = (RecyclerView) getDialog().findViewById(R.id.message_spec_list);
messageSpecList.setAdapter(adapter);
}
public interface ClickListener {
void onClick(AbstractMessageSpec abstractMessageSpec);
}
}
package chat.rocket.android.layouthelper.chatroom;
import java.util.HashMap;
import bolts.Task;
import chat.rocket.android.layouthelper.extra_action.AbstractExtraActionItem;
import chat.rocket.android.widget.message.MessageFormLayout;
/**
......@@ -9,27 +11,30 @@ import chat.rocket.android.widget.message.MessageFormLayout;
public class MessageFormManager {
private final MessageFormLayout messageFormLayout;
private SendMessageCallback sendMessageCallback;
private ExtrasPickerListener extrasPickerListener;
private ExtraActionPickerCallback extraActionPickerCallback;
private final HashMap<Integer, AbstractExtraActionItem> extraActionItemMap;
public MessageFormManager(MessageFormLayout messageFormLayout) {
this.messageFormLayout = messageFormLayout;
this.extraActionItemMap = new HashMap<>();
init();
}
private void init() {
messageFormLayout.setOnActionListener(new MessageFormLayout.ActionListener() {
@Override
public void onSubmit(String message) {
public void onSubmitText(String message) {
sendMessage(message);
}
@Override
public void onExtra() {
openExtras();
public void onExtraActionSelected(int itemId) {
if (extraActionItemMap.containsKey(itemId)) {
AbstractExtraActionItem item = extraActionItemMap.get(itemId);
if (extraActionPickerCallback != null) {
extraActionPickerCallback.onExtraActionSelected(item);
}
}
@Override
public void onCancel() {
}
});
}
......@@ -38,8 +43,8 @@ public class MessageFormManager {
this.sendMessageCallback = sendMessageCallback;
}
public void setExtrasPickerListener(ExtrasPickerListener listener) {
extrasPickerListener = listener;
public void setExtraActionPickerCallback(ExtraActionPickerCallback extraActionPickerCallback) {
this.extraActionPickerCallback = extraActionPickerCallback;
}
public void clearComposingText() {
......@@ -52,7 +57,7 @@ public class MessageFormManager {
}
messageFormLayout.setEnabled(false);
sendMessageCallback.onSubmit(message).onSuccess(task -> {
sendMessageCallback.onSubmitText(message).onSuccess(task -> {
clearComposingText();
return null;
}).continueWith(task -> {
......@@ -61,19 +66,16 @@ public class MessageFormManager {
});
}
private void openExtras() {
if (extrasPickerListener == null) {
return;
}
extrasPickerListener.onOpen();
public void registerExtraActionItem(AbstractExtraActionItem actionItem) {
messageFormLayout.addExtraActionItem(actionItem);
extraActionItemMap.put(actionItem.getItemId(), actionItem);
}
public interface SendMessageCallback {
Task<Void> onSubmit(String messageText);
Task<Void> onSubmitText(String messageText);
}
public interface ExtrasPickerListener {
void onOpen();
public interface ExtraActionPickerCallback {
void onExtraActionSelected(AbstractExtraActionItem item);
}
}
package chat.rocket.android.layouthelper.chatroom.dialog;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
import chat.rocket.android.R;
import chat.rocket.android.message.AbstractMessageSpec;
public class MessageSelectionAdapter
extends RecyclerView.Adapter<MessageSelectionViewHolder> {
private List<AbstractMessageSpec> abstractMessageSpecs = new ArrayList<>();
private ClickListener listener;
public void setListener(ClickListener listener) {
this.listener = listener;
}
public void addMessageSpec(AbstractMessageSpec abstractMessageSpec) {
abstractMessageSpecs.add(abstractMessageSpec);
notifyDataSetChanged();
}
@Override
public MessageSelectionViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.dialog_message_selection_item, parent, false);
itemView.setOnClickListener(view -> {
if (listener != null) {
listener.onClick((AbstractMessageSpec) itemView.getTag());
}
});
return new MessageSelectionViewHolder(itemView);
}
@Override
public void onBindViewHolder(MessageSelectionViewHolder holder,
int position) {
holder.onBind(abstractMessageSpecs.get(position));
}
@Override
public int getItemCount() {
return abstractMessageSpecs.size();
}
public interface ClickListener {
void onClick(AbstractMessageSpec abstractMessageSpec);
}
}
package chat.rocket.android.layouthelper.extra_action;
import chat.rocket.android.widget.message.MessageExtraActionItemPresenter;
/**
* Simple base class that implements MessageExtraActionBehavior, MessageExtraActionItemPresenter.
*/
public abstract class AbstractExtraActionItem
implements MessageExtraActionBehavior, MessageExtraActionItemPresenter {
}
package chat.rocket.android.layouthelper.extra_action;
import android.app.Activity;
import android.support.v4.app.Fragment;
public interface MessageExtraActionBehavior {
void handleItemSelectedOnActivity(Activity activity);
void handleItemSelectedOnFragment(Fragment fragment);
}
package chat.rocket.android.layouthelper.extra_action.upload;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;
import chat.rocket.android.R;
import chat.rocket.android.layouthelper.extra_action.AbstractExtraActionItem;
public abstract class AbstractUploadActionItem extends AbstractExtraActionItem {
public static final int RC_UPL = 0x12;
@Override
public void handleItemSelectedOnActivity(Activity activity) {
activity.startActivityForResult(getIntentForPickFile(), RC_UPL);
}
@Override
public void handleItemSelectedOnFragment(Fragment fragment) {
fragment.startActivityForResult(getIntentForPickFile(), RC_UPL);
}
protected abstract Intent getIntentForPickFile();
@Override
public int getBackgroundTint() {
return R.color.colorAccent;
}
}
package chat.rocket.android.message;
package chat.rocket.android.layouthelper.extra_action.upload;
import android.content.Intent;
import chat.rocket.android.R;
public class AudioUploadMessageSpec extends AbstractUploadMessageSpec {
public class AudioUploadActionItem extends AbstractUploadActionItem {
@Override
protected Intent getIntent() {
public int getItemId() {
return 11;
}
@Override
protected Intent getIntentForPickFile() {
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Audio to Upload");
}
@Override
public ViewData getSpecificViewData() {
return new AudioUploadViewData();
}
private static class AudioUploadViewData implements AbstractMessageSpec.ViewData {
@Override
public int getBackgroundTint() {
return R.color.colorAccent;
}
@Override
public int getIcon() {
return R.drawable.ic_audiotrack_white_24dp;
......@@ -34,5 +28,4 @@ public class AudioUploadMessageSpec extends AbstractUploadMessageSpec {
public int getTitle() {
return R.string.audio_upload_message_spec_title;
}
}
}
package chat.rocket.android.message;
package chat.rocket.android.layouthelper.extra_action.upload;
import android.content.Intent;
import chat.rocket.android.R;
public class ImageUploadMessageSpec extends AbstractUploadMessageSpec {
public class ImageUploadActionItem extends AbstractUploadActionItem {
@Override
public ViewData getSpecificViewData() {
return new ImageUploadViewData();
public int getItemId() {
return 10;
}
@Override
protected Intent getIntent() {
protected Intent getIntentForPickFile() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Picture to Upload");
}
private static class ImageUploadViewData implements AbstractMessageSpec.ViewData {
@Override
public int getBackgroundTint() {
return R.color.colorAccent;
}
@Override
public int getIcon() {
return R.drawable.ic_insert_photo_white_24dp;
......@@ -34,5 +28,4 @@ public class ImageUploadMessageSpec extends AbstractUploadMessageSpec {
public int getTitle() {
return R.string.image_upload_message_spec_title;
}
}
}
package chat.rocket.android.message;
package chat.rocket.android.layouthelper.extra_action.upload;
import android.content.Intent;
import chat.rocket.android.R;
public class VideoUploadMessageSpec extends AbstractUploadMessageSpec {
public class VideoUploadActionItem extends AbstractUploadActionItem {
@Override
public ViewData getSpecificViewData() {
return new VideoUploadViewData();
public int getItemId() {
return 12;
}
@Override
protected Intent getIntent() {
protected Intent getIntentForPickFile() {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Video to Upload");
}
private static class VideoUploadViewData implements AbstractMessageSpec.ViewData {
@Override
public int getBackgroundTint() {
return R.color.colorAccent;
}
@Override
public int getIcon() {
return R.drawable.ic_video_call_white_24dp;
......@@ -34,5 +28,4 @@ public class VideoUploadMessageSpec extends AbstractUploadMessageSpec {
public int getTitle() {
return R.string.video_upload_message_spec_title;
}
}
}
package chat.rocket.android.message;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
public abstract class AbstractMessageSpec {
public abstract ViewData getViewData();
public abstract void onSelect(Activity activity);
public abstract void onSelect(Fragment fragment);
public interface ViewData {
@ColorRes
int getBackgroundTint();
@DrawableRes
int getIcon();
@StringRes
int getTitle();
}
}
package chat.rocket.android.message;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.content.Intent;
public abstract class AbstractUploadMessageSpec extends AbstractMessageSpec {
public static final int RC_UPL = 0x12;
private ViewData viewData;
@Override
public ViewData getViewData() {
if (viewData == null) {
viewData = getSpecificViewData();
}
return viewData;
}
@Override
public void onSelect(Activity activity) {
activity.startActivityForResult(getIntent(), RC_UPL);
}
@Override
public void onSelect(Fragment fragment) {
fragment.startActivityForResult(getIntent(), RC_UPL);
}
protected abstract Intent getIntent();
protected abstract ViewData getSpecificViewData();
}
......@@ -38,4 +38,5 @@ dependencies {
compile rootProject.ext.okhttp3
compile rootProject.ext.picasso
compile rootProject.ext.picasso2Okhttp3Downloader
compile rootProject.ext.boltsTask
}
package chat.rocket.android.widget.internal;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.OperationCanceledException;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.RecyclerView;
import java.util.List;
import bolts.Task;
import bolts.TaskCompletionSource;
import chat.rocket.android.widget.R;
import chat.rocket.android.widget.layouthelper.MessageExtraActionListAdapter;
import chat.rocket.android.widget.message.MessageExtraActionItemPresenter;
public class ExtraActionPickerDialog {
/**
* show extra actions picker diaog.
*/
public static Task<Integer> showAsTask(Context context,
List<MessageExtraActionItemPresenter> actionItems) {
final TaskCompletionSource<Integer> task = new TaskCompletionSource<>();
Impl dialog = new Impl(context, actionItems);
dialog.setCallback(new Impl.Callback() {
@Override
public void onItemSelected(int itemId) {
task.setResult(itemId);
}
@Override
public void onCanceled() {
task.setError(new OperationCanceledException());
}
});
dialog.show();
return task.getTask();
}
private static class Impl extends BottomSheetDialog {
private interface Callback {
void onItemSelected(int itemId);
void onCanceled();
}
private Callback callback;
private final List<MessageExtraActionItemPresenter> actionItems;
public void setCallback(Callback callback) {
this.callback = callback;
}
public Impl(@NonNull Context context, List<MessageExtraActionItemPresenter> actionItems) {
super(context);
this.actionItems = actionItems;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_message_extra_action_picker);
MessageExtraActionListAdapter adapter = new MessageExtraActionListAdapter(actionItems);
adapter.setOnItemClickListener(new MessageExtraActionListAdapter.OnItemClickListener() {
@Override
public void onItemClick(int itemId) {
doCallback(itemId);
dismiss();
}
});
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.message_extra_action_listview);
recyclerView.setAdapter(adapter);
setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
if (callback != null) {
callback.onCanceled();
}
}
});
}
private void doCallback(int itemId) {
if (callback != null) {
callback.onItemSelected(itemId);
}
}
}
}
\ No newline at end of file
package chat.rocket.android.layouthelper.chatroom.dialog;
package chat.rocket.android.widget.layouthelper;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
......@@ -10,40 +10,39 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import chat.rocket.android.R;
import chat.rocket.android.message.AbstractMessageSpec;
import chat.rocket.android.widget.R;
import chat.rocket.android.widget.message.MessageExtraActionItemPresenter;
public class MessageSelectionViewHolder extends RecyclerView.ViewHolder {
public class MessageExtraActionItemViewHolder extends RecyclerView.ViewHolder {
private ImageView messageSpecIcon;
private TextView messageSpecTitle;
private ImageView iconView;
private TextView titleView;
public MessageSelectionViewHolder(View itemView) {
public MessageExtraActionItemViewHolder(View itemView) {
super(itemView);
messageSpecIcon = (ImageView) itemView.findViewById(R.id.message_spec_icon);
messageSpecTitle = (TextView) itemView.findViewById(R.id.message_spec_title);
iconView = (ImageView) itemView.findViewById(R.id.icon);
titleView = (TextView) itemView.findViewById(R.id.title);
}
public void onBind(AbstractMessageSpec abstractMessageSpec) {
itemView.setTag(abstractMessageSpec);
public void onBind(MessageExtraActionItemPresenter actionItem) {
itemView.setTag(actionItem.getItemId());
AbstractMessageSpec.ViewData viewData = abstractMessageSpec.getViewData();
setIconBackgroundColorTint(viewData.getBackgroundTint());
setIcon(viewData.getIcon());
setTitle(viewData.getTitle());
setIconBackgroundColorTint(actionItem.getBackgroundTint());
setIcon(actionItem.getIcon());
setTitle(actionItem.getTitle());
}
public void setIconBackgroundColorTint(@ColorRes int color) {
// Drawable background = DrawableCompat.wrap(messageSpecIcon.getBackground());
DrawableCompat.setTint(messageSpecIcon.getBackground(),
ContextCompat.getColor(messageSpecIcon.getContext(), color));
DrawableCompat.setTint(iconView.getBackground(),
ContextCompat.getColor(iconView.getContext(), color));
}
public void setIcon(@DrawableRes int icon) {
messageSpecIcon.setImageResource(icon);
iconView.setImageResource(icon);
}
public void setTitle(@StringRes int title) {
messageSpecTitle.setText(title);
titleView.setText(title);
}
}
package chat.rocket.android.widget.layouthelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import chat.rocket.android.widget.R;
import chat.rocket.android.widget.message.MessageExtraActionItemPresenter;
public class MessageExtraActionListAdapter
extends RecyclerView.Adapter<MessageExtraActionItemViewHolder> {
private final List<MessageExtraActionItemPresenter> actionItems;
private OnItemClickListener listener;
public MessageExtraActionListAdapter(List<MessageExtraActionItemPresenter> actionItems) {
this.actionItems = actionItems;
}
public void setOnItemClickListener(OnItemClickListener listener) {
this.listener = listener;
}
@Override
public MessageExtraActionItemViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.message_extra_action_item, parent, false);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
if (view.getTag() != null) {
listener.onItemClick((int) view.getTag());
}
}
}
});
return new MessageExtraActionItemViewHolder(itemView);
}
@Override
public void onBindViewHolder(MessageExtraActionItemViewHolder holder,
int position) {
holder.onBind(actionItems.get(position));
}
@Override
public int getItemCount() {
return actionItems.size();
}
public interface OnItemClickListener {
void onItemClick(int itemId);
}
}
package chat.rocket.android.widget.message;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
/**
* View Data for message extra action item.
*/
public interface MessageExtraActionItemPresenter {
int getItemId();
@ColorRes
int getBackgroundTint();
@DrawableRes
int getIcon();
@StringRes
int getTitle();
}
......@@ -15,7 +15,12 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import bolts.Continuation;
import bolts.Task;
import chat.rocket.android.widget.R;
import chat.rocket.android.widget.internal.ExtraActionPickerDialog;
public class MessageFormLayout extends LinearLayout {
......@@ -24,6 +29,7 @@ public class MessageFormLayout extends LinearLayout {
private View btnExtra;
private View btnSubmit;
private List<MessageExtraActionItemPresenter> extraActionItems;
public MessageFormLayout(Context context) {
super(context);
......@@ -51,6 +57,7 @@ public class MessageFormLayout extends LinearLayout {
}
private void init() {
extraActionItems = new ArrayList<>();
composer = (ViewGroup) LayoutInflater.from(getContext())
.inflate(R.layout.message_composer, this, false);
......@@ -58,10 +65,8 @@ public class MessageFormLayout extends LinearLayout {
btnExtra.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (actionListener != null) {
actionListener.onExtra();
}
public void onClick(View view) {
showExtraActionSelectionDialog();
}
});
......@@ -72,7 +77,7 @@ public class MessageFormLayout extends LinearLayout {
public void onClick(View view) {
String messageText = getText();
if (messageText.length() > 0 && actionListener != null) {
actionListener.onSubmit(messageText);
actionListener.onSubmitText(messageText);
}
}
});
......@@ -105,6 +110,20 @@ public class MessageFormLayout extends LinearLayout {
addView(composer);
}
public void addExtraActionItem(MessageExtraActionItemPresenter itemPresenter) {
boolean found = false;
for (MessageExtraActionItemPresenter item : extraActionItems) {
if (item.getItemId() == itemPresenter.getItemId()) {
found = true;
break;
}
}
if (!found) {
extraActionItems.add(itemPresenter);
}
}
private TextView getEditor() {
return (TextView) composer.findViewById(R.id.editor);
}
......@@ -140,11 +159,23 @@ public class MessageFormLayout extends LinearLayout {
});
}
public interface ActionListener {
void onSubmit(String message);
private void showExtraActionSelectionDialog() {
ExtraActionPickerDialog.showAsTask(getContext(), extraActionItems)
.onSuccess(new Continuation<Integer, Object>() {
@Override
public Object then(Task<Integer> task) throws Exception {
int which = task.getResult();
if (actionListener != null) {
actionListener.onExtraActionSelected(which);
}
return null;
}
});
}
void onExtra();
public interface ActionListener {
void onSubmitText(String message);
void onCancel();
void onExtraActionSelected(int itemId);
}
}
<?xml version="1.0" encoding="utf-8"?>
<chat.rocket.android.widget.AutofitRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/message_spec_list"
android:id="@+id/message_extra_action_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="80dp"
tools:listitem="@layout/dialog_message_selection_item"
tools:listitem="@layout/message_extra_action_item"
android:clipToPadding="false">
</chat.rocket.android.widget.AutofitRecyclerView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:padding="@dimen/margin_8">
android:padding="8dp">
<ImageView
android:id="@+id/message_spec_icon"
android:id="@+id/icon"
android:layout_width="64dp"
android:layout_height="64dp"
android:padding="@dimen/margin_16"
tools:src="@drawable/ic_insert_photo_white_24dp"
android:padding="16dp"
android:layout_marginBottom="4dp"
android:background="@drawable/circle_black" />
<TextView
android:id="@+id/message_spec_title"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
tools:text="Attach file" />
android:gravity="center_horizontal"/>
</LinearLayout>
\ 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