Commit 8b3ed8b1 authored by Tiago Cunha's avatar Tiago Cunha

How to show editting?

parent c687071d
......@@ -289,6 +289,12 @@ public class RoomFragment extends AbstractChatRoomFragment
public boolean onItemLongClick(PairedMessage pairedMessage) {
MessageOptionsDialogFragment messageOptionsDialogFragment = MessageOptionsDialogFragment
.create(pairedMessage.target);
messageOptionsDialogFragment.setOnMessageOptionSelectedListener(message -> {
messageOptionsDialogFragment.dismiss();
onEditMessage(message);
});
messageOptionsDialogFragment.show(getChildFragmentManager(), "MessageOptionsDialogFragment");
return true;
}
......@@ -589,4 +595,7 @@ public class RoomFragment extends AbstractChatRoomFragment
public void manualLoadImages() {
adapter.setAutoloadImages(false);
}
private void onEditMessage(Message message) {
}
}
......@@ -6,6 +6,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v4.util.Pair;
import android.view.View;
import android.widget.TextView;
......@@ -39,6 +40,16 @@ public class MessageOptionsDialogFragment extends BottomSheetDialogFragment {
public final static String ARG_MESSAGE_ID = "messageId";
private CompositeDisposable compositeDisposable = new CompositeDisposable();
private OnMessageOptionSelectedListener internalListener = new OnMessageOptionSelectedListener() {
@Override
public void onEdit(Message message) {
if (externalListener != null) {
externalListener.onEdit(message);
}
}
};
private OnMessageOptionSelectedListener externalListener = null;
public static MessageOptionsDialogFragment create(@NonNull Message message) {
Bundle bundle = new Bundle();
......@@ -50,6 +61,11 @@ public class MessageOptionsDialogFragment extends BottomSheetDialogFragment {
return messageOptionsDialogFragment;
}
public void setOnMessageOptionSelectedListener(
OnMessageOptionSelectedListener onMessageOptionSelectedListener) {
externalListener = onMessageOptionSelectedListener;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
......@@ -87,18 +103,25 @@ public class MessageOptionsDialogFragment extends BottomSheetDialogFragment {
Disposable disposable = messageRepository.getById(messageId)
.flatMap(it -> {
if (!it.isPresent()) {
return Single.just(false);
return Single.just(Pair.<Message, Boolean>create(null, false));
}
return editMessageInteractor.isAllowed(it.get());
Message message = it.get();
return Single.zip(
Single.just(message),
editMessageInteractor.isAllowed(message),
Pair::create
);
})
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
isEditAllowed -> {
if (isEditAllowed) {
bottomSheetDialog.findViewById(R.id.message_options_edit_action)
.setVisibility(View.VISIBLE);
pair -> {
if (pair.second) {
View editView = bottomSheetDialog.findViewById(R.id.message_options_edit_action);
editView.setVisibility(View.VISIBLE);
editView.setOnClickListener(view -> internalListener.onEdit(pair.first));
} else {
((TextView) bottomSheetDialog.findViewById(R.id.message_options_info))
.setText(R.string.message_options_no_permissions_info);
......@@ -138,4 +161,8 @@ public class MessageOptionsDialogFragment extends BottomSheetDialogFragment {
publicSettingRepository
);
}
public interface OnMessageOptionSelectedListener {
void onEdit(Message 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