Commit 151b4d03 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add image thumb when replying to image attachments

parent 1c2e9e44
...@@ -5,6 +5,7 @@ import android.support.annotation.Nullable; ...@@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
import java.util.List; import java.util.List;
import chat.rocket.android.shared.BaseContract; import chat.rocket.android.shared.BaseContract;
import chat.rocket.android.widget.AbsoluteUrl;
import chat.rocket.core.models.Message; import chat.rocket.core.models.Message;
import chat.rocket.core.models.Room; import chat.rocket.core.models.Room;
import chat.rocket.core.models.User; import chat.rocket.core.models.User;
...@@ -37,7 +38,7 @@ public interface RoomContract { ...@@ -37,7 +38,7 @@ public interface RoomContract {
void manualLoadImages(); void manualLoadImages();
void onReply(String markdown, Message message); void onReply(AbsoluteUrl absoluteUrl, String markdown, Message message);
void onCopy(String message); void onCopy(String message);
......
...@@ -60,6 +60,7 @@ import chat.rocket.android.renderer.RocketChatUserStatusProvider; ...@@ -60,6 +60,7 @@ import chat.rocket.android.renderer.RocketChatUserStatusProvider;
import chat.rocket.android.service.ConnectivityManager; import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.service.temp.DeafultTempSpotlightRoomCaller; import chat.rocket.android.service.temp.DeafultTempSpotlightRoomCaller;
import chat.rocket.android.service.temp.DefaultTempSpotlightUserCaller; import chat.rocket.android.service.temp.DefaultTempSpotlightUserCaller;
import chat.rocket.android.widget.AbsoluteUrl;
import chat.rocket.android.widget.RoomToolbar; import chat.rocket.android.widget.RoomToolbar;
import chat.rocket.android.widget.internal.ExtraActionPickerDialogFragment; import chat.rocket.android.widget.internal.ExtraActionPickerDialogFragment;
import chat.rocket.android.widget.message.MessageFormLayout; import chat.rocket.android.widget.message.MessageFormLayout;
...@@ -649,8 +650,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -649,8 +650,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void onReply(String markdown, Message message) { public void onReply(AbsoluteUrl absoluteUrl, String markdown, Message message) {
messageFormManager.setReply(markdown, message); messageFormManager.setReply(absoluteUrl, markdown, message);
} }
@Override @Override
......
...@@ -24,7 +24,6 @@ import chat.rocket.core.repositories.UserRepository; ...@@ -24,7 +24,6 @@ import chat.rocket.core.repositories.UserRepository;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
public class RoomPresenter extends BasePresenter<RoomContract.View> public class RoomPresenter extends BasePresenter<RoomContract.View>
implements RoomContract.Presenter { implements RoomContract.Presenter {
...@@ -133,7 +132,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -133,7 +132,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
serverUrl -> { serverUrl -> {
if (serverUrl.isPresent()) { if (serverUrl.isPresent()) {
String baseUrl = serverUrl.get().getBaseUrl(); String baseUrl = serverUrl.get().getBaseUrl();
view.onReply(buildReplyMarkDown(baseUrl, message), message); view.onReply(serverUrl.get(), buildReplyMarkDown(baseUrl, message), message);
} }
}, },
Logger::report Logger::report
......
package chat.rocket.android.layouthelper.chatroom package chat.rocket.android.layouthelper.chatroom
import android.text.TextUtils
import android.view.View import android.view.View
import chat.rocket.android.widget.AbsoluteUrl
import chat.rocket.android.widget.message.MessageFormLayout import chat.rocket.android.widget.message.MessageFormLayout
import chat.rocket.core.models.Message import chat.rocket.core.models.Message
...@@ -34,9 +36,9 @@ class MessageFormManager(private val messageFormLayout: MessageFormLayout, val c ...@@ -34,9 +36,9 @@ class MessageFormManager(private val messageFormLayout: MessageFormLayout, val c
messageFormLayout.isEnabled = enable messageFormLayout.isEnabled = enable
} }
fun setReply(replyMarkDown: String, message: Message) { fun setReply(absoluteUrl: AbsoluteUrl, replyMarkDown: String, message: Message) {
this.replyMarkDown = replyMarkDown this.replyMarkDown = replyMarkDown
messageFormLayout.setReplyContent(message) messageFormLayout.setReplyContent(absoluteUrl, message)
messageFormLayout.setReplyCancelListener({ messageFormLayout.setReplyCancelListener({
this.replyMarkDown = "" this.replyMarkDown = ""
messageFormLayout.clearReplyContent() messageFormLayout.clearReplyContent()
......
...@@ -6,7 +6,6 @@ import android.support.v4.util.Pair; ...@@ -6,7 +6,6 @@ import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
......
...@@ -21,8 +21,14 @@ import android.widget.LinearLayout; ...@@ -21,8 +21,14 @@ import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import chat.rocket.android.widget.AbsoluteUrl;
import chat.rocket.android.widget.R; import chat.rocket.android.widget.R;
import chat.rocket.android.widget.helper.DebouncingOnClickListener; import chat.rocket.android.widget.helper.DebouncingOnClickListener;
import chat.rocket.android.widget.helper.FrescoHelper;
import chat.rocket.core.models.Attachment;
import chat.rocket.core.models.AttachmentTitle;
import chat.rocket.core.models.Message; import chat.rocket.core.models.Message;
public class MessageFormLayout extends LinearLayout { public class MessageFormLayout extends LinearLayout {
...@@ -34,6 +40,7 @@ public class MessageFormLayout extends LinearLayout { ...@@ -34,6 +40,7 @@ public class MessageFormLayout extends LinearLayout {
private RelativeLayout replyBar; private RelativeLayout replyBar;
private ImageView replyCancelButton; private ImageView replyCancelButton;
private SimpleDraweeView replyThumb;
private TextView replyMessageText; private TextView replyMessageText;
private TextView replyUsernameText; private TextView replyUsernameText;
...@@ -78,6 +85,7 @@ public class MessageFormLayout extends LinearLayout { ...@@ -78,6 +85,7 @@ public class MessageFormLayout extends LinearLayout {
replyCancelButton = composer.findViewById(R.id.reply_cancel); replyCancelButton = composer.findViewById(R.id.reply_cancel);
replyMessageText = composer.findViewById(R.id.reply_message); replyMessageText = composer.findViewById(R.id.reply_message);
replyUsernameText = composer.findViewById(R.id.reply_username); replyUsernameText = composer.findViewById(R.id.reply_username);
replyThumb = composer.findViewById(R.id.reply_thumb);
replyBar = composer.findViewById(R.id.reply_bar); replyBar = composer.findViewById(R.id.reply_bar);
sendButton = composer.findViewById(R.id.button_send); sendButton = composer.findViewById(R.id.button_send);
...@@ -136,9 +144,13 @@ public class MessageFormLayout extends LinearLayout { ...@@ -136,9 +144,13 @@ public class MessageFormLayout extends LinearLayout {
public void clearReplyContent() { public void clearReplyContent() {
replyBar.setVisibility(View.GONE); replyBar.setVisibility(View.GONE);
replyThumb.setVisibility(View.GONE);
replyMessageText.setText(""); replyMessageText.setText("");
replyUsernameText.setText(""); replyUsernameText.setText("");
} }
public void showReplyThumb() {
replyThumb.setVisibility(View.VISIBLE);
}
public void setReplyCancelListener(OnClickListener onClickListener) { public void setReplyCancelListener(OnClickListener onClickListener) {
replyCancelButton.setOnClickListener(onClickListener); replyCancelButton.setOnClickListener(onClickListener);
...@@ -196,14 +208,34 @@ public class MessageFormLayout extends LinearLayout { ...@@ -196,14 +208,34 @@ public class MessageFormLayout extends LinearLayout {
this.listener = listener; this.listener = listener;
} }
public void setReplyContent(@NonNull Message message) { public void setReplyContent(@NonNull AbsoluteUrl absoluteUrl, @NonNull Message message) {
String text = message.getMessage(); String text = message.getMessage();
replyUsernameText.setText(message.getUser().getUsername());
if (!TextUtils.isEmpty(text)) { if (!TextUtils.isEmpty(text)) {
replyMessageText.setText(text); replyMessageText.setText(text);
replyUsernameText.setText(message.getUser().getUsername()); } else {
replyBar.setVisibility(View.VISIBLE); if (message.getAttachments() != null && message.getAttachments().size() > 0) {
requestFocusAndShowKeyboard(); Attachment attachment = message.getAttachments().get(0);
AttachmentTitle attachmentTitle = attachment.getAttachmentTitle();
String imageUrl = null;
if (attachment.getImageUrl() != null) {
imageUrl = absoluteUrl.from(attachment.getImageUrl());
}
if (attachmentTitle != null) {
text = attachmentTitle.getTitle();
}
if (TextUtils.isEmpty(text)) {
text = "Unknown";
}
if (imageUrl != null) {
FrescoHelper.INSTANCE.loadImageWithCustomization(replyThumb, imageUrl);
showReplyThumb();
}
replyMessageText.setText(text);
}
} }
replyBar.setVisibility(View.VISIBLE);
requestFocusAndShowKeyboard();
} }
private void requestFocusAndShowKeyboard() { private void requestFocusAndShowKeyboard() {
......
<!-- drawable/reply.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M10,9V5L3,12L10,19V14.9C15,14.9 18.5,16.5 21,20C20,15 17,10 10,9Z" />
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -13,10 +14,10 @@ ...@@ -13,10 +14,10 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="8dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="8dp"
android:layout_marginRight="16dp" android:layout_marginRight="8dp"
android:layout_marginStart="16dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/keyboard_container" app:layout_constraintBottom_toTopOf="@+id/keyboard_container"
...@@ -27,10 +28,25 @@ ...@@ -27,10 +28,25 @@
tools:layout_editor_absoluteY="8dp" tools:layout_editor_absoluteY="8dp"
tools:visibility="visible"> tools:visibility="visible">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/reply_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:adjustViewBounds="true"
app:srcCompat="@drawable/ic_reply"
app:tint="@color/color_accent" />
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/reply_cancel" android:id="@+id/reply_cancel"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
...@@ -45,12 +61,28 @@ ...@@ -45,12 +61,28 @@
android:layout_alignBaseline="@id/reply_username" android:layout_alignBaseline="@id/reply_username"
android:layout_toLeftOf="@+id/reply_cancel" android:layout_toLeftOf="@+id/reply_cancel"
android:layout_toStartOf="@id/reply_cancel" android:layout_toStartOf="@id/reply_cancel"
android:layout_toRightOf="@+id/reply_thumb"
android:layout_toEndOf="@+id/reply_thumb"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textColor="@color/color_accent" android:textColor="@color/color_accent"
android:textStyle="bold" android:textStyle="bold"
tools:text="jane.doe" /> tools:text="jane.doe" />
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/reply_thumb"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_marginEnd="4dp"
android:layout_toRightOf="@+id/reply_icon"
android:layout_toEndOf="@+id/reply_icon"
android:layout_alignBottom="@+id/reply_message"
android:layout_alignTop="@+id/reply_username"
android:layout_centerVertical="true"
android:visibility="gone"
fresco:actualImageScaleType="fitCenter" />
<TextView <TextView
android:id="@+id/reply_message" android:id="@+id/reply_message"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -58,9 +90,11 @@ ...@@ -58,9 +90,11 @@
android:layout_below="@id/reply_username" android:layout_below="@id/reply_username"
android:layout_toLeftOf="@+id/reply_cancel" android:layout_toLeftOf="@+id/reply_cancel"
android:layout_toStartOf="@id/reply_cancel" android:layout_toStartOf="@id/reply_cancel"
android:layout_toRightOf="@+id/reply_thumb"
android:layout_toEndOf="@+id/reply_thumb"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
tools:text="Mensagemaaaaaaaaaaaaaaaaaddddddddddddddddddddddddddddddddsdsdsdsdsdsdsdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadadadadddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" /> tools:text="Message" />
</RelativeLayout> </RelativeLayout>
......
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